|  |  |  | 
|---|
|  |  |  | import ChConfig | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import json | 
|---|
|  |  |  | import time | 
|---|
|  |  |  |  | 
|---|
|  |  |  | ViewCacheMgr = GameWorld.GameWorldData.GetPlayerViewCacheMgr() | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | # 优先取缓存数据,后取可保存数据 | 
|---|
|  |  |  | def GetItemData(curCache): | 
|---|
|  |  |  | result = curCache.GetItemDataNoSave() | 
|---|
|  |  |  | if not result: | 
|---|
|  |  |  | return curCache.GetItemData() | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return result | 
|---|
|  |  |  |  | 
|---|
|  |  |  | def GetPlusData(curCache): | 
|---|
|  |  |  | result = curCache.GetPlusDataNoSave() | 
|---|
|  |  |  | if not result: | 
|---|
|  |  |  | return curCache.GetPlusData() | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return result | 
|---|
|  |  |  | def DoOnDayEx(): | 
|---|
|  |  |  | DelOutofTimeViewCacheData() | 
|---|
|  |  |  | return | 
|---|
|  |  |  |  | 
|---|
|  |  |  | def IsSaveDBViewCache(playerID, playerLV): | 
|---|
|  |  |  | ## 是否保存基本的缓存数据 | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return False | 
|---|
|  |  |  |  | 
|---|
|  |  |  | def DelOutofTimeViewCacheData(): | 
|---|
|  |  |  | ## 删除过期的查看缓存数据 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | curTime = int(time.time()) | 
|---|
|  |  |  | MaxTime = 30 * 3600 * 24 # 30天 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | pyViewCacheMgr = PyDataManager.GetPlayerViewCachePyManager() | 
|---|
|  |  |  | playerViewCachePyDict = pyViewCacheMgr.playerViewCachePyDict | 
|---|
|  |  |  | for playerID, viewCache in playerViewCachePyDict.items(): | 
|---|
|  |  |  |  | 
|---|
|  |  |  | passTime = curTime - viewCache.OffTime | 
|---|
|  |  |  | if passTime < MaxTime: | 
|---|
|  |  |  | continue | 
|---|
|  |  |  | if IsSaveAllViewCache(playerID): | 
|---|
|  |  |  | continue | 
|---|
|  |  |  | playerViewCachePyDict.pop(playerID) | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return | 
|---|
|  |  |  |  | 
|---|
|  |  |  | def DeleteViewCache(playerID): | 
|---|
|  |  |  | ## 删除玩家缓存 | 
|---|
|  |  |  | pyViewCacheMgr = PyDataManager.GetPlayerViewCachePyManager() | 
|---|
|  |  |  | playerViewCachePyDict = pyViewCacheMgr.playerViewCachePyDict | 
|---|
|  |  |  | playerViewCachePyDict.pop(playerID) | 
|---|
|  |  |  | playerViewCachePyDict.pop(playerID, None) | 
|---|
|  |  |  | GameWorld.DebugLog("删除查看缓存!", playerID) | 
|---|
|  |  |  | return | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | curCache.PlayerID = playerID | 
|---|
|  |  |  | playerViewCachePyDict[playerID] = curCache | 
|---|
|  |  |  | return curCache | 
|---|
|  |  |  |  | 
|---|
|  |  |  | def GetCachePropDataDict(curCache): | 
|---|
|  |  |  | ## 获取缓存基础属性字典信息 | 
|---|
|  |  |  | if not hasattr(curCache, "PropDataDict"): | 
|---|
|  |  |  | curCache.PropDataDict = {} | 
|---|
|  |  |  | if not curCache.PropDataDict: | 
|---|
|  |  |  | curCache.PropDataDict = eval(curCache.PropData) | 
|---|
|  |  |  | return curCache.PropDataDict | 
|---|
|  |  |  |  | 
|---|
|  |  |  | #//04 01 地图同步玩家缓存数据到GameServer#tagMGUpdatePlayerCache | 
|---|
|  |  |  | # | 
|---|
|  |  |  | 
|---|
|  |  |  | curCache.GeTuiID = curPlayer.GetGeTuiClientID() | 
|---|
|  |  |  | curCache.GeTuiIDSize = len(curCache.GeTuiID) | 
|---|
|  |  |  |  | 
|---|
|  |  |  | curCache.PropDataDict = {} # 每次更新数据时,重置字典缓存,下次获取时重新eval缓存 | 
|---|
|  |  |  | curCache.PropData = curPackData.PropData | 
|---|
|  |  |  | curCache.PropDataSize = curPackData.PropDataSize | 
|---|
|  |  |  | curCache.PlusData = curPackData.PlusData | 
|---|
|  |  |  | 
|---|
|  |  |  | #GameWorld.DebugLog("    %s" % curCache.outputString()) | 
|---|
|  |  |  | # 同步更新助战信息 | 
|---|
|  |  |  | if PlayerFBHelpBattle.IsInHelpBattleCheckInList(playerID): | 
|---|
|  |  |  | #PropDataDict = json.loads(curCache.PropData) | 
|---|
|  |  |  | PropDataDict = eval(curCache.PropData) | 
|---|
|  |  |  | PropDataDict = GetCachePropDataDict(curCache) | 
|---|
|  |  |  | fightPower = PropDataDict.get("FightPower", 0) | 
|---|
|  |  |  | familyID = PropDataDict.get("FamilyID", 0) | 
|---|
|  |  |  | playerName = PropDataDict.get("Name", "") | 
|---|
|  |  |  | 
|---|
|  |  |  | if not curCache: | 
|---|
|  |  |  | PlayerControl.NotifyCode(curPlayer, "ViewPlayer_OffLine") | 
|---|
|  |  |  | return | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Sync_PlayerCache(curPlayer, curCache, equipClassLV) | 
|---|
|  |  |  | return | 
|---|
|  |  |  |  | 
|---|
|  |  |  | def Sync_PlayerCache(curPlayer, curCache, equipClassLV=0): | 
|---|
|  |  |  | ## 同步玩家缓存 | 
|---|
|  |  |  | if equipClassLV: | 
|---|
|  |  |  | itemData = "" | 
|---|
|  |  |  | if hasattr(curCache, "ItemDataSize%s" % equipClassLV): | 
|---|
|  |  |  | itemData = getattr(curCache, "ItemData%s" % equipClassLV) | 
|---|
|  |  |  | sendPack = ChPyNetSendPack.tagSCPlayerEquipCacheResult() | 
|---|
|  |  |  | sendPack.PlayerID = findPlayerID | 
|---|
|  |  |  | sendPack.PlayerID = curCache.PlayerID | 
|---|
|  |  |  | sendPack.EquipClassLV = equipClassLV | 
|---|
|  |  |  | sendPack.ItemData = itemData | 
|---|
|  |  |  | sendPack.ItemDataSize = len(sendPack.ItemData) | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | #回包客户端 | 
|---|
|  |  |  | sendPack = ChPyNetSendPack.tagSCQueryPlayerCacheResult() | 
|---|
|  |  |  | sendPack.PlayerID = findPlayerID | 
|---|
|  |  |  | sendPack.PlayerID = curCache.PlayerID | 
|---|
|  |  |  | sendPack.PropData = curCache.PropData | 
|---|
|  |  |  | sendPack.PropDataSize = len(sendPack.PropData) | 
|---|
|  |  |  | sendPack.PlusData = curCache.PlusData | 
|---|
|  |  |  | sendPack.PlusDataSize = len(sendPack.PlusData) | 
|---|
|  |  |  | NetPackCommon.SendFakePack(curPlayer, sendPack) | 
|---|
|  |  |  | #GameWorld.DebugLog('ViewCache### OnMGQueryPlayerCache out') | 
|---|
|  |  |  | return | 
|---|
|  |  |  |  | 
|---|
|  |  |  | #=============================================================================== | 
|---|
|  |  |  | 
|---|
|  |  |  | answerPack.OnlineType = ChConfig.Def_Offline | 
|---|
|  |  |  | answerPack.ServerGroupID = 0 | 
|---|
|  |  |  | else: | 
|---|
|  |  |  | cacheDict = eval(curCache.PropData) | 
|---|
|  |  |  | cacheDict = GetCachePropDataDict(curCache) | 
|---|
|  |  |  | answerPack.PlayerID = clientPack.PlayerID | 
|---|
|  |  |  | answerPack.PlayerName = cacheDict["Name"] | 
|---|
|  |  |  | answerPack.Job = cacheDict["Job"] | 
|---|
|  |  |  | 
|---|
|  |  |  | curCache = FindViewCache(playerID) | 
|---|
|  |  |  | if not curCache: | 
|---|
|  |  |  | return | 
|---|
|  |  |  | PropData = eval(curCache.PropData) | 
|---|
|  |  |  | PropData = GetCachePropDataDict(curCache) | 
|---|
|  |  |  | PropData["FamilyID"] = familyID | 
|---|
|  |  |  | PropData["FamilyName"] = familyName | 
|---|
|  |  |  | PropData = json.dumps(PropData, ensure_ascii=False).replace(" ", "") | 
|---|