1
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful

This commit is contained in:
昔念
2026-04-25 02:28:50 +08:00
parent 1efc8517e1
commit 9452e36782
2 changed files with 10 additions and 4 deletions

View File

@@ -78,7 +78,7 @@ func (s *Server) OnClose(c gnet.Conn, err error) (action gnet.Action) {
if v != nil {
v.Close()
if v.Player != nil {
v.Player.Save() //保存玩家数据
v.Player.SaveOnDisconnect() //保存玩家数据
}
}
return

View File

@@ -23,9 +23,14 @@ func (p *Player) Save() {
defer cancel()
cool.CacheManager.Remove(cacheCtx, fmt.Sprintf("player:%d", p.Info.UserID))
newtime := time.Now().Unix()
p.Info.TimeToday = p.Info.TimeToday + newtime - int64(p.Logintime) //保存电池时间
// p.Info.FightTime = p.Info.FightTime + (newtime - int64(p.Logintime))
p.Info.OnlineTime = p.Info.OnlineTime + (newtime-int64(p.Logintime))/60 //每次退出时候保存已经在线的分钟数
if p.Logintime > 0 {
onlineSeconds := newtime - int64(p.Logintime)
if onlineSeconds > 0 {
p.Info.TimeToday += onlineSeconds //保存电池时间
// p.Info.FightTime += onlineSeconds
p.Info.OnlineTime += onlineSeconds / 60 //每次退出时候保存已经在线的分钟数
}
}
if p.FightC != nil {
@@ -63,6 +68,7 @@ func (p *Player) Save() {
Mainplayer.Delete(p.Info.UserID)
share.ShareManager.DeleteUserOnline(p.Info.UserID) //设置用户登录服务器
p.Logintime = 0
}
func (p *Player) SaveOnDisconnect() {