比赛观战

This commit is contained in:
sk 2024-08-21 17:22:58 +08:00
parent 00b0e01000
commit 71655d8126
13 changed files with 283 additions and 449 deletions

View File

@ -699,7 +699,7 @@ func (this *Scene) AudienceLeave(p *Player, reason int) {
//当前状态不能离场
if !this.CanChangeCoinScene(p) {
pack := &gamehall.SCLeaveRoom{
OpRetCode: (gamehall.OpResultCode_Game(p.OpCode)), //protocol.OpResultCode_OPRC_Hundred_YouHadBetCannotLeave,
OpRetCode: gamehall.OpResultCode_Game(p.OpCode), //protocol.OpResultCode_OPRC_Hundred_YouHadBetCannotLeave,
RoomId: proto.Int(this.SceneId),
}
proto.SetDefaults(pack)

View File

@ -517,7 +517,7 @@ func TienLenCreateRoomInfoPacket(s *base.Scene, p *base.Player, sceneEx *TienLen
//手牌
for j := int32(0); j < rule.HandCardNum; j++ {
if nowPlayer.cards[j] != rule.InvalideCard {
if s.GetSceneState().GetState() == rule.TienLenSceneStateBilled { //结算状态显示用
if s.GetSceneState().GetState() == rule.TienLenSceneStateBilled || p.IsMarkFlag(base.PlayerState_Audience) { //结算状态显示用
pd1.Cards = append(pd1.Cards, nowPlayer.cards[j])
} else {
pd1.Cards = append(pd1.Cards, rule.InvalideCard)

View File

@ -183,94 +183,6 @@ failed:
return nil
}
type CSAudienceEnterRoomHandler struct {
}
func (this *CSAudienceEnterRoomHandler) Process(s *netlib.Session, packetid int, data interface{}, sid int64) error {
logger.Logger.Trace("CSAudienceEnterRoomHandler Process recv ", data)
if msg, ok := data.(*gamehall.CSEnterRoom); ok {
p := PlayerMgrSington.GetPlayer(sid)
if p == nil {
return nil
}
var code = gamehall.OpResultCode_Game_OPRC_Sucess_Game
var sp ScenePolicy
var dbGameFree *server.DB_GameFree
var cfg *webapiproto.GameFree
scene := SceneMgrSingleton.GetScene(int(msg.GetRoomId()))
if scene == nil {
code = gamehall.OpResultCode_Game_OPRC_RoomNotExist_Game
logger.Logger.Trace("CSAudienceEnterRoomHandler scene == nil")
goto failed
}
if !scene.CanAudience() {
code = gamehall.OpResultCode_Game_OPRC_RoomNotExist_Game
logger.Logger.Tracef("CSAudienceEnterRoomHandler scene.CanAudience() %v", scene.sceneId)
goto failed
}
if scene.IsMatchScene() && !PlatformMgrSingleton.IsMatchAudience(p.Platform, p.SnId) {
code = gamehall.OpResultCode_Game_OPRC_RoomNotExist_Game
logger.Logger.Tracef("CSAudienceEnterRoomHandler scene.IsMatchAudience() %v", scene.sceneId)
goto failed
}
if p.scene != nil {
code = gamehall.OpResultCode_Game_OPRC_CannotWatchReasonInOther_Game
logger.Logger.Trace("CSAudienceEnterRoomHandler p.scene != nil")
goto failed
}
cfg = PlatformMgrSingleton.GetGameFree(p.Platform, scene.dbGameFree.Id)
if cfg != nil && (cfg.GroupId != scene.groupId || cfg.GroupId == 0) {
if scene.limitPlatform != nil {
if scene.limitPlatform.Isolated && p.Platform != scene.limitPlatform.IdStr {
code = gamehall.OpResultCode_Game_OPRC_RoomNotExist_Game
logger.Logger.Tracef("CSEnterRoomHandler ScenePolicy(gameid:%v mode:%v) scene.limitPlatform.Isolated && p.Platform != scene.limitPlatform.Name", scene.gameId, scene.gameMode)
goto failed
}
}
}
//if !scene.starting {
// code = gamehall.OpResultCode_Game_OPRC_CannotWatchReasonRoomNotStart_Game
// logger.Logger.Trace("CSAudienceEnterRoomHandler !scene.starting")
// goto failed
//}
if scene.deleting {
code = gamehall.OpResultCode_Game_OPRC_RoomNotExist_Game
logger.Logger.Trace("CSAudienceEnterRoomHandler scene is deleting")
goto failed
}
if scene.closed {
code = gamehall.OpResultCode_Game_OPRC_RoomHadClosed_Game
logger.Logger.Trace("CSAudienceEnterRoomHandler scene is closed")
goto failed
}
//if scene.IsCoinScene() || scene.IsHundredScene() {
// code = gamehall.OpResultCode_Game_OPRC_Error_Game
// logger.Logger.Trace("CSAudienceEnterRoomHandler scene is IsCoinScene IsHundredScene")
// goto failed
//}
sp = GetScenePolicy(scene.gameId, scene.gameMode)
if sp == nil {
code = gamehall.OpResultCode_Game_OPRC_GameNotExist_Game
logger.Logger.Tracef("CSAudienceEnterRoomHandler ScenePolicy(gameid:%v mode:%v) not registe", scene.gameId, scene.gameMode)
goto failed
}
dbGameFree = scene.dbGameFree
code = gamehall.OpResultCode_Game(CoinSceneMgrSingleton.AudienceEnter(p, dbGameFree.GetId(), msg.GetRoomId(), nil, true))
failed:
if code != gamehall.OpResultCode_Game_OPRC_Sucess_Game {
resp := &gamehall.SCEnterRoom{
OpRetCode: code,
}
proto.SetDefaults(resp)
p.SendToClient(int(gamehall.GameHallPacketID_PACKET_SC_ENTERROOM), resp)
}
}
return nil
}
type CSReturnRoomPacketFactory struct {
}
type CSReturnRoomHandler struct {
@ -1235,10 +1147,95 @@ func (this *CSRecordAndNoticeHandler) Process(s *netlib.Session, packetid int, d
return nil
}
func CSAudienceEnterRoomHandler(s *netlib.Session, packetId int, data interface{}, sid int64) error {
logger.Logger.Trace("CSAudienceEnterRoomHandler Process recv ", data)
msg, ok := data.(*gamehall.CSEnterRoom)
if !ok {
return nil
}
p := PlayerMgrSington.GetPlayer(sid)
if p == nil {
return nil
}
var code = gamehall.OpResultCode_Game_OPRC_Error_Game
var sp ScenePolicy
var cfg *webapiproto.GameFree
// 房间是否存在
scene := SceneMgrSingleton.GetScene(int(msg.GetRoomId()))
if scene == nil {
code = gamehall.OpResultCode_Game_OPRC_RoomNotExist_Game
logger.Logger.Trace("CSAudienceEnterRoomHandler scene == nil")
goto failed
}
// 房间是否正在销毁
if scene.deleting {
code = gamehall.OpResultCode_Game_OPRC_RoomNotExist_Game
logger.Logger.Trace("CSAudienceEnterRoomHandler scene is deleting")
goto failed
}
// 房间是否已经关闭
if scene.closed {
code = gamehall.OpResultCode_Game_OPRC_RoomHadClosed_Game
logger.Logger.Trace("CSAudienceEnterRoomHandler scene is closed")
goto failed
}
// 玩家没有在房间中
if p.scene != nil {
code = gamehall.OpResultCode_Game_OPRC_CannotWatchReasonInOther_Game
logger.Logger.Trace("CSAudienceEnterRoomHandler p.scene != nil")
goto failed
}
// 房间是否可以观战
if !scene.CanAudience() {
code = gamehall.OpResultCode_Game_OPRC_RoomNotExist_Game
logger.Logger.Tracef("CSAudienceEnterRoomHandler scene.CanAudience() %v", scene.sceneId)
goto failed
}
// 比赛场白名单观众
if scene.IsMatchScene() && !PlatformMgrSingleton.IsMatchAudience(p.Platform, p.SnId) {
code = gamehall.OpResultCode_Game_OPRC_RoomNotExist_Game
logger.Logger.Tracef("CSAudienceEnterRoomHandler scene.IsMatchAudience() %v", scene.sceneId)
goto failed
}
// 是不是相同平台
cfg = PlatformMgrSingleton.GetGameFree(p.Platform, scene.dbGameFree.Id)
if cfg == nil || (scene.limitPlatform != nil && scene.limitPlatform.Isolated && p.Platform != scene.limitPlatform.IdStr) {
code = gamehall.OpResultCode_Game_OPRC_RoomNotExist_Game
logger.Logger.Tracef("CSEnterRoomHandler ScenePolicy(gameid:%v mode:%v) scene.limitPlatform.Isolated && p.Platform != scene.limitPlatform.Name", scene.gameId, scene.gameMode)
goto failed
}
// 游戏规则是否存在
sp = GetScenePolicy(scene.gameId, scene.gameMode)
if sp == nil {
code = gamehall.OpResultCode_Game_OPRC_GameNotExist_Game
logger.Logger.Tracef("CSAudienceEnterRoomHandler ScenePolicy(gameid:%v mode:%v) not registe", scene.gameId, scene.gameMode)
goto failed
}
switch {
case scene.IsCoinScene():
code = gamehall.OpResultCode_Game(CoinSceneMgrSingleton.AudienceEnter(p, cfg.GetDbGameFree().GetId(), msg.GetRoomId(), nil, true))
case scene.IsHundredScene():
case scene.IsMatchScene():
code = gamehall.OpResultCode_Game(MatchSceneMgrSingleton.AudienceEnter(p, cfg.GetDbGameFree().GetId(), int(msg.GetRoomId()), nil, true))
}
failed:
if code != gamehall.OpResultCode_Game_OPRC_Sucess_Game {
resp := &gamehall.SCEnterRoom{
OpRetCode: code,
}
p.SendToClient(int(gamehall.GameHallPacketID_PACKET_SC_ENTERROOM), resp)
}
return nil
}
func init() {
// 观众进入房间
common.RegisterHandler(int(gamehall.GameHallPacketID_PACKET_CS_AUDIENCE_ENTERROOM), &CSAudienceEnterRoomHandler{})
netlib.RegisterFactory(int(gamehall.GameHallPacketID_PACKET_CS_AUDIENCE_ENTERROOM), &CSEnterRoomPacketFactory{})
// 返回房间
common.RegisterHandler(int(gamehall.GameHallPacketID_PACKET_CS_RETURNROOM), &CSReturnRoomHandler{})
netlib.RegisterFactory(int(gamehall.GameHallPacketID_PACKET_CS_RETURNROOM), &CSReturnRoomPacketFactory{})
@ -1266,4 +1263,7 @@ func init() {
//我的游戏信息及平台公告
common.RegisterHandler(int(gamehall.GameHallPacketID_PACKET_CS_COMNOTICE), &CSRecordAndNoticeHandler{})
netlib.RegisterFactory(int(gamehall.GameHallPacketID_PACKET_CS_COMNOTICE), &CSRecordAndNoticePacketFactory{})
// 观众进入房间
common.Register(int(gamehall.GameHallPacketID_PACKET_CS_AUDIENCE_ENTERROOM), &gamehall.CSEnterRoom{}, CSAudienceEnterRoomHandler)
}

View File

@ -253,8 +253,11 @@ func init() {
p.GameCoinTs = gameCoinTs
p.dirty = true
}
CoinSceneMgrSingleton.PlayerLeave(p, int(msg.GetReason()))
if scene.IsMatchScene() {
scene.AudienceLeave(p, int(msg.GetReason()))
} else {
CoinSceneMgrSingleton.PlayerLeave(p, int(msg.GetReason()))
}
//变化金币
p.dirty = true
@ -639,7 +642,7 @@ func init() {
if msg, ok := pack.(*serverproto.GWChangeSceneEvent); ok {
scene := SceneMgrSingleton.GetScene(int(msg.GetSceneId()))
if scene != nil {
scene.PlayerTryChange()
//scene.PlayerTryChange()
}
}
return nil

View File

@ -212,6 +212,12 @@ func CSRoomList(s *netlib.Session, packetId int, data interface{}, sid int64) er
}
room.Players = append(room.Players, d)
}
sort.Slice(room.Players, func(i, j int) bool {
if room.Players[i].Rank == room.Players[j].Rank {
return room.Players[i].SnId < room.Players[j].SnId
}
return room.Players[i].Rank < room.Players[j].Rank
})
pack.List = append(pack.List, room)
}
p.SendToClient(int(tournament.TOURNAMENTID_PACKET_TM_SCRoomList), pack)

View File

@ -330,7 +330,7 @@ func (csp *CoinScenePool) onPlayerLeave(s *Scene, p *Player) {
// 玩家离开结算空房间的私人房
if s.IsPrivateScene() {
if s.IsEmpty() {
s.DoDelete(false)
s.SendGameDelete(false)
}
return
}
@ -345,7 +345,7 @@ func (csp *CoinScenePool) onPlayerLeave(s *Scene, p *Player) {
}
}
if hasCnt > int(csp.dbGameFree.GetCreateRoomNum()) {
s.DoDelete(false)
s.SendGameDelete(false)
}
}
}

View File

@ -80,18 +80,14 @@ func (this *GameSession) GetSrvId() int32 {
// 关闭其上的所有场景
func (this *GameSession) CloseAllScene() {
for sceneId, scene := range this.scenes {
if scene.IsMiniGameScene() {
} else {
scDestroyRoom := &gamehall_proto.SCDestroyRoom{
RoomId: proto.Int(sceneId),
OpRetCode: gamehall_proto.OpResultCode_Game_OPRC_Sucess_Game,
IsForce: proto.Int(1),
}
proto.SetDefaults(scDestroyRoom)
scene.Broadcast(int(gamehall_proto.GameHallPacketID_PACKET_SC_DESTROYROOM), scDestroyRoom, 0)
SceneMgrSingleton.DestroyScene(sceneId, true)
scDestroyRoom := &gamehall_proto.SCDestroyRoom{
RoomId: proto.Int(sceneId),
OpRetCode: gamehall_proto.OpResultCode_Game_OPRC_Sucess_Game,
IsForce: proto.Int(1),
}
proto.SetDefaults(scDestroyRoom)
scene.Broadcast(int(gamehall_proto.GameHallPacketID_PACKET_SC_DESTROYROOM), scDestroyRoom, 0)
SceneMgrSingleton.DestroyScene(sceneId, true)
}
this.scenes = nil
this.players = nil

View File

@ -392,7 +392,7 @@ func (this *HundredSceneMgr) OnPlatformGameFreeUpdate(p *Platform, oldCfg, newCf
}
if scenes, exist := this.scenesOfPlatform[p.IdStr]; exist {
if s, ok := scenes[newCfg.DbGameFree.Id]; ok {
s.DoDelete(false)
s.SendGameDelete(false)
}
}
}

View File

@ -5,6 +5,7 @@ import (
"mongo.games.com/game/common"
"mongo.games.com/game/proto"
hallproto "mongo.games.com/game/protocol/gamehall"
"mongo.games.com/game/protocol/server"
)
@ -172,11 +173,22 @@ func (ms *MatchSceneMgr) OnDestroyScene(sceneId int) {
delete(ms.scenes, sceneId)
}
func (ms *MatchSceneMgr) AudienceEnter(p *Player, id int32, roomId int, exclude []int32, ischangeroom bool) hallproto.OpResultCode {
scene, ok := ms.scenes[roomId]
if !ok {
return hallproto.OpResultCode_OPRC_RoomHadClosed
}
if !scene.AudienceEnter(p, ischangeroom) {
return hallproto.OpResultCode_OPRC_RoomHadClosed
}
return hallproto.OpResultCode_OPRC_Sucess
}
func (ms *MatchSceneMgr) MatchStop(tm *TmMatch) {
if SceneMgrSingleton.scenes != nil && tm != nil {
for _, scene := range SceneMgrSingleton.scenes {
if scene.IsMatchScene() && scene.matchId == tm.SortId {
scene.DoDelete(false)
scene.SendGameDelete(false)
}
}
}

View File

@ -1662,7 +1662,7 @@ func (this *Player) OnLogouted() {
this.Save(true)
}
func (this *Player) MarshalData(gameid int) (d []byte, e error) {
func (this *Player) MarshalData() (d []byte, e error) {
d, e = netlib.Gob.Marshal(this.PlayerData)
return
}

View File

@ -18,7 +18,6 @@ import (
"mongo.games.com/game/model"
"mongo.games.com/game/proto"
hallproto "mongo.games.com/game/protocol/gamehall"
playerproto "mongo.games.com/game/protocol/player"
serverproto "mongo.games.com/game/protocol/server"
"mongo.games.com/game/srvdata"
)
@ -50,11 +49,11 @@ type PlayerGameCtx struct {
type Scene struct {
sceneId int //场景id
gameId int //游戏id
gameMode int //游戏模式
gameMode int //游戏模式(玩法)
sceneMode int //房间模式,参考common.SceneMode_XXX
params []int64 //场景参数
paramsEx []int32 //其他扩展参数
playerNum int //人数
playerNum int //房间最大人数
robotNum int //机器人数量
robotLimit int //最大限制机器人数量
preInviteRobNum int //准备邀请机器人的数量
@ -145,7 +144,7 @@ func NewScene(agentor, creator int32, id, gameId, gameMode, sceneMode int, clycl
s.playerNum = int(sp.GetPlayerNum(s))
s.lastTime = s.createTime
if s.IsHallScene() || s.IsCoinScene() {
if s.IsCoinScene() {
code := SceneMgrSingleton.AllocReplayCode()
s.replayCode = code
}
@ -228,6 +227,13 @@ func (this *Scene) RobotIsLimit() bool {
return false
}
func (this *Scene) GetPlayerGameCtx(snid int32) *PlayerGameCtx {
if ctx, exist := this.gameCtx[snid]; exist {
return ctx
}
return nil
}
func (this *Scene) PlayerEnter(p *Player, pos int, ischangeroom bool) bool {
logger.Logger.Infof("(this *Scene:%v) PlayerEnter(%v, %v) ", this.sceneId, p.SnId, pos)
@ -273,15 +279,6 @@ func (this *Scene) PlayerEnter(p *Player, pos int, ischangeroom bool) bool {
this.players[p.SnId] = p
this.gameSess.AddPlayer(p)
switch {
case this.IsCoinScene():
case this.IsHundredScene():
case this.IsMatchScene():
}
// 如果正在等待比赛,退赛
if !this.IsMatchScene() {
isWaiting, tmid := TournamentMgr.IsMatchWaiting(p.Platform, p.SnId)
@ -458,8 +455,7 @@ func (this *Scene) PlayerEnter(p *Player, pos int, ischangeroom bool) bool {
logger.Logger.Tracef("(this *Scene) PlayerEnter(%v) robot(%v) robotlimit(%v)", name, this.robotNum, this.robotLimit)
}
//todo:send add msg to gamesrv
data, err := p.MarshalData(this.gameId)
data, err := p.MarshalData()
if err == nil {
var gateSid int64
if p.gateSess != nil {
@ -563,158 +559,111 @@ func (this *Scene) PlayerEnter(p *Player, pos int, ischangeroom bool) bool {
}
}
func ExePMCmd(s *netlib.Session, cmd string) {
CSPMCmd := &playerproto.CSPMCmd{
Cmd: proto.String(cmd),
func (this *Scene) AudienceEnter(p *Player, ischangeroom bool) bool {
logger.Logger.Infof("(this *Scene:%v) AudienceEnter(%v) ", this.sceneId, p.SnId)
p.scene = this
takeCoin := p.Coin
p.takeCoin = takeCoin
this.audiences[p.SnId] = p
this.gameSess.AddPlayer(p)
data, err := p.MarshalData()
if err != nil {
return false
}
proto.SetDefaults(CSPMCmd)
logger.Logger.Trace("CSPMCmd:", CSPMCmd)
s.Send(int(playerproto.PlayerPacketID_PACKET_CS_PMCMD), CSPMCmd)
}
func (this *Scene) GetPlayerGameCtx(snid int32) *PlayerGameCtx {
if ctx, exist := this.gameCtx[snid]; exist {
return ctx
var gateSid int64
if p.gateSess != nil {
if srvInfo, ok := p.gateSess.GetAttribute(srvlib.SessionAttributeServerInfo).(*srvlibproto.SSSrvRegiste); ok && srvInfo != nil {
sessionId := srvlib.NewSessionIdEx(srvInfo.GetAreaId(), srvInfo.GetType(), srvInfo.GetId(), 0)
gateSid = sessionId.Get()
}
}
return nil
}
func (this *Scene) PlayerLeave(p *Player, reason int) {
logger.Logger.Infof("(this *Scene:%v) PlayerLeave(%v, %v) ", this.sceneId, p.SnId, reason)
//if !this.IsMatchScene() {
//pack := &hall_proto.SCLeaveRoom{
// Reason: proto.Int(reason),
// OpRetCode: hall_proto.OpResultCode_Game_OPRC_Sucess_Game,
// Mode: proto.Int(0),
// RoomId: proto.Int(this.sceneId),
//}
//proto.SetDefaults(pack)
//p.SendToClient(int(hall_proto.GameHallPacketID_PACKET_SC_LEAVEROOM), pack)
pack := &hallproto.SCQuitGame{
Id: int32(this.dbGameFree.Id),
Reason: proto.Int(reason),
msg := &serverproto.WGPlayerEnter{
Sid: proto.Int64(p.sid),
SnId: proto.Int32(p.SnId),
GateSid: proto.Int64(gateSid),
SceneId: proto.Int(this.sceneId),
PlayerData: data,
TakeCoin: takeCoin,
IsLoaded: proto.Bool(ischangeroom),
IsQM: false,
IParams: p.MarshalIParam(),
SParams: p.MarshalSParam(),
CParams: p.MarshalCParam(),
}
pack.OpCode = hallproto.OpResultCode_Game_OPRC_Sucess_Game
proto.SetDefaults(pack)
p.SendToClient(int(hallproto.GameHallPacketID_PACKET_SC_QUITGAME), pack)
//}
//其他人直接从房间退出来
this.DelPlayer(p)
// 玩家最后所在游戏
p.LastGameId = int(this.dbGameFree.GetGameId())
if !p.IsRob {
if !p.IsRob { //保存下进入时的环境
p.enterts = time.Now()
this.gameCtx[p.SnId] = &PlayerGameCtx{
takeCoin: p.takeCoin,
enterTs: p.enterts.Unix(),
}
this.lastTime = time.Now()
}
this.SendToGame(int(serverproto.SSPacketID_PACKET_WG_AUDIENCEENTER), msg)
return true
}
func (this *Scene) DelPlayer(p *Player) bool {
if p.scene != this {
inroomid := 0
roomId := 0
if p.scene != nil {
inroomid = p.scene.sceneId
roomId = p.scene.sceneId
}
logger.Logger.Warnf("(this *Scene) DelPlayer found player:%v in room:%v but room:%v", p.SnId, inroomid, this.sceneId)
logger.Logger.Errorf("DelPlayer found player:%v in room:%v but room:%v", p.SnId, roomId, this.sceneId)
}
if this.gameSess != nil {
this.gameSess.DelPlayer(p)
}
delete(this.players, p.SnId)
// 玩家离开游戏
if _, ok := this.players[p.SnId]; ok {
delete(this.players, p.SnId)
if p.IsRobot() {
this.robotNum--
}
// 记录玩家最近玩游戏的房间
SceneMgrSingleton.OnPlayerLeaveScene(this, p)
// 玩家最后所在游戏
p.LastGameId = int(this.dbGameFree.GetGameId())
}
// 观众离开游戏
if _, ok := this.audiences[p.SnId]; ok {
delete(this.audiences, p.SnId)
}
for k, v := range this.seats {
if v != nil && v.SnId == p.SnId {
p.pos = -1
this.seats[k] = nil
break
}
}
if !p.IsRob {
delete(this.gameCtx, p.SnId)
}
p.scene = nil
SceneMgrSingleton.OnPlayerLeaveScene(this, p)
switch {
case this.IsHundredScene():
//case this.IsHallScene():
// PlatformMgrSingleton.OnPlayerLeaveScene(this, p)
// for i := 0; i < this.playerNum; i++ {
// if this.seats[i] == p {
// p.pos = -1
// this.seats[i] = nil
// break
// }
// }
case this.IsCoinScene() || this.IsMatchScene():
for i := 0; i < this.playerNum; i++ {
if this.seats[i] == p {
p.pos = -1
this.seats[i] = nil
break
}
}
if !p.IsRob {
this.lastTime = time.Now()
}
if p.IsRob {
this.robotNum--
name := this.GetSceneName()
logger.Logger.Tracef("(this *Scene) PlayerLeave(%v) robot(%v) robotlimit(%v)", name, this.robotNum, this.robotLimit)
}
//from gameserver, so don't need send msg
return true
}
func (this *Scene) AudienceEnter(p *Player, ischangeroom bool) bool {
logger.Logger.Infof("(this *Scene:%v) AudienceEnter(%v) ", this.sceneId, p.SnId)
p.scene = this
this.audiences[p.SnId] = p
this.gameSess.AddPlayer(p)
//todo:send add msg to gamesrv
data, err := p.MarshalData(this.gameId)
if err == nil {
var gateSid int64
if p.gateSess != nil {
if srvInfo, ok := p.gateSess.GetAttribute(srvlib.SessionAttributeServerInfo).(*srvlibproto.SSSrvRegiste); ok && srvInfo != nil {
sessionId := srvlib.NewSessionIdEx(srvInfo.GetAreaId(), srvInfo.GetType(), srvInfo.GetId(), 0)
gateSid = sessionId.Get()
}
}
isQuMin := false
//if !p.IsRob {
// pt := PlatformMgrSingleton.GetPackageTag(p.PackageID)
// if pt != nil && pt.SpreadTag == 1 {
// isQuMin = true
// }
//}
msg := &serverproto.WGPlayerEnter{
Sid: proto.Int64(p.sid),
SnId: proto.Int32(p.SnId),
GateSid: proto.Int64(gateSid),
SceneId: proto.Int(this.sceneId),
PlayerData: data,
IsLoaded: proto.Bool(ischangeroom),
IsQM: proto.Bool(isQuMin),
IParams: p.MarshalIParam(),
SParams: p.MarshalSParam(),
CParams: p.MarshalCParam(),
}
if !p.IsRob { //保存下进入时的环境
this.gameCtx[p.SnId] = &PlayerGameCtx{
takeCoin: p.takeCoin,
enterTs: p.enterts.Unix(),
totalConvertibleFlow: p.TotalConvertibleFlow,
}
this.lastTime = time.Now()
}
takeCoin := p.Coin
p.takeCoin = takeCoin
msg.TakeCoin = proto.Int64(takeCoin)
proto.SetDefaults(msg)
this.SendToGame(int(serverproto.SSPacketID_PACKET_WG_AUDIENCEENTER), msg)
p.enterts = time.Now()
return true
// PlayerLeave 玩家离开
func (this *Scene) PlayerLeave(p *Player, reason int) {
logger.Logger.Infof("(this *Scene:%v) PlayerLeave(%v, %v) ", this.sceneId, p.SnId, reason)
pack := &hallproto.SCQuitGame{
Id: this.dbGameFree.Id,
Reason: proto.Int(reason),
}
return false
pack.OpCode = hallproto.OpResultCode_Game_OPRC_Sucess_Game
p.SendToClient(int(hallproto.GameHallPacketID_PACKET_SC_QUITGAME), pack)
logger.Logger.Tracef("SCQuitGame: %v, %v", p.SnId, pack)
this.DelPlayer(p)
}
// AudienceLeave 观众离开
func (this *Scene) AudienceLeave(p *Player, reason int) {
logger.Logger.Infof("(this *Scene:%v) AudienceLeave(%v, %v) ", this.sceneId, p.SnId, reason)
pack := &hallproto.SCLeaveRoom{
@ -723,97 +672,25 @@ func (this *Scene) AudienceLeave(p *Player, reason int) {
Mode: proto.Int(0),
RoomId: proto.Int(this.sceneId),
}
proto.SetDefaults(pack)
p.SendToClient(int(hallproto.GameHallPacketID_PACKET_SC_LEAVEROOM), pack)
//观众直接从房间退出来
this.DelAudience(p)
if !p.IsRob {
this.lastTime = time.Now()
}
logger.Logger.Tracef("AudienceLeave SCLeaveRoom: %v, %v", p.SnId, pack)
this.DelPlayer(p)
}
func (this *Scene) DelAudience(p *Player) bool {
logger.Logger.Infof("(this *Scene:%v) DelAudience(%v) ", this.sceneId, p.SnId)
if p.scene != this {
return false
}
if this.gameSess != nil {
this.gameSess.DelPlayer(p)
}
delete(this.audiences, p.SnId)
if !p.IsRob {
delete(this.gameCtx, p.SnId)
}
p.scene = nil
SceneMgrSingleton.OnPlayerLeaveScene(this, p)
//from gameserver, so don't need send msg
return true
}
//观众坐下
//func (this *Scene) AudienceSit(p *Player, pos int) bool {
// logger.Logger.Infof("(this *Scene:%v) AudienceSit(%v, %v, %v) ", this.sceneId, p.SnId, pos)
// if _, exist := this.audiences[p.SnId]; exist {
// if pos == -1 && !this.IsHundredScene() { //自动匹配;百人场没座位概念
// for i := 0; i < this.playerNum; i++ {
// if this.seats[i] == nil {
// pos = i
// break
// }
// }
// }
// if pos != -1 || this.IsHundredScene() {
// if !this.IsHundredScene() {
// if this.seats[pos] != nil {
// return false
// }
// p.pos = pos
// p.applyPos = -1
// this.seats[pos] = p
// }
// delete(this.audiences, p.SnId)
// }
//
// p.scene = this
// this.players[p.SnId] = p
//
// NpcServerAgentSington.OnPlayerEnterScene(this, p)
// if this.IsCoinScene() {
// CoinSceneMgrSingleton.OnPlayerEnter(p, int32(this.sceneId))
// } else if this.IsHallScene() {
// PlatformMgrSingleton.OnPlayerEnterScene(this, p)
// }
//
// msg := &protocol.WGAudienceSit{
// SnId: proto.Int32(p.SnId),
// SceneId: proto.Int(this.sceneId),
// Pos: proto.Int(pos),
// }
// p.takeCoin = p.Coin
// msg.TakeCoin = proto.Int64(p.Coin)
// proto.SetDefaults(msg)
// this.SendToGame(int(protocol.MmoPacketID_PACKET_WG_AUDIENCESIT), msg)
// this.lastTime = time.Now()
// return true
// }
// return false
//}
// AudienceSit 观众坐下
func (this *Scene) AudienceSit(p *Player, pos int) bool {
logger.Logger.Infof("(this *Scene:%v) AudienceSit(%v, %v, %v) ", this.sceneId, p.SnId, pos, this.dbGameFree.GetId())
if _, exist := this.audiences[p.SnId]; exist {
delete(this.audiences, p.SnId)
p.scene = this
this.players[p.SnId] = p
msg := &serverproto.WGAudienceSit{
SnId: proto.Int32(p.SnId),
SceneId: proto.Int(this.sceneId),
Pos: proto.Int(pos),
}
p.takeCoin = p.Coin
msg.TakeCoin = proto.Int64(p.Coin)
proto.SetDefaults(msg)
this.players[p.SnId] = p
msg := &serverproto.WGAudienceSit{
SnId: proto.Int32(p.SnId),
TakeCoin: p.Coin,
SceneId: proto.Int(this.sceneId),
Pos: proto.Int(pos),
}
this.SendToGame(int(serverproto.SSPacketID_PACKET_WG_AUDIENCESIT), msg)
if !p.IsRob {
this.lastTime = time.Now()
@ -871,6 +748,8 @@ func (this *Scene) GetAudienceCnt() int {
return len(this.audiences)
}
// IsFull 是否满人
// 不包含观众
func (this *Scene) IsFull() bool {
return this.GetPlayerCnt() >= this.playerNum
}
@ -883,23 +762,24 @@ func (this *Scene) AllIsRobot() bool {
return len(this.players) == this.robotNum
}
// OnClose 房间销毁
func (this *Scene) OnClose() {
scDestroyRoom := &hallproto.SCDestroyRoom{
RoomId: proto.Int(this.sceneId),
OpRetCode: hallproto.OpResultCode_Game_OPRC_Sucess_Game,
IsForce: proto.Int(1),
}
proto.SetDefaults(scDestroyRoom)
this.Broadcast(int(hallproto.GameHallPacketID_PACKET_SC_DESTROYROOM), scDestroyRoom, 0)
this.deleting = true
this.closed = true
this.sp.OnStop(this)
//NpcServerAgentSington.OnSceneClose(this)
for _, p := range this.players {
this.DelPlayer(p)
}
for _, p := range this.audiences {
this.DelAudience(p)
this.DelPlayer(p)
}
this.players = nil
this.audiences = nil
@ -913,17 +793,13 @@ func (this *Scene) SendToGame(packetId int, pack interface{}) bool {
}
return false
}
func (this *Scene) SendToClient(packetid int, rawpack interface{}, excludeId int32) {
for snid, value := range this.players {
if snid == excludeId {
func (this *Scene) SendToClient(packetId int, pack interface{}, excludeId int32) {
for v, value := range this.players {
if v == excludeId {
continue
}
value.SendToClient(packetid, rawpack)
}
}
func (this *Scene) BilledRoomCard(snid []int32) {
if this.sp != nil {
this.sp.BilledRoomCard(this, snid)
value.SendToClient(packetId, pack)
}
}
@ -936,7 +812,7 @@ func (this *Scene) IsLongTimeInactive() bool {
return false
}
func (this *Scene) DoDelete(isGrace bool) {
func (this *Scene) SendGameDelete(isGrace bool) {
if !isGrace {
this.deleting = true
this.force = true
@ -949,46 +825,32 @@ func (this *Scene) DoDelete(isGrace bool) {
logger.Logger.Tracef("WG_DESTROYSCENE: %v", pack)
}
func (this *Scene) Shutdown() {
if this.hadCost && this.sp != nil {
this.sp.OnShutdown(this)
}
}
// 小游戏场
func (this *Scene) IsMiniGameScene() bool {
return this.sceneId >= common.MiniGameSceneStartId && this.sceneId < common.MiniGameSceneMaxId
}
// 比赛场
// IsMatchScene 比赛场
func (this *Scene) IsMatchScene() bool {
return this.sceneId >= common.MatchSceneStartId && this.sceneId < common.MatchSceneMaxId
}
// 大厅场
func (this *Scene) IsHallScene() bool {
return this.sceneId >= common.HallSceneStartId && this.sceneId < common.HallSceneMaxId
}
// 金币场
// IsCoinScene 金币场
func (this *Scene) IsCoinScene() bool {
return this.sceneId >= common.CoinSceneStartId && this.sceneId < common.CoinSceneMaxId
}
// 百人场
// IsHundredScene 百人场
func (this *Scene) IsHundredScene() bool {
return this.sceneId >= common.HundredSceneStartId && this.sceneId < common.HundredSceneMaxId
}
// 私人房间
// IsPrivateScene 私人房间
func (this *Scene) IsPrivateScene() bool {
return this.sceneId >= common.PrivateSceneStartId && this.sceneId < common.PrivateSceneMaxId || this.sceneMode == common.SceneMode_Private
}
// IsSceneMode 房间模式
func (this *Scene) IsSceneMode(mode int) bool {
return this.sceneMode == mode
}
// IsRankMatch 排位赛
func (this *Scene) IsRankMatch() bool {
if this.dbGameFree == nil {
return false
@ -996,6 +858,7 @@ func (this *Scene) IsRankMatch() bool {
return this.dbGameFree.RankType > 0
}
// IsTestScene 试玩场
func (this *Scene) IsTestScene() bool {
if this.dbGameFree != nil {
return this.dbGameFree.GetSceneType() == -1
@ -1010,6 +873,9 @@ func (this *Scene) IsTestScene() bool {
}
func (this *Scene) GetSceneName() string {
if this.dbGameFree != nil {
return this.dbGameFree.GetName() + this.dbGameFree.GetTitle()
}
if len(this.paramsEx) > 0 {
dbGameFree := srvdata.PBDB_GameFreeMgr.GetData(this.paramsEx[0])
if dbGameFree != nil {
@ -1020,6 +886,21 @@ func (this *Scene) GetSceneName() string {
}
func (this *Scene) RandRobotCnt() {
if this.dbGameFree != nil {
numrng := this.dbGameFree.GetRobotNumRng()
if len(numrng) >= 2 {
if numrng[1] == numrng[0] {
this.robotLimit = int(numrng[0])
} else {
if numrng[1] < numrng[0] {
numrng[1], numrng[0] = numrng[0], numrng[1]
}
this.robotLimit = int(numrng[1]) //int(numrng[0] + rand.Int31n(numrng[1]-numrng[0]) + 1)
}
}
return
}
if len(this.paramsEx) > 0 {
gps := PlatformMgrSingleton.GetGameFree(this.limitPlatform.IdStr, this.paramsEx[0])
if gps != nil {
@ -1045,7 +926,7 @@ func (this *Scene) RandRobotCnt() {
}
}
func (this *Scene) isPlatform(platform string) bool {
func (this *Scene) IsPlatform(platform string) bool {
if platform == "0" || platform == this.limitPlatform.IdStr {
return true
}
@ -1106,31 +987,7 @@ func (this *Scene) GetTruePlayerCnt() int {
return len(this.players) - this.robotNum
}
func (this *Scene) GetPlayerType(gameid, gamefreeid int32) (types []int32) {
for _, p := range this.players {
t := int32(0)
if p.IsRob {
t = common.PlayerType_Rob
} else if p.WBLevel < 0 {
t = common.PlayerType_Black
} else if p.WBLevel > 0 {
t = common.PlayerType_White
} else {
pt := p.CheckType(gameid, gamefreeid)
if pt != nil {
t = pt.GetId()
} else {
t = common.PlayerType_Undefine
}
}
if !common.InSliceInt32(types, t) {
types = append(types, t)
}
}
return
}
func (this *Scene) Broadcast(packetid int, msg rawproto.Message, excludeSid int64) {
func (this *Scene) Broadcast(packetId int, msg rawproto.Message, excludeSid int64) {
mgs := make(map[*netlib.Session][]*srvlibproto.MCSessionUnion)
for _, p := range this.players {
if p != nil {
@ -1159,7 +1016,7 @@ func (this *Scene) Broadcast(packetid int, msg rawproto.Message, excludeSid int6
for gateSess, v := range mgs {
if gateSess != nil && len(v) != 0 {
pack, err := common.CreateMulticastPacket(packetid, msg, v...)
pack, err := common.CreateMulticastPacket(packetId, msg, v...)
if err == nil {
proto.SetDefaults(pack)
gateSess.Send(int(srvlibproto.SrvlibPacketID_PACKET_SS_MULTICAST), pack)
@ -1171,12 +1028,11 @@ func (this *Scene) Broadcast(packetid int, msg rawproto.Message, excludeSid int6
func (this *Scene) HasSameIp(ip string) bool {
for _, p := range this.players {
if !p.IsRob {
if p.GMLevel == 0 && p.Ip == ip {
if p.Ip == ip {
return true
}
}
}
return false
}
@ -1184,45 +1040,6 @@ func (this *Scene) IsPreCreateScene() bool {
return this.dbGameFree.GetCreateRoomNum() > 0
}
func (this *Scene) PlayerTryChange() {
var member []*Player
var player *Player
for _, value := range this.players {
if !value.IsRob {
member = append(member, value)
player = value
}
}
if len(member) <= 1 {
return
}
gameFreeId := this.dbGameFree.GetId()
gameConfig := PlatformMgrSingleton.GetGameFree(player.Platform, gameFreeId)
if gameConfig != nil && gameConfig.DbGameFree.GetMatchMode() == 1 {
return
}
for i := 0; i < len(member)-1; i++ {
p := member[i]
other := member[i+1:]
if this.dbGameFree.GetSamePlaceLimit() > 0 && sceneLimitMgr.LimitSamePlaceBySnid(other, p,
this.dbGameFree.GetGameId(), this.dbGameFree.GetSamePlaceLimit()) {
if p.scene.IsPrivateScene() {
//if ClubSceneMgrSington.PlayerInChanging(p) {
// continue
//}
//ClubSceneMgrSington.PlayerTryChange(p, gameFreeId, []int32{int32(this.sceneId)}, false)
} else {
if CoinSceneMgrSingleton.PlayerInChanging(p) {
continue
}
excludeSceneIds := p.lastSceneId[gameFreeId]
CoinSceneMgrSingleton.PlayerTryChange(p, gameFreeId, excludeSceneIds, false)
}
}
}
}
func (this *Scene) GetParamEx(idx int) int32 {
if idx < 0 || idx > len(this.paramsEx) {
return -1
@ -1238,7 +1055,7 @@ func (this *Scene) SetParamEx(idx int, val int32) {
}
}
func (this *Scene) TryForceDelectMatchInfo() {
func (this *Scene) TryForceDeleteMatchInfo() {
if !this.IsMatchScene() {
return
}

View File

@ -435,18 +435,18 @@ func (m *SceneMgr) OnMiniTimer() {
case s.IsCoinScene():
if s.IsLongTimeInactive() {
if s.dbGameFree.GetCreateRoomNum() == 0 {
logger.Logger.Warnf("SceneMgr.DeleteLongTimeInactive CoinScene DoDelete scene:%v IsLongTimeInactive", s.sceneId)
s.DoDelete(false)
logger.Logger.Warnf("SceneMgr.DeleteLongTimeInactive CoinScene SendGameDelete scene:%v IsLongTimeInactive", s.sceneId)
s.SendGameDelete(false)
}
if s.dbGameFree.GetCreateRoomNum() > 0 && s.csp != nil && s.csp.GetRoomNum() > int(s.dbGameFree.GetCreateRoomNum()) {
logger.Logger.Warnf("SceneMgr.DeleteLongTimeInactive CoinScene DoDelete scene:%v IsLongTimeInactive", s.sceneId)
s.DoDelete(false)
logger.Logger.Warnf("SceneMgr.DeleteLongTimeInactive CoinScene SendGameDelete scene:%v IsLongTimeInactive", s.sceneId)
s.SendGameDelete(false)
}
}
case s.IsPrivateScene():
if s.IsLongTimeInactive() {
logger.Logger.Warnf("SceneMgr.DeleteLongTimeInactive PrivateScene DoDelete scene:%v IsLongTimeInactive", s.sceneId)
s.DoDelete(false)
logger.Logger.Warnf("SceneMgr.DeleteLongTimeInactive PrivateScene SendGameDelete scene:%v IsLongTimeInactive", s.sceneId)
s.SendGameDelete(false)
}
}
}

View File

@ -1747,24 +1747,24 @@ func init() {
switch msg.DestroyType {
case 1: //删除所有空房间
for _, s := range SceneMgrSingleton.scenes {
if !s.isPlatform(platform) {
if !s.IsPlatform(platform) {
continue
}
if s != nil && !s.deleting && len(s.players) == 0 {
logger.Logger.Warnf("WebService SpecailEmptySceneId destroyroom scene:%v", s.sceneId)
s.TryForceDelectMatchInfo()
s.DoDelete(false)
s.TryForceDeleteMatchInfo()
s.SendGameDelete(false)
}
}
case 2: //删除所有未开始的房间
for _, s := range SceneMgrSingleton.scenes {
if !s.isPlatform(platform) {
if !s.IsPlatform(platform) {
continue
}
if s != nil && !s.deleting && !s.starting && !s.IsHundredScene() {
logger.Logger.Warnf("WebService SpecailUnstartSceneId destroyroom scene:%v", s.sceneId)
s.TryForceDelectMatchInfo()
s.DoDelete(false)
s.TryForceDeleteMatchInfo()
s.SendGameDelete(false)
}
}
default: //删除指定房间
@ -1780,14 +1780,14 @@ func init() {
pack.Msg = "the sceneid is nil"
return common.ResponseTag_NoFindRoom, pack
}
if !s.isPlatform(platform) {
if !s.IsPlatform(platform) {
pack.Tag = webapiproto.TagCode_FAILED
pack.Msg = "the sceneid is not ower platform"
return common.ResponseTag_NoFindRoom, pack
}
logger.Logger.Warnf("WebService destroyroom scene:%v", s.sceneId)
s.TryForceDelectMatchInfo()
s.DoDelete(false)
s.TryForceDeleteMatchInfo()
s.SendGameDelete(false)
}
}
return common.ResponseTag_Ok, pack