From da5bb974691d62ea0917d4fe786e80130d81b91f Mon Sep 17 00:00:00 2001 From: sk <123456@qq.com> Date: Sat, 25 May 2024 15:45:59 +0800 Subject: [PATCH 1/2] review --- worldsrv/action_friend.go | 2 +- worldsrv/action_game.go | 6 +- worldsrv/actsignmgr.go | 154 -------------------------------------- worldsrv/coinscenepool.go | 94 ++++++++++++----------- worldsrv/player.go | 18 ----- worldsrv/scene.go | 3 +- 6 files changed, 54 insertions(+), 223 deletions(-) delete mode 100644 worldsrv/actsignmgr.go diff --git a/worldsrv/action_friend.go b/worldsrv/action_friend.go index 1c9adf4..5be220e 100644 --- a/worldsrv/action_friend.go +++ b/worldsrv/action_friend.go @@ -520,7 +520,7 @@ func (this *CSInviteFriendOpHandler) Process(s *netlib.Session, packetid int, da send(p) return nil } - if !p.EnterScene(scene, true, pos) { + if !scene.PlayerEnter(p, pos, true) { logger.Logger.Trace("CSInviteFriendHandler EnterScene fail") opRetCode = friend.OpResultCode_OPRC_Error //进入房间失败 send(p) diff --git a/worldsrv/action_game.go b/worldsrv/action_game.go index 250d930..6b24192 100644 --- a/worldsrv/action_game.go +++ b/worldsrv/action_game.go @@ -165,7 +165,7 @@ func (this *CSEnterRoomHandler) Process(s *netlib.Session, packetid int, data in } } - if !p.EnterScene(scene, true, -1) { + if !scene.PlayerEnter(p, -1, true) { code = gamehall.OpResultCode_Game_OPRC_Error_Game } @@ -1940,7 +1940,7 @@ func (this *CSCreateRoomHandler) ProcessLocalGame(s *netlib.Session, packetid in // try enter scene csp.scenes[scene.sceneId] = scene scene.csp = csp - if !p.EnterScene(scene, true, -1) { + if !scene.PlayerEnter(p, -1, true) { code = gamehall.OpResultCode_Game_OPRC_Error_Game } } @@ -2048,7 +2048,7 @@ func (this *CSCreateRoomHandler) ProcessThirteen(s *netlib.Session, packetid int // try enter scene csp.scenes[scene.sceneId] = scene scene.csp = csp - if !p.EnterScene(scene, true, -1) { + if !scene.PlayerEnter(p, -1, true) { code = gamehall.OpResultCode_Game_OPRC_Error_Game } } diff --git a/worldsrv/actsignmgr.go b/worldsrv/actsignmgr.go deleted file mode 100644 index b333c85..0000000 --- a/worldsrv/actsignmgr.go +++ /dev/null @@ -1,154 +0,0 @@ -package main - -import ( - "github.com/globalsign/mgo" - "mongo.games.com/game/common" - "mongo.games.com/game/model" - "mongo.games.com/game/proto" - "mongo.games.com/game/protocol/activity" - "mongo.games.com/game/protocol/server" - "mongo.games.com/game/srvdata" - "mongo.games.com/goserver/core/logger" - "time" -) - -var ActSignMgrSington = &ActSignMgr{ - SignConfigs: make(map[int]*server.DB_ActSign), -} - -type ActSignMgr struct { - SignConfigs map[int]*server.DB_ActSign -} - -func (this *ActSignMgr) Init() { - if this.SignConfigs == nil { - this.SignConfigs = make(map[int]*server.DB_ActSign) - } - for _, v := range srvdata.PBDB_ActSignMgr.Datas.GetArr() { - this.SignConfigs[int(v.Id)] = v - } -} - -func (this *ActSignMgr) GetConfig(id int) *server.DB_ActSign { - signConfig, ok := this.SignConfigs[id] - if ok { - return signConfig - } - return nil -} - -func (this *ActSignMgr) OnPlayerLogin(player *Player) error { - return this.RefixedPlayerData(player) -} - -func (this *ActSignMgr) OnDayChanged(player *Player) error { - //跨天不需要 - //this.RefixedPlayerData(player) - //this.SendSignDataToPlayer(player) - return nil -} - -func (this *ActSignMgr) RefixedPlayerData(player *Player) error { - if player.IsRob { - return nil - } - if player.SignData == nil { - player.SignData = &model.SignData{ - SignIndex: 0, - LastSignTickets: 0, - } - } - return nil -} - -func (this *ActSignMgr) SendSignDataToPlayer(player *Player) { - if player.IsRob { - return - } - pack := &activity.SCSignData{} - //已经领取第几个 - pack.SignCount = proto.Int(player.SignData.SignIndex) - if player.SignData.LastSignTickets != 0 { - lastSignTime := time.Unix(player.SignData.LastSignTickets, 0) - dayDiff := int32(common.DiffDay(time.Now(), lastSignTime)) - if dayDiff == 0 { - pack.TodaySign = proto.Int32(1) - } else { - pack.TodaySign = proto.Int32(0) - } - } else { - pack.TodaySign = proto.Int32(0) - } - proto.SetDefaults(pack) - player.SendToClient(int(activity.ActSignPacketID_PACKET_SCSignData), pack) - logger.Logger.Trace("SCSignData: ", pack) -} - -func (this *ActSignMgr) CanSign(player *Player, signIndex int) activity.OpResultCode_ActSign { - signConfig := this.GetConfig(signIndex) - if signConfig == nil { - return activity.OpResultCode_ActSign_OPRC_Activity_Sign_Error - } - - if player.SignData.LastSignTickets != 0 { - lastSignTime := time.Unix(player.SignData.LastSignTickets, 0) - dayDiff := int32(common.DiffDay(time.Now(), lastSignTime)) - if dayDiff == 0 { - if player.SignData.SignIndex == signIndex { - return activity.OpResultCode_ActSign_OPRC_Activity_Sign_Repeat - } else { - return activity.OpResultCode_ActSign_OPRC_Activity_Sign_Config_Day_Error - } - } - - if player.SignData.SignIndex != (signIndex - 1) { - return activity.OpResultCode_ActSign_OPRC_Activity_Sign_Config_Day_Error - } - } else { - if signIndex != 1 { - return activity.OpResultCode_ActSign_OPRC_Activity_Sign_Config_Day_Error - } - } - - return activity.OpResultCode_ActSign_OPRC_Activity_Sign_Sucess -} - -//func (this *ActSignMgr) Sign(player *Player, signIndex int, signType int32) activity.OpResultCode_ActSign { -// errCode := this.CanSign(player, signIndex) -// if errCode != activity.OpResultCode_ActSign_OPRC_Activity_Sign_Sucess { -// return errCode -// } -// -// signConfig := this.GetConfig(signIndex) -// if signConfig == nil { -// return activity.OpResultCode_ActSign_OPRC_Activity_Sign_Error -// } -// -// player.SignData.LastSignTickets = time.Now().Unix() -// player.SignData.SignIndex = signIndex -// -// logger.Logger.Info("签到成功: ", signConfig) -// grade := signConfig.Grade -// switch signType { -// case 0: //普通签到 -// case 1: //双倍签到 -// grade *= 2 -// } -// switch signConfig.Type { -// case 1: //金币 -// player.AddCoin(int64(grade), 0, common.GainWay_ActSign, strconv.Itoa(signIndex), time.Now().Format("2006-01-02 15:04:05")) -// case 2: //钻石 -// player.AddDiamond(int64(grade), 0, common.GainWay_ActSign, strconv.Itoa(signIndex), time.Now().Format("2006-01-02 15:04:05")) -// case 3: //道具 -// item := &Item{ -// ItemId: signConfig.Item_Id, -// ItemNum: int64(grade), -// } -// BagMgrSingleton.AddItems(player, []*Item{item}, 0, common.GainWay_ActSign, strconv.Itoa(signIndex), time.Now().Format("2006-01-02 15:04:05"), 0, 0, false) -// } -// return activity.OpResultCode_ActSign_OPRC_Activity_Sign_Sucess -//} - -func init() { - mgo.SetStats(true) -} diff --git a/worldsrv/coinscenepool.go b/worldsrv/coinscenepool.go index 1882309..d710354 100644 --- a/worldsrv/coinscenepool.go +++ b/worldsrv/coinscenepool.go @@ -5,20 +5,20 @@ import ( "mongo.games.com/game/model" "mongo.games.com/game/proto" - gamehall_proto "mongo.games.com/game/protocol/gamehall" - server_proto "mongo.games.com/game/protocol/server" + gamehallproto "mongo.games.com/game/protocol/gamehall" + serverproto "mongo.games.com/game/protocol/server" "mongo.games.com/game/srvdata" ) // CoinScenePool 房间池 type CoinScenePool struct { - platform string // 平台id - groupId int32 // 组id - id int32 // 场次id - dbGameFree *server_proto.DB_GameFree // 场次配置 - dbGameRule *server_proto.DB_GameRule // 场次配置 - scenes map[int]*Scene // 所有房间,房间id - players map[int32]struct{} // 玩家id + platform string // 平台id + groupId int32 // 组id + id int32 // 场次id + dbGameFree *serverproto.DB_GameFree // 场次配置 + dbGameRule *serverproto.DB_GameRule // 场次配置 + scenes map[int]*Scene // 所有房间,房间id + players map[int32]struct{} // 玩家id // 扩展数据 extraData interface{} @@ -26,7 +26,7 @@ type CoinScenePool struct { policy ICoinScenePool } -func NewCoinScenePool(platform string, groupId int32, dbGameFree *server_proto.DB_GameFree) *CoinScenePool { +func NewCoinScenePool(platform string, groupId int32, dbGameFree *serverproto.DB_GameFree) *CoinScenePool { if dbGameFree == nil { return nil } @@ -87,20 +87,20 @@ func (csp *CoinScenePool) CanInviteRob() bool { } // CanEnter 检查入场条件 -func (csp *CoinScenePool) CanEnter(p *Player) gamehall_proto.OpResultCode { +func (csp *CoinScenePool) CanEnter(p *Player) gamehallproto.OpResultCode { if csp.dbGameFree == nil || p == nil { - return gamehall_proto.OpResultCode_OPRC_Error + return gamehallproto.OpResultCode_OPRC_Error } //检测房间状态是否开启 gps := PlatformMgrSingleton.GetGameFree(p.Platform, csp.id) if gps == nil || !gps.Status { - return gamehall_proto.OpResultCode_OPRC_RoomHadClosed + return gamehallproto.OpResultCode_OPRC_RoomHadClosed } dbGameFree := csp.dbGameFree if dbGameFree == nil { - return gamehall_proto.OpResultCode_OPRC_RoomHadClosed + return gamehallproto.OpResultCode_OPRC_RoomHadClosed } //检查游戏次数限制 @@ -109,7 +109,7 @@ func (csp *CoinScenePool) CanEnter(p *Player) gamehall_proto.OpResultCode { if dbGameFree.GetPlayNumLimit() != 0 && todayData != nil && todayData.GameTimes >= int64(dbGameFree.GetPlayNumLimit()) { - return gamehall_proto.OpResultCode_OPRC_RoomGameTimes + return gamehallproto.OpResultCode_OPRC_RoomGameTimes } } @@ -117,28 +117,30 @@ func (csp *CoinScenePool) CanEnter(p *Player) gamehall_proto.OpResultCode { } // CanAudienceEnter 检查观众入场条件 -func (csp *CoinScenePool) CanAudienceEnter(p *Player) gamehall_proto.OpResultCode { +func (csp *CoinScenePool) CanAudienceEnter(p *Player) gamehallproto.OpResultCode { if csp.dbGameFree == nil || p == nil { - return gamehall_proto.OpResultCode_OPRC_Error + return gamehallproto.OpResultCode_OPRC_Error } //检测房间状态是否开启 gps := PlatformMgrSingleton.GetGameFree(p.Platform, csp.id) if gps == nil { - return gamehall_proto.OpResultCode_OPRC_RoomHadClosed + return gamehallproto.OpResultCode_OPRC_RoomHadClosed } dbGameFree := csp.dbGameFree if dbGameFree == nil { - return gamehall_proto.OpResultCode_OPRC_RoomHadClosed + return gamehallproto.OpResultCode_OPRC_RoomHadClosed } return csp.policy.CanAudienceEnter(csp, p) } // PlayerEnter 玩家进入房间池 -func (csp *CoinScenePool) PlayerEnter(p *Player, roomId int32, exclude []int32, ischangeroom bool) gamehall_proto.OpResultCode { - if ret := csp.CanEnter(p); ret != gamehall_proto.OpResultCode_OPRC_Sucess { +// exclude 排除的房间id +// isChangeRoom 是否换房 +func (csp *CoinScenePool) PlayerEnter(p *Player, roomId int32, exclude []int32, isChangeRoom bool) gamehallproto.OpResultCode { + if ret := csp.CanEnter(p); ret != gamehallproto.OpResultCode_OPRC_Sucess { logger.Logger.Warnf("(csp *CoinScenePool) PlayerEnter find snid:%v csp.CanEnter coin:%v ret:%v id:%v", p.SnId, p.Coin, ret, csp.dbGameFree.GetId()) return ret @@ -146,40 +148,42 @@ func (csp *CoinScenePool) PlayerEnter(p *Player, roomId int32, exclude []int32, if p.scene != nil { logger.Logger.Warnf("(csp *CoinScenePool) PlayerEnter[p.scene != nil] find snid:%v in scene:%v gameId:%v", p.SnId, p.scene.sceneId, p.scene.gameId) - return gamehall_proto.OpResultCode_OPRC_Error + return gamehallproto.OpResultCode_OPRC_Error } var scene *Scene // 进入房间 - if roomId != 0 && (p.IsRob || p.GMLevel > 0 || csp.dbGameFree.GetCreateRoomNum() != 0) { + // 指定房间id进入,忽略排除exclude,只有机器人和进入预创建房间才允许 + if roomId != 0 && (p.IsRob || csp.dbGameFree.GetCreateRoomNum() != 0) { if s, ok := csp.scenes[int(roomId)]; ok { if s != nil && !s.deleting { //指定房间id进入,那么忽略掉排除id if s.IsFull() { - return gamehall_proto.OpResultCode_OPRC_RoomIsFull + return gamehallproto.OpResultCode_OPRC_RoomIsFull } if sp, ok := s.sp.(*ScenePolicyData); ok { if !s.starting || sp.EnterAfterStart { scene = s } else { logger.Logger.Warnf("(csp *CoinScenePool) PlayerEnter[!s.starting || sp.EnterAfterStart] snid:%v sceneid:%v starting:%v EnterAfterStart:%v", p.SnId, s.sceneId, s.starting, sp.EnterAfterStart) - return gamehall_proto.OpResultCode_OPRC_Error + return gamehallproto.OpResultCode_OPRC_Error } } } } else { - logger.Logger.Warnf("(csp *CoinScenePool) PlayerEnter(robot:%v,roomid:%v, exclude:%v, ischangeroom:%v) no found scene", p.SnId, roomId, exclude, ischangeroom) - return gamehall_proto.OpResultCode_OPRC_Error + logger.Logger.Warnf("(csp *CoinScenePool) PlayerEnter(robot:%v,roomid:%v, exclude:%v, isChangeRoom:%v) no found scene", p.SnId, roomId, exclude, isChangeRoom) + return gamehallproto.OpResultCode_OPRC_Error } } if scene == nil { - var ret gamehall_proto.OpResultCode - ret, scene = csp.policy.PlayerEnter(csp, p, exclude, ischangeroom) - if ret != gamehall_proto.OpResultCode_OPRC_Sucess { + var ret gamehallproto.OpResultCode + ret, scene = csp.policy.PlayerEnter(csp, p, exclude, isChangeRoom) + if ret != gamehallproto.OpResultCode_OPRC_Sucess { return ret } } + // 没有找到房间,创建新房间 if scene == nil { scene = csp.policy.NewScene(csp, p) if scene != nil { @@ -191,25 +195,25 @@ func (csp *CoinScenePool) PlayerEnter(p *Player, roomId int32, exclude []int32, } if scene != nil { - if p.EnterScene(scene, ischangeroom, -1) { + if scene.PlayerEnter(p, -1, isChangeRoom) { csp.OnPlayerEnter(p, scene) - return gamehall_proto.OpResultCode_OPRC_Sucess + return gamehallproto.OpResultCode_OPRC_Sucess } } logger.Logger.Warnf("(csp *CoinScenePool) PlayerEnter snid:%v not found scene", p.SnId) - return gamehall_proto.OpResultCode_OPRC_SceneServerMaintain + return gamehallproto.OpResultCode_OPRC_SceneServerMaintain } // AudienceEnter 观众入场 -func (csp *CoinScenePool) AudienceEnter(p *Player, roomId int32, exclude []int32, ischangeroom bool) gamehall_proto.OpResultCode { - if ret := csp.CanAudienceEnter(p); ret != gamehall_proto.OpResultCode_OPRC_Sucess { +func (csp *CoinScenePool) AudienceEnter(p *Player, roomId int32, exclude []int32, ischangeroom bool) gamehallproto.OpResultCode { + if ret := csp.CanAudienceEnter(p); ret != gamehallproto.OpResultCode_OPRC_Sucess { logger.Logger.Warnf("(csp *CoinScenePool) AudienceEnter find snid:%v csp.CanEnter coin:%v ret:%v id:%v", p.SnId, p.Coin, ret, csp.dbGameFree.GetId()) return ret } if p.scene != nil { logger.Logger.Warnf("(csp *CoinScenePool) AudienceEnter[p.scene != nil] find snid:%v in scene:%v gameId:%v", p.SnId, p.scene.sceneId, p.scene.gameId) - return gamehall_proto.OpResultCode_OPRC_Error + return gamehallproto.OpResultCode_OPRC_Error } var scene *Scene @@ -224,29 +228,29 @@ func (csp *CoinScenePool) AudienceEnter(p *Player, roomId int32, exclude []int32 } if scene == nil { - var ret gamehall_proto.OpResultCode + var ret gamehallproto.OpResultCode ret, scene = csp.policy.AudienceEnter(csp, p, exclude, ischangeroom) - if ret != gamehall_proto.OpResultCode_OPRC_Sucess { + if ret != gamehallproto.OpResultCode_OPRC_Sucess { return ret } } if scene == nil { - return gamehall_proto.OpResultCode_OPRC_NoFindDownTiceRoom + return gamehallproto.OpResultCode_OPRC_NoFindDownTiceRoom } if scene != nil { // 预创建房间检查观众数量 if scene.IsPreCreateScene() && scene.GetAudienceCnt() >= model.GameParamData.MaxAudienceNum { - return gamehall_proto.OpResultCode_OPRC_RoomIsFull + return gamehallproto.OpResultCode_OPRC_RoomIsFull } if scene.AudienceEnter(p, ischangeroom) { csp.OnPlayerEnter(p, scene) - return gamehall_proto.OpResultCode_OPRC_Sucess + return gamehallproto.OpResultCode_OPRC_Sucess } } logger.Logger.Warnf("(csp *CoinScenePool) PlayerEnter snid:%v not found scene", p.SnId) - return gamehall_proto.OpResultCode_OPRC_NoFindDownTiceRoom + return gamehallproto.OpResultCode_OPRC_NoFindDownTiceRoom } // OnPlayerEnter 玩家进入房间完成 @@ -431,7 +435,7 @@ func (csp *CoinScenePool) ListRoom(p *Player) bool { return false } - pack := &gamehall_proto.SCCoinSceneListRoom{ + pack := &gamehallproto.SCCoinSceneListRoom{ Id: csp.dbGameFree.Id, LimitCoin: csp.dbGameFree.LimitCoin, MaxCoinLimit: csp.dbGameFree.MaxCoinLimit, @@ -442,7 +446,7 @@ func (csp *CoinScenePool) ListRoom(p *Player) bool { maxPlayerNum := 0 for sceneId, s := range csp.scenes { - data := &gamehall_proto.CoinSceneInfo{ + data := &gamehallproto.CoinSceneInfo{ SceneId: proto.Int(sceneId), PlayerNum: proto.Int(len(s.players)), } @@ -451,7 +455,7 @@ func (csp *CoinScenePool) ListRoom(p *Player) bool { } pack.MaxPlayerNum = proto.Int(maxPlayerNum) proto.SetDefaults(pack) - p.SendToClient(int(gamehall_proto.CoinSceneGamePacketID_PACKET_SC_COINSCENE_LISTROOM), pack) + p.SendToClient(int(gamehallproto.CoinSceneGamePacketID_PACKET_SC_COINSCENE_LISTROOM), pack) return true } diff --git a/worldsrv/player.go b/worldsrv/player.go index 23107e8..488d5a2 100644 --- a/worldsrv/player.go +++ b/worldsrv/player.go @@ -179,7 +179,6 @@ func NewPlayer(sid int64, pd *model.PlayerData, s *netlib.Session) *Player { func (this *Player) init() bool { this.SetOnline() this.isNewbie = this.CreateTime == this.LastLoginTime - this.applyPos = -1 return true } @@ -2351,23 +2350,6 @@ func (this *Player) CreateLocalGameScene(sceneId, gameId, gameSite, sceneMode, p return s, hall_proto.OpResultCode_Game_OPRC_Sucess_Game } -func (this *Player) EnterScene(s *Scene, ischangeroom bool, pos int) bool { - if s == nil { - logger.Logger.Tracef("(this *Player) EnterScene, s == nil %v", this.SnId) - return false - } - - if s != nil { - this.applyPos = -1 - if s.PlayerEnter(this, pos, ischangeroom) { - FirePlayerEnterScene(this, s) - return true - } - } - - return false -} - func (this *Player) ReturnScene(isLoaded bool) *Scene { logger.Logger.Tracef("(this *Player) ReturnScene %v", this.SnId) if this.scene == nil { diff --git a/worldsrv/scene.go b/worldsrv/scene.go index f4464d6..790d478 100644 --- a/worldsrv/scene.go +++ b/worldsrv/scene.go @@ -553,6 +553,7 @@ func (this *Scene) PlayerEnter(p *Player, pos int, ischangeroom bool) bool { this.SendToGame(int(serverproto.SSPacketID_PACKET_WG_PLAYERENTER), msg) logger.Logger.Tracef("SSPacketID_PACKET_WG_PLAYERENTER Scene:%v ;PlayerEnter(%v, %v)", this.sceneId, p.SnId, pos) this.lastTime = time.Now() + FirePlayerEnterScene(p, this) return true } else { logger.Logger.Warnf("(this *Scene:%v) PlayerEnter(%v, %v) Marshal player data error %v", this.sceneId, p.SnId, pos, err) @@ -659,7 +660,6 @@ func (this *Scene) DelPlayer(p *Player) bool { func (this *Scene) AudienceEnter(p *Player, ischangeroom bool) bool { logger.Logger.Infof("(this *Scene:%v) AudienceEnter(%v) ", this.sceneId, p.SnId) p.scene = this - p.applyPos = -1 this.audiences[p.SnId] = p this.gameSess.AddPlayer(p) if this.IsHundredScene() { @@ -744,7 +744,6 @@ func (this *Scene) DelAudience(p *Player) bool { delete(this.gameCtx, p.SnId) } p.scene = nil - p.applyPos = -1 SceneMgrSingleton.OnPlayerLeaveScene(this, p) if this.IsHundredScene() { HundredSceneMgrSington.OnPlayerLeave(p) From 516ab3f811d5b6f7c5850dc084af5585a0efa084 Mon Sep 17 00:00:00 2001 From: sk <123456@qq.com> Date: Mon, 27 May 2024 18:16:38 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=A2=84=E5=88=9B?= =?UTF-8?q?=E5=BB=BA=E6=88=BF=E9=97=B4=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/constant.go | 4 +- worldsrv/action_game.go | 66 +------ worldsrv/coinscenemgr.go | 260 ++++++++-------------------- worldsrv/coinscenepool.go | 157 ++++++++++------- worldsrv/coinscenepool_base.go | 47 ++--- worldsrv/coinscenepool_interface.go | 23 ++- worldsrv/coinscenepool_local.go | 67 +++---- worldsrv/gamesess.go | 1 - worldsrv/minigamemgr.go | 12 +- worldsrv/scene.go | 21 +-- worldsrv/scenemgr.go | 99 +++++++---- 11 files changed, 300 insertions(+), 457 deletions(-) diff --git a/common/constant.go b/common/constant.go index c337c01..19b957d 100644 --- a/common/constant.go +++ b/common/constant.go @@ -248,8 +248,8 @@ const ( GainWay_ActSignNew2 = 58 //签到看视频双倍领取 GainWay_ItemUse = 59 //道具使用 GainWay_PhoneScore = 60 //积分抽奖活动 - GainWay_RankReward = 61 // - GainWay_TaskReward = 62 // + GainWay_RankReward = 61 //排位奖励 + GainWay_TaskReward = 62 //任务奖励 GainWay_Interact = 63 //房间内互动效果 GainWay_Collect = 64 //集卡活动 GainWay_WeekCardAward = 65 //周卡奖励 diff --git a/worldsrv/action_game.go b/worldsrv/action_game.go index 6b24192..a1e09bd 100644 --- a/worldsrv/action_game.go +++ b/worldsrv/action_game.go @@ -1339,58 +1339,6 @@ func (this *CSQueryRoomInfoHandler) ProcessLocalGame(s *netlib.Session, packetid return nil } -func (this *CSQueryRoomInfoHandler) ProcessId(s *netlib.Session, packetid int, data interface{}, sid int64) error { - logger.Logger.Trace("CSQueryRoomInfoHandler Process recv ProcessId", data) - if msg, ok := data.(*gamehall.CSQueryRoomInfo); ok { - p := PlayerMgrSington.GetPlayer(sid) - if p == nil { - logger.Logger.Warn("CSQueryRoomInfoHandler p == nil") - return nil - } - - pack := &gamehall.SCQueryRoomInfo{} - mapGameCfg := PlatformMgrSingleton.GetGameFrees(p.Platform) - for _, v := range msg.GetId() { - gameid := v / 10000 - pack.GameIds = append(pack.GameIds, gameid) - scenes := SceneMgrSingleton.GetScenesByGame(int(gameid)) - for _, scene := range scenes { - var isShow bool - if mapGameCfg != nil { - if cfg, have := mapGameCfg[scene.dbGameFree.Id]; have && cfg.GroupId != 0 && cfg.GroupId == scene.groupId { - isShow = true - } - } - if p.Platform == scene.limitPlatform.IdStr || isShow { - if scene != nil && scene.sceneMode == common.SceneMode_Public && len(scene.players) != 0 { - if scene.dbGameFree.Id == v { - roomInfo := &gamehall.QRoomInfo{ - GameFreeId: proto.Int32(scene.dbGameFree.GetId()), - GameId: proto.Int32(scene.dbGameFree.GetGameId()), - RoomId: proto.Int(scene.sceneId), - BaseCoin: proto.Int64(int64(scene.BaseScore)), - LimitCoin: proto.Int64(scene.dbGameFree.GetLimitCoin()), - CurrNum: proto.Int(scene.GetPlayerCnt()), - MaxPlayer: proto.Int(scene.playerNum), - Creator: proto.Int32(scene.creator), - CreateTs: proto.Int32(int32(scene.createTime.Unix())), - Params: common.CopySliceInt64ToInt32(scene.params), - } - pack.RoomInfo = append(pack.RoomInfo, roomInfo) - } - } - } - } - } - - pack.OpRetCode = gamehall.OpResultCode_Game_OPRC_Sucess_Game - proto.SetDefaults(pack) - p.SendToClient(int(gamehall.GameHallPacketID_PACKET_SC_QUERYROOMINFO), pack) - logger.Logger.Trace("SCQueryRoomInfo: ", pack) - } - return nil -} - type CSLotteryLogPacketFactory struct { } type CSLotteryLogHandler struct { @@ -1934,15 +1882,11 @@ func (this *CSCreateRoomHandler) ProcessLocalGame(s *netlib.Session, packetid in } scene, code = p.CreateLocalGameScene(roomId, int(gameId), int(gameSite), int(msg.GetSceneMode()), maxPlayerNum, params, dbGameFree, baseScore, csp.groupId) - if scene != nil { - if code == gamehall.OpResultCode_Game_OPRC_Sucess_Game { - logger.Logger.Tracef("CSCreateRoomHandler SnId:%v Create Sucess GameId:%v", p.SnId, gameId) - // try enter scene - csp.scenes[scene.sceneId] = scene - scene.csp = csp - if !scene.PlayerEnter(p, -1, true) { - code = gamehall.OpResultCode_Game_OPRC_Error_Game - } + if scene != nil && code == gamehall.OpResultCode_Game_OPRC_Sucess_Game { + logger.Logger.Tracef("CSCreateRoomHandler SnId:%v Create Sucess GameId:%v", p.SnId, gameId) + csp.AddScene(scene) + if !scene.PlayerEnter(p, -1, true) { + code = gamehall.OpResultCode_Game_OPRC_Error_Game } } diff --git a/worldsrv/coinscenemgr.go b/worldsrv/coinscenemgr.go index bb300f5..da57922 100644 --- a/worldsrv/coinscenemgr.go +++ b/worldsrv/coinscenemgr.go @@ -23,10 +23,10 @@ var CoinSceneMgrSingleton = &CoinSceneMgr{ playerChanging: make(map[int32]int32), //按平台管理 scenesOfPlatform: make(map[string]map[int32]*CoinScenePool), - platformOfScene: make(map[int32]string), + platformOfScene: make(map[int]string), //按组管理 scenesOfGroup: make(map[int32]map[int32]*CoinScenePool), - groupOfScene: make(map[int32]int32), + groupOfScene: make(map[int]int32), } type CreateRoomCache struct { @@ -39,14 +39,14 @@ type CoinSceneMgr struct { //按平台管理 scenesOfPlatform map[string]map[int32]*CoinScenePool // platform:gamefreeid - platformOfScene map[int32]string // sceneid:platform; 创建房间后记录房间所在平台 + platformOfScene map[int]string // sceneid:platform; 创建房间后记录房间所在平台 //按组管理 scenesOfGroup map[int32]map[int32]*CoinScenePool // groupid:gamefreeid - groupOfScene map[int32]int32 // sceneid:groupid; + groupOfScene map[int]int32 // sceneid:groupid; //延迟创建房间列表 - delayCache []CreateRoomCache // 待预创建房间 + delayCache []*CreateRoomCache // 待预创建房间 } // GetCoinScenePool 获取一个场景池 @@ -72,29 +72,33 @@ func (csm *CoinSceneMgr) GetCoinScenePool(plt string, id int32) *CoinScenePool { } } - var dbGameFree *server_proto.DB_GameFree - if groupId != 0 { - conf := PlatformGameGroupMgrSington.GetGameGroup(groupId) - if conf != nil { - dbGameFree = conf.GetDbGameFree() - } - } - if dbGameFree == nil { - dbGameFree = gf.GetDbGameFree() - } - if dbGameFree == nil { + if gf.GetDbGameFree() == nil { return nil } // 创建了一个新的 // 应该是走不到这里,因为模块启动时所有场次都创建了房间池 - return NewCoinScenePool(plt, groupId, dbGameFree) + pool := newCoinScenePool(plt, groupId, gf.GetDbGameFree()) + if groupId != 0 { + v, ok := csm.scenesOfGroup[groupId] + if !ok || v == nil { + csm.scenesOfGroup[groupId] = make(map[int32]*CoinScenePool) + } + csm.scenesOfGroup[groupId][id] = pool + } else { + v, ok := csm.scenesOfPlatform[plt] + if !ok || v == nil { + csm.scenesOfPlatform[plt] = make(map[int32]*CoinScenePool) + } + csm.scenesOfPlatform[plt][id] = pool + } + return pool } func (csm *CoinSceneMgr) findCoinScenePool(platform string, id int32) (pools map[int32]*CoinScenePool, groupID int32, dbGameFree *server.DB_GameFree) { gf := PlatformMgrSingleton.GetGameFree(platform, id) - if gf == nil { + if gf == nil || gf.GetDbGameFree() == nil { return nil, 0, nil } groupId := gf.GetGroupId() @@ -102,31 +106,24 @@ func (csm *CoinSceneMgr) findCoinScenePool(platform string, id int32) (pools map var ss map[int32]*CoinScenePool var ok bool if groupId != 0 { - pgg := PlatformGameGroupMgrSington.GetGameGroup(groupId) - if pgg != nil { - ss, ok = csm.scenesOfGroup[groupId] - if !ok { - ss = make(map[int32]*CoinScenePool) - csm.scenesOfGroup[groupId] = ss - } - return ss, groupId, pgg.GetDbGameFree() - } - } - - if ss == nil { - ss, ok = csm.scenesOfPlatform[platform] + ss, ok = csm.scenesOfGroup[groupId] if !ok { ss = make(map[int32]*CoinScenePool) - csm.scenesOfPlatform[platform] = ss + csm.scenesOfGroup[groupId] = ss } - return ss, 0, gf.GetDbGameFree() + return ss, groupId, gf.GetDbGameFree() } - return nil, 0, nil + ss, ok = csm.scenesOfPlatform[platform] + if !ok { + ss = make(map[int32]*CoinScenePool) + csm.scenesOfPlatform[platform] = ss + } + return ss, 0, gf.GetDbGameFree() } // PlayerEnter 玩家进入房间池 -func (csm *CoinSceneMgr) PlayerEnter(p *Player, id int32, roomId int32, exclude []int32, ischangeroom bool) hall_proto.OpResultCode { +func (csm *CoinSceneMgr) PlayerEnter(p *Player, id int32, roomId int32, exclude []int32, isChangeRoom bool) hall_proto.OpResultCode { logger.Logger.Tracef("(csm *CoinSceneMgr) PlayerEnter snid:%v id:%v roomid:%v exclude:%v", p.SnId, id, roomId, exclude) if p.isDelete { //删档用户不让进游戏 return hall_proto.OpResultCode_OPRC_RoomHadClosed @@ -144,22 +141,9 @@ func (csm *CoinSceneMgr) PlayerEnter(p *Player, id int32, roomId int32, exclude return hall_proto.OpResultCode_OPRC_Error } - pools, groupID, free := csm.findCoinScenePool(platform.IdStr, id) - if pools == nil { - return hall_proto.OpResultCode_OPRC_RoomHadClosed - } + csp := csm.GetCoinScenePool(platform.IdStr, id) - csp, ok := pools[id] - if !ok || csp == nil { - csp = NewCoinScenePool(platform.IdStr, groupID, free) - if csp == nil { - logger.Logger.Warnf("(csm *CoinSceneMgr) PlayerEnter snid:%v find in id:%v exclude:%v NewCoinScenePool failed", p.SnId, id, exclude) - return hall_proto.OpResultCode_OPRC_Error - } - pools[id] = csp - } - - ret := csp.PlayerEnter(p, roomId, exclude, ischangeroom) + ret := csp.PlayerEnter(p, roomId, exclude, isChangeRoom) logger.Logger.Warnf("(csm *CoinSceneMgr) PlayerEnter snid:%v find in id:%v exclude:%v return false", p.SnId, id, exclude) return ret @@ -244,28 +228,28 @@ func (csm *CoinSceneMgr) PlayerLeave(p *Player, reason int) bool { // OnDestroyScene 解散房间 // sceneId 房间id func (csm *CoinSceneMgr) OnDestroyScene(sceneId int) { - if platformName, ok := csm.platformOfScene[int32(sceneId)]; ok { + if platformName, ok := csm.platformOfScene[sceneId]; ok { if ss, ok := csm.scenesOfPlatform[platformName]; ok { for _, csp := range ss { csp.OnDestroyScene(sceneId) } } - delete(csm.platformOfScene, int32(sceneId)) + delete(csm.platformOfScene, sceneId) } - if groupId, ok := csm.groupOfScene[int32(sceneId)]; ok { + if groupId, ok := csm.groupOfScene[sceneId]; ok { if ss, ok := csm.scenesOfGroup[groupId]; ok { for _, csp := range ss { csp.OnDestroyScene(sceneId) } } - delete(csm.groupOfScene, int32(sceneId)) + delete(csm.groupOfScene, sceneId) } } // GetPlatformBySceneId 获取房间所在平台 func (csm *CoinSceneMgr) GetPlatformBySceneId(sceneId int) string { - if platformName, ok := csm.platformOfScene[int32(sceneId)]; ok { + if platformName, ok := csm.platformOfScene[sceneId]; ok { return platformName } s := SceneMgrSingleton.GetScene(sceneId) @@ -417,76 +401,18 @@ func (csm *CoinSceneMgr) StartChangeCoinSceneTransact(p *Player, id int32, exclu return hall_proto.OpResultCode_OPRC_Error } -// ListRooms 给客户端发送场次房间列表 -// id 场次id -func (csm *CoinSceneMgr) ListRooms(p *Player, id int32) bool { - //多平台支持 - platform := p.GetPlatform() - if platform == nil { - return false - } - - pools, groupID, free := csm.findCoinScenePool(platform.IdStr, id) - if pools == nil { - return false - } - - if csp, ok := pools[id]; ok && csp != nil { - return csp.ListRoom(p) - } - csp := NewCoinScenePool(platform.IdStr, groupID, free) - if csp == nil { - return false - } - pools[id] = csp - return csp.ListRoom(p) -} - -// CreateRoomByCache 创建预创建房间 -// 每2秒创建一次 -func (csm *CoinSceneMgr) CreateRoomByCache() { - cnt := len(csm.delayCache) - if cnt > 0 { - data := csm.delayCache[cnt-1] - csm.delayCache = csm.delayCache[:cnt-1] - pdd := PlatformMgrSingleton.GetGameFree(data.platformName, data.gameFreeId) - //对战场和捕鱼场 预创建 - if pdd != nil && pdd.DbGameFree != nil { - var ss map[int32]*CoinScenePool - var ok bool - //分组模式 - if pdd.GroupId != 0 { - pgg := PlatformGameGroupMgrSington.GetGameGroup(pdd.GroupId) - if pgg != nil { - ss, ok = csm.scenesOfGroup[pdd.GroupId] - if !ok { - ss = make(map[int32]*CoinScenePool) - csm.scenesOfGroup[pdd.GroupId] = ss - } - } - } - //独立模式 - if ss == nil { - ss, ok = csm.scenesOfPlatform[data.platformName] - if !ok { - ss = make(map[int32]*CoinScenePool) - csm.scenesOfPlatform[data.platformName] = ss - } - } - if ss == nil { - return - } - if csp, ok := ss[pdd.DbGameFree.Id]; ok && csp != nil { - csp.PreCreateRoom() - return - } - csp := NewCoinScenePool(data.platformName, 0, pdd.DbGameFree) - if csp != nil { - ss[pdd.DbGameFree.Id] = csp - csp.PreCreateRoom() - return - } - } +// TouchCreateRoom 触发预创建房间 +// 1.模块启动后触发 +// 2.游戏服建立连接后触发 +// 3.房间解散后触发 +func (csm *CoinSceneMgr) TouchCreateRoom(platform string, gameFreeId int32) { + gf := PlatformMgrSingleton.GetGameFree(platform, gameFreeId) + if gf.Status && gf.DbGameFree.GetCreateRoomNum() > 0 { + logger.Logger.Tracef("TouchCreateRoom platform:%v gameFreeId:%v", platform, gameFreeId) + csm.delayCache = append(csm.delayCache, &CreateRoomCache{ + platformName: platform, + gameFreeId: gameFreeId, + }) } } @@ -495,42 +421,14 @@ func (csm *CoinSceneMgr) ModuleName() string { } func (csm *CoinSceneMgr) Init() { - // 场次池预创建 + // 房间池初始化 for _, platform := range PlatformMgrSingleton.GetPlatforms() { if platform.Isolated || platform.IdStr == "" { - arr := srvdata.PBDB_GameFreeMgr.Datas.GetArr() - for _, dbGame := range arr { - gps := PlatformMgrSingleton.GetGameFree(platform.IdStr, dbGame.GetId()) + for _, v := range srvdata.PBDB_GameFreeMgr.Datas.GetArr() { + gps := PlatformMgrSingleton.GetGameFree(platform.IdStr, v.GetId()) if gps != nil { - // dbGameFree - dbGameFree := gps.DbGameFree - if gps.GroupId != 0 { - pgg := PlatformGameGroupMgrSington.GetGameGroup(gps.GroupId) - if pgg != nil { - dbGameFree = pgg.DbGameFree - } - } - // CoinScenePool - csp := NewCoinScenePool(platform.IdStr, gps.GroupId, dbGameFree) - if csp != nil { - if gps.GroupId != 0 { - if ss, exist := csm.scenesOfGroup[gps.GroupId]; exist { - ss[dbGame.GetId()] = csp - } else { - ss = make(map[int32]*CoinScenePool) - ss[dbGame.GetId()] = csp - csm.scenesOfGroup[gps.GroupId] = ss - } - } else { - if ss, exist := csm.scenesOfPlatform[platform.IdStr]; exist { - ss[dbGame.GetId()] = csp - } else { - ss = make(map[int32]*CoinScenePool) - ss[dbGame.GetId()] = csp - csm.scenesOfPlatform[platform.IdStr] = ss - } - } - } + csm.GetCoinScenePool(platform.IdStr, v.GetId()) + csm.TouchCreateRoom(platform.IdStr, v.GetId()) } } } @@ -538,8 +436,18 @@ func (csm *CoinSceneMgr) Init() { } func (csm *CoinSceneMgr) Update() { - // 预创建房间 - csm.CreateRoomByCache() + cnt := len(csm.delayCache) + if cnt > 0 { + data := csm.delayCache[cnt-1] + csm.delayCache = csm.delayCache[:cnt-1] + gf := PlatformMgrSingleton.GetGameFree(data.platformName, data.gameFreeId) + if gf != nil && gf.DbGameFree != nil { + csp := csm.GetCoinScenePool(data.platformName, data.gameFreeId) + if csp != nil { + csp.PreCreateRoom() + } + } + } } func (csm *CoinSceneMgr) Shutdown() { @@ -549,24 +457,15 @@ func (csm *CoinSceneMgr) Shutdown() { //=====================PlatformObserver====================== func (this *CoinSceneMgr) OnPlatformCreate(p *Platform) { - if p.IdStr == DefaultPlatform { - return - } - //获取配置 - gps := PlatformMgrSingleton.GetGameFrees(p.IdStr) - for _, v := range gps { - if v.Status && v.DbGameFree.GetCreateRoomNum() > 0 { - this.delayCache = append(this.delayCache, CreateRoomCache{gameFreeId: v.DbGameFree.Id, platformName: p.IdStr}) - } - } + } func (this *CoinSceneMgr) OnPlatformDestroy(p *Platform) { if p == nil { return } - if csps, ok := this.scenesOfPlatform[p.IdStr]; ok { - for _, csp := range csps { + if v, ok := this.scenesOfPlatform[p.IdStr]; ok { + for _, csp := range v { pack := &server_proto.WGGraceDestroyScene{} for _, scene := range csp.scenes { pack.Ids = append(pack.Ids, int32(scene.sceneId)) @@ -577,12 +476,6 @@ func (this *CoinSceneMgr) OnPlatformDestroy(p *Platform) { } } -func (this *CoinSceneMgr) OnPlatformChangeIsolated(p *Platform, isolated bool) { - if !isolated { - this.OnPlatformDestroy(p) - } -} - func (this *CoinSceneMgr) OnPlatformChangeDisabled(p *Platform, disabled bool) { if disabled { this.OnPlatformDestroy(p) @@ -613,13 +506,6 @@ func (this *CoinSceneMgr) OnPlatformGameFreeUpdate(p *Platform, oldCfg, newCfg * } srvlib.ServerSessionMgrSington.Broadcast(int(server_proto.SSPacketID_PACKET_WG_GRACE_DESTROYSCENE), pack, common.GetSelfAreaId(), srvlib.GameServerType) - - //预创建房间配置更新 - if newCfg.DbGameFree.GetCreateRoomNum() != 0 && p.IdStr != DefaultPlatform && newCfg.Status { - logger.Logger.Tracef(">>>预创建房间 platform:%v %v_%v gamefreeid:%v CreateRoomNum:%v", p.Name, - newCfg.DbGameFree.GetName(), newCfg.DbGameFree.GetTitle(), newCfg.DbGameFree.GetId(), newCfg.DbGameFree.GetCreateRoomNum()) - this.delayCache = append(this.delayCache, CreateRoomCache{gameFreeId: newCfg.DbGameFree.GetId(), platformName: p.IdStr}) - } } } @@ -683,8 +569,8 @@ func (csm *CoinSceneMgr) OnGameSessionRegiste(gs *GameSession) { //获取配置 gps := PlatformMgrSingleton.GetGameFrees(platform.IdStr) for _, v := range gps { - if v.Status && v.DbGameFree.GetCreateRoomNum() > 0 && (wildGs || common.InSliceInt32(gs.gameIds, v.DbGameFree.GetGameId())) { - csm.delayCache = append(csm.delayCache, CreateRoomCache{gameFreeId: v.DbGameFree.Id, platformName: platform.IdStr}) + if v != nil && (wildGs || common.InSliceInt32(gs.gameIds, v.DbGameFree.GetGameId())) { + csm.TouchCreateRoom(platform.IdStr, v.DbGameFree.Id) } } } diff --git a/worldsrv/coinscenepool.go b/worldsrv/coinscenepool.go index d710354..00da5ab 100644 --- a/worldsrv/coinscenepool.go +++ b/worldsrv/coinscenepool.go @@ -1,10 +1,10 @@ package main import ( + "mongo.games.com/game/common" "mongo.games.com/goserver/core/logger" "mongo.games.com/game/model" - "mongo.games.com/game/proto" gamehallproto "mongo.games.com/game/protocol/gamehall" serverproto "mongo.games.com/game/protocol/server" "mongo.games.com/game/srvdata" @@ -22,14 +22,17 @@ type CoinScenePool struct { // 扩展数据 extraData interface{} - // 匹配规则 + // 房间池规则 policy ICoinScenePool } -func NewCoinScenePool(platform string, groupId int32, dbGameFree *serverproto.DB_GameFree) *CoinScenePool { +func newCoinScenePool(platform string, groupId int32, dbGameFree *serverproto.DB_GameFree) *CoinScenePool { if dbGameFree == nil { return nil } + if platform == "" { + platform = DefaultPlatform + } dbGameRule := srvdata.PBDB_GameRuleMgr.GetData(dbGameFree.GetGameRule()) if dbGameRule == nil { @@ -136,6 +139,20 @@ func (csp *CoinScenePool) CanAudienceEnter(p *Player) gamehallproto.OpResultCode return csp.policy.CanAudienceEnter(csp, p) } +// AddScene 添加房间 +func (csp *CoinScenePool) AddScene(s *Scene) { + if s == nil { + return + } + csp.scenes[s.sceneId] = s + s.csp = csp + if csp.groupId != 0 { + CoinSceneMgrSingleton.groupOfScene[s.sceneId] = csp.groupId + } else { + CoinSceneMgrSingleton.platformOfScene[s.sceneId] = csp.platform + } +} + // PlayerEnter 玩家进入房间池 // exclude 排除的房间id // isChangeRoom 是否换房 @@ -187,8 +204,7 @@ func (csp *CoinScenePool) PlayerEnter(p *Player, roomId int32, exclude []int32, if scene == nil { scene = csp.policy.NewScene(csp, p) if scene != nil { - csp.scenes[scene.sceneId] = scene - scene.csp = csp + csp.AddScene(scene) } else { logger.Logger.Errorf("Create %v scene failed.", csp.id) } @@ -205,7 +221,7 @@ func (csp *CoinScenePool) PlayerEnter(p *Player, roomId int32, exclude []int32, } // AudienceEnter 观众入场 -func (csp *CoinScenePool) AudienceEnter(p *Player, roomId int32, exclude []int32, ischangeroom bool) gamehallproto.OpResultCode { +func (csp *CoinScenePool) AudienceEnter(p *Player, roomId int32, exclude []int32, isChangeRoom bool) gamehallproto.OpResultCode { if ret := csp.CanAudienceEnter(p); ret != gamehallproto.OpResultCode_OPRC_Sucess { logger.Logger.Warnf("(csp *CoinScenePool) AudienceEnter find snid:%v csp.CanEnter coin:%v ret:%v id:%v", p.SnId, p.Coin, ret, csp.dbGameFree.GetId()) return ret @@ -219,7 +235,7 @@ func (csp *CoinScenePool) AudienceEnter(p *Player, roomId int32, exclude []int32 var scene *Scene if roomId != 0 { if s, ok := csp.scenes[int(roomId)]; ok { - if s != nil && !s.deleting /*&& s.sceneId != int(exclude)*/ { + if s != nil && !s.deleting { scene = s } else { logger.Logger.Warnf("(csp *CoinScenePool) AudienceEnter[!s.starting || sp.EnterAfterStart] snid:%v sceneid:%v starting:%v EnterAfterStart:%v", p.SnId, s.sceneId, s.starting) @@ -229,7 +245,7 @@ func (csp *CoinScenePool) AudienceEnter(p *Player, roomId int32, exclude []int32 if scene == nil { var ret gamehallproto.OpResultCode - ret, scene = csp.policy.AudienceEnter(csp, p, exclude, ischangeroom) + ret, scene = csp.policy.AudienceEnter(csp, p, exclude, isChangeRoom) if ret != gamehallproto.OpResultCode_OPRC_Sucess { return ret } @@ -239,16 +255,16 @@ func (csp *CoinScenePool) AudienceEnter(p *Player, roomId int32, exclude []int32 return gamehallproto.OpResultCode_OPRC_NoFindDownTiceRoom } - if scene != nil { - // 预创建房间检查观众数量 - if scene.IsPreCreateScene() && scene.GetAudienceCnt() >= model.GameParamData.MaxAudienceNum { - return gamehallproto.OpResultCode_OPRC_RoomIsFull - } - if scene.AudienceEnter(p, ischangeroom) { - csp.OnPlayerEnter(p, scene) - return gamehallproto.OpResultCode_OPRC_Sucess - } + // 预创建房间检查观众数量 + if scene.IsPreCreateScene() && scene.GetAudienceCnt() >= model.GameParamData.MaxAudienceNum { + return gamehallproto.OpResultCode_OPRC_RoomIsFull } + + if scene.AudienceEnter(p, isChangeRoom) { + csp.OnPlayerEnter(p, scene) + return gamehallproto.OpResultCode_OPRC_Sucess + } + logger.Logger.Warnf("(csp *CoinScenePool) PlayerEnter snid:%v not found scene", p.SnId) return gamehallproto.OpResultCode_OPRC_NoFindDownTiceRoom } @@ -355,13 +371,16 @@ func (csp *CoinScenePool) OnPlayerLeave(s *Scene, p *Player) { } // OnDestroyScene 解散房间 -// todo 是否需要优化 +// 房间解散一定是游戏服确认的,worldsrv收到游戏房间解散消息后解散房间 func (csp *CoinScenePool) OnDestroyScene(sceneId int) { scene, ok := csp.scenes[sceneId] if !ok { return } + logger.Logger.Tracef("(csp *CoinScenePool) OnDestroyScene scene:%v", sceneId) + + // todo 是否需要优化 for id := range scene.players { player := PlayerMgrSington.GetPlayerBySnId(id) if player != nil { @@ -390,6 +409,7 @@ func (csp *CoinScenePool) OnDestroyScene(sceneId int) { csp.policy.OnDestroyScene(csp, sceneId) scene.csp = nil // 解除关联 delete(csp.scenes, sceneId) + CoinSceneMgrSingleton.TouchCreateRoom(csp.platform, csp.dbGameFree.Id) } // PreCreateRoom 预创建房间 @@ -397,68 +417,79 @@ func (csp *CoinScenePool) PreCreateRoom() { if csp.platform == DefaultPlatform { return } - preCreateNum := int(csp.dbGameFree.GetCreateRoomNum()) - if preCreateNum == 0 || model.GameParamData.ClosePreCreateRoom { - return - } if p := PlatformMgrSingleton.GetPlatform(csp.platform); p == nil || p.Disable { return } - var num int - for _, scene := range csp.scenes { - if scene.limitPlatform.IdStr == csp.platform { - num++ - } + preCreateNum := int(csp.dbGameFree.GetCreateRoomNum()) + if preCreateNum <= 0 || model.GameParamData.ClosePreCreateRoom { + return } - if num < preCreateNum { - inc := preCreateNum - num - for i := 0; i < inc; i++ { + num := preCreateNum - csp.GetRoomNum(common.SceneMode_Public) + if num > 0 { + logger.Logger.Tracef("预创建房间 [inc:%v] platform:%v gameFreeId:%v", num, csp.platform, csp.dbGameFree.Id) + for i := 0; i < num; i++ { scene := csp.policy.NewPreCreateScene(csp) if scene != nil { - csp.scenes[scene.sceneId] = scene - scene.csp = csp + csp.AddScene(scene) } } } } -// ListRoom 房间列表 -func (csp *CoinScenePool) ListRoom(p *Player) bool { - if p.scene != nil { - logger.Logger.Warnf("(csp *CoinScenePool) PlayerListRoom[p.scene != nil] find snid:%v in scene:%v gameId:%v", p.SnId, p.scene.sceneId, p.scene.gameId) - return false +func (csp *CoinScenePool) GetRoomNum(mode ...int) int { + tp := 0 + if len(mode) > 0 { + tp = mode[0] } - csp.PreCreateRoom() - - if len(csp.scenes) == 0 { - return false - } - - pack := &gamehallproto.SCCoinSceneListRoom{ - Id: csp.dbGameFree.Id, - LimitCoin: csp.dbGameFree.LimitCoin, - MaxCoinLimit: csp.dbGameFree.MaxCoinLimit, - BaseScore: csp.dbGameFree.BaseScore, - MaxScore: csp.dbGameFree.MaxChip, - OtherIntParams: csp.dbGameFree.OtherIntParams, - } - - maxPlayerNum := 0 - for sceneId, s := range csp.scenes { - data := &gamehallproto.CoinSceneInfo{ - SceneId: proto.Int(sceneId), - PlayerNum: proto.Int(len(s.players)), + var num int + for _, scene := range csp.scenes { + if tp > 0 { + if scene.IsSceneMode(tp) { + num++ + } + } else { + num++ } - pack.Datas = append(pack.Datas, data) - maxPlayerNum = s.playerNum } - pack.MaxPlayerNum = proto.Int(maxPlayerNum) - proto.SetDefaults(pack) - p.SendToClient(int(gamehallproto.CoinSceneGamePacketID_PACKET_SC_COINSCENE_LISTROOM), pack) - return true + return num } +// ListRoom 房间列表 +//func (csp *CoinScenePool) ListRoom(p *Player) bool { +// if p.scene != nil { +// logger.Logger.Warnf("(csp *CoinScenePool) PlayerListRoom[p.scene != nil] find snid:%v in scene:%v gameId:%v", p.SnId, p.scene.sceneId, p.scene.gameId) +// return false +// } +// +// if len(csp.scenes) == 0 { +// return false +// } +// +// pack := &gamehallproto.SCCoinSceneListRoom{ +// Id: csp.dbGameFree.Id, +// LimitCoin: csp.dbGameFree.LimitCoin, +// MaxCoinLimit: csp.dbGameFree.MaxCoinLimit, +// BaseScore: csp.dbGameFree.BaseScore, +// MaxScore: csp.dbGameFree.MaxChip, +// OtherIntParams: csp.dbGameFree.OtherIntParams, +// } +// +// maxPlayerNum := 0 +// for sceneId, s := range csp.scenes { +// data := &gamehallproto.CoinSceneInfo{ +// SceneId: proto.Int(sceneId), +// PlayerNum: proto.Int(len(s.players)), +// } +// pack.Datas = append(pack.Datas, data) +// maxPlayerNum = s.playerNum +// } +// pack.MaxPlayerNum = proto.Int(maxPlayerNum) +// proto.SetDefaults(pack) +// p.SendToClient(int(gamehallproto.CoinSceneGamePacketID_PACKET_SC_COINSCENE_LISTROOM), pack) +// return true +//} + // GetHasTruePlayerSceneCnt 有真人的房间数量 func (csp *CoinScenePool) GetHasTruePlayerSceneCnt() int { cnt := 0 diff --git a/worldsrv/coinscenepool_base.go b/worldsrv/coinscenepool_base.go index fdab485..670d816 100644 --- a/worldsrv/coinscenepool_base.go +++ b/worldsrv/coinscenepool_base.go @@ -34,7 +34,7 @@ func (this *BaseCoinScenePool) CanEnter(pool *CoinScenePool, p *Player) gamehall } // 通用入场检测 - if pool.dbGameFree.GetLimitCoin() != 0 && int64(pool.dbGameFree.GetLimitCoin()) > p.Coin { + if pool.dbGameFree.GetLimitCoin() != 0 && pool.dbGameFree.GetLimitCoin() > p.Coin && !p.IsRob { return gamehall.OpResultCode_OPRC_CoinNotEnough } if pool.dbGameFree.GetMaxCoinLimit() != 0 && int64(pool.dbGameFree.GetMaxCoinLimit()) < p.Coin && !p.IsRob { @@ -67,6 +67,10 @@ func (this *BaseCoinScenePool) PlayerEnter(pool *CoinScenePool, p *Player, exclu } if !common.Config.IsDevMode { + // 私人房 + if s.IsPrivateScene() { + continue + } // 禁止真人匹配 if matchTrueManRule == MatchTrueManForbid && !p.IsRob && s.GetTruePlayerCnt() != 0 { continue @@ -94,7 +98,7 @@ func (this *BaseCoinScenePool) PlayerEnter(pool *CoinScenePool, p *Player, exclu } //优先黑白名单 - if scene == nil && len(scenes) != 0 { + if len(scenes) != 0 { gameId := pool.dbGameFree.GetGameId() if p.WBLevel < 0 { //黑名单玩家 var cntWhite int @@ -172,22 +176,13 @@ func (this *BaseCoinScenePool) PlayerEnter(pool *CoinScenePool, p *Player, exclu if scene == nil && len(scenes) != 0 { //1.其次游戏的配桌规则 - if scene == nil { - matchFunc := GetCoinSceneMatchFunc(int(gameId)) - if matchFunc != nil { - scene = matchFunc(pool, p, scenes, sameIpLimit, exclude) - return gamehall.OpResultCode_OPRC_Sucess, scene - } + matchFunc := GetCoinSceneMatchFunc(int(gameId)) + if matchFunc != nil { + scene = matchFunc(pool, p, scenes, sameIpLimit, exclude) + return gamehall.OpResultCode_OPRC_Sucess, scene } } } - // 随机 - if scene == nil { - for _, v := range scenes { - scene = v - break - } - } } return gamehall.OpResultCode_OPRC_Sucess, scene @@ -219,36 +214,22 @@ func (this *BaseCoinScenePool) NewScene(pool *CoinScenePool, p *Player) *Scene { gameId := int(pool.dbGameRule.GetGameId()) gs := GameSessMgrSington.GetMinLoadSess(gameId) if gs == nil { - logger.Logger.Errorf("Get %v game min session failed.", gameId) + logger.Logger.Warnf("Get %v game min session failed.", gameId) return nil } gameMode := pool.dbGameRule.GetGameMode() params := common.CopySliceInt32ToInt64(pool.dbGameRule.GetParams()) - var platformName string limitPlatform := PlatformMgrSingleton.GetPlatform(pool.platform) if limitPlatform == nil || !limitPlatform.Isolated { limitPlatform = PlatformMgrSingleton.GetPlatform(DefaultPlatform) - platformName = DefaultPlatform - } else { - platformName = limitPlatform.IdStr } sceneId := SceneMgrSingleton.GenOneCoinSceneId() - scene := SceneMgrSingleton.CreateScene(0, 0, sceneId, gameId, int(gameMode), int(common.SceneMode_Public), - 1, -1, params, gs, limitPlatform, pool.groupId, pool.dbGameFree, int32(pool.id)) - if scene != nil { - scene.hallId = pool.id - scene.csp = pool - if pool.groupId != 0 { - CoinSceneMgrSingleton.groupOfScene[int32(sceneId)] = pool.groupId - } else { - CoinSceneMgrSingleton.platformOfScene[int32(sceneId)] = platformName - } - return scene - } - return nil + scene := SceneMgrSingleton.CreateScene(0, 0, sceneId, gameId, int(gameMode), common.SceneMode_Public, + 1, -1, params, gs, limitPlatform, pool.groupId, pool.dbGameFree, pool.id) + return scene } func (this *BaseCoinScenePool) NewPreCreateScene(pool *CoinScenePool) *Scene { diff --git a/worldsrv/coinscenepool_interface.go b/worldsrv/coinscenepool_interface.go index 4e64993..144216a 100644 --- a/worldsrv/coinscenepool_interface.go +++ b/worldsrv/coinscenepool_interface.go @@ -6,7 +6,7 @@ import ( var coinScenePools = map[int32]ICoinScenePool{} -// RegisterCoinScenePool 注册游戏匹配规则 +// RegisterCoinScenePool 注册房间池规则 func RegisterCoinScenePool(gameId int32, policy ICoinScenePool) { coinScenePools[gameId] = policy } @@ -15,21 +15,36 @@ func GetCoinScenePool(gameId int32) ICoinScenePool { return coinScenePools[gameId] } +// ICoinScenePool 定义房间池规则的接口 +// 公共处理逻辑可以写在 CoinScenePool,不能满足需求时再实现 ICoinScenePool type ICoinScenePool interface { + // New 创建房间池 New() interface{} + // CanEnter 玩家是否可以进入 CanEnter(pool *CoinScenePool, p *Player) gamehall.OpResultCode + // CanAudienceEnter 观众是否可以进入 CanAudienceEnter(pool *CoinScenePool, p *Player) gamehall.OpResultCode - PlayerEnter(pool *CoinScenePool, p *Player, exclude []int32, ischangeroom bool) (ret gamehall.OpResultCode, scene *Scene) - AudienceEnter(pool *CoinScenePool, p *Player, exclude []int32, ischangeroom bool) (ret gamehall.OpResultCode, scene *Scene) + // PlayerEnter 玩家进入(匹配房间) + // exclude 排除的房间列表 + // isChangeRoom 是否是换房间 + PlayerEnter(pool *CoinScenePool, p *Player, exclude []int32, isChangeRoom bool) (ret gamehall.OpResultCode, scene *Scene) + // AudienceEnter 观众进入(匹配房间) + AudienceEnter(pool *CoinScenePool, p *Player, exclude []int32, isChangeRoom bool) (ret gamehall.OpResultCode, scene *Scene) + // OnPlayerEnter 玩家进入房间之后 OnPlayerEnter(pool *CoinScenePool, p *Player, scene *Scene) + // PlayerLeave 玩家离开 PlayerLeave(pool *CoinScenePool, p *Player, reason int) bool + // AudienceLeave 观众离开 AudienceLeave(pool *CoinScenePool, p *Player, reason int) bool + // OnPlayerLeave 玩家离开房间之后 OnPlayerLeave(pool *CoinScenePool, s *Scene, p *Player) + // NewScene 创建房间 NewScene(pool *CoinScenePool, p *Player) *Scene + // NewPreCreateScene 创建预创建房间 NewPreCreateScene(pool *CoinScenePool) *Scene - + // OnDestroyScene 房间解散之后 OnDestroyScene(pool *CoinScenePool, sceneId int) } diff --git a/worldsrv/coinscenepool_local.go b/worldsrv/coinscenepool_local.go index f726859..d458859 100644 --- a/worldsrv/coinscenepool_local.go +++ b/worldsrv/coinscenepool_local.go @@ -8,7 +8,7 @@ import ( "mongo.games.com/game/common" "mongo.games.com/game/model" "mongo.games.com/game/protocol/gamehall" - server_proto "mongo.games.com/game/protocol/server" + serverproto "mongo.games.com/game/protocol/server" "mongo.games.com/game/srvdata" ) @@ -30,7 +30,7 @@ type CoinScenePoolLocal struct { BaseCoinScenePool } -func (this *CoinScenePoolLocal) PlayerEnter(pool *CoinScenePool, p *Player, exclude []int32, ischangeroom bool) (ret gamehall.OpResultCode, scene *Scene) { +func (l *CoinScenePoolLocal) PlayerEnter(pool *CoinScenePool, p *Player, exclude []int32, isChangeRoom bool) (ret gamehall.OpResultCode, scene *Scene) { // 配房规则 // 如果全局为限制则看具体的游戏是否限制,如果全局为不限制则不考虑具体的游戏。 sameIpLimit := !model.GameParamData.SameIpNoLimit @@ -42,12 +42,12 @@ func (this *CoinScenePoolLocal) PlayerEnter(pool *CoinScenePool, p *Player, excl matchTrueManRule := pool.dbGameFree.GetMatchTrueMan() //根据携带金额取进房间底注 DB_Createroom - var dbCreateRoom *server_proto.DB_Createroom + var dbCreateRoom *serverproto.DB_Createroom gameId := pool.dbGameFree.GetGameId() dbCreateRoom = srvdata.CreateRoomMgrSington.GetDataByGameIdWithTakeCoin(gameId, p.Coin) if dbCreateRoom == nil { - logger.Logger.Warnf("(csp *CoinScenePool) PlayerEnter(robot:%v, exclude:%v, ischangeroom:%v) no found scene from DB_Createroom", - p.SnId, exclude, ischangeroom) + logger.Logger.Warnf("(csp *CoinScenePool) PlayerEnter(robot:%v, exclude:%v, isChangeRoom:%v) no found scene from DB_Createroom", + p.SnId, exclude, isChangeRoom) return gamehall.OpResultCode_OPRC_Error, nil } @@ -58,6 +58,10 @@ func (this *CoinScenePoolLocal) PlayerEnter(pool *CoinScenePool, p *Player, excl } if !common.Config.IsDevMode { + // 私人房 + if s.IsPrivateScene() { + continue + } // 禁止真人匹配 if matchTrueManRule == MatchTrueManForbid && !p.IsRob && s.GetTruePlayerCnt() != 0 { continue @@ -81,7 +85,7 @@ func (this *CoinScenePoolLocal) PlayerEnter(pool *CoinScenePool, p *Player, excl } } //根据携带金额取可进房间 - if dbCreateRoom != nil && len(dbCreateRoom.GetBetRange()) != 0 { + if len(dbCreateRoom.GetBetRange()) != 0 { betRange := dbCreateRoom.GetBetRange() if common.InSliceInt32(betRange, s.BaseScore) { scenes[sceneId] = s @@ -92,7 +96,7 @@ func (this *CoinScenePoolLocal) PlayerEnter(pool *CoinScenePool, p *Player, excl } //优先黑白名单 - if scene == nil && len(scenes) != 0 { + if len(scenes) != 0 { gameId := pool.dbGameFree.GetGameId() if p.WBLevel < 0 { //黑名单玩家 var cntWhite int @@ -151,7 +155,7 @@ func (this *CoinScenePoolLocal) PlayerEnter(pool *CoinScenePool, p *Player, excl } } else { //按类型匹配 //优先真人 - if scene == nil && len(scenes) != 0 && matchTrueManRule == MatchTrueManPriority { + if len(scenes) != 0 && matchTrueManRule == MatchTrueManPriority { var selScene []*Scene for _, value := range scenes { if value != nil { @@ -170,11 +174,9 @@ func (this *CoinScenePoolLocal) PlayerEnter(pool *CoinScenePool, p *Player, excl if scene == nil && len(scenes) != 0 { //1.其次游戏的配桌规则 - if scene == nil { - matchFunc := GetCoinSceneMatchFunc(int(gameId)) - if matchFunc != nil { - scene = matchFunc(pool, p, scenes, sameIpLimit, exclude) - } + matchFunc := GetCoinSceneMatchFunc(int(gameId)) + if matchFunc != nil { + scene = matchFunc(pool, p, scenes, sameIpLimit, exclude) } } } @@ -183,7 +185,7 @@ func (this *CoinScenePoolLocal) PlayerEnter(pool *CoinScenePool, p *Player, excl return gamehall.OpResultCode_OPRC_Sucess, scene } -func (this *CoinScenePoolLocal) NewScene(pool *CoinScenePool, p *Player) *Scene { +func (l *CoinScenePoolLocal) NewScene(pool *CoinScenePool, p *Player) *Scene { gameId := int(pool.dbGameFree.GetGameId()) gs := GameSessMgrSington.GetMinLoadSess(gameId) if gs == nil { @@ -194,20 +196,16 @@ func (this *CoinScenePoolLocal) NewScene(pool *CoinScenePool, p *Player) *Scene sceneId := SceneMgrSingleton.GenOneCoinSceneId() params := pool.dbGameRule.GetParams() - var platformName string limitPlatform := PlatformMgrSingleton.GetPlatform(pool.platform) if limitPlatform == nil || !limitPlatform.Isolated { limitPlatform = PlatformMgrSingleton.GetPlatform(DefaultPlatform) - platformName = DefaultPlatform - } else { - platformName = limitPlatform.IdStr } //根据携带金额取可创房间 DB_Createroom baseScore := int32(0) gameSite := 0 playerTakeCoin := p.Coin - var dbCreateRoom *server_proto.DB_Createroom + var dbCreateRoom *serverproto.DB_Createroom arrs := srvdata.PBDB_CreateroomMgr.Datas.Arr for i := len(arrs) - 1; i >= 0; i-- { if arrs[i].GetGameId() == int32(gameId) { @@ -236,33 +234,23 @@ func (this *CoinScenePoolLocal) NewScene(pool *CoinScenePool, p *Player) *Scene scene := SceneMgrSingleton.CreateLocalGameScene(p.SnId, sceneId, gameId, gameSite, common.SceneMode_Public, 1, common.CopySliceInt32ToInt64(params), gs, limitPlatform, 0, pool.dbGameFree, baseScore, pool.groupId, pool.id) - if scene != nil { - scene.hallId = pool.id - scene.groupId = pool.groupId - CoinSceneMgrSingleton.platformOfScene[int32(sceneId)] = platformName - return scene - } - return nil + return scene } -func (this *CoinScenePoolLocal) NewPreCreateScene(pool *CoinScenePool) *Scene { +func (l *CoinScenePoolLocal) NewPreCreateScene(pool *CoinScenePool) *Scene { gameId := int(pool.dbGameRule.GetGameId()) gs := GameSessMgrSington.GetMinLoadSess(gameId) if gs == nil { - logger.Logger.Errorf("Get %v game min session failed.", gameId) + logger.Logger.Warnf("Get %v game min session failed.", gameId) return nil } sceneId := SceneMgrSingleton.GenOneCoinSceneId() params := pool.dbGameRule.GetParams() - var platformName string limitPlatform := PlatformMgrSingleton.GetPlatform(pool.platform) if limitPlatform == nil || !limitPlatform.Isolated { limitPlatform = PlatformMgrSingleton.GetPlatform(DefaultPlatform) - platformName = DefaultPlatform - } else { - platformName = limitPlatform.IdStr } var scene *Scene @@ -274,7 +262,7 @@ func (this *CoinScenePoolLocal) NewPreCreateScene(pool *CoinScenePool) *Scene { //根据SceneType随机可创房间 DB_Createroom baseScore := int32(0) gameSite := 0 - var dbCreateRooms []*server_proto.DB_Createroom + var dbCreateRooms []*serverproto.DB_Createroom arrs := srvdata.PBDB_CreateroomMgr.Datas.Arr for i := len(arrs) - 1; i >= 0; i-- { if arrs[i].GetGameId() == int32(gameId) && arrs[i].GetGameSite() == pool.dbGameFree.GetSceneType() { @@ -303,16 +291,5 @@ func (this *CoinScenePoolLocal) NewPreCreateScene(pool *CoinScenePool) *Scene { } } } - - if scene != nil { - scene.hallId = pool.id - scene.csp = pool - if pool.groupId != 0 { - CoinSceneMgrSingleton.groupOfScene[int32(sceneId)] = pool.groupId - } else { - CoinSceneMgrSingleton.platformOfScene[int32(sceneId)] = platformName - } - return scene - } - return nil + return scene } diff --git a/worldsrv/gamesess.go b/worldsrv/gamesess.go index bce0b9d..eb7339a 100644 --- a/worldsrv/gamesess.go +++ b/worldsrv/gamesess.go @@ -222,7 +222,6 @@ func (this *GameSession) AddScene(s *Scene) { func (this *GameSession) DelScene(s *Scene) { delete(this.scenes, s.sceneId) - //from gameserver, so don't need send msg } func (this *GameSession) AddPlayer(p *Player) { diff --git a/worldsrv/minigamemgr.go b/worldsrv/minigamemgr.go index bb89706..33dce86 100644 --- a/worldsrv/minigamemgr.go +++ b/worldsrv/minigamemgr.go @@ -18,7 +18,7 @@ package main // scenesOfPlatform: make(map[string]map[int32]*Scene), // //玩家当前打开的小游戏列表 // playerGaming: make(map[int32]map[int32]*Scene), -// autoId: common.MiniGameSceneStartId, +// matchAutoId: common.MiniGameSceneStartId, //} // //type MiniGameMgr struct { @@ -27,15 +27,15 @@ package main // scenesOfPlatform map[string]map[int32]*Scene // //玩家当前打开的小游戏列表 // playerGaming map[int32]map[int32]*Scene -// autoId int +// matchAutoId int //} // //func (this *MiniGameMgr) GenOneSceneId() int { -// this.autoId++ -// if this.autoId > common.MiniGameSceneMaxId { -// this.autoId = common.MiniGameSceneStartId +// this.matchAutoId++ +// if this.matchAutoId > common.MiniGameSceneMaxId { +// this.matchAutoId = common.MiniGameSceneStartId // } -// return this.autoId +// return this.matchAutoId //} // //func (this *MiniGameMgr) PlayerEnter(p *Player, id int32) mngame.MNGameOpResultCode { diff --git a/worldsrv/scene.go b/worldsrv/scene.go index 790d478..cb9b3c1 100644 --- a/worldsrv/scene.go +++ b/worldsrv/scene.go @@ -952,23 +952,6 @@ func (this *Scene) ForceDelete(isManual bool) { proto.SetDefaults(pack) this.SendToGame(int(serverproto.SSPacketID_PACKET_WG_DESTROYSCENE), pack) logger.Logger.Warnf("(this *Scene) ForceDelete() sceneid=%v", this.sceneId) - - //if this.sceneId == SceneMgrSingleton.GetDgSceneId() { - // for _, value := range PlayerMgrSington.sidMap { - // if value.scene == nil { - // continue - // } - // if value.scene.sceneId == SceneMgrSingleton.GetDgSceneId() { - // value.DgGameLogout() - // pack := &hallproto.SCLeaveDgGame{} - // pack.OpRetCode = hallproto.OpResultCode_Game_OPRC_Sucess_Game - // value.SendToClient(int(hallproto.GameHallPacketID_PACKET_SC_LEAVEDGGAME), pack) - // } - // } - //} - if this.IsPreCreateScene() { - CoinSceneMgrSingleton.delayCache = append(CoinSceneMgrSingleton.delayCache, CreateRoomCache{gameFreeId: this.dbGameFree.GetId(), platformName: this.limitPlatform.IdStr}) - } } func (this *Scene) Shutdown() { @@ -1007,6 +990,10 @@ func (this *Scene) IsPrivateScene() bool { return this.sceneId >= common.PrivateSceneStartId && this.sceneId < common.PrivateSceneMaxId || this.sceneMode == common.SceneMode_Private } +func (this *Scene) IsSceneMode(mode int) bool { + return this.sceneMode == mode +} + func (this *Scene) IsRankMatch() bool { if this.dbGameFree == nil { return false diff --git a/worldsrv/scenemgr.go b/worldsrv/scenemgr.go index 1641571..8d03634 100644 --- a/worldsrv/scenemgr.go +++ b/worldsrv/scenemgr.go @@ -10,7 +10,6 @@ import ( "mongo.games.com/game/model" serverproto "mongo.games.com/game/protocol/server" webapi2 "mongo.games.com/game/protocol/webapi" - "mongo.games.com/game/srvdata" "mongo.games.com/game/webapi" ) @@ -20,7 +19,8 @@ func init() { var SceneMgrSingleton = &SceneMgr{ scenes: make(map[int]*Scene), - autoId: common.MatchSceneStartId, + privateAutoId: common.PrivateSceneStartId, + matchAutoId: common.MatchSceneStartId, coinSceneAutoId: common.CoinSceneStartId, hundredSceneAutoId: common.HundredSceneStartId, } @@ -29,8 +29,9 @@ var SceneMgrSingleton = &SceneMgr{ type SceneMgr struct { BaseClockSinker // 驱动时间事件 - scenes map[int]*Scene // sceneid:Scene - autoId int // 比赛场房间号 + scenes map[int]*Scene // 房间id: Scene + privateAutoId int // 私人房房间号 + matchAutoId int // 比赛场房间号 coinSceneAutoId int // 金币场房间号 hundredSceneAutoId int // 百人场房间号 } @@ -41,6 +42,15 @@ func (m *SceneMgr) AllocReplayCode() string { return code } +// GenOnePrivateSceneId 生产一个私人房间id +func (m *SceneMgr) GenOnePrivateSceneId() int { + m.privateAutoId++ + if m.privateAutoId > common.PrivateSceneMaxId { + m.privateAutoId = common.PrivateSceneStartId + } + return m.privateAutoId +} + // GenOneCoinSceneId 生产一个金币场房间id func (m *SceneMgr) GenOneCoinSceneId() int { m.coinSceneAutoId++ @@ -61,11 +71,11 @@ func (m *SceneMgr) GenOneHundredSceneId() int { // GenOneMatchSceneId 生产一个比赛场房间id func (m *SceneMgr) GenOneMatchSceneId() int { - m.autoId++ - if m.autoId > common.MatchSceneMaxId { - m.autoId = common.MatchSceneStartId + m.matchAutoId++ + if m.matchAutoId > common.MatchSceneMaxId { + m.matchAutoId = common.MatchSceneStartId } - return m.autoId + return m.matchAutoId } // GetScene 获取房间对象 @@ -81,7 +91,10 @@ func (m *SceneMgr) GetScenesByGame(gameId int) []*Scene { var scenes []*Scene for _, value := range m.scenes { if value.gameId == gameId { - scenes = append(scenes, value) + s := m.GetScene(value.sceneId) + if s != nil { + scenes = append(scenes, value) + } } } return scenes @@ -92,7 +105,10 @@ func (m *SceneMgr) GetScenesByGameFreeId(gameFreeId int32) []*Scene { var scenes []*Scene for _, value := range m.scenes { if value.dbGameFree.GetId() == gameFreeId { - scenes = append(scenes, value) + s := m.GetScene(value.sceneId) + if s != nil { + scenes = append(scenes, value) + } } } return scenes @@ -336,29 +352,29 @@ func (m *SceneMgr) OnPlayerLeaveScene(s *Scene, p *Player) { } // GetThirdScene 获取三方游戏房间 -func (m *SceneMgr) GetThirdScene(i webapi.IThirdPlatform) *Scene { - if i == nil { - return nil - } - sceneId := i.GetPlatformBase().SceneId - scene := m.scenes[sceneId] - if scene != nil { - return scene - } - - gs := GameSessMgrSington.GetMinLoadSess(i.GetPlatformBase().BaseGameID) - if gs != nil { - limitPlatform := PlatformMgrSingleton.GetPlatform(DefaultPlatform) - var gameMode = common.SceneMode_Thr - dbGameFree := srvdata.PBDB_GameFreeMgr.GetData(i.GetPlatformBase().VultGameID) - scene := SceneMgrSingleton.CreateScene(0, 0, sceneId, i.GetPlatformBase().BaseGameID, gameMode, int(common.SceneMode_Thr), 1, -1, - []int64{}, gs, limitPlatform, 0, dbGameFree, i.GetPlatformBase().VultGameID) - return scene - } else { - logger.Logger.Errorf("Get %v game min session failed.", i.GetPlatformBase().BaseGameID) - return nil - } -} +//func (m *SceneMgr) GetThirdScene(i webapi.IThirdPlatform) *Scene { +// if i == nil { +// return nil +// } +// sceneId := i.GetPlatformBase().SceneId +// scene := m.scenes[sceneId] +// if scene != nil { +// return scene +// } +// +// gs := GameSessMgrSington.GetMinLoadSess(i.GetPlatformBase().BaseGameID) +// if gs != nil { +// limitPlatform := PlatformMgrSingleton.GetPlatform(DefaultPlatform) +// var gameMode = common.SceneMode_Thr +// dbGameFree := srvdata.PBDB_GameFreeMgr.GetData(i.GetPlatformBase().VultGameID) +// scene := SceneMgrSingleton.CreateScene(0, 0, sceneId, i.GetPlatformBase().BaseGameID, gameMode, int(common.SceneMode_Thr), 1, -1, +// []int64{}, gs, limitPlatform, 0, dbGameFree, i.GetPlatformBase().VultGameID) +// return scene +// } else { +// logger.Logger.Errorf("Get %v game min session failed.", i.GetPlatformBase().BaseGameID) +// return nil +// } +//} //=========================ClockSinker=============================== @@ -373,12 +389,19 @@ func (m *SceneMgr) OnMiniTimer() { if webapi.ThridPlatformMgrSington.FindPlatformByPlatformBaseGameId(s.gameId) != nil { continue } - if s.IsCoinScene() { - if s.IsLongTimeInactive() && s.dbGameFree.GetCreateRoomNum() == 0 { //预创建的房间,暂不过期销毁,判定依据:CreateRoomNum>0 - logger.Logger.Warnf("SceneMgr.DeleteLongTimeInactive CoinScene ForceDelete scene:%v IsLongTimeInactive", s.sceneId) - s.ForceDelete(false) + switch { + case s.IsCoinScene(): + if s.IsLongTimeInactive() { + if s.dbGameFree.GetCreateRoomNum() == 0 { + logger.Logger.Warnf("SceneMgr.DeleteLongTimeInactive CoinScene ForceDelete scene:%v IsLongTimeInactive", s.sceneId) + s.ForceDelete(false) + } + if s.dbGameFree.GetCreateRoomNum() > 0 && s.csp != nil && s.csp.GetRoomNum() > int(s.dbGameFree.GetCreateRoomNum()) { + logger.Logger.Warnf("SceneMgr.DeleteLongTimeInactive CoinScene ForceDelete scene:%v IsLongTimeInactive", s.sceneId) + s.ForceDelete(false) + } } - } else if s.IsPrivateScene() { + case s.IsPrivateScene(): if s.IsLongTimeInactive() { logger.Logger.Warnf("SceneMgr.DeleteLongTimeInactive PrivateScene ForceDelete scene:%v IsLongTimeInactive", s.sceneId) s.ForceDelete(false)