This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user