From 3bff2c17f3650732f8e9e5c54daadd3d7eff7488 Mon Sep 17 00:00:00 2001 From: sk <123456@qq.com> Date: Thu, 29 Aug 2024 14:28:54 +0800 Subject: [PATCH] review --- common/constant.go | 11 + gamesrv/tienlen/scenepolicy_tienlen.go | 3 + worldsrv/action_game.go | 4 +- worldsrv/coinscenepool_local.go | 4 +- worldsrv/hundredscenemgr.go | 1 - worldsrv/player.go | 11 - worldsrv/playersingleadjust.go | 273 --------------- worldsrv/playgamenum.go | 47 --- worldsrv/scene.go | 446 +++++++++++-------------- worldsrv/scenemgr.go | 2 +- worldsrv/trascate_webapi.go | 4 +- 11 files changed, 221 insertions(+), 585 deletions(-) delete mode 100644 worldsrv/playersingleadjust.go delete mode 100644 worldsrv/playgamenum.go diff --git a/common/constant.go b/common/constant.go index cadbc44..625d141 100644 --- a/common/constant.go +++ b/common/constant.go @@ -876,3 +876,14 @@ const ( SceneStateStart = 1 // 开始 SceneStateEnd = 2 // 结束 ) + +const ( + // PlayerHistoryModel . + PlayerHistoryModel = iota + 1 + + // BIGWIN_HISTORY_MODEL . + BIGWIN_HISTORY_MODEL + + // GameHistoryModel . + GameHistoryModel +) diff --git a/gamesrv/tienlen/scenepolicy_tienlen.go b/gamesrv/tienlen/scenepolicy_tienlen.go index 1117595..2c52a0f 100644 --- a/gamesrv/tienlen/scenepolicy_tienlen.go +++ b/gamesrv/tienlen/scenepolicy_tienlen.go @@ -148,6 +148,9 @@ func (this *ScenePolicyTienLen) OnPlayerLeave(s *base.Scene, p *base.Player, rea } sceneEx.OnPlayerLeave(p, reason) s.FirePlayerEvent(p, base.PlayerEventLeave, []int64{int64(reason)}) + if s.IsCustom() && len(s.Players) == 0 { + s.Destroy(true) + } } // 玩家掉线 diff --git a/worldsrv/action_game.go b/worldsrv/action_game.go index 88488a4..603710c 100644 --- a/worldsrv/action_game.go +++ b/worldsrv/action_game.go @@ -229,7 +229,7 @@ func (this *CSReturnRoomHandler) Process(s *netlib.Session, packetid int, data i pack.GameId = proto.Int(scene.gameId) pack.ModeType = proto.Int(scene.gameMode) pack.Params = common.CopySliceInt64ToInt32(scene.params) - pack.HallId = proto.Int32(scene.hallId) + pack.HallId = proto.Int32(scene.dbGameFree.GetId()) gameVers := srvdata.GetGameVers(p.PackageID) if ver, ok := gameVers[fmt.Sprintf("%v,%v", scene.gameId, p.Channel)]; ok { pack.MinApkVer = proto.Int32(ver.MinApkVer) @@ -872,7 +872,7 @@ func (this *CSCreateRoomHandler) ProcessLocalGame(s *netlib.Session, packetid in //创建房间 csp = CoinSceneMgrSingleton.GetCoinScenePool(p.GetPlatform().IdStr, dbGameFree.GetId()) - roomId = SceneMgrSingleton.GenOneCoinSceneId() + roomId = SceneMgrSingleton.GenOnePrivateSceneId() 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) diff --git a/worldsrv/coinscenepool_local.go b/worldsrv/coinscenepool_local.go index 6ec2898..39cd9c6 100644 --- a/worldsrv/coinscenepool_local.go +++ b/worldsrv/coinscenepool_local.go @@ -219,7 +219,7 @@ func (l *CoinScenePoolLocal) NewScene(pool *CoinScenePool, p *Player) *Scene { baseScore = common.RandInt32Slice(dbCreateRoom.GetBetRange()) } if baseScore == 0 { - logger.Logger.Tracef("CoinScenePool CreateLocalGameNewScene failed! baseScore==0") + logger.Logger.Tracef("CoinScenePool CreateLocalGameNewScene failed! BaseScore==0") return nil } scene := SceneMgrSingleton.CreateScene(&CreateSceneParam{ @@ -284,7 +284,7 @@ func (l *CoinScenePoolLocal) NewPreCreateScene(pool *CoinScenePool) *Scene { BaseScore: baseScore, }) if scene != nil { - logger.Logger.Tracef("CreateLocalGameScene success.gameId:%v gameSite:%v baseScore:%v randIdx:%v", scene.gameId, scene.dbGameFree.GetSceneType(), baseScore, randIdx) + logger.Logger.Tracef("CreateLocalGameScene success.gameId:%v gameSite:%v BaseScore:%v randIdx:%v", scene.gameId, scene.dbGameFree.GetSceneType(), baseScore, randIdx) } } } diff --git a/worldsrv/hundredscenemgr.go b/worldsrv/hundredscenemgr.go index e7e5d77..2766caa 100644 --- a/worldsrv/hundredscenemgr.go +++ b/worldsrv/hundredscenemgr.go @@ -212,7 +212,6 @@ func (this *HundredSceneMgr) CreateNewScene(id, groupId int32, limitPlatform *Pl }) if scene != nil { logger.Logger.Infof("Create hundred scene %v-%v success.", gameId, sceneId) - scene.hallId = id scene.hp = this return scene } else { diff --git a/worldsrv/player.go b/worldsrv/player.go index 2ecf0cc..654d23a 100644 --- a/worldsrv/player.go +++ b/worldsrv/player.go @@ -1667,17 +1667,6 @@ func (this *Player) MarshalData() (d []byte, e error) { return } -func (this *Player) MarshalSingleAdjustData(gamefreeid int32) (d []byte, e error) { - if this.IsRob { - return - } - sa := PlayerSingleAdjustMgr.GetSingleAdjust(this.Platform, this.SnId, gamefreeid) - if sa != nil { - d, e = netlib.Gob.Marshal(sa) - } - return -} - // UnmarshalData 更新玩家数据 // 例如游戏服数据同步 func (this *Player) UnmarshalData(data []byte, scene *Scene) { diff --git a/worldsrv/playersingleadjust.go b/worldsrv/playersingleadjust.go deleted file mode 100644 index e59a3ad..0000000 --- a/worldsrv/playersingleadjust.go +++ /dev/null @@ -1,273 +0,0 @@ -package main - -import ( - "github.com/globalsign/mgo/bson" - "mongo.games.com/game/model" - "mongo.games.com/game/protocol/server" - "mongo.games.com/game/protocol/webapi" - "mongo.games.com/goserver/core/basic" - "mongo.games.com/goserver/core/logger" - "mongo.games.com/goserver/core/module" - "mongo.games.com/goserver/core/task" - "time" -) - -type PlayerSingleAdjustManager struct { - AdjustData map[uint64]*model.PlayerSingleAdjust - dirtyList map[uint64]bool - cacheDirtyList map[uint64]bool //缓存待删除数据 -} - -var PlayerSingleAdjustMgr = &PlayerSingleAdjustManager{ - AdjustData: make(map[uint64]*model.PlayerSingleAdjust), - dirtyList: make(map[uint64]bool), - cacheDirtyList: make(map[uint64]bool), -} - -func (this *PlayerSingleAdjustManager) WebData(msg *webapi.ASSinglePlayerAdjust, p *Player) (sa *webapi.PlayerSingleAdjust) { - psa := model.WebSingleAdjustToModel(msg.PlayerSingleAdjust) - switch msg.Opration { - case 1: - this.AddNewSingleAdjust(psa) - case 2: - this.EditSingleAdjust(psa) - case 3: - this.DeleteSingleAdjust(psa.Platform, psa.SnId, psa.GameFreeId) - case 4: - sa = this.WebGetSingleAdjust(psa.Platform, psa.SnId, psa.GameFreeId) - return - } - //同步到游服 - if p != nil { - if p.scene != nil && p.scene.dbGameFree.Id == psa.GameFreeId { - gss := GameSessMgrSington.GetGameServerSess(int(psa.GameId)) - pack := &server.WGSingleAdjust{ - SceneId: int32(p.scene.sceneId), - Option: msg.Opration, - PlayerSingleAdjust: model.MarshalSingleAdjust(psa), - } - for _, gs := range gss { - gs.Send(int(server.SSPacketID_PACKET_WG_SINGLEADJUST), pack) - } - } - if p.miniScene != nil { - for _, game := range p.miniScene { - if game.dbGameFree.Id == psa.GameFreeId { - gss := GameSessMgrSington.GetGameServerSess(int(psa.GameId)) - pack := &server.WGSingleAdjust{ - SceneId: int32(game.sceneId), - Option: msg.Opration, - PlayerSingleAdjust: model.MarshalSingleAdjust(psa), - } - for _, gs := range gss { - gs.Send(int(server.SSPacketID_PACKET_WG_SINGLEADJUST), pack) - } - break - } - } - } - } - return -} - -func (this *PlayerSingleAdjustManager) IsSingleAdjustPlayer(snid int32, gameFreeId int32) (*model.PlayerSingleAdjust, bool) { - key := uint64(snid)<<32 + uint64(gameFreeId) - if data, ok := this.AdjustData[key]; ok { - if data.CurTime < data.TotalTime { - return data, true - } - } - return nil, false -} -func (this *PlayerSingleAdjustManager) AddAdjustCount(snid int32, gameFreeId int32) { - key := uint64(snid)<<32 + uint64(gameFreeId) - if ad, ok := this.AdjustData[key]; ok { - ad.CurTime++ - this.dirtyList[key] = true - } -} -func (this *PlayerSingleAdjustManager) GetSingleAdjust(platform string, snid, gameFreeId int32) *model.PlayerSingleAdjust { - key := uint64(snid)<<32 + uint64(gameFreeId) - if psa, ok := this.AdjustData[key]; ok { - return psa - } - return nil -} -func (this *PlayerSingleAdjustManager) WebGetSingleAdjust(platform string, snid, gameFreeId int32) *webapi.PlayerSingleAdjust { - key := uint64(snid)<<32 + uint64(gameFreeId) - if psa, ok := this.AdjustData[key]; ok { - return &webapi.PlayerSingleAdjust{ - Id: psa.Id.Hex(), - Platform: psa.Platform, - GameFreeId: psa.GameFreeId, - SnId: psa.SnId, - Mode: psa.Mode, - TotalTime: psa.TotalTime, - CurTime: psa.CurTime, - BetMin: psa.BetMin, - BetMax: psa.BetMax, - BankerLoseMin: psa.BankerLoseMin, - BankerWinMin: psa.BankerWinMin, - CardMin: psa.CardMin, - CardMax: psa.CardMax, - Priority: psa.Priority, - WinRate: psa.WinRate, - GameId: psa.GameId, - GameMode: psa.GameMode, - Operator: psa.Operator, - CreateTime: psa.CreateTime, - UpdateTime: psa.UpdateTime, - } - } - return nil -} -func (this *PlayerSingleAdjustManager) AddNewSingleAdjust(psa *model.PlayerSingleAdjust) *model.PlayerSingleAdjust { - if psa != nil { - key := uint64(psa.SnId)<<32 + uint64(psa.GameFreeId) - psa.Id = bson.NewObjectId() - psa.CreateTime = time.Now().Unix() - psa.UpdateTime = time.Now().Unix() - - this.AdjustData[key] = psa - logger.Logger.Trace("SinglePlayerAdjust new:", psa) - task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} { - return model.AddNewSingleAdjust(psa) - }), nil, "AddNewSingleAdjust").StartByFixExecutor("AddNewSingleAdjust") - } - return psa -} -func (this *PlayerSingleAdjustManager) EditSingleAdjust(psa *model.PlayerSingleAdjust) { - if psa != nil { - var inGame bool - psa.UpdateTime = time.Now().Unix() - for key, value := range this.AdjustData { - if value.Id == psa.Id { - var tempKey = key - if psa.GameFreeId != value.GameFreeId { - delete(this.AdjustData, key) - delete(this.dirtyList, key) - tempKey = uint64(psa.SnId)<<32 + uint64(psa.GameFreeId) - } - this.AdjustData[tempKey] = psa - this.dirtyList[tempKey] = true - inGame = true - break - } - } - logger.Logger.Trace("SinglePlayerAdjust edit:", *psa) - if !inGame { - //不在游戏 直接更新库 - task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} { - return model.EditSingleAdjust(psa) - }), nil, "EditSingleAdjust").StartByFixExecutor("EditSingleAdjust") - } - } -} -func (this *PlayerSingleAdjustManager) DeleteSingleAdjust(platform string, snid, gameFreeId int32) { - key := uint64(snid)<<32 + uint64(gameFreeId) - if _, ok := this.AdjustData[key]; ok { - delete(this.AdjustData, key) - delete(this.dirtyList, key) - } - logger.Logger.Trace("SinglePlayerAdjust delete:", snid, gameFreeId) - task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} { - return model.DeleteSingleAdjust(&model.PlayerSingleAdjust{SnId: snid, GameFreeId: gameFreeId, Platform: platform}) - }), nil, "DeleteSingleAdjust").Start() -} - -func (this *PlayerSingleAdjustManager) ModuleName() string { - return "PlayerSingleAdjustManager" -} -func (this *PlayerSingleAdjustManager) Init() { - //data, err := model.QueryAllSingleAdjust("1") - //if err != nil { - // logger.Logger.Warn("QueryAllSingleAdjust is err:", err) - // return - //} - //if len(data) > 0 { - // for _, psa := range data { - // _, gameType := srvdata.DataMgr.GetGameFreeIds(psa.GameId, psa.GameMode) - // if gameType != common.GameType_Mini { - // key := uint64(psa.SnId)<<32 + uint64(psa.GameFreeId) - // this.AdjustData[key] = psa - // } - // } - //} -} - -// 登录加载 -func (this *PlayerSingleAdjustManager) LoadSingleAdjustData(platform string, snid int32) { - task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} { - ret, err := model.QueryAllSingleAdjustByKey(platform, snid) - if err != nil { - return nil - } - return ret - }), task.CompleteNotifyWrapper(func(data interface{}, tt task.Task) { - if data != nil { - ret := data.([]*model.PlayerSingleAdjust) - for _, psa := range ret { - key := uint64(psa.SnId)<<32 + uint64(psa.GameFreeId) - this.AdjustData[key] = psa - } - } - })).StartByFixExecutor("LoadPlayerSingleAdjust") -} - -// 掉线删除 -func (this *PlayerSingleAdjustManager) DelPlayerData(platform string, snid int32) { - for _, psa := range this.AdjustData { - if psa.Platform == platform && psa.SnId == snid { - key := uint64(psa.SnId)<<32 + uint64(psa.GameFreeId) - if this.dirtyList[key] { - this.cacheDirtyList[key] = true - } else { - delete(this.AdjustData, key) - } - } - } -} -func (this *PlayerSingleAdjustManager) Update() { - if len(this.dirtyList) == 0 { - return - } - var syncArr []*model.PlayerSingleAdjust - for key, _ := range this.dirtyList { - syncArr = append(syncArr, this.AdjustData[key]) - delete(this.dirtyList, key) - } - task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} { - var saveArr [2][]uint64 - for _, value := range syncArr { - err := model.EditSingleAdjust(value) - if err != nil { - logger.Logger.Error("PlayerSingleAdjustManager edit ", err) - saveArr[0] = append(saveArr[0], uint64(value.SnId)<<32+uint64(value.GameFreeId)) - } else { - saveArr[1] = append(saveArr[1], uint64(value.SnId)<<32+uint64(value.GameFreeId)) - } - } - return saveArr - }), task.CompleteNotifyWrapper(func(data interface{}, tt task.Task) { - if saveArr, ok := data.([2][]uint64); ok { - //失败处理 - for _, key := range saveArr[0] { - this.dirtyList[key] = true - } - //成功处理 - for _, key := range saveArr[1] { - if this.cacheDirtyList[key] { - delete(this.cacheDirtyList, key) - delete(this.AdjustData, key) - } - } - } - return - })).StartByFixExecutor("PlayerSingleAdjustManager") -} -func (this *PlayerSingleAdjustManager) Shutdown() { - module.UnregisteModule(this) -} -func init() { - module.RegisteModule(PlayerSingleAdjustMgr, time.Minute*5, 0) -} diff --git a/worldsrv/playgamenum.go b/worldsrv/playgamenum.go deleted file mode 100644 index 7e26726..0000000 --- a/worldsrv/playgamenum.go +++ /dev/null @@ -1,47 +0,0 @@ -package main - -import ( - "mongo.games.com/game/common" - //"mongo.games.com/game/gamerule/blackjack" - //"mongo.games.com/game/gamerule/dezhoupoker" - //"mongo.games.com/game/gamerule/fivecardstud" - //"mongo.games.com/game/gamerule/omahapoker" -) - -var minPlayGameNum = map[int]int{ - common.GameId_TenHalf: 2, - common.GameId_DezhouPoker: 2, - common.GameId_FiveCardStud: 2, - common.GameId_BlackJack: 1, - //common.GameId_OmahaPoker: omahapoker.MinNumOfPlayer, -} - -var maxPlayGameNum = map[int]int{ - //common.GameId_DezhouPoker: int(dezhoupoker.MaxNumOfPlayer), - //common.GameId_FiveCardStud: int(fivecardstud.MaxNumOfPlayer), - //common.GameId_BlackJack: blackjack.MaxPlayer, - //common.GameId_OmahaPoker: omahapoker.MaxNumOfPlayer, -} - -func GetGameStartMinNum(gameid int) int { - return minPlayGameNum[gameid] -} -func GetGameSuiableNum(gameid int, flag int32) int { - minNum, maxNum := minPlayGameNum[gameid], maxPlayGameNum[gameid] - if flag == MatchTrueManForbid { - if minNum == maxNum { - return minNum - } else { - return maxNum - 1 - } - } else { - if minNum == maxNum { - return minNum - } else { - return maxNum - 2 - } - } -} -func IsRegularNum(gameid int) bool { - return minPlayGameNum[gameid] == maxPlayGameNum[gameid] -} diff --git a/worldsrv/scene.go b/worldsrv/scene.go index de9b098..fd9f401 100644 --- a/worldsrv/scene.go +++ b/worldsrv/scene.go @@ -6,7 +6,6 @@ import ( "time" rawproto "google.golang.org/protobuf/proto" - "mongo.games.com/goserver/core/logger" "mongo.games.com/goserver/core/netlib" "mongo.games.com/goserver/srvlib" @@ -21,35 +20,21 @@ import ( "mongo.games.com/game/srvdata" ) -const ( - // PlayerHistoryModel . - PlayerHistoryModel = iota + 1 - - // BIGWIN_HISTORY_MODEL . - BIGWIN_HISTORY_MODEL - - // GameHistoryModel . - GameHistoryModel -) - type PlayerGameCtx struct { - takeCoin int64 //进房时携带的金币量 - enterTs int64 //进入时间 - totalConvertibleFlow int64 //进房时玩家身上的总流水 + takeCoin int64 //进房时携带的金币量 + enterTs int64 //进入时间 } // Scene 场景(房间) -// todo 结构优化 type Scene struct { sceneId int // 场景id gameId int // 游戏id - gameMode int // 游戏模式(玩法) + gameMode int // 废弃,游戏模式(玩法) sceneMode int // 房间模式,参考common.SceneMode_XXX params []int64 // 场景参数 playerNum int // 房间最大人数 robotNum int // 机器人数量 robotLimit int // 最大限制机器人数量 - preInviteRobNum int // 准备邀请机器人的数量 creator int32 // 创建者账号id replayCode string // 回放码 currRound int32 // 当前第几轮 @@ -66,13 +51,11 @@ type Scene struct { sp ScenePolicy // 场景上的一些业务策略 createTime time.Time // 创建时间 lastTime time.Time // 最后活跃时间 - startTime time.Time // 开始时间 - applyTimes map[int32]int32 // 申请坐下次数 + startTime time.Time // 游戏开始时间 limitPlatform *Platform // 限制平台 groupId int32 // 组id - hallId int32 // 厅id dbGameFree *serverproto.DB_GameFree // 场次配置 - gameCtx map[int32]*PlayerGameCtx // 进入房间的环境 + gameCtx map[int32]*PlayerGameCtx // 进入房间的环境,没有机器人数据 SnId BaseScore int32 // 游戏底分,优先级,创建参数>本地配置>场次配置 SceneState int32 // 房间当前状态 State int32 // 当前游戏状态,后期放到ScenePolicy里去处理 @@ -89,8 +72,6 @@ type Scene struct { func NewScene(args *CreateSceneParam) *Scene { gameId := int(args.GF.GetGameId()) gameMode := int(args.GF.GetGameMode()) - gameFreeId := args.GF.GetId() - sp := GetScenePolicy(gameId, gameMode) if sp == nil { logger.Logger.Errorf("NewScene sp == nil, gameId=%v gameMode=%v", gameId, gameMode) @@ -99,7 +80,6 @@ func NewScene(args *CreateSceneParam) *Scene { s := &Scene{ sceneId: args.RoomId, - hallId: gameFreeId, playerNum: int(args.PlayerNum), creator: args.CreateId, gameId: gameId, @@ -141,7 +121,18 @@ func NewScene(args *CreateSceneParam) *Scene { s.replayCode = SceneMgrSingleton.AllocReplayCode() if s.dbGameFree.GetMatchMode() == 0 { - s.RandRobotCnt() + // 普通匹配设置最大机器人数量 + number := s.dbGameFree.GetRobotNumRng() + if len(number) >= 2 { + if number[1] == number[0] { + s.robotLimit = int(number[0]) + } else { + if number[1] < number[0] { + number[1], number[0] = number[0], number[1] + } + s.robotLimit = int(number[1]) + } + } } s.sp.OnStart(s) return s @@ -178,10 +169,13 @@ func (this *Scene) GetPlayerGameCtx(snid int32) *PlayerGameCtx { } // PlayerEnter 玩家进入场景 -// todo 优化 func (this *Scene) PlayerEnter(p *Player, pos int, ischangeroom bool) bool { logger.Logger.Infof("(this *Scene:%v) PlayerEnter(%v, %v) ", this.sceneId, p.SnId, pos) + if this.dbGameFree == nil { + return false + } + // 机器人数量限制 if p.IsRobot() && this.robotLimit != 0 { if this.robotNum+1 > this.robotLimit { @@ -224,15 +218,15 @@ func (this *Scene) PlayerEnter(p *Player, pos int, ischangeroom bool) bool { } } - p.scene = this - this.players[p.SnId] = p - this.gameSess.AddPlayer(p) - takeCoin := p.Coin leaveCoin := int64(0) gameTimes := rand.Int31n(100) - var matchParams []int32 //排名、段位、假snid、假角色、假皮肤 + if this.IsCustom() { // 房卡场初始1000金币 + takeCoin = 1000 + } + + var matchParams []int32 //排名、段位、假snid、假角色、假皮肤 if this.IsMatchScene() && p.matchCtx != nil { takeCoin = int64(p.matchCtx.grade) matchParams = append(matchParams, p.matchCtx.rank) //排名 @@ -246,108 +240,6 @@ func (this *Scene) PlayerEnter(p *Player, pos int, ischangeroom bool) bool { matchParams = append(matchParams, p.matchCtx.copySkinId) //假SkinId } - if this.IsCustom() { - takeCoin = 1000 - } - - if p.IsRob && !this.IsMatchScene() && !this.IsCustom() { - if this.dbGameFree != nil { //机器人携带金币动态调整 - gps := PlatformMgrSingleton.GetGameFree(this.limitPlatform.IdStr, this.dbGameFree.GetId()) - if gps != nil { - dbGameFree := gps.DbGameFree - flag := false - if common.IsLocalGame(this.gameId) { - baseScore := this.BaseScore - arrs := srvdata.PBDB_CreateroomMgr.Datas.Arr - tmpIds := []int32{} - for i := 0; i < len(arrs); i++ { - arr := arrs[i] - if int(arr.GameId) == this.gameId && arr.GameSite == this.dbGameFree.GetSceneType() { - betRange := arr.GetBetRange() - if len(betRange) == 0 { - continue - } - for j := 0; j < len(betRange); j++ { - if betRange[j] == baseScore && len(arr.GetGoldRange()) > 0 && arr.GetGoldRange()[0] != 0 { - tmpIds = append(tmpIds, arr.GetId()) - break - } - } - } - } - if len(tmpIds) > 0 { - randId := common.RandInt32Slice(tmpIds) - crData := srvdata.PBDB_CreateroomMgr.GetData(randId) - if crData != nil { - goldRange := crData.GetGoldRange() - if len(goldRange) == 2 { - takeCoin = common.RandFromRangeInt64(int64(goldRange[0]), int64(goldRange[1])) - flag = true - } else if len(goldRange) == 1 { - takeCoin = common.RandFromRangeInt64(int64(goldRange[0]), 2*int64(goldRange[0])) - flag = true - } - leaveCoin = int64(goldRange[0]) - for _, id := range tmpIds { - tmp := srvdata.PBDB_CreateroomMgr.GetData(id).GetGoldRange() - if int64(tmp[0]) < leaveCoin && tmp[0] != 0 { - leaveCoin = int64(tmp[0]) - } - } - } - } else { - logger.Logger.Warn("gameId: ", this.gameId, " gameSite: ", this.dbGameFree.GetSceneType(), " baseScore: ", baseScore) - } - if leaveCoin > takeCoin { - logger.Logger.Warn("robotSnId: ", p.SnId, " baseScore: ", baseScore, " takeCoin: ", takeCoin, " leaveCoin: ", leaveCoin) - } - if takeCoin > p.Coin { - p.Coin = takeCoin - } - } - - if !flag { - takerng := dbGameFree.GetRobotTakeCoin() - if len(takerng) >= 2 && takerng[1] > takerng[0] { - if takerng[0] < dbGameFree.GetLimitCoin() { - takerng[0] = dbGameFree.GetLimitCoin() - } - takeCoin = int64(common.RandInt(int(takerng[0]), int(takerng[1]))) - } else { - maxlimit := int64(dbGameFree.GetMaxCoinLimit()) - if maxlimit != 0 && p.Coin > maxlimit { - logger.Logger.Trace("Player coin:", p.Coin) - //在下限和上限之间随机,并对其的100的整数倍 - takeCoin = int64(common.RandInt(int(dbGameFree.GetLimitCoin()), int(maxlimit))) - logger.Logger.Trace("Take coin:", takeCoin) - } - if maxlimit == 0 && this.IsCoinScene() { - maxlimit = int64(common.RandInt(10, 50)) * int64(dbGameFree.GetLimitCoin()) - takeCoin = int64(common.RandInt(int(dbGameFree.GetLimitCoin()), int(maxlimit))) - logger.Logger.Trace("Take coin:", takeCoin) - } - } - takeCoin = takeCoin / 100 * 100 - //离场金币 - leaverng := dbGameFree.GetRobotLimitCoin() - if len(leaverng) >= 2 { - leaveCoin = int64(leaverng[0] + rand.Int63n(leaverng[1]-leaverng[0])) - } - } - - // 象棋积分 - chessScore := dbGameFree.GetChessScoreParams() - if len(chessScore) == 2 { - p.ChessGrade = int64(common.RandInt(int(chessScore[0]), int(chessScore[1]))) - } - - if takeCoin > p.Coin { - p.Coin = takeCoin - } - } - } - } - if p.IsRob { this.robotNum++ p.RobotRandName() @@ -356,95 +248,180 @@ func (this *Scene) PlayerEnter(p *Player, pos int, ischangeroom bool) bool { p.RandRobotPetSkillLevel() name := this.GetSceneName() logger.Logger.Tracef("(this *Scene) PlayerEnter(%v) robot(%v) robotlimit(%v)", name, this.robotNum, this.robotLimit) + + if !this.IsMatchScene() && !this.IsCustom() { + flag := false + // 本地游戏机器人携带金币 + if common.IsLocalGame(this.gameId) { + baseScore := this.BaseScore + arrs := srvdata.PBDB_CreateroomMgr.Datas.Arr + var tmpIds []int32 + for i := 0; i < len(arrs); i++ { + arr := arrs[i] + if int(arr.GameId) == this.gameId && arr.GameSite == this.dbGameFree.GetSceneType() { + betRange := arr.GetBetRange() + if len(betRange) == 0 { + continue + } + for j := 0; j < len(betRange); j++ { + if betRange[j] == baseScore && len(arr.GetGoldRange()) > 0 && arr.GetGoldRange()[0] != 0 { + tmpIds = append(tmpIds, arr.GetId()) + break + } + } + } + } + if len(tmpIds) > 0 { + randId := common.RandInt32Slice(tmpIds) + crData := srvdata.PBDB_CreateroomMgr.GetData(randId) + if crData != nil { + goldRange := crData.GetGoldRange() + if len(goldRange) == 2 { + takeCoin = common.RandFromRangeInt64(int64(goldRange[0]), int64(goldRange[1])) + flag = true + } else if len(goldRange) == 1 { + takeCoin = common.RandFromRangeInt64(int64(goldRange[0]), 2*int64(goldRange[0])) + flag = true + } + leaveCoin = int64(goldRange[0]) + for _, id := range tmpIds { + tmp := srvdata.PBDB_CreateroomMgr.GetData(id).GetGoldRange() + if int64(tmp[0]) < leaveCoin && tmp[0] != 0 { + leaveCoin = int64(tmp[0]) + } + } + } + } else { + logger.Logger.Warn("gameId: ", this.gameId, " gameSite: ", this.dbGameFree.GetSceneType(), " BaseScore: ", baseScore) + } + if leaveCoin > takeCoin { + logger.Logger.Warn("robotSnId: ", p.SnId, " BaseScore: ", baseScore, " takeCoin: ", takeCoin, " leaveCoin: ", leaveCoin) + } + if takeCoin > p.Coin { + p.Coin = takeCoin + } + } + + // 非本地游戏机器人携带金币 + if !flag { + takerng := this.dbGameFree.GetRobotTakeCoin() + if len(takerng) >= 2 && takerng[1] > takerng[0] { + if takerng[0] < this.dbGameFree.GetLimitCoin() { + takerng[0] = this.dbGameFree.GetLimitCoin() + } + takeCoin = int64(common.RandInt(int(takerng[0]), int(takerng[1]))) + } else { + maxlimit := int64(this.dbGameFree.GetMaxCoinLimit()) + if maxlimit != 0 && p.Coin > maxlimit { + logger.Logger.Trace("Player coin:", p.Coin) + //在下限和上限之间随机,并对其的100的整数倍 + takeCoin = int64(common.RandInt(int(this.dbGameFree.GetLimitCoin()), int(maxlimit))) + logger.Logger.Trace("Take coin:", takeCoin) + } + if maxlimit == 0 && this.IsCoinScene() { + maxlimit = int64(common.RandInt(10, 50)) * int64(this.dbGameFree.GetLimitCoin()) + takeCoin = int64(common.RandInt(int(this.dbGameFree.GetLimitCoin()), int(maxlimit))) + logger.Logger.Trace("Take coin:", takeCoin) + } + } + takeCoin = takeCoin / 100 * 100 + //离场金币 + leaverng := this.dbGameFree.GetRobotLimitCoin() + if len(leaverng) >= 2 { + leaveCoin = leaverng[0] + rand.Int63n(leaverng[1]-leaverng[0]) + } + } + + // 象棋积分 + chessScore := this.dbGameFree.GetChessScoreParams() + if len(chessScore) == 2 { + p.ChessGrade = int64(common.RandInt(int(chessScore[0]), int(chessScore[1]))) + } + + if takeCoin > p.Coin { + p.Coin = takeCoin + } + } } data, err := p.MarshalData() - if err == nil { - var gateSid int64 - if p.gateSess != nil { - if srvInfo, ok := p.gateSess.GetAttribute(srvlib.SessionAttributeServerInfo).(*srvlibproto.SSSrvRegiste); ok && srvInfo != nil { - sessionId := srvlib.NewSessionIdEx(srvInfo.GetAreaId(), srvInfo.GetType(), srvInfo.GetId(), 0) - gateSid = sessionId.Get() - } - } - msg := &serverproto.WGPlayerEnter{ - Sid: proto.Int64(p.sid), - SnId: proto.Int32(p.SnId), - GateSid: proto.Int64(gateSid), - SceneId: proto.Int(this.sceneId), - PlayerData: data, - IsLoaded: proto.Bool(ischangeroom), - IParams: p.MarshalIParam(), - SParams: p.MarshalSParam(), - CParams: p.MarshalCParam(), - } - p.takeCoin = takeCoin - p.sceneCoin = takeCoin - p.enterts = time.Now() - - if !p.IsRob { //保存下进入时的环境 - this.gameCtx[p.SnId] = &PlayerGameCtx{ - takeCoin: p.takeCoin, - enterTs: p.enterts.Unix(), - totalConvertibleFlow: p.TotalConvertibleFlow, - } - this.lastTime = time.Now() - } - msg.TakeCoin = proto.Int64(takeCoin) - msg.ExpectLeaveCoin = proto.Int64(leaveCoin) - msg.ExpectGameTimes = proto.Int32(gameTimes) - msg.Pos = proto.Int(p.pos) - if matchParams != nil { - for _, param := range matchParams { - msg.MatchParams = append(msg.MatchParams, param) - } - } - - // 道具 - dbItemArr := srvdata.GameItemMgr.GetArr(p.Platform) - if dbItemArr != nil { - msg.Items = make(map[int32]int64) - for _, dbItem := range dbItemArr { - msg.Items[dbItem.Id] = 0 - itemInfo := BagMgrSingleton.GetItem(p.SnId, dbItem.Id) - if itemInfo != nil { - msg.Items[dbItem.Id] = itemInfo.ItemNum - } - } - } - - // 排位积分 - ret := RankMgrSingleton.GetPlayerSeason(p.SnId) - if ret != nil && ret.PlayerRankSeason != nil { - msg.RankScore = make(map[int32]int64) - for k, v := range ret.RankType { - if v != nil { - msg.RankScore[k] = v.Score - } - } - } - - if p.IsRobot() { - msg.RankScore = make(map[int32]int64) - rankScore := this.dbGameFree.GetRankScoreParams() - if len(rankScore) == 2 { - switch { - case this.dbGameFree.GameDif == common.GameDifTienlen: - msg.RankScore[tienlen.RankType] = int64(common.RandInt(int(rankScore[0]), int(rankScore[1]))) - } - } - } - - proto.SetDefaults(msg) - 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) - 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) - this.DelPlayer(p) + if err != nil { + logger.Logger.Errorf("Scene PlayerEnter MarshalData failed, err:%v", err) return false } + + var gateSid int64 + if p.gateSess != nil { + if srvInfo, ok := p.gateSess.GetAttribute(srvlib.SessionAttributeServerInfo).(*srvlibproto.SSSrvRegiste); ok && srvInfo != nil { + sessionId := srvlib.NewSessionIdEx(srvInfo.GetAreaId(), srvInfo.GetType(), srvInfo.GetId(), 0) + gateSid = sessionId.Get() + } + } + msg := &serverproto.WGPlayerEnter{ + Sid: proto.Int64(p.sid), + GateSid: proto.Int64(gateSid), + SceneId: proto.Int(this.sceneId), + PlayerData: data, + TakeCoin: takeCoin, + IsLoaded: proto.Bool(ischangeroom), + IsQM: false, + ExpectLeaveCoin: leaveCoin, + ExpectGameTimes: gameTimes, + IParams: p.MarshalIParam(), + SParams: p.MarshalSParam(), + CParams: p.MarshalCParam(), + SnId: proto.Int32(p.SnId), + Pos: int32(p.pos), + MatchParams: matchParams, + } + // 道具 + msg.Items = make(map[int32]int64) + dbItemArr := srvdata.GameItemMgr.GetArr(p.Platform) + for _, dbItem := range dbItemArr { + msg.Items[dbItem.Id] = 0 + itemInfo := BagMgrSingleton.GetItem(p.SnId, dbItem.Id) + if itemInfo != nil { + msg.Items[dbItem.Id] = itemInfo.ItemNum + } + } + // 排位积分 + ret := RankMgrSingleton.GetPlayerSeason(p.SnId) + if ret != nil && ret.PlayerRankSeason != nil { + msg.RankScore = make(map[int32]int64) + for k, v := range ret.RankType { + if v != nil { + msg.RankScore[k] = v.Score + } + } + } + if p.IsRobot() { + msg.RankScore = make(map[int32]int64) + rankScore := this.dbGameFree.GetRankScoreParams() + if len(rankScore) == 2 { + switch { + case this.dbGameFree.GameDif == common.GameDifTienlen: + msg.RankScore[tienlen.RankType] = int64(common.RandInt(int(rankScore[0]), int(rankScore[1]))) + } + } + } + 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) + + p.scene = this + p.takeCoin = takeCoin + p.sceneCoin = takeCoin + p.enterts = time.Now() + this.players[p.SnId] = p + if !p.IsRob { //保存下进入时的环境 + this.gameCtx[p.SnId] = &PlayerGameCtx{ + takeCoin: p.takeCoin, + enterTs: p.enterts.Unix(), + } + this.lastTime = time.Now() + } + this.gameSess.AddPlayer(p) + FirePlayerEnterScene(p, this) + return true } func (this *Scene) AudienceEnter(p *Player, ischangeroom bool) bool { @@ -476,7 +453,6 @@ func (this *Scene) AudienceEnter(p *Player, ischangeroom bool) bool { PlayerData: data, TakeCoin: takeCoin, IsLoaded: proto.Bool(ischangeroom), - IsQM: false, IParams: p.MarshalIParam(), SParams: p.MarshalSParam(), CParams: p.MarshalCParam(), @@ -674,6 +650,9 @@ func (this *Scene) GetAudienceCnt() int { // IsFull 是否满人 // 不包含观众 func (this *Scene) IsFull() bool { + if this.playerNum == 0 { + return false + } return this.GetPlayerCnt() >= this.playerNum } @@ -717,15 +696,7 @@ func (this *Scene) SendToGame(packetId int, pack interface{}) bool { return false } -func (this *Scene) SendToClient(packetId int, pack interface{}, excludeId int32) { - for v, value := range this.players { - if v == excludeId { - continue - } - value.SendToClient(packetId, pack) - } -} - +// IsLongTimeInactive 房间是否长时间没有活动 func (this *Scene) IsLongTimeInactive() bool { tNow := time.Now() // 房间没有真人,没有观众,长时间没有真人进出房间 @@ -765,7 +736,7 @@ func (this *Scene) IsHundredScene() bool { // IsPrivateScene 私人房间 func (this *Scene) IsPrivateScene() bool { - return this.sceneId >= common.PrivateSceneStartId && this.sceneId < common.PrivateSceneMaxId || this.sceneMode == common.SceneMode_Private + return this.sceneId >= common.PrivateSceneStartId && this.sceneId < common.PrivateSceneMaxId } // IsCustom 房卡场房间 @@ -804,23 +775,6 @@ func (this *Scene) GetSceneName() string { return "[unknow scene name]" } -func (this *Scene) RandRobotCnt() { - if this.dbGameFree != nil { - number := this.dbGameFree.GetRobotNumRng() - if len(number) >= 2 { - if number[1] == number[0] { - this.robotLimit = int(number[0]) - } else { - if number[1] < number[0] { - number[1], number[0] = number[0], number[1] - } - this.robotLimit = int(number[1]) //int(number[0] + rand.Int31n(number[1]-number[0]) + 1) - } - } - return - } -} - func (this *Scene) IsPlatform(platform string) bool { if platform == "0" || platform == this.limitPlatform.IdStr { return true diff --git a/worldsrv/scenemgr.go b/worldsrv/scenemgr.go index 982790b..2c6e824 100644 --- a/worldsrv/scenemgr.go +++ b/worldsrv/scenemgr.go @@ -493,7 +493,7 @@ func (m *SceneMgr) OnMiniTimer() { 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() > int(s.dbGameFree.GetCreateRoomNum()) { + 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) } diff --git a/worldsrv/trascate_webapi.go b/worldsrv/trascate_webapi.go index 75efbcd..7106457 100644 --- a/worldsrv/trascate_webapi.go +++ b/worldsrv/trascate_webapi.go @@ -662,7 +662,7 @@ func init() { //gameid := 112 switch int(historyModel) { - case PlayerHistoryModel: // 历史记录 + case common.PlayerHistoryModel: // 历史记录 task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} { var genPlayerHistoryInfo = func(logid string, gameid int32, spinID, username string, isFree bool, createdTime, totalBetValue, totalPriceValue, totalBonusValue, multiple int64, player *qpapi.PlayerHistoryInfo) { player.SpinID = proto.String(spinID) @@ -728,7 +728,7 @@ func init() { } }), "CSGetPlayerHistoryHandlerWorld").Start() return common.ResponseTag_TransactYield, pack - case GameHistoryModel: + case common.GameHistoryModel: task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} { var genGameHistoryInfo = func(gameNumber string, createdTime, multiple int64, hash string, gamehistory *qpapi.GameHistoryInfo) {