上传挤号代码优化

This commit is contained in:
liwei1dao 2023-09-01 21:50:31 +08:00
parent 3d5290fe45
commit f0be3be2bf
5 changed files with 27 additions and 15 deletions

View File

@ -70,7 +70,8 @@ type IUserSession interface {
UnBind() (err error)
SendMsg(mainType, subType string, msg proto.Message) (err error)
Polls() []*pb.UserMessage
Push() (err error) //警告 api传递过来的会话禁用此接口
Push() (err error) //警告 api传递过来的会话禁用此接口
SyncPush() (err error) //警告 api传递过来的会话禁用此接口 同步
Close() (err error)
Reset()
Clone() (session IUserSession) //克隆

View File

@ -126,7 +126,7 @@ func (this *UserSession) SendMsg(mainType, subType string, msg proto.Message) (e
// 关闭用户连接对象
func (this *UserSession) Close() (err error) {
reply := &pb.RPCMessageReply{}
if err := this.service.RpcCall(context.Background(), fmt.Sprintf("%s/%s", Service_Gateway, this.GatewayServiceId), string(Rpc_GatewayAgentSendMsg), &pb.AgentCloseeReq{
if err := this.service.RpcCall(context.Background(), fmt.Sprintf("%s/%s", Service_Gateway, this.GatewayServiceId), string(Rpc_GatewayAgentClose), &pb.AgentCloseeReq{
UserSessionId: this.SessionId,
}, reply); err != nil {
log.Errorf("Close UserSession:%s UserId:%s err:%v", this.SessionId, this.UserId, err)
@ -156,6 +156,20 @@ func (this *UserSession) Push() (err error) {
return
}
func (this *UserSession) SyncPush() (err error) {
// reply := &pb.RPCMessageReply{}
if len(this.msgqueue) > 0 {
if err = this.service.AcrossClusterRpcCall(context.Background(), this.ServiceTag, fmt.Sprintf("%s/%s", Service_Gateway, this.GatewayServiceId), string(Rpc_GatewayAgentSendMsg), &pb.AgentSendMessageReq{
UserSessionId: this.SessionId,
Reply: this.msgqueue,
}, &pb.RPCMessageReply{}); err != nil {
log.Errorf("SendMsgToUsers:%v err:%v", this, err)
}
}
this.msgqueue = this.msgqueue[:0]
return
}
// 克隆
func (this *UserSession) Clone() (session IUserSession) {
session = this.service.GetUserSession()

View File

@ -199,6 +199,7 @@ func (this *AgentMgrComp) SendMsgToAllAgent(ctx context.Context, args *pb.BroadC
func (this *AgentMgrComp) CloseAgent(ctx context.Context, args *pb.AgentCloseeReq, reply *pb.RPCMessageReply) error {
if a, ok := this.agents.Load(args.UserSessionId); ok {
a.(IAgent).Close()
this.agents.Delete(args.UserSessionId)
} else {
reply.ErrorData = &pb.ErrorData{
Code: pb.ErrorCode_UserSessionNobeing,

View File

@ -198,7 +198,7 @@ func (this *ModuleBase) SendMsgToUser(mainType, subType string, msg proto.Messag
session := this.scomp.GetUserSession(user)
session.SendMsg(mainType, subType, msg)
err = session.Push()
this.scomp.PutUserSession(session)
this.PutUserSession(session)
return
}

View File

@ -70,16 +70,11 @@ func (this *apiComp) Login(session comm.IUserSession, req *pb.UserLoginReq) (err
isNewUser = true
} else {
// 玩家是否已在线
if cu := this.module.modelSession.getUserSession(user.Uid); cu != nil {
if cu.SessionId != "" {
// 通知先登录的玩家并解绑
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)
}
}
}
if isession, ok := this.module.ModuleBase.GetUserSession(user.Uid); ok {
isession.SendMsg(string(this.module.GetType()), "othertermlogin", &pb.UserOtherTermLoginPush{Uid: user.Uid})
isession.SyncPush()
isession.UnBind()
this.module.PutUserSession(isession)
}
}
@ -87,8 +82,9 @@ func (this *apiComp) Login(session comm.IUserSession, req *pb.UserLoginReq) (err
err = session.Bind(user.Uid, this.service.GetId())
if err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_BindUser,
Title: pb.ErrorCode_BindUser.ToString(),
Code: pb.ErrorCode_BindUser,
Title: pb.ErrorCode_BindUser.ToString(),
Message: err.Error(),
}
return
}