diff --git a/robot/base/clientmgr.go b/robot/base/clientmgr.go index ae3cab7..793556b 100644 --- a/robot/base/clientmgr.go +++ b/robot/base/clientmgr.go @@ -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{ sessionPool: make(map[string]*netlib.Session), Running: true, @@ -182,3 +195,19 @@ func (this *ClientMgr) DayChange() { 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 +} diff --git a/robot/base/clock.go b/robot/base/clock.go deleted file mode 100644 index a4cc3a5..0000000 --- a/robot/base/clock.go +++ /dev/null @@ -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) -} diff --git a/robot/base/playermgr.go b/robot/base/playermgr.go index a5f8cfa..cfc1c53 100644 --- a/robot/base/playermgr.go +++ b/robot/base/playermgr.go @@ -2,6 +2,7 @@ package base import ( "math/rand" + "mongo.games.com/game/common" "mongo.games.com/goserver/core/logger" "mongo.games.com/goserver/core/netlib" @@ -11,6 +12,17 @@ import ( 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{ playersMapSnId: make(map[int32]*player_proto.SCPlayerData), playersSession: make(map[int32]*netlib.Session), diff --git a/robot/base/scenemgr.go b/robot/base/scenemgr.go index b8a1164..a354d92 100644 --- a/robot/base/scenemgr.go +++ b/robot/base/scenemgr.go @@ -3,12 +3,28 @@ package base import ( "time" + "mongo.games.com/goserver/core/logger" "mongo.games.com/goserver/core/module" + "mongo.games.com/game/common" server_proto "mongo.games.com/game/protocol/server" "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{ Scenes: make(map[int32]IScene), 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) } +// IsFreeMode 是否是自由桌 func (sm *SceneMgr) IsFreeMode(sceneId int32) bool { if data, exist := sm.sceneDBGameFree[sceneId]; exist { return data.GetFreeMode() == 1 @@ -74,7 +91,3 @@ func (sm *SceneMgr) ModuleName() string { func (sm *SceneMgr) Shutdown() { module.UnregisteModule(sm) } - -func init() { - module.RegisteModule(SceneMgrSingleton, time.Millisecond*100, 0) -} diff --git a/worldsrv/welfmgr.go b/worldsrv/welfmgr.go index 772d847..a0d0a49 100644 --- a/worldsrv/welfmgr.go +++ b/worldsrv/welfmgr.go @@ -1118,7 +1118,7 @@ func (this *WelfareMgr) BlindBoxInfo(p *Player, bid int32) { if cyc == 1 || blindBox.Cycle == model.WelfareOpen { p.WelfData.BlindBoxId = 0 } - } // == 1代表当日循环 + } // == 1代表当日循环 if p.WelfData.BlindBoxId == 0 { // 未领取过发随机Date idx := bid