diff --git a/common/socket/ServerEvent.go b/common/socket/ServerEvent.go index 5c1686f0..92c16757 100644 --- a/common/socket/ServerEvent.go +++ b/common/socket/ServerEvent.go @@ -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 diff --git a/logic/service/player/save.go b/logic/service/player/save.go index ca32dc0d..3ceadf6d 100644 --- a/logic/service/player/save.go +++ b/logic/service/player/save.go @@ -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() {