From 7e2fba6800afaaeef3ac9d2d3c8c42ebcefd2016 Mon Sep 17 00:00:00 2001
From: hch <305670599@qq.com>
Date: 星期二, 05 三月 2019 15:53:48 +0800
Subject: [PATCH] 6328 【后端】优化代码eval

---
 ServerPython/CoreServerGroup/GameServer/Script/GameWorldLogic/CrossRealmMsg.py             |    8 ++--
 ServerPython/CoreServerGroup/GameServer/Script/GameWorldLogic/GameWorldActionControl.py    |   11 +++--
 ServerPython/CoreServerGroup/GameServer/Script/GameWorldLogic/CrossRealmPK.py              |    5 +-
 ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerFamily.py |    5 +-
 ServerPython/CoreServerGroup/GameServer/Script/Player/PlayerGeTui.py                       |    8 ++--
 ServerPython/CoreServerGroup/GameServer/Script/Player/PlayerViewCache.py                   |    8 ++--
 ServerPython/CoreServerGroup/GameServer/Script/GameWorldLogic/GameWorldFamilyWar.py        |    6 +-
 ServerPython/CoreServerGroup/GameServer/Script/GameWorldLogic/GameWorldBoss.py             |   19 ++++-----
 ServerPython/CoreServerGroup/GameServer/Script/Player/PlayerSocial.py                      |    4 +-
 ServerPython/CoreServerGroup/GameServer/Script/Player/PlayerTalk.py                        |    3 +
 ServerPython/CoreServerGroup/GameServer/Script/Player/PlayerFamilyAction.py                |    3 +
 ServerPython/CoreServerGroup/GameServer/Script/Player/PlayerFriend.py                      |    7 ++-
 12 files changed, 46 insertions(+), 41 deletions(-)

diff --git a/ServerPython/CoreServerGroup/GameServer/Script/GameWorldLogic/CrossRealmMsg.py b/ServerPython/CoreServerGroup/GameServer/Script/GameWorldLogic/CrossRealmMsg.py
index b67d031..c198f41 100644
--- a/ServerPython/CoreServerGroup/GameServer/Script/GameWorldLogic/CrossRealmMsg.py
+++ b/ServerPython/CoreServerGroup/GameServer/Script/GameWorldLogic/CrossRealmMsg.py
@@ -37,7 +37,7 @@
         return
     if not dataMsg:
         return
-    sendMsg = str({"MsgType":msgType, "Data":dataMsg, "ServerGroupID":GameWorld.GetServerGroupID()})
+    sendMsg = json.dumps({"MsgType":msgType, "Data":dataMsg, "ServerGroupID":GameWorld.GetServerGroupID()}, ensure_ascii=False)
     if not GameWorld.GetGameWorld().GetDictByKey(ChConfig.Def_WorldKey_GameWorldInitOK):
         GameWorld.ErrLog("服务器未启动好,不允许向跨服服务器发送数据! %s" % (sendMsg))
         return
@@ -52,7 +52,7 @@
         if not GameWorld.GetGameWorld().GetDictByKey(ChConfig.Def_WorldKey_GameWorldInitOK):
             GameWorld.Log("服务器未启动好,不处理子服信息!")
             return
-        msgDict = eval(recvMsg)
+        msgDict = json.loads(recvMsg)
         
         msgType = msgDict.get("MsgType", -1)    
         msgData = msgDict.get("Data", "")
@@ -157,7 +157,7 @@
         return
     if not dataMsg:
         return
-    sendMsg = str({"MsgType":msgType, "Data":dataMsg})
+    sendMsg = json.dumps({"MsgType":msgType, "Data":dataMsg}, ensure_ascii=False)
     if not GameWorld.GetGameWorld().GetDictByKey(ChConfig.Def_WorldKey_GameWorldInitOK):
         GameWorld.ErrLog("跨服服务器未启动好,不允许向子服发送数据! serverGroupIDList=%s, sendMsg=%s" % (serverGroupIDList, sendMsg))
         return
@@ -183,7 +183,7 @@
             GameWorld.Log("服务器未启动好,不处理跨服信息!")
             return
         
-        msgDict = eval(dataMsg)
+        msgDict = json.loads(dataMsg)
         msgType = msgDict.get("MsgType", -1)    
         msgData = msgDict.get("Data", "")
         
diff --git a/ServerPython/CoreServerGroup/GameServer/Script/GameWorldLogic/CrossRealmPK.py b/ServerPython/CoreServerGroup/GameServer/Script/GameWorldLogic/CrossRealmPK.py
index 9b62c48..9ae3cb6 100644
--- a/ServerPython/CoreServerGroup/GameServer/Script/GameWorldLogic/CrossRealmPK.py
+++ b/ServerPython/CoreServerGroup/GameServer/Script/GameWorldLogic/CrossRealmPK.py
@@ -35,6 +35,7 @@
 import operator
 import random
 import time
