review
This commit is contained in:
parent
71655d8126
commit
7ebe12c3de
|
@ -370,7 +370,7 @@ func (m *CoinSceneMgr) OnPlatformDestroy(p *Platform) {
|
|||
}
|
||||
}
|
||||
}
|
||||
SceneMgrSingleton.DoDelete(ids, true)
|
||||
SceneMgrSingleton.SendGameDestroy(ids, true)
|
||||
}
|
||||
|
||||
func (m *CoinSceneMgr) OnPlatformChangeDisabled(p *Platform, disabled bool) {
|
||||
|
@ -395,7 +395,7 @@ func (m *CoinSceneMgr) OnPlatformGameFreeUpdate(p *Platform, oldCfg, newCfg *web
|
|||
for _, scene := range cps.scenes {
|
||||
ids = append(ids, scene.sceneId)
|
||||
}
|
||||
SceneMgrSingleton.DoDelete(ids, true)
|
||||
SceneMgrSingleton.SendGameDestroy(ids, true)
|
||||
m.TouchCreateRoom(p.IdStr, newCfg.DbGameFree.Id)
|
||||
}
|
||||
}
|
||||
|
@ -414,7 +414,7 @@ func (m *CoinSceneMgr) OnPlatformDestroyByGameFreeId(p *Platform, gameFreeId int
|
|||
}
|
||||
}
|
||||
}
|
||||
SceneMgrSingleton.DoDelete(ids, true)
|
||||
SceneMgrSingleton.SendGameDestroy(ids, true)
|
||||
}
|
||||
|
||||
//=========================PlatformGameGroupObserver==============================
|
||||
|
|
|
@ -330,7 +330,7 @@ func (csp *CoinScenePool) onPlayerLeave(s *Scene, p *Player) {
|
|||
// 玩家离开结算空房间的私人房
|
||||
if s.IsPrivateScene() {
|
||||
if s.IsEmpty() {
|
||||
s.SendGameDelete(false)
|
||||
s.SendGameDestroy(false)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -345,7 +345,7 @@ func (csp *CoinScenePool) onPlayerLeave(s *Scene, p *Player) {
|
|||
}
|
||||
}
|
||||
if hasCnt > int(csp.dbGameFree.GetCreateRoomNum()) {
|
||||
s.SendGameDelete(false)
|
||||
s.SendGameDestroy(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -373,7 +373,7 @@ func (this *HundredSceneMgr) OnPlatformDestroy(p *Platform) {
|
|||
for _, scene := range ss {
|
||||
ids = append(ids, scene.sceneId)
|
||||
}
|
||||
SceneMgrSingleton.DoDelete(ids, true)
|
||||
SceneMgrSingleton.SendGameDestroy(ids, true)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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.SendGameDelete(false)
|
||||
s.SendGameDestroy(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -412,7 +412,7 @@ func (this *HundredSceneMgr) OnPlatformDestroyByGameFreeId(p *Platform, gameFree
|
|||
ids = append(ids, scene.sceneId)
|
||||
}
|
||||
}
|
||||
SceneMgrSingleton.DoDelete(ids, true)
|
||||
SceneMgrSingleton.SendGameDestroy(ids, true)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -188,7 +188,7 @@ 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.SendGameDelete(false)
|
||||
scene.SendGameDestroy(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2415,21 +2415,6 @@ func (this *Player) GetIP() string {
|
|||
return this.Ip
|
||||
}
|
||||
|
||||
func (this *Player) CreateScene(sceneId, gameId, gameMode, sceneMode int, numOfGames int32, params []int64, dbGameFree *serverproto.DB_GameFree) (*Scene, hallproto.OpResultCode_Game) {
|
||||
gs := GameSessMgrSington.GetMinLoadSess(gameId)
|
||||
if gs == nil {
|
||||
logger.Logger.Warnf("(this *Player) EnterScene %v, %v GameSessMgrSington.GetMinLoadSess() = nil ", this.SnId, gameId)
|
||||
return nil, hallproto.OpResultCode_Game_OPRC_SceneServerMaintain_Game
|
||||
}
|
||||
|
||||
s := SceneMgrSingleton.CreateScene(0, this.SnId, sceneId, gameId, gameMode, sceneMode, 1, numOfGames, params, gs, this.GetPlatform(), 0, dbGameFree, dbGameFree.GetId())
|
||||
if s == nil {
|
||||
logger.Logger.Tracef("(this *Player) EnterScene %v, SceneMgrSingleton.CreateScene() = nil ", this.SnId)
|
||||
return nil, hallproto.OpResultCode_Game_OPRC_Error_Game
|
||||
}
|
||||
return s, hallproto.OpResultCode_Game_OPRC_Sucess_Game
|
||||
}
|
||||
|
||||
func (this *Player) CreateLocalGameScene(sceneId, gameId, gameSite, sceneMode, playerNum int, params []int64,
|
||||
dbGameFree *serverproto.DB_GameFree, baseScore, groupId int32) (*Scene, hallproto.OpResultCode_Game) {
|
||||
gs := GameSessMgrSington.GetMinLoadSess(gameId)
|
||||
|
|
|
@ -606,6 +606,41 @@ func (this *Scene) AudienceEnter(p *Player, ischangeroom bool) bool {
|
|||
return true
|
||||
}
|
||||
|
||||
func (this *Scene) lastScene(p *Player) {
|
||||
// 记录玩家在每个游戏场次最后进入的房间号
|
||||
// 只记录金币场
|
||||
if this.IsCoinScene() {
|
||||
const MINHOLD = 10
|
||||
const MAXHOLD = 20
|
||||
holdCnt := MINHOLD
|
||||
if this.csp != nil {
|
||||
holdCnt = this.csp.GetHasTruePlayerSceneCnt() + 2
|
||||
if holdCnt < MINHOLD {
|
||||
holdCnt = MINHOLD
|
||||
}
|
||||
if holdCnt > MAXHOLD {
|
||||
holdCnt = MAXHOLD
|
||||
}
|
||||
}
|
||||
if p.lastSceneId == nil {
|
||||
p.lastSceneId = make(map[int32][]int32)
|
||||
}
|
||||
id := this.dbGameFree.GetId()
|
||||
if sceneIds, exist := p.lastSceneId[id]; exist {
|
||||
if !common.InSliceInt32(sceneIds, int32(this.sceneId)) {
|
||||
sceneIds = append(sceneIds, int32(this.sceneId))
|
||||
cnt := len(sceneIds)
|
||||
if cnt > holdCnt {
|
||||
sceneIds = sceneIds[cnt-holdCnt:]
|
||||
}
|
||||
p.lastSceneId[id] = sceneIds
|
||||
}
|
||||
} else {
|
||||
p.lastSceneId[id] = []int32{int32(this.sceneId)}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (this *Scene) DelPlayer(p *Player) bool {
|
||||
if p.scene != this {
|
||||
roomId := 0
|
||||
|
@ -625,7 +660,7 @@ func (this *Scene) DelPlayer(p *Player) bool {
|
|||
this.robotNum--
|
||||
}
|
||||
// 记录玩家最近玩游戏的房间
|
||||
SceneMgrSingleton.OnPlayerLeaveScene(this, p)
|
||||
this.lastScene(p)
|
||||
// 玩家最后所在游戏
|
||||
p.LastGameId = int(this.dbGameFree.GetGameId())
|
||||
}
|
||||
|
@ -812,7 +847,7 @@ func (this *Scene) IsLongTimeInactive() bool {
|
|||
return false
|
||||
}
|
||||
|
||||
func (this *Scene) SendGameDelete(isGrace bool) {
|
||||
func (this *Scene) SendGameDestroy(isGrace bool) {
|
||||
if !isGrace {
|
||||
this.deleting = true
|
||||
this.force = true
|
||||
|
|
|
@ -10,7 +10,7 @@ import (
|
|||
"mongo.games.com/game/common"
|
||||
"mongo.games.com/game/model"
|
||||
serverproto "mongo.games.com/game/protocol/server"
|
||||
webapi2 "mongo.games.com/game/protocol/webapi"
|
||||
webapiproto "mongo.games.com/game/protocol/webapi"
|
||||
"mongo.games.com/game/webapi"
|
||||
)
|
||||
|
||||
|
@ -28,21 +28,13 @@ var SceneMgrSingleton = &SceneMgr{
|
|||
|
||||
// SceneMgr 房间管理器
|
||||
type SceneMgr struct {
|
||||
BaseClockSinker // 驱动时间事件
|
||||
BaseClockSinker // 驱动时间事件
|
||||
scenes map[int]*Scene // 房间id: Scene
|
||||
|
||||
scenes map[int]*Scene // 房间id: Scene
|
||||
privateAutoId int // 私人房房间号
|
||||
matchAutoId int // 比赛场房间号
|
||||
coinSceneAutoId int // 金币场房间号
|
||||
hundredSceneAutoId int // 百人场房间号
|
||||
}
|
||||
|
||||
func (m *SceneMgr) GetPlatformBySceneId(sceneId int) string {
|
||||
s := m.GetScene(sceneId)
|
||||
if s != nil && s.limitPlatform != nil {
|
||||
return s.limitPlatform.IdStr
|
||||
}
|
||||
return ""
|
||||
privateAutoId int // 私人房房间号
|
||||
matchAutoId int // 比赛场房间号
|
||||
coinSceneAutoId int // 金币场房间号
|
||||
hundredSceneAutoId int // 百人场房间号
|
||||
}
|
||||
|
||||
// AllocReplayCode 获取回访码
|
||||
|
@ -87,6 +79,14 @@ func (m *SceneMgr) GenOneMatchSceneId() int {
|
|||
return m.matchAutoId
|
||||
}
|
||||
|
||||
func (m *SceneMgr) GetPlatformBySceneId(sceneId int) string {
|
||||
s := m.GetScene(sceneId)
|
||||
if s != nil && s.limitPlatform != nil {
|
||||
return s.limitPlatform.IdStr
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// GetScene 获取房间对象
|
||||
func (m *SceneMgr) GetScene(sceneId int) *Scene {
|
||||
if s, exist := m.scenes[sceneId]; exist && !s.deleting {
|
||||
|
@ -123,6 +123,8 @@ func (m *SceneMgr) GetScenesByGameFreeId(gameFreeId int32) []*Scene {
|
|||
return scenes
|
||||
}
|
||||
|
||||
// GetMatchRoom 获取比赛房间
|
||||
// sortId 比赛id
|
||||
func (m *SceneMgr) GetMatchRoom(sortId int64) []*Scene {
|
||||
var scenes []*Scene
|
||||
for _, value := range m.scenes {
|
||||
|
@ -137,9 +139,10 @@ func (m *SceneMgr) GetMatchRoom(sortId int64) []*Scene {
|
|||
}
|
||||
|
||||
// MarshalAllRoom 获取房间列表
|
||||
// 返回 房间列表,总页数,总条数
|
||||
func (m *SceneMgr) MarshalAllRoom(platform string, groupId, gameId int, gameMode, clubId, sceneMode, sceneId int,
|
||||
gameFreeId, snId int32, start, end, pageSize int32) ([]*webapi2.RoomInfo, int32, int32) {
|
||||
roomInfo := make([]*webapi2.RoomInfo, 0, len(m.scenes))
|
||||
gameFreeId, snId int32, start, end, pageSize int32) ([]*webapiproto.RoomInfo, int32, int32) {
|
||||
roomInfo := make([]*webapiproto.RoomInfo, 0, len(m.scenes))
|
||||
var isNeedFindAll = false
|
||||
if model.GameParamData.IsFindRoomByGroup && platform != "" && snId != 0 && gameId == 0 &&
|
||||
gameMode == 0 && sceneId == -1 && groupId == 0 && clubId == 0 && sceneMode == 0 {
|
||||
|
@ -159,7 +162,7 @@ func (m *SceneMgr) MarshalAllRoom(platform string, groupId, gameId int, gameMode
|
|||
platformName = s.limitPlatform.IdStr
|
||||
}
|
||||
|
||||
si := &webapi2.RoomInfo{
|
||||
si := &webapiproto.RoomInfo{
|
||||
Platform: platformName,
|
||||
SceneId: int32(s.sceneId),
|
||||
GameId: int32(s.gameId),
|
||||
|
@ -266,18 +269,21 @@ func (m *SceneMgr) CreateScene(agentor, creator int32, sceneId, gameId, gameMode
|
|||
numOfGames int32, params []int64, gs *GameSession, limitPlatform *Platform, groupId int32, dbGameFree *serverproto.DB_GameFree,
|
||||
paramsEx ...int32) *Scene {
|
||||
logger.Logger.Trace("(this *SceneMgr) CreateScene ")
|
||||
// 创建房间
|
||||
s := NewScene(agentor, creator, sceneId, gameId, gameMode, sceneMode, clycleTimes, numOfGames, params, gs, limitPlatform, groupId,
|
||||
dbGameFree, paramsEx...)
|
||||
if s == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
m.scenes[sceneId] = s
|
||||
|
||||
// 创建水池
|
||||
if !s.IsMatchScene() && dbGameFree != nil && limitPlatform != nil {
|
||||
//平台水池设置
|
||||
gs.DetectCoinPoolSetting(limitPlatform.IdStr, dbGameFree.GetId(), s.groupId)
|
||||
}
|
||||
|
||||
// 添加到游戏服记录中
|
||||
gs.AddScene(s)
|
||||
var platformName string
|
||||
if limitPlatform != nil {
|
||||
|
@ -298,10 +304,9 @@ func (m *SceneMgr) CreateLocalGameScene(creator int32, sceneId, gameId, gameSite
|
|||
if s == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
m.scenes[sceneId] = s
|
||||
gs.AddScene(s)
|
||||
|
||||
gs.AddScene(s)
|
||||
var platformName string
|
||||
if limitPlatform != nil {
|
||||
platformName = limitPlatform.IdStr
|
||||
|
@ -336,44 +341,7 @@ func (m *SceneMgr) DestroyScene(sceneId int, isCompleted bool) {
|
|||
logger.Logger.Infof("(this *SceneMgr) DestroyScene, SceneId=%v", sceneId)
|
||||
}
|
||||
|
||||
func (m *SceneMgr) OnPlayerLeaveScene(s *Scene, p *Player) {
|
||||
logger.Logger.Trace("(this *SceneMgr) OnPlayerLeaveScene", p.SnId)
|
||||
|
||||
// 记录玩家在每个游戏场次最后进入的房间号
|
||||
// 只记录金币场
|
||||
if s.IsCoinScene() {
|
||||
const MINHOLD = 10
|
||||
const MAXHOLD = 20
|
||||
holdCnt := MINHOLD
|
||||
if s.csp != nil {
|
||||
holdCnt = s.csp.GetHasTruePlayerSceneCnt() + 2
|
||||
if holdCnt < MINHOLD {
|
||||
holdCnt = MINHOLD
|
||||
}
|
||||
if holdCnt > MAXHOLD {
|
||||
holdCnt = MAXHOLD
|
||||
}
|
||||
}
|
||||
if p.lastSceneId == nil {
|
||||
p.lastSceneId = make(map[int32][]int32)
|
||||
}
|
||||
id := s.dbGameFree.GetId()
|
||||
if sceneIds, exist := p.lastSceneId[id]; exist {
|
||||
if !common.InSliceInt32(sceneIds, int32(s.sceneId)) {
|
||||
sceneIds = append(sceneIds, int32(s.sceneId))
|
||||
cnt := len(sceneIds)
|
||||
if cnt > holdCnt {
|
||||
sceneIds = sceneIds[cnt-holdCnt:]
|
||||
}
|
||||
p.lastSceneId[id] = sceneIds
|
||||
}
|
||||
} else {
|
||||
p.lastSceneId[id] = []int32{int32(s.sceneId)}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (m *SceneMgr) DoDelete(sceneId []int, isGrace bool) {
|
||||
func (m *SceneMgr) SendGameDestroy(sceneId []int, isGrace bool) {
|
||||
if len(sceneId) == 0 {
|
||||
return
|
||||
}
|
||||
|
@ -393,31 +361,6 @@ func (m *SceneMgr) DoDelete(sceneId []int, isGrace bool) {
|
|||
srvlib.ServerSessionMgrSington.Broadcast(int(serverproto.SSPacketID_PACKET_WG_DESTROYSCENE), pack, common.GetSelfAreaId(), srvlib.GameServerType)
|
||||
}
|
||||
|
||||
// GetThirdScene 获取三方游戏房间
|
||||
//func (m *SceneMgr) GetThirdScene(i webapi.IThirdPlatform) *Scene {
|
||||
// if i == nil {
|
||||
// return nil
|
||||
// }
|
||||
// sceneId := i.GetPlatformBase().SceneId
|
||||
// scene := m.scenes[sceneId]
|
||||
// if scene != nil {
|
||||
// return scene
|
||||
// }
|
||||
//
|
||||
// gs := GameSessMgrSington.GetMinLoadSess(i.GetPlatformBase().BaseGameID)
|
||||
// if gs != nil {
|
||||
// limitPlatform := PlatformMgrSingleton.GetPlatform(DefaultPlatform)
|
||||
// var gameMode = common.SceneMode_Thr
|
||||
// dbGameFree := srvdata.PBDB_GameFreeMgr.GetData(i.GetPlatformBase().VultGameID)
|
||||
// scene := SceneMgrSingleton.CreateScene(0, 0, sceneId, i.GetPlatformBase().BaseGameID, gameMode, int(common.SceneMode_Thr), 1, -1,
|
||||
// []int64{}, gs, limitPlatform, 0, dbGameFree, i.GetPlatformBase().VultGameID)
|
||||
// return scene
|
||||
// } else {
|
||||
// logger.Logger.Errorf("Get %v game min session failed.", i.GetPlatformBase().BaseGameID)
|
||||
// return nil
|
||||
// }
|
||||
//}
|
||||
|
||||
//=========================ClockSinker===============================
|
||||
|
||||
// InterestClockEvent 接收所有时间事件
|
||||
|
@ -435,18 +378,18 @@ func (m *SceneMgr) OnMiniTimer() {
|
|||
case s.IsCoinScene():
|
||||
if s.IsLongTimeInactive() {
|
||||
if s.dbGameFree.GetCreateRoomNum() == 0 {
|
||||
logger.Logger.Warnf("SceneMgr.DeleteLongTimeInactive CoinScene SendGameDelete scene:%v IsLongTimeInactive", s.sceneId)
|
||||
s.SendGameDelete(false)
|
||||
logger.Logger.Warnf("SceneMgr.DeleteLongTimeInactive CoinScene SendGameDestroy scene:%v IsLongTimeInactive", s.sceneId)
|
||||
s.SendGameDestroy(false)
|
||||
}
|
||||
if s.dbGameFree.GetCreateRoomNum() > 0 && s.csp != nil && s.csp.GetRoomNum() > int(s.dbGameFree.GetCreateRoomNum()) {
|
||||
logger.Logger.Warnf("SceneMgr.DeleteLongTimeInactive CoinScene SendGameDelete scene:%v IsLongTimeInactive", s.sceneId)
|
||||
s.SendGameDelete(false)
|
||||
logger.Logger.Warnf("SceneMgr.DeleteLongTimeInactive CoinScene SendGameDestroy scene:%v IsLongTimeInactive", s.sceneId)
|
||||
s.SendGameDestroy(false)
|
||||
}
|
||||
}
|
||||
case s.IsPrivateScene():
|
||||
if s.IsLongTimeInactive() {
|
||||
logger.Logger.Warnf("SceneMgr.DeleteLongTimeInactive PrivateScene SendGameDelete scene:%v IsLongTimeInactive", s.sceneId)
|
||||
s.SendGameDelete(false)
|
||||
logger.Logger.Warnf("SceneMgr.DeleteLongTimeInactive PrivateScene SendGameDestroy scene:%v IsLongTimeInactive", s.sceneId)
|
||||
s.SendGameDestroy(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -61,10 +61,6 @@ type ScenePolicyData struct {
|
|||
customIndexParams []*ScenePolicyDataParam
|
||||
}
|
||||
|
||||
func alignto(val, align int32) int32 {
|
||||
return (val + align - 1) / align
|
||||
}
|
||||
|
||||
func (spd *ScenePolicyData) Init() bool {
|
||||
spd.nameMap = make(map[string]*ScenePolicyDataParam)
|
||||
spd.aliasNameMap = make(map[string]*ScenePolicyDataParam)
|
||||
|
|
|
@ -1753,7 +1753,7 @@ func init() {
|
|||
if s != nil && !s.deleting && len(s.players) == 0 {
|
||||
logger.Logger.Warnf("WebService SpecailEmptySceneId destroyroom scene:%v", s.sceneId)
|
||||
s.TryForceDeleteMatchInfo()
|
||||
s.SendGameDelete(false)
|
||||
s.SendGameDestroy(false)
|
||||
}
|
||||
}
|
||||
case 2: //删除所有未开始的房间
|
||||
|
@ -1764,7 +1764,7 @@ func init() {
|
|||
if s != nil && !s.deleting && !s.starting && !s.IsHundredScene() {
|
||||
logger.Logger.Warnf("WebService SpecailUnstartSceneId destroyroom scene:%v", s.sceneId)
|
||||
s.TryForceDeleteMatchInfo()
|
||||
s.SendGameDelete(false)
|
||||
s.SendGameDestroy(false)
|
||||
}
|
||||
}
|
||||
default: //删除指定房间
|
||||
|
@ -1787,7 +1787,7 @@ func init() {
|
|||
}
|
||||
logger.Logger.Warnf("WebService destroyroom scene:%v", s.sceneId)
|
||||
s.TryForceDeleteMatchInfo()
|
||||
s.SendGameDelete(false)
|
||||
s.SendGameDestroy(false)
|
||||
}
|
||||
}
|
||||
return common.ResponseTag_Ok, pack
|
||||
|
|
Loading…
Reference in New Issue