账号多终端登录提示

This commit is contained in:
wh_zcy 2022-11-10 13:47:03 +08:00
parent e6bcad1090
commit 2d46852079
4 changed files with 389 additions and 321 deletions

View File

@ -23,7 +23,7 @@ const (
)
const (
RDS_SESSION = "online"
RDS_SESSION = ""
)
//ERR

View File

@ -70,13 +70,18 @@ func (this *apiComp) Login(session comm.IUserSession, req *pb.UserLoginReq) (cod
go this.module.ModuleTask.InitTaskAll(user.Uid)
isNewUser = true
} else {
// 玩家是否已在线
if cu := this.module.modelSession.getUserSession(user.Uid); cu != nil {
if cu.SessionId != "" {
code = pb.ErrorCode_UserLogined
return
// 通知先登录的玩家并解绑
this.module.SendMsgToUser(string(this.module.GetType()), "othertermlogin", &pb.UserOtherTermLoginPush{Uid: cu.Uid}, cu.Uid)
if isession, ok := this.module.ModuleBase.GetUserSession(cu.Uid); ok {
if err := isession.UnBind(); err != nil {
this.module.Errorf("解绑失败 uid:%v sessionId:%v err:%v", cu.Uid, cu.SessionId, err)
}
}
}
}
}
//bind user
@ -88,7 +93,7 @@ func (this *apiComp) Login(session comm.IUserSession, req *pb.UserLoginReq) (cod
}
//缓存user session
err = this.module.modelSession.setUserSession(user.Uid, session)
err = this.module.modelSession.addUserSession(user.Uid, session)
if err != nil {
this.module.Errorf("set user session err:%v", err)
code = pb.ErrorCode_UserSessionNobeing

View File

@ -44,7 +44,7 @@ func (this *ModelSession) getUserSession(uid string) (user *pb.CacheUser) {
}
//设置用户session
func (this *ModelSession) setUserSession(uid string, session comm.IUserSession) (err error) {
func (this *ModelSession) addUserSession(uid string, session comm.IUserSession) (err error) {
if err = this.AddList(comm.RDS_SESSION, uid, map[string]interface{}{
"uid": uid,
"sessionId": session.GetSessionId(),

File diff suppressed because it is too large Load Diff