6328 【后端】优化代码eval -- 玩家缓存数据提取常用字段 等级和最后一次发送时间
8个文件已修改
152 ■■■■■ 已修改文件
ServerPython/CoreServerGroup/GameServer/Script/ChMapToGamePyPack.py 11 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ServerPython/CoreServerGroup/GameServer/Script/IPY_PlayerViewCache.py 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ServerPython/CoreServerGroup/GameServer/Script/Player/PlayerFriend.py 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ServerPython/CoreServerGroup/GameServer/Script/Player/PlayerGeTui.py 39 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ServerPython/CoreServerGroup/GameServer/Script/Player/PlayerViewCache.py 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/ChMapToGamePyPack.py 11 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerViewCacheTube.py 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
Tool/数据库/ChangeAccount/Collections/DataServerPlayerData.py 61 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ServerPython/CoreServerGroup/GameServer/Script/ChMapToGamePyPack.py
@@ -672,6 +672,7 @@
    PlusDataSize = 0    #(DWORD PlusDataSize)
    PlusData = ""    #(String PlusData)//扩展记录
    IsLogouting = 0    #(BYTE IsLogouting)//本次是否为下线同步
    OffTime = 0    #(DWORD OffTime)// ä¸‹çº¿æ—¶é—´æˆ³
    data = None
    def __init__(self):
@@ -692,6 +693,7 @@
        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):
@@ -708,6 +710,7 @@
        self.PlusDataSize = 0
        self.PlusData = ""
        self.IsLogouting = 0
        self.OffTime = 0
        return
    def GetLength(self):
@@ -722,6 +725,7 @@
        length += 4
        length += len(self.PlusData)
        length += 1
        length += 4
        return length
@@ -737,6 +741,7 @@
        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):
@@ -750,7 +755,8 @@
                                ItemData:%s,
                                PlusDataSize:%d,
                                PlusData:%s,
                                IsLogouting:%d
                                IsLogouting:%d,
                                OffTime:%d
                                '''\
                                %(
                                self.Head.OutputString(),
@@ -762,7 +768,8 @@
                                self.ItemData,
                                self.PlusDataSize,
                                self.PlusData,
                                self.IsLogouting
                                self.IsLogouting,
                                self.OffTime
                                )
        return DumpString
ServerPython/CoreServerGroup/GameServer/Script/IPY_PlayerViewCache.py
@@ -233,8 +233,12 @@
    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)
ServerPython/CoreServerGroup/GameServer/Script/Player/PlayerFriend.py
@@ -81,8 +81,7 @@
            #玩家的数据没有缓存过
            PlayerControl.NotifyCode(curPlayer, 'Friend_OffLine')
            return
        cacheDict = eval(curCache.GetPropData())
        tagLV = cacheDict["LV"]
        tagLV = curCache.GetPlayerLV()
    else:
        tagLV = tagPlayer.GetLV()
    
ServerPython/CoreServerGroup/GameServer/Script/Player/PlayerGeTui.py
@@ -86,14 +86,6 @@
# æ£€æŸ¥æ˜¯å¦å¯ä»¥ä¸ªæŽ¨ï¼Œ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:
@@ -263,6 +255,16 @@
                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玩家 å°é­”坛个推
@@ -281,17 +283,24 @@
        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):
@@ -327,6 +336,10 @@
    if not curCache:
        return
    if not CanGeTuiByCache(curCache):
        #无推送资格,基础判定
        return
    cacheDict = eval(curCache.GetPropData())
    if not CheckCanGeTui(cacheDict, Def_Onoff_Chat):
        # è¿‡æ»¤ä¸ªæŽ¨
ServerPython/CoreServerGroup/GameServer/Script/Player/PlayerViewCache.py
@@ -55,11 +55,13 @@
##更新缓存数据
#  @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, \
@@ -106,13 +108,15 @@
##玩家下线缓存数据
#  @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
## æ ¹æ®è§„则判定是否需要继续保存离线玩家数据
@@ -179,12 +183,11 @@
    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
ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/ChMapToGamePyPack.py
@@ -672,6 +672,7 @@
    PlusDataSize = 0    #(DWORD PlusDataSize)
    PlusData = ""    #(String PlusData)//扩展记录
    IsLogouting = 0    #(BYTE IsLogouting)//本次是否为下线同步
    OffTime = 0    #(DWORD OffTime)// ä¸‹çº¿æ—¶é—´æˆ³
    data = None
    def __init__(self):
@@ -692,6 +693,7 @@
        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):
@@ -708,6 +710,7 @@
        self.PlusDataSize = 0
        self.PlusData = ""
        self.IsLogouting = 0
        self.OffTime = 0
        return
    def GetLength(self):
@@ -722,6 +725,7 @@
        length += 4
        length += len(self.PlusData)
        length += 1
        length += 4
        return length
@@ -737,6 +741,7 @@
        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):
@@ -750,7 +755,8 @@
                                ItemData:%s,
                                PlusDataSize:%d,
                                PlusData:%s,
                                IsLogouting:%d
                                IsLogouting:%d,
                                OffTime:%d
                                '''\
                                %(
                                self.Head.OutputString(),
@@ -762,7 +768,8 @@
                                self.ItemData,
                                self.PlusDataSize,
                                self.PlusData,
                                self.IsLogouting
                                self.IsLogouting,
                                self.OffTime
                                )
        return DumpString
ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerViewCacheTube.py
@@ -73,6 +73,7 @@
    sendPack.PlusData = curPlayerPlusData
    sendPack.PlusDataSize = len(curPlayerPlusData)
    sendPack.IsLogouting = IsLogouting #通知本次同步是否下线前保存
    sendPack.OffTime = int(time.time())    # æœ€åŽä¸€æ¬¡å‘送即当做离线时间
    NetPackCommon.SendPyPackToGameServer(sendPack)
    GameWorld.DebugLog('ViewCache### UpdateGameServerPlayerCache out')
    return
@@ -106,7 +107,6 @@
    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
    # å°é­”坛剩余次数
Tool/Êý¾Ý¿â/ChangeAccount/Collections/DataServerPlayerData.py
@@ -18854,13 +18854,15 @@
        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),
@@ -18876,7 +18878,10 @@
    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
@@ -18894,7 +18899,11 @@
            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)
@@ -18909,7 +18918,10 @@
    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)
@@ -18921,7 +18933,10 @@
    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)
@@ -18934,7 +18949,10 @@
        '''组织存储记录'''
        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
@@ -18946,7 +18964,10 @@
    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)
@@ -19057,7 +19078,10 @@
    def outputString(self):
        output = '''//玩家数据查看缓存表#tagPlayerViewCache:
            PlayerID = %s,
            UpdateTime = %s,
            GeTuiIDSize = %s,
            GeTuiID = %s,
            LV = %s,
            OffTime = %s,
            PropDataSize = %s,
            PropData = %s,
            ItemDataSize = %s,
@@ -19067,7 +19091,10 @@
            ADOResult = %s,
            '''%(
                self.PlayerID,
                self.UpdateTime,
                self.GeTuiIDSize,
                self.GeTuiID,
                self.LV,
                self.OffTime,
                self.PropDataSize,
                self.PropData,
                self.ItemDataSize,
@@ -19079,9 +19106,12 @@
        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,
@@ -19091,13 +19121,6 @@
            )
        return output
    #Char数组类型Set接口,使用该接口对此类型数据赋值,防止赋值的数据过长报错
    def SetUpdateTime(self,Str):
        if len(Str)<=30:
            self.UpdateTime = Str
        else:
            self.UpdateTime = Str[:30]
#玩家好友表#tagDBPyPlayerFriend