修改底层

This commit is contained in:
1
2025-10-27 09:36:49 +00:00
parent 225aff42c5
commit 448943ca75
8 changed files with 223 additions and 129 deletions

View File

@@ -51,9 +51,10 @@ func (s *Server) OnClose(c gnet.Conn, _ error) (action gnet.Action) {
}()
atomic.AddInt64(&s.connected, -1)
//logging.Infof("conn[%v] disconnected", c.RemoteAddr().String())
v, ok := c.Context().(*player.ClientData)
v, _ := c.Context().(*player.ClientData)
v.Lf.Close() //关闭lockfree
if ok && v.Player != nil {
if v.Player != nil {
//cool.Loger.Info(context.TODO(), "准备保存", v.Player.Info.UserID)
v.Player.Save() //保存玩家数据
//cool.Loger.Info(context.TODO(), "保存完成", v.Player.Info.UserID)
@@ -139,9 +140,15 @@ func (s *Server) OnTraffic(c gnet.Conn) (action gnet.Action) {
}
for _, msg := range messages {
t := c.Context().(*player.ClientData)
//client := conn.RemoteAddr().String()
_ = s.workerPool.Submit(func() {
s.handler.Handle(c, msg.Payload)
_ = s.workerPool.Submit(func() { //TODO 这里可能存在顺序执行问题,待修复
t.Lf.Producer().Write(&player.RecvData{
Conn: c,
Data: msg.Payload,
})
})
}
@@ -174,11 +181,15 @@ func (s *Server) handleTcp(conn gnet.Conn) (action gnet.Action) {
}
if data != nil {
//client := conn.RemoteAddr().String()
//cool.Loger.Debug(context.Background(), "数据", hex.EncodeToString(data))
t := conn.Context().(*player.ClientData)
_ = s.workerPool.Submit(func() { //TODO 这里可能存在顺序执行问题,待修复
//todo 这里待实现注入player实体
s.handler.Handle(conn, data)
t.Lf.Producer().Write(&player.RecvData{
Conn: conn,
Data: data,
})
})
}