解决冲突

This commit is contained in:
sk 2024-05-28 09:26:18 +08:00
commit 8b478a9f33
14 changed files with 346 additions and 672 deletions

View File

@ -248,8 +248,8 @@ const (
GainWay_ActSignNew2 = 58 //签到看视频双倍领取 GainWay_ActSignNew2 = 58 //签到看视频双倍领取
GainWay_ItemUse = 59 //道具使用 GainWay_ItemUse = 59 //道具使用
GainWay_PhoneScore = 60 //手机积分活动 GainWay_PhoneScore = 60 //手机积分活动
GainWay_RankReward = 61 // GainWay_RankReward = 61 //排位奖励
GainWay_TaskReward = 62 // GainWay_TaskReward = 62 //任务奖励
GainWay_Interact = 63 //房间内互动效果 GainWay_Interact = 63 //房间内互动效果
GainWay_Collect = 64 //集卡活动 GainWay_Collect = 64 //集卡活动
GainWay_WeekCardAward = 65 //周卡奖励 GainWay_WeekCardAward = 65 //周卡奖励

View File

@ -520,7 +520,7 @@ func (this *CSInviteFriendOpHandler) Process(s *netlib.Session, packetid int, da
send(p) send(p)
return nil return nil
} }
if !p.EnterScene(scene, true, pos) { if !scene.PlayerEnter(p, pos, true) {
logger.Logger.Trace("CSInviteFriendHandler EnterScene fail") logger.Logger.Trace("CSInviteFriendHandler EnterScene fail")
opRetCode = friend.OpResultCode_OPRC_Error //进入房间失败 opRetCode = friend.OpResultCode_OPRC_Error //进入房间失败
send(p) send(p)

View File

@ -165,7 +165,7 @@ func (this *CSEnterRoomHandler) Process(s *netlib.Session, packetid int, data in
} }
} }
if !p.EnterScene(scene, true, -1) { if !scene.PlayerEnter(p, -1, true) {
code = gamehall.OpResultCode_Game_OPRC_Error_Game code = gamehall.OpResultCode_Game_OPRC_Error_Game
} }
@ -1339,58 +1339,6 @@ func (this *CSQueryRoomInfoHandler) ProcessLocalGame(s *netlib.Session, packetid
return nil 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 CSLotteryLogPacketFactory struct {
} }
type CSLotteryLogHandler struct { type CSLotteryLogHandler struct {
@ -1934,17 +1882,13 @@ func (this *CSCreateRoomHandler) ProcessLocalGame(s *netlib.Session, packetid in
} }
scene, code = p.CreateLocalGameScene(roomId, int(gameId), int(gameSite), int(msg.GetSceneMode()), maxPlayerNum, scene, code = p.CreateLocalGameScene(roomId, int(gameId), int(gameSite), int(msg.GetSceneMode()), maxPlayerNum,
params, dbGameFree, baseScore, csp.groupId) params, dbGameFree, baseScore, csp.groupId)
if scene != nil { if scene != nil && code == gamehall.OpResultCode_Game_OPRC_Sucess_Game {
if code == gamehall.OpResultCode_Game_OPRC_Sucess_Game {
logger.Logger.Tracef("CSCreateRoomHandler SnId:%v Create Sucess GameId:%v", p.SnId, gameId) logger.Logger.Tracef("CSCreateRoomHandler SnId:%v Create Sucess GameId:%v", p.SnId, gameId)
// try enter scene csp.AddScene(scene)
csp.scenes[scene.sceneId] = scene if !scene.PlayerEnter(p, -1, true) {
scene.csp = csp
if !p.EnterScene(scene, true, -1) {
code = gamehall.OpResultCode_Game_OPRC_Error_Game code = gamehall.OpResultCode_Game_OPRC_Error_Game
} }
} }
}
failed: failed:
resp := &gamehall.SCCreateRoom{ resp := &gamehall.SCCreateRoom{
@ -2048,7 +1992,7 @@ func (this *CSCreateRoomHandler) ProcessThirteen(s *netlib.Session, packetid int
// try enter scene // try enter scene
csp.scenes[scene.sceneId] = scene csp.scenes[scene.sceneId] = scene
scene.csp = csp scene.csp = csp
if !p.EnterScene(scene, true, -1) { if !scene.PlayerEnter(p, -1, true) {
code = gamehall.OpResultCode_Game_OPRC_Error_Game code = gamehall.OpResultCode_Game_OPRC_Error_Game
} }
} }

View File

@ -1,154 +0,0 @@
package main
import (
"github.com/globalsign/mgo"
"mongo.games.com/game/common"
"mongo.games.com/game/model"
"mongo.games.com/game/proto"
"mongo.games.com/game/protocol/activity"
"mongo.games.com/game/protocol/server"
"mongo.games.com/game/srvdata"
"mongo.games.com/goserver/core/logger"
"time"
)
var ActSignMgrSington = &ActSignMgr{
SignConfigs: make(map[int]*server.DB_ActSign),
}
type ActSignMgr struct {
SignConfigs map[int]*server.DB_ActSign
}
func (this *ActSignMgr) Init() {
if this.SignConfigs == nil {
this.SignConfigs = make(map[int]*server.DB_ActSign)
}
for _, v := range srvdata.PBDB_ActSignMgr.Datas.GetArr() {
this.SignConfigs[int(v.Id)] = v
}
}
func (this *ActSignMgr) GetConfig(id int) *server.DB_ActSign {
signConfig, ok := this.SignConfigs[id]
if ok {
return signConfig
}
return nil
}
func (this *ActSignMgr) OnPlayerLogin(player *Player) error {
return this.RefixedPlayerData(player)
}
func (this *ActSignMgr) OnDayChanged(player *Player) error {
//跨天不需要
//this.RefixedPlayerData(player)
//this.SendSignDataToPlayer(player)
return nil
}
func (this *ActSignMgr) RefixedPlayerData(player *Player) error {
if player.IsRob {
return nil
}
if player.SignData == nil {
player.SignData = &model.SignData{
SignIndex: 0,
LastSignTickets: 0,
}
}
return nil
}
func (this *ActSignMgr) SendSignDataToPlayer(player *Player) {
if player.IsRob {
return
}
pack := &activity.SCSignData{}
//已经领取第几个
pack.SignCount = proto.Int(player.SignData.SignIndex)
if player.SignData.LastSignTickets != 0 {
lastSignTime := time.Unix(player.SignData.LastSignTickets, 0)
dayDiff := int32(common.DiffDay(time.Now(), lastSignTime))
if dayDiff == 0 {
pack.TodaySign = proto.Int32(1)
} else {
pack.TodaySign = proto.Int32(0)
}
} else {
pack.TodaySign = proto.Int32(0)
}
proto.SetDefaults(pack)
player.SendToClient(int(activity.ActSignPacketID_PACKET_SCSignData), pack)
logger.Logger.Trace("SCSignData: ", pack)
}
func (this *ActSignMgr) CanSign(player *Player, signIndex int) activity.OpResultCode_ActSign {
signConfig := this.GetConfig(signIndex)
if signConfig == nil {
return activity.OpResultCode_ActSign_OPRC_Activity_Sign_Error
}
if player.SignData.LastSignTickets != 0 {
lastSignTime := time.Unix(player.SignData.LastSignTickets, 0)
dayDiff := int32(common.DiffDay(time.Now(), lastSignTime))
if dayDiff == 0 {
if player.SignData.SignIndex == signIndex {
return activity.OpResultCode_ActSign_OPRC_Activity_Sign_Repeat
} else {
return activity.OpResultCode_ActSign_OPRC_Activity_Sign_Config_Day_Error
}
}
if player.SignData.SignIndex != (signIndex - 1) {
return activity.OpResultCode_ActSign_OPRC_Activity_Sign_Config_Day_Error
}
} else {
if signIndex != 1 {
return activity.OpResultCode_ActSign_OPRC_Activity_Sign_Config_Day_Error
}
}
return activity.OpResultCode_ActSign_OPRC_Activity_Sign_Sucess
}
//func (this *ActSignMgr) Sign(player *Player, signIndex int, signType int32) activity.OpResultCode_ActSign {
// errCode := this.CanSign(player, signIndex)
// if errCode != activity.OpResultCode_ActSign_OPRC_Activity_Sign_Sucess {
// return errCode
// }
//
// signConfig := this.GetConfig(signIndex)
// if signConfig == nil {
// return activity.OpResultCode_ActSign_OPRC_Activity_Sign_Error
// }
//
// player.SignData.LastSignTickets = time.Now().Unix()
// player.SignData.SignIndex = signIndex
//
// logger.Logger.Info("签到成功: ", signConfig)
// grade := signConfig.Grade
// switch signType {
// case 0: //普通签到
// case 1: //双倍签到
// grade *= 2
// }
// switch signConfig.Type {
// case 1: //金币
// player.AddCoin(int64(grade), 0, common.GainWay_ActSign, strconv.Itoa(signIndex), time.Now().Format("2006-01-02 15:04:05"))
// case 2: //钻石
// player.AddDiamond(int64(grade), 0, common.GainWay_ActSign, strconv.Itoa(signIndex), time.Now().Format("2006-01-02 15:04:05"))
// case 3: //道具
// item := &Item{
// ItemId: signConfig.Item_Id,
// ItemNum: int64(grade),
// }
// BagMgrSingleton.AddItems(player, []*Item{item}, 0, common.GainWay_ActSign, strconv.Itoa(signIndex), time.Now().Format("2006-01-02 15:04:05"), 0, 0, false)
// }
// return activity.OpResultCode_ActSign_OPRC_Activity_Sign_Sucess
//}
func init() {
mgo.SetStats(true)
}

View File

@ -23,10 +23,10 @@ var CoinSceneMgrSingleton = &CoinSceneMgr{
playerChanging: make(map[int32]int32), playerChanging: make(map[int32]int32),
//按平台管理 //按平台管理
scenesOfPlatform: make(map[string]map[int32]*CoinScenePool), scenesOfPlatform: make(map[string]map[int32]*CoinScenePool),
platformOfScene: make(map[int32]string), platformOfScene: make(map[int]string),
//按组管理 //按组管理
scenesOfGroup: make(map[int32]map[int32]*CoinScenePool), scenesOfGroup: make(map[int32]map[int32]*CoinScenePool),
groupOfScene: make(map[int32]int32), groupOfScene: make(map[int]int32),
} }
type CreateRoomCache struct { type CreateRoomCache struct {
@ -39,14 +39,14 @@ type CoinSceneMgr struct {
//按平台管理 //按平台管理
scenesOfPlatform map[string]map[int32]*CoinScenePool // platform:gamefreeid 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 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 获取一个场景池 // GetCoinScenePool 获取一个场景池
@ -72,29 +72,33 @@ func (csm *CoinSceneMgr) GetCoinScenePool(plt string, id int32) *CoinScenePool {
} }
} }
var dbGameFree *server_proto.DB_GameFree if gf.GetDbGameFree() == nil {
if groupId != 0 {
conf := PlatformGameGroupMgrSington.GetGameGroup(groupId)
if conf != nil {
dbGameFree = conf.GetDbGameFree()
}
}
if dbGameFree == nil {
dbGameFree = gf.GetDbGameFree()
}
if dbGameFree == nil {
return 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, func (csm *CoinSceneMgr) findCoinScenePool(platform string, id int32) (pools map[int32]*CoinScenePool, groupID int32,
dbGameFree *server.DB_GameFree) { dbGameFree *server.DB_GameFree) {
gf := PlatformMgrSingleton.GetGameFree(platform, id) gf := PlatformMgrSingleton.GetGameFree(platform, id)
if gf == nil { if gf == nil || gf.GetDbGameFree() == nil {
return nil, 0, nil return nil, 0, nil
} }
groupId := gf.GetGroupId() groupId := gf.GetGroupId()
@ -102,18 +106,14 @@ func (csm *CoinSceneMgr) findCoinScenePool(platform string, id int32) (pools map
var ss map[int32]*CoinScenePool var ss map[int32]*CoinScenePool
var ok bool var ok bool
if groupId != 0 { if groupId != 0 {
pgg := PlatformGameGroupMgrSington.GetGameGroup(groupId)
if pgg != nil {
ss, ok = csm.scenesOfGroup[groupId] ss, ok = csm.scenesOfGroup[groupId]
if !ok { if !ok {
ss = make(map[int32]*CoinScenePool) ss = make(map[int32]*CoinScenePool)
csm.scenesOfGroup[groupId] = ss csm.scenesOfGroup[groupId] = ss
} }
return ss, groupId, pgg.GetDbGameFree() return ss, groupId, gf.GetDbGameFree()
}
} }
if ss == nil {
ss, ok = csm.scenesOfPlatform[platform] ss, ok = csm.scenesOfPlatform[platform]
if !ok { if !ok {
ss = make(map[int32]*CoinScenePool) ss = make(map[int32]*CoinScenePool)
@ -122,11 +122,8 @@ func (csm *CoinSceneMgr) findCoinScenePool(platform string, id int32) (pools map
return ss, 0, gf.GetDbGameFree() return ss, 0, gf.GetDbGameFree()
} }
return nil, 0, nil
}
// PlayerEnter 玩家进入房间池 // 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) logger.Logger.Tracef("(csm *CoinSceneMgr) PlayerEnter snid:%v id:%v roomid:%v exclude:%v", p.SnId, id, roomId, exclude)
if p.isDelete { //删档用户不让进游戏 if p.isDelete { //删档用户不让进游戏
return hall_proto.OpResultCode_OPRC_RoomHadClosed 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 return hall_proto.OpResultCode_OPRC_Error
} }
pools, groupID, free := csm.findCoinScenePool(platform.IdStr, id) csp := csm.GetCoinScenePool(platform.IdStr, id)
if pools == nil {
return hall_proto.OpResultCode_OPRC_RoomHadClosed
}
csp, ok := pools[id] ret := csp.PlayerEnter(p, roomId, exclude, isChangeRoom)
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)
logger.Logger.Warnf("(csm *CoinSceneMgr) PlayerEnter snid:%v find in id:%v exclude:%v return false", p.SnId, id, exclude) logger.Logger.Warnf("(csm *CoinSceneMgr) PlayerEnter snid:%v find in id:%v exclude:%v return false", p.SnId, id, exclude)
return ret return ret
@ -244,28 +228,28 @@ func (csm *CoinSceneMgr) PlayerLeave(p *Player, reason int) bool {
// OnDestroyScene 解散房间 // OnDestroyScene 解散房间
// sceneId 房间id // sceneId 房间id
func (csm *CoinSceneMgr) OnDestroyScene(sceneId int) { 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 { if ss, ok := csm.scenesOfPlatform[platformName]; ok {
for _, csp := range ss { for _, csp := range ss {
csp.OnDestroyScene(sceneId) 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 { if ss, ok := csm.scenesOfGroup[groupId]; ok {
for _, csp := range ss { for _, csp := range ss {
csp.OnDestroyScene(sceneId) csp.OnDestroyScene(sceneId)
} }
} }
delete(csm.groupOfScene, int32(sceneId)) delete(csm.groupOfScene, sceneId)
} }
} }
// GetPlatformBySceneId 获取房间所在平台 // GetPlatformBySceneId 获取房间所在平台
func (csm *CoinSceneMgr) GetPlatformBySceneId(sceneId int) string { func (csm *CoinSceneMgr) GetPlatformBySceneId(sceneId int) string {
if platformName, ok := csm.platformOfScene[int32(sceneId)]; ok { if platformName, ok := csm.platformOfScene[sceneId]; ok {
return platformName return platformName
} }
s := SceneMgrSingleton.GetScene(sceneId) s := SceneMgrSingleton.GetScene(sceneId)
@ -417,76 +401,18 @@ func (csm *CoinSceneMgr) StartChangeCoinSceneTransact(p *Player, id int32, exclu
return hall_proto.OpResultCode_OPRC_Error return hall_proto.OpResultCode_OPRC_Error
} }
// ListRooms 给客户端发送场次房间列表 // TouchCreateRoom 触发预创建房间
// id 场次id // 1.模块启动后触发
func (csm *CoinSceneMgr) ListRooms(p *Player, id int32) bool { // 2.游戏服建立连接后触发
//多平台支持 // 3.房间解散后触发
platform := p.GetPlatform() func (csm *CoinSceneMgr) TouchCreateRoom(platform string, gameFreeId int32) {
if platform == nil { gf := PlatformMgrSingleton.GetGameFree(platform, gameFreeId)
return false if gf.Status && gf.DbGameFree.GetCreateRoomNum() > 0 {
} logger.Logger.Tracef("TouchCreateRoom platform:%v gameFreeId:%v", platform, gameFreeId)
csm.delayCache = append(csm.delayCache, &CreateRoomCache{
pools, groupID, free := csm.findCoinScenePool(platform.IdStr, id) platformName: platform,
if pools == nil { gameFreeId: gameFreeId,
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
}
}
} }
} }
@ -495,42 +421,14 @@ func (csm *CoinSceneMgr) ModuleName() string {
} }
func (csm *CoinSceneMgr) Init() { func (csm *CoinSceneMgr) Init() {
// 场次池预创建 // 房间池初始化
for _, platform := range PlatformMgrSingleton.GetPlatforms() { for _, platform := range PlatformMgrSingleton.GetPlatforms() {
if platform.Isolated || platform.IdStr == "" { if platform.Isolated || platform.IdStr == "" {
arr := srvdata.PBDB_GameFreeMgr.Datas.GetArr() for _, v := range srvdata.PBDB_GameFreeMgr.Datas.GetArr() {
for _, dbGame := range arr { gps := PlatformMgrSingleton.GetGameFree(platform.IdStr, v.GetId())
gps := PlatformMgrSingleton.GetGameFree(platform.IdStr, dbGame.GetId())
if gps != nil { if gps != nil {
// dbGameFree csm.GetCoinScenePool(platform.IdStr, v.GetId())
dbGameFree := gps.DbGameFree csm.TouchCreateRoom(platform.IdStr, v.GetId())
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
}
}
}
} }
} }
} }
@ -538,8 +436,18 @@ func (csm *CoinSceneMgr) Init() {
} }
func (csm *CoinSceneMgr) Update() { func (csm *CoinSceneMgr) Update() {
// 预创建房间 cnt := len(csm.delayCache)
csm.CreateRoomByCache() 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() { func (csm *CoinSceneMgr) Shutdown() {
@ -549,24 +457,15 @@ func (csm *CoinSceneMgr) Shutdown() {
//=====================PlatformObserver====================== //=====================PlatformObserver======================
func (this *CoinSceneMgr) OnPlatformCreate(p *Platform) { 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) { func (this *CoinSceneMgr) OnPlatformDestroy(p *Platform) {
if p == nil { if p == nil {
return return
} }
if csps, ok := this.scenesOfPlatform[p.IdStr]; ok { if v, ok := this.scenesOfPlatform[p.IdStr]; ok {
for _, csp := range csps { for _, csp := range v {
pack := &server_proto.WGGraceDestroyScene{} pack := &server_proto.WGGraceDestroyScene{}
for _, scene := range csp.scenes { for _, scene := range csp.scenes {
pack.Ids = append(pack.Ids, int32(scene.sceneId)) 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) { func (this *CoinSceneMgr) OnPlatformChangeDisabled(p *Platform, disabled bool) {
if disabled { if disabled {
this.OnPlatformDestroy(p) 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), srvlib.ServerSessionMgrSington.Broadcast(int(server_proto.SSPacketID_PACKET_WG_GRACE_DESTROYSCENE),
pack, common.GetSelfAreaId(), srvlib.GameServerType) 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) gps := PlatformMgrSingleton.GetGameFrees(platform.IdStr)
for _, v := range gps { for _, v := range gps {
if v.Status && v.DbGameFree.GetCreateRoomNum() > 0 && (wildGs || common.InSliceInt32(gs.gameIds, v.DbGameFree.GetGameId())) { if v != nil && (wildGs || common.InSliceInt32(gs.gameIds, v.DbGameFree.GetGameId())) {
csm.delayCache = append(csm.delayCache, CreateRoomCache{gameFreeId: v.DbGameFree.Id, platformName: platform.IdStr}) csm.TouchCreateRoom(platform.IdStr, v.DbGameFree.Id)
} }
} }
} }

View File

@ -1,12 +1,12 @@
package main package main
import ( import (
"mongo.games.com/game/common"
"mongo.games.com/goserver/core/logger" "mongo.games.com/goserver/core/logger"
"mongo.games.com/game/model" "mongo.games.com/game/model"
"mongo.games.com/game/proto" gamehallproto "mongo.games.com/game/protocol/gamehall"
gamehall_proto "mongo.games.com/game/protocol/gamehall" serverproto "mongo.games.com/game/protocol/server"
server_proto "mongo.games.com/game/protocol/server"
"mongo.games.com/game/srvdata" "mongo.games.com/game/srvdata"
) )
@ -15,21 +15,24 @@ type CoinScenePool struct {
platform string // 平台id platform string // 平台id
groupId int32 // 组id groupId int32 // 组id
id int32 // 场次id id int32 // 场次id
dbGameFree *server_proto.DB_GameFree // 场次配置 dbGameFree *serverproto.DB_GameFree // 场次配置
dbGameRule *server_proto.DB_GameRule // 场次配置 dbGameRule *serverproto.DB_GameRule // 场次配置
scenes map[int]*Scene // 所有房间,房间id scenes map[int]*Scene // 所有房间,房间id
players map[int32]struct{} // 玩家id players map[int32]struct{} // 玩家id
// 扩展数据 // 扩展数据
extraData interface{} extraData interface{}
// 匹配规则 // 房间池规则
policy ICoinScenePool policy ICoinScenePool
} }
func NewCoinScenePool(platform string, groupId int32, dbGameFree *server_proto.DB_GameFree) *CoinScenePool { func newCoinScenePool(platform string, groupId int32, dbGameFree *serverproto.DB_GameFree) *CoinScenePool {
if dbGameFree == nil { if dbGameFree == nil {
return nil return nil
} }
if platform == "" {
platform = DefaultPlatform
}
dbGameRule := srvdata.PBDB_GameRuleMgr.GetData(dbGameFree.GetGameRule()) dbGameRule := srvdata.PBDB_GameRuleMgr.GetData(dbGameFree.GetGameRule())
if dbGameRule == nil { if dbGameRule == nil {
@ -87,20 +90,20 @@ func (csp *CoinScenePool) CanInviteRob() bool {
} }
// CanEnter 检查入场条件 // CanEnter 检查入场条件
func (csp *CoinScenePool) CanEnter(p *Player) gamehall_proto.OpResultCode { func (csp *CoinScenePool) CanEnter(p *Player) gamehallproto.OpResultCode {
if csp.dbGameFree == nil || p == nil { if csp.dbGameFree == nil || p == nil {
return gamehall_proto.OpResultCode_OPRC_Error return gamehallproto.OpResultCode_OPRC_Error
} }
//检测房间状态是否开启 //检测房间状态是否开启
gps := PlatformMgrSingleton.GetGameFree(p.Platform, csp.id) gps := PlatformMgrSingleton.GetGameFree(p.Platform, csp.id)
if gps == nil || !gps.Status { if gps == nil || !gps.Status {
return gamehall_proto.OpResultCode_OPRC_RoomHadClosed return gamehallproto.OpResultCode_OPRC_RoomHadClosed
} }
dbGameFree := csp.dbGameFree dbGameFree := csp.dbGameFree
if dbGameFree == nil { if dbGameFree == nil {
return gamehall_proto.OpResultCode_OPRC_RoomHadClosed return gamehallproto.OpResultCode_OPRC_RoomHadClosed
} }
//检查游戏次数限制 //检查游戏次数限制
@ -109,7 +112,7 @@ func (csp *CoinScenePool) CanEnter(p *Player) gamehall_proto.OpResultCode {
if dbGameFree.GetPlayNumLimit() != 0 && if dbGameFree.GetPlayNumLimit() != 0 &&
todayData != nil && todayData != nil &&
todayData.GameTimes >= int64(dbGameFree.GetPlayNumLimit()) { todayData.GameTimes >= int64(dbGameFree.GetPlayNumLimit()) {
return gamehall_proto.OpResultCode_OPRC_RoomGameTimes return gamehallproto.OpResultCode_OPRC_RoomGameTimes
} }
} }
@ -117,28 +120,44 @@ func (csp *CoinScenePool) CanEnter(p *Player) gamehall_proto.OpResultCode {
} }
// CanAudienceEnter 检查观众入场条件 // CanAudienceEnter 检查观众入场条件
func (csp *CoinScenePool) CanAudienceEnter(p *Player) gamehall_proto.OpResultCode { func (csp *CoinScenePool) CanAudienceEnter(p *Player) gamehallproto.OpResultCode {
if csp.dbGameFree == nil || p == nil { if csp.dbGameFree == nil || p == nil {
return gamehall_proto.OpResultCode_OPRC_Error return gamehallproto.OpResultCode_OPRC_Error
} }
//检测房间状态是否开启 //检测房间状态是否开启
gps := PlatformMgrSingleton.GetGameFree(p.Platform, csp.id) gps := PlatformMgrSingleton.GetGameFree(p.Platform, csp.id)
if gps == nil { if gps == nil {
return gamehall_proto.OpResultCode_OPRC_RoomHadClosed return gamehallproto.OpResultCode_OPRC_RoomHadClosed
} }
dbGameFree := csp.dbGameFree dbGameFree := csp.dbGameFree
if dbGameFree == nil { if dbGameFree == nil {
return gamehall_proto.OpResultCode_OPRC_RoomHadClosed return gamehallproto.OpResultCode_OPRC_RoomHadClosed
} }
return csp.policy.CanAudienceEnter(csp, p) 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 玩家进入房间池 // PlayerEnter 玩家进入房间池
func (csp *CoinScenePool) PlayerEnter(p *Player, roomId int32, exclude []int32, ischangeroom bool) gamehall_proto.OpResultCode { // exclude 排除的房间id
if ret := csp.CanEnter(p); ret != gamehall_proto.OpResultCode_OPRC_Sucess { // isChangeRoom 是否换房
func (csp *CoinScenePool) PlayerEnter(p *Player, roomId int32, exclude []int32, isChangeRoom bool) gamehallproto.OpResultCode {
if ret := csp.CanEnter(p); ret != gamehallproto.OpResultCode_OPRC_Sucess {
logger.Logger.Warnf("(csp *CoinScenePool) PlayerEnter find snid:%v csp.CanEnter coin:%v ret:%v id:%v", p.SnId, logger.Logger.Warnf("(csp *CoinScenePool) PlayerEnter find snid:%v csp.CanEnter coin:%v ret:%v id:%v", p.SnId,
p.Coin, ret, csp.dbGameFree.GetId()) p.Coin, ret, csp.dbGameFree.GetId())
return ret return ret
@ -146,76 +165,77 @@ func (csp *CoinScenePool) PlayerEnter(p *Player, roomId int32, exclude []int32,
if p.scene != nil { if p.scene != nil {
logger.Logger.Warnf("(csp *CoinScenePool) PlayerEnter[p.scene != nil] find snid:%v in scene:%v gameId:%v", p.SnId, p.scene.sceneId, p.scene.gameId) logger.Logger.Warnf("(csp *CoinScenePool) PlayerEnter[p.scene != nil] find snid:%v in scene:%v gameId:%v", p.SnId, p.scene.sceneId, p.scene.gameId)
return gamehall_proto.OpResultCode_OPRC_Error return gamehallproto.OpResultCode_OPRC_Error
} }
var scene *Scene var scene *Scene
// 进入房间 // 进入房间
if roomId != 0 && (p.IsRob || p.GMLevel > 0 || csp.dbGameFree.GetCreateRoomNum() != 0) { // 指定房间id进入忽略排除exclude只有机器人和进入预创建房间才允许
if roomId != 0 && (p.IsRob || csp.dbGameFree.GetCreateRoomNum() != 0) {
if s, ok := csp.scenes[int(roomId)]; ok { if s, ok := csp.scenes[int(roomId)]; ok {
if s != nil && !s.deleting { //指定房间id进入那么忽略掉排除id if s != nil && !s.deleting { //指定房间id进入那么忽略掉排除id
if s.IsFull() { if s.IsFull() {
return gamehall_proto.OpResultCode_OPRC_RoomIsFull return gamehallproto.OpResultCode_OPRC_RoomIsFull
} }
if sp, ok := s.sp.(*ScenePolicyData); ok { if sp, ok := s.sp.(*ScenePolicyData); ok {
if !s.starting || sp.EnterAfterStart { if !s.starting || sp.EnterAfterStart {
scene = s scene = s
} else { } else {
logger.Logger.Warnf("(csp *CoinScenePool) PlayerEnter[!s.starting || sp.EnterAfterStart] snid:%v sceneid:%v starting:%v EnterAfterStart:%v", p.SnId, s.sceneId, s.starting, sp.EnterAfterStart) logger.Logger.Warnf("(csp *CoinScenePool) PlayerEnter[!s.starting || sp.EnterAfterStart] snid:%v sceneid:%v starting:%v EnterAfterStart:%v", p.SnId, s.sceneId, s.starting, sp.EnterAfterStart)
return gamehall_proto.OpResultCode_OPRC_Error return gamehallproto.OpResultCode_OPRC_Error
} }
} }
} }
} else { } else {
logger.Logger.Warnf("(csp *CoinScenePool) PlayerEnter(robot:%v,roomid:%v, exclude:%v, ischangeroom:%v) no found scene", p.SnId, roomId, exclude, ischangeroom) logger.Logger.Warnf("(csp *CoinScenePool) PlayerEnter(robot:%v,roomid:%v, exclude:%v, isChangeRoom:%v) no found scene", p.SnId, roomId, exclude, isChangeRoom)
return gamehall_proto.OpResultCode_OPRC_Error return gamehallproto.OpResultCode_OPRC_Error
} }
} }
if scene == nil { if scene == nil {
var ret gamehall_proto.OpResultCode var ret gamehallproto.OpResultCode
ret, scene = csp.policy.PlayerEnter(csp, p, exclude, ischangeroom) ret, scene = csp.policy.PlayerEnter(csp, p, exclude, isChangeRoom)
if ret != gamehall_proto.OpResultCode_OPRC_Sucess { if ret != gamehallproto.OpResultCode_OPRC_Sucess {
return ret return ret
} }
} }
// 没有找到房间,创建新房间
if scene == nil { if scene == nil {
scene = csp.policy.NewScene(csp, p) scene = csp.policy.NewScene(csp, p)
if scene != nil { if scene != nil {
csp.scenes[scene.sceneId] = scene csp.AddScene(scene)
scene.csp = csp
} else { } else {
logger.Logger.Errorf("Create %v scene failed.", csp.id) logger.Logger.Errorf("Create %v scene failed.", csp.id)
} }
} }
if scene != nil { if scene != nil {
if p.EnterScene(scene, ischangeroom, -1) { if scene.PlayerEnter(p, -1, isChangeRoom) {
csp.OnPlayerEnter(p, scene) csp.OnPlayerEnter(p, scene)
return gamehall_proto.OpResultCode_OPRC_Sucess return gamehallproto.OpResultCode_OPRC_Sucess
} }
} }
logger.Logger.Warnf("(csp *CoinScenePool) PlayerEnter snid:%v not found scene", p.SnId) logger.Logger.Warnf("(csp *CoinScenePool) PlayerEnter snid:%v not found scene", p.SnId)
return gamehall_proto.OpResultCode_OPRC_SceneServerMaintain return gamehallproto.OpResultCode_OPRC_SceneServerMaintain
} }
// AudienceEnter 观众入场 // AudienceEnter 观众入场
func (csp *CoinScenePool) AudienceEnter(p *Player, roomId int32, exclude []int32, ischangeroom bool) gamehall_proto.OpResultCode { func (csp *CoinScenePool) AudienceEnter(p *Player, roomId int32, exclude []int32, isChangeRoom bool) gamehallproto.OpResultCode {
if ret := csp.CanAudienceEnter(p); ret != gamehall_proto.OpResultCode_OPRC_Sucess { 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()) 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 return ret
} }
if p.scene != nil { if p.scene != nil {
logger.Logger.Warnf("(csp *CoinScenePool) AudienceEnter[p.scene != nil] find snid:%v in scene:%v gameId:%v", p.SnId, p.scene.sceneId, p.scene.gameId) logger.Logger.Warnf("(csp *CoinScenePool) AudienceEnter[p.scene != nil] find snid:%v in scene:%v gameId:%v", p.SnId, p.scene.sceneId, p.scene.gameId)
return gamehall_proto.OpResultCode_OPRC_Error return gamehallproto.OpResultCode_OPRC_Error
} }
var scene *Scene var scene *Scene
if roomId != 0 { if roomId != 0 {
if s, ok := csp.scenes[int(roomId)]; ok { if s, ok := csp.scenes[int(roomId)]; ok {
if s != nil && !s.deleting /*&& s.sceneId != int(exclude)*/ { if s != nil && !s.deleting {
scene = s scene = s
} else { } 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) logger.Logger.Warnf("(csp *CoinScenePool) AudienceEnter[!s.starting || sp.EnterAfterStart] snid:%v sceneid:%v starting:%v EnterAfterStart:%v", p.SnId, s.sceneId, s.starting)
@ -224,29 +244,29 @@ func (csp *CoinScenePool) AudienceEnter(p *Player, roomId int32, exclude []int32
} }
if scene == nil { if scene == nil {
var ret gamehall_proto.OpResultCode var ret gamehallproto.OpResultCode
ret, scene = csp.policy.AudienceEnter(csp, p, exclude, ischangeroom) ret, scene = csp.policy.AudienceEnter(csp, p, exclude, isChangeRoom)
if ret != gamehall_proto.OpResultCode_OPRC_Sucess { if ret != gamehallproto.OpResultCode_OPRC_Sucess {
return ret return ret
} }
} }
if scene == nil { if scene == nil {
return gamehall_proto.OpResultCode_OPRC_NoFindDownTiceRoom return gamehallproto.OpResultCode_OPRC_NoFindDownTiceRoom
} }
if scene != nil {
// 预创建房间检查观众数量 // 预创建房间检查观众数量
if scene.IsPreCreateScene() && scene.GetAudienceCnt() >= model.GameParamData.MaxAudienceNum { if scene.IsPreCreateScene() && scene.GetAudienceCnt() >= model.GameParamData.MaxAudienceNum {
return gamehall_proto.OpResultCode_OPRC_RoomIsFull return gamehallproto.OpResultCode_OPRC_RoomIsFull
} }
if scene.AudienceEnter(p, ischangeroom) {
if scene.AudienceEnter(p, isChangeRoom) {
csp.OnPlayerEnter(p, scene) csp.OnPlayerEnter(p, scene)
return gamehall_proto.OpResultCode_OPRC_Sucess return gamehallproto.OpResultCode_OPRC_Sucess
}
} }
logger.Logger.Warnf("(csp *CoinScenePool) PlayerEnter snid:%v not found scene", p.SnId) logger.Logger.Warnf("(csp *CoinScenePool) PlayerEnter snid:%v not found scene", p.SnId)
return gamehall_proto.OpResultCode_OPRC_NoFindDownTiceRoom return gamehallproto.OpResultCode_OPRC_NoFindDownTiceRoom
} }
// OnPlayerEnter 玩家进入房间完成 // OnPlayerEnter 玩家进入房间完成
@ -351,13 +371,16 @@ func (csp *CoinScenePool) OnPlayerLeave(s *Scene, p *Player) {
} }
// OnDestroyScene 解散房间 // OnDestroyScene 解散房间
// todo 是否需要优化 // 房间解散一定是游戏服确认的worldsrv收到游戏房间解散消息后解散房间
func (csp *CoinScenePool) OnDestroyScene(sceneId int) { func (csp *CoinScenePool) OnDestroyScene(sceneId int) {
scene, ok := csp.scenes[sceneId] scene, ok := csp.scenes[sceneId]
if !ok { if !ok {
return return
} }
logger.Logger.Tracef("(csp *CoinScenePool) OnDestroyScene scene:%v", sceneId)
// todo 是否需要优化
for id := range scene.players { for id := range scene.players {
player := PlayerMgrSington.GetPlayerBySnId(id) player := PlayerMgrSington.GetPlayerBySnId(id)
if player != nil { if player != nil {
@ -386,6 +409,7 @@ func (csp *CoinScenePool) OnDestroyScene(sceneId int) {
csp.policy.OnDestroyScene(csp, sceneId) csp.policy.OnDestroyScene(csp, sceneId)
scene.csp = nil // 解除关联 scene.csp = nil // 解除关联
delete(csp.scenes, sceneId) delete(csp.scenes, sceneId)
CoinSceneMgrSingleton.TouchCreateRoom(csp.platform, csp.dbGameFree.Id)
} }
// PreCreateRoom 预创建房间 // PreCreateRoom 预创建房间
@ -393,67 +417,78 @@ func (csp *CoinScenePool) PreCreateRoom() {
if csp.platform == DefaultPlatform { if csp.platform == DefaultPlatform {
return return
} }
preCreateNum := int(csp.dbGameFree.GetCreateRoomNum())
if preCreateNum == 0 || model.GameParamData.ClosePreCreateRoom {
return
}
if p := PlatformMgrSingleton.GetPlatform(csp.platform); p == nil || p.Disable { if p := PlatformMgrSingleton.GetPlatform(csp.platform); p == nil || p.Disable {
return return
} }
preCreateNum := int(csp.dbGameFree.GetCreateRoomNum())
if preCreateNum <= 0 || model.GameParamData.ClosePreCreateRoom {
return
}
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.AddScene(scene)
}
}
}
}
func (csp *CoinScenePool) GetRoomNum(mode ...int) int {
tp := 0
if len(mode) > 0 {
tp = mode[0]
}
var num int var num int
for _, scene := range csp.scenes { for _, scene := range csp.scenes {
if scene.limitPlatform.IdStr == csp.platform { if tp > 0 {
if scene.IsSceneMode(tp) {
num++
}
} else {
num++ num++
} }
} }
if num < preCreateNum { return num
inc := preCreateNum - num
for i := 0; i < inc; i++ {
scene := csp.policy.NewPreCreateScene(csp)
if scene != nil {
csp.scenes[scene.sceneId] = scene
scene.csp = csp
}
}
}
} }
// ListRoom 房间列表 // ListRoom 房间列表
func (csp *CoinScenePool) ListRoom(p *Player) bool { //func (csp *CoinScenePool) ListRoom(p *Player) bool {
if p.scene != nil { // 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) // 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 // return false
} // }
//
csp.PreCreateRoom() // if len(csp.scenes) == 0 {
// return false
if len(csp.scenes) == 0 { // }
return false //
} // pack := &gamehallproto.SCCoinSceneListRoom{
// Id: csp.dbGameFree.Id,
pack := &gamehall_proto.SCCoinSceneListRoom{ // LimitCoin: csp.dbGameFree.LimitCoin,
Id: csp.dbGameFree.Id, // MaxCoinLimit: csp.dbGameFree.MaxCoinLimit,
LimitCoin: csp.dbGameFree.LimitCoin, // BaseScore: csp.dbGameFree.BaseScore,
MaxCoinLimit: csp.dbGameFree.MaxCoinLimit, // MaxScore: csp.dbGameFree.MaxChip,
BaseScore: csp.dbGameFree.BaseScore, // OtherIntParams: csp.dbGameFree.OtherIntParams,
MaxScore: csp.dbGameFree.MaxChip, // }
OtherIntParams: csp.dbGameFree.OtherIntParams, //
} // maxPlayerNum := 0
// for sceneId, s := range csp.scenes {
maxPlayerNum := 0 // data := &gamehallproto.CoinSceneInfo{
for sceneId, s := range csp.scenes { // SceneId: proto.Int(sceneId),
data := &gamehall_proto.CoinSceneInfo{ // PlayerNum: proto.Int(len(s.players)),
SceneId: proto.Int(sceneId), // }
PlayerNum: proto.Int(len(s.players)), // pack.Datas = append(pack.Datas, data)
} // maxPlayerNum = s.playerNum
pack.Datas = append(pack.Datas, data) // }
maxPlayerNum = s.playerNum // pack.MaxPlayerNum = proto.Int(maxPlayerNum)
} // proto.SetDefaults(pack)
pack.MaxPlayerNum = proto.Int(maxPlayerNum) // p.SendToClient(int(gamehallproto.CoinSceneGamePacketID_PACKET_SC_COINSCENE_LISTROOM), pack)
proto.SetDefaults(pack) // return true
p.SendToClient(int(gamehall_proto.CoinSceneGamePacketID_PACKET_SC_COINSCENE_LISTROOM), pack) //}
return true
}
// GetHasTruePlayerSceneCnt 有真人的房间数量 // GetHasTruePlayerSceneCnt 有真人的房间数量
func (csp *CoinScenePool) GetHasTruePlayerSceneCnt() int { func (csp *CoinScenePool) GetHasTruePlayerSceneCnt() int {

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 return gamehall.OpResultCode_OPRC_CoinNotEnough
} }
if pool.dbGameFree.GetMaxCoinLimit() != 0 && int64(pool.dbGameFree.GetMaxCoinLimit()) < p.Coin && !p.IsRob { 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 !common.Config.IsDevMode {
// 私人房
if s.IsPrivateScene() {
continue
}
// 禁止真人匹配 // 禁止真人匹配
if matchTrueManRule == MatchTrueManForbid && !p.IsRob && s.GetTruePlayerCnt() != 0 { if matchTrueManRule == MatchTrueManForbid && !p.IsRob && s.GetTruePlayerCnt() != 0 {
continue 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() gameId := pool.dbGameFree.GetGameId()
if p.WBLevel < 0 { //黑名单玩家 if p.WBLevel < 0 { //黑名单玩家
var cntWhite int var cntWhite int
@ -172,7 +176,6 @@ func (this *BaseCoinScenePool) PlayerEnter(pool *CoinScenePool, p *Player, exclu
if scene == nil && len(scenes) != 0 { if scene == nil && len(scenes) != 0 {
//1.其次游戏的配桌规则 //1.其次游戏的配桌规则
if scene == nil {
matchFunc := GetCoinSceneMatchFunc(int(gameId)) matchFunc := GetCoinSceneMatchFunc(int(gameId))
if matchFunc != nil { if matchFunc != nil {
scene = matchFunc(pool, p, scenes, sameIpLimit, exclude) scene = matchFunc(pool, p, scenes, sameIpLimit, exclude)
@ -181,14 +184,6 @@ func (this *BaseCoinScenePool) PlayerEnter(pool *CoinScenePool, p *Player, exclu
} }
} }
} }
// 随机
if scene == nil {
for _, v := range scenes {
scene = v
break
}
}
}
return gamehall.OpResultCode_OPRC_Sucess, scene return gamehall.OpResultCode_OPRC_Sucess, scene
} }
@ -219,37 +214,23 @@ func (this *BaseCoinScenePool) NewScene(pool *CoinScenePool, p *Player) *Scene {
gameId := int(pool.dbGameRule.GetGameId()) gameId := int(pool.dbGameRule.GetGameId())
gs := GameSessMgrSington.GetMinLoadSess(gameId) gs := GameSessMgrSington.GetMinLoadSess(gameId)
if gs == nil { 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 return nil
} }
gameMode := pool.dbGameRule.GetGameMode() gameMode := pool.dbGameRule.GetGameMode()
params := common.CopySliceInt32ToInt64(pool.dbGameRule.GetParams()) params := common.CopySliceInt32ToInt64(pool.dbGameRule.GetParams())
var platformName string
limitPlatform := PlatformMgrSingleton.GetPlatform(pool.platform) limitPlatform := PlatformMgrSingleton.GetPlatform(pool.platform)
if limitPlatform == nil || !limitPlatform.Isolated { if limitPlatform == nil || !limitPlatform.Isolated {
limitPlatform = PlatformMgrSingleton.GetPlatform(DefaultPlatform) limitPlatform = PlatformMgrSingleton.GetPlatform(DefaultPlatform)
platformName = DefaultPlatform
} else {
platformName = limitPlatform.IdStr
} }
sceneId := SceneMgrSingleton.GenOneCoinSceneId() sceneId := SceneMgrSingleton.GenOneCoinSceneId()
scene := SceneMgrSingleton.CreateScene(0, 0, sceneId, gameId, int(gameMode), int(common.SceneMode_Public), scene := SceneMgrSingleton.CreateScene(0, 0, sceneId, gameId, int(gameMode), common.SceneMode_Public,
1, -1, params, gs, limitPlatform, pool.groupId, pool.dbGameFree, int32(pool.id)) 1, -1, params, gs, limitPlatform, pool.groupId, pool.dbGameFree, 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 scene
} }
return nil
}
func (this *BaseCoinScenePool) NewPreCreateScene(pool *CoinScenePool) *Scene { func (this *BaseCoinScenePool) NewPreCreateScene(pool *CoinScenePool) *Scene {
return this.NewScene(pool, nil) return this.NewScene(pool, nil)

View File

@ -6,7 +6,7 @@ import (
var coinScenePools = map[int32]ICoinScenePool{} var coinScenePools = map[int32]ICoinScenePool{}
// RegisterCoinScenePool 注册游戏匹配规则 // RegisterCoinScenePool 注册房间池规则
func RegisterCoinScenePool(gameId int32, policy ICoinScenePool) { func RegisterCoinScenePool(gameId int32, policy ICoinScenePool) {
coinScenePools[gameId] = policy coinScenePools[gameId] = policy
} }
@ -15,21 +15,36 @@ func GetCoinScenePool(gameId int32) ICoinScenePool {
return coinScenePools[gameId] return coinScenePools[gameId]
} }
// ICoinScenePool 定义房间池规则的接口
// 公共处理逻辑可以写在 CoinScenePool不能满足需求时再实现 ICoinScenePool
type ICoinScenePool interface { type ICoinScenePool interface {
// New 创建房间池
New() interface{} New() interface{}
// CanEnter 玩家是否可以进入
CanEnter(pool *CoinScenePool, p *Player) gamehall.OpResultCode CanEnter(pool *CoinScenePool, p *Player) gamehall.OpResultCode
// CanAudienceEnter 观众是否可以进入
CanAudienceEnter(pool *CoinScenePool, p *Player) gamehall.OpResultCode CanAudienceEnter(pool *CoinScenePool, p *Player) gamehall.OpResultCode
PlayerEnter(pool *CoinScenePool, p *Player, exclude []int32, ischangeroom bool) (ret gamehall.OpResultCode, scene *Scene) // PlayerEnter 玩家进入(匹配房间)
AudienceEnter(pool *CoinScenePool, p *Player, exclude []int32, ischangeroom bool) (ret gamehall.OpResultCode, scene *Scene) // 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) OnPlayerEnter(pool *CoinScenePool, p *Player, scene *Scene)
// PlayerLeave 玩家离开
PlayerLeave(pool *CoinScenePool, p *Player, reason int) bool PlayerLeave(pool *CoinScenePool, p *Player, reason int) bool
// AudienceLeave 观众离开
AudienceLeave(pool *CoinScenePool, p *Player, reason int) bool AudienceLeave(pool *CoinScenePool, p *Player, reason int) bool
// OnPlayerLeave 玩家离开房间之后
OnPlayerLeave(pool *CoinScenePool, s *Scene, p *Player) OnPlayerLeave(pool *CoinScenePool, s *Scene, p *Player)
// NewScene 创建房间
NewScene(pool *CoinScenePool, p *Player) *Scene NewScene(pool *CoinScenePool, p *Player) *Scene
// NewPreCreateScene 创建预创建房间
NewPreCreateScene(pool *CoinScenePool) *Scene NewPreCreateScene(pool *CoinScenePool) *Scene
// OnDestroyScene 房间解散之后
OnDestroyScene(pool *CoinScenePool, sceneId int) OnDestroyScene(pool *CoinScenePool, sceneId int)
} }

View File

@ -8,7 +8,7 @@ import (
"mongo.games.com/game/common" "mongo.games.com/game/common"
"mongo.games.com/game/model" "mongo.games.com/game/model"
"mongo.games.com/game/protocol/gamehall" "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" "mongo.games.com/game/srvdata"
) )
@ -30,7 +30,7 @@ type CoinScenePoolLocal struct {
BaseCoinScenePool 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 sameIpLimit := !model.GameParamData.SameIpNoLimit
@ -42,12 +42,12 @@ func (this *CoinScenePoolLocal) PlayerEnter(pool *CoinScenePool, p *Player, excl
matchTrueManRule := pool.dbGameFree.GetMatchTrueMan() matchTrueManRule := pool.dbGameFree.GetMatchTrueMan()
//根据携带金额取进房间底注 DB_Createroom //根据携带金额取进房间底注 DB_Createroom
var dbCreateRoom *server_proto.DB_Createroom var dbCreateRoom *serverproto.DB_Createroom
gameId := pool.dbGameFree.GetGameId() gameId := pool.dbGameFree.GetGameId()
dbCreateRoom = srvdata.CreateRoomMgrSington.GetDataByGameIdWithTakeCoin(gameId, p.Coin) dbCreateRoom = srvdata.CreateRoomMgrSington.GetDataByGameIdWithTakeCoin(gameId, p.Coin)
if dbCreateRoom == nil { if dbCreateRoom == nil {
logger.Logger.Warnf("(csp *CoinScenePool) PlayerEnter(robot:%v, exclude:%v, ischangeroom:%v) no found scene from DB_Createroom", logger.Logger.Warnf("(csp *CoinScenePool) PlayerEnter(robot:%v, exclude:%v, isChangeRoom:%v) no found scene from DB_Createroom",
p.SnId, exclude, ischangeroom) p.SnId, exclude, isChangeRoom)
return gamehall.OpResultCode_OPRC_Error, nil return gamehall.OpResultCode_OPRC_Error, nil
} }
@ -58,6 +58,10 @@ func (this *CoinScenePoolLocal) PlayerEnter(pool *CoinScenePool, p *Player, excl
} }
if !common.Config.IsDevMode { if !common.Config.IsDevMode {
// 私人房
if s.IsPrivateScene() {
continue
}
// 禁止真人匹配 // 禁止真人匹配
if matchTrueManRule == MatchTrueManForbid && !p.IsRob && s.GetTruePlayerCnt() != 0 { if matchTrueManRule == MatchTrueManForbid && !p.IsRob && s.GetTruePlayerCnt() != 0 {
continue 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() betRange := dbCreateRoom.GetBetRange()
if common.InSliceInt32(betRange, s.BaseScore) { if common.InSliceInt32(betRange, s.BaseScore) {
scenes[sceneId] = s 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() gameId := pool.dbGameFree.GetGameId()
if p.WBLevel < 0 { //黑名单玩家 if p.WBLevel < 0 { //黑名单玩家
var cntWhite int var cntWhite int
@ -151,7 +155,7 @@ func (this *CoinScenePoolLocal) PlayerEnter(pool *CoinScenePool, p *Player, excl
} }
} else { //按类型匹配 } else { //按类型匹配
//优先真人 //优先真人
if scene == nil && len(scenes) != 0 && matchTrueManRule == MatchTrueManPriority { if len(scenes) != 0 && matchTrueManRule == MatchTrueManPriority {
var selScene []*Scene var selScene []*Scene
for _, value := range scenes { for _, value := range scenes {
if value != nil { if value != nil {
@ -170,7 +174,6 @@ func (this *CoinScenePoolLocal) PlayerEnter(pool *CoinScenePool, p *Player, excl
if scene == nil && len(scenes) != 0 { if scene == nil && len(scenes) != 0 {
//1.其次游戏的配桌规则 //1.其次游戏的配桌规则
if scene == nil {
matchFunc := GetCoinSceneMatchFunc(int(gameId)) matchFunc := GetCoinSceneMatchFunc(int(gameId))
if matchFunc != nil { if matchFunc != nil {
scene = matchFunc(pool, p, scenes, sameIpLimit, exclude) scene = matchFunc(pool, p, scenes, sameIpLimit, exclude)
@ -178,12 +181,11 @@ func (this *CoinScenePoolLocal) PlayerEnter(pool *CoinScenePool, p *Player, excl
} }
} }
} }
}
return gamehall.OpResultCode_OPRC_Sucess, scene 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()) gameId := int(pool.dbGameFree.GetGameId())
gs := GameSessMgrSington.GetMinLoadSess(gameId) gs := GameSessMgrSington.GetMinLoadSess(gameId)
if gs == nil { if gs == nil {
@ -194,20 +196,16 @@ func (this *CoinScenePoolLocal) NewScene(pool *CoinScenePool, p *Player) *Scene
sceneId := SceneMgrSingleton.GenOneCoinSceneId() sceneId := SceneMgrSingleton.GenOneCoinSceneId()
params := pool.dbGameRule.GetParams() params := pool.dbGameRule.GetParams()
var platformName string
limitPlatform := PlatformMgrSingleton.GetPlatform(pool.platform) limitPlatform := PlatformMgrSingleton.GetPlatform(pool.platform)
if limitPlatform == nil || !limitPlatform.Isolated { if limitPlatform == nil || !limitPlatform.Isolated {
limitPlatform = PlatformMgrSingleton.GetPlatform(DefaultPlatform) limitPlatform = PlatformMgrSingleton.GetPlatform(DefaultPlatform)
platformName = DefaultPlatform
} else {
platformName = limitPlatform.IdStr
} }
//根据携带金额取可创房间 DB_Createroom //根据携带金额取可创房间 DB_Createroom
baseScore := int32(0) baseScore := int32(0)
gameSite := 0 gameSite := 0
playerTakeCoin := p.Coin playerTakeCoin := p.Coin
var dbCreateRoom *server_proto.DB_Createroom var dbCreateRoom *serverproto.DB_Createroom
arrs := srvdata.PBDB_CreateroomMgr.Datas.Arr arrs := srvdata.PBDB_CreateroomMgr.Datas.Arr
for i := len(arrs) - 1; i >= 0; i-- { for i := len(arrs) - 1; i >= 0; i-- {
if arrs[i].GetGameId() == int32(gameId) { 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), 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) 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 scene
} }
return nil
}
func (this *CoinScenePoolLocal) NewPreCreateScene(pool *CoinScenePool) *Scene { func (l *CoinScenePoolLocal) NewPreCreateScene(pool *CoinScenePool) *Scene {
gameId := int(pool.dbGameRule.GetGameId()) gameId := int(pool.dbGameRule.GetGameId())
gs := GameSessMgrSington.GetMinLoadSess(gameId) gs := GameSessMgrSington.GetMinLoadSess(gameId)
if gs == nil { 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 return nil
} }
sceneId := SceneMgrSingleton.GenOneCoinSceneId() sceneId := SceneMgrSingleton.GenOneCoinSceneId()
params := pool.dbGameRule.GetParams() params := pool.dbGameRule.GetParams()
var platformName string
limitPlatform := PlatformMgrSingleton.GetPlatform(pool.platform) limitPlatform := PlatformMgrSingleton.GetPlatform(pool.platform)
if limitPlatform == nil || !limitPlatform.Isolated { if limitPlatform == nil || !limitPlatform.Isolated {
limitPlatform = PlatformMgrSingleton.GetPlatform(DefaultPlatform) limitPlatform = PlatformMgrSingleton.GetPlatform(DefaultPlatform)
platformName = DefaultPlatform
} else {
platformName = limitPlatform.IdStr
} }
var scene *Scene var scene *Scene
@ -274,7 +262,7 @@ func (this *CoinScenePoolLocal) NewPreCreateScene(pool *CoinScenePool) *Scene {
//根据SceneType随机可创房间 DB_Createroom //根据SceneType随机可创房间 DB_Createroom
baseScore := int32(0) baseScore := int32(0)
gameSite := 0 gameSite := 0
var dbCreateRooms []*server_proto.DB_Createroom var dbCreateRooms []*serverproto.DB_Createroom
arrs := srvdata.PBDB_CreateroomMgr.Datas.Arr arrs := srvdata.PBDB_CreateroomMgr.Datas.Arr
for i := len(arrs) - 1; i >= 0; i-- { for i := len(arrs) - 1; i >= 0; i-- {
if arrs[i].GetGameId() == int32(gameId) && arrs[i].GetGameSite() == pool.dbGameFree.GetSceneType() { 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 scene
} }
return nil
}

View File

@ -222,7 +222,6 @@ func (this *GameSession) AddScene(s *Scene) {
func (this *GameSession) DelScene(s *Scene) { func (this *GameSession) DelScene(s *Scene) {
delete(this.scenes, s.sceneId) delete(this.scenes, s.sceneId)
//from gameserver, so don't need send msg
} }
func (this *GameSession) AddPlayer(p *Player) { func (this *GameSession) AddPlayer(p *Player) {

View File

@ -18,7 +18,7 @@ package main
// scenesOfPlatform: make(map[string]map[int32]*Scene), // scenesOfPlatform: make(map[string]map[int32]*Scene),
// //玩家当前打开的小游戏列表 // //玩家当前打开的小游戏列表
// playerGaming: make(map[int32]map[int32]*Scene), // playerGaming: make(map[int32]map[int32]*Scene),
// autoId: common.MiniGameSceneStartId, // matchAutoId: common.MiniGameSceneStartId,
//} //}
// //
//type MiniGameMgr struct { //type MiniGameMgr struct {
@ -27,15 +27,15 @@ package main
// scenesOfPlatform map[string]map[int32]*Scene // scenesOfPlatform map[string]map[int32]*Scene
// //玩家当前打开的小游戏列表 // //玩家当前打开的小游戏列表
// playerGaming map[int32]map[int32]*Scene // playerGaming map[int32]map[int32]*Scene
// autoId int // matchAutoId int
//} //}
// //
//func (this *MiniGameMgr) GenOneSceneId() int { //func (this *MiniGameMgr) GenOneSceneId() int {
// this.autoId++ // this.matchAutoId++
// if this.autoId > common.MiniGameSceneMaxId { // if this.matchAutoId > common.MiniGameSceneMaxId {
// this.autoId = common.MiniGameSceneStartId // this.matchAutoId = common.MiniGameSceneStartId
// } // }
// return this.autoId // return this.matchAutoId
//} //}
// //
//func (this *MiniGameMgr) PlayerEnter(p *Player, id int32) mngame.MNGameOpResultCode { //func (this *MiniGameMgr) PlayerEnter(p *Player, id int32) mngame.MNGameOpResultCode {

View File

@ -179,7 +179,6 @@ func NewPlayer(sid int64, pd *model.PlayerData, s *netlib.Session) *Player {
func (this *Player) init() bool { func (this *Player) init() bool {
this.SetOnline() this.SetOnline()
this.isNewbie = this.CreateTime == this.LastLoginTime this.isNewbie = this.CreateTime == this.LastLoginTime
this.applyPos = -1
return true return true
} }
@ -2351,23 +2350,6 @@ func (this *Player) CreateLocalGameScene(sceneId, gameId, gameSite, sceneMode, p
return s, hall_proto.OpResultCode_Game_OPRC_Sucess_Game return s, hall_proto.OpResultCode_Game_OPRC_Sucess_Game
} }
func (this *Player) EnterScene(s *Scene, ischangeroom bool, pos int) bool {
if s == nil {
logger.Logger.Tracef("(this *Player) EnterScene, s == nil %v", this.SnId)
return false
}
if s != nil {
this.applyPos = -1
if s.PlayerEnter(this, pos, ischangeroom) {
FirePlayerEnterScene(this, s)
return true
}
}
return false
}
func (this *Player) ReturnScene(isLoaded bool) *Scene { func (this *Player) ReturnScene(isLoaded bool) *Scene {
logger.Logger.Tracef("(this *Player) ReturnScene %v", this.SnId) logger.Logger.Tracef("(this *Player) ReturnScene %v", this.SnId)
if this.scene == nil { if this.scene == nil {

View File

@ -553,6 +553,7 @@ func (this *Scene) PlayerEnter(p *Player, pos int, ischangeroom bool) bool {
this.SendToGame(int(serverproto.SSPacketID_PACKET_WG_PLAYERENTER), 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) logger.Logger.Tracef("SSPacketID_PACKET_WG_PLAYERENTER Scene:%v ;PlayerEnter(%v, %v)", this.sceneId, p.SnId, pos)
this.lastTime = time.Now() this.lastTime = time.Now()
FirePlayerEnterScene(p, this)
return true return true
} else { } else {
logger.Logger.Warnf("(this *Scene:%v) PlayerEnter(%v, %v) Marshal player data error %v", this.sceneId, p.SnId, pos, err) logger.Logger.Warnf("(this *Scene:%v) PlayerEnter(%v, %v) Marshal player data error %v", this.sceneId, p.SnId, pos, err)
@ -659,7 +660,6 @@ func (this *Scene) DelPlayer(p *Player) bool {
func (this *Scene) AudienceEnter(p *Player, ischangeroom bool) bool { func (this *Scene) AudienceEnter(p *Player, ischangeroom bool) bool {
logger.Logger.Infof("(this *Scene:%v) AudienceEnter(%v) ", this.sceneId, p.SnId) logger.Logger.Infof("(this *Scene:%v) AudienceEnter(%v) ", this.sceneId, p.SnId)
p.scene = this p.scene = this
p.applyPos = -1
this.audiences[p.SnId] = p this.audiences[p.SnId] = p
this.gameSess.AddPlayer(p) this.gameSess.AddPlayer(p)
if this.IsHundredScene() { if this.IsHundredScene() {
@ -744,7 +744,6 @@ func (this *Scene) DelAudience(p *Player) bool {
delete(this.gameCtx, p.SnId) delete(this.gameCtx, p.SnId)
} }
p.scene = nil p.scene = nil
p.applyPos = -1
SceneMgrSingleton.OnPlayerLeaveScene(this, p) SceneMgrSingleton.OnPlayerLeaveScene(this, p)
if this.IsHundredScene() { if this.IsHundredScene() {
HundredSceneMgrSington.OnPlayerLeave(p) HundredSceneMgrSington.OnPlayerLeave(p)
@ -953,23 +952,6 @@ func (this *Scene) ForceDelete(isManual bool) {
proto.SetDefaults(pack) proto.SetDefaults(pack)
this.SendToGame(int(serverproto.SSPacketID_PACKET_WG_DESTROYSCENE), pack) this.SendToGame(int(serverproto.SSPacketID_PACKET_WG_DESTROYSCENE), pack)
logger.Logger.Warnf("(this *Scene) ForceDelete() sceneid=%v", this.sceneId) 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() { func (this *Scene) Shutdown() {
@ -1008,6 +990,10 @@ 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 || this.sceneMode == common.SceneMode_Private
} }
func (this *Scene) IsSceneMode(mode int) bool {
return this.sceneMode == mode
}
func (this *Scene) IsRankMatch() bool { func (this *Scene) IsRankMatch() bool {
if this.dbGameFree == nil { if this.dbGameFree == nil {
return false return false

View File

@ -10,7 +10,6 @@ import (
"mongo.games.com/game/model" "mongo.games.com/game/model"
serverproto "mongo.games.com/game/protocol/server" serverproto "mongo.games.com/game/protocol/server"
webapi2 "mongo.games.com/game/protocol/webapi" webapi2 "mongo.games.com/game/protocol/webapi"
"mongo.games.com/game/srvdata"
"mongo.games.com/game/webapi" "mongo.games.com/game/webapi"
) )
@ -20,7 +19,8 @@ func init() {
var SceneMgrSingleton = &SceneMgr{ var SceneMgrSingleton = &SceneMgr{
scenes: make(map[int]*Scene), scenes: make(map[int]*Scene),
autoId: common.MatchSceneStartId, privateAutoId: common.PrivateSceneStartId,
matchAutoId: common.MatchSceneStartId,
coinSceneAutoId: common.CoinSceneStartId, coinSceneAutoId: common.CoinSceneStartId,
hundredSceneAutoId: common.HundredSceneStartId, hundredSceneAutoId: common.HundredSceneStartId,
} }
@ -29,8 +29,9 @@ var SceneMgrSingleton = &SceneMgr{
type SceneMgr struct { type SceneMgr struct {
BaseClockSinker // 驱动时间事件 BaseClockSinker // 驱动时间事件
scenes map[int]*Scene // sceneid:Scene scenes map[int]*Scene // 房间id: Scene
autoId int // 比赛场房间号 privateAutoId int // 私人房房间号
matchAutoId int // 比赛场房间号
coinSceneAutoId int // 金币场房间号 coinSceneAutoId int // 金币场房间号
hundredSceneAutoId int // 百人场房间号 hundredSceneAutoId int // 百人场房间号
} }
@ -41,6 +42,15 @@ func (m *SceneMgr) AllocReplayCode() string {
return code 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 // GenOneCoinSceneId 生产一个金币场房间id
func (m *SceneMgr) GenOneCoinSceneId() int { func (m *SceneMgr) GenOneCoinSceneId() int {
m.coinSceneAutoId++ m.coinSceneAutoId++
@ -61,11 +71,11 @@ func (m *SceneMgr) GenOneHundredSceneId() int {
// GenOneMatchSceneId 生产一个比赛场房间id // GenOneMatchSceneId 生产一个比赛场房间id
func (m *SceneMgr) GenOneMatchSceneId() int { func (m *SceneMgr) GenOneMatchSceneId() int {
m.autoId++ m.matchAutoId++
if m.autoId > common.MatchSceneMaxId { if m.matchAutoId > common.MatchSceneMaxId {
m.autoId = common.MatchSceneStartId m.matchAutoId = common.MatchSceneStartId
} }
return m.autoId return m.matchAutoId
} }
// GetScene 获取房间对象 // GetScene 获取房间对象
@ -81,9 +91,12 @@ func (m *SceneMgr) GetScenesByGame(gameId int) []*Scene {
var scenes []*Scene var scenes []*Scene
for _, value := range m.scenes { for _, value := range m.scenes {
if value.gameId == gameId { if value.gameId == gameId {
s := m.GetScene(value.sceneId)
if s != nil {
scenes = append(scenes, value) scenes = append(scenes, value)
} }
} }
}
return scenes return scenes
} }
@ -92,9 +105,12 @@ func (m *SceneMgr) GetScenesByGameFreeId(gameFreeId int32) []*Scene {
var scenes []*Scene var scenes []*Scene
for _, value := range m.scenes { for _, value := range m.scenes {
if value.dbGameFree.GetId() == gameFreeId { if value.dbGameFree.GetId() == gameFreeId {
s := m.GetScene(value.sceneId)
if s != nil {
scenes = append(scenes, value) scenes = append(scenes, value)
} }
} }
}
return scenes return scenes
} }
@ -336,29 +352,29 @@ func (m *SceneMgr) OnPlayerLeaveScene(s *Scene, p *Player) {
} }
// GetThirdScene 获取三方游戏房间 // GetThirdScene 获取三方游戏房间
func (m *SceneMgr) GetThirdScene(i webapi.IThirdPlatform) *Scene { //func (m *SceneMgr) GetThirdScene(i webapi.IThirdPlatform) *Scene {
if i == nil { // if i == nil {
return nil // return nil
} // }
sceneId := i.GetPlatformBase().SceneId // sceneId := i.GetPlatformBase().SceneId
scene := m.scenes[sceneId] // scene := m.scenes[sceneId]
if scene != nil { // if scene != nil {
return scene // return scene
} // }
//
gs := GameSessMgrSington.GetMinLoadSess(i.GetPlatformBase().BaseGameID) // gs := GameSessMgrSington.GetMinLoadSess(i.GetPlatformBase().BaseGameID)
if gs != nil { // if gs != nil {
limitPlatform := PlatformMgrSingleton.GetPlatform(DefaultPlatform) // limitPlatform := PlatformMgrSingleton.GetPlatform(DefaultPlatform)
var gameMode = common.SceneMode_Thr // var gameMode = common.SceneMode_Thr
dbGameFree := srvdata.PBDB_GameFreeMgr.GetData(i.GetPlatformBase().VultGameID) // dbGameFree := srvdata.PBDB_GameFreeMgr.GetData(i.GetPlatformBase().VultGameID)
scene := SceneMgrSingleton.CreateScene(0, 0, sceneId, i.GetPlatformBase().BaseGameID, gameMode, int(common.SceneMode_Thr), 1, -1, // scene := SceneMgrSingleton.CreateScene(0, 0, sceneId, i.GetPlatformBase().BaseGameID, gameMode, int(common.SceneMode_Thr), 1, -1,
[]int64{}, gs, limitPlatform, 0, dbGameFree, i.GetPlatformBase().VultGameID) // []int64{}, gs, limitPlatform, 0, dbGameFree, i.GetPlatformBase().VultGameID)
return scene // return scene
} else { // } else {
logger.Logger.Errorf("Get %v game min session failed.", i.GetPlatformBase().BaseGameID) // logger.Logger.Errorf("Get %v game min session failed.", i.GetPlatformBase().BaseGameID)
return nil // return nil
} // }
} //}
//=========================ClockSinker=============================== //=========================ClockSinker===============================
@ -373,12 +389,19 @@ func (m *SceneMgr) OnMiniTimer() {
if webapi.ThridPlatformMgrSington.FindPlatformByPlatformBaseGameId(s.gameId) != nil { if webapi.ThridPlatformMgrSington.FindPlatformByPlatformBaseGameId(s.gameId) != nil {
continue continue
} }
if s.IsCoinScene() { switch {
if s.IsLongTimeInactive() && s.dbGameFree.GetCreateRoomNum() == 0 { //预创建的房间,暂不过期销毁,判定依据:CreateRoomNum>0 case s.IsCoinScene():
if s.IsLongTimeInactive() {
if s.dbGameFree.GetCreateRoomNum() == 0 {
logger.Logger.Warnf("SceneMgr.DeleteLongTimeInactive CoinScene ForceDelete scene:%v IsLongTimeInactive", s.sceneId) logger.Logger.Warnf("SceneMgr.DeleteLongTimeInactive CoinScene ForceDelete scene:%v IsLongTimeInactive", s.sceneId)
s.ForceDelete(false) s.ForceDelete(false)
} }
} else if s.IsPrivateScene() { 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)
}
}
case s.IsPrivateScene():
if s.IsLongTimeInactive() { if s.IsLongTimeInactive() {
logger.Logger.Warnf("SceneMgr.DeleteLongTimeInactive PrivateScene ForceDelete scene:%v IsLongTimeInactive", s.sceneId) logger.Logger.Warnf("SceneMgr.DeleteLongTimeInactive PrivateScene ForceDelete scene:%v IsLongTimeInactive", s.sceneId)
s.ForceDelete(false) s.ForceDelete(false)