6328 【后端】优化代码eval -- 玩家缓存数据提取常用字段 等级和最后一次发送时间
| | |
| | | PlusDataSize = 0 #(DWORD PlusDataSize)
|
| | | PlusData = "" #(String PlusData)//æ©å±è®°å½
|
| | | IsLogouting = 0 #(BYTE IsLogouting)//æ¬æ¬¡æ¯å¦ä¸ºä¸çº¿åæ¥
|
| | | OffTime = 0 #(DWORD OffTime)// ä¸çº¿æ¶é´æ³
|
| | | data = None
|
| | |
|
| | | def __init__(self):
|
| | |
| | | self.PlusDataSize,_pos = CommFunc.ReadDWORD(_lpData, _pos)
|
| | | self.PlusData,_pos = CommFunc.ReadString(_lpData, _pos,self.PlusDataSize)
|
| | | self.IsLogouting,_pos = CommFunc.ReadBYTE(_lpData, _pos)
|
| | | self.OffTime,_pos = CommFunc.ReadDWORD(_lpData, _pos)
|
| | | return _pos
|
| | |
|
| | | def Clear(self):
|
| | |
| | | self.PlusDataSize = 0
|
| | | self.PlusData = ""
|
| | | self.IsLogouting = 0
|
| | | self.OffTime = 0
|
| | | return
|
| | |
|
| | | def GetLength(self):
|
| | |
| | | length += 4
|
| | | length += len(self.PlusData)
|
| | | length += 1
|
| | | length += 4
|
| | |
|
| | | return length
|
| | |
|
| | |
| | | data = CommFunc.WriteDWORD(data, self.PlusDataSize)
|
| | | data = CommFunc.WriteString(data, self.PlusDataSize, self.PlusData)
|
| | | data = CommFunc.WriteBYTE(data, self.IsLogouting)
|
| | | data = CommFunc.WriteDWORD(data, self.OffTime)
|
| | | return data
|
| | |
|
| | | def OutputString(self):
|
| | |
| | | ItemData:%s,
|
| | | PlusDataSize:%d,
|
| | | PlusData:%s,
|
| | | IsLogouting:%d
|
| | | IsLogouting:%d,
|
| | | OffTime:%d
|
| | | '''\
|
| | | %(
|
| | | self.Head.OutputString(),
|
| | |
| | | self.ItemData,
|
| | | self.PlusDataSize,
|
| | | self.PlusData,
|
| | | self.IsLogouting
|
| | | self.IsLogouting,
|
| | | self.OffTime
|
| | | )
|
| | | return DumpString
|
| | |
|
| | |
| | | def Clear(self): return _IPY_PlayerViewCache.IPY_PlayerViewCache_Clear(self)
|
| | | def GetPlayerID(self): return _IPY_PlayerViewCache.IPY_PlayerViewCache_GetPlayerID(self)
|
| | | def SetPlayerID(self, *args): return _IPY_PlayerViewCache.IPY_PlayerViewCache_SetPlayerID(self, *args)
|
| | | def GetUpdateTime(self): return _IPY_PlayerViewCache.IPY_PlayerViewCache_GetUpdateTime(self)
|
| | | def SetUpdateTime(self, *args): return _IPY_PlayerViewCache.IPY_PlayerViewCache_SetUpdateTime(self, *args)
|
| | | def GetPlayerLV(self): return _IPY_PlayerViewCache.IPY_PlayerViewCache_GetPlayerLV(self)
|
| | | def SetPlayerLV(self, *args): return _IPY_PlayerViewCache.IPY_PlayerViewCache_SetPlayerLV(self, *args)
|
| | | def GetOffTime(self): return _IPY_PlayerViewCache.IPY_PlayerViewCache_GetOffTime(self)
|
| | | def SetOffTime(self, *args): return _IPY_PlayerViewCache.IPY_PlayerViewCache_SetOffTime(self, *args)
|
| | | def GetGeTuiID(self): return _IPY_PlayerViewCache.IPY_PlayerViewCache_GetGeTuiID(self)
|
| | | def SetGeTuiID(self, *args): return _IPY_PlayerViewCache.IPY_PlayerViewCache_SetGeTuiID(self, *args)
|
| | | def SetPropData(self, *args): return _IPY_PlayerViewCache.IPY_PlayerViewCache_SetPropData(self, *args)
|
| | | def GetPropData(self): return _IPY_PlayerViewCache.IPY_PlayerViewCache_GetPropData(self)
|
| | | def SetItemData(self, *args): return _IPY_PlayerViewCache.IPY_PlayerViewCache_SetItemData(self, *args)
|
| | |
| | | #ç©å®¶çæ°æ®æ²¡æç¼åè¿
|
| | | PlayerControl.NotifyCode(curPlayer, 'Friend_OffLine')
|
| | | return
|
| | | cacheDict = eval(curCache.GetPropData())
|
| | | tagLV = cacheDict["LV"]
|
| | | tagLV = curCache.GetPlayerLV()
|
| | | else:
|
| | | tagLV = tagPlayer.GetLV()
|
| | |
|
| | |
| | |
|
| | | # æ£æ¥æ¯å¦å¯ä»¥ä¸ªæ¨ï¼geTuiTypeå°äº0ç代表é»è®¤å¯æ¨ï¼æ VIPéå¶
|
| | | def CheckCanGeTui(playerCache, geTuiType=-1):
|
| | | if not playerCache.get("GeTuiClientID", ""):
|
| | | return False
|
| | | |
| | | # 离线è¶
è¿24å°æ¶ä¸åæ¨éï¼ç®åæå
æ¨éçç¹ç¹æ¯æ¨éIDåæºå¨ä¸åå
齿¯åä¸ä¸ªID
|
| | | if not playerCache.get("Time", 0):
|
| | | return False
|
| | | if time.time() - playerCache.get("Time", 0) > 24*60*60:
|
| | | return False
|
| | |
|
| | | if not playerCache.get("VIPLV", 0):
|
| | | if geTuiType < 0:
|
| | |
| | | return True
|
| | | return True
|
| | |
|
| | | # 个æ¨åºç¡å¤å®
|
| | | def CanGeTuiByCache(curCache):
|
| | | if not curCache.GetGeTuiID():
|
| | | return False
|
| | | |
| | | # 离线è¶
è¿24å°æ¶ä¸åæ¨éï¼ç®åæå
æ¨éçç¹ç¹æ¯æ¨éIDåæºå¨ä¸åå
齿¯åä¸ä¸ªID
|
| | | if time.time() - curCache.GetOffTime() > 24*60*60:
|
| | | return False
|
| | | return True
|
| | | |
| | | def BossAttentionGeTui(bossData, bossID):
|
| | | if bossData.GetMapID() == ChConfig.Def_FBMapID_SealDemon:
|
| | | # éVIPç©å®¶ å°éå个æ¨
|
| | |
| | | curPlayer = GameWorld.GetPlayerManager().FindPlayerByID(playerID)
|
| | | if curPlayer and not PlayerControl.GetIsTJG(curPlayer):
|
| | | continue
|
| | |
|
| | | |
| | | # 离线ç©å®¶
|
| | | curCache = PlayerViewCache.ViewCacheMgr.FindCache(playerID)
|
| | | if not curCache:
|
| | | continue
|
| | | |
| | | if not CanGeTuiByCache(curCache):
|
| | | #æ æ¨éèµæ ¼ï¼åå°æ£ç´¢åeval
|
| | | continue
|
| | | |
| | | recordDict = eval(bossAttentionData.RecordData)
|
| | | if recordDict.get(bossID, 0) in [0, 9]:
|
| | | #0-é»è®¤æªå
³æ³¨, 1-主å¨å
³æ³¨, 2-èªå¨å
³æ³¨, 9-主å¨åæ¶å
³æ³¨
|
| | | continue
|
| | | curCache = PlayerViewCache.ViewCacheMgr.FindCache(playerID)
|
| | | if not curCache:
|
| | | continue
|
| | | |
| | | cacheDict = eval(curCache.GetPropData())
|
| | | if not CheckCanGeTui(cacheDict, geTuiType):
|
| | | # è¿æ»¤ä¸ªæ¨
|
| | | # 个æ¨é»è¾æ£æ¥
|
| | | continue
|
| | |
|
| | | if not CheckBossGeTuiCnt(playerID, bossID, geTuiType, cacheDict):
|
| | |
| | | if not curCache:
|
| | | return
|
| | |
|
| | | if not CanGeTuiByCache(curCache):
|
| | | #æ æ¨éèµæ ¼ï¼åºç¡å¤å®
|
| | | return
|
| | |
|
| | | cacheDict = eval(curCache.GetPropData())
|
| | | if not CheckCanGeTui(cacheDict, Def_Onoff_Chat):
|
| | | # è¿æ»¤ä¸ªæ¨
|
| | |
| | | ##æ´æ°ç¼åæ°æ®
|
| | | # @param PlayerID, PropData, ItemData, PlusData, isSaveDB
|
| | | # @return None
|
| | | def UpdatePlayerCache(PlayerID, PropData, ItemData, PlusData, isSaveDB=False):
|
| | | def UpdatePlayerCache(PlayerID, PropData, ItemData, PlusData, isSaveDB=False, packData=None):
|
| | | curCache = ViewCacheMgr.FindCache(PlayerID)
|
| | | if not curCache:
|
| | | curCache = ViewCacheMgr.AddNewCache(PlayerID)
|
| | | curCache.SetUpdateTime(GameWorld.GetCurrentDataTimeStr())
|
| | | if packData:
|
| | | curCache.SetPlayerLV(packData.PlayerLV)
|
| | | curCache.SetOffTime(packData.OffTime)
|
| | |
|
| | |
|
| | | GameWorld.DebugLog('ViewCache### UpdatePlayerCache PlayerID %s, \
|
| | |
| | | ##ç©å®¶ä¸çº¿ç¼åæ°æ®
|
| | | # @param PlayerID, PlayerLV, PropData, ItemData, PlusData
|
| | | # @return None
|
| | | def OnPlayerLogout(PlayerID, PlayerLV, PropData, ItemData, PlusData): |
| | | def OnPlayerLogout(curPackData): |
| | | PlayerID = curPackData.PlayerID
|
| | | PlayerLV = curPackData.PlayerLV
|
| | | #ä¸éè¦ä¿åç¦»çº¿æ°æ®çï¼ç´æ¥å é¤ç¼åæ°æ®
|
| | | if not IsNeedSaveLogoutPlayer(PlayerID, PlayerLV):
|
| | | ViewCacheMgr.DeleteCache(PlayerID)
|
| | | return
|
| | | #æ´æ°æ°æ®ï¼å¹¶è®¾ç½®éè¦ä¿åæ°æ®åº
|
| | | UpdatePlayerCache(PlayerID, PropData, ItemData, PlusData, True) |
| | | UpdatePlayerCache(PlayerID, curPackData.PropData, curPackData.ItemData, curPackData.PlusData, True, packData=curPackData) |
| | | return
|
| | |
|
| | | ## æ ¹æ®è§åå¤å®æ¯å¦éè¦ç»§ç»ä¿å离线ç©å®¶æ°æ®
|
| | |
| | | PlayerID = curPackData.PlayerID
|
| | | PlayerLV = curPackData.PlayerLV
|
| | | if curPackData.IsLogouting:
|
| | | OnPlayerLogout(PlayerID, PlayerLV, \
|
| | | curPackData.PropData, curPackData.ItemData, curPackData.PlusData)
|
| | | OnPlayerLogout(curPackData)
|
| | | else:
|
| | | # æ¤å¤ä¿å设置为Trueæ¯ä¸ºå®å
¨é²èï¼æ¯å¦çªç¶æçµï¼å®æºçæ
åµ å¯¼è´è¯¯ä»¥ä¸ºä¸ä¿åï¼æ
ç级å¯è®¾ç½®é«ä¸ç¹
|
| | | UpdatePlayerCache(PlayerID, curPackData.PropData, \
|
| | | curPackData.ItemData, curPackData.PlusData, True if PlayerLV > 150 else False)
|
| | | curPackData.ItemData, curPackData.PlusData, True if PlayerLV > 150 else False, packData=curPackData)
|
| | | GameWorld.DebugLog('ViewCache### OnMGUpdatePlayerCache out')
|
| | | return
|
| | |
|
| | |
| | | PlusDataSize = 0 #(DWORD PlusDataSize)
|
| | | PlusData = "" #(String PlusData)//æ©å±è®°å½
|
| | | IsLogouting = 0 #(BYTE IsLogouting)//æ¬æ¬¡æ¯å¦ä¸ºä¸çº¿åæ¥
|
| | | OffTime = 0 #(DWORD OffTime)// ä¸çº¿æ¶é´æ³
|
| | | data = None
|
| | |
|
| | | def __init__(self):
|
| | |
| | | self.PlusDataSize,_pos = CommFunc.ReadDWORD(_lpData, _pos)
|
| | | self.PlusData,_pos = CommFunc.ReadString(_lpData, _pos,self.PlusDataSize)
|
| | | self.IsLogouting,_pos = CommFunc.ReadBYTE(_lpData, _pos)
|
| | | self.OffTime,_pos = CommFunc.ReadDWORD(_lpData, _pos)
|
| | | return _pos
|
| | |
|
| | | def Clear(self):
|
| | |
| | | self.PlusDataSize = 0
|
| | | self.PlusData = ""
|
| | | self.IsLogouting = 0
|
| | | self.OffTime = 0
|
| | | return
|
| | |
|
| | | def GetLength(self):
|
| | |
| | | length += 4
|
| | | length += len(self.PlusData)
|
| | | length += 1
|
| | | length += 4
|
| | |
|
| | | return length
|
| | |
|
| | |
| | | data = CommFunc.WriteDWORD(data, self.PlusDataSize)
|
| | | data = CommFunc.WriteString(data, self.PlusDataSize, self.PlusData)
|
| | | data = CommFunc.WriteBYTE(data, self.IsLogouting)
|
| | | data = CommFunc.WriteDWORD(data, self.OffTime)
|
| | | return data
|
| | |
|
| | | def OutputString(self):
|
| | |
| | | ItemData:%s,
|
| | | PlusDataSize:%d,
|
| | | PlusData:%s,
|
| | | IsLogouting:%d
|
| | | IsLogouting:%d,
|
| | | OffTime:%d
|
| | | '''\
|
| | | %(
|
| | | self.Head.OutputString(),
|
| | |
| | | self.ItemData,
|
| | | self.PlusDataSize,
|
| | | self.PlusData,
|
| | | self.IsLogouting
|
| | | self.IsLogouting,
|
| | | self.OffTime
|
| | | )
|
| | | return DumpString
|
| | |
|
| | |
| | | sendPack.PlusData = curPlayerPlusData
|
| | | sendPack.PlusDataSize = len(curPlayerPlusData)
|
| | | sendPack.IsLogouting = IsLogouting #éç¥æ¬æ¬¡åæ¥æ¯å¦ä¸çº¿åä¿å
|
| | | sendPack.OffTime = int(time.time()) # æå䏿¬¡åéå³å½å离线æ¶é´
|
| | | NetPackCommon.SendPyPackToGameServer(sendPack)
|
| | | GameWorld.DebugLog('ViewCache### UpdateGameServerPlayerCache out')
|
| | | return
|
| | |
| | | curPlayerPropDict[ChConfig.Def_PDict_GeTuiSet] = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GeTuiSet)
|
| | | curPlayerPropDict[ChConfig.Def_PDict_NoGeTuiTime] = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_NoGeTuiTime)
|
| | | curPlayerPropDict['GeTuiClientID'] = curPlayer.GetAccountData().GetGeTuiClientID()
|
| | | curPlayerPropDict['Time'] = int(time.time()) # æå䏿¬¡åéå³å½å离线æ¶é´
|
| | |
|
| | | # åç±»åè½ BOSS次æ°, BOSSç¸å
³å¯¹åºB.Bossä¿¡æ¯.xlsxçCntMark
|
| | | # å°éåå©ä½æ¬¡æ°
|
| | |
| | | else:
|
| | | self.GUID = Str[:40]
|
| | |
|
| | | |
| | | #ç©å®¶æ°æ®æ¥çç¼å表#tagPlayerViewCache
|
| | | class tagPlayerViewCache(Structure):
|
| | | _pack_ = 1
|
| | | _fields_ = [
|
| | | ('PlayerID', ctypes.c_ulong),
|
| | | ('UpdateTime', ctypes.c_char * 30),
|
| | | ('GeTuiIDSize', ctypes.c_ubyte),
|
| | | ('GeTuiID', ctypes.c_char_p),
|
| | | ('LV', ctypes.c_ushort),
|
| | | ('OffTime', ctypes.c_ulong),
|
| | | ('PropDataSize', ctypes.c_ulong),
|
| | | ('PropData', ctypes.c_char_p),
|
| | | ('ItemDataSize', ctypes.c_ulong),
|
| | |
| | |
|
| | | def clear(self):
|
| | | self.PlayerID = 0
|
| | | self.UpdateTime = ''
|
| | | self.GeTuiIDSize = 0
|
| | | self.GeTuiID = ''
|
| | | self.LV = 0
|
| | | self.OffTime = 0
|
| | | self.PropDataSize = 0
|
| | | self.PropData = ''
|
| | | self.ItemDataSize = 0
|
| | |
| | | mylog.error(msg)
|
| | | self.clear()
|
| | | self.PlayerID, pos = CommFunc.ReadDWORD(buf, pos)
|
| | | self.UpdateTime, pos = CommFunc.ReadString(buf, pos, 30)
|
| | | self.GeTuiIDSize, pos = CommFunc.ReadBYTE(buf, pos)
|
| | | tmp, pos = CommFunc.ReadString(buf, pos, self.GeTuiIDSize)
|
| | | self.GeTuiID = ctypes.c_char_p(tmp)
|
| | | self.LV, pos = CommFunc.ReadWORD(buf, pos)
|
| | | self.OffTime, pos = CommFunc.ReadDWORD(buf, pos)
|
| | | self.PropDataSize, pos = CommFunc.ReadDWORD(buf, pos)
|
| | | tmp, pos = CommFunc.ReadString(buf, pos, self.PropDataSize)
|
| | | self.PropData = ctypes.c_char_p(tmp)
|
| | |
| | | def getBuffer(self):
|
| | | buf = ''
|
| | | buf = CommFunc.WriteDWORD(buf, self.PlayerID)
|
| | | buf = CommFunc.WriteString(buf, sizeof(ctypes.c_char) * 30, self.UpdateTime)
|
| | | buf = CommFunc.WriteBYTE(buf, self.GeTuiIDSize)
|
| | | buf = CommFunc.WriteString(buf, self.GeTuiIDSize, self.GeTuiID)
|
| | | buf = CommFunc.WriteWORD(buf, self.LV)
|
| | | buf = CommFunc.WriteDWORD(buf, self.OffTime)
|
| | | buf = CommFunc.WriteDWORD(buf, self.PropDataSize)
|
| | | buf = CommFunc.WriteString(buf, self.PropDataSize, self.PropData)
|
| | | buf = CommFunc.WriteDWORD(buf, self.ItemDataSize)
|
| | |
| | | def getLength(self):
|
| | | length = 0
|
| | | length += sizeof(ctypes.c_ulong)
|
| | | length += sizeof(ctypes.c_char) * 30
|
| | | length += sizeof(ctypes.c_ubyte)
|
| | | length += self.GeTuiIDSize
|
| | | length += sizeof(ctypes.c_ushort)
|
| | | length += sizeof(ctypes.c_ulong)
|
| | | length += sizeof(ctypes.c_ulong)
|
| | | length += self.PropDataSize
|
| | | length += sizeof(ctypes.c_ulong)
|
| | |
| | | '''ç»ç»åå¨è®°å½'''
|
| | | rec = {}
|
| | | rec[u'PlayerID'] = self.PlayerID
|
| | | rec[u'UpdateTime'] = fix_incomingText(self.UpdateTime)
|
| | | rec[u'GeTuiIDSize'] = self.GeTuiIDSize
|
| | | rec[u'GeTuiID'] = fix_incomingText(self.GeTuiID)
|
| | | rec[u'LV'] = self.LV
|
| | | rec[u'OffTime'] = self.OffTime
|
| | | rec[u'PropDataSize'] = self.PropDataSize
|
| | | rec[u'PropData'] = fix_incomingText(self.PropData)
|
| | | rec[u'ItemDataSize'] = self.ItemDataSize
|
| | |
| | | def readRecord(self, rec):
|
| | | '''ç±äºMongoDBè¯»åºæ¥æ¯unicode,ææå符串éè¦è¿è¡è½¬æ¢'''
|
| | | self.PlayerID = rec.get(u'PlayerID', 0)
|
| | | self.UpdateTime = fix_outgoingText(rec.get(u'UpdateTime', u''))
|
| | | self.GeTuiIDSize = rec.get(u'GeTuiIDSize', 0)
|
| | | self.GeTuiID = fix_outgoingText(rec.get(u'GeTuiID', u''))
|
| | | self.LV = rec.get(u'LV', 0)
|
| | | self.OffTime = rec.get(u'OffTime', 0)
|
| | | self.PropDataSize = rec.get(u'PropDataSize', 0)
|
| | | self.PropData = fix_outgoingText(rec.get(u'PropData', u''))
|
| | | self.ItemDataSize = rec.get(u'ItemDataSize', 0)
|
| | |
| | | def outputString(self):
|
| | | output = '''//ç©å®¶æ°æ®æ¥çç¼å表#tagPlayerViewCache:
|
| | | PlayerID = %s,
|
| | | UpdateTime = %s,
|
| | | GeTuiIDSize = %s,
|
| | | GeTuiID = %s,
|
| | | LV = %s,
|
| | | OffTime = %s,
|
| | | PropDataSize = %s,
|
| | | PropData = %s,
|
| | | ItemDataSize = %s,
|
| | |
| | | ADOResult = %s,
|
| | | '''%(
|
| | | self.PlayerID,
|
| | | self.UpdateTime,
|
| | | self.GeTuiIDSize,
|
| | | self.GeTuiID,
|
| | | self.LV,
|
| | | self.OffTime,
|
| | | self.PropDataSize,
|
| | | self.PropData,
|
| | | self.ItemDataSize,
|
| | |
| | | return output
|
| | |
|
| | | def dumpString(self):
|
| | | output = '''%1s\t%1s\t%1s\t%1s\t%1s\t%1s\t%1s\t%1s'''%(
|
| | | output = '''%1s\t%1s\t%1s\t%1s\t%1s\t%1s\t%1s\t%1s\t%1s\t%1s\t%1s'''%(
|
| | | self.PlayerID,
|
| | | self.UpdateTime,
|
| | | self.GeTuiIDSize,
|
| | | self.GeTuiID,
|
| | | self.LV,
|
| | | self.OffTime,
|
| | | self.PropDataSize,
|
| | | self.PropData,
|
| | | self.ItemDataSize,
|
| | |
| | | )
|
| | | return output
|
| | |
|
| | | #Charæ°ç»ç±»åSetæ¥å£,使ç¨è¯¥æ¥å£å¯¹æ¤ç±»åæ°æ®èµå¼ï¼é²æ¢èµå¼çæ°æ®è¿é¿æ¥é
|
| | | def SetUpdateTime(self,Str):
|
| | | if len(Str)<=30:
|
| | | self.UpdateTime = Str
|
| | | else:
|
| | | self.UpdateTime = Str[:30]
|
| | | |
| | |
|
| | |
|
| | | #ç©å®¶å¥½å表#tagDBPyPlayerFriend
|