|
|
@ -47,6 +47,7 @@ type LongConnServer interface {
|
|
|
|
Validate(s interface{}) error
|
|
|
|
Validate(s interface{}) error
|
|
|
|
SetCacheHandler(cache cache.MsgModel)
|
|
|
|
SetCacheHandler(cache cache.MsgModel)
|
|
|
|
SetDiscoveryRegistry(client discoveryregistry.SvcDiscoveryRegistry)
|
|
|
|
SetDiscoveryRegistry(client discoveryregistry.SvcDiscoveryRegistry)
|
|
|
|
|
|
|
|
KickUserConn(client *Client) error
|
|
|
|
UnRegister(c *Client)
|
|
|
|
UnRegister(c *Client)
|
|
|
|
Compressor
|
|
|
|
Compressor
|
|
|
|
Encoder
|
|
|
|
Encoder
|
|
|
@ -145,7 +146,7 @@ func (ws *WsServer) Run() error {
|
|
|
|
case client = <-ws.unregisterChan:
|
|
|
|
case client = <-ws.unregisterChan:
|
|
|
|
ws.unregisterClient(client)
|
|
|
|
ws.unregisterClient(client)
|
|
|
|
case onlineInfo := <-ws.kickHandlerChan:
|
|
|
|
case onlineInfo := <-ws.kickHandlerChan:
|
|
|
|
ws.multiTerminalLoginChecker(onlineInfo)
|
|
|
|
ws.multiTerminalLoginChecker(onlineInfo.clientOK, onlineInfo.oldClients, onlineInfo.newClient)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}()
|
|
|
@ -207,80 +208,77 @@ func getRemoteAdders(client []*Client) string {
|
|
|
|
return ret
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (ws *WsServer) multiTerminalLoginChecker(info *kickHandler) {
|
|
|
|
func (ws *WsServer) KickUserConn(client *Client) error {
|
|
|
|
|
|
|
|
ws.clients.deleteClients(client.UserID, []*Client{client})
|
|
|
|
|
|
|
|
return client.KickOnlineMessage()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (ws *WsServer) multiTerminalLoginChecker(clientOK bool, oldClients []*Client, newClient *Client) {
|
|
|
|
switch config.Config.MultiLoginPolicy {
|
|
|
|
switch config.Config.MultiLoginPolicy {
|
|
|
|
case constant.DefalutNotKick:
|
|
|
|
case constant.DefalutNotKick:
|
|
|
|
case constant.PCAndOther:
|
|
|
|
case constant.PCAndOther:
|
|
|
|
if constant.PlatformIDToClass(info.newClient.PlatformID) == constant.TerminalPC {
|
|
|
|
if constant.PlatformIDToClass(newClient.PlatformID) == constant.TerminalPC {
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fallthrough
|
|
|
|
fallthrough
|
|
|
|
case constant.AllLoginButSameTermKick:
|
|
|
|
case constant.AllLoginButSameTermKick:
|
|
|
|
if info.clientOK {
|
|
|
|
if clientOK {
|
|
|
|
ws.clients.deleteClients(info.newClient.UserID, info.oldClients)
|
|
|
|
ws.clients.deleteClients(newClient.UserID, oldClients)
|
|
|
|
for _, c := range info.oldClients {
|
|
|
|
for _, c := range oldClients {
|
|
|
|
err := c.KickOnlineMessage()
|
|
|
|
err := c.KickOnlineMessage()
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.ZWarn(c.ctx, "KickOnlineMessage", err)
|
|
|
|
log.ZWarn(c.ctx, "KickOnlineMessage", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m, err := ws.cache.GetTokensWithoutError(
|
|
|
|
m, err := ws.cache.GetTokensWithoutError(
|
|
|
|
info.newClient.ctx,
|
|
|
|
newClient.ctx,
|
|
|
|
info.newClient.UserID,
|
|
|
|
newClient.UserID,
|
|
|
|
info.newClient.PlatformID,
|
|
|
|
newClient.PlatformID,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
if err != nil && err != redis.Nil {
|
|
|
|
if err != nil && err != redis.Nil {
|
|
|
|
log.ZWarn(
|
|
|
|
log.ZWarn(
|
|
|
|
info.newClient.ctx,
|
|
|
|
newClient.ctx,
|
|
|
|
"get token from redis err",
|
|
|
|
"get token from redis err",
|
|
|
|
err,
|
|
|
|
err,
|
|
|
|
"userID",
|
|
|
|
"userID",
|
|
|
|
info.newClient.UserID,
|
|
|
|
newClient.UserID,
|
|
|
|
"platformID",
|
|
|
|
"platformID",
|
|
|
|
info.newClient.PlatformID,
|
|
|
|
newClient.PlatformID,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if m == nil {
|
|
|
|
if m == nil {
|
|
|
|
log.ZWarn(
|
|
|
|
log.ZWarn(
|
|
|
|
info.newClient.ctx,
|
|
|
|
newClient.ctx,
|
|
|
|
"m is nil",
|
|
|
|
"m is nil",
|
|
|
|
errors.New("m is nil"),
|
|
|
|
errors.New("m is nil"),
|
|
|
|
"userID",
|
|
|
|
"userID",
|
|
|
|
info.newClient.UserID,
|
|
|
|
newClient.UserID,
|
|
|
|
"platformID",
|
|
|
|
"platformID",
|
|
|
|
info.newClient.PlatformID,
|
|
|
|
newClient.PlatformID,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
log.ZDebug(
|
|
|
|
log.ZDebug(
|
|
|
|
info.newClient.ctx,
|
|
|
|
newClient.ctx,
|
|
|
|
"get token from redis",
|
|
|
|
"get token from redis",
|
|
|
|
"userID",
|
|
|
|
"userID",
|
|
|
|
info.newClient.UserID,
|
|
|
|
newClient.UserID,
|
|
|
|
"platformID",
|
|
|
|
"platformID",
|
|
|
|
info.newClient.PlatformID,
|
|
|
|
newClient.PlatformID,
|
|
|
|
"tokenMap",
|
|
|
|
"tokenMap",
|
|
|
|
m,
|
|
|
|
m,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
for k := range m {
|
|
|
|
for k := range m {
|
|
|
|
if k != info.newClient.ctx.GetToken() {
|
|
|
|
if k != newClient.ctx.GetToken() {
|
|
|
|
m[k] = constant.KickedToken
|
|
|
|
m[k] = constant.KickedToken
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
log.ZDebug(info.newClient.ctx, "set token map is ", "token map", m, "userID", info.newClient.UserID)
|
|
|
|
log.ZDebug(newClient.ctx, "set token map is ", "token map", m, "userID", newClient.UserID)
|
|
|
|
err = ws.cache.SetTokenMapByUidPid(info.newClient.ctx, info.newClient.UserID, info.newClient.PlatformID, m)
|
|
|
|
err = ws.cache.SetTokenMapByUidPid(newClient.ctx, newClient.UserID, newClient.PlatformID, m)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.ZWarn(
|
|
|
|
log.ZWarn(newClient.ctx, "SetTokenMapByUidPid err", err, "userID", newClient.UserID, "platformID", newClient.PlatformID)
|
|
|
|
info.newClient.ctx,
|
|
|
|
|
|
|
|
"SetTokenMapByUidPid err",
|
|
|
|
|
|
|
|
err,
|
|
|
|
|
|
|
|
"userID",
|
|
|
|
|
|
|
|
info.newClient.UserID,
|
|
|
|
|
|
|
|
"platformID",
|
|
|
|
|
|
|
|
info.newClient.PlatformID,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|