|  |  |  | 
|---|
|  |  |  | import binascii | 
|---|
|  |  |  | import PyGameData | 
|---|
|  |  |  | import CrossRealmPK | 
|---|
|  |  |  | import AuctionHouse | 
|---|
|  |  |  | import PyGameDataStruct | 
|---|
|  |  |  | import CommFunc | 
|---|
|  |  |  |  | 
|---|
|  |  |  | def GetSavePyData(): | 
|---|
|  |  |  | result = PyGameData.g_pyGameDataManager.GetSaveData() | 
|---|
|  |  |  | GameWorld.DebugLog("GetSavePyData!! id = %s-%s"%(id(PyGameData.g_pyGameDataManager), len(result))) | 
|---|
|  |  |  | pyGameDataMgr = GetPyGameDataManager() | 
|---|
|  |  |  | result = pyGameDataMgr.GetSaveData() | 
|---|
|  |  |  | GameWorld.DebugLog("GetSavePyData!! id = %s-%s"%(id(pyGameDataMgr), len(result))) | 
|---|
|  |  |  | result = binascii.b2a_hex(result) | 
|---|
|  |  |  | #GameWorld.DebugLog("GetSavePyData!! result = %s-%s"%(result, len(result))) | 
|---|
|  |  |  | # 字节码在C++转化会发生错误must be string without null bytes, not str,但是可以正常保存,错误会在下次调用便宜接口才会触发 | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | def LoadPyGameData(gameBuffer, pos): | 
|---|
|  |  |  | PyGameData.g_pyGameDataManager = PyGameDataManager() | 
|---|
|  |  |  | GameWorld.Log("LoadPyGameData!!id = %s %s"%(id(PyGameData.g_pyGameDataManager), len(gameBuffer))) | 
|---|
|  |  |  | return PyGameData.g_pyGameDataManager.LoadGameData(gameBuffer, pos) | 
|---|
|  |  |  | pyGameDataMgr = GetPyGameDataManager() | 
|---|
|  |  |  | GameWorld.Log("LoadPyGameData!!id = %s %s"%(id(pyGameDataMgr), len(gameBuffer))) | 
|---|
|  |  |  | return pyGameDataMgr.LoadGameData(gameBuffer, pos) | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | #拍卖记录管理,该类只做数据缓存存取,不写功能逻辑,防止重读脚本时功能逻辑脚本不生效 | 
|---|
|  |  |  | class AuctionRecordManager(object): | 
|---|
|  |  |  |  | 
|---|
|  |  |  | def __init__(self): | 
|---|
|  |  |  | self.myAuctionItemRecordDict = {} # 我的拍品记录 {playerID:[tagDBAuctionRecord, ...], ...} | 
|---|
|  |  |  | self.myBidItemRecordDict = {} # 我的竞拍记录 {playerID:[tagDBAuctionRecord, ...], ...} | 
|---|
|  |  |  | self.familyAuctionItemRecordDict = {} # 仙盟拍品记录 {familyID:[tagDBAuctionRecord, ...], ...} | 
|---|
|  |  |  | return | 
|---|
|  |  |  |  | 
|---|
|  |  |  | # 保存数据 存数据库和realtimebackup | 
|---|
|  |  |  | def GetSaveData(self): | 
|---|
|  |  |  | savaData = "" | 
|---|
|  |  |  | cntData = "" | 
|---|
|  |  |  | cnt = 0 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | for recordDict in [self.myAuctionItemRecordDict, self.myBidItemRecordDict, self.familyAuctionItemRecordDict]: | 
|---|
|  |  |  | for recordList in recordDict.values(): | 
|---|
|  |  |  | for dbData in recordList: | 
|---|
|  |  |  | cnt += 1 | 
|---|
|  |  |  | savaData += dbData.getBuffer() | 
|---|
|  |  |  |  | 
|---|
|  |  |  | GameWorld.Log("Save AuctionRecord count :%s" % cnt) | 
|---|
|  |  |  | return CommFunc.WriteDWORD(cntData, cnt) + savaData | 
|---|
|  |  |  |  | 
|---|
|  |  |  | # 从数据库载入数据 | 
|---|
|  |  |  | def LoadPyGameData(self, datas, pos, dataslen): | 
|---|
|  |  |  | cnt, pos = CommFunc.ReadDWORD(datas, pos) | 
|---|
|  |  |  | GameWorld.Log("Load AuctionRecord count :%s" % cnt) | 
|---|
|  |  |  |  | 
|---|
|  |  |  | for _ in xrange(cnt): | 
|---|
|  |  |  | dbData = PyGameDataStruct.tagDBAuctionRecord() | 
|---|
|  |  |  | dbData.clear() | 
|---|
|  |  |  | pos += dbData.readData(datas, pos, dataslen) | 
|---|
|  |  |  |  | 
|---|
|  |  |  | AuctionHouse.AddNewAuctionRecord(dbData) | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return pos | 
|---|
|  |  |  |  | 
|---|
|  |  |  | #拍卖关注管理,该类只做数据缓存存取,不写功能逻辑,防止重读脚本时功能逻辑脚本不生效 | 
|---|
|  |  |  | class AuctionAttentionManager(object): | 
|---|
|  |  |  |  | 
|---|
|  |  |  | def __init__(self): | 
|---|
|  |  |  | self.playerAttentionDict = {} # 玩家关注拍卖品ID {playerID:tagDBAuctionAttention, ...} | 
|---|
|  |  |  | return | 
|---|
|  |  |  |  | 
|---|
|  |  |  | # 保存数据 存数据库和realtimebackup | 
|---|
|  |  |  | def GetSaveData(self): | 
|---|
|  |  |  | savaData = "" | 
|---|
|  |  |  | cntData = "" | 
|---|
|  |  |  | cnt = 0 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | for dbData in self.playerAttentionDict.values(): | 
|---|
|  |  |  | cnt += 1 | 
|---|
|  |  |  | savaData += dbData.getBuffer() | 
|---|
|  |  |  |  | 
|---|
|  |  |  | GameWorld.Log("Save AuctionAttention count :%s" % cnt) | 
|---|
|  |  |  | return CommFunc.WriteDWORD(cntData, cnt) + savaData | 
|---|
|  |  |  |  | 
|---|
|  |  |  | # 从数据库载入数据 | 
|---|
|  |  |  | def LoadPyGameData(self, datas, pos, dataslen): | 
|---|
|  |  |  | cnt, pos = CommFunc.ReadDWORD(datas, pos) | 
|---|
|  |  |  | GameWorld.Log("Load AuctionAttention count :%s" % cnt) | 
|---|
|  |  |  |  | 
|---|
|  |  |  | for _ in xrange(cnt): | 
|---|
|  |  |  | dbData = PyGameDataStruct.tagDBAuctionAttention() | 
|---|
|  |  |  | dbData.clear() | 
|---|
|  |  |  | pos += dbData.readData(datas, pos, dataslen) | 
|---|
|  |  |  |  | 
|---|
|  |  |  | self.playerAttentionDict[dbData.PlayerID] = dbData | 
|---|
|  |  |  | AuctionHouse.OnLoadAuctionAttentionDataEx(dbData) | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return pos | 
|---|
|  |  |  |  | 
|---|
|  |  |  | def __InitAuctionAttentionAttrEx(self, attentionData): | 
|---|
|  |  |  | ## 初始化拍卖关注实例附加属性 | 
|---|
|  |  |  | setattr(attentionData, "AttentionItemIDList", [] if not attentionData.AttentionInfo else eval(attentionData.AttentionInfo)) | 
|---|
|  |  |  | return | 
|---|
|  |  |  |  | 
|---|
|  |  |  | #拍卖物品数据缓存,该类只做数据缓存存取,不写功能逻辑,防止重读脚本时功能逻辑脚本不生效 | 
|---|
|  |  |  | class AuctionItemManager(): | 
|---|
|  |  |  |  | 
|---|
|  |  |  | def __init__(self): | 
|---|
|  |  |  | self.allAuctionItemDict = {} # 所有拍品字典缓存 {ItemGUID:tagDBAuctionItem, ...} | 
|---|
|  |  |  | self.allAuctionItemByEndTimeList = [] # 根据结束时间排序的所有拍品缓存 [tagDBAuctionItem, ...] | 
|---|
|  |  |  | self.worldAuctionItemList = [] # 全服拍品列表缓存 [tagDBAuctionItem, ...] | 
|---|
|  |  |  | self.worldAuctionItemQueryDict = {} # 全服拍品过滤查询缓存,添加拍品时重置 {(job, (itemType, ...), itemClassLV, (itemID, ...)):[tagDBAuctionItem, ...], ...} | 
|---|
|  |  |  | self.familyAuctionItemDict = {} # 仙盟拍品列表缓存,包含转移到全服的仙盟拍品 {familyID:[tagDBAuctionItem, ...], ...} | 
|---|
|  |  |  |  | 
|---|
|  |  |  | self.nowBiddingAuctionItemDict = {} # 玩家当前是最高竞价的拍品,含所有拍品 {playerID:[tagDBAuctionItem, ...], ...} | 
|---|
|  |  |  | self.hisBiddingAuctionItemDict = {} # 玩家曾经参与过竞价的拍品,含所有拍品 {playerID:[tagDBAuctionItem, ...], ...} | 
|---|
|  |  |  | self.myAuctionItemDict = {} # 玩家拍卖中的物品 ,不包含仙盟拍品,由前端界面自行整合数据 {playerID:[tagDBAuctionItem, ...], ...} | 
|---|
|  |  |  | self.myAttentionItemDict = {} # 玩家关注中的物品 ,不包含仙盟拍品,由前端界面自行整合数据,只保存在线的玩家,离线清除,上线不同步,由前端查询 {playerID:[tagDBAuctionItem, ...], ...} | 
|---|
|  |  |  | return | 
|---|
|  |  |  |  | 
|---|
|  |  |  | # 保存数据 存数据库和realtimebackup | 
|---|
|  |  |  | def GetSaveData(self): | 
|---|
|  |  |  | savaData = "" | 
|---|
|  |  |  | cntData = "" | 
|---|
|  |  |  | cnt = 0 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | for dbData in self.allAuctionItemDict.values(): | 
|---|
|  |  |  | cnt += 1 | 
|---|
|  |  |  | savaData += dbData.getBuffer() | 
|---|
|  |  |  |  | 
|---|
|  |  |  | GameWorld.Log("Save AuctionItem count :%s" % cnt) | 
|---|
|  |  |  | return CommFunc.WriteDWORD(cntData, cnt) + savaData | 
|---|
|  |  |  |  | 
|---|
|  |  |  | # 从数据库载入数据 | 
|---|
|  |  |  | def LoadPyGameData(self, datas, pos, dataslen): | 
|---|
|  |  |  | cnt, pos = CommFunc.ReadDWORD(datas, pos) | 
|---|
|  |  |  | GameWorld.Log("Load AuctionItem count :%s" % cnt) | 
|---|
|  |  |  |  | 
|---|
|  |  |  | for _ in xrange(cnt): | 
|---|
|  |  |  | dbData = PyGameDataStruct.tagDBAuctionItem() | 
|---|
|  |  |  | dbData.clear() | 
|---|
|  |  |  | pos += dbData.readData(datas, pos, dataslen) | 
|---|
|  |  |  |  | 
|---|
|  |  |  | self.allAuctionItemDict[dbData.ItemGUID] = dbData | 
|---|
|  |  |  | AuctionHouse.OnLoadAuctionItemDataEx(dbData) | 
|---|
|  |  |  |  | 
|---|
|  |  |  | AuctionHouse.OnLoadAuctionItemDataOK() | 
|---|
|  |  |  | return pos | 
|---|
|  |  |  |  | 
|---|
|  |  |  | # 个人社交相关表 | 
|---|
|  |  |  | # 好友表,仇人表,最近联系人,黑名单,四张表公用的社交信息表 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | class PyGameDataManager(object): | 
|---|
|  |  |  | def __init__(self): | 
|---|
|  |  |  | self.AuctionAttentionManager = AuctionAttentionManager() | 
|---|
|  |  |  | self.AuctionRecordManager = AuctionRecordManager() | 
|---|
|  |  |  | self.AuctionItemManager = AuctionItemManager() | 
|---|
|  |  |  | self.crossPKUnNotifyOverInfo = CrossRealmPK.CrossPKUnNotifyOverInfoManager() | 
|---|
|  |  |  | self.crossPKBillboard = CrossRealmPK.CrossPKBillboardManager() | 
|---|
|  |  |  | self.XMZZManager = PlayerXMZZ.XMZZManager() | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | def GetSaveData(self): | 
|---|
|  |  |  | buff = "" | 
|---|
|  |  |  | buff += self.AuctionAttentionManager.GetSaveData() | 
|---|
|  |  |  | buff += self.AuctionRecordManager.GetSaveData() | 
|---|
|  |  |  | buff += self.AuctionItemManager.GetSaveData() | 
|---|
|  |  |  | buff += self.crossPKUnNotifyOverInfo.GetSaveData() | 
|---|
|  |  |  | buff += self.crossPKBillboard.GetSaveData() | 
|---|
|  |  |  | buff += self.XMZZManager.GetSaveData() | 
|---|
|  |  |  | 
|---|
|  |  |  | return buff | 
|---|
|  |  |  |  | 
|---|
|  |  |  | def LoadGameData(self, gameBuffer, pos): | 
|---|
|  |  |  | pos = self.AuctionAttentionManager.LoadPyGameData(gameBuffer, pos, len(gameBuffer)) | 
|---|
|  |  |  | pos = self.AuctionRecordManager.LoadPyGameData(gameBuffer, pos, len(gameBuffer)) | 
|---|
|  |  |  | pos = self.AuctionItemManager.LoadPyGameData(gameBuffer, pos, len(gameBuffer)) | 
|---|
|  |  |  | pos = self.crossPKUnNotifyOverInfo.LoadPyGameData(gameBuffer, pos, len(gameBuffer)) | 
|---|
|  |  |  | pos = self.crossPKBillboard.LoadPyGameData(gameBuffer, pos, len(gameBuffer)) | 
|---|
|  |  |  | pos = self.XMZZManager.LoadPyGameData(gameBuffer, pos, len(gameBuffer)) | 
|---|
|  |  |  | 
|---|
|  |  |  | pos = self.blacklistManager.LoadPyGameData(gameBuffer, pos, len(gameBuffer)) | 
|---|
|  |  |  | pos = self.socialInfoManager.LoadPyGameData(gameBuffer, pos, len(gameBuffer)) | 
|---|
|  |  |  | return pos | 
|---|
|  |  |  |  | 
|---|
|  |  |  | def GetPyGameDataManager(): | 
|---|
|  |  |  | ## py数据库表数据管理器 | 
|---|
|  |  |  | pyGameDataMgr = PyGameData.g_pyGameDataManager | 
|---|
|  |  |  | if not pyGameDataMgr: | 
|---|
|  |  |  | pyGameDataMgr = PyGameDataManager() | 
|---|
|  |  |  | PyGameData.g_pyGameDataManager = pyGameDataMgr | 
|---|
|  |  |  | return pyGameDataMgr | 
|---|
|  |  |  |  | 
|---|
|  |  |  | def GetAuctionItemManager(): | 
|---|
|  |  |  | ## 拍卖物品缓存数据管理 | 
|---|
|  |  |  | pyGameDataMgr = GetPyGameDataManager() | 
|---|
|  |  |  | return pyGameDataMgr.AuctionItemManager | 
|---|
|  |  |  |  | 
|---|
|  |  |  | def GetAuctionAttentionManager(): | 
|---|
|  |  |  | # 拍卖记录表 | 
|---|
|  |  |  | pyGameDataMgr = GetPyGameDataManager() | 
|---|
|  |  |  | return pyGameDataMgr.AuctionAttentionManager | 
|---|
|  |  |  |  | 
|---|
|  |  |  | def GetAuctionRecordManager(): | 
|---|
|  |  |  | # 拍卖记录表 | 
|---|
|  |  |  | pyGameDataMgr = GetPyGameDataManager() | 
|---|
|  |  |  | return pyGameDataMgr.AuctionRecordManager | 
|---|
|  |  |  |  | 
|---|
|  |  |  | # 跨服竞技场未通知玩家的比赛结果 | 
|---|
|  |  |  | def GetCrossPKUnNotifyOverInfoManager(): | 
|---|
|  |  |  | return PyGameData.g_pyGameDataManager.crossPKUnNotifyOverInfo | 
|---|
|  |  |  | pyGameDataMgr = GetPyGameDataManager() | 
|---|
|  |  |  | return pyGameDataMgr.crossPKUnNotifyOverInfo | 
|---|
|  |  |  |  | 
|---|
|  |  |  | # 跨服竞技场排行榜管理 | 
|---|
|  |  |  | def GetCrossPKBillboardManager(): | 
|---|
|  |  |  | return PyGameData.g_pyGameDataManager.crossPKBillboard | 
|---|
|  |  |  | pyGameDataMgr = GetPyGameDataManager() | 
|---|
|  |  |  | return pyGameDataMgr.crossPKBillboard | 
|---|
|  |  |  |  | 
|---|
|  |  |  | # 仙魔之争管理 | 
|---|
|  |  |  | def GetXMZZManager(): | 
|---|
|  |  |  | return PyGameData.g_pyGameDataManager.XMZZManager | 
|---|
|  |  |  | pyGameDataMgr = GetPyGameDataManager() | 
|---|
|  |  |  | return pyGameDataMgr.XMZZManager | 
|---|
|  |  |  |  | 
|---|
|  |  |  | # 封魔坛结果管理 | 
|---|
|  |  |  | def GetSealDemonRecordManager(): | 
|---|
|  |  |  | return PyGameData.g_pyGameDataManager.sealDemonManager | 
|---|
|  |  |  | pyGameDataMgr = GetPyGameDataManager() | 
|---|
|  |  |  | return pyGameDataMgr.sealDemonManager | 
|---|
|  |  |  |  | 
|---|
|  |  |  | # Boss关注记录管理 | 
|---|
|  |  |  | def GetBossAttentionManager(): | 
|---|
|  |  |  | return PyGameData.g_pyGameDataManager.bossAttentionManager | 
|---|
|  |  |  | pyGameDataMgr = GetPyGameDataManager() | 
|---|
|  |  |  | return pyGameDataMgr.bossAttentionManager | 
|---|
|  |  |  |  | 
|---|
|  |  |  | # 交易所物品最近成交单价管理 | 
|---|
|  |  |  | def GetBourseItemLastPriceManager(): | 
|---|
|  |  |  | return PyGameData.g_pyGameDataManager.bourseItemLastPriceManager | 
|---|
|  |  |  | pyGameDataMgr = GetPyGameDataManager() | 
|---|
|  |  |  | return pyGameDataMgr.bourseItemLastPriceManager | 
|---|
|  |  |  |  | 
|---|
|  |  |  | # 交易所记录管理 | 
|---|
|  |  |  | def GetBourseRecordManager(): | 
|---|
|  |  |  | return PyGameData.g_pyGameDataManager.bourseRecordManager | 
|---|
|  |  |  | pyGameDataMgr = GetPyGameDataManager() | 
|---|
|  |  |  | return pyGameDataMgr.bourseRecordManager | 
|---|
|  |  |  |  | 
|---|
|  |  |  | # 战盟仓库物品管理 | 
|---|
|  |  |  | def GetFamilyStoreItemManager(): | 
|---|
|  |  |  | return PyGameData.g_pyGameDataManager.familyStoreItemManager | 
|---|
|  |  |  | pyGameDataMgr = GetPyGameDataManager() | 
|---|
|  |  |  | return pyGameDataMgr.familyStoreItemManager | 
|---|
|  |  |  |  | 
|---|
|  |  |  | # 好友系统 | 
|---|
|  |  |  | def GetFriendManager(): | 
|---|
|  |  |  | return PyGameData.g_pyGameDataManager.friendManager | 
|---|
|  |  |  | pyGameDataMgr = GetPyGameDataManager() | 
|---|
|  |  |  | return pyGameDataMgr.friendManager | 
|---|
|  |  |  |  | 
|---|
|  |  |  | # 社交信息管理 | 
|---|
|  |  |  | def GetPersonalSocialManager(): | 
|---|
|  |  |  | return PyGameData.g_pyGameDataManager.socialInfoManager | 
|---|
|  |  |  | pyGameDataMgr = GetPyGameDataManager() | 
|---|
|  |  |  | return pyGameDataMgr.socialInfoManager | 
|---|
|  |  |  |  | 
|---|
|  |  |  | # 仇人系统 | 
|---|
|  |  |  | def GetEnemyManager(): | 
|---|
|  |  |  | return PyGameData.g_pyGameDataManager.enemyManager | 
|---|
|  |  |  | pyGameDataMgr = GetPyGameDataManager() | 
|---|
|  |  |  | return pyGameDataMgr.enemyManager | 
|---|
|  |  |  |  | 
|---|
|  |  |  | # 最近联系人系统 | 
|---|
|  |  |  | def GetContactsManager(): | 
|---|
|  |  |  | return PyGameData.g_pyGameDataManager.contactsManager | 
|---|
|  |  |  | pyGameDataMgr = GetPyGameDataManager() | 
|---|
|  |  |  | return pyGameDataMgr.contactsManager | 
|---|
|  |  |  |  | 
|---|
|  |  |  | # 黑名单系统 | 
|---|
|  |  |  | def GetBlacklistManager(): | 
|---|
|  |  |  | return PyGameData.g_pyGameDataManager.blacklistManager | 
|---|
|  |  |  |  | 
|---|
|  |  |  | #=============================================================================== | 
|---|
|  |  |  | # PyGameData.g_pyGameDataManager = PyGameDataManager() | 
|---|
|  |  |  | # | 
|---|
|  |  |  | # PyGameData.g_pyGameDataManager.GetFriendManager().AddFriendBoth(3, 4) | 
|---|
|  |  |  | # PyGameData.g_pyGameDataManager.GetFriendManager().AddFriendBoth(3, 5) | 
|---|
|  |  |  | # PyGameData.g_pyGameDataManager.GetFriendManager().AddFriendBoth(3, 6) | 
|---|
|  |  |  | # PyGameData.g_pyGameDataManager.GetFriendManager().AddFriendBoth(6, 4) | 
|---|
|  |  |  | #=============================================================================== | 
|---|
|  |  |  | pyGameDataMgr = GetPyGameDataManager() | 
|---|
|  |  |  | return pyGameDataMgr.blacklistManager | 
|---|