代码优化

This commit is contained in:
sk 2024-08-30 18:52:11 +08:00
parent 89bdfac420
commit b7d4efb7a6
18 changed files with 108 additions and 170 deletions

View File

@ -1,27 +1,26 @@
package main package common
import ( import (
"time" "time"
"mongo.games.com/game/common"
"mongo.games.com/goserver/core/module" "mongo.games.com/goserver/core/module"
) )
var ClockMgrSington = &ClockMgr{ var ClockMgrSingleton = &ClockMgr{
LastHour: -1, LastHour: -1,
LastDay: -1, LastDay: -1,
Notifying: false, Notifying: false,
} }
const ( const (
CLOCK_EVENT_SECOND int = iota ClockEventSecond int = iota
CLOCK_EVENT_MINUTE ClockEventMinute
CLOCK_EVENT_HOUR ClockEventHour
CLOCK_EVENT_DAY ClockEventDay
CLOCK_EVENT_WEEK ClockEventWeek
CLOCK_EVENT_MONTH ClockEventMonth
CLOCK_EVENT_SHUTDOWN ClockEventShutdown
CLOCK_EVENT_MAX ClockEventMax
) )
type ClockSinker interface { type ClockSinker interface {
@ -38,7 +37,7 @@ type ClockSinker interface {
type BaseClockSinker struct { type BaseClockSinker struct {
} }
func (s *BaseClockSinker) InterestClockEvent() int { return (1 << CLOCK_EVENT_MAX) - 1 } func (s *BaseClockSinker) InterestClockEvent() int { return (1 << ClockEventMax) - 1 }
func (s *BaseClockSinker) OnSecTimer() {} func (s *BaseClockSinker) OnSecTimer() {}
func (s *BaseClockSinker) OnMiniTimer() {} func (s *BaseClockSinker) OnMiniTimer() {}
func (s *BaseClockSinker) OnHourTimer() {} func (s *BaseClockSinker) OnHourTimer() {}
@ -48,7 +47,7 @@ func (s *BaseClockSinker) OnMonthTimer() {}
func (s *BaseClockSinker) OnShutdown() {} func (s *BaseClockSinker) OnShutdown() {}
type ClockMgr struct { type ClockMgr struct {
sinkers [CLOCK_EVENT_MAX][]ClockSinker sinkers [ClockEventMax][]ClockSinker
LastTickTime time.Time LastTickTime time.Time
LastMonth time.Month LastMonth time.Month
LastWeek int LastWeek int
@ -60,9 +59,9 @@ type ClockMgr struct {
LastFiveMin int LastFiveMin int
} }
func (this *ClockMgr) RegisteSinker(sinker ClockSinker) { func (this *ClockMgr) RegisterSinker(sinker ClockSinker) {
interest := sinker.InterestClockEvent() interest := sinker.InterestClockEvent()
for i := 0; i < CLOCK_EVENT_MAX; i++ { for i := 0; i < ClockEventMax; i++ {
if (1<<i)&interest != 0 { if (1<<i)&interest != 0 {
found := false found := false
ss := this.sinkers[i] ss := this.sinkers[i]
@ -115,7 +114,7 @@ func (this *ClockMgr) Update() {
this.LastDay = day this.LastDay = day
this.fireDayEvent() this.fireDayEvent()
week := common.GetWeekStartTs(tNow.Unix()) week := GetWeekStartTs(tNow.Unix())
if week != int64(this.LastWeek) { if week != int64(this.LastWeek) {
this.LastWeek = int(week) this.LastWeek = int(week)
this.fireWeekEvent() this.fireWeekEvent()
@ -138,43 +137,43 @@ func (this *ClockMgr) Shutdown() {
} }
func (this *ClockMgr) fireSecondEvent() { func (this *ClockMgr) fireSecondEvent() {
for _, s := range this.sinkers[CLOCK_EVENT_SECOND] { for _, s := range this.sinkers[ClockEventSecond] {
s.OnSecTimer() s.OnSecTimer()
} }
} }
func (this *ClockMgr) fireMinuteEvent() { func (this *ClockMgr) fireMinuteEvent() {
for _, s := range this.sinkers[CLOCK_EVENT_MINUTE] { for _, s := range this.sinkers[ClockEventMinute] {
s.OnMiniTimer() s.OnMiniTimer()
} }
} }
func (this *ClockMgr) fireHourEvent() { func (this *ClockMgr) fireHourEvent() {
for _, s := range this.sinkers[CLOCK_EVENT_HOUR] { for _, s := range this.sinkers[ClockEventHour] {
s.OnHourTimer() s.OnHourTimer()
} }
} }
func (this *ClockMgr) fireDayEvent() { func (this *ClockMgr) fireDayEvent() {
for _, s := range this.sinkers[CLOCK_EVENT_DAY] { for _, s := range this.sinkers[ClockEventDay] {
s.OnDayTimer() s.OnDayTimer()
} }
} }
func (this *ClockMgr) fireWeekEvent() { func (this *ClockMgr) fireWeekEvent() {
for _, s := range this.sinkers[CLOCK_EVENT_WEEK] { for _, s := range this.sinkers[ClockEventWeek] {
s.OnWeekTimer() s.OnWeekTimer()
} }
} }
func (this *ClockMgr) fireMonthEvent() { func (this *ClockMgr) fireMonthEvent() {
for _, s := range this.sinkers[CLOCK_EVENT_MONTH] { for _, s := range this.sinkers[ClockEventMonth] {
s.OnMonthTimer() s.OnMonthTimer()
} }
} }
func (this *ClockMgr) fireShutdownEvent() { func (this *ClockMgr) fireShutdownEvent() {
for _, s := range this.sinkers[CLOCK_EVENT_SHUTDOWN] { for _, s := range this.sinkers[ClockEventShutdown] {
s.OnShutdown() s.OnShutdown()
} }
} }
@ -184,5 +183,5 @@ func (this *ClockMgr) GetLast() (int, int, int, int, int, int) {
} }
func init() { func init() {
module.RegisteModule(ClockMgrSington, time.Millisecond*500, 0) module.RegisteModule(ClockMgrSingleton, time.Millisecond*500, 0)
} }

View File

@ -38,19 +38,19 @@ func HandleWGBuyRecTimeItem(session *netlib.Session, packetId int, data interfac
return nil return nil
} }
func HandleWGPlayerLeave(session *netlib.Session, packetId int, data interface{}) error { //func HandleWGPlayerLeave(session *netlib.Session, packetId int, data interface{}) error {
logger.Logger.Trace("receive WGPlayerLeaveGame") // logger.Logger.Trace("receive WGPlayerLeaveGame")
if msg, ok := data.(*server.WGPlayerLeave); ok { // if msg, ok := data.(*server.WGPlayerLeave); ok {
p := base.PlayerMgrSington.GetPlayerBySnId(msg.GetSnId()) // p := base.PlayerMgrSington.GetPlayerBySnId(msg.GetSnId())
if p != nil { // if p != nil {
scene := p.GetScene() // scene := p.GetScene()
if scene != nil { // if scene != nil {
scene.PlayerLeave(p, common.PlayerLeaveReason_DropLine, false) // scene.PlayerLeave(p, common.PlayerLeaveReason_DropLine, false)
} // }
} // }
} // }
return nil // return nil
} //}
//func HandlePlayerChangeItems(session *netlib.Session, packetId int, data interface{}) error { //func HandlePlayerChangeItems(session *netlib.Session, packetId int, data interface{}) error {
// logger.Logger.Tracef("receive PlayerChangeItems %v", data) // logger.Logger.Tracef("receive PlayerChangeItems %v", data)
@ -561,9 +561,9 @@ func init() {
})) }))
common.RegisterMulticastHandler() common.RegisterMulticastHandler()
//玩家离开 // 玩家离开
netlib.Register(int(server.SSPacketID_PACKET_WG_PlayerLEAVE), server.WGPlayerLeave{}, HandleWGPlayerLeave) //netlib.Register(int(server.SSPacketID_PACKET_WG_PlayerLEAVE), server.WGPlayerLeave{}, HandleWGPlayerLeave)
//同步记牌器过期时间 // 同步记牌器过期时间
netlib.Register(int(server.SSPacketID_PACKET_WG_BUYRECTIMEITEM), server.WGBuyRecTimeItem{}, HandleWGBuyRecTimeItem) netlib.Register(int(server.SSPacketID_PACKET_WG_BUYRECTIMEITEM), server.WGBuyRecTimeItem{}, HandleWGBuyRecTimeItem)
// 修改皮肤 // 修改皮肤
netlib.Register(int(server.SSPacketID_PACKET_WG_UpdateSkin), server.WGUpdateSkin{}, HandleWGUpdateSkin) netlib.Register(int(server.SSPacketID_PACKET_WG_UpdateSkin), server.WGUpdateSkin{}, HandleWGUpdateSkin)

View File

@ -21,15 +21,11 @@ var SceneMgrSington = &SceneMgr{
} }
type SceneMgr struct { type SceneMgr struct {
scenes map[int]*Scene scenes map[int]*Scene // 房间id
scenesByGame map[int]map[int]*Scene scenesByGame map[int]map[int]*Scene // 游戏id:房间id
scenesByGameFree map[int32]map[int]*Scene scenesByGameFree map[int32]map[int]*Scene // 场次id:房间id
lastSendJackPot time.Time lastSendJackPot time.Time //
PlatformScene map[string]bool PlatformScene map[string]bool //
}
func (this *SceneMgr) makeKey(gameid, gamemode int) int {
return int(gameid*10000 + gamemode)
} }
type CreateSceneParam struct { type CreateSceneParam struct {
@ -46,7 +42,6 @@ func (this *SceneMgr) CreateScene(args *CreateSceneParam) *Scene {
platform := args.GetPlatform() platform := args.GetPlatform()
gameId := args.GetGameId() gameId := args.GetGameId()
gameMode := args.GetGameMode()
gameFreeId := args.GetDBGameFree().GetId() gameFreeId := args.GetDBGameFree().GetId()
// 平台标记 // 平台标记
this.scenes[int(scene.SceneId)] = scene this.scenes[int(scene.SceneId)] = scene
@ -54,13 +49,12 @@ func (this *SceneMgr) CreateScene(args *CreateSceneParam) *Scene {
this.PlatformScene[platform] = true this.PlatformScene[platform] = true
} }
// 游戏id索引 // 游戏id索引
key := this.makeKey(int(gameId), int(gameMode)) if ss, exist := this.scenesByGame[int(gameId)]; exist {
if ss, exist := this.scenesByGame[key]; exist {
ss[int(scene.SceneId)] = scene ss[int(scene.SceneId)] = scene
} else { } else {
ss = make(map[int]*Scene) ss = make(map[int]*Scene)
ss[int(scene.SceneId)] = scene ss[int(scene.SceneId)] = scene
this.scenesByGame[key] = ss this.scenesByGame[int(gameId)] = ss
} }
// 场次id索引 // 场次id索引
if ss, exist := this.scenesByGameFree[gameFreeId]; exist { if ss, exist := this.scenesByGameFree[gameFreeId]; exist {
@ -79,87 +73,30 @@ func (this *SceneMgr) CreateScene(args *CreateSceneParam) *Scene {
func (this *SceneMgr) DestroyScene(sceneId int) { func (this *SceneMgr) DestroyScene(sceneId int) {
if scene, exist := this.scenes[sceneId]; exist { if scene, exist := this.scenes[sceneId]; exist {
scene.OnStop() scene.OnStop()
// // 游戏id
key := this.makeKey(int(scene.GameId), int(scene.GameMode)) if ss, exist := this.scenesByGame[scene.GetGameId()]; exist {
if ss, exist := this.scenesByGame[key]; exist {
delete(ss, int(scene.SceneId)) delete(ss, int(scene.SceneId))
} }
// // 场次id
if ss, exist := this.scenesByGameFree[scene.GetGameFreeId()]; exist { if ss, exist := this.scenesByGameFree[scene.GetGameFreeId()]; exist {
delete(ss, int(scene.SceneId)) delete(ss, int(scene.SceneId))
} }
// 房间id
delete(this.scenes, sceneId) delete(this.scenes, sceneId)
logger.Logger.Infof("(this *SceneMgr) DestroyScene, sceneid = %v", sceneId) logger.Logger.Infof("(this *SceneMgr) DestroyScene, sceneid = %v", sceneId)
} }
} }
func (this *SceneMgr) GetPlayerNumByGameFree(platform string, gamefreeid, groupId int32) int32 {
var num int32
if ss, exist := SceneMgrSington.scenesByGameFree[gamefreeid]; exist {
for _, scene := range ss {
if groupId != 0 {
if scene.GroupId == groupId {
cnt := scene.GetRealPlayerCnt()
num += int32(cnt)
}
} else {
if scene.Platform == platform {
cnt := scene.GetRealPlayerCnt()
num += int32(cnt)
}
}
}
}
return num
}
func (this *SceneMgr) GetPlayerNumByGame(platform string, gameid, gamemode, groupId int32) map[int32]int32 {
nums := make(map[int32]int32)
key := this.makeKey(int(gameid), int(gamemode))
if ss, exist := SceneMgrSington.scenesByGame[key]; exist {
for _, scene := range ss {
if groupId != 0 {
if scene.GroupId == groupId {
cnt := scene.GetRealPlayerCnt()
nums[scene.GetGameFreeId()] = nums[scene.GetGameFreeId()] + int32(cnt)
}
} else {
if scene.Platform == platform {
cnt := scene.GetRealPlayerCnt()
nums[scene.GetGameFreeId()] = nums[scene.GetGameFreeId()] + int32(cnt)
}
}
}
}
return nums
}
func (this *SceneMgr) GetPlayersByGameFree(platform string, gamefreeid int32) []*Player {
players := make([]*Player, 0)
if ss, exist := SceneMgrSington.scenesByGameFree[gamefreeid]; exist {
for _, scene := range ss {
if scene.Platform == platform {
for _, p := range scene.Players {
if p != nil {
players = append(players, p)
}
}
}
}
}
return players
}
func (this *SceneMgr) GetScene(sceneId int) *Scene { func (this *SceneMgr) GetScene(sceneId int) *Scene {
if s, exist := this.scenes[sceneId]; exist { if s, exist := this.scenes[sceneId]; exist {
return s return s
} }
return nil return nil
} }
func (this *SceneMgr) GetSceneByGameId(platform string, gameId int32) []*Scene { func (this *SceneMgr) GetSceneByGameId(platform string, gameId int32) []*Scene {
key := this.makeKey(int(gameId), 0)
var ss []*Scene var ss []*Scene
if data, ok := this.scenesByGame[key]; ok { if data, ok := this.scenesByGame[int(gameId)]; ok {
for _, scene := range data { for _, scene := range data {
if scene.Platform == platform { if scene.Platform == platform {
ss = append(ss, scene) ss = append(ss, scene)
@ -168,6 +105,7 @@ func (this *SceneMgr) GetSceneByGameId(platform string, gameId int32) []*Scene {
} }
return ss return ss
} }
func (this *SceneMgr) JackPotSync(platform string, gameIds ...int32) { func (this *SceneMgr) JackPotSync(platform string, gameIds ...int32) {
for _, gameId := range gameIds { for _, gameId := range gameIds {
ss := this.GetSceneByGameId(platform, gameId) ss := this.GetSceneByGameId(platform, gameId)
@ -214,16 +152,13 @@ func (this *SceneMgr) JackPotSync(platform string, gameIds ...int32) {
} }
} }
} }
func (this *SceneMgr) OnMiniTimer() { func (this *SceneMgr) OnMiniTimer() {
for _, scene := range this.scenes {
scene.SyncPlayerCoin()
}
} }
func (this *SceneMgr) OnHourTimer() { func (this *SceneMgr) OnHourTimer() {
// for _, scene := range this.scenes {
// scene.OnHourTimer()
// }
} }
func (this *SceneMgr) OnDayTimer() { func (this *SceneMgr) OnDayTimer() {

View File

@ -1,15 +1,9 @@
package base package base
import (
"time"
)
// 根据不同的房间模式,选择不同的房间业务逻辑 // 根据不同的房间模式,选择不同的房间业务逻辑
var ScenePolicyPool = make(map[int]map[int]ScenePolicy) // gameId:gameMode var ScenePolicyPool = make(map[int]map[int]ScenePolicy) // gameId:gameMode
type ScenePolicy interface { type ScenePolicy interface {
//心跳间隔
GetHeartBeatInterval() time.Duration
//场景开启事件 //场景开启事件
OnStart(s *Scene) OnStart(s *Scene)
//场景关闭事件 //场景关闭事件
@ -105,7 +99,6 @@ func RegisteScenePolicy(gameId, mode int, sp ScenePolicy) {
type BaseScenePolicy struct { type BaseScenePolicy struct {
} }
func (bsp *BaseScenePolicy) GetHeartBeatInterval() time.Duration { return time.Second }
func (bsp *BaseScenePolicy) OnStart(s *Scene) { func (bsp *BaseScenePolicy) OnStart(s *Scene) {
if s.aiMgr != nil { if s.aiMgr != nil {
s.aiMgr.OnStart(s) s.aiMgr.OnStart(s)

View File

@ -906,13 +906,20 @@ func (this *SceneWaitStartStateTienLen) OnTick(s *base.Scene) {
return return
} }
//开始前再次检查开始条件 //开始前再次检查开始条件
if sceneEx.CanStart() == true { if sceneEx.CanStart() {
s.ChangeSceneState(rule.TienLenSceneStateHandCard) s.ChangeSceneState(rule.TienLenSceneStateHandCard)
} else { } else {
s.ChangeSceneState(rule.TienLenSceneStateWaitPlayer) s.ChangeSceneState(rule.TienLenSceneStateWaitPlayer)
} }
} }
} }
if sceneEx.IsCustom() {
if sceneEx.CanStart() {
s.ChangeSceneState(rule.TienLenSceneStateHandCard)
} else {
s.ChangeSceneState(rule.TienLenSceneStateWaitPlayer)
}
}
} }
} }
@ -2626,6 +2633,7 @@ func (this *SceneBilledStateTienLen) OnEnter(s *base.Scene) {
} }
} }
s.Broadcast(int(tienlen.TienLenPacketID_PACKET_SCTienLenCycleBilled), packBilled, 0) s.Broadcast(int(tienlen.TienLenPacketID_PACKET_SCTienLenCycleBilled), packBilled, 0)
logger.Logger.Tracef("SCTienLenCycleBilled: %v", packBilled)
s.SyncSceneState(common.SceneStateEnd) s.SyncSceneState(common.SceneStateEnd)
sceneEx.SaveCustomLog() sceneEx.SaveCustomLog()
} }

View File

@ -13,7 +13,7 @@ import (
) )
type AwardLogManager struct { type AwardLogManager struct {
BaseClockSinker common.BaseClockSinker
AwardMap map[string]map[int32]map[int32]int64 //key1:plt key2:1话费 2实物 key3 itemId value:数量 AwardMap map[string]map[int32]map[int32]int64 //key1:plt key2:1话费 2实物 key3 itemId value:数量
AnnouncerLog map[string]map[int32][]model.AnnouncerLog //key:1话费 2实物 AnnouncerLog map[string]map[int32][]model.AnnouncerLog //key:1话费 2实物
} }
@ -153,5 +153,5 @@ func (this *AwardLogManager) Save() {
func init() { func init() {
module.RegisteModule(AwardLogMgr, time.Hour, 0) module.RegisteModule(AwardLogMgr, time.Hour, 0)
ClockMgrSington.RegisteSinker(AwardLogMgr) common.ClockMgrSingleton.RegisterSinker(AwardLogMgr)
} }

View File

@ -2,6 +2,7 @@ package main
import ( import (
"fmt" "fmt"
"mongo.games.com/game/common"
"sync" "sync"
"time" "time"
) )
@ -23,7 +24,7 @@ var CacheDataMgr = &CacheDataManager{
} }
type CacheDataManager struct { type CacheDataManager struct {
BaseClockSinker common.BaseClockSinker
MiniCache *sync.Map MiniCache *sync.Map
HourCache *sync.Map HourCache *sync.Map
DayCache *sync.Map DayCache *sync.Map
@ -67,7 +68,7 @@ func (this *CacheDataManager) addCacheData(timeRange int, key string, data inter
// 感兴趣所有clock event // 感兴趣所有clock event
func (this *CacheDataManager) InterestClockEvent() int { func (this *CacheDataManager) InterestClockEvent() int {
return 1 << CLOCK_EVENT_MINUTE return 1 << common.ClockEventMinute
} }
func (this *CacheDataManager) OnMiniTimer() { func (this *CacheDataManager) OnMiniTimer() {
@ -129,5 +130,5 @@ func (this *CacheDataManager) ClearCacheBill(billNo int, platform string) {
} }
func init() { func init() {
ClockMgrSington.RegisteSinker(CacheDataMgr) common.ClockMgrSingleton.RegisterSinker(CacheDataMgr)
} }

View File

@ -16,11 +16,11 @@ import (
var PermitMgrInst = new(PermitMgr) var PermitMgrInst = new(PermitMgr)
type PermitMgr struct { type PermitMgr struct {
BaseClockSinker common.BaseClockSinker
} }
func (r *PermitMgr) InterestClockEvent() int { func (r *PermitMgr) InterestClockEvent() int {
return 1 << CLOCK_EVENT_DAY return 1 << common.ClockEventDay
} }
func (r *PermitMgr) OnDayTimer() { func (r *PermitMgr) OnDayTimer() {
@ -180,5 +180,5 @@ func (r *PermitMgr) OnDayTimer() {
} }
func init() { func init() {
ClockMgrSington.RegisteSinker(PermitMgrInst) common.ClockMgrSingleton.RegisterSinker(PermitMgrInst)
} }

View File

@ -39,7 +39,7 @@ var PlatformMgrSingleton = &PlatformMgr{
} }
type PlatformMgr struct { type PlatformMgr struct {
BaseClockSinker common.BaseClockSinker
*model.ConfigMgr *model.ConfigMgr
platforms map[string]*Platform platforms map[string]*Platform
observers []PlatformObserver observers []PlatformObserver
@ -493,7 +493,7 @@ func (this *PlatformMgr) Shutdown() {
} }
func (this *PlatformMgr) InterestClockEvent() int { func (this *PlatformMgr) InterestClockEvent() int {
return 1<<CLOCK_EVENT_HOUR | 1<<CLOCK_EVENT_DAY return 1<<common.ClockEventHour | 1<<common.ClockEventDay
} }
func (this *PlatformMgr) OnDayTimer() { func (this *PlatformMgr) OnDayTimer() {
@ -593,6 +593,6 @@ func CopyDBGameFreeField(src, dst *serverproto.DB_GameFree) {
} }
func init() { func init() {
ClockMgrSington.RegisteSinker(PlatformMgrSingleton) common.ClockMgrSingleton.RegisterSinker(PlatformMgrSingleton)
module.RegisteModule(PlatformMgrSingleton, time.Hour, 0) module.RegisteModule(PlatformMgrSingleton, time.Hour, 0)
} }

View File

@ -1845,8 +1845,8 @@ func (this *Player) Save(force bool) {
pi := model.ClonePlayerData(this.PlayerData) pi := model.ClonePlayerData(this.PlayerData)
if pi != nil { if pi != nil {
this.SendToRepSrv(pi) this.SendToRepSrv(pi)
// 跨天任务依赖LastLogoutTime的准确性跨天任务是定时器ClockMgrSington触发的所以这里要用定时器的触发时间 // 跨天任务依赖LastLogoutTime的准确性跨天任务是定时器common.ClockMgrSington触发的所以这里要用定时器的触发时间
pi.LastLogoutTime = ClockMgrSington.LastTickTime pi.LastLogoutTime = common.ClockMgrSingleton.LastTickTime
t := task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} { t := task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
if !model.SavePlayerData(pi) { if !model.SavePlayerData(pi) {
//save 失败先写到json里面 //save 失败先写到json里面

View File

@ -36,7 +36,7 @@ type PlayerPendingData struct {
} }
type PlayerMgr struct { type PlayerMgr struct {
BaseClockSinker common.BaseClockSinker
sidMap map[int64]*Player // sid sidMap map[int64]*Player // sid
snidMap map[int32]*Player // snid snidMap map[int32]*Player // snid
accountMap map[string]*Player // accountid accountMap map[string]*Player // accountid
@ -452,7 +452,7 @@ func (this *PlayerMgr) BroadcastMessageToTarget(target []int32, packetid int, ra
// 感兴趣所有clock event // 感兴趣所有clock event
func (this *PlayerMgr) InterestClockEvent() int { func (this *PlayerMgr) InterestClockEvent() int {
return (1 << CLOCK_EVENT_MAX) - 1 return (1 << common.ClockEventMax) - 1
} }
func (this *PlayerMgr) OnSecTimer() { func (this *PlayerMgr) OnSecTimer() {
@ -1138,5 +1138,5 @@ func init() {
PlayerSubjectSign.AttachHead(FriendMgrSington) PlayerSubjectSign.AttachHead(FriendMgrSington)
// 定时器 // 定时器
ClockMgrSington.RegisteSinker(PlayerMgrSington) common.ClockMgrSingleton.RegisterSinker(PlayerMgrSington)
} }

View File

@ -7,7 +7,7 @@ import (
) )
func init() { func init() {
ClockMgrSington.RegisteSinker(PlayerNotifySingle) common.ClockMgrSingleton.RegisterSinker(PlayerNotifySingle)
} }
var PlayerNotifySingle = &PlayerNotify{ var PlayerNotifySingle = &PlayerNotify{
@ -20,12 +20,12 @@ type PlayerNotifyInfo struct {
} }
type PlayerNotify struct { type PlayerNotify struct {
BaseClockSinker common.BaseClockSinker
players map[int32]map[int32]*PlayerNotifyInfo // 消息类型玩家id玩家信息 players map[int32]map[int32]*PlayerNotifyInfo // 消息类型玩家id玩家信息
} }
func (p *PlayerNotify) InterestClockEvent() int { func (p *PlayerNotify) InterestClockEvent() int {
return 1 << CLOCK_EVENT_MINUTE return 1 << common.ClockEventMinute
} }
func (p *PlayerNotify) OnMiniTimer() { func (p *PlayerNotify) OnMiniTimer() {

View File

@ -1,6 +1,7 @@
package main package main
import ( import (
"mongo.games.com/game/common"
"mongo.games.com/game/model" "mongo.games.com/game/model"
server_proto "mongo.games.com/game/protocol/server" server_proto "mongo.games.com/game/protocol/server"
"mongo.games.com/game/webapi" "mongo.games.com/game/webapi"
@ -13,7 +14,7 @@ import (
) )
type QMFlowManager struct { type QMFlowManager struct {
BaseClockSinker common.BaseClockSinker
playerStatement map[int32]map[int32]*webapi.PlayerStatementSrc playerStatement map[int32]map[int32]*webapi.PlayerStatementSrc
offPlayerStatement map[int32]map[int32]*webapi.PlayerStatementSrc offPlayerStatement map[int32]map[int32]*webapi.PlayerStatementSrc
} }
@ -40,7 +41,7 @@ func (this *QMFlowManager) Shutdown() {
// 感兴趣所有clock event // 感兴趣所有clock event
func (this *QMFlowManager) InterestClockEvent() int { func (this *QMFlowManager) InterestClockEvent() int {
return 1 << CLOCK_EVENT_HOUR return 1 << common.ClockEventHour
} }
func (this *QMFlowManager) OnHourTimer() { func (this *QMFlowManager) OnHourTimer() {
@ -458,5 +459,5 @@ func (this *QMFlowManager) Save() {
func init() { func init() {
module.RegisteModule(QMFlowMgr, time.Minute*3, 0) module.RegisteModule(QMFlowMgr, time.Minute*3, 0)
ClockMgrSington.RegisteSinker(QMFlowMgr) common.ClockMgrSingleton.RegisterSinker(QMFlowMgr)
} }

View File

@ -4,6 +4,7 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"mongo.games.com/game/common"
"sort" "sort"
"strings" "strings"
"time" "time"
@ -244,7 +245,7 @@ func (this *PlayerRankSeason) rankLog(rankType int32) {
} }
type RankMatchMgr struct { type RankMatchMgr struct {
BaseClockSinker common.BaseClockSinker
failSeason []string failSeason []string
seasons map[string]*RankSeasonId // 当前赛季 key平台id seasons map[string]*RankSeasonId // 当前赛季 key平台id
playerSeasons map[int32]*PlayerRankSeason // 玩家排位信息 key玩家id playerSeasons map[int32]*PlayerRankSeason // 玩家排位信息 key玩家id
@ -638,7 +639,7 @@ func (r *RankMatchMgr) GetRankAwardList(rankType int32) []*rankmatch.AwardItem {
//========================implement ClockSinker ============================== //========================implement ClockSinker ==============================
func (r *RankMatchMgr) InterestClockEvent() int { func (r *RankMatchMgr) InterestClockEvent() int {
return 1 << CLOCK_EVENT_DAY return 1 << common.ClockEventDay
} }
func (r *RankMatchMgr) OnDayTimer() { func (r *RankMatchMgr) OnDayTimer() {
@ -934,6 +935,6 @@ func (r *RankMatchMgr) Release(platform string, snid int32) {
func init() { func init() {
module.RegisteModule(RankMgrSingleton, time.Minute, 0) module.RegisteModule(RankMgrSingleton, time.Minute, 0)
ClockMgrSington.RegisteSinker(RankMgrSingleton) common.ClockMgrSingleton.RegisterSinker(RankMgrSingleton)
internal.RegisterPlayerLoad(RankMgrSingleton) internal.RegisterPlayerLoad(RankMgrSingleton)
} }

View File

@ -17,7 +17,7 @@ import (
) )
func init() { func init() {
ClockMgrSington.RegisteSinker(SceneMgrSingleton) common.ClockMgrSingleton.RegisterSinker(SceneMgrSingleton)
} }
var SceneMgrSingleton = &SceneMgr{ var SceneMgrSingleton = &SceneMgr{
@ -31,8 +31,8 @@ var SceneMgrSingleton = &SceneMgr{
// SceneMgr 房间管理器 // SceneMgr 房间管理器
type SceneMgr struct { type SceneMgr struct {
BaseClockSinker // 驱动时间事件 common.BaseClockSinker // 驱动时间事件
scenes map[int]*Scene // 房间id: Scene scenes map[int]*Scene // 房间id: Scene
privateAutoId int // 私人房房间号 privateAutoId int // 私人房房间号
matchAutoId int // 比赛场房间号 matchAutoId int // 比赛场房间号
@ -477,7 +477,7 @@ func (m *SceneMgr) SendGameDestroy(sceneId []int, isGrace bool) {
// InterestClockEvent 接收所有时间事件 // InterestClockEvent 接收所有时间事件
func (m *SceneMgr) InterestClockEvent() int { func (m *SceneMgr) InterestClockEvent() int {
return 1 << CLOCK_EVENT_MINUTE return 1 << common.ClockEventMinute
} }
func (m *SceneMgr) OnMiniTimer() { func (m *SceneMgr) OnMiniTimer() {

View File

@ -51,7 +51,7 @@ const (
func init() { func init() {
module.RegisteModule(TournamentMgr, time.Second, 0) module.RegisteModule(TournamentMgr, time.Second, 0)
ClockMgrSington.RegisteSinker(TournamentMgr) common.ClockMgrSingleton.RegisterSinker(TournamentMgr)
} }
var TournamentMgr = NewTournament() var TournamentMgr = NewTournament()
@ -83,7 +83,7 @@ type PlayerRoundInfo struct {
} }
type Tournament struct { type Tournament struct {
BaseClockSinker common.BaseClockSinker
TypeList map[string]*webapiproto.GameMatchType // 比赛类型列表 平台id比赛类型列表 TypeList map[string]*webapiproto.GameMatchType // 比赛类型列表 平台id比赛类型列表
GameMatchDateList map[string]map[int32]*webapiproto.GameMatchDate // 比赛配置platform:比赛场配置id:比赛配置 GameMatchDateList map[string]map[int32]*webapiproto.GameMatchDate // 比赛配置platform:比赛场配置id:比赛配置
singleSignupPlayers map[int32]*SignupInfo // 开启机器人时报名的玩家玩家Id:报名信息 singleSignupPlayers map[int32]*SignupInfo // 开启机器人时报名的玩家玩家Id:报名信息

View File

@ -17,7 +17,7 @@ type DayTimeChangeTransactHandler struct {
func (this *DayTimeChangeTransactHandler) OnExcute(tNode *transact.TransNode, ud interface{}) transact.TransExeResult { func (this *DayTimeChangeTransactHandler) OnExcute(tNode *transact.TransNode, ud interface{}) transact.TransExeResult {
//logger.Logger.Trace("DayTimeChangeTransactHandler.OnExcute ") //logger.Logger.Trace("DayTimeChangeTransactHandler.OnExcute ")
ClockMgrSington.Notifying = true common.ClockMgrSingleton.Notifying = true
for sid, _ := range GameSessMgrSington.servers { for sid, _ := range GameSessMgrSington.servers {
tnp := &transact.TransNodeParam{ tnp := &transact.TransNodeParam{
Tt: common.TransType_DayTimeChange, Tt: common.TransType_DayTimeChange,
@ -27,7 +27,7 @@ func (this *DayTimeChangeTransactHandler) OnExcute(tNode *transact.TransNode, ud
Tct: transact.TransactCommitPolicy_SelfDecide, Tct: transact.TransactCommitPolicy_SelfDecide,
} }
//logger.Logger.Tracef("TransNode=%v", *tnp) //logger.Logger.Tracef("TransNode=%v", *tnp)
_, wgDayTimeChangePack.LastMin, wgDayTimeChangePack.LastHour, wgDayTimeChangePack.LastDay, wgDayTimeChangePack.LastWeek, wgDayTimeChangePack.LastMonth = ClockMgrSington.GetLast() _, wgDayTimeChangePack.LastMin, wgDayTimeChangePack.LastHour, wgDayTimeChangePack.LastDay, wgDayTimeChangePack.LastWeek, wgDayTimeChangePack.LastMonth = common.ClockMgrSingleton.GetLast()
tNode.StartChildTrans(tnp, wgDayTimeChangePack, DayTimeChangeTimeOut) tNode.StartChildTrans(tnp, wgDayTimeChangePack, DayTimeChangeTimeOut)
} }
@ -36,13 +36,13 @@ func (this *DayTimeChangeTransactHandler) OnExcute(tNode *transact.TransNode, ud
func (this *DayTimeChangeTransactHandler) OnCommit(tNode *transact.TransNode) transact.TransExeResult { func (this *DayTimeChangeTransactHandler) OnCommit(tNode *transact.TransNode) transact.TransExeResult {
//logger.Logger.Trace("DayTimeChangeTransactHandler.OnCommit ") //logger.Logger.Trace("DayTimeChangeTransactHandler.OnCommit ")
ClockMgrSington.Notifying = false common.ClockMgrSingleton.Notifying = false
return transact.TransExeResult_Success return transact.TransExeResult_Success
} }
func (this *DayTimeChangeTransactHandler) OnRollBack(tNode *transact.TransNode) transact.TransExeResult { func (this *DayTimeChangeTransactHandler) OnRollBack(tNode *transact.TransNode) transact.TransExeResult {
//logger.Logger.Trace("DayTimeChangeTransactHandler.OnRollBack ") //logger.Logger.Trace("DayTimeChangeTransactHandler.OnRollBack ")
ClockMgrSington.Notifying = false common.ClockMgrSingleton.Notifying = false
return transact.TransExeResult_Success return transact.TransExeResult_Success
} }
@ -53,7 +53,7 @@ func (this *DayTimeChangeTransactHandler) OnChildTransRep(tNode *transact.TransN
} }
type DayTimeChangeTransactSinker struct { type DayTimeChangeTransactSinker struct {
BaseClockSinker common.BaseClockSinker
} }
func (this *DayTimeChangeTransactSinker) OnMiniTimer() { func (this *DayTimeChangeTransactSinker) OnMiniTimer() {
@ -70,6 +70,6 @@ func (this *DayTimeChangeTransactSinker) OnMiniTimer() {
} }
func init() { func init() {
ClockMgrSington.RegisteSinker(&DayTimeChangeTransactSinker{}) common.ClockMgrSingleton.RegisterSinker(&DayTimeChangeTransactSinker{})
transact.RegisteHandler(common.TransType_DayTimeChange, &DayTimeChangeTransactHandler{}) transact.RegisteHandler(common.TransType_DayTimeChange, &DayTimeChangeTransactHandler{})
} }

View File

@ -27,7 +27,7 @@ var WelfareMgrSington = &WelfareMgr{
} }
type WelfareMgr struct { type WelfareMgr struct {
BaseClockSinker common.BaseClockSinker
*model.ConfigMgr *model.ConfigMgr
} }
@ -2010,10 +2010,10 @@ func (this *WelfareMgr) OnDayTimer() {
} }
func (this *WelfareMgr) InterestClockEvent() int { func (this *WelfareMgr) InterestClockEvent() int {
return (1 << CLOCK_EVENT_MAX) - 1 return (1 << common.ClockEventMax) - 1
} }
func init() { func init() {
module.RegisteModule(WelfareMgrSington, time.Second, 0) module.RegisteModule(WelfareMgrSington, time.Second, 0)
ClockMgrSington.RegisteSinker(WelfareMgrSington) common.ClockMgrSingleton.RegisterSinker(WelfareMgrSington)
} }