优化心跳代码

This commit is contained in:
liwei1dao 2023-01-29 15:02:51 +08:00
parent 705b16a362
commit c7d421e421

View File

@ -78,6 +78,17 @@ locp:
var code pb.ErrorCode
code, err = this.secAuth(msg)
if err == nil {
if msg.MainType == string(comm.ModuleGate) { //心跳消息
data, _ := anypb.New(&pb.GatewayHeartbeatResp{
Timestamp: configure.Now().Unix(),
})
this.WriteMsg(&pb.UserMessage{
MainType: string(comm.ModuleGate),
SubType: "heartbeat",
Data: data,
})
continue
}
if err := this.messageDistribution(msg); err != nil {
go this.Close()
break locp
@ -150,17 +161,6 @@ func (this *Agent) decodeUserData(msg *pb.UserMessage) (code pb.ErrorCode, err e
this.gateway.Errorf("last timestamp:%v more than 30s", timestamp)
return pb.ErrorCode_TimestampTimeout, fmt.Errorf("sec key expire")
}
if msg.MainType == string(comm.ModuleGate) { //心跳消息
data, _ := anypb.New(&pb.GatewayHeartbeatResp{
Timestamp: configure.Now().Unix(),
})
this.WriteMsg(&pb.UserMessage{
MainType: string(comm.ModuleGate),
SubType: "heartbeat",
Data: data,
})
return
}
//只有login的时候才需要设置Data
if msg.MainType == string(comm.ModuleUser) && msg.SubType == "login" {