review
This commit is contained in:
parent
159e69094f
commit
07150c660d
|
@ -23,6 +23,7 @@
|
|||
"ClosePreCreateRoom": true,
|
||||
"AgoraAddress": "http://47.105.78.29:8081",
|
||||
"InviteUrl": "http://47.105.78.29:8000/",
|
||||
"GuideTs": 1723790567,
|
||||
"RankTimeout": 2,
|
||||
"PermitInitScore": 0
|
||||
}
|
|
@ -574,9 +574,11 @@ func (this *CSEnterGameHandler) ProcessLocal(s *netlib.Session, packetid int, da
|
|||
|
||||
if len(params) != 0 {
|
||||
roomId = params[0]
|
||||
platformName := CoinSceneMgrSingleton.GetPlatformBySceneId(int(roomId))
|
||||
platformName := SceneMgrSingleton.GetPlatformBySceneId(int(roomId))
|
||||
if p.IsRob {
|
||||
p.Platform = platformName
|
||||
if platformName != "" {
|
||||
p.Platform = platformName
|
||||
}
|
||||
} else if p.GMLevel > 0 && p.Platform == platformName { //允许GM直接按房间ID进场
|
||||
roomId = params[0]
|
||||
}
|
||||
|
@ -672,13 +674,12 @@ func (this *CSEnterGameHandler) ProcessNormal(s *netlib.Session, packetid int, d
|
|||
case common.IsHundredType(gameType):
|
||||
if len(params) != 0 {
|
||||
roomId = params[0]
|
||||
name, ok := HundredSceneMgrSington.GetPlatformNameBySceneId(roomId)
|
||||
platform := SceneMgrSingleton.GetPlatformBySceneId(int(roomId))
|
||||
if p.IsRob {
|
||||
//机器人先伪装成对应平台的用户
|
||||
if ok {
|
||||
p.Platform = name
|
||||
if platform != "" {
|
||||
p.Platform = platform
|
||||
}
|
||||
} else if p.GMLevel > 0 && p.Platform == name { //允许GM直接按房间ID进场
|
||||
} else if p.GMLevel > 0 && p.Platform == platform { //允许GM直接按房间ID进场
|
||||
roomId = params[0]
|
||||
}
|
||||
}
|
||||
|
@ -691,7 +692,7 @@ func (this *CSEnterGameHandler) ProcessNormal(s *netlib.Session, packetid int, d
|
|||
}
|
||||
}
|
||||
}
|
||||
ret = gamehall.OpResultCode_Game(HundredSceneMgrSington.PlayerEnter(p, msg.GetId()))
|
||||
ret = gamehall.OpResultCode_Game(HundredSceneMgrSingleton.PlayerEnter(p, msg.GetId()))
|
||||
if p.scene != nil {
|
||||
pack.OpParams = append(pack.OpParams, msg.GetId())
|
||||
if ret != gamehall.OpResultCode_Game_OPRC_Sucess_Game {
|
||||
|
@ -703,9 +704,11 @@ func (this *CSEnterGameHandler) ProcessNormal(s *netlib.Session, packetid int, d
|
|||
case common.IsCoinSceneType(gameType):
|
||||
if len(params) != 0 {
|
||||
roomId = params[0]
|
||||
platformName := CoinSceneMgrSingleton.GetPlatformBySceneId(int(roomId))
|
||||
platformName := SceneMgrSingleton.GetPlatformBySceneId(int(roomId))
|
||||
if p.IsRob {
|
||||
p.Platform = platformName
|
||||
if platformName != "" {
|
||||
p.Platform = platformName
|
||||
}
|
||||
} else if p.GMLevel > 0 && p.Platform == platformName { //允许GM直接按房间ID进场
|
||||
roomId = params[0]
|
||||
}
|
||||
|
@ -763,7 +766,10 @@ func (this *CSQuitGameHandler) Process(s *netlib.Session, packetid int, data int
|
|||
dbGameFree := srvdata.PBDB_GameFreeMgr.GetData(msg.GetId())
|
||||
gameType := dbGameFree.GetGameType()
|
||||
if common.IsHundredType(gameType) {
|
||||
ret = gamehall.OpResultCode_Game(HundredSceneMgrSington.PlayerTryLeave(p))
|
||||
ret = gamehall.OpResultCode_Game(HundredSceneMgrSingleton.PlayerTryLeave(p))
|
||||
if gamehall.OpResultCode_Game_OPRC_OpYield_Game == ret {
|
||||
return nil
|
||||
}
|
||||
} else if common.IsCoinSceneType(gameType) {
|
||||
ret = gamehall.OpResultCode_Game(CoinSceneMgrSingleton.PlayerTryLeave(p, msg.IsAudience))
|
||||
if gamehall.OpResultCode_Game_OPRC_OpYield_Game == ret {
|
||||
|
@ -945,7 +951,7 @@ func (this *CSCreateRoomHandler) ProcessLocalGame(s *netlib.Session, packetid in
|
|||
goto failed
|
||||
}
|
||||
scene, code = p.CreateLocalGameScene(roomId, int(gameId), int(gameSite), int(msg.GetSceneMode()), maxPlayerNum,
|
||||
params, dbGameFree, baseScore, csp.groupId)
|
||||
params, dbGameFree, baseScore, 0)
|
||||
if scene != nil && code == gamehall.OpResultCode_Game_OPRC_Sucess_Game {
|
||||
logger.Logger.Tracef("CSCreateRoomHandler SnId:%v Create Sucess GameId:%v", p.SnId, gameId)
|
||||
csp.AddScene(scene)
|
||||
|
@ -1049,7 +1055,7 @@ func (this *CSCreateRoomHandler) ProcessThirteen(s *netlib.Session, packetid int
|
|||
goto failed
|
||||
}
|
||||
scene, code = p.CreateLocalGameScene(roomId, int(gameId), int(dbGameFree.GetSceneType()), int(msg.GetSceneMode()),
|
||||
maxPlayerNum, params, dbGameFree, baseScore, csp.groupId)
|
||||
maxPlayerNum, params, dbGameFree, baseScore, 0)
|
||||
if scene != nil {
|
||||
if code == gamehall.OpResultCode_Game_OPRC_Sucess_Game {
|
||||
logger.Logger.Tracef("CSCreateRoomHandler SnId:%v Create Sucess GameId:%v", p.SnId, gameId)
|
||||
|
|
|
@ -2,13 +2,15 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"mongo.games.com/goserver/core/logger"
|
||||
"mongo.games.com/goserver/core/netlib"
|
||||
|
||||
"mongo.games.com/game/common"
|
||||
"mongo.games.com/game/proto"
|
||||
"mongo.games.com/game/protocol/gamehall"
|
||||
"mongo.games.com/game/srvdata"
|
||||
"mongo.games.com/goserver/core/logger"
|
||||
"mongo.games.com/goserver/core/netlib"
|
||||
"time"
|
||||
)
|
||||
|
||||
type CSHundredSceneGetPlayerNumPacketFactory struct {
|
||||
|
@ -26,7 +28,7 @@ func (this *CSHundredSceneGetPlayerNumHandler) Process(s *netlib.Session, packet
|
|||
if msg, ok := data.(*gamehall.CSHundredSceneGetPlayerNum); ok {
|
||||
p := PlayerMgrSington.GetPlayer(sid)
|
||||
if p != nil {
|
||||
nums := HundredSceneMgrSington.GetPlayerNums(p, msg.GetGameId(), msg.GetGameModel())
|
||||
nums := HundredSceneMgrSingleton.GetPlayerNums(p, msg.GetGameId(), msg.GetGameModel())
|
||||
pack := &gamehall.SCHundredSceneGetPlayerNum{
|
||||
Nums: nums,
|
||||
}
|
||||
|
@ -61,7 +63,7 @@ func (this *CSHundredSceneOpHandler) Process(s *netlib.Session, packetid int, da
|
|||
}
|
||||
oldPlatform := p.Platform
|
||||
switch msg.GetOpType() {
|
||||
case HundredSceneOp_Enter:
|
||||
case HundredSceneOPEnter:
|
||||
//pt := PlatformMgrSingleton.GetPackageTag(p.PackageID)
|
||||
//if pt != nil && pt.IsForceBind == 1 {
|
||||
// if p.BeUnderAgentCode == "" || p.BeUnderAgentCode == "0" {
|
||||
|
@ -80,13 +82,13 @@ func (this *CSHundredSceneOpHandler) Process(s *netlib.Session, packetid int, da
|
|||
params := msg.GetOpParams()
|
||||
if len(params) != 0 {
|
||||
roomId = params[0]
|
||||
name, ok := HundredSceneMgrSington.GetPlatformNameBySceneId(roomId)
|
||||
platform := SceneMgrSingleton.GetPlatformBySceneId(int(roomId))
|
||||
if p.IsRob {
|
||||
//机器人先伪装成对应平台的用户
|
||||
if ok {
|
||||
p.Platform = name
|
||||
if platform != "" {
|
||||
p.Platform = platform
|
||||
}
|
||||
} else if p.GMLevel > 0 && p.Platform == name { //允许GM直接按房间ID进场
|
||||
} else if p.GMLevel > 0 && p.Platform == platform { //允许GM直接按房间ID进场
|
||||
roomId = params[0]
|
||||
}
|
||||
}
|
||||
|
@ -153,7 +155,7 @@ func (this *CSHundredSceneOpHandler) Process(s *netlib.Session, packetid int, da
|
|||
}
|
||||
}
|
||||
|
||||
ret = HundredSceneMgrSington.PlayerEnter(p, msg.GetId())
|
||||
ret = HundredSceneMgrSingleton.PlayerEnter(p, msg.GetId())
|
||||
if p.scene != nil {
|
||||
pack.OpParams = append(pack.OpParams, msg.GetId())
|
||||
//TODO 有房间还进入失败,尝试returnroom
|
||||
|
@ -162,9 +164,9 @@ func (this *CSHundredSceneOpHandler) Process(s *netlib.Session, packetid int, da
|
|||
return nil
|
||||
}
|
||||
}
|
||||
case HundredSceneOp_Leave:
|
||||
ret = HundredSceneMgrSington.PlayerTryLeave(p)
|
||||
case HundredSceneOp_Change:
|
||||
case HundredSceneOPLeave:
|
||||
ret = HundredSceneMgrSingleton.PlayerTryLeave(p)
|
||||
case HundredSceneOPChange:
|
||||
/*var exclude int32
|
||||
if p.scene != nil {
|
||||
exclude = int32(p.scene.sceneId)
|
||||
|
@ -173,10 +175,10 @@ func (this *CSHundredSceneOpHandler) Process(s *netlib.Session, packetid int, da
|
|||
if len(params) != 0 {
|
||||
exclude = params[0]
|
||||
}
|
||||
if HundredSceneMgrSington.PlayerInChanging(p) { //换桌中
|
||||
if HundredSceneMgrSingleton.PlayerInChanging(p) { //换桌中
|
||||
return nil
|
||||
}
|
||||
ret = HundredSceneMgrSington.PlayerTryChange(p, msg.GetId(), exclude)*/
|
||||
ret = HundredSceneMgrSingleton.PlayerTryChange(p, msg.GetId(), exclude)*/
|
||||
}
|
||||
done:
|
||||
//机器人要避免身上的平台标记被污染
|
||||
|
@ -218,7 +220,7 @@ func (this *CSGameObserveHandler) Process(s *netlib.Session, packetid int, data
|
|||
gameStateMgr.PlayerRegiste(p, msg.GetGameId(), msg.GetStartOrEnd())
|
||||
pack := &gamehall.SCGameSubList{}
|
||||
statePack := &gamehall.SCGameState{}
|
||||
scenes := HundredSceneMgrSington.GetPlatformScene(p.Platform, msg.GetGameId())
|
||||
scenes := HundredSceneMgrSingleton.GetPlatformScene(p.Platform, msg.GetGameId())
|
||||
for _, value := range scenes {
|
||||
pack.List = append(pack.List, &gamehall.GameSubRecord{
|
||||
GameFreeId: proto.Int32(value.dbGameFree.GetId()),
|
||||
|
@ -269,7 +271,7 @@ func (this *CSGameObserveHandler) Process(s *netlib.Session, packetid int, data
|
|||
// // gameid == common.GameId_Avengers || gameid == common.GameId_EasterIsland {
|
||||
// // gameStateMgr.PlayerRegiste(p, msg.GetGameId(), true)
|
||||
// // pack := &gamehall.SCHundredSceneGetGameJackpot{}
|
||||
// // scenes := HundredSceneMgrSington.GetPlatformScene(p.Platform, msg.GetGameId())
|
||||
// // scenes := HundredSceneMgrSingleton.GetPlatformScene(p.Platform, msg.GetGameId())
|
||||
// // for _, v := range scenes {
|
||||
// // jpfi := &gamehall.GameJackpotFundInfo{
|
||||
// // GameFreeId: proto.Int32(v.dbGameFree.GetId()),
|
||||
|
|
|
@ -13,32 +13,32 @@ import (
|
|||
"mongo.games.com/game/common"
|
||||
"mongo.games.com/game/model"
|
||||
"mongo.games.com/game/proto"
|
||||
gamehall_proto "mongo.games.com/game/protocol/gamehall"
|
||||
login_proto "mongo.games.com/game/protocol/login"
|
||||
player_proto "mongo.games.com/game/protocol/player"
|
||||
server_proto "mongo.games.com/game/protocol/server"
|
||||
gamehallproto "mongo.games.com/game/protocol/gamehall"
|
||||
loginproto "mongo.games.com/game/protocol/login"
|
||||
playerproto "mongo.games.com/game/protocol/player"
|
||||
serverproto "mongo.games.com/game/protocol/server"
|
||||
"mongo.games.com/game/srvdata"
|
||||
)
|
||||
|
||||
func init() {
|
||||
// 销毁房间
|
||||
netlib.RegisterFactory(int(server_proto.SSPacketID_PACKET_GW_DESTROYSCENE), netlib.PacketFactoryWrapper(func() interface{} {
|
||||
return &server_proto.GWDestroyScene{}
|
||||
netlib.RegisterFactory(int(serverproto.SSPacketID_PACKET_GW_DESTROYSCENE), netlib.PacketFactoryWrapper(func() interface{} {
|
||||
return &serverproto.GWDestroyScene{}
|
||||
}))
|
||||
netlib.RegisterHandler(int(server_proto.SSPacketID_PACKET_GW_DESTROYSCENE), netlib.HandlerWrapper(func(s *netlib.Session, packetid int, pack interface{}) error {
|
||||
netlib.RegisterHandler(int(serverproto.SSPacketID_PACKET_GW_DESTROYSCENE), netlib.HandlerWrapper(func(s *netlib.Session, packetid int, pack interface{}) error {
|
||||
logger.Logger.Trace("receive GWDestroyScene:", pack)
|
||||
if msg, ok := pack.(*server_proto.GWDestroyScene); ok {
|
||||
if msg, ok := pack.(*serverproto.GWDestroyScene); ok {
|
||||
SceneMgrSingleton.DestroyScene(int(msg.GetSceneId()), msg.GetIsCompleted())
|
||||
}
|
||||
return nil
|
||||
}))
|
||||
|
||||
// 离开房间
|
||||
netlib.RegisterFactory(int(server_proto.SSPacketID_PACKET_GW_PLAYERLEAVE), netlib.PacketFactoryWrapper(func() interface{} {
|
||||
return &server_proto.GWPlayerLeave{}
|
||||
netlib.RegisterFactory(int(serverproto.SSPacketID_PACKET_GW_PLAYERLEAVE), netlib.PacketFactoryWrapper(func() interface{} {
|
||||
return &serverproto.GWPlayerLeave{}
|
||||
}))
|
||||
netlib.RegisterHandler(int(server_proto.SSPacketID_PACKET_GW_PLAYERLEAVE), netlib.HandlerWrapper(func(s *netlib.Session, packetid int, pack interface{}) error {
|
||||
if msg, ok := pack.(*server_proto.GWPlayerLeave); ok {
|
||||
netlib.RegisterHandler(int(serverproto.SSPacketID_PACKET_GW_PLAYERLEAVE), netlib.HandlerWrapper(func(s *netlib.Session, packetid int, pack interface{}) error {
|
||||
if msg, ok := pack.(*serverproto.GWPlayerLeave); ok {
|
||||
logger.Logger.Trace("receive GWPlayerLeave:", msg.GetPlayerId())
|
||||
scene := SceneMgrSingleton.GetScene(int(msg.GetRoomId()))
|
||||
if scene != nil {
|
||||
|
@ -68,7 +68,7 @@ func init() {
|
|||
}
|
||||
}
|
||||
case scene.IsHundredScene():
|
||||
if !HundredSceneMgrSington.PlayerLeave(p, int(msg.GetReason())) {
|
||||
if !HundredSceneMgrSingleton.PlayerLeave(p, int(msg.GetReason())) {
|
||||
logger.Logger.Warnf("GWPlayerLeave snid:%v sceneid:%v gameid:%v modeid:%v [hundredcene]",
|
||||
p.SnId, scene.sceneId, scene.gameId, scene.gameMode)
|
||||
}
|
||||
|
@ -228,12 +228,12 @@ func init() {
|
|||
}))
|
||||
|
||||
// 观众离开房间
|
||||
netlib.RegisterFactory(int(server_proto.SSPacketID_PACKET_GW_AUDIENCELEAVE), netlib.PacketFactoryWrapper(func() interface{} {
|
||||
return &server_proto.GWPlayerLeave{}
|
||||
netlib.RegisterFactory(int(serverproto.SSPacketID_PACKET_GW_AUDIENCELEAVE), netlib.PacketFactoryWrapper(func() interface{} {
|
||||
return &serverproto.GWPlayerLeave{}
|
||||
}))
|
||||
netlib.RegisterHandler(int(server_proto.SSPacketID_PACKET_GW_AUDIENCELEAVE), netlib.HandlerWrapper(func(s *netlib.Session, packetid int, pack interface{}) error {
|
||||
netlib.RegisterHandler(int(serverproto.SSPacketID_PACKET_GW_AUDIENCELEAVE), netlib.HandlerWrapper(func(s *netlib.Session, packetid int, pack interface{}) error {
|
||||
logger.Logger.Trace("receive PACKET_GW_AUDIENCELEAVE GWPlayerLeave:", pack)
|
||||
if msg, ok := pack.(*server_proto.GWPlayerLeave); ok {
|
||||
if msg, ok := pack.(*serverproto.GWPlayerLeave); ok {
|
||||
scene := SceneMgrSingleton.GetScene(int(msg.GetRoomId()))
|
||||
if scene != nil {
|
||||
p := PlayerMgrSington.GetPlayerBySnId(msg.GetPlayerId())
|
||||
|
@ -270,12 +270,12 @@ func init() {
|
|||
}))
|
||||
|
||||
// 房间游戏开始
|
||||
netlib.RegisterFactory(int(server_proto.SSPacketID_PACKET_GW_SCENESTART), netlib.PacketFactoryWrapper(func() interface{} {
|
||||
return &server_proto.GWSceneStart{}
|
||||
netlib.RegisterFactory(int(serverproto.SSPacketID_PACKET_GW_SCENESTART), netlib.PacketFactoryWrapper(func() interface{} {
|
||||
return &serverproto.GWSceneStart{}
|
||||
}))
|
||||
netlib.RegisterHandler(int(server_proto.SSPacketID_PACKET_GW_SCENESTART), netlib.HandlerWrapper(func(s *netlib.Session, packetid int, pack interface{}) error {
|
||||
netlib.RegisterHandler(int(serverproto.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)
|
||||
if msg, ok := pack.(*server_proto.GWSceneStart); ok {
|
||||
if msg, ok := pack.(*serverproto.GWSceneStart); ok {
|
||||
scene := SceneMgrSingleton.GetScene(int(msg.GetRoomId()))
|
||||
if scene != nil {
|
||||
scene.starting = msg.GetStart()
|
||||
|
@ -299,12 +299,12 @@ func init() {
|
|||
|
||||
// 房间游戏状态
|
||||
// 捕鱼
|
||||
netlib.RegisterFactory(int(server_proto.SSPacketID_PACKET_GW_SCENESTATE), netlib.PacketFactoryWrapper(func() interface{} {
|
||||
return &server_proto.GWSceneState{}
|
||||
netlib.RegisterFactory(int(serverproto.SSPacketID_PACKET_GW_SCENESTATE), netlib.PacketFactoryWrapper(func() interface{} {
|
||||
return &serverproto.GWSceneState{}
|
||||
}))
|
||||
netlib.RegisterHandler(int(server_proto.SSPacketID_PACKET_GW_SCENESTATE), netlib.HandlerWrapper(func(s *netlib.Session, packetid int, pack interface{}) error {
|
||||
netlib.RegisterHandler(int(serverproto.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)
|
||||
if msg, ok := pack.(*server_proto.GWSceneState); ok {
|
||||
if msg, ok := pack.(*serverproto.GWSceneState); ok {
|
||||
scene := SceneMgrSingleton.GetScene(int(msg.GetRoomId()))
|
||||
if scene != nil {
|
||||
scene.state = msg.GetCurrState()
|
||||
|
@ -315,12 +315,12 @@ func init() {
|
|||
}))
|
||||
|
||||
// 用户状态同步 flag
|
||||
netlib.RegisterFactory(int(server_proto.SSPacketID_PACKET_GW_PLAYERSTATE), netlib.PacketFactoryWrapper(func() interface{} {
|
||||
return &server_proto.GWPlayerFlag{}
|
||||
netlib.RegisterFactory(int(serverproto.SSPacketID_PACKET_GW_PLAYERSTATE), netlib.PacketFactoryWrapper(func() interface{} {
|
||||
return &serverproto.GWPlayerFlag{}
|
||||
}))
|
||||
netlib.RegisterHandler(int(server_proto.SSPacketID_PACKET_GW_PLAYERSTATE), netlib.HandlerWrapper(func(s *netlib.Session, packetid int, pack interface{}) error {
|
||||
netlib.RegisterHandler(int(serverproto.SSPacketID_PACKET_GW_PLAYERSTATE), netlib.HandlerWrapper(func(s *netlib.Session, packetid int, pack interface{}) error {
|
||||
logger.Logger.Trace("receive GWPlayerFlag:", pack)
|
||||
if msg, ok := pack.(*server_proto.GWPlayerFlag); ok {
|
||||
if msg, ok := pack.(*serverproto.GWPlayerFlag); ok {
|
||||
player := PlayerMgrSington.GetPlayerBySnId(msg.GetSnId())
|
||||
if player != nil {
|
||||
player.flag = msg.GetFlag()
|
||||
|
@ -330,12 +330,12 @@ func init() {
|
|||
}))
|
||||
|
||||
// 房间服务器状态切换
|
||||
netlib.RegisterFactory(int(server_proto.SSPacketID_PACKET_GB_STATE_SWITCH), netlib.PacketFactoryWrapper(func() interface{} {
|
||||
return &server_proto.ServerStateSwitch{}
|
||||
netlib.RegisterFactory(int(serverproto.SSPacketID_PACKET_GB_STATE_SWITCH), netlib.PacketFactoryWrapper(func() interface{} {
|
||||
return &serverproto.ServerStateSwitch{}
|
||||
}))
|
||||
netlib.RegisterHandler(int(server_proto.SSPacketID_PACKET_GB_STATE_SWITCH), netlib.HandlerWrapper(func(s *netlib.Session, packetid int, pack interface{}) error {
|
||||
netlib.RegisterHandler(int(serverproto.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)
|
||||
if sr, ok := pack.(*server_proto.ServerStateSwitch); ok {
|
||||
if sr, ok := pack.(*serverproto.ServerStateSwitch); ok {
|
||||
srvid := int(sr.GetSrvId())
|
||||
gameSess := GameSessMgrSington.GetGameSess(srvid)
|
||||
if gameSess != nil {
|
||||
|
@ -360,13 +360,13 @@ func init() {
|
|||
|
||||
// 游戏服务器的系统广播
|
||||
// 捕鱼
|
||||
netlib.RegisterFactory(int(server_proto.SSPacketID_PACKET_GW_NEWNOTICE), netlib.PacketFactoryWrapper(func() interface{} {
|
||||
return &server_proto.GWNewNotice{}
|
||||
netlib.RegisterFactory(int(serverproto.SSPacketID_PACKET_GW_NEWNOTICE), netlib.PacketFactoryWrapper(func() interface{} {
|
||||
return &serverproto.GWNewNotice{}
|
||||
}))
|
||||
netlib.RegisterHandler(int(server_proto.SSPacketID_PACKET_GW_NEWNOTICE), netlib.HandlerWrapper(func(s *netlib.Session,
|
||||
netlib.RegisterHandler(int(serverproto.SSPacketID_PACKET_GW_NEWNOTICE), netlib.HandlerWrapper(func(s *netlib.Session,
|
||||
packetid int, pack interface{}) error {
|
||||
logger.Logger.Trace("receive GWNewNotice:", pack)
|
||||
if msg, ok := pack.(*server_proto.GWNewNotice); ok {
|
||||
if msg, ok := pack.(*serverproto.GWNewNotice); ok {
|
||||
//立即发送改为定期发送,控制下广播包的频度
|
||||
HorseRaceLampMgrSington.PushGameHorseRaceLamp(msg.GetCh(), msg.GetPlatform(), msg.GetContent(), int32(msg.GetMsgtype()), msg.GetIsrob(), msg.GetPriority())
|
||||
}
|
||||
|
@ -374,13 +374,13 @@ func init() {
|
|||
}))
|
||||
|
||||
// 同步每局游戏那些玩家一起玩的
|
||||
netlib.RegisterFactory(int(server_proto.SSPacketID_PACKET_GW_SCENEPLAYERLOG), netlib.PacketFactoryWrapper(func() interface{} {
|
||||
return &server_proto.GWScenePlayerLog{}
|
||||
netlib.RegisterFactory(int(serverproto.SSPacketID_PACKET_GW_SCENEPLAYERLOG), netlib.PacketFactoryWrapper(func() interface{} {
|
||||
return &serverproto.GWScenePlayerLog{}
|
||||
}))
|
||||
netlib.RegisterHandler(int(server_proto.SSPacketID_PACKET_GW_SCENEPLAYERLOG), netlib.HandlerWrapper(func(s *netlib.Session,
|
||||
netlib.RegisterHandler(int(serverproto.SSPacketID_PACKET_GW_SCENEPLAYERLOG), netlib.HandlerWrapper(func(s *netlib.Session,
|
||||
packetid int, pack interface{}) error {
|
||||
logger.Logger.Trace("receive GWScenePlayerLog:", pack)
|
||||
if msg, ok := pack.(*server_proto.GWScenePlayerLog); ok {
|
||||
if msg, ok := pack.(*serverproto.GWScenePlayerLog); ok {
|
||||
sceneLimitMgr.ReceiveData(msg.GetGameId(), msg.GetSnids())
|
||||
}
|
||||
return nil
|
||||
|
@ -388,11 +388,11 @@ func init() {
|
|||
|
||||
// 强制离开房间
|
||||
// 返回房间失败
|
||||
netlib.RegisterFactory(int(server_proto.SSPacketID_PACKET_GW_PLAYERFORCELEAVE), netlib.PacketFactoryWrapper(func() interface{} {
|
||||
return &server_proto.GWPlayerForceLeave{}
|
||||
netlib.RegisterFactory(int(serverproto.SSPacketID_PACKET_GW_PLAYERFORCELEAVE), netlib.PacketFactoryWrapper(func() interface{} {
|
||||
return &serverproto.GWPlayerForceLeave{}
|
||||
}))
|
||||
netlib.RegisterHandler(int(server_proto.SSPacketID_PACKET_GW_PLAYERFORCELEAVE), netlib.HandlerWrapper(func(s *netlib.Session, packetid int, pack interface{}) error {
|
||||
if msg, ok := pack.(*server_proto.GWPlayerForceLeave); ok {
|
||||
netlib.RegisterHandler(int(serverproto.SSPacketID_PACKET_GW_PLAYERFORCELEAVE), netlib.HandlerWrapper(func(s *netlib.Session, packetid int, pack interface{}) error {
|
||||
if msg, ok := pack.(*serverproto.GWPlayerForceLeave); ok {
|
||||
logger.Logger.Warn("receive GWPlayerForceLeave:", msg)
|
||||
scene := SceneMgrSingleton.GetScene(int(msg.GetRoomId()))
|
||||
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)
|
||||
}
|
||||
case scene.IsHundredScene():
|
||||
if !HundredSceneMgrSington.PlayerLeave(p, int(msg.GetReason())) {
|
||||
if !HundredSceneMgrSingleton.PlayerLeave(p, int(msg.GetReason())) {
|
||||
logger.Logger.Warnf("GWPlayerForceLeave snid:%v sceneid:%v gameid:%v modeid:%v [hundredcene]", p.SnId, scene.sceneId, scene.gameId, scene.gameMode)
|
||||
}
|
||||
case scene.IsMatchScene():
|
||||
|
@ -438,12 +438,12 @@ func init() {
|
|||
//1.同步玩家游戏场内的实时金币
|
||||
//2.触发相关任务:统计有效下注金币数,赢取金币数,牌局次数等
|
||||
//3.黑名单处理
|
||||
netlib.RegisterFactory(int(server_proto.SSPacketID_PACKET_GW_PLAYERDATA), netlib.PacketFactoryWrapper(func() interface{} {
|
||||
return &server_proto.GWPlayerData{}
|
||||
netlib.RegisterFactory(int(serverproto.SSPacketID_PACKET_GW_PLAYERDATA), netlib.PacketFactoryWrapper(func() interface{} {
|
||||
return &serverproto.GWPlayerData{}
|
||||
}))
|
||||
netlib.RegisterHandler(int(server_proto.SSPacketID_PACKET_GW_PLAYERDATA), netlib.HandlerWrapper(func(s *netlib.Session, packetid int, pack interface{}) error {
|
||||
netlib.RegisterHandler(int(serverproto.SSPacketID_PACKET_GW_PLAYERDATA), netlib.HandlerWrapper(func(s *netlib.Session, packetid int, pack interface{}) error {
|
||||
logger.Logger.Trace("receive GWPlayerBet:", pack)
|
||||
if msg, ok := pack.(*server_proto.GWPlayerData); ok {
|
||||
if msg, ok := pack.(*serverproto.GWPlayerData); ok {
|
||||
scene := SceneMgrSingleton.GetScene(int(msg.GetSceneId()))
|
||||
if scene == nil {
|
||||
return nil
|
||||
|
@ -573,13 +573,13 @@ func init() {
|
|||
}))
|
||||
|
||||
//推送游戏的状态
|
||||
netlib.RegisterFactory(int(server_proto.SSPacketID_PACKET_GW_GAMESTATE), netlib.PacketFactoryWrapper(func() interface{} {
|
||||
return &server_proto.GWGameState{}
|
||||
netlib.RegisterFactory(int(serverproto.SSPacketID_PACKET_GW_GAMESTATE), netlib.PacketFactoryWrapper(func() interface{} {
|
||||
return &serverproto.GWGameState{}
|
||||
}))
|
||||
netlib.RegisterHandler(int(server_proto.SSPacketID_PACKET_GW_GAMESTATE), netlib.HandlerWrapper(func(s *netlib.Session,
|
||||
netlib.RegisterHandler(int(serverproto.SSPacketID_PACKET_GW_GAMESTATE), netlib.HandlerWrapper(func(s *netlib.Session,
|
||||
packetid int, pack interface{}) error {
|
||||
logger.Logger.Trace("receive SSPacketID_PACKET_GW_GAMESTATE GWGameState:", pack)
|
||||
if msg, ok := pack.(*server_proto.GWGameState); ok {
|
||||
if msg, ok := pack.(*serverproto.GWGameState); ok {
|
||||
scene := SceneMgrSingleton.GetScene(int(msg.GetSceneId()))
|
||||
if scene != nil {
|
||||
scene.State = msg.GetState()
|
||||
|
@ -591,38 +591,38 @@ func init() {
|
|||
if leftTime < 0 {
|
||||
leftTime = 0
|
||||
}
|
||||
pack := &gamehall_proto.SCGameState{}
|
||||
pack.List = append(pack.List, &gamehall_proto.GameState{
|
||||
pack := &gamehallproto.SCGameState{}
|
||||
pack.List = append(pack.List, &gamehallproto.GameState{
|
||||
GameFreeId: proto.Int32(scene.dbGameFree.GetId()),
|
||||
Ts: proto.Int64(leftTime),
|
||||
Sec: proto.Int32(scene.StateSec),
|
||||
})
|
||||
gameStateMgr.BrodcastGameState(int32(scene.gameId), scene.limitPlatform.IdStr,
|
||||
int(gamehall_proto.GameHallPacketID_PACKET_SC_GAMESTATE), pack)
|
||||
int(gamehallproto.GameHallPacketID_PACKET_SC_GAMESTATE), pack)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}))
|
||||
|
||||
netlib.RegisterFactory(int(server_proto.SSPacketID_PACKET_GW_JACKPOTLIST), netlib.PacketFactoryWrapper(func() interface{} {
|
||||
return &server_proto.GWGameJackList{}
|
||||
netlib.RegisterFactory(int(serverproto.SSPacketID_PACKET_GW_JACKPOTLIST), netlib.PacketFactoryWrapper(func() interface{} {
|
||||
return &serverproto.GWGameJackList{}
|
||||
}))
|
||||
netlib.RegisterHandler(int(server_proto.SSPacketID_PACKET_GW_JACKPOTLIST), netlib.HandlerWrapper(func(s *netlib.Session, packetid int, pack interface{}) error {
|
||||
netlib.RegisterHandler(int(serverproto.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)
|
||||
if msg, ok := pack.(*server_proto.GWGameJackList); ok {
|
||||
if msg, ok := pack.(*serverproto.GWGameJackList); ok {
|
||||
FishJackListMgr.Insert(msg.GetCoin(), msg.GetSnId(), msg.GetRoomId(), msg.GetJackType(), msg.GetGameId(),
|
||||
msg.GetPlatform(), msg.GetChannel(), msg.GetName())
|
||||
}
|
||||
return nil
|
||||
}))
|
||||
|
||||
netlib.RegisterFactory(int(server_proto.SSPacketID_PACKET_GW_JACKPOTCOIN), netlib.PacketFactoryWrapper(func() interface{} {
|
||||
return &server_proto.GWGameJackCoin{}
|
||||
netlib.RegisterFactory(int(serverproto.SSPacketID_PACKET_GW_JACKPOTCOIN), netlib.PacketFactoryWrapper(func() interface{} {
|
||||
return &serverproto.GWGameJackCoin{}
|
||||
}))
|
||||
netlib.RegisterHandler(int(server_proto.SSPacketID_PACKET_GW_JACKPOTCOIN), netlib.HandlerWrapper(func(s *netlib.Session, packetid int, pack interface{}) error {
|
||||
netlib.RegisterHandler(int(serverproto.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)
|
||||
if msg, ok := pack.(*server_proto.GWGameJackCoin); ok {
|
||||
if msg, ok := pack.(*serverproto.GWGameJackCoin); ok {
|
||||
for i, pl := range msg.Platform {
|
||||
FishJackpotCoinMgr.Jackpot[pl] = msg.Coin[i]
|
||||
}
|
||||
|
@ -631,12 +631,12 @@ func init() {
|
|||
}))
|
||||
|
||||
//强制换桌
|
||||
netlib.RegisterFactory(int(server_proto.SSPacketID_PACKET_GW_CHANGESCENEEVENT), netlib.PacketFactoryWrapper(func() interface{} {
|
||||
return &server_proto.GWChangeSceneEvent{}
|
||||
netlib.RegisterFactory(int(serverproto.SSPacketID_PACKET_GW_CHANGESCENEEVENT), netlib.PacketFactoryWrapper(func() interface{} {
|
||||
return &serverproto.GWChangeSceneEvent{}
|
||||
}))
|
||||
netlib.RegisterHandler(int(server_proto.SSPacketID_PACKET_GW_CHANGESCENEEVENT), netlib.HandlerWrapper(func(s *netlib.Session, packetid int, pack interface{}) error {
|
||||
netlib.RegisterHandler(int(serverproto.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)
|
||||
if msg, ok := pack.(*server_proto.GWChangeSceneEvent); ok {
|
||||
if msg, ok := pack.(*serverproto.GWChangeSceneEvent); ok {
|
||||
scene := SceneMgrSingleton.GetScene(int(msg.GetSceneId()))
|
||||
if scene != nil {
|
||||
scene.PlayerTryChange()
|
||||
|
@ -646,13 +646,13 @@ func init() {
|
|||
}))
|
||||
|
||||
//玩家中转消息
|
||||
netlib.RegisterFactory(int(server_proto.SSPacketID_PACKET_SS_REDIRECTTOPLAYER), netlib.PacketFactoryWrapper(func() interface{} {
|
||||
return &server_proto.SSRedirectToPlayer{}
|
||||
netlib.RegisterFactory(int(serverproto.SSPacketID_PACKET_SS_REDIRECTTOPLAYER), netlib.PacketFactoryWrapper(func() interface{} {
|
||||
return &serverproto.SSRedirectToPlayer{}
|
||||
}))
|
||||
netlib.RegisterHandler(int(server_proto.SSPacketID_PACKET_SS_REDIRECTTOPLAYER), netlib.HandlerWrapper(func(s *netlib.Session,
|
||||
netlib.RegisterHandler(int(serverproto.SSPacketID_PACKET_SS_REDIRECTTOPLAYER), netlib.HandlerWrapper(func(s *netlib.Session,
|
||||
packetid int, pack interface{}) error {
|
||||
logger.Logger.Trace("SSRedirectToPlayer Process recv ", pack)
|
||||
if msg, ok := pack.(*server_proto.SSRedirectToPlayer); ok {
|
||||
if msg, ok := pack.(*serverproto.SSRedirectToPlayer); ok {
|
||||
p := PlayerMgrSington.GetPlayerBySnId(msg.GetSnId())
|
||||
if p == nil {
|
||||
return nil
|
||||
|
@ -670,13 +670,13 @@ type CSPMCmdHandler struct {
|
|||
}
|
||||
|
||||
func (this *CSPMCmdPacketFactory) CreatePacket() interface{} {
|
||||
pack := &player_proto.CSPMCmd{}
|
||||
pack := &playerproto.CSPMCmd{}
|
||||
return pack
|
||||
}
|
||||
|
||||
func (this *CSPMCmdHandler) Process(s *netlib.Session, packetid int, data interface{}, sid int64) error {
|
||||
logger.Logger.Trace("CSPMCmdHandler Process recv ", data)
|
||||
if msg, ok := data.(*player_proto.CSPMCmd); ok {
|
||||
if msg, ok := data.(*playerproto.CSPMCmd); ok {
|
||||
p := PlayerMgrSington.GetPlayer(sid)
|
||||
if p == nil {
|
||||
logger.Logger.Trace("CSPMCmdHandler p == nil")
|
||||
|
@ -729,13 +729,13 @@ type CSRobotChgDataHandler struct {
|
|||
}
|
||||
|
||||
func (this *CSRobotChgDataPacketFactory) CreatePacket() interface{} {
|
||||
pack := &player_proto.CSRobotChgData{}
|
||||
pack := &playerproto.CSRobotChgData{}
|
||||
return pack
|
||||
}
|
||||
|
||||
func (this *CSRobotChgDataHandler) Process(s *netlib.Session, packetid int, data interface{}, sid int64) error {
|
||||
logger.Logger.Trace("CSRobotChgDataHandler Process recv ", data)
|
||||
if _, ok := data.(*player_proto.CSRobotChgData); ok {
|
||||
if _, ok := data.(*playerproto.CSRobotChgData); ok {
|
||||
p := PlayerMgrSington.GetPlayer(sid)
|
||||
if p == nil {
|
||||
logger.Logger.Trace("CSRobotChgDataHandler p == nil")
|
||||
|
@ -756,13 +756,13 @@ type CSAccountInvalidHandler struct {
|
|||
}
|
||||
|
||||
func (this *CSAccountInvalidPacketFactory) CreatePacket() interface{} {
|
||||
pack := &login_proto.CSAccountInvalid{}
|
||||
pack := &loginproto.CSAccountInvalid{}
|
||||
return pack
|
||||
}
|
||||
|
||||
func (this *CSAccountInvalidHandler) Process(s *netlib.Session, packetid int, data interface{}, sid int64) error {
|
||||
logger.Logger.Trace("CSAccountInvalidHandler Process recv ", data)
|
||||
if _, ok := data.(*login_proto.CSAccountInvalid); ok {
|
||||
if _, ok := data.(*loginproto.CSAccountInvalid); ok {
|
||||
p := PlayerMgrSington.GetPlayer(sid)
|
||||
if p != nil && p.IsRobot() {
|
||||
snid := p.SnId
|
||||
|
@ -789,12 +789,12 @@ func (this *CSAccountInvalidHandler) Process(s *netlib.Session, packetid int, da
|
|||
}
|
||||
|
||||
func init() {
|
||||
common.RegisterHandler(int(player_proto.PlayerPacketID_PACKET_CS_PMCMD), &CSPMCmdHandler{})
|
||||
netlib.RegisterFactory(int(player_proto.PlayerPacketID_PACKET_CS_PMCMD), &CSPMCmdPacketFactory{})
|
||||
common.RegisterHandler(int(playerproto.PlayerPacketID_PACKET_CS_PMCMD), &CSPMCmdHandler{})
|
||||
netlib.RegisterFactory(int(playerproto.PlayerPacketID_PACKET_CS_PMCMD), &CSPMCmdPacketFactory{})
|
||||
|
||||
common.RegisterHandler(int(player_proto.PlayerPacketID_PACKET_CS_ROBOTCHGDATA), &CSRobotChgDataHandler{})
|
||||
netlib.RegisterFactory(int(player_proto.PlayerPacketID_PACKET_CS_ROBOTCHGDATA), &CSRobotChgDataPacketFactory{})
|
||||
common.RegisterHandler(int(playerproto.PlayerPacketID_PACKET_CS_ROBOTCHGDATA), &CSRobotChgDataHandler{})
|
||||
netlib.RegisterFactory(int(playerproto.PlayerPacketID_PACKET_CS_ROBOTCHGDATA), &CSRobotChgDataPacketFactory{})
|
||||
|
||||
common.RegisterHandler(int(login_proto.LoginPacketID_PACKET_CS_ACCOUNTINVALID), &CSAccountInvalidHandler{})
|
||||
netlib.RegisterFactory(int(login_proto.LoginPacketID_PACKET_CS_ACCOUNTINVALID), &CSAccountInvalidPacketFactory{})
|
||||
common.RegisterHandler(int(loginproto.LoginPacketID_PACKET_CS_ACCOUNTINVALID), &CSAccountInvalidHandler{})
|
||||
netlib.RegisterFactory(int(loginproto.LoginPacketID_PACKET_CS_ACCOUNTINVALID), &CSAccountInvalidPacketFactory{})
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"games.yol.com/win88/model"
|
||||
"math/rand"
|
||||
"time"
|
||||
|
||||
|
@ -11,20 +12,15 @@ import (
|
|||
|
||||
"mongo.games.com/game/common"
|
||||
"mongo.games.com/game/proto"
|
||||
hall_proto "mongo.games.com/game/protocol/gamehall"
|
||||
hallproto "mongo.games.com/game/protocol/gamehall"
|
||||
"mongo.games.com/game/protocol/server"
|
||||
"mongo.games.com/game/protocol/webapi"
|
||||
"mongo.games.com/game/srvdata"
|
||||
)
|
||||
|
||||
var CoinSceneMgrSingleton = &CoinSceneMgr{
|
||||
playerChanging: make(map[int32]int32),
|
||||
//按平台管理
|
||||
playerChanging: make(map[int32]int32),
|
||||
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 {
|
||||
|
@ -33,16 +29,8 @@ type CreateRoomCache struct {
|
|||
}
|
||||
|
||||
type CoinSceneMgr struct {
|
||||
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;
|
||||
|
||||
scenesOfPlatform map[string]map[int32]*CoinScenePool // 场次房间池 platform:gamefreeid
|
||||
playerChanging map[int32]int32 // 换桌中的玩家 snid:gamefreeid
|
||||
//延迟创建房间列表
|
||||
delayCache []*CreateRoomCache // 待预创建房间
|
||||
}
|
||||
|
@ -50,216 +38,126 @@ type CoinSceneMgr struct {
|
|||
// GetCoinScenePool 获取一个场景池
|
||||
// plt 平台id
|
||||
// id 场次id
|
||||
func (csm *CoinSceneMgr) GetCoinScenePool(plt string, id int32) *CoinScenePool {
|
||||
func (m *CoinSceneMgr) GetCoinScenePool(plt string, id int32) *CoinScenePool {
|
||||
gf := PlatformMgrSingleton.GetGameFree(plt, id)
|
||||
if gf == nil {
|
||||
if gf == nil || gf.DbGameFree == nil {
|
||||
return nil
|
||||
}
|
||||
groupId := gf.GetGroupId()
|
||||
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 {
|
||||
return csp
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if gf.GetDbGameFree() == nil {
|
||||
return nil
|
||||
if ss, ok := m.scenesOfPlatform[plt]; ok {
|
||||
if csp, ok := ss[id]; ok && csp != nil {
|
||||
return csp
|
||||
}
|
||||
}
|
||||
|
||||
// 创建了一个新的
|
||||
// 应该是走不到这里,因为模块启动时所有场次都创建了房间池
|
||||
pool := newCoinScenePool(plt, groupId, gf.GetDbGameFree())
|
||||
if groupId != 0 {
|
||||
v, ok := csm.scenesOfGroup[groupId]
|
||||
if !ok || v == nil {
|
||||
csm.scenesOfGroup[groupId] = make(map[int32]*CoinScenePool)
|
||||
}
|
||||
csm.scenesOfGroup[groupId][id] = pool
|
||||
} else {
|
||||
v, ok := csm.scenesOfPlatform[plt]
|
||||
if !ok || v == nil {
|
||||
csm.scenesOfPlatform[plt] = make(map[int32]*CoinScenePool)
|
||||
}
|
||||
csm.scenesOfPlatform[plt][id] = pool
|
||||
// 模块启动时所有场次都创建了房间池
|
||||
pool := newCoinScenePool(plt, gf.GetDbGameFree())
|
||||
v, ok := m.scenesOfPlatform[plt]
|
||||
if !ok || v == nil {
|
||||
m.scenesOfPlatform[plt] = make(map[int32]*CoinScenePool)
|
||||
}
|
||||
m.scenesOfPlatform[plt][id] = pool
|
||||
return pool
|
||||
}
|
||||
|
||||
func (csm *CoinSceneMgr) findCoinScenePool(platform string, id int32) (pools map[int32]*CoinScenePool, groupID int32,
|
||||
dbGameFree *server.DB_GameFree) {
|
||||
func (m *CoinSceneMgr) findCoinScenePool(platform string, id int32) (pools map[int32]*CoinScenePool, dbGameFree *server.DB_GameFree) {
|
||||
gf := PlatformMgrSingleton.GetGameFree(platform, id)
|
||||
if gf == nil || gf.GetDbGameFree() == 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()
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
ss, ok = csm.scenesOfPlatform[platform]
|
||||
if !ok {
|
||||
ss, ok := m.scenesOfPlatform[platform]
|
||||
if !ok || ss == nil {
|
||||
ss = make(map[int32]*CoinScenePool)
|
||||
csm.scenesOfPlatform[platform] = ss
|
||||
m.scenesOfPlatform[platform] = ss
|
||||
}
|
||||
return ss, 0, gf.GetDbGameFree()
|
||||
return ss, gf.GetDbGameFree()
|
||||
}
|
||||
|
||||
// PlayerEnter 玩家进入房间池
|
||||
func (csm *CoinSceneMgr) PlayerEnter(p *Player, id int32, roomId int32, exclude []int32, isChangeRoom bool) hall_proto.OpResultCode {
|
||||
logger.Logger.Tracef("(csm *CoinSceneMgr) PlayerEnter snid:%v id:%v roomid:%v exclude:%v", p.SnId, id, roomId, exclude)
|
||||
func (m *CoinSceneMgr) PlayerEnter(p *Player, id int32, roomId int32, exclude []int32, isChangeRoom bool) hallproto.OpResultCode {
|
||||
logger.Logger.Tracef("CoinSceneMgr PlayerEnter snid:%v id:%v roomid:%v exclude:%v", p.SnId, id, roomId, exclude)
|
||||
if p.isDelete { //删档用户不让进游戏
|
||||
return hall_proto.OpResultCode_OPRC_RoomHadClosed
|
||||
return hallproto.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()
|
||||
if platform == nil {
|
||||
return hall_proto.OpResultCode_OPRC_RoomHadClosed
|
||||
return hallproto.OpResultCode_OPRC_RoomHadClosed
|
||||
}
|
||||
|
||||
// 玩家已经在房间里了
|
||||
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)
|
||||
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)
|
||||
return ret
|
||||
}
|
||||
|
||||
// AudienceEnter 观众进入房间
|
||||
// id 场次id
|
||||
func (csm *CoinSceneMgr) AudienceEnter(p *Player, id int32, roomId int32, exclude []int32, ischangeroom bool) hall_proto.OpResultCode {
|
||||
func (m *CoinSceneMgr) AudienceEnter(p *Player, id int32, roomId int32, exclude []int32, ischangeroom bool) hallproto.OpResultCode {
|
||||
logger.Logger.Tracef("CoinSceneMgr AudienceEnter snid:%v id:%v roomid:%v exclude:%v", p.SnId, id, roomId, exclude)
|
||||
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()
|
||||
if platform == nil {
|
||||
return hall_proto.OpResultCode_OPRC_RoomHadClosed
|
||||
return hallproto.OpResultCode_OPRC_RoomHadClosed
|
||||
}
|
||||
|
||||
pools, _, _ := csm.findCoinScenePool(platform.IdStr, id)
|
||||
pools, _ := m.findCoinScenePool(platform.IdStr, id)
|
||||
if pools == nil {
|
||||
return hall_proto.OpResultCode_OPRC_RoomHadClosed
|
||||
return hallproto.OpResultCode_OPRC_RoomHadClosed
|
||||
}
|
||||
|
||||
if len(pools) == 0 {
|
||||
return hall_proto.OpResultCode_OPRC_NoFindDownTiceRoom
|
||||
return hallproto.OpResultCode_OPRC_NoFindDownTiceRoom
|
||||
}
|
||||
|
||||
if csp, ok := pools[id]; ok && csp != nil {
|
||||
ret := csp.AudienceEnter(p, roomId, exclude, ischangeroom)
|
||||
logger.Logger.Warnf("(csm *CoinSceneMgr) AudienceEnter snid:%v find in id:%v exclude:%v return false", p.SnId, id, exclude)
|
||||
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
|
||||
csp, ok := pools[id]
|
||||
if !ok || csp == nil {
|
||||
return hallproto.OpResultCode_OPRC_RoomHadClosed
|
||||
}
|
||||
|
||||
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
|
||||
ret := csp.audienceEnter(p, roomId, exclude, ischangeroom)
|
||||
logger.Logger.Tracef("CoinSceneMgr AudienceEnter snid:%v id:%v ret:%v", p.SnId, id, ret)
|
||||
return ret
|
||||
}
|
||||
|
||||
// PlayerLeave 玩家离开
|
||||
func (csm *CoinSceneMgr) PlayerLeave(p *Player, reason int) bool {
|
||||
logger.Logger.Tracef("玩家离开: snid %v, reason %v isAudience %v", p.SnId, reason)
|
||||
return csm.playerLeave(p, reason)
|
||||
// 游戏服玩家离开房间消息触发
|
||||
func (m *CoinSceneMgr) PlayerLeave(p *Player, reason int) bool {
|
||||
logger.Logger.Tracef("玩家离开: snid %v, reason %v", p.SnId, 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 解散房间
|
||||
// 游戏服解散房间消息触发
|
||||
// sceneId 房间id
|
||||
func (csm *CoinSceneMgr) OnDestroyScene(sceneId int) {
|
||||
if platformName, ok := csm.platformOfScene[sceneId]; ok {
|
||||
if ss, ok := csm.scenesOfPlatform[platformName]; ok {
|
||||
for _, csp := range ss {
|
||||
csp.OnDestroyScene(sceneId)
|
||||
}
|
||||
}
|
||||
delete(csm.platformOfScene, sceneId)
|
||||
func (m *CoinSceneMgr) OnDestroyScene(sceneId int) {
|
||||
if s := SceneMgrSingleton.GetScene(sceneId); s != nil && s.csp != nil {
|
||||
s.csp.onDestroyScene(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 获取场次人数
|
||||
func (csm *CoinSceneMgr) GetPlayerNums(p *Player, gameId, gameMode int32) []int32 {
|
||||
func (m *CoinSceneMgr) GetPlayerNums(p *Player, gameId, gameMode int32) []int32 {
|
||||
//多平台支持
|
||||
platform := p.GetPlatform()
|
||||
var nums [10]int32
|
||||
|
@ -276,22 +174,11 @@ func (csm *CoinSceneMgr) GetPlayerNums(p *Player, gameId, gameMode int32) []int3
|
|||
for _, id := range ids {
|
||||
gps := PlatformMgrSingleton.GetGameFree(platform.IdStr, id)
|
||||
if gps != nil {
|
||||
if gps.GroupId != 0 {
|
||||
if ss, exist := csm.scenesOfGroup[gps.GroupId]; exist {
|
||||
if csp, exist := ss[id]; exist {
|
||||
sceneType := csp.GetSceneType() - 1
|
||||
if sceneType >= 0 && sceneType < len(nums) {
|
||||
nums[sceneType] += csp.GetPlayerNum() + csp.GetFakePlayerNum()
|
||||
}
|
||||
}
|
||||
}
|
||||
} 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()
|
||||
}
|
||||
if ss, ok := m.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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -305,9 +192,9 @@ func (csm *CoinSceneMgr) GetPlayerNums(p *Player, gameId, gameMode int32) []int3
|
|||
}
|
||||
|
||||
// InCoinScene 是否在场次中
|
||||
func (csm *CoinSceneMgr) InCoinScene(p *Player) bool {
|
||||
func (m *CoinSceneMgr) InCoinScene(p *Player) bool {
|
||||
if p == nil {
|
||||
logger.Logger.Tracef("(csm *CoinSceneMgr) InCoinScene p == nil snid:%v ", p.SnId)
|
||||
logger.Logger.Tracef("(m *CoinSceneMgr) InCoinScene p == nil")
|
||||
return false
|
||||
}
|
||||
|
||||
|
@ -322,10 +209,10 @@ func (csm *CoinSceneMgr) InCoinScene(p *Player) bool {
|
|||
}
|
||||
|
||||
// PlayerTryLeave 通知游戏服务玩家要离开房间
|
||||
func (csm *CoinSceneMgr) PlayerTryLeave(p *Player, isAudience bool) hall_proto.OpResultCode {
|
||||
if !csm.InCoinScene(p) {
|
||||
logger.Logger.Tracef("(csm *CoinSceneMgr) PlayerTryLeave !csm.InCoinScene(p) snid:%v ", p.SnId)
|
||||
return hall_proto.OpResultCode_OPRC_Sucess
|
||||
func (m *CoinSceneMgr) PlayerTryLeave(p *Player, isAudience bool) hallproto.OpResultCode {
|
||||
if !m.InCoinScene(p) {
|
||||
logger.Logger.Tracef("(m *CoinSceneMgr) PlayerTryLeave !m.InCoinScene(p) snid:%v ", p.SnId)
|
||||
return hallproto.OpResultCode_OPRC_Sucess
|
||||
}
|
||||
|
||||
// 通知gamesrv
|
||||
|
@ -333,46 +220,54 @@ func (csm *CoinSceneMgr) PlayerTryLeave(p *Player, isAudience bool) hall_proto.O
|
|||
if isAudience {
|
||||
op = common.CoinSceneOp_AudienceLeave
|
||||
}
|
||||
pack := &hall_proto.CSCoinSceneOp{
|
||||
Id: proto.Int32(p.scene.csp.id),
|
||||
pack := &hallproto.CSCoinSceneOp{
|
||||
Id: proto.Int32(p.scene.csp.ID()),
|
||||
OpType: proto.Int32(op),
|
||||
}
|
||||
proto.SetDefaults(pack)
|
||||
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 hall_proto.OpResultCode_OPRC_OpYield
|
||||
common.TransmitToServer(p.sid, int(hallproto.CoinSceneGamePacketID_PACKET_CS_COINSCENE_OP), pack, p.scene.gameSess.Session)
|
||||
logger.Logger.Tracef("(m *CoinSceneMgr) PlayerTryLeave snid:%v id:%v", p.SnId, pack.GetId())
|
||||
|
||||
return hallproto.OpResultCode_OPRC_OpYield
|
||||
}
|
||||
|
||||
func (csm *CoinSceneMgr) PlayerInChanging(p *Player) bool {
|
||||
_, exist := csm.playerChanging[p.SnId]
|
||||
// PlayerInChanging 换房中
|
||||
func (m *CoinSceneMgr) PlayerInChanging(p *Player) bool {
|
||||
_, exist := m.playerChanging[p.SnId]
|
||||
return exist
|
||||
}
|
||||
|
||||
func (csm *CoinSceneMgr) ClearPlayerChanging(p *Player) {
|
||||
delete(csm.playerChanging, p.SnId)
|
||||
// ClearPlayerChanging 换房结束
|
||||
func (m *CoinSceneMgr) ClearPlayerChanging(p *Player) {
|
||||
delete(m.playerChanging, p.SnId)
|
||||
}
|
||||
|
||||
func (csm *CoinSceneMgr) PlayerTryChange(p *Player, id int32, exclude []int32, isAudience bool) hall_proto.OpResultCode {
|
||||
if csm.InCoinScene(p) {
|
||||
return csm.StartChangeCoinSceneTransact(p, id, exclude, isAudience)
|
||||
// PlayerTryChange 换房
|
||||
// id 场次id
|
||||
// excludeRoomId 排除的房间id
|
||||
// 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 {
|
||||
return csm.AudienceEnter(p, id, 0, exclude, true)
|
||||
return m.AudienceEnter(p, id, 0, excludeRoomId, true)
|
||||
}
|
||||
return csm.PlayerEnter(p, id, 0, exclude, true)
|
||||
// 不在场次中,进入房间
|
||||
return m.PlayerEnter(p, id, 0, excludeRoomId, true)
|
||||
}
|
||||
|
||||
func (csm *CoinSceneMgr) StartChangeCoinSceneTransact(p *Player, id int32, exclude []int32, isAudience bool) hall_proto.OpResultCode {
|
||||
func (m *CoinSceneMgr) StartChangeCoinSceneTransact(p *Player, id int32, exclude []int32, isAudience bool) hallproto.OpResultCode {
|
||||
if p == nil || p.scene == nil {
|
||||
logger.Logger.Warnf("(csm *CoinSceneMgr) StartChangeCoinSceneTransact p == nil || p.scene == nil snid:%v id:%v", p.SnId, id)
|
||||
return hall_proto.OpResultCode_OPRC_Error
|
||||
logger.Logger.Warnf("(m *CoinSceneMgr) StartChangeCoinSceneTransact p == nil || p.scene == nil snid:%v id:%v", p.SnId, id)
|
||||
return hallproto.OpResultCode_OPRC_Error
|
||||
}
|
||||
|
||||
tNow := time.Now()
|
||||
if !p.lastChangeScene.IsZero() && tNow.Sub(p.lastChangeScene) < time.Second {
|
||||
logger.Logger.Warnf("(csm *CoinSceneMgr) StartChangeCoinSceneTransact !p.lastChangeScene.IsZero() && tNow.Sub(p.lastChangeScene) < time.Second snid:%v id:%v", p.SnId, id)
|
||||
return hall_proto.OpResultCode_OPRC_ChangeRoomTooOften
|
||||
logger.Logger.Warnf("(m *CoinSceneMgr) StartChangeCoinSceneTransact !p.lastChangeScene.IsZero() && tNow.Sub(p.lastChangeScene) < time.Second snid:%v id:%v", p.SnId, id)
|
||||
return hallproto.OpResultCode_OPRC_ChangeRoomTooOften
|
||||
}
|
||||
|
||||
tnp := &transact.TransNodeParam{
|
||||
|
@ -392,12 +287,12 @@ func (csm *CoinSceneMgr) StartChangeCoinSceneTransact(p *Player, id int32, exclu
|
|||
tNode := transact.DTCModule.StartTrans(tnp, ctx, CoinSceneChangeTimeOut)
|
||||
if tNode != nil {
|
||||
tNode.Go(core.CoreObject())
|
||||
csm.playerChanging[p.SnId] = id
|
||||
m.playerChanging[p.SnId] = id
|
||||
p.lastChangeScene = tNow
|
||||
return hall_proto.OpResultCode_OPRC_Sucess
|
||||
return hallproto.OpResultCode_OPRC_Sucess
|
||||
}
|
||||
logger.Logger.Warnf("(csm *CoinSceneMgr) StartChangeCoinSceneTransact tNode == nil snid:%v id:%v", p.SnId, id)
|
||||
return hall_proto.OpResultCode_OPRC_Error
|
||||
logger.Logger.Warnf("(m *CoinSceneMgr) StartChangeCoinSceneTransact tNode == nil snid:%v id:%v", p.SnId, id)
|
||||
return hallproto.OpResultCode_OPRC_Error
|
||||
}
|
||||
|
||||
// TouchCreateRoom 触发预创建房间
|
||||
|
@ -405,44 +300,47 @@ func (csm *CoinSceneMgr) StartChangeCoinSceneTransact(p *Player, id int32, exclu
|
|||
// 2.游戏服建立连接后触发
|
||||
// 3.房间解散后触发
|
||||
// 4.场次配置更新后
|
||||
func (csm *CoinSceneMgr) TouchCreateRoom(platform string, gameFreeId int32) {
|
||||
func (m *CoinSceneMgr) TouchCreateRoom(platform string, gameFreeId int32) {
|
||||
if model.GameParamData.ClosePreCreateRoom {
|
||||
return
|
||||
}
|
||||
gf := PlatformMgrSingleton.GetGameFree(platform, gameFreeId)
|
||||
if gf.Status && gf.DbGameFree.GetCreateRoomNum() > 0 {
|
||||
logger.Logger.Tracef("TouchCreateRoom platform:%v gameFreeId:%v", platform, gameFreeId)
|
||||
csm.delayCache = append(csm.delayCache, &CreateRoomCache{
|
||||
m.delayCache = append(m.delayCache, &CreateRoomCache{
|
||||
platformName: platform,
|
||||
gameFreeId: gameFreeId,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (csm *CoinSceneMgr) ModuleName() string {
|
||||
func (m *CoinSceneMgr) ModuleName() string {
|
||||
return "CoinSceneMgr"
|
||||
}
|
||||
|
||||
func (csm *CoinSceneMgr) Init() {
|
||||
func (m *CoinSceneMgr) Init() {
|
||||
// 房间池初始化
|
||||
for _, platform := range PlatformMgrSingleton.GetPlatforms() {
|
||||
if platform.Isolated || platform.IdStr == "" {
|
||||
for _, v := range srvdata.PBDB_GameFreeMgr.Datas.GetArr() {
|
||||
gps := PlatformMgrSingleton.GetGameFree(platform.IdStr, v.GetId())
|
||||
if gps != nil {
|
||||
csm.GetCoinScenePool(platform.IdStr, v.GetId())
|
||||
csm.TouchCreateRoom(platform.IdStr, v.GetId())
|
||||
m.GetCoinScenePool(platform.IdStr, v.GetId())
|
||||
m.TouchCreateRoom(platform.IdStr, v.GetId())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (csm *CoinSceneMgr) Update() {
|
||||
cnt := len(csm.delayCache)
|
||||
func (m *CoinSceneMgr) Update() {
|
||||
cnt := len(m.delayCache)
|
||||
if cnt > 0 {
|
||||
data := csm.delayCache[cnt-1]
|
||||
csm.delayCache = csm.delayCache[:cnt-1]
|
||||
data := m.delayCache[cnt-1]
|
||||
m.delayCache = m.delayCache[:cnt-1]
|
||||
gf := PlatformMgrSingleton.GetGameFree(data.platformName, data.gameFreeId)
|
||||
if gf != nil && gf.DbGameFree != nil {
|
||||
csp := csm.GetCoinScenePool(data.platformName, data.gameFreeId)
|
||||
csp := m.GetCoinScenePool(data.platformName, data.gameFreeId)
|
||||
if csp != nil {
|
||||
csp.PreCreateRoom()
|
||||
}
|
||||
|
@ -450,22 +348,22 @@ func (csm *CoinSceneMgr) Update() {
|
|||
}
|
||||
}
|
||||
|
||||
func (csm *CoinSceneMgr) Shutdown() {
|
||||
module.UnregisteModule(csm)
|
||||
func (m *CoinSceneMgr) Shutdown() {
|
||||
module.UnregisteModule(m)
|
||||
}
|
||||
|
||||
//=====================PlatformObserver======================
|
||||
|
||||
func (this *CoinSceneMgr) OnPlatformCreate(p *Platform) {
|
||||
func (m *CoinSceneMgr) OnPlatformCreate(p *Platform) {
|
||||
|
||||
}
|
||||
|
||||
func (this *CoinSceneMgr) OnPlatformDestroy(p *Platform) {
|
||||
func (m *CoinSceneMgr) OnPlatformDestroy(p *Platform) {
|
||||
if p == nil {
|
||||
return
|
||||
}
|
||||
var ids []int
|
||||
if v, ok := this.scenesOfPlatform[p.IdStr]; ok {
|
||||
if v, ok := m.scenesOfPlatform[p.IdStr]; ok {
|
||||
for _, csp := range v {
|
||||
for _, scene := range csp.scenes {
|
||||
ids = append(ids, scene.sceneId)
|
||||
|
@ -475,24 +373,18 @@ func (this *CoinSceneMgr) OnPlatformDestroy(p *Platform) {
|
|||
SceneMgrSingleton.DoDelete(ids, true)
|
||||
}
|
||||
|
||||
func (this *CoinSceneMgr) OnPlatformChangeDisabled(p *Platform, disabled bool) {
|
||||
func (m *CoinSceneMgr) OnPlatformChangeDisabled(p *Platform, disabled bool) {
|
||||
if disabled {
|
||||
this.OnPlatformDestroy(p)
|
||||
m.OnPlatformDestroy(p)
|
||||
}
|
||||
}
|
||||
|
||||
func (this *CoinSceneMgr) OnPlatformGameFreeUpdate(p *Platform, oldCfg, newCfg *webapi.GameFree) {
|
||||
func (m *CoinSceneMgr) OnPlatformGameFreeUpdate(p *Platform, oldCfg, newCfg *webapi.GameFree) {
|
||||
if p == nil || newCfg == nil {
|
||||
return
|
||||
}
|
||||
|
||||
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]
|
||||
}
|
||||
ss, ok := m.scenesOfPlatform[p.IdStr]
|
||||
if !ok || ss == nil {
|
||||
return
|
||||
}
|
||||
|
@ -504,62 +396,36 @@ func (this *CoinSceneMgr) OnPlatformGameFreeUpdate(p *Platform, oldCfg, newCfg *
|
|||
ids = append(ids, scene.sceneId)
|
||||
}
|
||||
SceneMgrSingleton.DoDelete(ids, true)
|
||||
this.TouchCreateRoom(p.IdStr, newCfg.DbGameFree.Id)
|
||||
m.TouchCreateRoom(p.IdStr, newCfg.DbGameFree.Id)
|
||||
}
|
||||
}
|
||||
|
||||
func (this *CoinSceneMgr) OnPlatformDestroyByGameFreeId(p *Platform, gameFreeId int32) {
|
||||
func (m *CoinSceneMgr) OnPlatformDestroyByGameFreeId(p *Platform, gameFreeId int32) {
|
||||
if p == nil {
|
||||
return
|
||||
}
|
||||
if csps, ok := this.scenesOfPlatform[p.IdStr]; ok {
|
||||
var ids []int
|
||||
for _, csp := range csps {
|
||||
var ids []int
|
||||
if v, ok := m.scenesOfPlatform[p.IdStr]; ok {
|
||||
for _, csp := range v {
|
||||
for _, scene := range csp.scenes {
|
||||
if scene.dbGameFree.Id == gameFreeId {
|
||||
ids = append(ids, scene.sceneId)
|
||||
}
|
||||
}
|
||||
}
|
||||
SceneMgrSingleton.DoDelete(ids, true)
|
||||
}
|
||||
SceneMgrSingleton.DoDelete(ids, true)
|
||||
}
|
||||
|
||||
//=========================PlatformGameGroupObserver==============================
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
func (m *CoinSceneMgr) OnGameGroupUpdate(oldCfg, newCfg *webapi.GameConfigGroup) {
|
||||
|
||||
}
|
||||
|
||||
//=========================GameSessionListener======================================
|
||||
|
||||
func (csm *CoinSceneMgr) OnGameSessionRegiste(gs *GameSession) {
|
||||
func (m *CoinSceneMgr) OnGameSessionRegiste(gs *GameSession) {
|
||||
wildGs := len(gs.gameIds) == 0 || common.InSliceInt32(gs.gameIds, 0) // 是否所有游戏都支持
|
||||
for _, platform := range PlatformMgrSingleton.GetPlatforms() {
|
||||
if platform.IdStr == DefaultPlatform {
|
||||
|
@ -569,13 +435,13 @@ func (csm *CoinSceneMgr) OnGameSessionRegiste(gs *GameSession) {
|
|||
gps := PlatformMgrSingleton.GetGameFrees(platform.IdStr)
|
||||
for _, v := range gps {
|
||||
if v != nil && (wildGs || common.InSliceInt32(gs.gameIds, v.DbGameFree.GetGameId())) {
|
||||
csm.TouchCreateRoom(platform.IdStr, v.DbGameFree.Id)
|
||||
m.TouchCreateRoom(platform.IdStr, v.DbGameFree.Id)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (this *CoinSceneMgr) OnGameSessionUnregiste(gs *GameSession) {
|
||||
func (m *CoinSceneMgr) OnGameSessionUnregiste(gs *GameSession) {
|
||||
//todo 游戏服务断开,是否解散房间?
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"mongo.games.com/game/common"
|
||||
"mongo.games.com/goserver/core/logger"
|
||||
|
||||
"mongo.games.com/game/common"
|
||||
"mongo.games.com/game/model"
|
||||
gamehallproto "mongo.games.com/game/protocol/gamehall"
|
||||
serverproto "mongo.games.com/game/protocol/server"
|
||||
|
@ -13,8 +13,6 @@ import (
|
|||
// CoinScenePool 房间池
|
||||
type CoinScenePool struct {
|
||||
platform string // 平台id
|
||||
groupId int32 // 组id
|
||||
id int32 // 场次id
|
||||
dbGameFree *serverproto.DB_GameFree // 场次配置
|
||||
dbGameRule *serverproto.DB_GameRule // 场次配置
|
||||
scenes map[int]*Scene // 所有房间,房间id
|
||||
|
@ -26,7 +24,7 @@ type CoinScenePool struct {
|
|||
policy ICoinScenePool
|
||||
}
|
||||
|
||||
func newCoinScenePool(platform string, groupId int32, dbGameFree *serverproto.DB_GameFree) *CoinScenePool {
|
||||
func newCoinScenePool(platform string, dbGameFree *serverproto.DB_GameFree) *CoinScenePool {
|
||||
if dbGameFree == nil {
|
||||
return nil
|
||||
}
|
||||
|
@ -42,8 +40,6 @@ func newCoinScenePool(platform string, groupId int32, dbGameFree *serverproto.DB
|
|||
|
||||
csp := &CoinScenePool{
|
||||
platform: platform,
|
||||
groupId: groupId,
|
||||
id: dbGameFree.GetId(),
|
||||
dbGameFree: dbGameFree,
|
||||
dbGameRule: dbGameRule,
|
||||
scenes: make(map[int]*Scene),
|
||||
|
@ -59,6 +55,10 @@ func newCoinScenePool(platform string, groupId int32, dbGameFree *serverproto.DB
|
|||
return csp
|
||||
}
|
||||
|
||||
func (csp *CoinScenePool) ID() int32 {
|
||||
return csp.dbGameFree.Id
|
||||
}
|
||||
|
||||
func (csp *CoinScenePool) GetPlayerNum() int32 {
|
||||
return int32(len(csp.players))
|
||||
}
|
||||
|
@ -73,7 +73,8 @@ func (csp *CoinScenePool) GetFakePlayerNum() int32 {
|
|||
return 0
|
||||
}
|
||||
|
||||
// GetSceneType 获取场次id
|
||||
// GetSceneType 获取场次类型
|
||||
// 新手场,中级场 ...
|
||||
func (csp *CoinScenePool) GetSceneType() int {
|
||||
if csp.dbGameFree != nil {
|
||||
return int(csp.dbGameFree.GetSceneType())
|
||||
|
@ -89,14 +90,79 @@ func (csp *CoinScenePool) CanInviteRob() bool {
|
|||
return false
|
||||
}
|
||||
|
||||
// CanEnter 检查入场条件
|
||||
func (csp *CoinScenePool) CanEnter(p *Player) gamehallproto.OpResultCode {
|
||||
// PreCreateRoom 预创建房间
|
||||
func (csp *CoinScenePool) PreCreateRoom() {
|
||||
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 {
|
||||
return gamehallproto.OpResultCode_OPRC_Error
|
||||
}
|
||||
|
||||
//检测房间状态是否开启
|
||||
gps := PlatformMgrSingleton.GetGameFree(p.Platform, csp.id)
|
||||
gps := PlatformMgrSingleton.GetGameFree(p.Platform, csp.ID())
|
||||
if gps == nil || !gps.Status {
|
||||
return gamehallproto.OpResultCode_OPRC_RoomHadClosed
|
||||
}
|
||||
|
@ -106,7 +172,7 @@ func (csp *CoinScenePool) CanEnter(p *Player) gamehallproto.OpResultCode {
|
|||
return gamehallproto.OpResultCode_OPRC_RoomHadClosed
|
||||
}
|
||||
|
||||
//检查游戏次数限制
|
||||
// 检查游戏次数限制
|
||||
if !p.IsRob {
|
||||
todayData, _ := p.GetDaliyGameData(int(dbGameFree.GetId()))
|
||||
if dbGameFree.GetPlayNumLimit() != 0 &&
|
||||
|
@ -119,14 +185,14 @@ func (csp *CoinScenePool) CanEnter(p *Player) gamehallproto.OpResultCode {
|
|||
return csp.policy.CanEnter(csp, p)
|
||||
}
|
||||
|
||||
// CanAudienceEnter 检查观众入场条件
|
||||
func (csp *CoinScenePool) CanAudienceEnter(p *Player) gamehallproto.OpResultCode {
|
||||
// canAudienceEnter 检查观众入场条件
|
||||
func (csp *CoinScenePool) canAudienceEnter(p *Player) gamehallproto.OpResultCode {
|
||||
if csp.dbGameFree == nil || p == nil {
|
||||
return gamehallproto.OpResultCode_OPRC_Error
|
||||
}
|
||||
|
||||
//检测房间状态是否开启
|
||||
gps := PlatformMgrSingleton.GetGameFree(p.Platform, csp.id)
|
||||
gps := PlatformMgrSingleton.GetGameFree(p.Platform, csp.ID())
|
||||
if gps == nil {
|
||||
return gamehallproto.OpResultCode_OPRC_RoomHadClosed
|
||||
}
|
||||
|
@ -139,35 +205,16 @@ func (csp *CoinScenePool) CanAudienceEnter(p *Player) gamehallproto.OpResultCode
|
|||
return csp.policy.CanAudienceEnter(csp, p)
|
||||
}
|
||||
|
||||
// AddScene 添加房间
|
||||
func (csp *CoinScenePool) AddScene(s *Scene) {
|
||||
if s == nil {
|
||||
return
|
||||
}
|
||||
csp.scenes[s.sceneId] = s
|
||||
s.csp = csp
|
||||
if csp.groupId != 0 {
|
||||
CoinSceneMgrSingleton.groupOfScene[s.sceneId] = csp.groupId
|
||||
} else {
|
||||
CoinSceneMgrSingleton.platformOfScene[s.sceneId] = csp.platform
|
||||
}
|
||||
}
|
||||
|
||||
// PlayerEnter 玩家进入房间池
|
||||
// playerEnter 玩家进入房间池
|
||||
// exclude 排除的房间id
|
||||
// isChangeRoom 是否换房
|
||||
func (csp *CoinScenePool) PlayerEnter(p *Player, roomId int32, exclude []int32, isChangeRoom bool) gamehallproto.OpResultCode {
|
||||
if ret := csp.CanEnter(p); ret != gamehallproto.OpResultCode_OPRC_Sucess {
|
||||
logger.Logger.Warnf("(csp *CoinScenePool) PlayerEnter find snid:%v csp.CanEnter coin:%v ret:%v id:%v", p.SnId,
|
||||
func (csp *CoinScenePool) playerEnter(p *Player, roomId int32, exclude []int32, isChangeRoom bool) gamehallproto.OpResultCode {
|
||||
if ret := csp.canEnter(p); ret != gamehallproto.OpResultCode_OPRC_Sucess {
|
||||
logger.Logger.Warnf("(csp *CoinScenePool) PlayerEnter find snid:%v csp.canEnter coin:%v ret:%v id:%v", p.SnId,
|
||||
p.Coin, ret, csp.dbGameFree.GetId())
|
||||
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
|
||||
// 进入房间
|
||||
// 指定房间id进入,忽略排除exclude,只有机器人和进入预创建房间才允许
|
||||
|
@ -204,15 +251,17 @@ func (csp *CoinScenePool) PlayerEnter(p *Player, roomId int32, exclude []int32,
|
|||
if scene == nil {
|
||||
scene = csp.policy.NewScene(csp, p)
|
||||
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)
|
||||
} else {
|
||||
logger.Logger.Errorf("Create %v scene failed.", csp.id)
|
||||
logger.Logger.Errorf("Create %v scene failed.", csp.ID())
|
||||
}
|
||||
}
|
||||
|
||||
if scene != nil {
|
||||
if scene.PlayerEnter(p, -1, isChangeRoom) {
|
||||
csp.OnPlayerEnter(p, scene)
|
||||
logger.Logger.Infof("(csp *CoinScenePool) PlayerEnter snid:%v sceneid:%v gamefreeid:%v success", p.SnId, scene.sceneId, csp.ID())
|
||||
csp.onPlayerEnter(p, scene)
|
||||
return gamehallproto.OpResultCode_OPRC_Sucess
|
||||
}
|
||||
}
|
||||
|
@ -220,18 +269,13 @@ func (csp *CoinScenePool) PlayerEnter(p *Player, roomId int32, exclude []int32,
|
|||
return gamehallproto.OpResultCode_OPRC_SceneServerMaintain
|
||||
}
|
||||
|
||||
// AudienceEnter 观众入场
|
||||
func (csp *CoinScenePool) AudienceEnter(p *Player, roomId int32, exclude []int32, isChangeRoom bool) gamehallproto.OpResultCode {
|
||||
if ret := csp.CanAudienceEnter(p); ret != gamehallproto.OpResultCode_OPRC_Sucess {
|
||||
logger.Logger.Warnf("(csp *CoinScenePool) AudienceEnter find snid:%v csp.CanEnter coin:%v ret:%v id:%v", p.SnId, p.Coin, ret, csp.dbGameFree.GetId())
|
||||
// audienceEnter 观众入场
|
||||
func (csp *CoinScenePool) audienceEnter(p *Player, roomId int32, exclude []int32, isChangeRoom bool) gamehallproto.OpResultCode {
|
||||
if ret := csp.canAudienceEnter(p); ret != gamehallproto.OpResultCode_OPRC_Sucess {
|
||||
logger.Logger.Warnf("(csp *CoinScenePool) AudienceEnter find snid:%v csp.canEnter coin:%v ret:%v id:%v", p.SnId, p.Coin, ret, csp.dbGameFree.GetId())
|
||||
return ret
|
||||
}
|
||||
|
||||
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
|
||||
if roomId != 0 {
|
||||
if s, ok := csp.scenes[int(roomId)]; ok {
|
||||
|
@ -261,7 +305,8 @@ func (csp *CoinScenePool) AudienceEnter(p *Player, roomId int32, exclude []int32
|
|||
}
|
||||
|
||||
if scene.AudienceEnter(p, isChangeRoom) {
|
||||
csp.OnPlayerEnter(p, scene)
|
||||
logger.Logger.Infof("(csp *CoinScenePool) AudienceEnter snid:%v sceneid:%v gamefreeid:%v success", p.SnId, scene.sceneId, csp.ID())
|
||||
csp.onPlayerEnter(p, scene)
|
||||
return gamehallproto.OpResultCode_OPRC_Sucess
|
||||
}
|
||||
|
||||
|
@ -269,78 +314,14 @@ func (csp *CoinScenePool) AudienceEnter(p *Player, roomId int32, exclude []int32
|
|||
return gamehallproto.OpResultCode_OPRC_NoFindDownTiceRoom
|
||||
}
|
||||
|
||||
// OnPlayerEnter 玩家进入房间完成
|
||||
func (csp *CoinScenePool) OnPlayerEnter(p *Player, scene *Scene) {
|
||||
// onPlayerEnter 玩家进入房间完成
|
||||
func (csp *CoinScenePool) onPlayerEnter(p *Player, scene *Scene) {
|
||||
csp.players[p.SnId] = struct{}{}
|
||||
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 离开房间完成
|
||||
func (csp *CoinScenePool) OnPlayerLeave(s *Scene, p *Player) {
|
||||
func (csp *CoinScenePool) onPlayerLeave(s *Scene, p *Player) {
|
||||
if s == nil || p == nil {
|
||||
return
|
||||
}
|
||||
|
@ -370,17 +351,68 @@ func (csp *CoinScenePool) OnPlayerLeave(s *Scene, p *Player) {
|
|||
}
|
||||
}
|
||||
|
||||
// OnDestroyScene 解散房间
|
||||
// 房间解散一定是游戏服确认的,worldsrv收到游戏房间解散消息后解散房间
|
||||
func (csp *CoinScenePool) OnDestroyScene(sceneId int) {
|
||||
// playerLeave 玩家离开房间
|
||||
func (csp *CoinScenePool) playerLeave(p *Player, reason int) bool {
|
||||
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 {
|
||||
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]
|
||||
if !ok {
|
||||
if !ok || scene == nil {
|
||||
return
|
||||
}
|
||||
|
||||
logger.Logger.Tracef("(csp *CoinScenePool) OnDestroyScene scene:%v", sceneId)
|
||||
|
||||
// todo 是否需要优化
|
||||
// 游戏服异常断开,同步一次金币
|
||||
for id := range scene.players {
|
||||
player := PlayerMgrSington.GetPlayerBySnId(id)
|
||||
if player != nil {
|
||||
|
@ -407,96 +439,13 @@ func (csp *CoinScenePool) OnDestroyScene(sceneId int) {
|
|||
}
|
||||
|
||||
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 // 解除关联
|
||||
delete(csp.scenes, sceneId)
|
||||
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
|
||||
}
|
||||
|
|
|
@ -157,7 +157,7 @@ func (this *BaseCoinScenePool) PlayerEnter(pool *CoinScenePool, p *Player, exclu
|
|||
}
|
||||
} else { //按类型匹配
|
||||
//优先真人
|
||||
if scene == nil && len(scenes) != 0 && matchTrueManRule == MatchTrueManPriority {
|
||||
if len(scenes) != 0 && matchTrueManRule == MatchTrueManPriority {
|
||||
var selScene []*Scene
|
||||
for _, value := range scenes {
|
||||
if value != nil {
|
||||
|
@ -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) NewScene(pool *CoinScenePool, p *Player) *Scene {
|
||||
gameId := int(pool.dbGameRule.GetGameId())
|
||||
gameId := int(pool.dbGameFree.GetGameId())
|
||||
gs := GameSessMgrSington.GetMinLoadSess(gameId)
|
||||
if gs == nil {
|
||||
logger.Logger.Warnf("Get %v game min session failed.", gameId)
|
||||
return nil
|
||||
}
|
||||
|
||||
gameMode := pool.dbGameRule.GetGameMode()
|
||||
gameMode := pool.dbGameFree.GetGameMode()
|
||||
params := common.CopySliceInt32ToInt64(pool.dbGameRule.GetParams())
|
||||
limitPlatform := PlatformMgrSingleton.GetPlatform(pool.platform)
|
||||
if limitPlatform == nil || !limitPlatform.Isolated {
|
||||
|
@ -228,7 +228,7 @@ func (this *BaseCoinScenePool) NewScene(pool *CoinScenePool, p *Player) *Scene {
|
|||
sceneId := SceneMgrSingleton.GenOneCoinSceneId()
|
||||
|
||||
scene := SceneMgrSingleton.CreateScene(0, 0, sceneId, gameId, int(gameMode), common.SceneMode_Public,
|
||||
1, -1, params, gs, limitPlatform, pool.groupId, pool.dbGameFree, pool.id)
|
||||
1, -1, params, gs, limitPlatform, 0, pool.dbGameFree, pool.ID())
|
||||
return scene
|
||||
}
|
||||
|
||||
|
|
|
@ -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),
|
||||
gs, limitPlatform, 0, pool.dbGameFree, baseScore, pool.groupId, pool.id)
|
||||
gs, limitPlatform, 0, pool.dbGameFree, baseScore, 0, pool.ID())
|
||||
return scene
|
||||
}
|
||||
|
||||
|
@ -285,7 +285,7 @@ func (l *CoinScenePoolLocal) NewPreCreateScene(pool *CoinScenePool) *Scene {
|
|||
}
|
||||
if baseScore != 0 {
|
||||
scene = SceneMgrSingleton.CreateLocalGameScene(0, sceneId, gameId, gameSite, common.SceneMode_Public, 1, common.CopySliceInt32ToInt64(params),
|
||||
gs, limitPlatform, playerNum, pool.dbGameFree, baseScore, pool.groupId, pool.id)
|
||||
gs, limitPlatform, playerNum, pool.dbGameFree, baseScore, 0, pool.ID())
|
||||
if scene != nil {
|
||||
logger.Logger.Tracef("CreateLocalGameScene success.gameId:%v gameSite:%v baseScore:%v randIdx:%v", scene.gameId, scene.gameSite, baseScore, randIdx)
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ func (this *GameSessMgr) OnRegiste(s *netlib.Session) {
|
|||
}
|
||||
gs.OnRegiste()
|
||||
//尝试创建百人场
|
||||
HundredSceneMgrSington.TryCreateRoom()
|
||||
HundredSceneMgrSingleton.TryCreateRoom()
|
||||
}
|
||||
} else if srvInfo.GetType() == srvlib.GateServiceType {
|
||||
logger.Logger.Warn("(this *GameSessMgr) OnRegiste (GateSrv):", s)
|
||||
|
|
|
@ -10,383 +10,193 @@ import (
|
|||
"mongo.games.com/game/common"
|
||||
"mongo.games.com/game/model"
|
||||
"mongo.games.com/game/proto"
|
||||
gamehall_proto "mongo.games.com/game/protocol/gamehall"
|
||||
server_proto "mongo.games.com/game/protocol/server"
|
||||
gamehallproto "mongo.games.com/game/protocol/gamehall"
|
||||
serverproto "mongo.games.com/game/protocol/server"
|
||||
"mongo.games.com/game/protocol/webapi"
|
||||
"mongo.games.com/game/srvdata"
|
||||
)
|
||||
|
||||
const (
|
||||
HundredSceneType_Primary int = iota //初级
|
||||
HundredSceneType_Mid //中级
|
||||
HundredSceneType_Senior //高级
|
||||
HundredSceneType_Professor //专家
|
||||
HundredSceneType_Experience //体验场
|
||||
HundredSceneType_Max
|
||||
HundredSceneOPEnter int32 = iota //进入
|
||||
HundredSceneOPLeave //离开
|
||||
HundredSceneOPChange //换桌
|
||||
)
|
||||
|
||||
const (
|
||||
HundredSceneOp_Enter int32 = iota //进入
|
||||
HundredSceneOp_Leave //离开
|
||||
HundredSceneOp_Change //换桌
|
||||
HundredSceneOp_Audience //观战
|
||||
)
|
||||
|
||||
var HundredSceneMgrSington = &HundredSceneMgr{
|
||||
//分平台管理
|
||||
var HundredSceneMgrSingleton = &HundredSceneMgr{
|
||||
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 {
|
||||
//分平台管理
|
||||
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
|
||||
}
|
||||
|
||||
func (this *HundredSceneMgr) GetPlatformNameBySceneId(sceneid int32) (string, bool) {
|
||||
if name, exist := this.platformOfScene[sceneid]; exist {
|
||||
return name, exist
|
||||
}
|
||||
if _, exist := this.groupOfScene[sceneid]; exist {
|
||||
s := SceneMgrSingleton.GetScene(int(sceneid))
|
||||
if s != nil && s.limitPlatform != nil {
|
||||
return s.limitPlatform.IdStr, true
|
||||
}
|
||||
}
|
||||
return DefaultPlatform, false
|
||||
}
|
||||
|
||||
func (this *HundredSceneMgr) RebindPlayerSnId(oldSnId, newSnId int32) {
|
||||
if id, exist := this.playerIning[oldSnId]; exist {
|
||||
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
|
||||
// PlayerEnter 玩家进入场次
|
||||
// id 场次id
|
||||
func (this *HundredSceneMgr) PlayerEnter(p *Player, id int32) gamehallproto.OpResultCode_Hundred {
|
||||
logger.Logger.Tracef("HundredSceneMgr PlayerEnter snid:%v gamefreeid:%v", p.SnId, id)
|
||||
if p.isDelete {
|
||||
return gamehallproto.OpResultCode_Hundred_OPRC_RoomHadClosed_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
|
||||
if this.InHundredScene(p) {
|
||||
logger.Logger.Warnf("HundredSceneMgr PlayerEnter snid:%v find in gamefreeid:%v roomId:%v", p.SnId, p.scene.dbGameFree.Id, p.scene.sceneId)
|
||||
return gamehallproto.OpResultCode_Hundred_OPRC_Error_Hundred
|
||||
}
|
||||
|
||||
//多平台支持
|
||||
var limitPlatform *Platform
|
||||
platformName := DefaultPlatform
|
||||
platform := PlatformMgrSingleton.GetPlatform(p.Platform)
|
||||
if platform != nil && platform.Isolated {
|
||||
platformName = platform.IdStr
|
||||
limitPlatform = platform
|
||||
} else {
|
||||
limitPlatform = PlatformMgrSingleton.GetPlatform(DefaultPlatform)
|
||||
platform := p.GetPlatform()
|
||||
if platform == nil {
|
||||
return gamehallproto.OpResultCode_Hundred_OPRC_RoomHadClosed_Hundred
|
||||
}
|
||||
|
||||
gps := PlatformMgrSingleton.GetGameFree(limitPlatform.IdStr, id)
|
||||
gps := PlatformMgrSingleton.GetGameFree(platform.IdStr, id)
|
||||
if gps == nil {
|
||||
return gamehall_proto.OpResultCode_Hundred_OPRC_RoomHadClosed_Hundred
|
||||
return gamehallproto.OpResultCode_Hundred_OPRC_RoomHadClosed_Hundred
|
||||
}
|
||||
|
||||
if gps.GroupId != 0 { //按分组进入场景游戏
|
||||
pgg := PlatformGameGroupMgrSington.GetGameGroup(gps.GroupId)
|
||||
if pgg != nil {
|
||||
if _, ok := this.scenesOfGroup[gps.GroupId]; !ok {
|
||||
this.scenesOfGroup[gps.GroupId] = make(map[int32]*Scene)
|
||||
|
||||
}
|
||||
if ss, ok := this.scenesOfGroup[gps.GroupId]; ok {
|
||||
if s, ok := ss[id]; !ok {
|
||||
s = this.CreateNewScene(id, gps.GroupId, limitPlatform, pgg.DbGameFree)
|
||||
if s != nil {
|
||||
ss[id] = s
|
||||
this.groupOfScene[int32(s.sceneId)] = gps.GroupId
|
||||
logger.Logger.Tracef("(this *HundredSceneMgr) PlayerEnter(groupid=%v) Create %v scene success.", gps.GroupId, id)
|
||||
} else {
|
||||
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.PlayerEnter(p, -1, true) {
|
||||
this.OnPlayerEnter(p, id)
|
||||
return gamehall_proto.OpResultCode_Hundred_OPRC_Sucess_Hundred
|
||||
} else {
|
||||
logger.Logger.Warnf("(this *HundredSceneMgr) PlayerEnter(groupid=%v) enter %v scene failed.", gps.GroupId, id)
|
||||
}
|
||||
} else {
|
||||
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 _, ok := this.scenesOfPlatform[platform.IdStr]; !ok {
|
||||
this.scenesOfPlatform[platform.IdStr] = 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)
|
||||
}
|
||||
ss := this.scenesOfPlatform[platform.IdStr]
|
||||
if s, ok := ss[id]; !ok || s == nil {
|
||||
s = this.CreateNewScene(id, gps.GroupId, platform, gps.DbGameFree)
|
||||
if s != nil {
|
||||
ss[id] = s
|
||||
s.hp = this
|
||||
logger.Logger.Infof("HundredSceneMgr PlayerEnter(platform=%v snid=%v) Create %v scene success.", platform.IdStr, p.SnId, id)
|
||||
} else {
|
||||
logger.Logger.Warnf("(this *HundredSceneMgr) PlayerEnter(platform=%v) get %v scene failed.", platformName, id)
|
||||
logger.Logger.Errorf("HundredSceneMgr PlayerEnter(platform=%v snid=%v) Create %v scene failed.", platform.IdStr, p.SnId, 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
|
||||
}
|
||||
|
||||
func (this *HundredSceneMgr) OnPlayerEnter(p *Player, id int32) {
|
||||
this.playerIning[p.SnId] = id
|
||||
//尝试进入
|
||||
if s, ok := ss[id]; ok && s != nil {
|
||||
if s.PlayerEnter(p, -1, true) {
|
||||
logger.Logger.Infof("HundredSceneMgr PlayerEnter(platform=%v snid=%v) enter %v scene success.", platform.IdStr, p.SnId, id)
|
||||
return gamehallproto.OpResultCode_Hundred_OPRC_Sucess_Hundred
|
||||
} else {
|
||||
logger.Logger.Errorf("HundredSceneMgr PlayerEnter(platform=%v snid=%v) enter %v scene failed.", platform.IdStr, p.SnId, id)
|
||||
}
|
||||
} else {
|
||||
logger.Logger.Errorf("HundredSceneMgr PlayerEnter(platform=%v) get %v scene failed.", platform.IdStr, id)
|
||||
}
|
||||
|
||||
return gamehallproto.OpResultCode_Hundred_OPRC_SceneServerMaintain_Hundred
|
||||
}
|
||||
|
||||
// PlayerLeave 离开房间
|
||||
// 游戏服通知玩家离开房间
|
||||
func (this *HundredSceneMgr) PlayerLeave(p *Player, reason int) bool {
|
||||
if p == nil {
|
||||
if p == nil || p.scene == nil || p.scene.hp == nil {
|
||||
return false
|
||||
}
|
||||
if _, ok := this.playerIning[p.SnId]; ok {
|
||||
if p.scene != nil {
|
||||
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)
|
||||
|
||||
p.scene.PlayerLeave(p, reason)
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func (this *HundredSceneMgr) PlayerTryLeave(p *Player) gamehall_proto.OpResultCode_Hundred {
|
||||
if p.scene == nil || p.scene.gameSess == nil {
|
||||
logger.Logger.Tracef("(csm *HundredSceneMgr) PlayerTryLeave p.scene == nil || p.scene.gameSess == nil snid:%v ", p.SnId)
|
||||
return 1
|
||||
// PlayerTryLeave 玩家尝试离开房间
|
||||
// 给游戏服发离开消息
|
||||
func (this *HundredSceneMgr) PlayerTryLeave(p *Player) gamehallproto.OpResultCode_Hundred {
|
||||
if !this.InHundredScene(p) {
|
||||
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)}
|
||||
common.TransmitToServer(p.sid, int(gamehallproto.GameHallPacketID_PACKET_CS_LEAVEROOM), pack, p.scene.gameSess.Session)
|
||||
return gamehallproto.OpResultCode_Hundred_OPRC_Sucess_Hundred // ???
|
||||
}
|
||||
|
||||
func (this *HundredSceneMgr) OnPlayerLeave(p *Player) {
|
||||
delete(this.playerIning, p.SnId)
|
||||
}
|
||||
// OnDestroyScene 房间销毁
|
||||
func (this *HundredSceneMgr) OnDestroyScene(sceneId int) {
|
||||
s := SceneMgrSingleton.GetScene(sceneId)
|
||||
if s == nil {
|
||||
return
|
||||
}
|
||||
plt := SceneMgrSingleton.GetPlatformBySceneId(sceneId)
|
||||
if plt == "" {
|
||||
return
|
||||
}
|
||||
if ss, ok := this.scenesOfPlatform[plt]; ok {
|
||||
for id, scene := range ss {
|
||||
if scene.sceneId == sceneId {
|
||||
if scene != s {
|
||||
logger.Logger.Errorf("bug")
|
||||
}
|
||||
|
||||
func (this *HundredSceneMgr) OnDestroyScene(sceneid int) {
|
||||
var s *Scene
|
||||
if platformName, ok := this.platformOfScene[int32(sceneid)]; ok {
|
||||
if ss, ok := this.scenesOfPlatform[platformName]; 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)
|
||||
}
|
||||
}
|
||||
//删除玩家
|
||||
for _, v := range scene.players {
|
||||
if v != nil {
|
||||
if !v.IsRob {
|
||||
ctx := scene.GetPlayerGameCtx(v.SnId)
|
||||
if ctx != nil {
|
||||
//发送一个探针,等待ack后同步金币
|
||||
v.TryRetrieveLostGameCoin(sceneId)
|
||||
logger.Logger.Warnf("(this *HundredSceneMgr) OnDestroyScene(sceneid:%v) snid:%v SyncGameCoin", sceneId, v.SnId)
|
||||
}
|
||||
}
|
||||
}
|
||||
delete(ss, id)
|
||||
break
|
||||
}
|
||||
|
||||
scene.hp = nil
|
||||
delete(ss, id)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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})
|
||||
this.tryCreateRoom(plt, s.dbGameFree.Id)
|
||||
}
|
||||
|
||||
func (this *HundredSceneMgr) GetPlayerNums(p *Player, gameId, gameMode int32) []int32 {
|
||||
//多平台支持
|
||||
platformName := DefaultPlatform
|
||||
platform := PlatformMgrSingleton.GetPlatform(p.Platform)
|
||||
if platform != nil && platform.Isolated {
|
||||
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++ {
|
||||
platform := p.GetPlatform()
|
||||
var nums [10]int32
|
||||
wantNum := [10]int32{80, 50, 30, 20, 10, 10, 10, 10, 10, 10}
|
||||
for i := 0; i < 10; i++ {
|
||||
if wantNum[i]/2 > 0 {
|
||||
nums[i] = rand.Int31n(wantNum[i]/2) + wantNum[i]
|
||||
}
|
||||
}
|
||||
|
||||
if platform == nil {
|
||||
return nums[:]
|
||||
}
|
||||
|
||||
ids, _ := srvdata.GameFreeMgr.GetGameFreeIds(gameId, gameMode)
|
||||
for _, id := range ids {
|
||||
gps := PlatformMgrSingleton.GetGameFree(platform.IdStr, id)
|
||||
if gps != nil {
|
||||
if gps.GroupId != 0 {
|
||||
if ss, exist := this.scenesOfGroup[gps.GroupId]; exist {
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
} 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 ss, ok := this.scenesOfPlatform[platform.IdStr]; ok {
|
||||
if s, exist := ss[id]; exist && s.dbGameFree != nil {
|
||||
sceneType := s.dbGameFree.GetSceneType() - 1
|
||||
if sceneType >= 0 && int(sceneType) < len(nums) {
|
||||
nums[sceneType] += int32(s.GetPlayerCnt())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(ids) <= 10 {
|
||||
return nums[:len(ids)]
|
||||
}
|
||||
return nums[:]
|
||||
}
|
||||
|
||||
func (this *HundredSceneMgr) InHundredScene(p *Player) bool {
|
||||
if p == nil {
|
||||
logger.Logger.Tracef("(this *HundredSceneMgr) InHundredScene p == nil snid:%v ", p.SnId)
|
||||
return false
|
||||
}
|
||||
if _, ok := this.playerIning[p.SnId]; ok {
|
||||
return true
|
||||
if p.scene == nil {
|
||||
return false
|
||||
}
|
||||
logger.Logger.Tracef("(csm *HundredSceneMgr) InHundredScene false snid:%v ", p.SnId)
|
||||
return false
|
||||
if p.scene.hp == nil {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (this *HundredSceneMgr) CreateNewScene(id, groupId int32, limitPlatform *Platform, dbGameFree *server_proto.DB_GameFree) *Scene {
|
||||
func (this *HundredSceneMgr) CreateNewScene(id, groupId int32, limitPlatform *Platform, dbGameFree *serverproto.DB_GameFree) *Scene {
|
||||
if dbGameFree != nil {
|
||||
dbGameRule := srvdata.PBDB_GameRuleMgr.GetData(dbGameFree.GetGameRule())
|
||||
if dbGameRule != nil {
|
||||
|
@ -396,16 +206,11 @@ func (this *HundredSceneMgr) CreateNewScene(id, groupId int32, limitPlatform *Pl
|
|||
sceneId := SceneMgrSingleton.GenOneHundredSceneId()
|
||||
gameMode := dbGameRule.GetGameMode()
|
||||
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)
|
||||
if scene != nil {
|
||||
logger.Logger.Infof("Create hundred scene %v-%v success.", gameId, sceneId)
|
||||
scene.hallId = id
|
||||
//移动到SceneMgr中集中处理
|
||||
//if !scene.IsMatchScene() {
|
||||
// //平台水池设置
|
||||
// gs.DetectCoinPoolSetting(limitPlatform.Name, scene.hallId, scene.groupId)
|
||||
//}
|
||||
scene.hp = this
|
||||
return scene
|
||||
} else {
|
||||
logger.Logger.Errorf("Create hundred scene %v-%v failed.", gameId, sceneId)
|
||||
|
@ -419,135 +224,144 @@ func (this *HundredSceneMgr) CreateNewScene(id, groupId int32, limitPlatform *Pl
|
|||
} else {
|
||||
logger.Logger.Errorf("Game free data %v no found.", id)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (this *HundredSceneMgr) TryCreateRoom() {
|
||||
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)
|
||||
func (this *HundredSceneMgr) tryCreateRoom(plt string, id ...int32) {
|
||||
limitPlatform := PlatformMgrSingleton.GetPlatform(plt)
|
||||
if limitPlatform == nil || !limitPlatform.Isolated {
|
||||
limitPlatform = PlatformMgrSingleton.GetPlatform(DefaultPlatform)
|
||||
}
|
||||
if this.scenesOfPlatform[platform] == nil {
|
||||
this.scenesOfPlatform[platform] = make(map[int32]*Scene)
|
||||
if this.scenesOfPlatform[plt] == nil {
|
||||
this.scenesOfPlatform[plt] = make(map[int32]*Scene)
|
||||
}
|
||||
//var platformName string
|
||||
platformData := PlatformMgrSingleton.GetPlatform(platform)
|
||||
if platformData != nil && platformData.Isolated {
|
||||
//platformName = platformData.Name
|
||||
} else if platform != DefaultPlatform {
|
||||
platformData = PlatformMgrSingleton.GetPlatform(DefaultPlatform)
|
||||
}
|
||||
if platformData.IdStr == DefaultPlatform {
|
||||
if limitPlatform.IdStr == DefaultPlatform {
|
||||
return
|
||||
}
|
||||
if model.GameParamData.HundredScenePreCreate {
|
||||
//不创建已经存在的场景
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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)
|
||||
if platformData != nil && platformData.Isolated {
|
||||
platformName = platformData.IdStr
|
||||
} else if platform != DefaultPlatform {
|
||||
platformData = PlatformMgrSingleton.GetPlatform(DefaultPlatform)
|
||||
}
|
||||
|
||||
if platformData == nil {
|
||||
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 {
|
||||
this.tryCreateRoom(p.IdStr)
|
||||
}
|
||||
}
|
||||
|
||||
func (this *HundredSceneMgr) OnPlatformDestroy(p *Platform) {
|
||||
|
@ -563,34 +377,12 @@ 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) {
|
||||
if p == nil {
|
||||
return
|
||||
}
|
||||
if disabled {
|
||||
if ss, ok := this.scenesOfPlatform[p.IdStr]; ok {
|
||||
var ids []int
|
||||
for _, scene := range ss {
|
||||
ids = append(ids, scene.sceneId)
|
||||
}
|
||||
SceneMgrSingleton.DoDelete(ids, true)
|
||||
}
|
||||
this.OnPlatformDestroy(p)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -598,14 +390,6 @@ func (this *HundredSceneMgr) OnPlatformGameFreeUpdate(p *Platform, oldCfg, newCf
|
|||
if p == nil || newCfg == nil {
|
||||
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 s, ok := scenes[newCfg.DbGameFree.Id]; ok {
|
||||
s.DoDelete(false)
|
||||
|
@ -614,99 +398,7 @@ func (this *HundredSceneMgr) OnPlatformGameFreeUpdate(p *Platform, oldCfg, newCf
|
|||
}
|
||||
|
||||
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) {
|
||||
|
@ -723,8 +415,9 @@ func (this *HundredSceneMgr) OnPlatformDestroyByGameFreeId(p *Platform, gameFree
|
|||
SceneMgrSingleton.DoDelete(ids, true)
|
||||
}
|
||||
}
|
||||
|
||||
func init() {
|
||||
module.RegisteModule(HundredSceneMgrSington, time.Second*5, 0)
|
||||
PlatformMgrSingleton.RegisterObserver(HundredSceneMgrSington)
|
||||
PlatformGameGroupMgrSington.RegisteObserver(HundredSceneMgrSington)
|
||||
module.RegisteModule(HundredSceneMgrSingleton, time.Second*5, 0)
|
||||
PlatformMgrSingleton.RegisterObserver(HundredSceneMgrSingleton)
|
||||
PlatformGameGroupMgrSington.RegisteObserver(HundredSceneMgrSingleton)
|
||||
}
|
||||
|
|
|
@ -3686,8 +3686,6 @@ func (this *Player) TryRetrieveLostGameCoin(sceneid int) {
|
|||
logProbe.SeqNo = this.GameCoinTs
|
||||
logProbe.RoomId = int32(sceneid)
|
||||
LogChannelSingleton.WriteLog(logProbe)
|
||||
//先把玩家身上的钱清掉
|
||||
//this.Coin = 0
|
||||
this.SendDiffData()
|
||||
}
|
||||
|
||||
|
|
|
@ -105,7 +105,8 @@ type Scene struct {
|
|||
BaseScore int32 //tienlen游戏底分
|
||||
matchId int64 //比赛场id
|
||||
|
||||
csp *CoinScenePool // 所在场景池
|
||||
csp *CoinScenePool // 所在场景池
|
||||
hp *HundredSceneMgr // 百人场房间池
|
||||
}
|
||||
|
||||
// NewScene 创建房间
|
||||
|
@ -276,8 +277,7 @@ func (this *Scene) PlayerEnter(p *Player, pos int, ischangeroom bool) bool {
|
|||
case this.IsCoinScene():
|
||||
|
||||
case this.IsHundredScene():
|
||||
// todo 删除这个标记
|
||||
HundredSceneMgrSington.OnPlayerEnter(p, this.paramsEx[0])
|
||||
|
||||
case this.IsMatchScene():
|
||||
|
||||
}
|
||||
|
@ -630,7 +630,6 @@ func (this *Scene) DelPlayer(p *Player) bool {
|
|||
|
||||
switch {
|
||||
case this.IsHundredScene():
|
||||
HundredSceneMgrSington.OnPlayerLeave(p)
|
||||
//case this.IsHallScene():
|
||||
// PlatformMgrSingleton.OnPlayerLeaveScene(this, p)
|
||||
// for i := 0; i < this.playerNum; i++ {
|
||||
|
@ -664,9 +663,7 @@ func (this *Scene) AudienceEnter(p *Player, ischangeroom bool) bool {
|
|||
p.scene = this
|
||||
this.audiences[p.SnId] = p
|
||||
this.gameSess.AddPlayer(p)
|
||||
if this.IsHundredScene() {
|
||||
HundredSceneMgrSington.OnPlayerEnter(p, this.paramsEx[0])
|
||||
}
|
||||
|
||||
//todo:send add msg to gamesrv
|
||||
data, err := p.MarshalData(this.gameId)
|
||||
if err == nil {
|
||||
|
@ -749,9 +746,6 @@ func (this *Scene) DelAudience(p *Player) bool {
|
|||
}
|
||||
p.scene = nil
|
||||
SceneMgrSingleton.OnPlayerLeaveScene(this, p)
|
||||
if this.IsHundredScene() {
|
||||
HundredSceneMgrSington.OnPlayerLeave(p)
|
||||
}
|
||||
//from gameserver, so don't need send msg
|
||||
return true
|
||||
}
|
||||
|
|
|
@ -37,6 +37,14 @@ type SceneMgr struct {
|
|||
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 获取回访码
|
||||
func (m *SceneMgr) AllocReplayCode() string {
|
||||
code, _ := model.GetOneReplayId()
|
||||
|
@ -316,7 +324,7 @@ func (m *SceneMgr) DestroyScene(sceneId int, isCompleted bool) {
|
|||
CoinSceneMgrSingleton.OnDestroyScene(s.sceneId)
|
||||
|
||||
case s.IsHundredScene():
|
||||
HundredSceneMgrSington.OnDestroyScene(s.sceneId)
|
||||
HundredSceneMgrSingleton.OnDestroyScene(s.sceneId)
|
||||
|
||||
case s.IsMatchScene():
|
||||
MatchSceneMgrSingleton.OnDestroyScene(s.sceneId)
|
||||
|
|
|
@ -1765,7 +1765,7 @@ func (this *Tournament) Init() {
|
|||
}
|
||||
ret, err := model.GetMatchAward(v.IdStr)
|
||||
if err != nil {
|
||||
logger.Logger.Tracef("GetMatchAward error %v", err)
|
||||
logger.Logger.Warnf("GetMatchAward error %v", err)
|
||||
continue
|
||||
}
|
||||
if this.MatchAwardNum == nil {
|
||||
|
|
Loading…
Reference in New Issue