feat(player): 添加玩家断开连接时的安全保存机制

- 实现 SaveOnDisconnect 方法,确保玩家数据在断开连接时安全保存
- 添加并发控制防止重复保存操作,使用互斥锁和完成通道确保一次保存
- 在 socket 关闭事件中改为异步调用 SaveOnDisconnect 避免阻塞
- 添加 panic 恢复机制保护保存过程中的异常情况

refactor(login): 优化登录时的踢人逻辑和超时处理
This commit is contained in:
昔念
2026-04-05 11:14:25 +08:00
parent 37cd641942
commit c3da3162ee
6 changed files with 155 additions and 27 deletions

View File

@@ -4,6 +4,7 @@ import (
"blazing/cool"
"blazing/logic/service/fight/pvp"
"blazing/logic/service/fight/pvpwire"
"context"
"fmt"
"time"

View File

@@ -58,7 +58,7 @@ func (s *Server) OnClose(c gnet.Conn, err error) (action gnet.Action) {
if t.Player != nil {
if t.Player.Info != nil {
cool.Logger.Error(context.TODO(), "OnClose 错误:", cool.Config.ServerInfo.OnlineID, t.Player.Info.UserID, err)
t.Player.Service.Info.Save(*t.Player.Info)
go t.Player.SaveOnDisconnect()
}
}
@@ -89,7 +89,7 @@ func (s *Server) OnClose(c gnet.Conn, err error) (action gnet.Action) {
// v.LF.Close()
//close(v.MsgChan)
if v.Player != nil {
v.Player.Save() //保存玩家数据
go v.Player.SaveOnDisconnect() //保存玩家数据
}