修复预创建房间问题

This commit is contained in:
sk 2024-05-27 18:16:38 +08:00
parent da5bb97469
commit 516ab3f811
11 changed files with 300 additions and 457 deletions

View File

@ -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 //周卡奖励

View File

@ -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
}
}

View File

@ -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)
}
}
}

View File

@ -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

View File

@ -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 {

View File

@ -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)
}

View File

@ -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
}

View File

@ -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) {

View File

@ -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 {

View File

@ -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

View File

@ -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)