Compare commits

..

No commits in common. "0f7da88dabedab45b0595b32bf0afc3baf0ae55f" and "e5b80fda166b5c078d4b59171c171caaa5744cc7" have entirely different histories.

14 changed files with 1181 additions and 708 deletions

View File

@ -23,7 +23,6 @@
"ClosePreCreateRoom": true, "ClosePreCreateRoom": true,
"AgoraAddress": "http://47.105.78.29:8081", "AgoraAddress": "http://47.105.78.29:8081",
"InviteUrl": "http://47.105.78.29:8000/", "InviteUrl": "http://47.105.78.29:8000/",
"GuideTs": 1723790567,
"RankTimeout": 2, "RankTimeout": 2,
"PermitInitScore": 0 "PermitInitScore": 0
} }

View File

@ -574,11 +574,9 @@ func (this *CSEnterGameHandler) ProcessLocal(s *netlib.Session, packetid int, da
if len(params) != 0 { if len(params) != 0 {
roomId = params[0] roomId = params[0]
platformName := SceneMgrSingleton.GetPlatformBySceneId(int(roomId)) platformName := CoinSceneMgrSingleton.GetPlatformBySceneId(int(roomId))
if p.IsRob { if p.IsRob {
if platformName != "" {
p.Platform = platformName p.Platform = platformName
}
} else if p.GMLevel > 0 && p.Platform == platformName { //允许GM直接按房间ID进场 } else if p.GMLevel > 0 && p.Platform == platformName { //允许GM直接按房间ID进场
roomId = params[0] roomId = params[0]
} }
@ -674,12 +672,13 @@ func (this *CSEnterGameHandler) ProcessNormal(s *netlib.Session, packetid int, d
case common.IsHundredType(gameType): case common.IsHundredType(gameType):
if len(params) != 0 { if len(params) != 0 {
roomId = params[0] roomId = params[0]
platform := SceneMgrSingleton.GetPlatformBySceneId(int(roomId)) name, ok := HundredSceneMgrSington.GetPlatformNameBySceneId(roomId)
if p.IsRob { if p.IsRob {
if platform != "" { //机器人先伪装成对应平台的用户
p.Platform = platform if ok {
p.Platform = name
} }
} else if p.GMLevel > 0 && p.Platform == platform { //允许GM直接按房间ID进场 } else if p.GMLevel > 0 && p.Platform == name { //允许GM直接按房间ID进场
roomId = params[0] roomId = params[0]
} }
} }
@ -692,7 +691,7 @@ func (this *CSEnterGameHandler) ProcessNormal(s *netlib.Session, packetid int, d
} }
} }
} }
ret = gamehall.OpResultCode_Game(HundredSceneMgrSingleton.PlayerEnter(p, msg.GetId())) ret = gamehall.OpResultCode_Game(HundredSceneMgrSington.PlayerEnter(p, msg.GetId()))
if p.scene != nil { if p.scene != nil {
pack.OpParams = append(pack.OpParams, msg.GetId()) pack.OpParams = append(pack.OpParams, msg.GetId())
if ret != gamehall.OpResultCode_Game_OPRC_Sucess_Game { if ret != gamehall.OpResultCode_Game_OPRC_Sucess_Game {
@ -704,11 +703,9 @@ func (this *CSEnterGameHandler) ProcessNormal(s *netlib.Session, packetid int, d
case common.IsCoinSceneType(gameType): case common.IsCoinSceneType(gameType):
if len(params) != 0 { if len(params) != 0 {
roomId = params[0] roomId = params[0]
platformName := SceneMgrSingleton.GetPlatformBySceneId(int(roomId)) platformName := CoinSceneMgrSingleton.GetPlatformBySceneId(int(roomId))
if p.IsRob { if p.IsRob {
if platformName != "" {
p.Platform = platformName p.Platform = platformName
}
} else if p.GMLevel > 0 && p.Platform == platformName { //允许GM直接按房间ID进场 } else if p.GMLevel > 0 && p.Platform == platformName { //允许GM直接按房间ID进场
roomId = params[0] roomId = params[0]
} }
@ -766,10 +763,7 @@ func (this *CSQuitGameHandler) Process(s *netlib.Session, packetid int, data int
dbGameFree := srvdata.PBDB_GameFreeMgr.GetData(msg.GetId()) dbGameFree := srvdata.PBDB_GameFreeMgr.GetData(msg.GetId())
gameType := dbGameFree.GetGameType() gameType := dbGameFree.GetGameType()
if common.IsHundredType(gameType) { if common.IsHundredType(gameType) {
ret = gamehall.OpResultCode_Game(HundredSceneMgrSingleton.PlayerTryLeave(p)) ret = gamehall.OpResultCode_Game(HundredSceneMgrSington.PlayerTryLeave(p))
if gamehall.OpResultCode_Game_OPRC_OpYield_Game == ret {
return nil
}
} else if common.IsCoinSceneType(gameType) { } else if common.IsCoinSceneType(gameType) {
ret = gamehall.OpResultCode_Game(CoinSceneMgrSingleton.PlayerTryLeave(p, msg.IsAudience)) ret = gamehall.OpResultCode_Game(CoinSceneMgrSingleton.PlayerTryLeave(p, msg.IsAudience))
if gamehall.OpResultCode_Game_OPRC_OpYield_Game == ret { if gamehall.OpResultCode_Game_OPRC_OpYield_Game == ret {
@ -951,7 +945,7 @@ func (this *CSCreateRoomHandler) ProcessLocalGame(s *netlib.Session, packetid in
goto failed goto failed
} }
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, 0) params, dbGameFree, baseScore, csp.groupId)
if scene != nil && code == gamehall.OpResultCode_Game_OPRC_Sucess_Game { if scene != nil && 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)
csp.AddScene(scene) csp.AddScene(scene)
@ -1055,7 +1049,7 @@ func (this *CSCreateRoomHandler) ProcessThirteen(s *netlib.Session, packetid int
goto failed goto failed
} }
scene, code = p.CreateLocalGameScene(roomId, int(gameId), int(dbGameFree.GetSceneType()), int(msg.GetSceneMode()), scene, code = p.CreateLocalGameScene(roomId, int(gameId), int(dbGameFree.GetSceneType()), int(msg.GetSceneMode()),
maxPlayerNum, params, dbGameFree, baseScore, 0) maxPlayerNum, params, dbGameFree, baseScore, csp.groupId)
if scene != nil { if scene != nil {
if 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)

View File

@ -2,15 +2,13 @@ package main
import ( import (
"fmt" "fmt"
"time"
"mongo.games.com/goserver/core/logger"
"mongo.games.com/goserver/core/netlib"
"mongo.games.com/game/common" "mongo.games.com/game/common"
"mongo.games.com/game/proto" "mongo.games.com/game/proto"
"mongo.games.com/game/protocol/gamehall" "mongo.games.com/game/protocol/gamehall"
"mongo.games.com/game/srvdata" "mongo.games.com/game/srvdata"
"mongo.games.com/goserver/core/logger"
"mongo.games.com/goserver/core/netlib"
"time"
) )
type CSHundredSceneGetPlayerNumPacketFactory struct { type CSHundredSceneGetPlayerNumPacketFactory struct {
@ -28,7 +26,7 @@ func (this *CSHundredSceneGetPlayerNumHandler) Process(s *netlib.Session, packet
if msg, ok := data.(*gamehall.CSHundredSceneGetPlayerNum); ok { if msg, ok := data.(*gamehall.CSHundredSceneGetPlayerNum); ok {
p := PlayerMgrSington.GetPlayer(sid) p := PlayerMgrSington.GetPlayer(sid)
if p != nil { if p != nil {
nums := HundredSceneMgrSingleton.GetPlayerNums(p, msg.GetGameId(), msg.GetGameModel()) nums := HundredSceneMgrSington.GetPlayerNums(p, msg.GetGameId(), msg.GetGameModel())
pack := &gamehall.SCHundredSceneGetPlayerNum{ pack := &gamehall.SCHundredSceneGetPlayerNum{
Nums: nums, Nums: nums,
} }
@ -63,7 +61,7 @@ func (this *CSHundredSceneOpHandler) Process(s *netlib.Session, packetid int, da
} }
oldPlatform := p.Platform oldPlatform := p.Platform
switch msg.GetOpType() { switch msg.GetOpType() {
case HundredSceneOPEnter: case HundredSceneOp_Enter:
//pt := PlatformMgrSingleton.GetPackageTag(p.PackageID) //pt := PlatformMgrSingleton.GetPackageTag(p.PackageID)
//if pt != nil && pt.IsForceBind == 1 { //if pt != nil && pt.IsForceBind == 1 {
// if p.BeUnderAgentCode == "" || p.BeUnderAgentCode == "0" { // if p.BeUnderAgentCode == "" || p.BeUnderAgentCode == "0" {
@ -82,13 +80,13 @@ func (this *CSHundredSceneOpHandler) Process(s *netlib.Session, packetid int, da
params := msg.GetOpParams() params := msg.GetOpParams()
if len(params) != 0 { if len(params) != 0 {
roomId = params[0] roomId = params[0]
platform := SceneMgrSingleton.GetPlatformBySceneId(int(roomId)) name, ok := HundredSceneMgrSington.GetPlatformNameBySceneId(roomId)
if p.IsRob { if p.IsRob {
//机器人先伪装成对应平台的用户 //机器人先伪装成对应平台的用户
if platform != "" { if ok {
p.Platform = platform p.Platform = name
} }
} else if p.GMLevel > 0 && p.Platform == platform { //允许GM直接按房间ID进场 } else if p.GMLevel > 0 && p.Platform == name { //允许GM直接按房间ID进场
roomId = params[0] roomId = params[0]
} }
} }
@ -155,7 +153,7 @@ func (this *CSHundredSceneOpHandler) Process(s *netlib.Session, packetid int, da
} }
} }
ret = HundredSceneMgrSingleton.PlayerEnter(p, msg.GetId()) ret = HundredSceneMgrSington.PlayerEnter(p, msg.GetId())
if p.scene != nil { if p.scene != nil {
pack.OpParams = append(pack.OpParams, msg.GetId()) pack.OpParams = append(pack.OpParams, msg.GetId())
//TODO 有房间还进入失败尝试returnroom //TODO 有房间还进入失败尝试returnroom
@ -164,9 +162,9 @@ func (this *CSHundredSceneOpHandler) Process(s *netlib.Session, packetid int, da
return nil return nil
} }
} }
case HundredSceneOPLeave: case HundredSceneOp_Leave:
ret = HundredSceneMgrSingleton.PlayerTryLeave(p) ret = HundredSceneMgrSington.PlayerTryLeave(p)
case HundredSceneOPChange: case HundredSceneOp_Change:
/*var exclude int32 /*var exclude int32
if p.scene != nil { if p.scene != nil {
exclude = int32(p.scene.sceneId) exclude = int32(p.scene.sceneId)
@ -175,10 +173,10 @@ func (this *CSHundredSceneOpHandler) Process(s *netlib.Session, packetid int, da
if len(params) != 0 { if len(params) != 0 {
exclude = params[0] exclude = params[0]
} }
if HundredSceneMgrSingleton.PlayerInChanging(p) { //换桌中 if HundredSceneMgrSington.PlayerInChanging(p) { //换桌中
return nil return nil
} }
ret = HundredSceneMgrSingleton.PlayerTryChange(p, msg.GetId(), exclude)*/ ret = HundredSceneMgrSington.PlayerTryChange(p, msg.GetId(), exclude)*/
} }
done: done:
//机器人要避免身上的平台标记被污染 //机器人要避免身上的平台标记被污染
@ -220,7 +218,7 @@ func (this *CSGameObserveHandler) Process(s *netlib.Session, packetid int, data
gameStateMgr.PlayerRegiste(p, msg.GetGameId(), msg.GetStartOrEnd()) gameStateMgr.PlayerRegiste(p, msg.GetGameId(), msg.GetStartOrEnd())
pack := &gamehall.SCGameSubList{} pack := &gamehall.SCGameSubList{}
statePack := &gamehall.SCGameState{} statePack := &gamehall.SCGameState{}
scenes := HundredSceneMgrSingleton.GetPlatformScene(p.Platform, msg.GetGameId()) scenes := HundredSceneMgrSington.GetPlatformScene(p.Platform, msg.GetGameId())
for _, value := range scenes { for _, value := range scenes {
pack.List = append(pack.List, &gamehall.GameSubRecord{ pack.List = append(pack.List, &gamehall.GameSubRecord{
GameFreeId: proto.Int32(value.dbGameFree.GetId()), GameFreeId: proto.Int32(value.dbGameFree.GetId()),
@ -271,7 +269,7 @@ func (this *CSGameObserveHandler) Process(s *netlib.Session, packetid int, data
// // gameid == common.GameId_Avengers || gameid == common.GameId_EasterIsland { // // gameid == common.GameId_Avengers || gameid == common.GameId_EasterIsland {
// // gameStateMgr.PlayerRegiste(p, msg.GetGameId(), true) // // gameStateMgr.PlayerRegiste(p, msg.GetGameId(), true)
// // pack := &gamehall.SCHundredSceneGetGameJackpot{} // // pack := &gamehall.SCHundredSceneGetGameJackpot{}
// // scenes := HundredSceneMgrSingleton.GetPlatformScene(p.Platform, msg.GetGameId()) // // scenes := HundredSceneMgrSington.GetPlatformScene(p.Platform, msg.GetGameId())
// // for _, v := range scenes { // // for _, v := range scenes {
// // jpfi := &gamehall.GameJackpotFundInfo{ // // jpfi := &gamehall.GameJackpotFundInfo{
// // GameFreeId: proto.Int32(v.dbGameFree.GetId()), // // GameFreeId: proto.Int32(v.dbGameFree.GetId()),

View File

@ -13,32 +13,32 @@ 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/proto" "mongo.games.com/game/proto"
gamehallproto "mongo.games.com/game/protocol/gamehall" gamehall_proto "mongo.games.com/game/protocol/gamehall"
loginproto "mongo.games.com/game/protocol/login" login_proto "mongo.games.com/game/protocol/login"
playerproto "mongo.games.com/game/protocol/player" player_proto "mongo.games.com/game/protocol/player"
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"
) )
func init() { func init() {
// 销毁房间 // 销毁房间
netlib.RegisterFactory(int(serverproto.SSPacketID_PACKET_GW_DESTROYSCENE), netlib.PacketFactoryWrapper(func() interface{} { netlib.RegisterFactory(int(server_proto.SSPacketID_PACKET_GW_DESTROYSCENE), netlib.PacketFactoryWrapper(func() interface{} {
return &serverproto.GWDestroyScene{} return &server_proto.GWDestroyScene{}
})) }))
netlib.RegisterHandler(int(serverproto.SSPacketID_PACKET_GW_DESTROYSCENE), netlib.HandlerWrapper(func(s *netlib.Session, packetid int, pack interface{}) error { netlib.RegisterHandler(int(server_proto.SSPacketID_PACKET_GW_DESTROYSCENE), netlib.HandlerWrapper(func(s *netlib.Session, packetid int, pack interface{}) error {
logger.Logger.Trace("receive GWDestroyScene:", pack) logger.Logger.Trace("receive GWDestroyScene:", pack)
if msg, ok := pack.(*serverproto.GWDestroyScene); ok { if msg, ok := pack.(*server_proto.GWDestroyScene); ok {
SceneMgrSingleton.DestroyScene(int(msg.GetSceneId()), msg.GetIsCompleted()) SceneMgrSingleton.DestroyScene(int(msg.GetSceneId()), msg.GetIsCompleted())
} }
return nil return nil
})) }))
// 离开房间 // 离开房间
netlib.RegisterFactory(int(serverproto.SSPacketID_PACKET_GW_PLAYERLEAVE), netlib.PacketFactoryWrapper(func() interface{} { netlib.RegisterFactory(int(server_proto.SSPacketID_PACKET_GW_PLAYERLEAVE), netlib.PacketFactoryWrapper(func() interface{} {
return &serverproto.GWPlayerLeave{} return &server_proto.GWPlayerLeave{}
})) }))
netlib.RegisterHandler(int(serverproto.SSPacketID_PACKET_GW_PLAYERLEAVE), netlib.HandlerWrapper(func(s *netlib.Session, packetid int, pack interface{}) error { netlib.RegisterHandler(int(server_proto.SSPacketID_PACKET_GW_PLAYERLEAVE), netlib.HandlerWrapper(func(s *netlib.Session, packetid int, pack interface{}) error {
if msg, ok := pack.(*serverproto.GWPlayerLeave); ok { if msg, ok := pack.(*server_proto.GWPlayerLeave); ok {
logger.Logger.Trace("receive GWPlayerLeave:", msg.GetPlayerId()) logger.Logger.Trace("receive GWPlayerLeave:", msg.GetPlayerId())
scene := SceneMgrSingleton.GetScene(int(msg.GetRoomId())) scene := SceneMgrSingleton.GetScene(int(msg.GetRoomId()))
if scene != nil { if scene != nil {
@ -68,7 +68,7 @@ func init() {
} }
} }
case scene.IsHundredScene(): case scene.IsHundredScene():
if !HundredSceneMgrSingleton.PlayerLeave(p, int(msg.GetReason())) { if !HundredSceneMgrSington.PlayerLeave(p, int(msg.GetReason())) {
logger.Logger.Warnf("GWPlayerLeave snid:%v sceneid:%v gameid:%v modeid:%v [hundredcene]", logger.Logger.Warnf("GWPlayerLeave snid:%v sceneid:%v gameid:%v modeid:%v [hundredcene]",
p.SnId, scene.sceneId, scene.gameId, scene.gameMode) p.SnId, scene.sceneId, scene.gameId, scene.gameMode)
} }
@ -228,12 +228,12 @@ func init() {
})) }))
// 观众离开房间 // 观众离开房间
netlib.RegisterFactory(int(serverproto.SSPacketID_PACKET_GW_AUDIENCELEAVE), netlib.PacketFactoryWrapper(func() interface{} { netlib.RegisterFactory(int(server_proto.SSPacketID_PACKET_GW_AUDIENCELEAVE), netlib.PacketFactoryWrapper(func() interface{} {
return &serverproto.GWPlayerLeave{} return &server_proto.GWPlayerLeave{}
})) }))
netlib.RegisterHandler(int(serverproto.SSPacketID_PACKET_GW_AUDIENCELEAVE), netlib.HandlerWrapper(func(s *netlib.Session, packetid int, pack interface{}) error { netlib.RegisterHandler(int(server_proto.SSPacketID_PACKET_GW_AUDIENCELEAVE), netlib.HandlerWrapper(func(s *netlib.Session, packetid int, pack interface{}) error {
logger.Logger.Trace("receive PACKET_GW_AUDIENCELEAVE GWPlayerLeave:", pack) logger.Logger.Trace("receive PACKET_GW_AUDIENCELEAVE GWPlayerLeave:", pack)
if msg, ok := pack.(*serverproto.GWPlayerLeave); ok { if msg, ok := pack.(*server_proto.GWPlayerLeave); ok {
scene := SceneMgrSingleton.GetScene(int(msg.GetRoomId())) scene := SceneMgrSingleton.GetScene(int(msg.GetRoomId()))
if scene != nil { if scene != nil {
p := PlayerMgrSington.GetPlayerBySnId(msg.GetPlayerId()) p := PlayerMgrSington.GetPlayerBySnId(msg.GetPlayerId())
@ -270,12 +270,12 @@ func init() {
})) }))
// 房间游戏开始 // 房间游戏开始
netlib.RegisterFactory(int(serverproto.SSPacketID_PACKET_GW_SCENESTART), netlib.PacketFactoryWrapper(func() interface{} { netlib.RegisterFactory(int(server_proto.SSPacketID_PACKET_GW_SCENESTART), netlib.PacketFactoryWrapper(func() interface{} {
return &serverproto.GWSceneStart{} return &server_proto.GWSceneStart{}
})) }))
netlib.RegisterHandler(int(serverproto.SSPacketID_PACKET_GW_SCENESTART), netlib.HandlerWrapper(func(s *netlib.Session, packetid int, pack interface{}) error { netlib.RegisterHandler(int(server_proto.SSPacketID_PACKET_GW_SCENESTART), netlib.HandlerWrapper(func(s *netlib.Session, packetid int, pack interface{}) error {
logger.Logger.Trace("receive SSPacketID_PACKET_GW_SCENESTART GWSceneStart:", pack) logger.Logger.Trace("receive SSPacketID_PACKET_GW_SCENESTART GWSceneStart:", pack)
if msg, ok := pack.(*serverproto.GWSceneStart); ok { if msg, ok := pack.(*server_proto.GWSceneStart); ok {
scene := SceneMgrSingleton.GetScene(int(msg.GetRoomId())) scene := SceneMgrSingleton.GetScene(int(msg.GetRoomId()))
if scene != nil { if scene != nil {
scene.starting = msg.GetStart() scene.starting = msg.GetStart()
@ -299,12 +299,12 @@ func init() {
// 房间游戏状态 // 房间游戏状态
// 捕鱼 // 捕鱼
netlib.RegisterFactory(int(serverproto.SSPacketID_PACKET_GW_SCENESTATE), netlib.PacketFactoryWrapper(func() interface{} { netlib.RegisterFactory(int(server_proto.SSPacketID_PACKET_GW_SCENESTATE), netlib.PacketFactoryWrapper(func() interface{} {
return &serverproto.GWSceneState{} return &server_proto.GWSceneState{}
})) }))
netlib.RegisterHandler(int(serverproto.SSPacketID_PACKET_GW_SCENESTATE), netlib.HandlerWrapper(func(s *netlib.Session, packetid int, pack interface{}) error { netlib.RegisterHandler(int(server_proto.SSPacketID_PACKET_GW_SCENESTATE), netlib.HandlerWrapper(func(s *netlib.Session, packetid int, pack interface{}) error {
logger.Logger.Trace("receive SSPacketID_PACKET_GW_SCENESTATE GWSceneState:", pack) logger.Logger.Trace("receive SSPacketID_PACKET_GW_SCENESTATE GWSceneState:", pack)
if msg, ok := pack.(*serverproto.GWSceneState); ok { if msg, ok := pack.(*server_proto.GWSceneState); ok {
scene := SceneMgrSingleton.GetScene(int(msg.GetRoomId())) scene := SceneMgrSingleton.GetScene(int(msg.GetRoomId()))
if scene != nil { if scene != nil {
scene.state = msg.GetCurrState() scene.state = msg.GetCurrState()
@ -315,12 +315,12 @@ func init() {
})) }))
// 用户状态同步 flag // 用户状态同步 flag
netlib.RegisterFactory(int(serverproto.SSPacketID_PACKET_GW_PLAYERSTATE), netlib.PacketFactoryWrapper(func() interface{} { netlib.RegisterFactory(int(server_proto.SSPacketID_PACKET_GW_PLAYERSTATE), netlib.PacketFactoryWrapper(func() interface{} {
return &serverproto.GWPlayerFlag{} return &server_proto.GWPlayerFlag{}
})) }))
netlib.RegisterHandler(int(serverproto.SSPacketID_PACKET_GW_PLAYERSTATE), netlib.HandlerWrapper(func(s *netlib.Session, packetid int, pack interface{}) error { netlib.RegisterHandler(int(server_proto.SSPacketID_PACKET_GW_PLAYERSTATE), netlib.HandlerWrapper(func(s *netlib.Session, packetid int, pack interface{}) error {
logger.Logger.Trace("receive GWPlayerFlag:", pack) logger.Logger.Trace("receive GWPlayerFlag:", pack)
if msg, ok := pack.(*serverproto.GWPlayerFlag); ok { if msg, ok := pack.(*server_proto.GWPlayerFlag); ok {
player := PlayerMgrSington.GetPlayerBySnId(msg.GetSnId()) player := PlayerMgrSington.GetPlayerBySnId(msg.GetSnId())
if player != nil { if player != nil {
player.flag = msg.GetFlag() player.flag = msg.GetFlag()
@ -330,12 +330,12 @@ func init() {
})) }))
// 房间服务器状态切换 // 房间服务器状态切换
netlib.RegisterFactory(int(serverproto.SSPacketID_PACKET_GB_STATE_SWITCH), netlib.PacketFactoryWrapper(func() interface{} { netlib.RegisterFactory(int(server_proto.SSPacketID_PACKET_GB_STATE_SWITCH), netlib.PacketFactoryWrapper(func() interface{} {
return &serverproto.ServerStateSwitch{} return &server_proto.ServerStateSwitch{}
})) }))
netlib.RegisterHandler(int(serverproto.SSPacketID_PACKET_GB_STATE_SWITCH), netlib.HandlerWrapper(func(s *netlib.Session, packetid int, pack interface{}) error { netlib.RegisterHandler(int(server_proto.SSPacketID_PACKET_GB_STATE_SWITCH), netlib.HandlerWrapper(func(s *netlib.Session, packetid int, pack interface{}) error {
logger.Logger.Trace("receive SSPacketID_PACKET_GB_STATE_SWITCH ServerStateSwitch:", pack) logger.Logger.Trace("receive SSPacketID_PACKET_GB_STATE_SWITCH ServerStateSwitch:", pack)
if sr, ok := pack.(*serverproto.ServerStateSwitch); ok { if sr, ok := pack.(*server_proto.ServerStateSwitch); ok {
srvid := int(sr.GetSrvId()) srvid := int(sr.GetSrvId())
gameSess := GameSessMgrSington.GetGameSess(srvid) gameSess := GameSessMgrSington.GetGameSess(srvid)
if gameSess != nil { if gameSess != nil {
@ -360,13 +360,13 @@ func init() {
// 游戏服务器的系统广播 // 游戏服务器的系统广播
// 捕鱼 // 捕鱼
netlib.RegisterFactory(int(serverproto.SSPacketID_PACKET_GW_NEWNOTICE), netlib.PacketFactoryWrapper(func() interface{} { netlib.RegisterFactory(int(server_proto.SSPacketID_PACKET_GW_NEWNOTICE), netlib.PacketFactoryWrapper(func() interface{} {
return &serverproto.GWNewNotice{} return &server_proto.GWNewNotice{}
})) }))
netlib.RegisterHandler(int(serverproto.SSPacketID_PACKET_GW_NEWNOTICE), netlib.HandlerWrapper(func(s *netlib.Session, netlib.RegisterHandler(int(server_proto.SSPacketID_PACKET_GW_NEWNOTICE), netlib.HandlerWrapper(func(s *netlib.Session,
packetid int, pack interface{}) error { packetid int, pack interface{}) error {
logger.Logger.Trace("receive GWNewNotice:", pack) logger.Logger.Trace("receive GWNewNotice:", pack)
if msg, ok := pack.(*serverproto.GWNewNotice); ok { if msg, ok := pack.(*server_proto.GWNewNotice); ok {
//立即发送改为定期发送,控制下广播包的频度 //立即发送改为定期发送,控制下广播包的频度
HorseRaceLampMgrSington.PushGameHorseRaceLamp(msg.GetCh(), msg.GetPlatform(), msg.GetContent(), int32(msg.GetMsgtype()), msg.GetIsrob(), msg.GetPriority()) HorseRaceLampMgrSington.PushGameHorseRaceLamp(msg.GetCh(), msg.GetPlatform(), msg.GetContent(), int32(msg.GetMsgtype()), msg.GetIsrob(), msg.GetPriority())
} }
@ -374,13 +374,13 @@ func init() {
})) }))
// 同步每局游戏那些玩家一起玩的 // 同步每局游戏那些玩家一起玩的
netlib.RegisterFactory(int(serverproto.SSPacketID_PACKET_GW_SCENEPLAYERLOG), netlib.PacketFactoryWrapper(func() interface{} { netlib.RegisterFactory(int(server_proto.SSPacketID_PACKET_GW_SCENEPLAYERLOG), netlib.PacketFactoryWrapper(func() interface{} {
return &serverproto.GWScenePlayerLog{} return &server_proto.GWScenePlayerLog{}
})) }))
netlib.RegisterHandler(int(serverproto.SSPacketID_PACKET_GW_SCENEPLAYERLOG), netlib.HandlerWrapper(func(s *netlib.Session, netlib.RegisterHandler(int(server_proto.SSPacketID_PACKET_GW_SCENEPLAYERLOG), netlib.HandlerWrapper(func(s *netlib.Session,
packetid int, pack interface{}) error { packetid int, pack interface{}) error {
logger.Logger.Trace("receive GWScenePlayerLog:", pack) logger.Logger.Trace("receive GWScenePlayerLog:", pack)
if msg, ok := pack.(*serverproto.GWScenePlayerLog); ok { if msg, ok := pack.(*server_proto.GWScenePlayerLog); ok {
sceneLimitMgr.ReceiveData(msg.GetGameId(), msg.GetSnids()) sceneLimitMgr.ReceiveData(msg.GetGameId(), msg.GetSnids())
} }
return nil return nil
@ -388,11 +388,11 @@ func init() {
// 强制离开房间 // 强制离开房间
// 返回房间失败 // 返回房间失败
netlib.RegisterFactory(int(serverproto.SSPacketID_PACKET_GW_PLAYERFORCELEAVE), netlib.PacketFactoryWrapper(func() interface{} { netlib.RegisterFactory(int(server_proto.SSPacketID_PACKET_GW_PLAYERFORCELEAVE), netlib.PacketFactoryWrapper(func() interface{} {
return &serverproto.GWPlayerForceLeave{} return &server_proto.GWPlayerForceLeave{}
})) }))
netlib.RegisterHandler(int(serverproto.SSPacketID_PACKET_GW_PLAYERFORCELEAVE), netlib.HandlerWrapper(func(s *netlib.Session, packetid int, pack interface{}) error { netlib.RegisterHandler(int(server_proto.SSPacketID_PACKET_GW_PLAYERFORCELEAVE), netlib.HandlerWrapper(func(s *netlib.Session, packetid int, pack interface{}) error {
if msg, ok := pack.(*serverproto.GWPlayerForceLeave); ok { if msg, ok := pack.(*server_proto.GWPlayerForceLeave); ok {
logger.Logger.Warn("receive GWPlayerForceLeave:", msg) logger.Logger.Warn("receive GWPlayerForceLeave:", msg)
scene := SceneMgrSingleton.GetScene(int(msg.GetRoomId())) scene := SceneMgrSingleton.GetScene(int(msg.GetRoomId()))
if scene != nil { if scene != nil {
@ -406,7 +406,7 @@ func init() {
logger.Logger.Warnf("GWPlayerForceLeave snid:%v sceneid:%v gameid:%v modeid:%v [coinscene]", p.SnId, scene.sceneId, scene.gameId, scene.gameMode) logger.Logger.Warnf("GWPlayerForceLeave snid:%v sceneid:%v gameid:%v modeid:%v [coinscene]", p.SnId, scene.sceneId, scene.gameId, scene.gameMode)
} }
case scene.IsHundredScene(): case scene.IsHundredScene():
if !HundredSceneMgrSingleton.PlayerLeave(p, int(msg.GetReason())) { if !HundredSceneMgrSington.PlayerLeave(p, int(msg.GetReason())) {
logger.Logger.Warnf("GWPlayerForceLeave snid:%v sceneid:%v gameid:%v modeid:%v [hundredcene]", p.SnId, scene.sceneId, scene.gameId, scene.gameMode) logger.Logger.Warnf("GWPlayerForceLeave snid:%v sceneid:%v gameid:%v modeid:%v [hundredcene]", p.SnId, scene.sceneId, scene.gameId, scene.gameMode)
} }
case scene.IsMatchScene(): case scene.IsMatchScene():
@ -438,12 +438,12 @@ func init() {
//1.同步玩家游戏场内的实时金币 //1.同步玩家游戏场内的实时金币
//2.触发相关任务:统计有效下注金币数,赢取金币数,牌局次数等 //2.触发相关任务:统计有效下注金币数,赢取金币数,牌局次数等
//3.黑名单处理 //3.黑名单处理
netlib.RegisterFactory(int(serverproto.SSPacketID_PACKET_GW_PLAYERDATA), netlib.PacketFactoryWrapper(func() interface{} { netlib.RegisterFactory(int(server_proto.SSPacketID_PACKET_GW_PLAYERDATA), netlib.PacketFactoryWrapper(func() interface{} {
return &serverproto.GWPlayerData{} return &server_proto.GWPlayerData{}
})) }))
netlib.RegisterHandler(int(serverproto.SSPacketID_PACKET_GW_PLAYERDATA), netlib.HandlerWrapper(func(s *netlib.Session, packetid int, pack interface{}) error { netlib.RegisterHandler(int(server_proto.SSPacketID_PACKET_GW_PLAYERDATA), netlib.HandlerWrapper(func(s *netlib.Session, packetid int, pack interface{}) error {
logger.Logger.Trace("receive GWPlayerBet:", pack) logger.Logger.Trace("receive GWPlayerBet:", pack)
if msg, ok := pack.(*serverproto.GWPlayerData); ok { if msg, ok := pack.(*server_proto.GWPlayerData); ok {
scene := SceneMgrSingleton.GetScene(int(msg.GetSceneId())) scene := SceneMgrSingleton.GetScene(int(msg.GetSceneId()))
if scene == nil { if scene == nil {
return nil return nil
@ -573,13 +573,13 @@ func init() {
})) }))
//推送游戏的状态 //推送游戏的状态
netlib.RegisterFactory(int(serverproto.SSPacketID_PACKET_GW_GAMESTATE), netlib.PacketFactoryWrapper(func() interface{} { netlib.RegisterFactory(int(server_proto.SSPacketID_PACKET_GW_GAMESTATE), netlib.PacketFactoryWrapper(func() interface{} {
return &serverproto.GWGameState{} return &server_proto.GWGameState{}
})) }))
netlib.RegisterHandler(int(serverproto.SSPacketID_PACKET_GW_GAMESTATE), netlib.HandlerWrapper(func(s *netlib.Session, netlib.RegisterHandler(int(server_proto.SSPacketID_PACKET_GW_GAMESTATE), netlib.HandlerWrapper(func(s *netlib.Session,
packetid int, pack interface{}) error { packetid int, pack interface{}) error {
logger.Logger.Trace("receive SSPacketID_PACKET_GW_GAMESTATE GWGameState:", pack) logger.Logger.Trace("receive SSPacketID_PACKET_GW_GAMESTATE GWGameState:", pack)
if msg, ok := pack.(*serverproto.GWGameState); ok { if msg, ok := pack.(*server_proto.GWGameState); ok {
scene := SceneMgrSingleton.GetScene(int(msg.GetSceneId())) scene := SceneMgrSingleton.GetScene(int(msg.GetSceneId()))
if scene != nil { if scene != nil {
scene.State = msg.GetState() scene.State = msg.GetState()
@ -591,38 +591,38 @@ func init() {
if leftTime < 0 { if leftTime < 0 {
leftTime = 0 leftTime = 0
} }
pack := &gamehallproto.SCGameState{} pack := &gamehall_proto.SCGameState{}
pack.List = append(pack.List, &gamehallproto.GameState{ pack.List = append(pack.List, &gamehall_proto.GameState{
GameFreeId: proto.Int32(scene.dbGameFree.GetId()), GameFreeId: proto.Int32(scene.dbGameFree.GetId()),
Ts: proto.Int64(leftTime), Ts: proto.Int64(leftTime),
Sec: proto.Int32(scene.StateSec), Sec: proto.Int32(scene.StateSec),
}) })
gameStateMgr.BrodcastGameState(int32(scene.gameId), scene.limitPlatform.IdStr, gameStateMgr.BrodcastGameState(int32(scene.gameId), scene.limitPlatform.IdStr,
int(gamehallproto.GameHallPacketID_PACKET_SC_GAMESTATE), pack) int(gamehall_proto.GameHallPacketID_PACKET_SC_GAMESTATE), pack)
} }
} }
} }
return nil return nil
})) }))
netlib.RegisterFactory(int(serverproto.SSPacketID_PACKET_GW_JACKPOTLIST), netlib.PacketFactoryWrapper(func() interface{} { netlib.RegisterFactory(int(server_proto.SSPacketID_PACKET_GW_JACKPOTLIST), netlib.PacketFactoryWrapper(func() interface{} {
return &serverproto.GWGameJackList{} return &server_proto.GWGameJackList{}
})) }))
netlib.RegisterHandler(int(serverproto.SSPacketID_PACKET_GW_JACKPOTLIST), netlib.HandlerWrapper(func(s *netlib.Session, packetid int, pack interface{}) error { netlib.RegisterHandler(int(server_proto.SSPacketID_PACKET_GW_JACKPOTLIST), netlib.HandlerWrapper(func(s *netlib.Session, packetid int, pack interface{}) error {
logger.Logger.Trace("receive SSPacketID_PACKET_GW_JACKPOTLIST GWGameJackList:", pack) logger.Logger.Trace("receive SSPacketID_PACKET_GW_JACKPOTLIST GWGameJackList:", pack)
if msg, ok := pack.(*serverproto.GWGameJackList); ok { if msg, ok := pack.(*server_proto.GWGameJackList); ok {
FishJackListMgr.Insert(msg.GetCoin(), msg.GetSnId(), msg.GetRoomId(), msg.GetJackType(), msg.GetGameId(), FishJackListMgr.Insert(msg.GetCoin(), msg.GetSnId(), msg.GetRoomId(), msg.GetJackType(), msg.GetGameId(),
msg.GetPlatform(), msg.GetChannel(), msg.GetName()) msg.GetPlatform(), msg.GetChannel(), msg.GetName())
} }
return nil return nil
})) }))
netlib.RegisterFactory(int(serverproto.SSPacketID_PACKET_GW_JACKPOTCOIN), netlib.PacketFactoryWrapper(func() interface{} { netlib.RegisterFactory(int(server_proto.SSPacketID_PACKET_GW_JACKPOTCOIN), netlib.PacketFactoryWrapper(func() interface{} {
return &serverproto.GWGameJackCoin{} return &server_proto.GWGameJackCoin{}
})) }))
netlib.RegisterHandler(int(serverproto.SSPacketID_PACKET_GW_JACKPOTCOIN), netlib.HandlerWrapper(func(s *netlib.Session, packetid int, pack interface{}) error { netlib.RegisterHandler(int(server_proto.SSPacketID_PACKET_GW_JACKPOTCOIN), netlib.HandlerWrapper(func(s *netlib.Session, packetid int, pack interface{}) error {
logger.Logger.Trace("receive SSPacketID_PACKET_GW_JACKPOTCOIN GWGameJackCoin:", pack) logger.Logger.Trace("receive SSPacketID_PACKET_GW_JACKPOTCOIN GWGameJackCoin:", pack)
if msg, ok := pack.(*serverproto.GWGameJackCoin); ok { if msg, ok := pack.(*server_proto.GWGameJackCoin); ok {
for i, pl := range msg.Platform { for i, pl := range msg.Platform {
FishJackpotCoinMgr.Jackpot[pl] = msg.Coin[i] FishJackpotCoinMgr.Jackpot[pl] = msg.Coin[i]
} }
@ -631,12 +631,12 @@ func init() {
})) }))
//强制换桌 //强制换桌
netlib.RegisterFactory(int(serverproto.SSPacketID_PACKET_GW_CHANGESCENEEVENT), netlib.PacketFactoryWrapper(func() interface{} { netlib.RegisterFactory(int(server_proto.SSPacketID_PACKET_GW_CHANGESCENEEVENT), netlib.PacketFactoryWrapper(func() interface{} {
return &serverproto.GWChangeSceneEvent{} return &server_proto.GWChangeSceneEvent{}
})) }))
netlib.RegisterHandler(int(serverproto.SSPacketID_PACKET_GW_CHANGESCENEEVENT), netlib.HandlerWrapper(func(s *netlib.Session, packetid int, pack interface{}) error { netlib.RegisterHandler(int(server_proto.SSPacketID_PACKET_GW_CHANGESCENEEVENT), netlib.HandlerWrapper(func(s *netlib.Session, packetid int, pack interface{}) error {
logger.Logger.Trace("receive SSPacketID_PACKET_GW_CHANGESCENEEVENT GWChangeSceneEvent:", pack) logger.Logger.Trace("receive SSPacketID_PACKET_GW_CHANGESCENEEVENT GWChangeSceneEvent:", pack)
if msg, ok := pack.(*serverproto.GWChangeSceneEvent); ok { if msg, ok := pack.(*server_proto.GWChangeSceneEvent); ok {
scene := SceneMgrSingleton.GetScene(int(msg.GetSceneId())) scene := SceneMgrSingleton.GetScene(int(msg.GetSceneId()))
if scene != nil { if scene != nil {
scene.PlayerTryChange() scene.PlayerTryChange()
@ -646,13 +646,13 @@ func init() {
})) }))
//玩家中转消息 //玩家中转消息
netlib.RegisterFactory(int(serverproto.SSPacketID_PACKET_SS_REDIRECTTOPLAYER), netlib.PacketFactoryWrapper(func() interface{} { netlib.RegisterFactory(int(server_proto.SSPacketID_PACKET_SS_REDIRECTTOPLAYER), netlib.PacketFactoryWrapper(func() interface{} {
return &serverproto.SSRedirectToPlayer{} return &server_proto.SSRedirectToPlayer{}
})) }))
netlib.RegisterHandler(int(serverproto.SSPacketID_PACKET_SS_REDIRECTTOPLAYER), netlib.HandlerWrapper(func(s *netlib.Session, netlib.RegisterHandler(int(server_proto.SSPacketID_PACKET_SS_REDIRECTTOPLAYER), netlib.HandlerWrapper(func(s *netlib.Session,
packetid int, pack interface{}) error { packetid int, pack interface{}) error {
logger.Logger.Trace("SSRedirectToPlayer Process recv ", pack) logger.Logger.Trace("SSRedirectToPlayer Process recv ", pack)
if msg, ok := pack.(*serverproto.SSRedirectToPlayer); ok { if msg, ok := pack.(*server_proto.SSRedirectToPlayer); ok {
p := PlayerMgrSington.GetPlayerBySnId(msg.GetSnId()) p := PlayerMgrSington.GetPlayerBySnId(msg.GetSnId())
if p == nil { if p == nil {
return nil return nil
@ -670,13 +670,13 @@ type CSPMCmdHandler struct {
} }
func (this *CSPMCmdPacketFactory) CreatePacket() interface{} { func (this *CSPMCmdPacketFactory) CreatePacket() interface{} {
pack := &playerproto.CSPMCmd{} pack := &player_proto.CSPMCmd{}
return pack return pack
} }
func (this *CSPMCmdHandler) Process(s *netlib.Session, packetid int, data interface{}, sid int64) error { func (this *CSPMCmdHandler) Process(s *netlib.Session, packetid int, data interface{}, sid int64) error {
logger.Logger.Trace("CSPMCmdHandler Process recv ", data) logger.Logger.Trace("CSPMCmdHandler Process recv ", data)
if msg, ok := data.(*playerproto.CSPMCmd); ok { if msg, ok := data.(*player_proto.CSPMCmd); ok {
p := PlayerMgrSington.GetPlayer(sid) p := PlayerMgrSington.GetPlayer(sid)
if p == nil { if p == nil {
logger.Logger.Trace("CSPMCmdHandler p == nil") logger.Logger.Trace("CSPMCmdHandler p == nil")
@ -729,13 +729,13 @@ type CSRobotChgDataHandler struct {
} }
func (this *CSRobotChgDataPacketFactory) CreatePacket() interface{} { func (this *CSRobotChgDataPacketFactory) CreatePacket() interface{} {
pack := &playerproto.CSRobotChgData{} pack := &player_proto.CSRobotChgData{}
return pack return pack
} }
func (this *CSRobotChgDataHandler) Process(s *netlib.Session, packetid int, data interface{}, sid int64) error { func (this *CSRobotChgDataHandler) Process(s *netlib.Session, packetid int, data interface{}, sid int64) error {
logger.Logger.Trace("CSRobotChgDataHandler Process recv ", data) logger.Logger.Trace("CSRobotChgDataHandler Process recv ", data)
if _, ok := data.(*playerproto.CSRobotChgData); ok { if _, ok := data.(*player_proto.CSRobotChgData); ok {
p := PlayerMgrSington.GetPlayer(sid) p := PlayerMgrSington.GetPlayer(sid)
if p == nil { if p == nil {
logger.Logger.Trace("CSRobotChgDataHandler p == nil") logger.Logger.Trace("CSRobotChgDataHandler p == nil")
@ -756,13 +756,13 @@ type CSAccountInvalidHandler struct {
} }
func (this *CSAccountInvalidPacketFactory) CreatePacket() interface{} { func (this *CSAccountInvalidPacketFactory) CreatePacket() interface{} {
pack := &loginproto.CSAccountInvalid{} pack := &login_proto.CSAccountInvalid{}
return pack return pack
} }
func (this *CSAccountInvalidHandler) Process(s *netlib.Session, packetid int, data interface{}, sid int64) error { func (this *CSAccountInvalidHandler) Process(s *netlib.Session, packetid int, data interface{}, sid int64) error {
logger.Logger.Trace("CSAccountInvalidHandler Process recv ", data) logger.Logger.Trace("CSAccountInvalidHandler Process recv ", data)
if _, ok := data.(*loginproto.CSAccountInvalid); ok { if _, ok := data.(*login_proto.CSAccountInvalid); ok {
p := PlayerMgrSington.GetPlayer(sid) p := PlayerMgrSington.GetPlayer(sid)
if p != nil && p.IsRobot() { if p != nil && p.IsRobot() {
snid := p.SnId snid := p.SnId
@ -789,12 +789,12 @@ func (this *CSAccountInvalidHandler) Process(s *netlib.Session, packetid int, da
} }
func init() { func init() {
common.RegisterHandler(int(playerproto.PlayerPacketID_PACKET_CS_PMCMD), &CSPMCmdHandler{}) common.RegisterHandler(int(player_proto.PlayerPacketID_PACKET_CS_PMCMD), &CSPMCmdHandler{})
netlib.RegisterFactory(int(playerproto.PlayerPacketID_PACKET_CS_PMCMD), &CSPMCmdPacketFactory{}) netlib.RegisterFactory(int(player_proto.PlayerPacketID_PACKET_CS_PMCMD), &CSPMCmdPacketFactory{})
common.RegisterHandler(int(playerproto.PlayerPacketID_PACKET_CS_ROBOTCHGDATA), &CSRobotChgDataHandler{}) common.RegisterHandler(int(player_proto.PlayerPacketID_PACKET_CS_ROBOTCHGDATA), &CSRobotChgDataHandler{})
netlib.RegisterFactory(int(playerproto.PlayerPacketID_PACKET_CS_ROBOTCHGDATA), &CSRobotChgDataPacketFactory{}) netlib.RegisterFactory(int(player_proto.PlayerPacketID_PACKET_CS_ROBOTCHGDATA), &CSRobotChgDataPacketFactory{})
common.RegisterHandler(int(loginproto.LoginPacketID_PACKET_CS_ACCOUNTINVALID), &CSAccountInvalidHandler{}) common.RegisterHandler(int(login_proto.LoginPacketID_PACKET_CS_ACCOUNTINVALID), &CSAccountInvalidHandler{})
netlib.RegisterFactory(int(loginproto.LoginPacketID_PACKET_CS_ACCOUNTINVALID), &CSAccountInvalidPacketFactory{}) netlib.RegisterFactory(int(login_proto.LoginPacketID_PACKET_CS_ACCOUNTINVALID), &CSAccountInvalidPacketFactory{})
} }

View File

@ -1,7 +1,6 @@
package main package main
import ( import (
"games.yol.com/win88/model"
"math/rand" "math/rand"
"time" "time"
@ -12,7 +11,7 @@ import (
"mongo.games.com/game/common" "mongo.games.com/game/common"
"mongo.games.com/game/proto" "mongo.games.com/game/proto"
hallproto "mongo.games.com/game/protocol/gamehall" hall_proto "mongo.games.com/game/protocol/gamehall"
"mongo.games.com/game/protocol/server" "mongo.games.com/game/protocol/server"
"mongo.games.com/game/protocol/webapi" "mongo.games.com/game/protocol/webapi"
"mongo.games.com/game/srvdata" "mongo.games.com/game/srvdata"
@ -20,7 +19,12 @@ import (
var CoinSceneMgrSingleton = &CoinSceneMgr{ 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[int]string),
//按组管理
scenesOfGroup: make(map[int32]map[int32]*CoinScenePool),
groupOfScene: make(map[int]int32),
} }
type CreateRoomCache struct { type CreateRoomCache struct {
@ -29,8 +33,16 @@ type CreateRoomCache struct {
} }
type CoinSceneMgr struct { type CoinSceneMgr struct {
scenesOfPlatform map[string]map[int32]*CoinScenePool // 场次房间池 platform:gamefreeid playerChanging map[int32]int32 // snid:gamefreeid 换桌中的玩家
playerChanging map[int32]int32 // 换桌中的玩家 snid:gamefreeid
//按平台管理
scenesOfPlatform map[string]map[int32]*CoinScenePool // platform:gamefreeid
platformOfScene map[int]string // sceneid:platform; 创建房间后记录房间所在平台
//按组管理
scenesOfGroup map[int32]map[int32]*CoinScenePool // groupid:gamefreeid
groupOfScene map[int]int32 // sceneid:groupid;
//延迟创建房间列表 //延迟创建房间列表
delayCache []*CreateRoomCache // 待预创建房间 delayCache []*CreateRoomCache // 待预创建房间
} }
@ -38,126 +50,216 @@ type CoinSceneMgr struct {
// GetCoinScenePool 获取一个场景池 // GetCoinScenePool 获取一个场景池
// plt 平台id // plt 平台id
// id 场次id // id 场次id
func (m *CoinSceneMgr) GetCoinScenePool(plt string, id int32) *CoinScenePool { func (csm *CoinSceneMgr) GetCoinScenePool(plt string, id int32) *CoinScenePool {
gf := PlatformMgrSingleton.GetGameFree(plt, id) gf := PlatformMgrSingleton.GetGameFree(plt, id)
if gf == nil || gf.DbGameFree == nil { if gf == nil {
return nil return nil
} }
groupId := gf.GetGroupId()
if ss, ok := m.scenesOfPlatform[plt]; ok { if groupId != 0 {
if _, ok := csm.scenesOfGroup[groupId]; ok {
if csp, ok := csm.scenesOfGroup[groupId][id]; ok {
return csp
}
}
} else {
if ss, ok := csm.scenesOfPlatform[plt]; ok {
if csp, ok := ss[id]; ok && csp != nil { if csp, ok := ss[id]; ok && csp != nil {
return csp return csp
} }
} }
}
if gf.GetDbGameFree() == nil {
return nil
}
// 创建了一个新的 // 创建了一个新的
// 模块启动时所有场次都创建了房间池 // 应该是走不到这里,因为模块启动时所有场次都创建了房间池
pool := newCoinScenePool(plt, gf.GetDbGameFree()) pool := newCoinScenePool(plt, groupId, gf.GetDbGameFree())
v, ok := m.scenesOfPlatform[plt] if groupId != 0 {
v, ok := csm.scenesOfGroup[groupId]
if !ok || v == nil { if !ok || v == nil {
m.scenesOfPlatform[plt] = make(map[int32]*CoinScenePool) 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
} }
m.scenesOfPlatform[plt][id] = pool
return pool return pool
} }
func (m *CoinSceneMgr) findCoinScenePool(platform string, id int32) (pools map[int32]*CoinScenePool, dbGameFree *server.DB_GameFree) { func (csm *CoinSceneMgr) findCoinScenePool(platform string, id int32) (pools map[int32]*CoinScenePool, groupID int32,
dbGameFree *server.DB_GameFree) {
gf := PlatformMgrSingleton.GetGameFree(platform, id) gf := PlatformMgrSingleton.GetGameFree(platform, id)
if gf == nil || gf.GetDbGameFree() == nil { if gf == nil || gf.GetDbGameFree() == nil {
return nil, nil return nil, 0, nil
}
groupId := gf.GetGroupId()
var ss map[int32]*CoinScenePool
var ok bool
if groupId != 0 {
ss, ok = csm.scenesOfGroup[groupId]
if !ok {
ss = make(map[int32]*CoinScenePool)
csm.scenesOfGroup[groupId] = ss
}
return ss, groupId, gf.GetDbGameFree()
} }
ss, ok := m.scenesOfPlatform[platform] ss, ok = csm.scenesOfPlatform[platform]
if !ok || ss == nil { if !ok {
ss = make(map[int32]*CoinScenePool) ss = make(map[int32]*CoinScenePool)
m.scenesOfPlatform[platform] = ss csm.scenesOfPlatform[platform] = ss
} }
return ss, gf.GetDbGameFree() return ss, 0, gf.GetDbGameFree()
} }
// PlayerEnter 玩家进入房间池 // PlayerEnter 玩家进入房间池
func (m *CoinSceneMgr) PlayerEnter(p *Player, id int32, roomId int32, exclude []int32, isChangeRoom bool) hallproto.OpResultCode { func (csm *CoinSceneMgr) PlayerEnter(p *Player, id int32, roomId int32, exclude []int32, isChangeRoom bool) hall_proto.OpResultCode {
logger.Logger.Tracef("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 hallproto.OpResultCode_OPRC_RoomHadClosed return hall_proto.OpResultCode_OPRC_RoomHadClosed
}
// 玩家已经在房间里了
if m.InCoinScene(p) {
logger.Logger.Warnf("CoinSceneMgr PlayerEnter snid:%v find in gamefreeid:%v roomId:%v", p.SnId, p.scene.dbGameFree.Id, p.scene.sceneId)
return hallproto.OpResultCode_OPRC_Error
} }
//多平台支持 //多平台支持
platform := p.GetPlatform() platform := p.GetPlatform()
if platform == nil { if platform == nil {
return hallproto.OpResultCode_OPRC_RoomHadClosed return hall_proto.OpResultCode_OPRC_RoomHadClosed
} }
csp := m.GetCoinScenePool(platform.IdStr, id)
ret := csp.playerEnter(p, roomId, exclude, isChangeRoom) // 玩家已经在房间里了
logger.Logger.Tracef("CoinSceneMgr PlayerEnter snid:%v id:%v ret:%v", p.SnId, id, ret) if p.scene != nil {
logger.Logger.Warnf("(csm *CoinSceneMgr) PlayerEnter snid:%v find in gameId:%v gamefreeid:%v", p.SnId, p.scene.gameId, id)
return hall_proto.OpResultCode_OPRC_Error
}
csp := csm.GetCoinScenePool(platform.IdStr, id)
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 return ret
} }
// AudienceEnter 观众进入房间 // AudienceEnter 观众进入房间
func (m *CoinSceneMgr) AudienceEnter(p *Player, id int32, roomId int32, exclude []int32, ischangeroom bool) hallproto.OpResultCode { // id 场次id
logger.Logger.Tracef("CoinSceneMgr AudienceEnter snid:%v id:%v roomid:%v exclude:%v", p.SnId, id, roomId, exclude) func (csm *CoinSceneMgr) AudienceEnter(p *Player, id int32, roomId int32, exclude []int32, ischangeroom bool) hall_proto.OpResultCode {
if p.isDelete { //删档用户不让进游戏
return hallproto.OpResultCode_OPRC_RoomHadClosed
}
if m.InCoinScene(p) {
logger.Logger.Warnf("CoinSceneMgr AudienceEnter snid:%v find in gamefreeid:%v roomId:%v", p.SnId, p.scene.dbGameFree.Id, p.scene.sceneId)
return hallproto.OpResultCode_OPRC_Error
}
//多平台支持 //多平台支持
platform := p.GetPlatform() platform := p.GetPlatform()
if platform == nil { if platform == nil {
return hallproto.OpResultCode_OPRC_RoomHadClosed return hall_proto.OpResultCode_OPRC_RoomHadClosed
} }
pools, _ := m.findCoinScenePool(platform.IdStr, id) pools, _, _ := csm.findCoinScenePool(platform.IdStr, id)
if pools == nil { if pools == nil {
return hallproto.OpResultCode_OPRC_RoomHadClosed return hall_proto.OpResultCode_OPRC_RoomHadClosed
} }
if len(pools) == 0 { if len(pools) == 0 {
return hallproto.OpResultCode_OPRC_NoFindDownTiceRoom return hall_proto.OpResultCode_OPRC_NoFindDownTiceRoom
} }
csp, ok := pools[id] if csp, ok := pools[id]; ok && csp != nil {
if !ok || csp == nil { ret := csp.AudienceEnter(p, roomId, exclude, ischangeroom)
return hallproto.OpResultCode_OPRC_RoomHadClosed logger.Logger.Warnf("(csm *CoinSceneMgr) AudienceEnter snid:%v find in id:%v exclude:%v return false", p.SnId, id, exclude)
}
ret := csp.audienceEnter(p, roomId, exclude, ischangeroom)
logger.Logger.Tracef("CoinSceneMgr AudienceEnter snid:%v id:%v ret:%v", p.SnId, id, ret)
return ret return ret
} }
logger.Logger.Warnf("(csm *CoinSceneMgr) AudienceEnter snid:%v find in id:%v exclude:%v csp.AudienceEnter return false", p.SnId, id, exclude)
return hall_proto.OpResultCode_OPRC_Error
}
func (csm *CoinSceneMgr) playerLeave(p *Player, reason int) bool {
if p == nil || p.scene == nil {
return true
}
s := p.scene
if s.groupId != 0 {
if ss, ok := csm.scenesOfGroup[s.groupId]; ok && ss != nil {
if csp, ok := ss[s.dbGameFree.GetId()]; ok && csp != nil {
if !csp.PlayerLeave(p, reason) {
csp.AudienceLeave(p, reason)
}
}
return true
}
}
// 玩家身上平台
if platform := p.GetPlatform(); platform != nil {
if ss, ok := csm.scenesOfPlatform[platform.IdStr]; ok && ss != nil {
if csp, ok := ss[s.dbGameFree.GetId()]; ok && csp != nil {
if !csp.PlayerLeave(p, reason) {
csp.AudienceLeave(p, reason)
}
}
return true
}
}
// 房间所在平台
if s.limitPlatform != nil {
if ss, ok := csm.scenesOfPlatform[s.limitPlatform.IdStr]; ok && ss != nil {
if csp, ok := ss[s.dbGameFree.GetId()]; ok && csp != nil {
if !csp.PlayerLeave(p, reason) {
csp.AudienceLeave(p, reason)
}
}
return true
}
}
return true
}
// PlayerLeave 玩家离开 // PlayerLeave 玩家离开
// 游戏服玩家离开房间消息触发 func (csm *CoinSceneMgr) PlayerLeave(p *Player, reason int) bool {
func (m *CoinSceneMgr) PlayerLeave(p *Player, reason int) bool { logger.Logger.Tracef("玩家离开: snid %v, reason %v isAudience %v", p.SnId, reason)
logger.Logger.Tracef("玩家离开: snid %v, reason %v", p.SnId, reason) return csm.playerLeave(p, reason)
if p.scene == nil || p.scene.csp == nil {
return false
}
if p.scene.csp.playerLeave(p, reason) {
return true
}
if p.scene.csp.audienceLeave(p, reason) {
return true
}
return false
} }
// OnDestroyScene 解散房间 // OnDestroyScene 解散房间
// 游戏服解散房间消息触发
// sceneId 房间id // sceneId 房间id
func (m *CoinSceneMgr) OnDestroyScene(sceneId int) { func (csm *CoinSceneMgr) OnDestroyScene(sceneId int) {
if s := SceneMgrSingleton.GetScene(sceneId); s != nil && s.csp != nil { if platformName, ok := csm.platformOfScene[sceneId]; ok {
s.csp.onDestroyScene(sceneId) if ss, ok := csm.scenesOfPlatform[platformName]; ok {
for _, csp := range ss {
csp.OnDestroyScene(sceneId)
}
}
delete(csm.platformOfScene, sceneId)
}
if groupId, ok := csm.groupOfScene[sceneId]; ok {
if ss, ok := csm.scenesOfGroup[groupId]; ok {
for _, csp := range ss {
csp.OnDestroyScene(sceneId)
}
}
delete(csm.groupOfScene, sceneId)
} }
} }
// GetPlatformBySceneId 获取房间所在平台
func (csm *CoinSceneMgr) GetPlatformBySceneId(sceneId int) string {
if platformName, ok := csm.platformOfScene[sceneId]; ok {
return platformName
}
s := SceneMgrSingleton.GetScene(sceneId)
if s != nil && s.limitPlatform != nil {
return s.limitPlatform.IdStr
}
return DefaultPlatform
}
// GetPlayerNums 获取场次人数 // GetPlayerNums 获取场次人数
func (m *CoinSceneMgr) GetPlayerNums(p *Player, gameId, gameMode int32) []int32 { func (csm *CoinSceneMgr) GetPlayerNums(p *Player, gameId, gameMode int32) []int32 {
//多平台支持 //多平台支持
platform := p.GetPlatform() platform := p.GetPlatform()
var nums [10]int32 var nums [10]int32
@ -174,7 +276,8 @@ func (m *CoinSceneMgr) GetPlayerNums(p *Player, gameId, gameMode int32) []int32
for _, id := range ids { for _, id := range ids {
gps := PlatformMgrSingleton.GetGameFree(platform.IdStr, id) gps := PlatformMgrSingleton.GetGameFree(platform.IdStr, id)
if gps != nil { if gps != nil {
if ss, ok := m.scenesOfPlatform[platform.IdStr]; ok { if gps.GroupId != 0 {
if ss, exist := csm.scenesOfGroup[gps.GroupId]; exist {
if csp, exist := ss[id]; exist { if csp, exist := ss[id]; exist {
sceneType := csp.GetSceneType() - 1 sceneType := csp.GetSceneType() - 1
if sceneType >= 0 && sceneType < len(nums) { if sceneType >= 0 && sceneType < len(nums) {
@ -182,6 +285,16 @@ func (m *CoinSceneMgr) GetPlayerNums(p *Player, gameId, gameMode int32) []int32
} }
} }
} }
} else {
if ss, ok := csm.scenesOfPlatform[platform.IdStr]; ok {
if csp, exist := ss[id]; exist {
sceneType := csp.GetSceneType() - 1
if sceneType >= 0 && sceneType < len(nums) {
nums[sceneType] += csp.GetPlayerNum() + csp.GetFakePlayerNum()
}
}
}
}
} }
} }
@ -192,9 +305,9 @@ func (m *CoinSceneMgr) GetPlayerNums(p *Player, gameId, gameMode int32) []int32
} }
// InCoinScene 是否在场次中 // InCoinScene 是否在场次中
func (m *CoinSceneMgr) InCoinScene(p *Player) bool { func (csm *CoinSceneMgr) InCoinScene(p *Player) bool {
if p == nil { if p == nil {
logger.Logger.Tracef("(m *CoinSceneMgr) InCoinScene p == nil") logger.Logger.Tracef("(csm *CoinSceneMgr) InCoinScene p == nil snid:%v ", p.SnId)
return false return false
} }
@ -209,10 +322,10 @@ func (m *CoinSceneMgr) InCoinScene(p *Player) bool {
} }
// PlayerTryLeave 通知游戏服务玩家要离开房间 // PlayerTryLeave 通知游戏服务玩家要离开房间
func (m *CoinSceneMgr) PlayerTryLeave(p *Player, isAudience bool) hallproto.OpResultCode { func (csm *CoinSceneMgr) PlayerTryLeave(p *Player, isAudience bool) hall_proto.OpResultCode {
if !m.InCoinScene(p) { if !csm.InCoinScene(p) {
logger.Logger.Tracef("(m *CoinSceneMgr) PlayerTryLeave !m.InCoinScene(p) snid:%v ", p.SnId) logger.Logger.Tracef("(csm *CoinSceneMgr) PlayerTryLeave !csm.InCoinScene(p) snid:%v ", p.SnId)
return hallproto.OpResultCode_OPRC_Sucess return hall_proto.OpResultCode_OPRC_Sucess
} }
// 通知gamesrv // 通知gamesrv
@ -220,54 +333,46 @@ func (m *CoinSceneMgr) PlayerTryLeave(p *Player, isAudience bool) hallproto.OpRe
if isAudience { if isAudience {
op = common.CoinSceneOp_AudienceLeave op = common.CoinSceneOp_AudienceLeave
} }
pack := &hallproto.CSCoinSceneOp{ pack := &hall_proto.CSCoinSceneOp{
Id: proto.Int32(p.scene.csp.ID()), Id: proto.Int32(p.scene.csp.id),
OpType: proto.Int32(op), OpType: proto.Int32(op),
} }
common.TransmitToServer(p.sid, int(hallproto.CoinSceneGamePacketID_PACKET_CS_COINSCENE_OP), pack, p.scene.gameSess.Session) proto.SetDefaults(pack)
logger.Logger.Tracef("(m *CoinSceneMgr) PlayerTryLeave snid:%v id:%v", p.SnId, pack.GetId()) common.TransmitToServer(p.sid, int(hall_proto.CoinSceneGamePacketID_PACKET_CS_COINSCENE_OP), pack, p.scene.gameSess.Session)
logger.Logger.Tracef("(csm *CoinSceneMgr) PlayerTryLeave snid:%v id:%v", p.SnId, pack.GetId())
return hallproto.OpResultCode_OPRC_OpYield return hall_proto.OpResultCode_OPRC_OpYield
} }
// PlayerInChanging 换房中 func (csm *CoinSceneMgr) PlayerInChanging(p *Player) bool {
func (m *CoinSceneMgr) PlayerInChanging(p *Player) bool { _, exist := csm.playerChanging[p.SnId]
_, exist := m.playerChanging[p.SnId]
return exist return exist
} }
// ClearPlayerChanging 换房结束 func (csm *CoinSceneMgr) ClearPlayerChanging(p *Player) {
func (m *CoinSceneMgr) ClearPlayerChanging(p *Player) { delete(csm.playerChanging, p.SnId)
delete(m.playerChanging, p.SnId)
} }
// PlayerTryChange 换房 func (csm *CoinSceneMgr) PlayerTryChange(p *Player, id int32, exclude []int32, isAudience bool) hall_proto.OpResultCode {
// id 场次id if csm.InCoinScene(p) {
// excludeRoomId 排除的房间id return csm.StartChangeCoinSceneTransact(p, id, exclude, isAudience)
// isAudience 是否是观众
func (m *CoinSceneMgr) PlayerTryChange(p *Player, id int32, excludeRoomId []int32, isAudience bool) hallproto.OpResultCode {
if m.InCoinScene(p) {
return m.StartChangeCoinSceneTransact(p, id, excludeRoomId, isAudience)
} }
// 不在场次中,进入房间观战
if isAudience { if isAudience {
return m.AudienceEnter(p, id, 0, excludeRoomId, true) return csm.AudienceEnter(p, id, 0, exclude, true)
} }
// 不在场次中,进入房间 return csm.PlayerEnter(p, id, 0, exclude, true)
return m.PlayerEnter(p, id, 0, excludeRoomId, true)
} }
func (m *CoinSceneMgr) StartChangeCoinSceneTransact(p *Player, id int32, exclude []int32, isAudience bool) hallproto.OpResultCode { func (csm *CoinSceneMgr) StartChangeCoinSceneTransact(p *Player, id int32, exclude []int32, isAudience bool) hall_proto.OpResultCode {
if p == nil || p.scene == nil { if p == nil || p.scene == nil {
logger.Logger.Warnf("(m *CoinSceneMgr) StartChangeCoinSceneTransact p == nil || p.scene == nil snid:%v id:%v", p.SnId, id) logger.Logger.Warnf("(csm *CoinSceneMgr) StartChangeCoinSceneTransact p == nil || p.scene == nil snid:%v id:%v", p.SnId, id)
return hallproto.OpResultCode_OPRC_Error return hall_proto.OpResultCode_OPRC_Error
} }
tNow := time.Now() tNow := time.Now()
if !p.lastChangeScene.IsZero() && tNow.Sub(p.lastChangeScene) < time.Second { if !p.lastChangeScene.IsZero() && tNow.Sub(p.lastChangeScene) < time.Second {
logger.Logger.Warnf("(m *CoinSceneMgr) StartChangeCoinSceneTransact !p.lastChangeScene.IsZero() && tNow.Sub(p.lastChangeScene) < time.Second snid:%v id:%v", p.SnId, id) logger.Logger.Warnf("(csm *CoinSceneMgr) StartChangeCoinSceneTransact !p.lastChangeScene.IsZero() && tNow.Sub(p.lastChangeScene) < time.Second snid:%v id:%v", p.SnId, id)
return hallproto.OpResultCode_OPRC_ChangeRoomTooOften return hall_proto.OpResultCode_OPRC_ChangeRoomTooOften
} }
tnp := &transact.TransNodeParam{ tnp := &transact.TransNodeParam{
@ -287,12 +392,12 @@ func (m *CoinSceneMgr) StartChangeCoinSceneTransact(p *Player, id int32, exclude
tNode := transact.DTCModule.StartTrans(tnp, ctx, CoinSceneChangeTimeOut) tNode := transact.DTCModule.StartTrans(tnp, ctx, CoinSceneChangeTimeOut)
if tNode != nil { if tNode != nil {
tNode.Go(core.CoreObject()) tNode.Go(core.CoreObject())
m.playerChanging[p.SnId] = id csm.playerChanging[p.SnId] = id
p.lastChangeScene = tNow p.lastChangeScene = tNow
return hallproto.OpResultCode_OPRC_Sucess return hall_proto.OpResultCode_OPRC_Sucess
} }
logger.Logger.Warnf("(m *CoinSceneMgr) StartChangeCoinSceneTransact tNode == nil snid:%v id:%v", p.SnId, id) logger.Logger.Warnf("(csm *CoinSceneMgr) StartChangeCoinSceneTransact tNode == nil snid:%v id:%v", p.SnId, id)
return hallproto.OpResultCode_OPRC_Error return hall_proto.OpResultCode_OPRC_Error
} }
// TouchCreateRoom 触发预创建房间 // TouchCreateRoom 触发预创建房间
@ -300,47 +405,44 @@ func (m *CoinSceneMgr) StartChangeCoinSceneTransact(p *Player, id int32, exclude
// 2.游戏服建立连接后触发 // 2.游戏服建立连接后触发
// 3.房间解散后触发 // 3.房间解散后触发
// 4.场次配置更新后 // 4.场次配置更新后
func (m *CoinSceneMgr) TouchCreateRoom(platform string, gameFreeId int32) { func (csm *CoinSceneMgr) TouchCreateRoom(platform string, gameFreeId int32) {
if model.GameParamData.ClosePreCreateRoom {
return
}
gf := PlatformMgrSingleton.GetGameFree(platform, gameFreeId) gf := PlatformMgrSingleton.GetGameFree(platform, gameFreeId)
if gf.Status && gf.DbGameFree.GetCreateRoomNum() > 0 { if gf.Status && gf.DbGameFree.GetCreateRoomNum() > 0 {
logger.Logger.Tracef("TouchCreateRoom platform:%v gameFreeId:%v", platform, gameFreeId) logger.Logger.Tracef("TouchCreateRoom platform:%v gameFreeId:%v", platform, gameFreeId)
m.delayCache = append(m.delayCache, &CreateRoomCache{ csm.delayCache = append(csm.delayCache, &CreateRoomCache{
platformName: platform, platformName: platform,
gameFreeId: gameFreeId, gameFreeId: gameFreeId,
}) })
} }
} }
func (m *CoinSceneMgr) ModuleName() string { func (csm *CoinSceneMgr) ModuleName() string {
return "CoinSceneMgr" return "CoinSceneMgr"
} }
func (m *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 == "" {
for _, v := range srvdata.PBDB_GameFreeMgr.Datas.GetArr() { for _, v := range srvdata.PBDB_GameFreeMgr.Datas.GetArr() {
gps := PlatformMgrSingleton.GetGameFree(platform.IdStr, v.GetId()) gps := PlatformMgrSingleton.GetGameFree(platform.IdStr, v.GetId())
if gps != nil { if gps != nil {
m.GetCoinScenePool(platform.IdStr, v.GetId()) csm.GetCoinScenePool(platform.IdStr, v.GetId())
m.TouchCreateRoom(platform.IdStr, v.GetId()) csm.TouchCreateRoom(platform.IdStr, v.GetId())
} }
} }
} }
} }
} }
func (m *CoinSceneMgr) Update() { func (csm *CoinSceneMgr) Update() {
cnt := len(m.delayCache) cnt := len(csm.delayCache)
if cnt > 0 { if cnt > 0 {
data := m.delayCache[cnt-1] data := csm.delayCache[cnt-1]
m.delayCache = m.delayCache[:cnt-1] csm.delayCache = csm.delayCache[:cnt-1]
gf := PlatformMgrSingleton.GetGameFree(data.platformName, data.gameFreeId) gf := PlatformMgrSingleton.GetGameFree(data.platformName, data.gameFreeId)
if gf != nil && gf.DbGameFree != nil { if gf != nil && gf.DbGameFree != nil {
csp := m.GetCoinScenePool(data.platformName, data.gameFreeId) csp := csm.GetCoinScenePool(data.platformName, data.gameFreeId)
if csp != nil { if csp != nil {
csp.PreCreateRoom() csp.PreCreateRoom()
} }
@ -348,22 +450,22 @@ func (m *CoinSceneMgr) Update() {
} }
} }
func (m *CoinSceneMgr) Shutdown() { func (csm *CoinSceneMgr) Shutdown() {
module.UnregisteModule(m) module.UnregisteModule(csm)
} }
//=====================PlatformObserver====================== //=====================PlatformObserver======================
func (m *CoinSceneMgr) OnPlatformCreate(p *Platform) { func (this *CoinSceneMgr) OnPlatformCreate(p *Platform) {
} }
func (m *CoinSceneMgr) OnPlatformDestroy(p *Platform) { func (this *CoinSceneMgr) OnPlatformDestroy(p *Platform) {
if p == nil { if p == nil {
return return
} }
var ids []int var ids []int
if v, ok := m.scenesOfPlatform[p.IdStr]; ok { if v, ok := this.scenesOfPlatform[p.IdStr]; ok {
for _, csp := range v { for _, csp := range v {
for _, scene := range csp.scenes { for _, scene := range csp.scenes {
ids = append(ids, scene.sceneId) ids = append(ids, scene.sceneId)
@ -373,18 +475,24 @@ func (m *CoinSceneMgr) OnPlatformDestroy(p *Platform) {
SceneMgrSingleton.DoDelete(ids, true) SceneMgrSingleton.DoDelete(ids, true)
} }
func (m *CoinSceneMgr) OnPlatformChangeDisabled(p *Platform, disabled bool) { func (this *CoinSceneMgr) OnPlatformChangeDisabled(p *Platform, disabled bool) {
if disabled { if disabled {
m.OnPlatformDestroy(p) this.OnPlatformDestroy(p)
} }
} }
func (m *CoinSceneMgr) OnPlatformGameFreeUpdate(p *Platform, oldCfg, newCfg *webapi.GameFree) { func (this *CoinSceneMgr) OnPlatformGameFreeUpdate(p *Platform, oldCfg, newCfg *webapi.GameFree) {
if p == nil || newCfg == nil { if p == nil || newCfg == nil {
return return
} }
ss, ok := m.scenesOfPlatform[p.IdStr] var ss map[int32]*CoinScenePool
var ok bool
if oldCfg.GroupId != newCfg.GroupId || oldCfg.GroupId != 0 {
ss, ok = this.scenesOfGroup[oldCfg.GroupId]
} else {
ss, ok = this.scenesOfPlatform[p.IdStr]
}
if !ok || ss == nil { if !ok || ss == nil {
return return
} }
@ -396,36 +504,62 @@ func (m *CoinSceneMgr) OnPlatformGameFreeUpdate(p *Platform, oldCfg, newCfg *web
ids = append(ids, scene.sceneId) ids = append(ids, scene.sceneId)
} }
SceneMgrSingleton.DoDelete(ids, true) SceneMgrSingleton.DoDelete(ids, true)
m.TouchCreateRoom(p.IdStr, newCfg.DbGameFree.Id) this.TouchCreateRoom(p.IdStr, newCfg.DbGameFree.Id)
} }
} }
func (m *CoinSceneMgr) OnPlatformDestroyByGameFreeId(p *Platform, gameFreeId int32) { func (this *CoinSceneMgr) OnPlatformDestroyByGameFreeId(p *Platform, gameFreeId int32) {
if p == nil { if p == nil {
return return
} }
if csps, ok := this.scenesOfPlatform[p.IdStr]; ok {
var ids []int var ids []int
if v, ok := m.scenesOfPlatform[p.IdStr]; ok { for _, csp := range csps {
for _, csp := range v {
for _, scene := range csp.scenes { for _, scene := range csp.scenes {
if scene.dbGameFree.Id == gameFreeId { if scene.dbGameFree.Id == gameFreeId {
ids = append(ids, scene.sceneId) ids = append(ids, scene.sceneId)
} }
} }
} }
}
SceneMgrSingleton.DoDelete(ids, true) SceneMgrSingleton.DoDelete(ids, true)
} }
}
//=========================PlatformGameGroupObserver============================== //=========================PlatformGameGroupObserver==============================
func (m *CoinSceneMgr) OnGameGroupUpdate(oldCfg, newCfg *webapi.GameConfigGroup) { func (this *CoinSceneMgr) OnGameGroupUpdate(oldCfg, newCfg *webapi.GameConfigGroup) {
if newCfg == nil {
return
}
if scenes, exist := this.scenesOfGroup[newCfg.Id]; exist {
if cps, ok := scenes[newCfg.DbGameFree.Id]; ok {
needDestroy := false
if cps.dbGameFree.GetBot() != newCfg.DbGameFree.GetBot() ||
cps.dbGameFree.GetBaseScore() != newCfg.DbGameFree.GetBaseScore() ||
cps.dbGameFree.GetLimitCoin() != newCfg.DbGameFree.GetLimitCoin() ||
cps.dbGameFree.GetMaxCoinLimit() != newCfg.DbGameFree.GetMaxCoinLimit() ||
cps.dbGameFree.GetTaxRate() != newCfg.DbGameFree.GetTaxRate() ||
!common.SliceInt64Equal(cps.dbGameFree.GetOtherIntParams(), newCfg.DbGameFree.GetOtherIntParams()) ||
!common.SliceInt64Equal(cps.dbGameFree.GetRobotTakeCoin(), newCfg.DbGameFree.GetRobotTakeCoin()) ||
!common.SliceInt64Equal(cps.dbGameFree.GetRobotLimitCoin(), newCfg.DbGameFree.GetRobotLimitCoin()) {
needDestroy = true
}
//TODO 预创建房间配置更新,unsupport group model
cps.dbGameFree = newCfg.DbGameFree
if needDestroy {
var ids []int
for _, scene := range cps.scenes {
ids = append(ids, scene.sceneId)
}
SceneMgrSingleton.DoDelete(ids, true)
}
}
}
} }
//=========================GameSessionListener====================================== //=========================GameSessionListener======================================
func (m *CoinSceneMgr) OnGameSessionRegiste(gs *GameSession) { func (csm *CoinSceneMgr) OnGameSessionRegiste(gs *GameSession) {
wildGs := len(gs.gameIds) == 0 || common.InSliceInt32(gs.gameIds, 0) // 是否所有游戏都支持 wildGs := len(gs.gameIds) == 0 || common.InSliceInt32(gs.gameIds, 0) // 是否所有游戏都支持
for _, platform := range PlatformMgrSingleton.GetPlatforms() { for _, platform := range PlatformMgrSingleton.GetPlatforms() {
if platform.IdStr == DefaultPlatform { if platform.IdStr == DefaultPlatform {
@ -435,13 +569,13 @@ func (m *CoinSceneMgr) OnGameSessionRegiste(gs *GameSession) {
gps := PlatformMgrSingleton.GetGameFrees(platform.IdStr) gps := PlatformMgrSingleton.GetGameFrees(platform.IdStr)
for _, v := range gps { for _, v := range gps {
if v != nil && (wildGs || common.InSliceInt32(gs.gameIds, v.DbGameFree.GetGameId())) { if v != nil && (wildGs || common.InSliceInt32(gs.gameIds, v.DbGameFree.GetGameId())) {
m.TouchCreateRoom(platform.IdStr, v.DbGameFree.Id) csm.TouchCreateRoom(platform.IdStr, v.DbGameFree.Id)
} }
} }
} }
} }
func (m *CoinSceneMgr) OnGameSessionUnregiste(gs *GameSession) { func (this *CoinSceneMgr) OnGameSessionUnregiste(gs *GameSession) {
//todo 游戏服务断开,是否解散房间? //todo 游戏服务断开,是否解散房间?
} }

View File

@ -1,9 +1,9 @@
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/common"
"mongo.games.com/game/model" "mongo.games.com/game/model"
gamehallproto "mongo.games.com/game/protocol/gamehall" gamehallproto "mongo.games.com/game/protocol/gamehall"
serverproto "mongo.games.com/game/protocol/server" serverproto "mongo.games.com/game/protocol/server"
@ -13,6 +13,8 @@ import (
// CoinScenePool 房间池 // CoinScenePool 房间池
type CoinScenePool struct { type CoinScenePool struct {
platform string // 平台id platform string // 平台id
groupId int32 // 组id
id int32 // 场次id
dbGameFree *serverproto.DB_GameFree // 场次配置 dbGameFree *serverproto.DB_GameFree // 场次配置
dbGameRule *serverproto.DB_GameRule // 场次配置 dbGameRule *serverproto.DB_GameRule // 场次配置
scenes map[int]*Scene // 所有房间,房间id scenes map[int]*Scene // 所有房间,房间id
@ -24,7 +26,7 @@ type CoinScenePool struct {
policy ICoinScenePool policy ICoinScenePool
} }
func newCoinScenePool(platform string, dbGameFree *serverproto.DB_GameFree) *CoinScenePool { func newCoinScenePool(platform string, groupId int32, dbGameFree *serverproto.DB_GameFree) *CoinScenePool {
if dbGameFree == nil { if dbGameFree == nil {
return nil return nil
} }
@ -40,6 +42,8 @@ func newCoinScenePool(platform string, dbGameFree *serverproto.DB_GameFree) *Coi
csp := &CoinScenePool{ csp := &CoinScenePool{
platform: platform, platform: platform,
groupId: groupId,
id: dbGameFree.GetId(),
dbGameFree: dbGameFree, dbGameFree: dbGameFree,
dbGameRule: dbGameRule, dbGameRule: dbGameRule,
scenes: make(map[int]*Scene), scenes: make(map[int]*Scene),
@ -55,10 +59,6 @@ func newCoinScenePool(platform string, dbGameFree *serverproto.DB_GameFree) *Coi
return csp return csp
} }
func (csp *CoinScenePool) ID() int32 {
return csp.dbGameFree.Id
}
func (csp *CoinScenePool) GetPlayerNum() int32 { func (csp *CoinScenePool) GetPlayerNum() int32 {
return int32(len(csp.players)) return int32(len(csp.players))
} }
@ -73,8 +73,7 @@ func (csp *CoinScenePool) GetFakePlayerNum() int32 {
return 0 return 0
} }
// GetSceneType 获取场次类型 // GetSceneType 获取场次id
// 新手场,中级场 ...
func (csp *CoinScenePool) GetSceneType() int { func (csp *CoinScenePool) GetSceneType() int {
if csp.dbGameFree != nil { if csp.dbGameFree != nil {
return int(csp.dbGameFree.GetSceneType()) return int(csp.dbGameFree.GetSceneType())
@ -90,79 +89,14 @@ func (csp *CoinScenePool) CanInviteRob() bool {
return false return false
} }
// PreCreateRoom 预创建房间 // CanEnter 检查入场条件
func (csp *CoinScenePool) PreCreateRoom() { func (csp *CoinScenePool) CanEnter(p *Player) gamehallproto.OpResultCode {
if csp.platform == DefaultPlatform || model.GameParamData.ClosePreCreateRoom {
return
}
if p := PlatformMgrSingleton.GetPlatform(csp.platform); p == nil || p.Disable {
return
}
preCreateNum := int(csp.dbGameFree.GetCreateRoomNum())
if preCreateNum <= 0 {
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
for _, scene := range csp.scenes {
if tp > 0 {
if scene.IsSceneMode(tp) {
num++
}
} else {
num++
}
}
return num
}
// GetHasTruePlayerSceneCnt 有真人的房间数量
func (csp *CoinScenePool) GetHasTruePlayerSceneCnt() int {
cnt := 0
for _, s := range csp.scenes {
if s.GetTruePlayerCnt() != 0 {
cnt++
}
}
return cnt
}
// AddScene 添加房间
// 自定义房间参数的时候创建房间后添加到房间池
// 创建房间后调用AddScene添加到房间池在玩家进入房间之前调用
func (csp *CoinScenePool) AddScene(s *Scene) {
if s == nil {
return
}
csp.scenes[s.sceneId] = s
s.csp = csp
}
// canEnter 检查入场条件
func (csp *CoinScenePool) canEnter(p *Player) gamehallproto.OpResultCode {
if csp.dbGameFree == nil || p == nil { if csp.dbGameFree == nil || p == nil {
return gamehallproto.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 gamehallproto.OpResultCode_OPRC_RoomHadClosed return gamehallproto.OpResultCode_OPRC_RoomHadClosed
} }
@ -185,14 +119,14 @@ func (csp *CoinScenePool) canEnter(p *Player) gamehallproto.OpResultCode {
return csp.policy.CanEnter(csp, p) return csp.policy.CanEnter(csp, p)
} }
// canAudienceEnter 检查观众入场条件 // CanAudienceEnter 检查观众入场条件
func (csp *CoinScenePool) canAudienceEnter(p *Player) gamehallproto.OpResultCode { func (csp *CoinScenePool) CanAudienceEnter(p *Player) gamehallproto.OpResultCode {
if csp.dbGameFree == nil || p == nil { if csp.dbGameFree == nil || p == nil {
return gamehallproto.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 gamehallproto.OpResultCode_OPRC_RoomHadClosed return gamehallproto.OpResultCode_OPRC_RoomHadClosed
} }
@ -205,16 +139,35 @@ func (csp *CoinScenePool) canAudienceEnter(p *Player) gamehallproto.OpResultCode
return csp.policy.CanAudienceEnter(csp, p) return csp.policy.CanAudienceEnter(csp, p)
} }
// playerEnter 玩家进入房间池 // 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 // exclude 排除的房间id
// isChangeRoom 是否换房 // isChangeRoom 是否换房
func (csp *CoinScenePool) playerEnter(p *Player, roomId int32, exclude []int32, isChangeRoom bool) gamehallproto.OpResultCode { func (csp *CoinScenePool) PlayerEnter(p *Player, roomId int32, exclude []int32, isChangeRoom bool) gamehallproto.OpResultCode {
if ret := csp.canEnter(p); ret != gamehallproto.OpResultCode_OPRC_Sucess { 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
} }
if p.scene != nil {
logger.Logger.Warnf("(csp *CoinScenePool) PlayerEnter[p.scene != nil] find snid:%v in scene:%v gameId:%v", p.SnId, p.scene.sceneId, p.scene.gameId)
return gamehallproto.OpResultCode_OPRC_Error
}
var scene *Scene var scene *Scene
// 进入房间 // 进入房间
// 指定房间id进入忽略排除exclude只有机器人和进入预创建房间才允许 // 指定房间id进入忽略排除exclude只有机器人和进入预创建房间才允许
@ -251,17 +204,15 @@ func (csp *CoinScenePool) playerEnter(p *Player, roomId int32, exclude []int32,
if scene == nil { if scene == nil {
scene = csp.policy.NewScene(csp, p) scene = csp.policy.NewScene(csp, p)
if scene != nil { if scene != nil {
logger.Logger.Infof("(csp *CoinScenePool) PlayerEnter create new scene:%v snid:%v gamefreeid:%v", scene.sceneId, p.SnId, csp.ID())
csp.AddScene(scene) csp.AddScene(scene)
} 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 scene.PlayerEnter(p, -1, isChangeRoom) { if scene.PlayerEnter(p, -1, isChangeRoom) {
logger.Logger.Infof("(csp *CoinScenePool) PlayerEnter snid:%v sceneid:%v gamefreeid:%v success", p.SnId, scene.sceneId, csp.ID()) csp.OnPlayerEnter(p, scene)
csp.onPlayerEnter(p, scene)
return gamehallproto.OpResultCode_OPRC_Sucess return gamehallproto.OpResultCode_OPRC_Sucess
} }
} }
@ -269,13 +220,18 @@ func (csp *CoinScenePool) playerEnter(p *Player, roomId int32, exclude []int32,
return gamehallproto.OpResultCode_OPRC_SceneServerMaintain return gamehallproto.OpResultCode_OPRC_SceneServerMaintain
} }
// audienceEnter 观众入场 // 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 { 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 {
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 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 {
@ -305,8 +261,7 @@ func (csp *CoinScenePool) audienceEnter(p *Player, roomId int32, exclude []int32
} }
if scene.AudienceEnter(p, isChangeRoom) { if scene.AudienceEnter(p, isChangeRoom) {
logger.Logger.Infof("(csp *CoinScenePool) AudienceEnter snid:%v sceneid:%v gamefreeid:%v success", p.SnId, scene.sceneId, csp.ID()) csp.OnPlayerEnter(p, scene)
csp.onPlayerEnter(p, scene)
return gamehallproto.OpResultCode_OPRC_Sucess return gamehallproto.OpResultCode_OPRC_Sucess
} }
@ -314,14 +269,78 @@ func (csp *CoinScenePool) audienceEnter(p *Player, roomId int32, exclude []int32
return gamehallproto.OpResultCode_OPRC_NoFindDownTiceRoom return gamehallproto.OpResultCode_OPRC_NoFindDownTiceRoom
} }
// onPlayerEnter 玩家进入房间完成 // OnPlayerEnter 玩家进入房间完成
func (csp *CoinScenePool) onPlayerEnter(p *Player, scene *Scene) { func (csp *CoinScenePool) OnPlayerEnter(p *Player, scene *Scene) {
csp.players[p.SnId] = struct{}{} csp.players[p.SnId] = struct{}{}
csp.policy.OnPlayerEnter(csp, p, scene) csp.policy.OnPlayerEnter(csp, p, scene)
} }
// PlayerLeave 玩家离开房间
func (csp *CoinScenePool) PlayerLeave(p *Player, reason int) bool {
if p.scene == nil {
return true
}
if p.scene.csp != csp && p.scene == csp.scenes[p.scene.sceneId] {
logger.Logger.Error("bug")
}
if p.scene.csp != csp {
return false
}
if p.scene != csp.scenes[p.scene.sceneId] {
logger.Logger.Error("bug")
}
s, ok := csp.scenes[p.scene.sceneId]
if !ok || s == nil {
return false
}
if !s.HasPlayer(p) {
return false
}
if !csp.policy.PlayerLeave(csp, p, reason) {
return false
}
s.PlayerLeave(p, reason)
logger.Logger.Tracef("(csp *CoinScenePool) PlayerLeave snid:%v in scene:%v", p.SnId, s.sceneId)
csp.policy.OnPlayerLeave(csp, s, p)
csp.OnPlayerLeave(s, p)
return true
}
// AudienceLeave 观众离开房间
func (csp *CoinScenePool) AudienceLeave(p *Player, reason int) bool {
if p.scene == nil {
return true
}
if p.scene.csp != csp {
return false
}
s, ok := csp.scenes[p.scene.sceneId]
if !ok || s == nil {
return false
}
if !s.HasAudience(p) {
return false
}
if !csp.policy.AudienceLeave(csp, p, reason) {
return false
}
s.AudienceLeave(p, reason)
logger.Logger.Tracef("(csp *CoinScenePool) AudienceLeave snid:%v in scene:%v", p.SnId, s.sceneId)
csp.policy.OnPlayerLeave(csp, s, p)
csp.OnPlayerLeave(s, p)
return true
}
// OnPlayerLeave 离开房间完成 // OnPlayerLeave 离开房间完成
func (csp *CoinScenePool) onPlayerLeave(s *Scene, p *Player) { func (csp *CoinScenePool) OnPlayerLeave(s *Scene, p *Player) {
if s == nil || p == nil { if s == nil || p == nil {
return return
} }
@ -351,68 +370,17 @@ func (csp *CoinScenePool) onPlayerLeave(s *Scene, p *Player) {
} }
} }
// playerLeave 玩家离开房间 // OnDestroyScene 解散房间
func (csp *CoinScenePool) playerLeave(p *Player, reason int) bool { // 房间解散一定是游戏服确认的worldsrv收到游戏房间解散消息后解散房间
if p.scene != csp.scenes[p.scene.sceneId] { func (csp *CoinScenePool) OnDestroyScene(sceneId int) {
logger.Logger.Error("bug")
}
s, ok := csp.scenes[p.scene.sceneId]
if !ok || s == nil {
return false
}
if !s.HasPlayer(p) {
return false
}
if !csp.policy.PlayerLeave(csp, p, reason) {
return false
}
s.PlayerLeave(p, reason)
logger.Logger.Tracef("(csp *CoinScenePool) PlayerLeave snid:%v in scene:%v", p.SnId, s.sceneId)
csp.policy.OnPlayerLeave(csp, s, p)
csp.onPlayerLeave(s, p)
return true
}
// audienceLeave 观众离开房间
func (csp *CoinScenePool) audienceLeave(p *Player, reason int) bool {
s, ok := csp.scenes[p.scene.sceneId]
if !ok || s == nil {
return false
}
if !s.HasAudience(p) {
return false
}
if !csp.policy.AudienceLeave(csp, p, reason) {
return false
}
s.AudienceLeave(p, reason)
logger.Logger.Tracef("(csp *CoinScenePool) AudienceLeave snid:%v in scene:%v", p.SnId, s.sceneId)
csp.policy.OnPlayerLeave(csp, s, p)
csp.onPlayerLeave(s, p)
return true
}
// onDestroyScene 解散房间
// 房间解散一定是游戏服确认的worldsrv收到游戏房间解散消息后解散房间此时房间内玩家应该都离开了
// 或者游戏服异常断开触发房间解散,此时房间中还有人
func (csp *CoinScenePool) onDestroyScene(sceneId int) {
scene, ok := csp.scenes[sceneId] scene, ok := csp.scenes[sceneId]
if !ok || scene == nil { if !ok {
return return
} }
logger.Logger.Tracef("(csp *CoinScenePool) OnDestroyScene scene:%v", sceneId) logger.Logger.Tracef("(csp *CoinScenePool) OnDestroyScene scene:%v", sceneId)
// todo 是否需要优化 // 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 {
@ -439,13 +407,96 @@ func (csp *CoinScenePool) onDestroyScene(sceneId int) {
} }
csp.policy.OnDestroyScene(csp, sceneId) csp.policy.OnDestroyScene(csp, sceneId)
for k := range scene.players {
delete(csp.players, k)
}
for k := range scene.audiences {
delete(csp.players, k)
}
scene.csp = nil // 解除关联 scene.csp = nil // 解除关联
delete(csp.scenes, sceneId) delete(csp.scenes, sceneId)
CoinSceneMgrSingleton.TouchCreateRoom(csp.platform, csp.dbGameFree.Id) CoinSceneMgrSingleton.TouchCreateRoom(csp.platform, csp.dbGameFree.Id)
} }
// PreCreateRoom 预创建房间
func (csp *CoinScenePool) PreCreateRoom() {
if csp.platform == DefaultPlatform {
return
}
if p := PlatformMgrSingleton.GetPlatform(csp.platform); p == nil || p.Disable {
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
for _, scene := range csp.scenes {
if tp > 0 {
if scene.IsSceneMode(tp) {
num++
}
} else {
num++
}
}
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
for _, s := range csp.scenes {
if s.GetTruePlayerCnt() != 0 {
cnt++
}
}
return cnt
}

View File

@ -157,7 +157,7 @@ func (this *BaseCoinScenePool) PlayerEnter(pool *CoinScenePool, p *Player, exclu
} }
} else { //按类型匹配 } else { //按类型匹配
//优先真人 //优先真人
if len(scenes) != 0 && matchTrueManRule == MatchTrueManPriority { if scene == nil && 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 {
@ -211,14 +211,14 @@ func (this *BaseCoinScenePool) AudienceLeave(pool *CoinScenePool, p *Player, rea
func (this *BaseCoinScenePool) OnPlayerLeave(pool *CoinScenePool, s *Scene, p *Player) {} func (this *BaseCoinScenePool) OnPlayerLeave(pool *CoinScenePool, s *Scene, p *Player) {}
func (this *BaseCoinScenePool) NewScene(pool *CoinScenePool, p *Player) *Scene { func (this *BaseCoinScenePool) NewScene(pool *CoinScenePool, p *Player) *Scene {
gameId := int(pool.dbGameFree.GetGameId()) gameId := int(pool.dbGameRule.GetGameId())
gs := GameSessMgrSington.GetMinLoadSess(gameId) gs := GameSessMgrSington.GetMinLoadSess(gameId)
if gs == nil { if gs == nil {
logger.Logger.Warnf("Get %v game min session failed.", gameId) logger.Logger.Warnf("Get %v game min session failed.", gameId)
return nil return nil
} }
gameMode := pool.dbGameFree.GetGameMode() gameMode := pool.dbGameRule.GetGameMode()
params := common.CopySliceInt32ToInt64(pool.dbGameRule.GetParams()) params := common.CopySliceInt32ToInt64(pool.dbGameRule.GetParams())
limitPlatform := PlatformMgrSingleton.GetPlatform(pool.platform) limitPlatform := PlatformMgrSingleton.GetPlatform(pool.platform)
if limitPlatform == nil || !limitPlatform.Isolated { if limitPlatform == nil || !limitPlatform.Isolated {
@ -228,7 +228,7 @@ func (this *BaseCoinScenePool) NewScene(pool *CoinScenePool, p *Player) *Scene {
sceneId := SceneMgrSingleton.GenOneCoinSceneId() sceneId := SceneMgrSingleton.GenOneCoinSceneId()
scene := SceneMgrSingleton.CreateScene(0, 0, sceneId, gameId, int(gameMode), common.SceneMode_Public, scene := SceneMgrSingleton.CreateScene(0, 0, sceneId, gameId, int(gameMode), common.SceneMode_Public,
1, -1, params, gs, limitPlatform, 0, pool.dbGameFree, pool.ID()) 1, -1, params, gs, limitPlatform, pool.groupId, pool.dbGameFree, pool.id)
return scene return scene
} }

View File

@ -233,7 +233,7 @@ func (l *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, 0, pool.ID()) gs, limitPlatform, 0, pool.dbGameFree, baseScore, pool.groupId, pool.id)
return scene return scene
} }
@ -285,7 +285,7 @@ func (l *CoinScenePoolLocal) NewPreCreateScene(pool *CoinScenePool) *Scene {
} }
if baseScore != 0 { if baseScore != 0 {
scene = SceneMgrSingleton.CreateLocalGameScene(0, sceneId, gameId, gameSite, common.SceneMode_Public, 1, common.CopySliceInt32ToInt64(params), scene = SceneMgrSingleton.CreateLocalGameScene(0, sceneId, gameId, gameSite, common.SceneMode_Public, 1, common.CopySliceInt32ToInt64(params),
gs, limitPlatform, playerNum, pool.dbGameFree, baseScore, 0, pool.ID()) gs, limitPlatform, playerNum, pool.dbGameFree, baseScore, pool.groupId, pool.id)
if scene != nil { if scene != nil {
logger.Logger.Tracef("CreateLocalGameScene success.gameId:%v gameSite:%v baseScore:%v randIdx:%v", scene.gameId, scene.gameSite, baseScore, randIdx) logger.Logger.Tracef("CreateLocalGameScene success.gameId:%v gameSite:%v baseScore:%v randIdx:%v", scene.gameId, scene.gameSite, baseScore, randIdx)
} }

View File

@ -66,7 +66,7 @@ func (this *GameSessMgr) OnRegiste(s *netlib.Session) {
} }
gs.OnRegiste() gs.OnRegiste()
//尝试创建百人场 //尝试创建百人场
HundredSceneMgrSingleton.TryCreateRoom() HundredSceneMgrSington.TryCreateRoom()
} }
} else if srvInfo.GetType() == srvlib.GateServiceType { } else if srvInfo.GetType() == srvlib.GateServiceType {
logger.Logger.Warn("(this *GameSessMgr) OnRegiste (GateSrv):", s) logger.Logger.Warn("(this *GameSessMgr) OnRegiste (GateSrv):", s)

View File

@ -10,193 +10,383 @@ 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/proto" "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/protocol/webapi" "mongo.games.com/game/protocol/webapi"
"mongo.games.com/game/srvdata" "mongo.games.com/game/srvdata"
) )
const ( const (
HundredSceneOPEnter int32 = iota //进入 HundredSceneType_Primary int = iota //初级
HundredSceneOPLeave //离开 HundredSceneType_Mid //中级
HundredSceneOPChange //换桌 HundredSceneType_Senior //高级
HundredSceneType_Professor //专家
HundredSceneType_Experience //体验场
HundredSceneType_Max
) )
var HundredSceneMgrSingleton = &HundredSceneMgr{ const (
HundredSceneOp_Enter int32 = iota //进入
HundredSceneOp_Leave //离开
HundredSceneOp_Change //换桌
HundredSceneOp_Audience //观战
)
var HundredSceneMgrSington = &HundredSceneMgr{
//分平台管理
scenesOfPlatform: make(map[string]map[int32]*Scene), scenesOfPlatform: make(map[string]map[int32]*Scene),
platformOfScene: make(map[int32]string),
//分组管理
scenesOfGroup: make(map[int32]map[int32]*Scene),
groupOfScene: make(map[int32]int32),
playerIning: make(map[int32]int32),
} }
type HundredSceneMgr struct { type HundredSceneMgr struct {
//分平台管理
scenesOfPlatform map[string]map[int32]*Scene // platform:gamefreeid:房间 scenesOfPlatform map[string]map[int32]*Scene // platform:gamefreeid:房间
platformOfScene map[int32]string // sceneid:platform
//分组管理
scenesOfGroup map[int32]map[int32]*Scene // groupid:gamefreeid:房间
groupOfScene map[int32]int32 // sceneid:groupid
playerIning map[int32]int32 // snid:sceneid
} }
// PlayerEnter 玩家进入场次 func (this *HundredSceneMgr) GetPlatformNameBySceneId(sceneid int32) (string, bool) {
// id 场次id if name, exist := this.platformOfScene[sceneid]; exist {
func (this *HundredSceneMgr) PlayerEnter(p *Player, id int32) gamehallproto.OpResultCode_Hundred { return name, exist
logger.Logger.Tracef("HundredSceneMgr PlayerEnter snid:%v gamefreeid:%v", p.SnId, id) }
if p.isDelete { if _, exist := this.groupOfScene[sceneid]; exist {
return gamehallproto.OpResultCode_Hundred_OPRC_RoomHadClosed_Hundred s := SceneMgrSingleton.GetScene(int(sceneid))
if s != nil && s.limitPlatform != nil {
return s.limitPlatform.IdStr, true
}
}
return DefaultPlatform, false
} }
if this.InHundredScene(p) { func (this *HundredSceneMgr) RebindPlayerSnId(oldSnId, newSnId int32) {
logger.Logger.Warnf("HundredSceneMgr PlayerEnter snid:%v find in gamefreeid:%v roomId:%v", p.SnId, p.scene.dbGameFree.Id, p.scene.sceneId) if id, exist := this.playerIning[oldSnId]; exist {
return gamehallproto.OpResultCode_Hundred_OPRC_Error_Hundred delete(this.playerIning, oldSnId)
this.playerIning[newSnId] = id
}
for _, ss := range this.scenesOfPlatform {
for _, s := range ss {
s.RebindPlayerSnId(oldSnId, newSnId)
}
}
for _, ss := range this.scenesOfGroup {
for _, s := range ss {
s.RebindPlayerSnId(oldSnId, newSnId)
}
}
}
func (this *HundredSceneMgr) PlayerEnter(p *Player, id int32) gamehall_proto.OpResultCode_Hundred {
logger.Logger.Tracef("(this *HundredSceneMgr) PlayerEnter snid:%v id:%v", p.SnId, id)
if oid, exist := this.playerIning[p.SnId]; exist {
logger.Logger.Warnf("(this *HundredSceneMgr) PlayerEnter:%v snid:%v find in id:%v PlayerEnter return false", id, p.SnId, oid)
return gamehall_proto.OpResultCode_Hundred_OPRC_Error_Hundred
}
if p.scene != nil {
logger.Logger.Warnf("(this *HundredSceneMgr) PlayerEnter:%v snid:%v find in id:%v PlayerEnter return false", id, p.SnId, p.scene.sceneId)
return gamehall_proto.OpResultCode_Hundred_OPRC_Error_Hundred
}
if p.isDelete { //删档用户不让进游戏
return gamehall_proto.OpResultCode_Hundred_OPRC_RoomHadClosed_Hundred
} }
//多平台支持 //多平台支持
platform := p.GetPlatform() var limitPlatform *Platform
if platform == nil { platformName := DefaultPlatform
return gamehallproto.OpResultCode_Hundred_OPRC_RoomHadClosed_Hundred platform := PlatformMgrSingleton.GetPlatform(p.Platform)
if platform != nil && platform.Isolated {
platformName = platform.IdStr
limitPlatform = platform
} else {
limitPlatform = PlatformMgrSingleton.GetPlatform(DefaultPlatform)
} }
gps := PlatformMgrSingleton.GetGameFree(platform.IdStr, id) gps := PlatformMgrSingleton.GetGameFree(limitPlatform.IdStr, id)
if gps == nil { if gps == nil {
return gamehallproto.OpResultCode_Hundred_OPRC_RoomHadClosed_Hundred return gamehall_proto.OpResultCode_Hundred_OPRC_RoomHadClosed_Hundred
} }
//没有场景,尝试创建 if gps.GroupId != 0 { //按分组进入场景游戏
if _, ok := this.scenesOfPlatform[platform.IdStr]; !ok { pgg := PlatformGameGroupMgrSington.GetGameGroup(gps.GroupId)
this.scenesOfPlatform[platform.IdStr] = make(map[int32]*Scene) if pgg != nil {
if _, ok := this.scenesOfGroup[gps.GroupId]; !ok {
this.scenesOfGroup[gps.GroupId] = make(map[int32]*Scene)
} }
ss := this.scenesOfPlatform[platform.IdStr] if ss, ok := this.scenesOfGroup[gps.GroupId]; ok {
if s, ok := ss[id]; !ok || s == nil { if s, ok := ss[id]; !ok {
s = this.CreateNewScene(id, gps.GroupId, platform, gps.DbGameFree) s = this.CreateNewScene(id, gps.GroupId, limitPlatform, pgg.DbGameFree)
if s != nil { if s != nil {
ss[id] = s ss[id] = s
s.hp = this this.groupOfScene[int32(s.sceneId)] = gps.GroupId
logger.Logger.Infof("HundredSceneMgr PlayerEnter(platform=%v snid=%v) Create %v scene success.", platform.IdStr, p.SnId, id) logger.Logger.Tracef("(this *HundredSceneMgr) PlayerEnter(groupid=%v) Create %v scene success.", gps.GroupId, id)
} else { } else {
logger.Logger.Errorf("HundredSceneMgr PlayerEnter(platform=%v snid=%v) Create %v scene failed.", platform.IdStr, p.SnId, id) logger.Logger.Tracef("(this *HundredSceneMgr) PlayerEnter(groupid=%v) Create %v scene failed.", gps.GroupId, id)
} }
} }
//尝试进入 //尝试进入
if s, ok := ss[id]; ok && s != nil { if s, ok := ss[id]; ok && s != nil {
if s.PlayerEnter(p, -1, true) { if s.PlayerEnter(p, -1, true) {
logger.Logger.Infof("HundredSceneMgr PlayerEnter(platform=%v snid=%v) enter %v scene success.", platform.IdStr, p.SnId, id) this.OnPlayerEnter(p, id)
return gamehallproto.OpResultCode_Hundred_OPRC_Sucess_Hundred return gamehall_proto.OpResultCode_Hundred_OPRC_Sucess_Hundred
} else { } else {
logger.Logger.Errorf("HundredSceneMgr PlayerEnter(platform=%v snid=%v) enter %v scene failed.", platform.IdStr, p.SnId, id) logger.Logger.Warnf("(this *HundredSceneMgr) PlayerEnter(groupid=%v) enter %v scene failed.", gps.GroupId, id)
} }
} else { } else {
logger.Logger.Errorf("HundredSceneMgr PlayerEnter(platform=%v) get %v scene failed.", platform.IdStr, id) logger.Logger.Warnf("(this *HundredSceneMgr) PlayerEnter(groupid=%v) get %v scene failed.", gps.GroupId, id)
}
}
logger.Logger.Warnf("(this *HundredSceneMgr) PlayerEnter(groupid=%v) snid:%v find in id:%v csp.PlayerEnter return false", gps.GroupId, p.SnId, id)
return gamehall_proto.OpResultCode_Hundred_OPRC_Error_Hundred
}
}
//没有场景,尝试创建
if _, ok := this.scenesOfPlatform[platformName]; !ok {
this.scenesOfPlatform[platformName] = make(map[int32]*Scene)
}
if ss, ok := this.scenesOfPlatform[platformName]; ok {
if s, ok := ss[id]; !ok {
s = this.CreateNewScene(id, gps.GroupId, limitPlatform, gps.DbGameFree)
if s != nil {
ss[id] = s
this.platformOfScene[int32(s.sceneId)] = platformName
logger.Logger.Tracef("(this *HundredSceneMgr) PlayerEnter(platform=%v) Create %v scene success.", platformName, id)
} else {
logger.Logger.Tracef("(this *HundredSceneMgr) PlayerEnter(platform=%v) Create %v scene failed.", platformName, id)
}
}
//尝试进入
if s, ok := ss[id]; ok && s != nil {
if s.PlayerEnter(p, -1, true) {
this.OnPlayerEnter(p, id)
return gamehall_proto.OpResultCode_Hundred_OPRC_Sucess_Hundred
} else {
logger.Logger.Warnf("(this *HundredSceneMgr) PlayerEnter(platform=%v) enter %v scene failed.", platformName, id)
}
} else {
logger.Logger.Warnf("(this *HundredSceneMgr) PlayerEnter(platform=%v) get %v scene failed.", platformName, id)
}
}
logger.Logger.Warnf("(this *HundredSceneMgr) PlayerEnter(platform=%v) snid:%v find in id:%v csp.PlayerEnter return false", platformName, p.SnId, id)
return gamehall_proto.OpResultCode_Hundred_OPRC_SceneServerMaintain_Hundred
} }
return gamehallproto.OpResultCode_Hundred_OPRC_SceneServerMaintain_Hundred func (this *HundredSceneMgr) OnPlayerEnter(p *Player, id int32) {
this.playerIning[p.SnId] = id
} }
// PlayerLeave 离开房间
// 游戏服通知玩家离开房间
func (this *HundredSceneMgr) PlayerLeave(p *Player, reason int) bool { func (this *HundredSceneMgr) PlayerLeave(p *Player, reason int) bool {
if p == nil || p.scene == nil || p.scene.hp == nil { if p == nil {
return false return false
} }
if _, ok := this.playerIning[p.SnId]; ok {
if p.scene != nil {
p.scene.PlayerLeave(p, reason) p.scene.PlayerLeave(p, reason)
} else {
logger.Logger.Warnf("(this *HundredSceneMgr) PlayerLeave(%v) found scene=nil", p.SnId)
delete(this.playerIning, p.SnId)
}
return true
} else {
if p.scene != nil && p.scene.IsHundredScene() {
logger.Logger.Warnf("(this *HundredSceneMgr) PlayerLeave(%v) exception scene=%v gameid=%v", p.SnId, p.scene.sceneId, p.scene.gameId)
p.scene.PlayerLeave(p, reason)
return true
}
}
logger.Logger.Warnf("(this *HundredSceneMgr) PlayerLeave(%v) not found in hundred scene", p.SnId)
return false return false
} }
// PlayerTryLeave 玩家尝试离开房间 func (this *HundredSceneMgr) PlayerTryLeave(p *Player) gamehall_proto.OpResultCode_Hundred {
// 给游戏服发离开消息 if p.scene == nil || p.scene.gameSess == nil {
func (this *HundredSceneMgr) PlayerTryLeave(p *Player) gamehallproto.OpResultCode_Hundred { logger.Logger.Tracef("(csm *HundredSceneMgr) PlayerTryLeave p.scene == nil || p.scene.gameSess == nil snid:%v ", p.SnId)
if !this.InHundredScene(p) { return 1
logger.Logger.Tracef("(this *HundredSceneMgr) PlayerTryLeave !csm.InCoinScene(p) snid:%v ", p.SnId) }
return gamehallproto.OpResultCode_Hundred_OPRC_Sucess_Hundred //通知gamesrv托管
if _, ok := this.playerIning[p.SnId]; ok {
pack := &gamehall_proto.CSLeaveRoom{Mode: proto.Int(0)}
proto.SetDefaults(pack)
common.TransmitToServer(p.sid, int(gamehall_proto.GameHallPacketID_PACKET_CS_LEAVEROOM), pack, p.scene.gameSess.Session)
}
return 0
} }
pack := &gamehallproto.CSLeaveRoom{Mode: proto.Int(0)} func (this *HundredSceneMgr) OnPlayerLeave(p *Player) {
common.TransmitToServer(p.sid, int(gamehallproto.GameHallPacketID_PACKET_CS_LEAVEROOM), pack, p.scene.gameSess.Session) delete(this.playerIning, p.SnId)
return gamehallproto.OpResultCode_Hundred_OPRC_Sucess_Hundred // ???
} }
// OnDestroyScene 房间销毁 func (this *HundredSceneMgr) OnDestroyScene(sceneid int) {
func (this *HundredSceneMgr) OnDestroyScene(sceneId int) { var s *Scene
s := SceneMgrSingleton.GetScene(sceneId) if platformName, ok := this.platformOfScene[int32(sceneid)]; ok {
if s == nil { if ss, ok := this.scenesOfPlatform[platformName]; ok {
return
}
plt := SceneMgrSingleton.GetPlatformBySceneId(sceneId)
if plt == "" {
return
}
if ss, ok := this.scenesOfPlatform[plt]; ok {
for id, scene := range ss { for id, scene := range ss {
if scene.sceneId == sceneId { if scene.sceneId == sceneid {
if scene != s { s = scene
logger.Logger.Errorf("bug")
}
//删除玩家 //删除玩家
for _, v := range scene.players { for pid, hid := range this.playerIning {
if v != nil { if hid == id {
if !v.IsRob { delete(this.playerIning, pid)
ctx := scene.GetPlayerGameCtx(v.SnId) //TODO 非正常删除房间时,尝试同步金币
player := PlayerMgrSington.GetPlayerBySnId(pid)
if player != nil {
if !player.IsRob {
ctx := scene.GetPlayerGameCtx(player.SnId)
if ctx != nil { if ctx != nil {
//发送一个探针,等待ack后同步金币 //发送一个探针,等待ack后同步金币
v.TryRetrieveLostGameCoin(sceneId) player.TryRetrieveLostGameCoin(sceneid)
logger.Logger.Warnf("(this *HundredSceneMgr) OnDestroyScene(sceneid:%v) snid:%v SyncGameCoin", sceneId, v.SnId)
}
}
}
}
scene.hp = nil logger.Logger.Warnf("(this *HundredSceneMgr) OnDestroyScene(sceneid:%v) snid:%v SyncGameCoin", sceneid, player.SnId)
}
}
}
}
}
delete(ss, id) delete(ss, id)
break break
} }
} }
} }
}
this.tryCreateRoom(plt, s.dbGameFree.Id) if groupId, ok := this.groupOfScene[int32(sceneid)]; ok {
if ss, ok := this.scenesOfGroup[groupId]; ok {
for id, scene := range ss {
if scene.sceneId == sceneid {
s = scene
//删除玩家
for pid, hid := range this.playerIning {
if hid == id {
delete(this.playerIning, pid)
//TODO 非正常删除房间时,尝试同步金币
player := PlayerMgrSington.GetPlayerBySnId(pid)
if player != nil {
if !player.IsRob {
ctx := scene.GetPlayerGameCtx(player.SnId)
if ctx != nil {
//发送一个探针,等待ack后同步金币
player.TryRetrieveLostGameCoin(sceneid)
logger.Logger.Warnf("(this *HundredSceneMgr) OnDestroyScene(sceneid:%v) snid:%v SyncGameCoin", sceneid, player.SnId)
}
}
}
}
}
delete(ss, id)
break
}
}
}
}
this.PreCreateGame(s.limitPlatform.IdStr, []int32{s.dbGameFree.Id})
} }
func (this *HundredSceneMgr) GetPlayerNums(p *Player, gameId, gameMode int32) []int32 { func (this *HundredSceneMgr) GetPlayerNums(p *Player, gameId, gameMode int32) []int32 {
//多平台支持 //多平台支持
platform := p.GetPlatform() platformName := DefaultPlatform
var nums [10]int32 platform := PlatformMgrSingleton.GetPlatform(p.Platform)
wantNum := [10]int32{80, 50, 30, 20, 10, 10, 10, 10, 10, 10} if platform != nil && platform.Isolated {
for i := 0; i < 10; i++ { platformName = platform.IdStr
} else if p.Platform != DefaultPlatform {
platform = PlatformMgrSingleton.GetPlatform(DefaultPlatform)
}
var nums [HundredSceneType_Max]int32
wantNum := []int32{80, 50, 30, 20, 0}
for i := 0; i < HundredSceneType_Max; i++ {
if wantNum[i]/2 > 0 { if wantNum[i]/2 > 0 {
nums[i] = rand.Int31n(wantNum[i]/2) + wantNum[i] nums[i] = rand.Int31n(wantNum[i]/2) + wantNum[i]
} }
} }
if platform == nil { if platform == nil {
return nums[:] return nums[:]
} }
ids, _ := srvdata.GameFreeMgr.GetGameFreeIds(gameId, gameMode) ids, _ := srvdata.GameFreeMgr.GetGameFreeIds(gameId, gameMode)
for _, id := range ids { for _, id := range ids {
gps := PlatformMgrSingleton.GetGameFree(platform.IdStr, id) gps := PlatformMgrSingleton.GetGameFree(platform.IdStr, id)
if gps != nil { if gps != nil {
if ss, ok := this.scenesOfPlatform[platform.IdStr]; ok { if gps.GroupId != 0 {
if s, exist := ss[id]; exist && s.dbGameFree != nil { if ss, exist := this.scenesOfGroup[gps.GroupId]; exist {
sceneType := s.dbGameFree.GetSceneType() - 1 for _, s := range ss {
if sceneType >= 0 && int(sceneType) < len(nums) { if s.paramsEx[0] == id {
nums[sceneType] += int32(s.GetPlayerCnt()) dbGame := srvdata.PBDB_GameFreeMgr.GetData(s.paramsEx[0])
sceneType := int(dbGame.GetSceneType()) - 1
if sceneType == -2 {
//体验场
sceneType = HundredSceneType_Experience
}
truePlayerCount := int32(s.GetPlayerCnt())
//获取fake用户数量
var fakePlayerCount int32
//if truePlayerCount >= 21 {
// correctNum := dbGame.GetCorrectNum()
// correctRate := dbGame.GetCorrectRate()
// fakePlayerCount = correctNum + truePlayerCount*correctRate/100 + dbGame.GetDeviation()
//}
if sceneType >= 0 && sceneType < HundredSceneType_Max {
nums[sceneType] += int32(truePlayerCount + fakePlayerCount)
}
break
}
}
}
} else {
if ss, ok := this.scenesOfPlatform[platformName]; ok {
for _, s := range ss {
if s.paramsEx[0] == id {
dbGame := srvdata.PBDB_GameFreeMgr.GetData(s.paramsEx[0])
sceneType := int(dbGame.GetSceneType()) - 1
if sceneType == -2 {
//体验场
sceneType = HundredSceneType_Experience
}
truePlayerCount := int32(s.GetPlayerCnt())
//获取fake用户数量
var fakePlayerCount int32
//if truePlayerCount >= 21 {
// correctNum := dbGame.GetCorrectNum()
// correctRate := dbGame.GetCorrectRate()
// fakePlayerCount = correctNum + truePlayerCount*correctRate/100 + dbGame.GetDeviation()
//}
if sceneType >= 0 && sceneType < HundredSceneType_Max {
nums[sceneType] += int32(truePlayerCount + fakePlayerCount)
}
break
} }
} }
} }
} }
} }
if len(ids) <= 10 {
return nums[:len(ids)]
} }
return nums[:] return nums[:]
} }
func (this *HundredSceneMgr) InHundredScene(p *Player) bool { func (this *HundredSceneMgr) InHundredScene(p *Player) bool {
if p == nil { if p == nil {
logger.Logger.Tracef("(this *HundredSceneMgr) InHundredScene p == nil snid:%v ", p.SnId)
return false return false
} }
if p.scene == nil { if _, ok := this.playerIning[p.SnId]; ok {
return false
}
if p.scene.hp == nil {
return false
}
return true return true
} }
logger.Logger.Tracef("(csm *HundredSceneMgr) InHundredScene false snid:%v ", p.SnId)
return false
}
func (this *HundredSceneMgr) CreateNewScene(id, groupId int32, limitPlatform *Platform, dbGameFree *serverproto.DB_GameFree) *Scene { func (this *HundredSceneMgr) CreateNewScene(id, groupId int32, limitPlatform *Platform, dbGameFree *server_proto.DB_GameFree) *Scene {
if dbGameFree != nil { if dbGameFree != nil {
dbGameRule := srvdata.PBDB_GameRuleMgr.GetData(dbGameFree.GetGameRule()) dbGameRule := srvdata.PBDB_GameRuleMgr.GetData(dbGameFree.GetGameRule())
if dbGameRule != nil { if dbGameRule != nil {
@ -206,11 +396,16 @@ func (this *HundredSceneMgr) CreateNewScene(id, groupId int32, limitPlatform *Pl
sceneId := SceneMgrSingleton.GenOneHundredSceneId() sceneId := SceneMgrSingleton.GenOneHundredSceneId()
gameMode := dbGameRule.GetGameMode() gameMode := dbGameRule.GetGameMode()
params := common.CopySliceInt32ToInt64(dbGameRule.GetParams()) params := common.CopySliceInt32ToInt64(dbGameRule.GetParams())
//SceneType := dbGameFree.GetSceneType()
scene := SceneMgrSingleton.CreateScene(0, 0, sceneId, gameId, int(gameMode), common.SceneMode_Public, 1, -1, params, gs, limitPlatform, groupId, dbGameFree, id) scene := SceneMgrSingleton.CreateScene(0, 0, sceneId, gameId, int(gameMode), common.SceneMode_Public, 1, -1, params, gs, limitPlatform, groupId, dbGameFree, id)
if scene != nil { if scene != nil {
logger.Logger.Infof("Create hundred scene %v-%v success.", gameId, sceneId)
scene.hallId = id scene.hallId = id
scene.hp = this //移动到SceneMgr中集中处理
//if !scene.IsMatchScene() {
// //平台水池设置
// gs.DetectCoinPoolSetting(limitPlatform.Name, scene.hallId, scene.groupId)
//}
return scene return scene
} else { } else {
logger.Logger.Errorf("Create hundred scene %v-%v failed.", gameId, sceneId) logger.Logger.Errorf("Create hundred scene %v-%v failed.", gameId, sceneId)
@ -224,143 +419,134 @@ func (this *HundredSceneMgr) CreateNewScene(id, groupId int32, limitPlatform *Pl
} else { } else {
logger.Logger.Errorf("Game free data %v no found.", id) logger.Logger.Errorf("Game free data %v no found.", id)
} }
return nil return nil
} }
func (this *HundredSceneMgr) tryCreateRoom(plt string, id ...int32) { func (this *HundredSceneMgr) TryCreateRoom() {
limitPlatform := PlatformMgrSingleton.GetPlatform(plt) if model.GameParamData.HundredScenePreCreate {
arr := srvdata.PBDB_GameFreeMgr.Datas.GetArr()
for _, dbGame := range arr {
if dbGame.GetGameId() <= 0 {
continue
}
if common.IsHundredType(dbGame.GetGameType()) { //百人场
id := dbGame.GetId()
for k, ss := range this.scenesOfPlatform {
if _, exist := ss[id]; !exist {
limitPlatform := PlatformMgrSingleton.GetPlatform(k)
if limitPlatform == nil || !limitPlatform.Isolated {
limitPlatform = PlatformMgrSingleton.GetPlatform(DefaultPlatform)
k = DefaultPlatform
continue
}
gps := PlatformMgrSingleton.GetGameFree(limitPlatform.IdStr, id)
if gps != nil && gps.GroupId == 0 && gps.Status {
scene := this.CreateNewScene(id, gps.GroupId, limitPlatform, gps.DbGameFree)
logger.Logger.Trace("(this *HundredSceneMgr) TryCreateRoom(platform) ", id, k, scene)
if scene != nil {
this.platformOfScene[int32(scene.sceneId)] = k
ss[id] = scene
}
}
}
}
}
}
}
}
func (this *HundredSceneMgr) PreCreateGame(platform string, createIds []int32) {
limitPlatform := PlatformMgrSingleton.GetPlatform(platform)
if limitPlatform == nil || !limitPlatform.Isolated { if limitPlatform == nil || !limitPlatform.Isolated {
limitPlatform = PlatformMgrSingleton.GetPlatform(DefaultPlatform) limitPlatform = PlatformMgrSingleton.GetPlatform(DefaultPlatform)
} }
if this.scenesOfPlatform[plt] == nil { if this.scenesOfPlatform[platform] == nil {
this.scenesOfPlatform[plt] = make(map[int32]*Scene) this.scenesOfPlatform[platform] = make(map[int32]*Scene)
} }
if limitPlatform.IdStr == DefaultPlatform { //var platformName string
return
}
f := func(i int32) {
if this.scenesOfPlatform[plt][i] != nil {
return
}
gps := PlatformMgrSingleton.GetGameFree(plt, i)
if !common.IsHundredType(gps.GetDbGameFree().GetGameType()) {
return
}
scene := this.CreateNewScene(i, gps.GroupId, limitPlatform, gps.DbGameFree)
if scene != nil {
this.scenesOfPlatform[plt][i] = scene
scene.hp = this
logger.Logger.Infof("HundredSceneMgr PreCreateRoom Platform:%v Id:%v", plt, i)
}
}
if len(id) == 0 {
// 所有百人场
for _, vv := range srvdata.PBDB_GameFreeMgr.Datas.GetArr() {
f(vv.GetId())
}
} else {
for _, v := range id {
f(v)
}
}
}
// TryCreateRoom 预创建房间
func (this *HundredSceneMgr) TryCreateRoom() {
if !model.GameParamData.HundredScenePreCreate {
return
}
for _, v := range PlatformMgrSingleton.GetPlatforms() {
this.tryCreateRoom(v.IdStr)
}
}
func (this *HundredSceneMgr) OnPlatformChangeIsolated(p *Platform, isolated bool) {
if p == nil {
return
}
if isolated { //孤立
this.OnPlatformCreate(p) //预创建场景
} else {
this.OnPlatformDestroy(p)
}
}
func (this *HundredSceneMgr) GetPlatformSceneByGameFreeId(platform string, gameFreeIds []int32) []*Scene {
platformName := DefaultPlatform
platformData := PlatformMgrSingleton.GetPlatform(platform) platformData := PlatformMgrSingleton.GetPlatform(platform)
if platformData != nil && platformData.Isolated { if platformData != nil && platformData.Isolated {
platformName = platformData.IdStr //platformName = platformData.Name
} else if platform != DefaultPlatform { } else if platform != DefaultPlatform {
platformData = PlatformMgrSingleton.GetPlatform(DefaultPlatform) platformData = PlatformMgrSingleton.GetPlatform(DefaultPlatform)
} }
if platformData.IdStr == DefaultPlatform {
if platformData == nil { return
return nil
} }
var scenes []*Scene
for _, id := range gameFreeIds {
gps := PlatformMgrSingleton.GetGameFree(platformData.IdStr, id)
if gps != nil {
if ss, ok := this.scenesOfPlatform[platformName]; ok {
if s, exist := ss[id]; exist && s != nil {
scenes = append(scenes, s)
}
}
}
}
return scenes
}
func (this *HundredSceneMgr) GetPlatformScene(platform string, gameId int32) []*Scene {
gameFreeIds := gameStateMgr.gameIds[gameId]
gameScenes := this.GetPlatformSceneByGameFreeId(platform, gameFreeIds)
if len(gameScenes) != len(gameFreeIds) {
var createIds []int32
for _, gfi := range gameFreeIds {
bFind := false
for _, s := range gameScenes {
if s.dbGameFree.GetId() == gfi {
bFind = true
break
}
}
if !bFind {
createIds = append(createIds, gfi)
}
}
if len(createIds) > 0 {
this.tryCreateRoom(platform, createIds...)
gameScenes = this.GetPlatformSceneByGameFreeId(platform, gameFreeIds)
}
}
return gameScenes
}
func (this *HundredSceneMgr) ModuleName() string {
return "HundredSceneMgr"
}
func (this *HundredSceneMgr) Init() {
this.TryCreateRoom()
}
func (this *HundredSceneMgr) Update() {
}
func (this *HundredSceneMgr) Shutdown() {
module.UnregisteModule(this)
}
func (this *HundredSceneMgr) OnPlatformCreate(p *Platform) {
if model.GameParamData.HundredScenePreCreate { if model.GameParamData.HundredScenePreCreate {
this.tryCreateRoom(p.IdStr) //不创建已经存在的场景
for _, id := range createIds {
dbGame := srvdata.PBDB_GameFreeMgr.GetData(id)
if common.IsHundredType(dbGame.GetGameType()) {
gps := PlatformMgrSingleton.GetGameFree(platformData.IdStr, id)
if gps != nil && gps.Status {
if gps.GroupId != 0 {
if this.scenesOfGroup[gps.GroupId] != nil && this.scenesOfGroup[gps.GroupId][id] != nil {
continue
} else {
scene := this.CreateNewScene(dbGame.GetId(), gps.GroupId, limitPlatform, gps.DbGameFree)
if scene != nil {
this.scenesOfGroup[gps.GroupId][id] = scene
this.groupOfScene[int32(scene.sceneId)] = gps.GroupId
}
}
} else {
if this.scenesOfPlatform[platform] != nil && this.scenesOfPlatform[platform][dbGame.GetId()] != nil {
continue
} else {
scene := this.CreateNewScene(dbGame.GetId(), gps.GroupId, limitPlatform, gps.DbGameFree)
if scene != nil {
this.platformOfScene[int32(scene.sceneId)] = platform
this.scenesOfPlatform[platform][dbGame.GetId()] = scene
}
}
}
}
}
}
}
}
func (this *HundredSceneMgr) OnPlatformCreate(p *Platform) {
if p != nil && p.Isolated && p.IdStr != DefaultPlatform {
if _, exist := this.scenesOfPlatform[p.IdStr]; !exist {
this.scenesOfPlatform[p.IdStr] = make(map[int32]*Scene)
if model.GameParamData.HundredScenePreCreate {
arr := srvdata.PBDB_GameFreeMgr.Datas.GetArr()
for _, dbGame := range arr {
if common.IsHundredType(dbGame.GetGameType()) { //百人场
id := dbGame.GetId()
gps := PlatformMgrSingleton.GetGameFree(p.IdStr, id)
if gps != nil {
if gps.GroupId != 0 {
if ss, ok := this.scenesOfGroup[gps.GroupId]; ok {
if _, exist := ss[id]; !exist {
pgg := PlatformGameGroupMgrSington.GetGameGroup(gps.GroupId)
if pgg != nil {
scene := this.CreateNewScene(id, gps.GroupId, p, pgg.DbGameFree)
logger.Logger.Trace("(this *HundredSceneMgr) TryCreateRoom(group) ", id, gps.GroupId, scene)
if scene != nil {
ss[id] = scene
}
}
}
}
} else {
if ss, ok := this.scenesOfPlatform[p.IdStr]; ok {
if _, exist := ss[id]; !exist {
scene := this.CreateNewScene(id, gps.GroupId, p, gps.DbGameFree)
logger.Logger.Trace("(this *HundredSceneMgr) TryCreateRoom(platform) ", id, p.Name, scene)
if scene != nil {
ss[id] = scene
}
}
}
}
}
}
}
}
}
} }
} }
@ -377,12 +563,34 @@ func (this *HundredSceneMgr) OnPlatformDestroy(p *Platform) {
} }
} }
func (this *HundredSceneMgr) OnPlatformChangeIsolated(p *Platform, isolated bool) {
if p != nil {
if isolated { //孤立
this.OnPlatformCreate(p) //预创建场景
} else {
if ss, ok := this.scenesOfPlatform[p.IdStr]; ok {
var ids []int
for _, scene := range ss {
ids = append(ids, scene.sceneId)
}
SceneMgrSingleton.DoDelete(ids, true)
}
}
}
}
func (this *HundredSceneMgr) OnPlatformChangeDisabled(p *Platform, disabled bool) { func (this *HundredSceneMgr) OnPlatformChangeDisabled(p *Platform, disabled bool) {
if p == nil { if p == nil {
return return
} }
if disabled { if disabled {
this.OnPlatformDestroy(p) if ss, ok := this.scenesOfPlatform[p.IdStr]; ok {
var ids []int
for _, scene := range ss {
ids = append(ids, scene.sceneId)
}
SceneMgrSingleton.DoDelete(ids, true)
}
} }
} }
@ -390,6 +598,14 @@ func (this *HundredSceneMgr) OnPlatformGameFreeUpdate(p *Platform, oldCfg, newCf
if p == nil || newCfg == nil { if p == nil || newCfg == nil {
return return
} }
if oldCfg.GroupId != newCfg.GroupId || oldCfg.GroupId != 0 {
if scenes, exist := this.scenesOfGroup[oldCfg.GroupId]; exist {
if s, ok := scenes[newCfg.DbGameFree.Id]; ok {
s.DoDelete(false)
}
}
return
}
if scenes, exist := this.scenesOfPlatform[p.IdStr]; exist { if scenes, exist := this.scenesOfPlatform[p.IdStr]; exist {
if s, ok := scenes[newCfg.DbGameFree.Id]; ok { if s, ok := scenes[newCfg.DbGameFree.Id]; ok {
s.DoDelete(false) s.DoDelete(false)
@ -398,7 +614,99 @@ func (this *HundredSceneMgr) OnPlatformGameFreeUpdate(p *Platform, oldCfg, newCf
} }
func (this *HundredSceneMgr) OnGameGroupUpdate(oldCfg, newCfg *webapi.GameConfigGroup) { func (this *HundredSceneMgr) OnGameGroupUpdate(oldCfg, newCfg *webapi.GameConfigGroup) {
if newCfg == nil {
return
}
if scenes, exist := this.scenesOfGroup[newCfg.Id]; exist {
if s, ok := scenes[newCfg.DbGameFree.Id]; ok {
needDestroy := false
if s.dbGameFree.GetBot() != newCfg.DbGameFree.GetBot() ||
s.dbGameFree.GetBaseScore() != newCfg.DbGameFree.GetBaseScore() ||
s.dbGameFree.GetLimitCoin() != newCfg.DbGameFree.GetLimitCoin() ||
s.dbGameFree.GetMaxCoinLimit() != newCfg.DbGameFree.GetMaxCoinLimit() ||
!common.SliceInt64Equal(s.dbGameFree.GetRobotTakeCoin(), newCfg.DbGameFree.GetRobotTakeCoin()) ||
!common.SliceInt64Equal(s.dbGameFree.GetRobotLimitCoin(), newCfg.DbGameFree.GetRobotLimitCoin()) {
needDestroy = true
}
if needDestroy {
SceneMgrSingleton.DoDelete([]int{s.sceneId}, true)
}
}
}
}
func (this *HundredSceneMgr) GetPlatformSceneByGameFreeId(platform string, gameFreeIds []int32) []*Scene {
platformName := DefaultPlatform
platformData := PlatformMgrSingleton.GetPlatform(platform)
if platformData != nil && platformData.Isolated {
platformName = platformData.IdStr
} else if platform != DefaultPlatform {
platformData = PlatformMgrSingleton.GetPlatform(DefaultPlatform)
}
gameScenes := []*Scene{}
for _, id := range gameFreeIds {
gps := PlatformMgrSingleton.GetGameFree(platformData.IdStr, id)
if gps != nil {
if gps.GroupId != 0 {
if ss, exist := this.scenesOfGroup[gps.GroupId]; exist {
if s, exist := ss[id]; exist && s != nil {
gameScenes = append(gameScenes, s)
}
}
} else {
if ss, ok := this.scenesOfPlatform[platformName]; ok {
if s, exist := ss[id]; exist && s != nil {
gameScenes = append(gameScenes, s)
}
}
}
}
}
return gameScenes
}
func (this *HundredSceneMgr) GetPlatformScene(platform string, gameid int32) []*Scene {
gameFreeIds := gameStateMgr.gameIds[gameid]
gameScenes := this.GetPlatformSceneByGameFreeId(platform, gameFreeIds)
if len(gameScenes) != len(gameFreeIds) {
createIds := []int32{}
for _, gfi := range gameFreeIds {
bFind := false
for _, s := range gameScenes {
if s.dbGameFree.GetId() == gfi {
bFind = false
break
}
}
if !bFind {
createIds = append(createIds, gfi)
}
}
if len(createIds) > 0 {
this.PreCreateGame(platform, createIds)
gameScenes = this.GetPlatformSceneByGameFreeId(platform, gameFreeIds)
}
}
return gameScenes
}
func (this *HundredSceneMgr) ModuleName() string {
return "HundredSceneMgr"
}
func (this *HundredSceneMgr) Init() {
for _, platform := range PlatformMgrSingleton.GetPlatforms() {
if platform.Isolated || platform.IdStr == DefaultPlatform {
this.scenesOfPlatform[platform.IdStr] = make(map[int32]*Scene)
}
}
}
// 撮合
func (this *HundredSceneMgr) Update() {
}
func (this *HundredSceneMgr) Shutdown() {
module.UnregisteModule(this)
} }
func (this *HundredSceneMgr) OnPlatformDestroyByGameFreeId(p *Platform, gameFreeId int32) { func (this *HundredSceneMgr) OnPlatformDestroyByGameFreeId(p *Platform, gameFreeId int32) {
@ -415,9 +723,8 @@ func (this *HundredSceneMgr) OnPlatformDestroyByGameFreeId(p *Platform, gameFree
SceneMgrSingleton.DoDelete(ids, true) SceneMgrSingleton.DoDelete(ids, true)
} }
} }
func init() { func init() {
module.RegisteModule(HundredSceneMgrSingleton, time.Second*5, 0) module.RegisteModule(HundredSceneMgrSington, time.Second*5, 0)
PlatformMgrSingleton.RegisterObserver(HundredSceneMgrSingleton) PlatformMgrSingleton.RegisterObserver(HundredSceneMgrSington)
PlatformGameGroupMgrSington.RegisteObserver(HundredSceneMgrSingleton) PlatformGameGroupMgrSington.RegisteObserver(HundredSceneMgrSington)
} }

View File

@ -340,13 +340,6 @@ func (this *Player) OnLogined() {
this.RandRobotExData() this.RandRobotExData()
if !this.IsRob { if !this.IsRob {
if isFirstLogin {
cfg := PlatformMgrSingleton.GetConfig(this.Platform).GuideConfig
if cfg == nil || cfg.GetOn() != common.On {
this.GuideStep = -1
}
}
this.SendJackPotInit() this.SendJackPotInit()
this.GetPayGoodsInfo() this.GetPayGoodsInfo()
@ -3693,6 +3686,8 @@ func (this *Player) TryRetrieveLostGameCoin(sceneid int) {
logProbe.SeqNo = this.GameCoinTs logProbe.SeqNo = this.GameCoinTs
logProbe.RoomId = int32(sceneid) logProbe.RoomId = int32(sceneid)
LogChannelSingleton.WriteLog(logProbe) LogChannelSingleton.WriteLog(logProbe)
//先把玩家身上的钱清掉
//this.Coin = 0
this.SendDiffData() this.SendDiffData()
} }
@ -4953,9 +4948,6 @@ func (this *Player) SCGuide() {
func (this *Player) SCSpirit() { func (this *Player) SCSpirit() {
cfg := PlatformMgrSingleton.GetConfig(this.Platform).SpiritConfig cfg := PlatformMgrSingleton.GetConfig(this.Platform).SpiritConfig
if cfg == nil {
return
}
pack := &playerproto.SCDataConfig{ pack := &playerproto.SCDataConfig{
Cfg: []*playerproto.Config{ Cfg: []*playerproto.Config{
{ {

View File

@ -106,7 +106,6 @@ type Scene struct {
matchId int64 //比赛场id matchId int64 //比赛场id
csp *CoinScenePool // 所在场景池 csp *CoinScenePool // 所在场景池
hp *HundredSceneMgr // 百人场房间池
} }
// NewScene 创建房间 // NewScene 创建房间
@ -277,7 +276,8 @@ func (this *Scene) PlayerEnter(p *Player, pos int, ischangeroom bool) bool {
case this.IsCoinScene(): case this.IsCoinScene():
case this.IsHundredScene(): case this.IsHundredScene():
// todo 删除这个标记
HundredSceneMgrSington.OnPlayerEnter(p, this.paramsEx[0])
case this.IsMatchScene(): case this.IsMatchScene():
} }
@ -630,6 +630,7 @@ func (this *Scene) DelPlayer(p *Player) bool {
switch { switch {
case this.IsHundredScene(): case this.IsHundredScene():
HundredSceneMgrSington.OnPlayerLeave(p)
//case this.IsHallScene(): //case this.IsHallScene():
// PlatformMgrSingleton.OnPlayerLeaveScene(this, p) // PlatformMgrSingleton.OnPlayerLeaveScene(this, p)
// for i := 0; i < this.playerNum; i++ { // for i := 0; i < this.playerNum; i++ {
@ -663,7 +664,9 @@ func (this *Scene) AudienceEnter(p *Player, ischangeroom bool) bool {
p.scene = this p.scene = this
this.audiences[p.SnId] = p this.audiences[p.SnId] = p
this.gameSess.AddPlayer(p) this.gameSess.AddPlayer(p)
if this.IsHundredScene() {
HundredSceneMgrSington.OnPlayerEnter(p, this.paramsEx[0])
}
//todo:send add msg to gamesrv //todo:send add msg to gamesrv
data, err := p.MarshalData(this.gameId) data, err := p.MarshalData(this.gameId)
if err == nil { if err == nil {
@ -746,6 +749,9 @@ func (this *Scene) DelAudience(p *Player) bool {
} }
p.scene = nil p.scene = nil
SceneMgrSingleton.OnPlayerLeaveScene(this, p) SceneMgrSingleton.OnPlayerLeaveScene(this, p)
if this.IsHundredScene() {
HundredSceneMgrSington.OnPlayerLeave(p)
}
//from gameserver, so don't need send msg //from gameserver, so don't need send msg
return true return true
} }

View File

@ -37,14 +37,6 @@ type SceneMgr struct {
hundredSceneAutoId int // 百人场房间号 hundredSceneAutoId int // 百人场房间号
} }
func (m *SceneMgr) GetPlatformBySceneId(sceneId int) string {
s := m.GetScene(sceneId)
if s != nil && s.limitPlatform != nil {
return s.limitPlatform.IdStr
}
return ""
}
// AllocReplayCode 获取回访码 // AllocReplayCode 获取回访码
func (m *SceneMgr) AllocReplayCode() string { func (m *SceneMgr) AllocReplayCode() string {
code, _ := model.GetOneReplayId() code, _ := model.GetOneReplayId()
@ -324,7 +316,7 @@ func (m *SceneMgr) DestroyScene(sceneId int, isCompleted bool) {
CoinSceneMgrSingleton.OnDestroyScene(s.sceneId) CoinSceneMgrSingleton.OnDestroyScene(s.sceneId)
case s.IsHundredScene(): case s.IsHundredScene():
HundredSceneMgrSingleton.OnDestroyScene(s.sceneId) HundredSceneMgrSington.OnDestroyScene(s.sceneId)
case s.IsMatchScene(): case s.IsMatchScene():
MatchSceneMgrSingleton.OnDestroyScene(s.sceneId) MatchSceneMgrSingleton.OnDestroyScene(s.sceneId)

View File

@ -1765,7 +1765,7 @@ func (this *Tournament) Init() {
} }
ret, err := model.GetMatchAward(v.IdStr) ret, err := model.GetMatchAward(v.IdStr)
if err != nil { if err != nil {
logger.Logger.Warnf("GetMatchAward error %v", err) logger.Logger.Tracef("GetMatchAward error %v", err)
continue continue
} }
if this.MatchAwardNum == nil { if this.MatchAwardNum == nil {