+import json
 
 class CrossPKPlayer():
     ## 跨服PK玩家类
@@ -1922,7 +1923,7 @@
             overInfoData.OverType = overType
             overInfoData.PlayerID = playerID
             overInfoData.WinnerID = winnerID
-            overInfoData.RoundWinnerInfo = str(roundWinnerIDList)
+            overInfoData.RoundWinnerInfo = json.dumps(roundWinnerIDList, ensure_ascii=False)
             overInfoData.RoundWinnerLen = len(overInfoData.RoundWinnerInfo)
             overInfoData.PKScore = pkScore
             overInfoData.DanLV = danLV
@@ -1957,7 +1958,7 @@
     winnerID = overInfoData.WinnerID
     roundWinnerIDList = []
     try:
-        roundWinnerIDList = eval(overInfoData.RoundWinnerInfo)
+        roundWinnerIDList = json.loads(overInfoData.RoundWinnerInfo)
     except:
         GameWorld.ErrLog("__OnLoginNotifyPKOverInfo roundWinnerIDList eval error! RoundWinnerInfo=%s" % overInfoData.RoundWinnerInfo, playerID)
     pkScore = overInfoData.PKScore
diff --git a/ServerPython/CoreServerGroup/GameServer/Script/GameWorldLogic/GameWorldActionControl.py b/ServerPython/CoreServerGroup/GameServer/Script/GameWorldLogic/GameWorldActionControl.py
index f53d752..7d16d92 100644
--- a/ServerPython/CoreServerGroup/GameServer/Script/GameWorldLogic/GameWorldActionControl.py
+++ b/ServerPython/CoreServerGroup/GameServer/Script/GameWorldLogic/GameWorldActionControl.py
@@ -42,6 +42,7 @@
 
 from types import IntType
 import time
+import json
 #---------------------------------------------------------------------
 
 #年月日时间格式
@@ -1120,20 +1121,20 @@
         recMapID = universalRecData.GetValue1()
         if recMapID == mapID:
             findRecData = universalRecData
-        fbOpenRecord[recMapID] = eval(universalRecData.GetStrValue1())
+        fbOpenRecord[recMapID] = json.loads(universalRecData.GetStrValue1())
         
     if not findRecData:
         findRecData = recTypeListData.AddRec()
         findRecData.SetValue1(mapID)
-        findRecData.SetStrValue1(str([curDayStr]))
+        findRecData.SetStrValue1(json.dumps([curDayStr], ensure_ascii=False))
         fbOpenRecord[mapID] = [curDayStr]
     else:
-        recordList = eval(findRecData.GetStrValue1())
+        recordList = json.loads(findRecData.GetStrValue1())
         if curDayStr not in recordList:
             recordList.append(curDayStr)
             if len(recordList) > 3: #只存最近3次
                 del recordList[0]
-            findRecData.SetStrValue1(str(recordList))
+            findRecData.SetStrValue1(json.dumps(recordList, ensure_ascii=False))
             fbOpenRecord[mapID] = recordList
         else:
             return
@@ -1149,7 +1150,7 @@
     for index in range(recTypeListData.Count()):
         universalRecData = recTypeListData.At(index)
         recMapID = universalRecData.GetValue1()
-        recordList = eval(universalRecData.GetStrValue1())
+        recordList = json.loads(universalRecData.GetStrValue1())
         fbOpenRecord[recMapID] = recordList
     return fbOpenRecord
 
diff --git a/ServerPython/CoreServerGroup/GameServer/Script/GameWorldLogic/GameWorldBoss.py b/ServerPython/CoreServerGroup/GameServer/Script/GameWorldLogic/GameWorldBoss.py
index b8430ba..b83b6f9 100644
--- a/ServerPython/CoreServerGroup/GameServer/Script/GameWorldLogic/GameWorldBoss.py
+++ b/ServerPython/CoreServerGroup/GameServer/Script/GameWorldLogic/GameWorldBoss.py
@@ -50,7 +50,7 @@
 import CrossBoss
 
 import time
