refactor(fight): 优化战斗逻辑代码结构,清理冗余代码

This commit is contained in:
1
2025-11-05 22:17:03 +00:00
parent 5092186b4e
commit bd43c75dce
2 changed files with 19 additions and 13 deletions

View File

@@ -48,8 +48,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, _ := c.Context().(*player.ClientData)
v.LF.Close()
if v.Player != nil {
v.SaveL.Do(func() { //使用保存锁,确保在踢人和掉线的时候只保存一次
//cool.Loger.Info(context.TODO(), "准备保存", v.Player.Info.UserID)
@@ -140,7 +142,8 @@ func (s *Server) OnTraffic(c gnet.Conn) (action gnet.Action) {
//client := conn.RemoteAddr().String()
s.workerPool.Submit(func() { //TODO 这里可能存在顺序执行问题,待修复
for _, msg := range messages {
t.OnEvent(msg.Payload)
t.LF.Producer().Write(msg.Payload)
//t.OnEvent(msg.Payload)
}
})
@@ -164,8 +167,8 @@ func (s *Server) handleTcp(conn gnet.Conn) (action gnet.Action) {
}
s.workerPool.Submit(func() { //TODO 这里可能存在顺序执行问题,待修复
conn.Context().(*player.ClientData).OnEvent(data)
//conn.Context().(*player.ClientData).OnEvent(data)
conn.Context().(*player.ClientData).LF.Producer().Write(data)
})
if conn.InboundBuffered() > 0 {