diff --git a/worldsrv/loginstatemgr.go b/worldsrv/loginstatemgr.go index 4c52f6e..ab7b54f 100644 --- a/worldsrv/loginstatemgr.go +++ b/worldsrv/loginstatemgr.go @@ -2,15 +2,17 @@ package main import ( "fmt" - "mongo.games.com/goserver/core/logger" "time" - "mongo.games.com/game/common" - "mongo.games.com/game/model" "mongo.games.com/goserver/core/basic" + "mongo.games.com/goserver/core/logger" "mongo.games.com/goserver/core/module" "mongo.games.com/goserver/core/netlib" "mongo.games.com/goserver/core/task" + + "mongo.games.com/game/common" + "mongo.games.com/game/model" + "mongo.games.com/game/worldsrv/internal" ) const ( @@ -236,6 +238,7 @@ func (this *LoginStateMgr) LogoutAllBySession(session *netlib.Session) { p := PlayerMgrSington.GetOnlinePlayer(sid) if p != nil { p.DropLine() + internal.FirePlayerDropLine[*Player, *Scene](p) } } } diff --git a/worldsrv/player.go b/worldsrv/player.go index 7a46470..d71d73d 100644 --- a/worldsrv/player.go +++ b/worldsrv/player.go @@ -86,6 +86,7 @@ type Player struct { changeIconTime time.Time //上次修改头像时间 enterts time.Time //进入时间 lastChangeScene time.Time //上次换桌时间 + dropTime time.Time // 掉线时间 isAudience bool //是否是观众 customerToken string //客服会话token isDelete bool //是否已删档用户 @@ -1155,6 +1156,7 @@ func (this *Player) Kick(reason int32) { LoginStateMgrSington.LogoutBySid(this.sid) this.DropLine() + internal.FirePlayerDropLine[*Player, *Scene](this) } TournamentMgr.ForceQuit(this.Platform, this.SnId) } @@ -1632,10 +1634,19 @@ func (this *Player) OnSecTimer() { } func (this *Player) OnMiniTimer() { - TaskSubjectSingleton.Touch(common.TaskTypeOnlineTs, &TaskData{ - SnId: this.SnId, - Num: 60, - }) + if this.IsOnLine() { + TaskSubjectSingleton.Touch(common.TaskTypeOnlineTs, &TaskData{ + SnId: this.SnId, + Num: 60, + }) + } + // 长时间掉线又没有删除缓存 + if !this.dropTime.IsZero() && time.Now().Sub(this.dropTime).Minutes() > 20 { + logger.Logger.Errorf("清除缓存异常玩家 snid:%v dirty:%v lastLogoutTime:%v lastGameId:%v", this.SnId, this.dirty, this.LastLogoutTime, this.LastGameId) + if this.scene != nil { + logger.Logger.Errorf("清除缓存异常玩家 sceneId:%v", this.scene.sceneId) + } + } } func (this *Player) OnHourTimer() { @@ -3884,10 +3895,12 @@ func (this *Player) SCDataConfig(tp int) { func init() { internal.RegisterPlayerListenerFunc(&internal.PlayerListenerFunc[*Player, *Scene]{ - ClockFunc: common.ClockFunc{}, - OnPlayerLoginedFunc: nil, - OnPlayerLogoutedFunc: nil, - OnPlayerDropLineFunc: nil, + ClockFunc: common.ClockFunc{}, + OnPlayerLoginedFunc: nil, + OnPlayerLogoutedFunc: nil, + OnPlayerDropLineFunc: func(p *Player) { + p.dropTime = time.Now() + }, OnPlayerReholdFunc: nil, OnPlayerEnterSceneBeforeFunc: nil, OnPlayerEnterSceneAfterFunc: nil, diff --git a/worldsrv/scene.go b/worldsrv/scene.go index 3331464..d28a99b 100644 --- a/worldsrv/scene.go +++ b/worldsrv/scene.go @@ -21,6 +21,7 @@ import ( serverproto "mongo.games.com/game/protocol/server" webapiproto "mongo.games.com/game/protocol/webapi" "mongo.games.com/game/srvdata" + "mongo.games.com/game/worldsrv/internal" ) type PlayerGameCtx struct { @@ -193,6 +194,9 @@ func (this *Scene) PlayerEnter(p *Player, pos int, ischangeroom bool) bool { } } + internal.FirePlayerEnterSceneBefore(p, this) + defer internal.FirePlayerEnterSceneAfter(p, this) + // 非百人,设置座位 if !this.IsHundredScene() { if pos != -1 { @@ -515,6 +519,9 @@ func (this *Scene) lastScene(p *Player) { } func (this *Scene) DelPlayer(p *Player) bool { + internal.FirePlayerLeaveSceneBefore(p, this) + defer internal.FirePlayerLeaveSceneAfter(p, this) + if p.scene != this { roomId := 0 if p.scene != nil {