| | |
| | | import PyGameDataStruct
|
| | | import IpyGameDataPY
|
| | | import PyDataManager
|
| | | import CrossRealmPK
|
| | | import ShareDefine
|
| | | import ChPlayer
|
| | | import ChConfig
|
| | |
|
| | | import json
|
| | |
| | | DelOutofTimeViewCacheData()
|
| | | return
|
| | |
|
| | | def IsSaveDBViewCache(playerID, playerLV):
|
| | | ## 是否保存基本的缓存数据
|
| | | def IsSaveDBViewCache(viewCache):
|
| | | ## 缓存数据是否入库
|
| | | if not viewCache:
|
| | | return False
|
| | | |
| | | playerID = viewCache.PlayerID
|
| | | if PlayerFBHelpBattle.IsInHelpBattleCheckInList(playerID):
|
| | | return True
|
| | |
|
| | |
| | | if GameWorldSkyTower.IsSkyTowerPassPlayer(playerID):
|
| | | return True
|
| | |
|
| | | SaveDBLimitLV = IpyGameDataPY.GetFuncCfg("PlayerViewCache", 1)
|
| | | #校验玩家等级
|
| | | if playerLV < SaveDBLimitLV:
|
| | | return False
|
| | | |
| | | return True
|
| | |
|
| | | def IsSaveAllViewCache(playerID):
|
| | | ## 是否保存所有缓存数据
|
| | | |
| | | if PlayerFBHelpBattle.IsInHelpBattleCheckInList(playerID):
|
| | | return True
|
| | | |
| | | if GameWorldArena.IsArenaBattlePlayer(playerID):
|
| | | return True
|
| | | |
| | | if CrossBattlefield.IsBattlefieldCallPlayer(playerID):
|
| | | return True
|
| | | |
| | | if CrossChampionship.IsChampionshipPlayer(playerID):
|
| | | return True
|
| | | |
| | | NeedCheckBillBoardType = IpyGameDataPY.GetFuncEvalCfg("PlayerViewCache", 2)
|
| | | #校验玩家是否上排行榜
|
| | | billboardMgr = GameWorld.GetBillboard()
|
| | | for BillBoardType in NeedCheckBillBoardType:
|
| | | curBillboard = billboardMgr.FindBillboard(BillBoardType)
|
| | | if not curBillboard:
|
| | | continue
|
| | | if curBillboard.FindByID(playerID):
|
| | | return True
|
| | | |
| | | #跨服榜单上的默认保留
|
| | | if GameWorld.IsCrossServer():
|
| | | billboardMgr = PyDataManager.GetCrossBillboardManager()
|
| | |
| | | if billboardObj.FindByID(playerID):
|
| | | return True
|
| | |
|
| | | if CrossRealmPK.IsCrossRealmPKPlayer(playerID, checkPreSeason=True):
|
| | | return True
|
| | | else:
|
| | | NeedCheckBillBoardType = IpyGameDataPY.GetFuncEvalCfg("PlayerViewCache", 2)
|
| | | #校验玩家是否上排行榜
|
| | | billboardMgr = GameWorld.GetBillboard()
|
| | | for BillBoardType in NeedCheckBillBoardType:
|
| | | curBillboard = billboardMgr.FindBillboard(BillBoardType)
|
| | | if not curBillboard:
|
| | | continue
|
| | | if curBillboard.FindByID(playerID):
|
| | | return True
|
| | | |
| | | # 以上是相关功能需要用到的数据,必定不能删除的
|
| | | |
| | | # 以下是保留近期活跃玩家,等级限制
|
| | | playerLV = viewCache.LV
|
| | | offTime = viewCache.OffTime
|
| | | if not playerLV and not offTime:
|
| | | # 跨服服务器之前某些情况没有存储LV及OffTime,防止误删,做旧数据兼容用
|
| | | return True
|
| | | |
| | | SaveDBLimitLV = IpyGameDataPY.GetFuncCfg("PlayerViewCache", 1)
|
| | | if playerLV >= SaveDBLimitLV:
|
| | | maxDays = IpyGameDataPY.GetFuncCfg("PlayerViewCache", 3)
|
| | | if not maxDays:
|
| | | maxDays = 7 # 默认7天
|
| | | MaxTime = maxDays * 3600 * 24
|
| | | curTime = int(time.time())
|
| | | passTime = curTime - viewCache.OffTime
|
| | | if passTime < MaxTime:
|
| | | return True
|
| | | |
| | | return False
|
| | |
|
| | | def DelOutofTimeViewCacheData():
|
| | | ## 删除过期的查看缓存数据
|
| | |
|
| | | curTime = int(time.time())
|
| | | MaxTime = IpyGameDataPY.GetFuncCfg("PlayerViewCache", 3) * 3600 * 24
|
| | | |
| | | pyViewCacheMgr = PyDataManager.GetPlayerViewCachePyManager()
|
| | | playerViewCachePyDict = pyViewCacheMgr.playerViewCachePyDict
|
| | | for playerID, viewCache in playerViewCachePyDict.items():
|
| | | |
| | | passTime = curTime - viewCache.OffTime
|
| | | if passTime < MaxTime:
|
| | | continue
|
| | | if IsSaveAllViewCache(playerID):
|
| | | if IsSaveDBViewCache(viewCache):
|
| | | continue
|
| | | playerViewCachePyDict.pop(playerID)
|
| | |
|
| | |
| | | # 内网测试假玩家
|
| | | if playerID < 10000 and not newPropData:
|
| | | openJobList = IpyGameDataPY.GetFuncEvalCfg("OpenJob", 1)
|
| | | fakeName = "匿名玩家".decode(ShareDefine.Def_Game_Character_Encoding).encode(GameWorld.GetCharacterEncoding())
|
| | | fakeName = "神秘道友".decode(ShareDefine.Def_Game_Character_Encoding).encode(GameWorld.GetCharacterEncoding())
|
| | | fakeName = "%s%s" % (fakeName, playerID)
|
| | | serverID = random.randint(9900, 9950)
|
| | | serverID = playerID % 200 + 1 # 1 ~ 200 服
|
| | | serverGroupID = serverID
|
| | | if serverID < 50:
|
| | | serverGroupID = serverGroupID / 10 + 1 # 前50服每10服1主服
|
| | | isOnline = True if playerID % 2 == 0 else False
|
| | | olMgr = ChPlayer.GetOnlinePlayerMgr()
|
| | | olMgr.SetOnlineState(playerID, isOnline, serverGroupID)
|
| | | accID = "fake%s@test@s%s" % (playerID, serverID)
|
| | | newPropData = {
|
| | | "AccID":accID,
|
| | |
| | | "LV":random.randint(100, 200),
|
| | | "RealmLV":random.randint(5, 15),
|
| | | "FightPower":random.randint(1000000, 100000000),
|
| | | "ServerGroupID":serverID,
|
| | | "ServerGroupID":serverGroupID,
|
| | | }
|
| | | curCache = PyGameDataStruct.tagPlayerViewCachePy()
|
| | | curCache.PlayerID = playerID
|
| | | curCache.OffTime = int(time.time())
|
| | | if newPropData:
|
| | | curCache.PropData = json.dumps(newPropData, ensure_ascii=False).replace(" ", "")
|
| | | curCache.PropDataSize = len(curCache.PropData)
|
| | |
| | |
|
| | | def GetShotCahceDict(playerID, withEquip=False):
|
| | | ## 获取玩家简短的缓存信息字典
|
| | | cacheDict = GetCachePropDataDict(FindViewCache(playerID))
|
| | | viewCache = FindViewCache(playerID)
|
| | | cacheDict = GetCachePropDataDict(viewCache)
|
| | | if not cacheDict:
|
| | | return {}
|
| | | olMgr = ChPlayer.GetOnlinePlayerMgr()
|
| | | shotCacheDict = {
|
| | | "PlayerID":playerID,
|
| | | "Name":cacheDict["Name"],
|
| | |
| | | "RealmLV":cacheDict["RealmLV"],
|
| | | "FightPower":cacheDict["FightPower"],
|
| | | "ServerID":GameWorld.GetAccIDServerID(cacheDict["AccID"]),
|
| | | "OfflineValue":olMgr.GetOfflineValue(playerID, viewCache)
|
| | | }
|
| | | if withEquip:
|
| | | shotCacheDict.update({
|
| | |
| | | }
|
| | | return cacheBase
|
| | |
|
| | | def UpdCrossCacheBase(playerID, cacheBase):
|
| | | def UpdCrossCacheBase(playerID, cacheBase, isLogout=False):
|
| | | ## 更新同步跨服基础查看缓存
|
| | | cacheDict = GetCachePropDataDict(FindViewCache(playerID, True))
|
| | | #更新跨服在线状态,只要有同步即视为在线,除了指定是Logout的
|
| | | olMgr = ChPlayer.GetOnlinePlayerMgr()
|
| | | olMgr.SetOnlineState(playerID, not isLogout, cacheBase.get("ServerGroupID", 0))
|
| | | curCache = FindViewCache(playerID, True)
|
| | | if not curCache:
|
| | | return {}
|
| | | curCache.LV = cacheBase.get("LV", 0)
|
| | | curCache.OffTime = int(time.time()) # 每次都更新,最后一次可视为跨服玩家的最近一次离线时间
|
| | | cacheDict = GetCachePropDataDict(curCache)
|
| | | if not cacheBase:
|
| | | return cacheDict
|
| | | for k, v in cacheBase.items():
|
| | | cacheDict[k] = v
|
| | | if isLogout:
|
| | | if not IsSaveDBViewCache(curCache):
|
| | | DeleteViewCache(playerID)
|
| | | return {}
|
| | | return cacheDict
|
| | |
|
| | | #//04 01 地图同步玩家缓存数据到GameServer#tagMGUpdatePlayerCache
|
| | |
| | | #};
|
| | | def OnMGUpdatePlayerCache(routeIndex, mapID, curPackData, tick):
|
| | | playerID = curPackData.PlayerID
|
| | | playerLV = curPackData.PlayerLV
|
| | | #playerLV = curPackData.PlayerLV
|
| | | isLogout = curPackData.IsLogouting
|
| | | GameWorld.DebugLog('ViewCache### OnMGUpdatePlayerCache isLogout=%s' % isLogout, playerID)
|
| | | isSaveAll = True # 是否保存所有数据
|
| | | if isLogout:
|
| | | #不需要保存离线数据的,直接删除缓存数据
|
| | | if not IsSaveDBViewCache(playerID, playerLV):
|
| | | DeleteViewCache(playerID)
|
| | | return
|
| | | isSaveAll = IsSaveAllViewCache(playerID)
|
| | | GameWorld.DebugLog(" isSaveAll=%s" % isSaveAll, playerID)
|
| | |
|
| | | curCache = FindViewCache(playerID, True)
|
| | | if not curCache:
|
| | | return
|
| | | curCache.LV = curPackData.PlayerLV
|
| | | curCache.OffTime = curPackData.OffTime
|
| | | if isLogout:
|
| | | curPlayer = GameWorld.GetPlayerManager().FindPlayerByID(playerID)
|
| | | if curPlayer:
|
| | | curCache.GeTuiID = curPlayer.GetGeTuiClientID()
|
| | | curCache.GeTuiIDSize = len(curCache.GeTuiID)
|
| | | |
| | | curCache.PropDataDict = {} # 每次更新数据时,重置字典缓存,下次获取时重新eval缓存
|
| | | curCache.PropData = curPackData.PropData
|
| | | curCache.PropDataSize = curPackData.PropDataSize
|
| | |
| | | setattr(curCache, "ItemDataSize%s" % classLV, itemDataSize)
|
| | | #GameWorld.DebugLog(" 更新Item数据: classLV=%s,size=%s, %s" % (classLV, itemDataSize, itemData), playerID)
|
| | |
|
| | | if isLogout:
|
| | | #不需要保存离线数据的,直接删除缓存数据
|
| | | if not IsSaveDBViewCache(curCache):
|
| | | DeleteViewCache(playerID)
|
| | | return
|
| | | curPlayer = GameWorld.GetPlayerManager().FindPlayerByID(playerID)
|
| | | if curPlayer:
|
| | | curCache.GeTuiID = curPlayer.GetGeTuiClientID()
|
| | | curCache.GeTuiIDSize = len(curCache.GeTuiID)
|
| | | |
| | | #GameWorld.DebugLog(" %s" % curCache.outputString())
|
| | | # 同步更新助战信息
|
| | | if PlayerFBHelpBattle.IsInHelpBattleCheckInList(playerID):
|