From 07b985693edde5b7b7f19fc51068b67e4b519838 Mon Sep 17 00:00:00 2001 From: sk <123456@qq.com> Date: Sat, 7 Sep 2024 18:06:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/constant.go | 90 ++++---------------------- gamesrv/base/scene.go | 21 +++--- gamesrv/tienlen/scenepolicy_tienlen.go | 2 +- model/coinpoolsetting.go | 15 ----- robot/fishing/fishscene.go | 8 --- robot/thirteen/thirteenwaterscene.go | 2 +- worldsrv/action_friend.go | 4 +- worldsrv/action_game.go | 8 +-- worldsrv/action_server.go | 30 ++++----- worldsrv/coinscenepool.go | 2 +- worldsrv/coinscenepool_base.go | 2 +- worldsrv/coinscenepool_local.go | 4 +- worldsrv/gamesess.go | 5 ++ worldsrv/hundredscenemgr.go | 2 +- worldsrv/matchcontext.go | 1 - worldsrv/matchscenemgr.go | 78 +++++++++------------- worldsrv/player.go | 21 +----- worldsrv/scene.go | 33 +++++----- worldsrv/scenemgr.go | 79 +++++++++------------- 19 files changed, 136 insertions(+), 271 deletions(-) diff --git a/common/constant.go b/common/constant.go index ba96eb7..f8f3eb0 100644 --- a/common/constant.go +++ b/common/constant.go @@ -176,27 +176,24 @@ func IsDaZhong(gameId int) bool { // 房间编号区间 const ( - PrivateSceneStartId = 100000 - PrivateSceneMaxId = 999999 - MatchSceneStartId = 100000000 - MatchSceneMaxId = 199999999 - HundredSceneStartId = 200000000 - HundredSceneMaxId = 299999999 - HallSceneStartId = 300000000 - HallSceneMaxId = 399999999 - MiniGameSceneStartId = 400000000 - MiniGameSceneMaxId = 409999999 - CoinSceneStartId = 1000000000 //区间预留大点,因为队列匹配比较耗id,假定一天100w牌局,那么这个id区间够用1000天 - CoinSceneMaxId = 1999999999 - DgSceneId = 99 + PrivateSceneStartId = 100000 + PrivateSceneMaxId = 999999 + MatchSceneStartId = 100000000 + MatchSceneMaxId = 199999999 + HundredSceneStartId = 200000000 + HundredSceneMaxId = 299999999 + CoinSceneStartId = 1000000000 + CoinSceneMaxId = 1999999999 + DgSceneId = 99 ) // 房间模式 const ( - SceneMode_Public = 0 //公共房间 - SceneMode_Private = 2 //私人房间 - SceneMode_Match = 3 //赛事房间 - SceneMode_Thr = 4 //三方房间 + SceneModePublic = 0 // 公共房间 + SceneModePrivate = 2 // 私人房间 + SceneModeMatch = 3 // 赛事房间 + SceneModeThr = 4 // 三方房间 + SceneModePrivateMatch = 5 // 竞技馆房间 ) const ( @@ -359,30 +356,6 @@ const ( PlayerLeaveReason_AutoState //托管状态踢出房间 ) -// 万分比 -const RATE_BASE_VALUE int32 = 10000 - -const ( - SceneState_Normal int = iota - SceneState_Fishing //鱼潮 -) - -const ( - PlayerType_Rob int32 = 0 - PlayerType_Undefine = 1 - PlayerType_Black = -1 - PlayerType_White = -2 -) - -const ( - CoinPoolAIModel_Default int32 = iota //默认 - CoinPoolAIModel_Normal //正常模式 - CoinPoolAIModel_ShouFen //收分模式 - CoinPoolAIModel_ZheZhong //折中模式 - CoinPoolAIModel_TuFen //吐分 - CoinPoolAIModel_Max // -) - const ( RobotServerType int = 9 RobotServerId = 901 @@ -465,12 +438,6 @@ const ( MatchTrueMan_Priority = 1 //优先匹配真人 ) -const ( - SingleAdjustModeNormal = 0 - SingleAdjustModeWin = 1 - SingleAdjustModeLose = 2 -) - // 自动化标签(程序里产生的全部<0) const ( AutomaticTag_QZNN_Smart int32 = -1 @@ -515,35 +482,6 @@ const ( CodeTypeNo = 3 // 不使用验证码 ) -const ( - ActId_Share int = iota //0.微信分享 - ActId_OnlineReward //1.在线奖励 - ActId_UpgradeAccount //2.升级账号 - ActId_GoldTask //3.财神任务 - ActId_GoldCome //4.财神降临 - ActId_LuckyTurntable //5.转盘活动 - ActId_Yeb //6.余额宝 - ActId_Card //7.周卡月卡 - ActId_RebateTask //8.返利获取 - ActId_IOSINSTALLSTABLE //9.ios安装奖励 - ActId_VipLevelBonus //10.vip日周月等级奖励 - ActId_LoginRandCoin //11.登录红包 - ActId_OnlineRandCoin //12.红包雨 - ActId_MatchSwitch //13.比赛开关 - ActId_PromoterBind //14.手动绑定推广员 - ActId_Lottery //15.彩金池 - ActId_Task //16.活跃任务 - ActId_PROMOTER //17.全民推广 - ActId_Activity //18.活动界面 - ActId_NewYear //19.新年暗号红包活动 - ActId_Guess //20.猜灯谜活动 - ActId_Sign //21.七日签到 - ExchangeId_Alipay //22.兑换到支付宝 - ExchangeId_Bank //23.兑换到银行卡 - ExchangeId_Wechat //24.兑换到微信 - ActId_Max -) - // 匹配模式 const ( MatchMode_Normal int32 = iota //普通匹配 diff --git a/gamesrv/base/scene.go b/gamesrv/base/scene.go index 7f32058..a59680f 100644 --- a/gamesrv/base/scene.go +++ b/gamesrv/base/scene.go @@ -894,8 +894,13 @@ func (this *Scene) Destroy(force bool) { logger.Logger.Trace("(this *Scene) Destroy(force bool) isCompleted", isCompleted) } +// IsSceneMode 房间模式 +func (this *Scene) IsSceneMode(mode int) bool { + return this.SceneMode == int32(mode) +} + func (this *Scene) IsPrivateScene() bool { - return this.SceneId >= common.PrivateSceneStartId && this.SceneId <= common.PrivateSceneMaxId || this.SceneMode == common.SceneMode_Private + return this.IsSceneMode(common.SceneModePrivate) || this.IsSceneMode(common.SceneModePrivateMatch) } // IsFreePublic 自由桌 @@ -910,10 +915,13 @@ func (this *Scene) IsRankMatch() bool { // IsMatchScene 比赛场 func (this *Scene) IsMatchScene() bool { - return this.SceneId >= common.MatchSceneStartId && this.SceneId <= common.MatchSceneMaxId + return this.IsSceneMode(common.SceneModeMatch) } func (this *Scene) IsCustom() bool { + if this.IsSceneMode(common.SceneModePrivateMatch) { + return true + } return this.GetDBGameFree().GetIsCustom() > 0 } @@ -921,12 +929,7 @@ func (this *Scene) IsFull() bool { return len(this.Players) >= this.GetPlayerNum() } -// 大厅场 -func (this *Scene) IsHallScene() bool { - return this.SceneId >= common.HallSceneStartId && this.SceneId <= common.HallSceneMaxId -} - -// 金豆自由场 +// 对战场 func (this *Scene) IsCoinScene() bool { return this.SceneId >= common.CoinSceneStartId && this.SceneId <= common.CoinSceneMaxId } @@ -1547,7 +1550,7 @@ func GetSaveGamePlayerListLogParam(platform, channel, promoter, packageTag, logi } func (this *Scene) SaveFriendRecord(snid int32, isWin int32, billCoin int64, baseScore int32) { - if this.SceneMode == common.SceneMode_Private { + if this.SceneMode == common.SceneModePrivate { return } log := model.NewFriendRecordLogEx(this.Platform, snid, isWin, this.GameId, baseScore, billCoin, int64(this.GetMatch().GetMatchType())) diff --git a/gamesrv/tienlen/scenepolicy_tienlen.go b/gamesrv/tienlen/scenepolicy_tienlen.go index 07d2891..b76f130 100644 --- a/gamesrv/tienlen/scenepolicy_tienlen.go +++ b/gamesrv/tienlen/scenepolicy_tienlen.go @@ -896,7 +896,7 @@ func (this *SceneWaitStartStateTienLen) OnTick(s *base.Scene) { return } } - if sceneEx.SceneMode == common.SceneMode_Public { + if sceneEx.SceneMode == common.SceneModePublic { if time.Now().Sub(sceneEx.StateStartTime) > rule.TienLenWaitStartTimeout { if sceneEx.Creator != 0 && sceneEx.GetRealPlayerNum() == 0 { sceneEx.Destroy(true) diff --git a/model/coinpoolsetting.go b/model/coinpoolsetting.go index 5f04f2d..93c1d43 100644 --- a/model/coinpoolsetting.go +++ b/model/coinpoolsetting.go @@ -5,7 +5,6 @@ import ( "mongo.games.com/game/protocol/server" "time" - "github.com/globalsign/mgo" "github.com/globalsign/mgo/bson" "mongo.games.com/goserver/core/logger" ) @@ -125,17 +124,3 @@ func ManageCoinPoolSetting(dbSetting *CoinPoolSetting) { } CoinPoolSettingDatas[key] = dbSetting } - -// 删除水池历史调控记录 -func RemoveCoinPoolSettingHis(ts time.Time) (*mgo.ChangeInfo, error) { - if rpcCli == nil { - return nil, ErrRPClientNoConn - } - var ret mgo.ChangeInfo - err := rpcCli.CallWithTimeout("CoinPoolSettingSvc.RemoveCoinPoolSettingHis", ts, &ret, time.Second*30) - if err != nil { - logger.Logger.Warn("RemoveCoinPoolSettingHis error:", err) - return &ret, err - } - return &ret, err -} diff --git a/robot/fishing/fishscene.go b/robot/fishing/fishscene.go index 7948626..7e08889 100644 --- a/robot/fishing/fishscene.go +++ b/robot/fishing/fishscene.go @@ -104,14 +104,6 @@ func (this *FishingScene) IsFull() bool { return len(this.players) >= int(fishing.MaxPlayer) } -func (this *FishingScene) IsMatchScene() bool { - return this.GetRoomId() >= common.MatchSceneStartId && this.GetRoomId() <= common.MatchSceneMaxId -} - -func (this *FishingScene) IsCoinScene() bool { - return this.GetRoomId() >= common.CoinSceneStartId && this.GetRoomId() <= common.CoinSceneMaxId -} - func (this *FishingScene) InitPlayer(s *netlib.Session, p *FishingPlayer) { } diff --git a/robot/thirteen/thirteenwaterscene.go b/robot/thirteen/thirteenwaterscene.go index 05ba78f..efc333e 100644 --- a/robot/thirteen/thirteenwaterscene.go +++ b/robot/thirteen/thirteenwaterscene.go @@ -79,7 +79,7 @@ func (s *ThirteenWaterScene) IsFull() bool { } func (s *ThirteenWaterScene) IsMatchScene() bool { - return s.GetRoomId() >= common.MatchSceneStartId + return s.RoomMode == common.SceneModeMatch } func (s *ThirteenWaterScene) Update(ts int64) { diff --git a/worldsrv/action_friend.go b/worldsrv/action_friend.go index 981a779..92c6dfe 100644 --- a/worldsrv/action_friend.go +++ b/worldsrv/action_friend.go @@ -354,7 +354,7 @@ func (this *CSInviteFriendHandler) Process(s *netlib.Session, packetid int, data return nil } //私有房间 - if p.scene.sceneMode != common.SceneMode_Private { + if p.scene.sceneMode != common.SceneModePrivate { logger.Logger.Warn("CSInviteFriendHandler scene is common.SceneMode_Private") opRetCode = friend.OpResultCode_OPRC_InviteFriend_RoomLimit send(p) @@ -461,7 +461,7 @@ func (this *CSInviteFriendOpHandler) Process(s *netlib.Session, packetid int, da return nil } //私有房间 - if scene.sceneMode != common.SceneMode_Private { + if scene.sceneMode != common.SceneModePrivate { logger.Logger.Warn("CSInviteFriendHandler scene is common.SceneMode_Private") opRetCode = friend.OpResultCode_OPRC_InviteFriend_RoomLimit //只能进入私有房间 send(p) diff --git a/worldsrv/action_game.go b/worldsrv/action_game.go index 2d3a724..fcacfc2 100644 --- a/worldsrv/action_game.go +++ b/worldsrv/action_game.go @@ -314,7 +314,7 @@ func (this *CSQueryRoomInfoHandler) ProcessLocalGame(s *netlib.Session, packetid if scene.gameId == int(gameid) && scene.dbGameFree.GetSceneType() == msg.GetGameSite() { // 私人房需要是好友 - if scene.sceneMode == common.SceneMode_Private { + if scene.sceneMode == common.SceneModePrivate { if !FriendMgrSington.IsFriend(p.Platform, p.SnId, scene.creator) { continue } @@ -872,7 +872,7 @@ func (this *CSCreateRoomHandler) ProcessLocalGame(s *netlib.Session, packetid in //创建房间 csp = CoinSceneMgrSingleton.GetCoinScenePool(p.GetPlatform().IdStr, dbGameFree.GetId()) - roomId = SceneMgrSingleton.GenOnePrivateSceneId() + roomId = SceneMgrSingleton.GenOneCoinSceneId() if roomId == common.RANDID_INVALID { code = gamehall.OpResultCode_Game_OPRC_AllocRoomIdFailed_Game logger.Logger.Tracef("CSCreateRoomHandler SnId:%v GameId:%v sceneId == -1 ", p.SnId, gameId) @@ -1141,8 +1141,6 @@ func CSAudienceEnterRoomHandler(s *netlib.Session, packetId int, data interface{ code = gamehall.OpResultCode_Game(CoinSceneMgrSingleton.AudienceEnter(p, cfg.GetDbGameFree().GetId(), msg.GetRoomId(), nil, true)) case scene.IsHundredScene(): - case scene.IsMatchScene(): - code = gamehall.OpResultCode_Game(MatchSceneMgrSingleton.AudienceEnter(p, cfg.GetDbGameFree().GetId(), int(msg.GetRoomId()), nil, true)) } failed: @@ -1306,7 +1304,7 @@ func CSCreatePrivateRoomHandler(s *netlib.Session, packetId int, data interface{ scene := SceneMgrSingleton.CreateScene(&CreateSceneParam{ CreateId: p.SnId, RoomId: roomId, - SceneMode: common.SceneMode_Private, + SceneMode: common.SceneModePrivateMatch, CycleTimes: 0, TotalRound: int(msg.GetRound()), Params: common.CopySliceInt32ToInt64(csp.dbGameRule.GetParams()), diff --git a/worldsrv/action_server.go b/worldsrv/action_server.go index 441578d..b7e9e7c 100644 --- a/worldsrv/action_server.go +++ b/worldsrv/action_server.go @@ -49,24 +49,13 @@ func init() { logger.Logger.Trace("GWPlayerLeave p.UnmarshalData(data)") p.UnmarshalData(data, scene) } + switch { case scene.IsCoinScene(): if !CoinSceneMgrSingleton.PlayerLeave(p, int(msg.GetReason())) { logger.Logger.Warnf("GWPlayerLeave snid:%v sceneid:%v gameid:%v modeid:%v [coinscene]", p.SnId, scene.sceneId, scene.gameId, scene.gameMode) } - case scene.IsMatchScene(): - if !MatchSceneMgrSingleton.PlayerLeave(p, int(msg.GetReason())) { - logger.Logger.Warnf("GWPlayerLeave snid:%v sceneid:%v gameid:%v modeid:%v matchid:%v [matchscene]", - p.SnId, scene.sceneId, scene.gameId, scene.gameMode, scene.MatchSortId) - } else { - //结算积分 - if !p.IsRob { - TournamentMgr.UpdateMatchInfo(p, msg.MatchId, int32(msg.GetReturnCoin()), int32(msg.GetCurIsWin()), msg.GetMatchRobotGrades()) - } else { - p.matchCtx = nil - } - } case scene.IsHundredScene(): if !HundredSceneMgrSingleton.PlayerLeave(p, int(msg.GetReason())) { logger.Logger.Warnf("GWPlayerLeave snid:%v sceneid:%v gameid:%v modeid:%v [hundredcene]", @@ -77,7 +66,17 @@ func init() { } if p.scene != nil { - logger.Logger.Warnf("after GWPlayerLeave found snid:%v sceneid:%v gameid:%v modeid:%v", p.SnId, p.scene.sceneId, p.scene.gameId, p.scene.gameMode) + logger.Logger.Errorf("after GWPlayerLeave found snid:%v sceneid:%v gameid:%v modeid:%v", + p.SnId, p.scene.sceneId, p.scene.gameId, p.scene.gameMode) + } + + if scene.IsMatchScene() { + //结算积分 + if !p.IsRob { + TournamentMgr.UpdateMatchInfo(p, msg.MatchId, int32(msg.GetReturnCoin()), int32(msg.GetCurIsWin()), msg.GetMatchRobotGrades()) + } else { + p.matchCtx = nil + } } // 同步排位积分 @@ -363,11 +362,6 @@ func init() { if !HundredSceneMgrSingleton.PlayerLeave(p, int(msg.GetReason())) { logger.Logger.Warnf("GWPlayerForceLeave snid:%v sceneid:%v gameid:%v modeid:%v [hundredcene]", p.SnId, scene.sceneId, scene.gameId, scene.gameMode) } - case scene.IsMatchScene(): - if !MatchSceneMgrSingleton.PlayerLeave(p, int(msg.GetReason())) { - logger.Logger.Warnf("GWPlayerLeave snid:%v sceneid:%v gameid:%v modeid:%v matchid:%v [matchscene]", - p.SnId, scene.sceneId, scene.gameId, scene.gameMode, scene.MatchSortId) - } default: scene.PlayerLeave(p, int(msg.GetReason())) } diff --git a/worldsrv/coinscenepool.go b/worldsrv/coinscenepool.go index c4782fb..ad71f43 100644 --- a/worldsrv/coinscenepool.go +++ b/worldsrv/coinscenepool.go @@ -102,7 +102,7 @@ func (csp *CoinScenePool) PreCreateRoom() { if preCreateNum <= 0 { return } - num := preCreateNum - csp.GetRoomNum(common.SceneMode_Public) + num := preCreateNum - csp.GetRoomNum(common.SceneModePublic) if num > 0 { logger.Logger.Tracef("预创建房间 [inc:%v] platform:%v gameFreeId:%v", num, csp.platform, csp.dbGameFree.Id) for i := 0; i < num; i++ { diff --git a/worldsrv/coinscenepool_base.go b/worldsrv/coinscenepool_base.go index ee214c1..0888bbc 100644 --- a/worldsrv/coinscenepool_base.go +++ b/worldsrv/coinscenepool_base.go @@ -218,7 +218,7 @@ func (this *BaseCoinScenePool) NewScene(pool *CoinScenePool, p *Player) *Scene { sceneId := SceneMgrSingleton.GenOneCoinSceneId() scene := SceneMgrSingleton.CreateScene(&CreateSceneParam{ RoomId: sceneId, - SceneMode: common.SceneMode_Public, + SceneMode: common.SceneModePublic, Params: params, GS: nil, Platform: limitPlatform, diff --git a/worldsrv/coinscenepool_local.go b/worldsrv/coinscenepool_local.go index 39cd9c6..58c9017 100644 --- a/worldsrv/coinscenepool_local.go +++ b/worldsrv/coinscenepool_local.go @@ -225,7 +225,7 @@ func (l *CoinScenePoolLocal) NewScene(pool *CoinScenePool, p *Player) *Scene { scene := SceneMgrSingleton.CreateScene(&CreateSceneParam{ CreateId: p.SnId, RoomId: sceneId, - SceneMode: common.SceneMode_Public, + SceneMode: common.SceneModePublic, Params: common.CopySliceInt32ToInt64(params), GS: nil, Platform: limitPlatform, @@ -276,7 +276,7 @@ func (l *CoinScenePoolLocal) NewPreCreateScene(pool *CoinScenePool) *Scene { if baseScore != 0 { scene = SceneMgrSingleton.CreateScene(&CreateSceneParam{ RoomId: sceneId, - SceneMode: common.SceneMode_Public, + SceneMode: common.SceneModePublic, Params: common.CopySliceInt32ToInt64(params), Platform: limitPlatform, GF: pool.dbGameFree, diff --git a/worldsrv/gamesess.go b/worldsrv/gamesess.go index d395c4c..148b66c 100644 --- a/worldsrv/gamesess.go +++ b/worldsrv/gamesess.go @@ -200,6 +200,11 @@ func (this *GameSession) AddScene(args *AddSceneParam) { } this.Send(int(server_proto.SSPacketID_PACKET_WG_CREATESCENE), msg) logger.Logger.Tracef("WGCreateScene: %v", msg) + + // 初始化水池 + if args.S.limitPlatform != nil && args.S.dbGameFree != nil { + this.DetectCoinPoolSetting(args.S.limitPlatform.IdStr, args.S.dbGameFree.GetId(), args.S.groupId) + } } func (this *GameSession) DelScene(s *Scene) { diff --git a/worldsrv/hundredscenemgr.go b/worldsrv/hundredscenemgr.go index 70c59e0..caa6f5f 100644 --- a/worldsrv/hundredscenemgr.go +++ b/worldsrv/hundredscenemgr.go @@ -205,7 +205,7 @@ func (this *HundredSceneMgr) CreateNewScene(id, groupId int32, limitPlatform *Pl params := common.CopySliceInt32ToInt64(dbGameRule.GetParams()) scene := SceneMgrSingleton.CreateScene(&CreateSceneParam{ RoomId: sceneId, - SceneMode: common.SceneMode_Public, + SceneMode: common.SceneModePublic, Params: params, Platform: limitPlatform, GF: dbGameFree, diff --git a/worldsrv/matchcontext.go b/worldsrv/matchcontext.go index 30cfcc0..f9ae6c3 100644 --- a/worldsrv/matchcontext.go +++ b/worldsrv/matchcontext.go @@ -5,7 +5,6 @@ import "sort" type PlayerMatchContext struct { tm *TmMatch //比赛 p *Player //玩家数据 - scene *Scene //比赛房间 round int32 //第几轮 seq int //报名序号 grade int32 //比赛积分 diff --git a/worldsrv/matchscenemgr.go b/worldsrv/matchscenemgr.go index 11b6528..83aacdc 100644 --- a/worldsrv/matchscenemgr.go +++ b/worldsrv/matchscenemgr.go @@ -6,18 +6,13 @@ import ( "mongo.games.com/game/common" "mongo.games.com/game/proto" - hallproto "mongo.games.com/game/protocol/gamehall" "mongo.games.com/game/protocol/server" ) -var MatchSceneMgrSingleton = &MatchSceneMgr{ - scenes: make(map[int]*Scene), -} +var MatchSceneMgrSingleton = &MatchSceneMgr{} // MatchSceneMgr 比赛场房间管理器 -type MatchSceneMgr struct { - scenes map[int]*Scene // 比赛场房间,房间id:房间数据 -} +type MatchSceneMgr struct{} // NewScene 创建比赛场房间 // tm 一场比赛,数据 @@ -50,7 +45,7 @@ func (ms *MatchSceneMgr) NewScene(tm *TmMatch, isFinals bool, round int32) *Scen rule := srvdata.PBDB_GameRuleMgr.GetData(tm.dbGameFree.GetGameRule()) scene := SceneMgrSingleton.CreateScene(&CreateSceneParam{ RoomId: sceneId, - SceneMode: common.SceneMode_Match, + SceneMode: common.SceneModeMatch, Params: common.CopySliceInt32ToInt64(rule.GetParams()), Platform: limitPlatform, GF: tm.dbGameFree, @@ -73,16 +68,22 @@ func (ms *MatchSceneMgr) NewScene(tm *TmMatch, isFinals bool, round int32) *Scen // MatchStart 开始首轮比赛 func (ms *MatchSceneMgr) MatchStart(tm *TmMatch) { var scene *Scene + csp := CoinSceneMgrSingleton.GetCoinScenePool(tm.Platform, tm.dbGameFree.GetId()) + if csp == nil { + logger.Logger.Errorf("MatchStart: csp is nil, TMID=%v", tm.TMId) + return + } for _, tmp := range tm.TmPlayer { //先进真人 if scene == nil || scene.IsFull() { scene = ms.NewScene(tm, false, 1) - if scene != nil { - ms.scenes[scene.sceneId] = scene + if scene == nil { + logger.Logger.Errorf("MatchStart NewScene failed, TMID=%v", tm.TMId) + return } + csp.AddScene(scene) } p := PlayerMgrSington.GetPlayerBySnId(tmp.SnId) - if p == nil { continue } @@ -95,7 +96,10 @@ func (ms *MatchSceneMgr) MatchStart(tm *TmMatch) { mc := TournamentMgr.CreatePlayerMatchContext(p, tm, tmp.seq) if mc != nil { mc.gaming = true - scene.PlayerEnter(p, -1, true) + if !scene.PlayerEnter(p, -1, true) { + logger.Logger.Errorf("MatchStart error: snid:%v enter scene %v failed", p.SnId, scene.sceneId) + continue + } } } // 填充机器人 @@ -116,20 +120,28 @@ func (ms *MatchSceneMgr) MatchStart(tm *TmMatch) { // NewRoundStart 开始非首轮比赛 func (ms *MatchSceneMgr) NewRoundStart(tm *TmMatch, mct []*PlayerMatchContext, finals bool, round int32) { var scene *Scene + csp := CoinSceneMgrSingleton.GetCoinScenePool(tm.Platform, tm.dbGameFree.GetId()) + if csp == nil { + logger.Logger.Errorf("NewRoundStart: csp is nil, TMID=%v", tm.TMId) + return + } for _, tmp := range mct { if scene == nil || scene.IsFull() { scene = ms.NewScene(tm, finals, round) - if scene != nil { - ms.scenes[scene.sceneId] = scene + if scene == nil { + logger.Logger.Errorf("NewRoundStart NewScene failed, TMID=%v", tm.TMId) + return } + csp.AddScene(scene) } + p := tmp.p if p == nil { continue } if p.scene != nil { - logger.Logger.Errorf("NewRoundStart error: snid:%v in scene %v", p.SnId, p.scene.sceneId) + logger.Logger.Errorf("NewRoundStart error: snid:%v in scene %v gameId:%v", p.SnId, p.scene.sceneId, p.scene.gameId) continue } @@ -137,7 +149,10 @@ func (ms *MatchSceneMgr) NewRoundStart(tm *TmMatch, mct []*PlayerMatchContext, f mc.gaming = true mc.grade = mc.grade * 75 / 100 //积分衰减 mc.rank = tmp.rank - scene.PlayerEnter(p, -1, true) + if !scene.PlayerEnter(p, -1, true) { + logger.Logger.Errorf("NewRoundStart error: snid:%v enter scene %v failed", p.SnId, scene.sceneId) + continue + } } } // 填充机器人 @@ -156,36 +171,7 @@ func (ms *MatchSceneMgr) NewRoundStart(tm *TmMatch, mct []*PlayerMatchContext, f } } -func (ms *MatchSceneMgr) PlayerLeave(p *Player, reason int) bool { - if p == nil || p.scene == nil { - return true - } - if p.scene.MatchSortId == 0 { - return true - } - p.scene.PlayerLeave(p, reason) - return true -} - -func (ms *MatchSceneMgr) OnDestroyScene(sceneId int) { - _, has := ms.scenes[sceneId] - if !has { - return - } - delete(ms.scenes, sceneId) -} - -func (ms *MatchSceneMgr) AudienceEnter(p *Player, id int32, roomId int, exclude []int32, ischangeroom bool) hallproto.OpResultCode { - scene, ok := ms.scenes[roomId] - if !ok { - return hallproto.OpResultCode_OPRC_RoomHadClosed - } - if !scene.AudienceEnter(p, ischangeroom) { - return hallproto.OpResultCode_OPRC_RoomHadClosed - } - return hallproto.OpResultCode_OPRC_Sucess -} - +// MatchStop 强制停止比赛 func (ms *MatchSceneMgr) MatchStop(tm *TmMatch) { if SceneMgrSingleton.scenes != nil && tm != nil { for _, scene := range SceneMgrSingleton.scenes { diff --git a/worldsrv/player.go b/worldsrv/player.go index ff662e6..cd756c5 100644 --- a/worldsrv/player.go +++ b/worldsrv/player.go @@ -1055,23 +1055,6 @@ func (this *Player) EditMessage(msg *model.Message) { } } -func (this *Player) SendIosInstallStableMail() { - if this.layered[common.ActId_IOSINSTALLSTABLE] { - logger.Logger.Trace("this.layered[common.ActId_IOSINSTALLSTABLE] is true") - return - } - var newMsg *model.Message - task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} { - newMsg = model.NewMessage("", 0, "", this.SnId, model.MSGTYPE_IOSINSTALLSTABLE, "系统通知", fmt.Sprintf("感谢您下载稳定版本,额外奖励%d元,请查收", int(model.GameParamData.IosStableInstallPrize/100)), - int64(model.GameParamData.IosStableInstallPrize), 0, 0, time.Now().Unix(), 0, "", nil, this.Platform, model.HallAll, nil) - return model.InsertMessage(this.Platform, newMsg) - }), task.CompleteNotifyWrapper(func(data interface{}, t task.Task) { - if data == nil { - this.AddMessage(newMsg) - } - }), "SendMessage").Start() -} - func (this *Player) TestMail() { var newMsg *model.Message @@ -1974,7 +1957,7 @@ func (this *Player) AddCoin(num, add int64, gainWay int32, oper, remark string) //this.TotalData(num, gainWay) async := false - if num > 0 && this.scene != nil && !this.scene.IsTestScene() && !this.scene.IsMatchScene() && this.scene.sceneMode != common.SceneMode_Thr { //游戏场中加币,需要同步到gamesrv上 + if num > 0 && this.scene != nil && !this.scene.IsTestScene() && !this.scene.IsMatchScene() && this.scene.sceneMode != common.SceneModeThr { //游戏场中加币,需要同步到gamesrv上 if StartAsyncAddCoinTransact(this, num, gainWay, oper, remark, true, 0, true) { async = true } @@ -2029,7 +2012,7 @@ func (this *Player) AddCoinAsync(num, add int64, gainWay int32, oper, remark str //玩家可能正在换房间 async := false - if num > 0 && retryCnt < 3 && this.scene != nil && !this.scene.IsTestScene() && this.scene.sceneMode != common.SceneMode_Thr { //游戏场中加币,需要同步到gamesrv上 + if num > 0 && retryCnt < 3 && this.scene != nil && !this.scene.IsTestScene() && this.scene.sceneMode != common.SceneModeThr { //游戏场中加币,需要同步到gamesrv上 if StartAsyncAddCoinTransact(this, num, gainWay, oper, remark, broadcast, retryCnt, writeLog) { async = true } diff --git a/worldsrv/scene.go b/worldsrv/scene.go index 2ff2a09..6793dfb 100644 --- a/worldsrv/scene.go +++ b/worldsrv/scene.go @@ -681,8 +681,6 @@ func (this *Scene) OnClose() { IsForce: proto.Int(1), } this.Broadcast(int(hallproto.GameHallPacketID_PACKET_SC_DESTROYROOM), scDestroyRoom, 0) - - this.sp.OnStop(this) this.deleting = true this.closed = true @@ -728,39 +726,37 @@ func (this *Scene) SendGameDestroy(isGrace bool) { logger.Logger.Tracef("WG_DESTROYSCENE: %v", pack) } -// IsMatchScene 比赛场 -func (this *Scene) IsMatchScene() bool { - return this.sceneId >= common.MatchSceneStartId && this.sceneId < common.MatchSceneMaxId -} - // IsCoinScene 金币场 func (this *Scene) IsCoinScene() bool { - return this.sceneId >= common.CoinSceneStartId && this.sceneId < common.CoinSceneMaxId + return this != nil && this.csp != nil } // IsHundredScene 百人场 func (this *Scene) IsHundredScene() bool { - return this.sceneId >= common.HundredSceneStartId && this.sceneId < common.HundredSceneMaxId + return this != nil && this.hp != nil +} + +// IsMatchScene 比赛场 +func (this *Scene) IsMatchScene() bool { + return this.IsSceneMode(common.SceneModeMatch) } // IsPrivateScene 私人房间 func (this *Scene) IsPrivateScene() bool { - return this.sceneId >= common.PrivateSceneStartId && this.sceneId < common.PrivateSceneMaxId + return this.IsSceneMode(common.SceneModePrivate) } -// IsCustom 房卡场房间 +// IsCustom 竞技馆房间 func (this *Scene) IsCustom() bool { + if this.IsSceneMode(common.SceneModePrivateMatch) { + return true + } if this.dbGameFree == nil { return false } return this.dbGameFree.IsCustom > 0 } -// IsSceneMode 房间模式 -func (this *Scene) IsSceneMode(mode int) bool { - return this.sceneMode == mode -} - // IsRankMatch 排位赛 func (this *Scene) IsRankMatch() bool { if this.dbGameFree == nil { @@ -769,6 +765,11 @@ func (this *Scene) IsRankMatch() bool { return this.dbGameFree.RankType > 0 } +// IsSceneMode 房间模式 +func (this *Scene) IsSceneMode(mode int) bool { + return this.sceneMode == mode +} + // IsTestScene 试玩场 func (this *Scene) IsTestScene() bool { if this.dbGameFree != nil { diff --git a/worldsrv/scenemgr.go b/worldsrv/scenemgr.go index 439a945..b54b410 100644 --- a/worldsrv/scenemgr.go +++ b/worldsrv/scenemgr.go @@ -13,7 +13,6 @@ import ( "mongo.games.com/game/model" serverproto "mongo.games.com/game/protocol/server" webapiproto "mongo.games.com/game/protocol/webapi" - "mongo.games.com/game/webapi" ) func init() { @@ -94,18 +93,6 @@ func (m *SceneMgr) GenPassword() string { return "" } -func (m *SceneMgr) GenPasswordInt32() int32 { - for i := 0; i < 100; i++ { - s := strconv.Itoa(common.RandInt(10000, 100000)) - if _, ok := m.password[s]; !ok { - m.password[s] = struct{}{} - n, _ := strconv.Atoi(s) - return int32(n) - } - } - return 0 -} - func (m *SceneMgr) GetPlatformBySceneId(sceneId int) string { s := m.GetScene(sceneId) if s != nil && s.limitPlatform != nil { @@ -413,18 +400,12 @@ func (m *SceneMgr) CreateScene(args *CreateSceneParam) *Scene { return nil } m.scenes[args.RoomId] = s - s.sp.OnStart(s) // 添加到游戏服记录中 args.GS.AddScene(&AddSceneParam{ S: s, }) + s.sp.OnStart(s) logger.Logger.Infof("SceneMgr NewScene Platform:%v %+v", args.Platform.IdStr, args) - - // 创建水池 - if !s.IsMatchScene() && s.dbGameFree != nil && s.limitPlatform != nil { - //平台水池设置 - args.GS.DetectCoinPoolSetting(s.limitPlatform.IdStr, s.dbGameFree.GetId(), s.groupId) - } return s } @@ -437,24 +418,23 @@ func (m *SceneMgr) DestroyScene(sceneId int, isCompleted bool) { return } + s.sp.OnStop(s) + s.gameSess.DelScene(s) switch { case s.IsCoinScene(): CoinSceneMgrSingleton.OnDestroyScene(s.sceneId) case s.IsHundredScene(): HundredSceneMgrSingleton.OnDestroyScene(s.sceneId) - - case s.IsMatchScene(): - MatchSceneMgrSingleton.OnDestroyScene(s.sceneId) } - - s.gameSess.DelScene(s) s.OnClose() + delete(m.scenes, s.sceneId) delete(m.password, s.GetPassword()) logger.Logger.Infof("(this *SceneMgr) DestroyScene, SceneId=%v", sceneId) } +// SendGameDestroy 发送游戏服销毁房间 func (m *SceneMgr) SendGameDestroy(sceneId []int, isGrace bool) { if len(sceneId) == 0 { return @@ -475,6 +455,30 @@ func (m *SceneMgr) SendGameDestroy(sceneId []int, isGrace bool) { srvlib.ServerSessionMgrSington.Broadcast(int(serverproto.SSPacketID_PACKET_WG_DESTROYSCENE), pack, common.GetSelfAreaId(), srvlib.GameServerType) } +// CheckDestroyEmptyRoom 尝试解散空闲房间 +// 非必须,防止内存泄露 +func (m *SceneMgr) CheckDestroyEmptyRoom() { + for _, s := range m.scenes { + switch { + case s.IsCoinScene(): + if !s.IsLongTimeInactive() { + continue + } + if s.dbGameFree == nil { + continue + } + if s.dbGameFree.GetCreateRoomNum() == 0 { + logger.Logger.Warnf("SceneMgr.DeleteLongTimeInactive CoinScene SendGameDestroy scene:%v IsLongTimeInactive", s.sceneId) + s.SendGameDestroy(false) + } + if s.dbGameFree.GetCreateRoomNum() > 0 && s.csp.GetRoomNum(common.SceneModePublic) > int(s.dbGameFree.GetCreateRoomNum()) { + logger.Logger.Warnf("SceneMgr.DeleteLongTimeInactive CoinScene SendGameDestroy scene:%v IsLongTimeInactive", s.sceneId) + s.SendGameDestroy(false) + } + } + } +} + //=========================ClockSinker=============================== // InterestClockEvent 接收所有时间事件 @@ -483,28 +487,5 @@ func (m *SceneMgr) InterestClockEvent() int { } func (m *SceneMgr) OnMiniTimer() { - // 解散空闲房间 - for _, s := range m.scenes { - if webapi.ThridPlatformMgrSington.FindPlatformByPlatformBaseGameId(s.gameId) != nil { - continue - } - switch { - case s.IsCoinScene(): - if s.IsLongTimeInactive() { - if s.dbGameFree.GetCreateRoomNum() == 0 { - logger.Logger.Warnf("SceneMgr.DeleteLongTimeInactive CoinScene SendGameDestroy scene:%v IsLongTimeInactive", s.sceneId) - s.SendGameDestroy(false) - } - if s.dbGameFree.GetCreateRoomNum() > 0 && s.csp != nil && s.csp.GetRoomNum(common.SceneMode_Public) > int(s.dbGameFree.GetCreateRoomNum()) { - logger.Logger.Warnf("SceneMgr.DeleteLongTimeInactive CoinScene SendGameDestroy scene:%v IsLongTimeInactive", s.sceneId) - s.SendGameDestroy(false) - } - } - case s.IsPrivateScene(): - if s.IsLongTimeInactive() { - logger.Logger.Warnf("SceneMgr.DeleteLongTimeInactive PrivateScene SendGameDestroy scene:%v IsLongTimeInactive", s.sceneId) - s.SendGameDestroy(false) - } - } - } + m.CheckDestroyEmptyRoom() }