-
+import json
 
 
 '''
@@ -717,10 +717,12 @@
     def GetBossAttentionDict(self):
         return self.bossAttentionDict
 
+    # RecordData改json记录 bossid存为字符串
     def UpdateBossAttention(self, playerid, bossid, isAdd):
+        bossid = str(bossid)
         if playerid in self.bossAttentionDict:
             bossAttentionData = self.bossAttentionDict[playerid]
-            recordDict = eval(bossAttentionData.RecordData)
+            recordDict = json.loads(bossAttentionData.RecordData)
             if isAdd:
                 recordDict[bossid] = isAdd
             else:
@@ -731,7 +733,7 @@
                 self.bossAttentionDict.pop(playerid)
                 
             else:
-                bossAttentionData.RecordData = str(recordDict)
+                bossAttentionData.RecordData = json.dumps(recordDict, ensure_ascii=False)
                 bossAttentionData.DataLen = len(bossAttentionData.RecordData)
         else:
             if not isAdd:
@@ -739,7 +741,7 @@
             bossAttention = PyGameDataStruct.tagDBPyBossAttention()
             bossAttention.clear()
             bossAttention.PlayerID = playerid
-            bossAttention.RecordData = str({bossid:isAdd})
+            bossAttention.RecordData = json.dumps({bossid:isAdd}, ensure_ascii=False)
             bossAttention.DataLen = len(bossAttention.RecordData)
             self.bossAttentionDict[playerid] = bossAttention
         
@@ -753,12 +755,12 @@
         attentionData = self.bossAttentionDict.get(curPlayer.GetPlayerID())
         if not attentionData:
             return
-        bttentionDict = eval(attentionData.RecordData)
+        bttentionDict = json.loads(attentionData.RecordData)
         packData = ChPyNetSendPack.tagGCBossAttentionInfo()
         packData.BossList = []
         for bossid, addState in bttentionDict.items():
             bossInfo = ChPyNetSendPack.tagGCBossAttention()
-            bossInfo.BossID=bossid
+            bossInfo.BossID=int(bossid)
             bossInfo.AddState=addState
             packData.BossList.append(bossInfo)
         
@@ -790,10 +792,7 @@
             data.clear()
             pos += data.readData(datas, pos, dataslen)
             playerID = data.PlayerID
-            if type(eval(data.RecordData)) != list:
-                self.bossAttentionDict[playerID] = data
-            else:
-                data.clear()
+            self.bossAttentionDict[playerID] = data
             
         return pos
 
diff --git a/ServerPython/CoreServerGroup/GameServer/Script/GameWorldLogic/GameWorldFamilyWar.py b/ServerPython/CoreServerGroup/GameServer/Script/GameWorldLogic/GameWorldFamilyWar.py
index 794ca6f..8836b9a 100644
--- a/ServerPython/CoreServerGroup/GameServer/Script/GameWorldLogic/GameWorldFamilyWar.py
+++ b/ServerPython/CoreServerGroup/GameServer/Script/GameWorldLogic/GameWorldFamilyWar.py
@@ -32,7 +32,7 @@
 
 import random
 import copy
-
+import json
 
 '''
 1. 仙盟改名
@@ -80,8 +80,8 @@
 def SetBatRecFamilyNameA(recData, familyNameA): return recData.SetStrValue1(familyNameA)
 def GetBatRecFamilyNameB(recData): return recData.GetStrValue2()
 def SetBatRecFamilyNameB(recData, familyNameB): return recData.SetStrValue2(familyNameB)
