```
fix(controller): 优化数据发送逻辑,避免并发写冲突 将原先直接操作连接上下文并加锁的写法, 改为通过 player 实例封装的 SendPack 方法发送数据, 提高代码可维护性和安全性。 同时调整了 service 层踢出玩家时锁的获取顺序, 确保在关闭连接前
This commit is contained in:
@@ -185,21 +185,17 @@ func Recv(c gnet.Conn, data player.TomeeHeader) {
|
||||
return
|
||||
|
||||
}
|
||||
|
||||
t := player.GetPlayer(c, data.UserID)
|
||||
if ok && aa != 0 { //这里实现回复错误包
|
||||
|
||||
cool.Loger.Error(context.Background(), aa.Code())
|
||||
c.Context().(*player.ClientData).Mu.Lock()
|
||||
c.Write(data.Pack(nil))
|
||||
c.Context().(*player.ClientData).Mu.Unlock()
|
||||
t.SendPack(data.Pack(nil))
|
||||
|
||||
return
|
||||
|
||||
}
|
||||
|
||||
data.Version = "7"
|
||||
//glog.Debug(context.Background(), data.CMD, "回复数据")
|
||||
c.Context().(*player.ClientData).Mu.Lock()
|
||||
c.Write(data.Pack(ret[0].Interface()))
|
||||
c.Context().(*player.ClientData).Mu.Unlock()
|
||||
t.SendPack(data.Pack(ret[0].Interface()))
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user