机器人添加状态日志

This commit is contained in:
sk 2024-12-11 17:17:23 +08:00
parent 13e03f7428
commit acd3f4f676
5 changed files with 59 additions and 95 deletions

View File

@ -27,6 +27,19 @@ import (
登录及机器人账号更新 登录及机器人账号更新
*/ */
func init() {
common.RegisterClockFunc(&common.ClockFunc{
OnHourTimerFunc: func() {
ClientMgrSingleton.HourChange()
logger.Logger.Infof("client state: %+v", ClientMgrSingleton.GetState())
},
OnDayTimerFunc: func() {
ClientMgrSingleton.DayChange()
},
})
}
var ClientMgrSingleton = &ClientMgr{ var ClientMgrSingleton = &ClientMgr{
sessionPool: make(map[string]*netlib.Session), sessionPool: make(map[string]*netlib.Session),
Running: true, Running: true,
@ -182,3 +195,19 @@ func (this *ClientMgr) DayChange() {
this.CycleTimeEvent[timePoint] = eventArr this.CycleTimeEvent[timePoint] = eventArr
} }
} }
type ClientState struct {
SessionNum int
Event map[int]int
}
func (this *ClientMgr) GetState() *ClientState {
ret := &ClientState{
SessionNum: len(this.sessionPool),
Event: make(map[int]int),
}
for k, v := range this.CycleTimeEvent {
ret.Event[k] = len(v)
}
return ret
}

View File

@ -1,90 +0,0 @@
package base
import (
"time"
"mongo.games.com/goserver/core/module"
)
/*
计时器
*/
var ClockMgrSingleton = &ClockMgr{
LastHour: -1,
LastDay: -1,
}
type ClockMgr struct {
LastTime time.Time
LastMonth time.Month
LastWeek int
LastDay int
LastHour int
LastMini int
LastSec int
}
func (this *ClockMgr) ModuleName() string {
return "ClockMgr"
}
func (this *ClockMgr) Init() {
tNow := time.Now().Local()
this.LastTime = tNow
_, this.LastMonth, this.LastDay = tNow.Date()
this.LastHour, this.LastMini, this.LastSec = tNow.Hour(), tNow.Minute(), tNow.Second()
_, this.LastWeek = tNow.ISOWeek()
}
func (this *ClockMgr) Update() {
tNow := time.Now().Local()
sec := tNow.Second()
if sec != this.LastSec {
this.LastSec = sec
// 秒
PlayerMgrSingleton.OnSecondTimer()
min := tNow.Minute()
if min != this.LastMini {
this.LastMini = min
// 分
PlayerMgrSingleton.OnMiniTimer()
hour := tNow.Hour()
if hour != this.LastHour {
// 时
ClientMgrSingleton.HourChange()
this.LastHour = hour
day := tNow.Day()
if day != this.LastDay {
// 天
ClientMgrSingleton.DayChange()
this.LastDay = day
_, week := tNow.ISOWeek()
if week != this.LastWeek {
// 周
this.LastWeek = week
}
month := tNow.Month()
if month != this.LastMonth {
// 月
this.LastMonth = month
}
}
}
}
}
}
func (this *ClockMgr) Shutdown() {
module.UnregisteModule(this)
}
func init() {
module.RegisteModule(ClockMgrSingleton, time.Millisecond*500, 0)
}

View File

@ -2,6 +2,7 @@ package base
import ( import (
"math/rand" "math/rand"
"mongo.games.com/game/common"
"mongo.games.com/goserver/core/logger" "mongo.games.com/goserver/core/logger"
"mongo.games.com/goserver/core/netlib" "mongo.games.com/goserver/core/netlib"
@ -11,6 +12,17 @@ import (
player_proto "mongo.games.com/game/protocol/player" player_proto "mongo.games.com/game/protocol/player"
) )
func init() {
common.RegisterClockFunc(&common.ClockFunc{
OnSecTimerFunc: func() {
PlayerMgrSingleton.OnSecondTimer()
},
OnMiniTimerFunc: func() {
PlayerMgrSingleton.OnMiniTimer()
},
})
}
var PlayerMgrSingleton = &PlayerMgr{ var PlayerMgrSingleton = &PlayerMgr{
playersMapSnId: make(map[int32]*player_proto.SCPlayerData), playersMapSnId: make(map[int32]*player_proto.SCPlayerData),
playersSession: make(map[int32]*netlib.Session), playersSession: make(map[int32]*netlib.Session),

View File

@ -3,12 +3,28 @@ package base
import ( import (
"time" "time"
"mongo.games.com/goserver/core/logger"
"mongo.games.com/goserver/core/module" "mongo.games.com/goserver/core/module"
"mongo.games.com/game/common"
server_proto "mongo.games.com/game/protocol/server" server_proto "mongo.games.com/game/protocol/server"
"mongo.games.com/game/srvdata" "mongo.games.com/game/srvdata"
) )
func init() {
module.RegisteModule(SceneMgrSingleton, time.Millisecond*100, 0)
common.RegisterClockFunc(&common.ClockFunc{
OnHourTimerFunc: func() {
sceneState := map[int32]int{}
for _, v := range SceneMgrSingleton.Scenes {
sceneState[v.GetGameId()]++
}
logger.Logger.Infof("sceneState: %v", sceneState)
},
})
}
var SceneMgrSingleton = &SceneMgr{ var SceneMgrSingleton = &SceneMgr{
Scenes: make(map[int32]IScene), Scenes: make(map[int32]IScene),
sceneDBGameFree: make(map[int32]*server_proto.DB_GameFree), sceneDBGameFree: make(map[int32]*server_proto.DB_GameFree),
@ -47,6 +63,7 @@ func (sm *SceneMgr) GetSceneDBGameFree(sceneId, gamefreeId int32) *server_proto.
return srvdata.PBDB_GameFreeMgr.GetData(gamefreeId) return srvdata.PBDB_GameFreeMgr.GetData(gamefreeId)
} }
// IsFreeMode 是否是自由桌
func (sm *SceneMgr) IsFreeMode(sceneId int32) bool { func (sm *SceneMgr) IsFreeMode(sceneId int32) bool {
if data, exist := sm.sceneDBGameFree[sceneId]; exist { if data, exist := sm.sceneDBGameFree[sceneId]; exist {
return data.GetFreeMode() == 1 return data.GetFreeMode() == 1
@ -74,7 +91,3 @@ func (sm *SceneMgr) ModuleName() string {
func (sm *SceneMgr) Shutdown() { func (sm *SceneMgr) Shutdown() {
module.UnregisteModule(sm) module.UnregisteModule(sm)
} }
func init() {
module.RegisteModule(SceneMgrSingleton, time.Millisecond*100, 0)
}