From 7a3b56955ce6073a065b7f93a1a63ad362c21658 Mon Sep 17 00:00:00 2001 From: Gordon <1432970085@qq.com> Date: Thu, 25 Nov 2021 16:37:36 +0800 Subject: [PATCH] multi terminal kick eachOther --- internal/msg_gateway/gate/ws_server.go | 6 +++++- pkg/common/db/redisModel.go | 2 +- pkg/common/token_verify/jwt_token.go | 2 ++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/internal/msg_gateway/gate/ws_server.go b/internal/msg_gateway/gate/ws_server.go index 29c78813a..445c9d806 100644 --- a/internal/msg_gateway/gate/ws_server.go +++ b/internal/msg_gateway/gate/ws_server.go @@ -95,8 +95,9 @@ func (ws *WServer) MultiTerminalLoginChecker(uid string, platformID int32, newCo switch config.Config.MultiLoginPolicy { case constant.AllLoginButSameTermKick: if oldConn, ok := ws.wsUserToConn[genMapKey(uid, platformID)]; ok { + log.NewDebug("", uid, platformID, "kick old conn") ws.sendKickMsg(oldConn, newConn) - m, err := db.DB.GetTokenMapByUidPid(uid, utils.Int32ToString(platformID)) + m, err := db.DB.GetTokenMapByUidPid(uid, constant.PlatformIDToName(platformID)) if err != nil { log.NewError("", "get token from redis err", err.Error()) return @@ -110,6 +111,7 @@ func (ws *WServer) MultiTerminalLoginChecker(uid string, platformID int32, newCo m[k] = constant.KickedToken } } + log.NewDebug("get map is ", m) err = db.DB.SetTokenMapByUidPid(uid, platformID, m) if err != nil { log.NewError("", "SetTokenMapByUidPid err", err.Error()) @@ -120,6 +122,8 @@ func (ws *WServer) MultiTerminalLoginChecker(uid string, platformID int32, newCo if err != nil { log.NewError("", "conn close err", err.Error()) } + } else { + log.NewDebug("no other conn", ws.wsUserToConn) } case constant.SingleTerminalLogin: diff --git a/pkg/common/db/redisModel.go b/pkg/common/db/redisModel.go index 94914a46a..6e0848e81 100644 --- a/pkg/common/db/redisModel.go +++ b/pkg/common/db/redisModel.go @@ -101,7 +101,7 @@ func (d *DataBases) GetTokenMapByUidPid(userID, platformID string) (m map[string return nil, e } else { m = make(map[string]int) - _ = utils.JsonStringToStruct(s, m) + _ = utils.JsonStringToStruct(s, &m) return m, nil } } diff --git a/pkg/common/token_verify/jwt_token.go b/pkg/common/token_verify/jwt_token.go index 86271e352..2f5f32c23 100644 --- a/pkg/common/token_verify/jwt_token.go +++ b/pkg/common/token_verify/jwt_token.go @@ -108,6 +108,8 @@ func ParseToken(tokensString string) (claims *Claims, err error) { return nil, &constant.ErrTokenInvalid case constant.ExpiredToken: return nil, &constant.ErrTokenExpired + default: + return nil, &constant.ErrTokenUnknown } } return nil, err