diff --git a/worldsrv/action_server.go b/worldsrv/action_server.go index b7e9e7c..183f495 100644 --- a/worldsrv/action_server.go +++ b/worldsrv/action_server.go @@ -38,142 +38,148 @@ func init() { return &serverproto.GWPlayerLeave{} })) 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 { - p := PlayerMgrSington.GetPlayerBySnId(msg.GetPlayerId()) - if p != nil { - data := msg.GetPlayerData() - if len(data) != 0 { - logger.Logger.Trace("GWPlayerLeave p.UnmarshalData(data)") - p.UnmarshalData(data, scene) - } - - switch { - case scene.IsCoinScene(): - if !CoinSceneMgrSingleton.PlayerLeave(p, int(msg.GetReason())) { - logger.Logger.Warnf("GWPlayerLeave snid:%v sceneid:%v gameid:%v modeid:%v [coinscene]", - p.SnId, scene.sceneId, scene.gameId, scene.gameMode) - } - case scene.IsHundredScene(): - 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) - } - default: - scene.PlayerLeave(p, int(msg.GetReason())) - } - - if p.scene != nil { - logger.Logger.Errorf("after GWPlayerLeave found snid:%v sceneid:%v gameid:%v modeid:%v", - p.SnId, p.scene.sceneId, p.scene.gameId, p.scene.gameMode) - } - - if scene.IsMatchScene() { - //结算积分 - if !p.IsRob { - TournamentMgr.UpdateMatchInfo(p, msg.MatchId, int32(msg.GetReturnCoin()), int32(msg.GetCurIsWin()), msg.GetMatchRobotGrades()) - } else { - p.matchCtx = nil - } - } - - // 同步排位积分 - if scene.IsRankMatch() { - if p.IsRob { - RankMgrSingleton.UpdateRobotSeason(p.Platform, p.SnId, scene.dbGameFree.GetRankType(), - msg.GetRankScore()[scene.dbGameFree.GetRankType()], p.Name, p.Sex, p.HeadUrl, p.Coin, p.PlayerData.GetRoleId()) - } else { - if model.GameParamData.TestRankMatchAward { - if RankMgrSingleton.playerSeasons[p.SnId] != nil { - if RankMgrSingleton.playerSeasons[p.SnId].RankType == nil { - RankMgrSingleton.playerSeasons[p.SnId].RankType = make(map[int32]*model.PlayerRankInfo) - } - if RankMgrSingleton.playerSeasons[p.SnId].RankType[1] == nil { - RankMgrSingleton.playerSeasons[p.SnId].RankType[1] = &model.PlayerRankInfo{} - } - RankMgrSingleton.playerSeasons[p.SnId].RankType[1].LastScore = 7500 - RankMgrSingleton.playerSeasons[p.SnId].RankType[1].Score = 7500 - RankMgrSingleton.playerSeasons[p.SnId].RankType[1].Awards = nil - } - RankMgrSingleton.UpdatePlayerSeason(p.SnId, map[int32]int64{1: 10000}) - } else { - RankMgrSingleton.UpdatePlayerSeason(p.SnId, msg.GetRankScore()) - } - - } - } - //更新玩家等级排行榜 - LogChannelSingleton.WriteLog(&model.PlayerLevelInfo{ - SnId: p.SnId, - Name: p.Name, - Level: p.Level, - Exp: p.Exp, - ModId: p.PlayerData.GetRoleId(), - Platform: p.Platform, - }) - //比赛场不处理下面的内容 - if !scene.IsMatchScene() && !scene.IsCustom() { - // 破产检测 - sdata := srvdata.PBDB_GameSubsidyMgr.GetData(GameSubsidyid) - if sdata != nil { - if !p.IsRob && p.takeCoin > msg.GetReturnCoin() && p.takeCoin >= int64(sdata.LimitNum) && msg.GetReturnCoin() < int64(sdata.LimitNum) { - CostCoin := p.takeCoin - msg.GetReturnCoin() - - logger.Logger.Infof("NewBankruptLogEx: snid:%v GetReturnCoin:%v coin:%v CostCoin:%v", p.SnId, msg.GetReturnCoin(), p.takeCoin, CostCoin) - log := model.NewBankruptLogEx(p.SnId, scene.dbGameFree.GetId(), p.CreateTime.Unix(), CostCoin, p.Platform, p.Channel, scene.gameId) - if log != nil { - LogChannelSingleton.WriteLog(log) - } - } - } - // 破产检测 - - oldCoin := p.Coin - - //带回金币 - if p.Coin != msg.GetReturnCoin() { - p.Coin = msg.GetReturnCoin() - if p.Coin < 0 { - p.Coin = 0 - } - - p.dirty = true - } - - logger.Logger.Infof("SSPacketID_PACKET_GW_PLAYERLEAVE: snid:%v oldcoin:%v coin:%v", p.SnId, oldCoin, p.Coin) - p.diffData.Coin = -1 //强制更新金币 - p.diffData.TotalConvertibleFlow = -1 //强制更新流水 - p.SendDiffData() //只是把差异发给前端 - - gameCoinTs := msg.GetGameCoinTs() - if !p.IsRob && !scene.IsTestScene() { - //对账点同步 - if p.GameCoinTs < gameCoinTs { - p.GameCoinTs = gameCoinTs - p.dirty = true - } - - //破产统计 - //if int(msg.GetReason()) == common.PlayerLeaveReason_Bekickout { - // if len(scene.paramsEx) > 0 { - // gameIdEx := scene.paramsEx[0] - // gps := PlatformMgrSingleton.GetGameFree(scene.limitPlatform.IdStr, scene.paramsEx[0]) - // if gps != nil { - // lowLimit := gps.DbGameFree.GetLowerThanKick() - // if lowLimit != 0 && p.Coin+p.SafeBoxCoin < int64(lowLimit) { - // p.ReportBankRuptcy(int32(scene.gameId), int32(scene.gameMode), gameIdEx) - // } - // } - // } - //} - } + logger.Logger.Trace("receive GWPlayerLeave:", pack) + msg, ok := pack.(*serverproto.GWPlayerLeave) + if !ok { + return nil + } + + scene := SceneMgrSingleton.GetScene(int(msg.GetRoomId()), true) + if scene == nil { + logger.Logger.Warnf("玩家离开房间,房间没找到 %v", pack) + return nil + } + + p := PlayerMgrSington.GetPlayerBySnId(msg.GetPlayerId()) + if p == nil { + logger.Logger.Warnf("玩家离开房间,玩家信息没找到 %v", pack) + return nil + } + + data := msg.GetPlayerData() + if len(data) != 0 { + logger.Logger.Trace("GWPlayerLeave p.UnmarshalData(data)") + p.UnmarshalData(data, scene) + } + + switch { + case scene.IsCoinScene(): + if !CoinSceneMgrSingleton.PlayerLeave(p, int(msg.GetReason())) { + logger.Logger.Warnf("GWPlayerLeave snid:%v sceneid:%v gameid:%v modeid:%v [coinscene]", + p.SnId, scene.sceneId, scene.gameId, scene.gameMode) + } + case scene.IsHundredScene(): + 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) + } + default: + scene.PlayerLeave(p, int(msg.GetReason())) + } + + if p.scene != nil { + logger.Logger.Errorf("after GWPlayerLeave found snid:%v sceneid:%v gameid:%v modeid:%v", + p.SnId, p.scene.sceneId, p.scene.gameId, p.scene.gameMode) + } + + if scene.IsMatchScene() { + //结算积分 + if !p.IsRob { + TournamentMgr.UpdateMatchInfo(p, msg.MatchId, int32(msg.GetReturnCoin()), int32(msg.GetCurIsWin()), msg.GetMatchRobotGrades()) + } else { + p.matchCtx = nil + } + } + + // 同步排位积分 + if scene.IsRankMatch() { + if p.IsRob { + RankMgrSingleton.UpdateRobotSeason(p.Platform, p.SnId, scene.dbGameFree.GetRankType(), + msg.GetRankScore()[scene.dbGameFree.GetRankType()], p.Name, p.Sex, p.HeadUrl, p.Coin, p.PlayerData.GetRoleId()) + } else { + if model.GameParamData.TestRankMatchAward { + if RankMgrSingleton.playerSeasons[p.SnId] != nil { + if RankMgrSingleton.playerSeasons[p.SnId].RankType == nil { + RankMgrSingleton.playerSeasons[p.SnId].RankType = make(map[int32]*model.PlayerRankInfo) + } + if RankMgrSingleton.playerSeasons[p.SnId].RankType[1] == nil { + RankMgrSingleton.playerSeasons[p.SnId].RankType[1] = &model.PlayerRankInfo{} + } + RankMgrSingleton.playerSeasons[p.SnId].RankType[1].LastScore = 7500 + RankMgrSingleton.playerSeasons[p.SnId].RankType[1].Score = 7500 + RankMgrSingleton.playerSeasons[p.SnId].RankType[1].Awards = nil } + RankMgrSingleton.UpdatePlayerSeason(p.SnId, map[int32]int64{1: 10000}) } else { - logger.Logger.Tracef("GWPlayerLeave LocalRobotIdMgrSington %v", msg.GetPlayerId()) - //LocalRobotIdMgrSington.FreeId(msg.GetPlayerId()) + RankMgrSingleton.UpdatePlayerSeason(p.SnId, msg.GetRankScore()) } + + } + } + //更新玩家等级排行榜 + LogChannelSingleton.WriteLog(&model.PlayerLevelInfo{ + SnId: p.SnId, + Name: p.Name, + Level: p.Level, + Exp: p.Exp, + ModId: p.PlayerData.GetRoleId(), + Platform: p.Platform, + }) + //比赛场不处理下面的内容 + if !scene.IsMatchScene() && !scene.IsCustom() { + // 破产检测 + sdata := srvdata.PBDB_GameSubsidyMgr.GetData(GameSubsidyid) + if sdata != nil { + if !p.IsRob && p.takeCoin > msg.GetReturnCoin() && p.takeCoin >= int64(sdata.LimitNum) && msg.GetReturnCoin() < int64(sdata.LimitNum) { + CostCoin := p.takeCoin - msg.GetReturnCoin() + + logger.Logger.Infof("NewBankruptLogEx: snid:%v GetReturnCoin:%v coin:%v CostCoin:%v", p.SnId, msg.GetReturnCoin(), p.takeCoin, CostCoin) + log := model.NewBankruptLogEx(p.SnId, scene.dbGameFree.GetId(), p.CreateTime.Unix(), CostCoin, p.Platform, p.Channel, scene.gameId) + if log != nil { + LogChannelSingleton.WriteLog(log) + } + } + } + // 破产检测 + + oldCoin := p.Coin + + //带回金币 + if p.Coin != msg.GetReturnCoin() { + p.Coin = msg.GetReturnCoin() + if p.Coin < 0 { + p.Coin = 0 + } + + p.dirty = true + } + + logger.Logger.Infof("SSPacketID_PACKET_GW_PLAYERLEAVE: snid:%v oldcoin:%v coin:%v", p.SnId, oldCoin, p.Coin) + p.diffData.Coin = -1 //强制更新金币 + p.diffData.TotalConvertibleFlow = -1 //强制更新流水 + p.SendDiffData() //只是把差异发给前端 + + gameCoinTs := msg.GetGameCoinTs() + if !p.IsRob && !scene.IsTestScene() { + //对账点同步 + if p.GameCoinTs < gameCoinTs { + p.GameCoinTs = gameCoinTs + p.dirty = true + } + + //破产统计 + //if int(msg.GetReason()) == common.PlayerLeaveReason_Bekickout { + // if len(scene.paramsEx) > 0 { + // gameIdEx := scene.paramsEx[0] + // gps := PlatformMgrSingleton.GetGameFree(scene.limitPlatform.IdStr, scene.paramsEx[0]) + // if gps != nil { + // lowLimit := gps.DbGameFree.GetLowerThanKick() + // if lowLimit != 0 && p.Coin+p.SafeBoxCoin < int64(lowLimit) { + // p.ReportBankRuptcy(int32(scene.gameId), int32(scene.gameMode), gameIdEx) + // } + // } + // } + //} } } return nil diff --git a/worldsrv/scenemgr.go b/worldsrv/scenemgr.go index 2e19520..dc72570 100644 --- a/worldsrv/scenemgr.go +++ b/worldsrv/scenemgr.go @@ -102,8 +102,14 @@ func (m *SceneMgr) GetPlatformBySceneId(sceneId int) string { } // GetScene 获取房间对象 -func (m *SceneMgr) GetScene(sceneId int) *Scene { - if s, exist := m.scenes[sceneId]; exist && !s.deleting { +// 默认是不包含删除中的房间 +// hasDeleting true 包含删除中的房间 +func (m *SceneMgr) GetScene(sceneId int, hasDeleting ...bool) *Scene { + has := false + if len(hasDeleting) > 0 { + has = hasDeleting[0] + } + if s, exist := m.scenes[sceneId]; exist && (has || !s.deleting) { return s } return nil