-def GetBatRecDissolutionID(recData): return [] if not recData.GetStrValue3() else eval(recData.GetStrValue3()) # 解散的家族ID列表 [familyID, ...]
-def SetBatRecDissolutionID(recData, dissFamilyIDList): return recData.SetStrValue3(str(dissFamilyIDList))
+def GetBatRecDissolutionID(recData): return [] if not recData.GetStrValue3() else json.loads(recData.GetStrValue3()) # 解散的家族ID列表 [familyID, ...]
+def SetBatRecDissolutionID(recData, dissFamilyIDList): return recData.SetStrValue3(json.dumps(dissFamilyIDList, ensure_ascii=False))
 
 ''' 王者仙盟
 value1        家族ID
diff --git a/ServerPython/CoreServerGroup/GameServer/Script/Player/PlayerFamilyAction.py b/ServerPython/CoreServerGroup/GameServer/Script/Player/PlayerFamilyAction.py
index 31c9cff..2ac4979 100644
--- a/ServerPython/CoreServerGroup/GameServer/Script/Player/PlayerFamilyAction.py
+++ b/ServerPython/CoreServerGroup/GameServer/Script/Player/PlayerFamilyAction.py
@@ -34,6 +34,7 @@
 import PlayerControl
 import IPY_GameServer
 import DataRecordPack
+import json
 #---------------------------------------------------------------------
 
 ## 设置玩家家族行为
@@ -44,7 +45,7 @@
 #  @return None
 def MapServer_PlayerFamilyActionNote(curPlayer, actionType, actionData, tick):
     
-    actionDataList = eval(actionData)
+    actionDataList = json.loads(actionData)
     
     familyId = curPlayer.GetFamilyID()
     
diff --git a/ServerPython/CoreServerGroup/GameServer/Script/Player/PlayerFriend.py b/ServerPython/CoreServerGroup/GameServer/Script/Player/PlayerFriend.py
index ef6881f..68c9778 100644
--- a/ServerPython/CoreServerGroup/GameServer/Script/Player/PlayerFriend.py
+++ b/ServerPython/CoreServerGroup/GameServer/Script/Player/PlayerFriend.py
@@ -28,6 +28,7 @@
 import copy
 import PlayerViewCache
 import PlayerTeam
+import json
 
 #---------------------------------------------------------------------
 
@@ -81,7 +82,7 @@
             #玩家的数据没有缓存过
             PlayerControl.NotifyCode(curPlayer, 'Friend_OffLine')
             return
-        cacheDict = eval(curCache.GetPropData())
+        cacheDict = json.loads(curCache.GetPropData())
         tagLV = cacheDict["LV"]
     else:
         tagLV = tagPlayer.GetLV()
@@ -323,7 +324,7 @@
         PlayerControl.NotifyCode(srcPlayer, 'Friend_MakeFriend', [curPlayer.GetName()])
         #srcPlayer.MapServer_QueryPlayerResult(0, 0, 'AddFriendSucceed', "", 0)
     else:
-        cacheDict = eval(curCache.GetPropData())
+        cacheDict = json.loads(curCache.GetPropData())
         PlayerControl.NotifyCode(curPlayer, 'Friend_MakeFriend', [cacheDict['Name']])  
         # 记录等对方上线通知地图,任务等会用到触发逻辑,通用记录次数即可, MapServer_SyncFriendInfo为具体的好友数量,根据策划需求制作
         pass
@@ -395,7 +396,7 @@
         curCache = PlayerViewCache.ViewCacheMgr.FindCache(tagID)
         if not curCache:
             return
-        cacheDict = eval(curCache.GetPropData())
+        cacheDict = json.loads(curCache.GetPropData())
         playerName = cacheDict['Name']
     else:
         playerName = tagPlayer.GetName()
diff --git a/ServerPython/CoreServerGroup/GameServer/Script/Player/PlayerGeTui.py b/ServerPython/CoreServerGroup/GameServer/Script/Player/PlayerGeTui.py
index 8f3468d..4daf6d4 100644
--- a/ServerPython/CoreServerGroup/GameServer/Script/Player/PlayerGeTui.py
+++ b/ServerPython/CoreServerGroup/GameServer/Script/Player/PlayerGeTui.py
@@ -282,14 +282,14 @@
         if curPlayer and not PlayerControl.GetIsTJG(curPlayer):
             continue
 
-        recordDict = eval(bossAttentionData.RecordData)
-        if recordDict.get(bossID, 0) in [0, 9]:
+        recordDict = json.loads(bossAttentionData.RecordData)
+        if recordDict.get(str(bossID), 0) in [0, 9]:
             #0-默认未关注, 1-主动关注, 2-自动关注, 9-主动取消关注
             continue
         curCache = PlayerViewCache.ViewCacheMgr.FindCache(playerID)
         if not curCache:
             continue
-        cacheDict = eval(curCache.GetPropData())
+        cacheDict = json.loads(curCache.GetPropData())
         if not CheckCanGeTui(cacheDict, geTuiType):
             # 过滤个推
             continue
@@ -327,7 +327,7 @@
     if not curCache:
         return
 
-    cacheDict = eval(curCache.GetPropData())
+    cacheDict = json.loads(curCache.GetPropData())
     if not CheckCanGeTui(cacheDict, Def_Onoff_Chat):
         # 过滤个推
         return
diff --git a/ServerPython/CoreServerGroup/GameServer/Script/Player/PlayerSocial.py b/ServerPython/CoreServerGroup/GameServer/Script/Player/PlayerSocial.py
index 744608c..e5612fa 100644
--- a/ServerPython/CoreServerGroup/GameServer/Script/Player/PlayerSocial.py
+++ b/ServerPython/CoreServerGroup/GameServer/Script/Player/PlayerSocial.py
@@ -26,7 +26,7 @@
 import IpyGameDataPY
 import PlayerViewCache
 import PyGameData
-
+import json
 #--------------------社交圈基本结构-------------------
 # 社交圈
 class SocialPlayers(object):
@@ -723,7 +723,7 @@
             playerSocial.RealmLV = 1
             playerSocial.OnlineType = ChConfig.Def_Offline
         else:
-            cacheDict = eval(curCache.GetPropData())
+            cacheDict = json.loads(curCache.GetPropData())
     
             playerSocial.clear()
             playerSocial.PlayerID = playerID
diff --git a/ServerPython/CoreServerGroup/GameServer/Script/Player/PlayerTalk.py b/ServerPython/CoreServerGroup/GameServer/Script/Player/PlayerTalk.py
index d7aa654..59a7206 100644
--- a/ServerPython/CoreServerGroup/GameServer/Script/Player/PlayerTalk.py
+++ b/ServerPython/CoreServerGroup/GameServer/Script/Player/PlayerTalk.py
@@ -28,6 +28,7 @@
 import CrossRealmMsg
 import ChNetSendPack
 import NetPackCommon
+import json
 import PlayerGeTui
 import re
 
@@ -100,7 +101,7 @@
         return
     
     if curCache:
-        cacheDict = eval(curCache.GetPropData())
+        cacheDict = json.loads(curCache.GetPropData())
         tagPlayerName = cacheDict["Name"]
         
     talkType = sendPack.GetTalkType()
diff --git a/ServerPython/CoreServerGroup/GameServer/Script/Player/PlayerViewCache.py b/ServerPython/CoreServerGroup/GameServer/Script/Player/PlayerViewCache.py
index bffd6cb..525da05 100644
--- a/ServerPython/CoreServerGroup/GameServer/Script/Player/PlayerViewCache.py
+++ b/ServerPython/CoreServerGroup/GameServer/Script/Player/PlayerViewCache.py
@@ -85,7 +85,7 @@
     
     # 同步更新助战信息
     if PlayerFBHelpBattle.IsInHelpBattleCheckInList(PlayerID):
-        PropDataDict = eval(PropData)
+        PropDataDict = json.loads(PropData)
         fightPower = PropDataDict.get("FightPower", 0)
         familyID = PropDataDict.get("FamilyID", 0)
         playerName = PropDataDict.get("Name", "")
@@ -236,7 +236,7 @@
         return
     
     playerEquipList = []
-    equipItemList = eval(itemData)
+    equipItemList = json.loads(itemData)
     for equipItemDict in equipItemList:
         equipIndex = equipItemDict["ItemIndex"]
         if equipIndex not in ShareDefine.RoleEquipType:
@@ -276,7 +276,7 @@
             answerPack.OnlineType = ChConfig.Def_Offline
             answerPack.ServerGroupID = 0
         else:
-            cacheDict = eval(curCache.GetPropData())
+            cacheDict = json.loads(curCache.GetPropData())
     
             answerPack.PlayerID = clientPack.PlayerID
             answerPack.PlayerName = cacheDict["Name"]
@@ -305,7 +305,7 @@
     curCache = ViewCacheMgr.FindCache(playerID)
     if not curCache:
         return
-    PropData = eval(curCache.GetPropData())
+    PropData = json.loads(curCache.GetPropData())
     PropData["FamilyID"] = familyID
     PropData["FamilyName"] = familyName
     playerLV = PropData["LV"]
diff --git a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerFamily.py b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerFamily.py
index c390c49..3be21b8 100644
--- a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerFamily.py
+++ b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerFamily.py
@@ -36,6 +36,7 @@
 import GameFuncComm
 import PlayerTJG
 import IpyGameDataPY
+import json
 
 import time
 import random
@@ -590,7 +591,7 @@
             return
 
     #请求记录申请进入家族信息
-    sendMsg = str([familyID, curPlayer.GetFightPower()])
+    sendMsg = json.dumps([familyID, curPlayer.GetFightPower()])
     curPlayer.GameServer_QueryPlayerByID(ChConfig.queryType_AddFamilyAction, 
                                         ShareDefine.Def_ActionType_FamilyAdd, '', sendMsg, len(sendMsg))
     
@@ -745,7 +746,7 @@
 ## 添加家族事件记录
 def AddFamilyEventNote(curPlayer, eventType, valueList):
     ##同步记录到GameServer, eventType默认为value1
-    sendMsg = str([eventType] + valueList)
+    sendMsg = json.dumps([eventType] + valueList, ensure_ascii=False)
     curPlayer.GameServer_QueryPlayerByID(ChConfig.queryType_AddFamilyAction, ShareDefine.Def_ActionType_FamilyEvent, '', sendMsg, len(sendMsg))
     GameWorld.DebugLog("AddFamilyEventNote sendMsg=%s" % sendMsg)
     return

--
Gitblit v1.8.0