From bb284affe6541fa85c492ce9af26b4ee35805aab Mon Sep 17 00:00:00 2001
From: hch <305670599@qq.com>
Date: 星期二, 12 三月 2019 14:25:07 +0800
Subject: [PATCH] 6328 【后端】优化代码eval -- 玩家缓存数据提取常用字段 等级和最后一次发送时间

---
 ServerPython/CoreServerGroup/GameServer/Script/Player/CrossRealmPlayer.py |  115 +++++++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 90 insertions(+), 25 deletions(-)

diff --git a/ServerPython/CoreServerGroup/GameServer/Script/Player/CrossRealmPlayer.py b/ServerPython/CoreServerGroup/GameServer/Script/Player/CrossRealmPlayer.py
index bbcc5fd..5438e00 100644
--- a/ServerPython/CoreServerGroup/GameServer/Script/Player/CrossRealmPlayer.py
+++ b/ServerPython/CoreServerGroup/GameServer/Script/Player/CrossRealmPlayer.py
@@ -28,7 +28,6 @@
 import NetPackCommon
 import IpyGameDataPY
 import PyGameData
-
 # 获取玩家跨服服务器上的名字
 #===============================================================================
 # def GetCrossPlayerName(curPlayer):
@@ -46,7 +45,7 @@
 # 获取玩家跨服服务器上的名字
 def GetCrossPlayerName(curPlayer):
     # 通过游戏账号中的平台标志获取名称,目前为spid
-    playerName = curPlayer.GetPlayerName()
+    playerName = curPlayer.GetName()
     
     opName = ReadChConfig.GetPyMongoConfig("Merge", "OpName_%s_%s" % (GameWorld.GetPlayerPlatform(curPlayer), 
                                            GameWorld.GetPlayerServerSID(curPlayer)))
@@ -56,20 +55,19 @@
     
     return opName.decode('gbk').encode(GameWorld.GetCharacterEncoding()) + playerName
 
-def GetServerCrossZoneIpyData(mapID, serverGroupID=0):
-    ## 获取本服对应跨服玩法分区地图信息
-    if mapID not in ChConfig.Def_CrossZoneTableName:
+def GetCrossCommZoneIpyDataByZoneID(zoneID):
+    ## 获取跨服常规分区 
+    crossZoneName = GameWorld.GetCrossZoneName()
+    ipyData = IpyGameDataPY.GetIpyGameDataNotLog("CrossZoneComm", crossZoneName, zoneID)
+    return ipyData
+
+def GetCrossCommZoneIpyDataByServerGroupID(serverGroupID):
+    ## 获取跨服常规分区
+    crossZoneName = GameWorld.GetCrossZoneName()
+    ipyDataList = IpyGameDataPY.GetIpyGameDataByCondition("CrossZoneComm", {"CrossZoneName":crossZoneName}, True)
+    if not ipyDataList:
         return
-    if not serverGroupID:
-        serverGroupID = GameWorld.GetServerGroupID()
-        
-    tableName = ChConfig.Def_CrossZoneTableName[mapID]
-    ipyDataMgr = IpyGameDataPY.IPY_Data()
-    if not hasattr(ipyDataMgr, "Get%sCount" % tableName):
-        return
-    
-    for i in xrange(getattr(ipyDataMgr, "Get%sCount" % tableName)()):
-        ipyData = getattr(ipyDataMgr, "Get%sByIndex" % tableName)(i)
+    for ipyData in ipyDataList:
         serverGroupIDList = ipyData.GetServerGroupIDList()
         for serverGroupIDInfo in serverGroupIDList:
             if (isinstance(serverGroupIDInfo, tuple) and serverGroupIDInfo[0] <= serverGroupID <= serverGroupIDInfo[1]) \
@@ -77,15 +75,47 @@
                 return ipyData
     return
 
+def GetCrossCommZoneIpyDataListByServerGroupID(serverGroupID):
+    ## 获取跨服常规分区列表
+    if serverGroupID:
+        ipyData = GetCrossCommZoneIpyDataByServerGroupID(serverGroupID)
+        if not ipyData:
+            return
+        ipyDataList = [ipyData]
+    else:
+        crossZoneName = GameWorld.GetCrossZoneName()
+        ipyDataList = IpyGameDataPY.GetIpyGameDataByCondition("CrossZoneComm", {"CrossZoneName":crossZoneName}, True)
+    return ipyDataList
+
+def GetServerCrossZoneMapIpyData(mapID, serverGroupID=0):
+    ## 获取本服对应跨服玩法分区地图信息
+    if mapID not in ChConfig.Def_CrossZoneMapTableName:
+        return
+    tableName = ChConfig.Def_CrossZoneMapTableName[mapID]
+    if not serverGroupID:
+        if GameWorld.IsCrossServer():
+            return
+        serverGroupID = GameWorld.GetServerGroupID()
+    zoneIpyData = GetCrossCommZoneIpyDataByServerGroupID(serverGroupID)
+    if not zoneIpyData:
+        return
+    commZoneID = zoneIpyData.GetZoneID()
+    return IpyGameDataPY.GetIpyGameDataByCondition(tableName, {"ZoneID":commZoneID})
+
 def IsCrossServerOpen():
     ## 跨服服务器是否开放中
     return GameWorld.GetGameWorld().GetDictByKey(ShareDefine.Def_Notify_WorldKey_CrossServerOpen)
 
-def ClientServerMsg_ServerInitOK(serverGroupID):
-    ## 子服连接成功
+def Sync_CrossCommInitDataToClientServer(serverGroupID=0):
+    ''' 同步跨服常规通用数据到子服务器
+    @param serverGroupID: 为0时同步所有子服
+    '''
+    
     isOpen = GameWorld.GetGameWorld().GetDictByKey(ShareDefine.Def_Notify_WorldKey_CrossServerOpen)
-    GameWorld.Log("子服连接成功,通知当前跨服服务器状态: isOpen=%s" % isOpen)
-    CrossRealmMsg.SendMsgToClientServer(ShareDefine.CrossServerMsg_CrossServerState, {"isOpen":isOpen}, [serverGroupID])
+    crossZoneName = GameWorld.GetCrossZoneName()
+    GameWorld.Log("通知当前跨服服务器状态: isOpen=%s,crossZoneName=%s,syncServerGroupID=%s" % (isOpen, crossZoneName, serverGroupID))
+    serverGroupIDList = [serverGroupID] if serverGroupID else []
+    CrossRealmMsg.SendMsgToClientServer(ShareDefine.CrossServerMsg_CrossServerState, {"isOpen":isOpen, "crossZoneName":crossZoneName}, serverGroupIDList)
     return
 
 def DoChangeCrossServerState(isOpen):
@@ -101,7 +131,7 @@
             curPlayer = playerManager.GetActivePlayerAt(i)
             if curPlayer == None:
                 continue
-            PlayerControl.SetCrossRealmState(curPlayer, 0)
+            PlayerControl.SetCrossMapID(curPlayer, 0)
             curPlayer.Kick(0)
             
     # 广播所有子服,本服务器进入维护
@@ -110,6 +140,10 @@
 
 def CrossServerMsg_CrossServerState(msgData):
     ## 子服收到跨服服务器状态变更,子服不存DB,默认跨服维护中,连接跨服成功后由跨服同步状态直接更新到字典即可,没连上就默认维护中
+    if "crossZoneName" in msgData:
+        PyGameData.g_crossZoneName = msgData["crossZoneName"]
+        GameWorld.SendMapServerMsgEx(ShareDefine.Def_Notify_WorldKey_CrossZoneName, PyGameData.g_crossZoneName)
+        
     isOpen = msgData["isOpen"]
     isOpen = 1 if isOpen else 0
     GameWorld.Log("收到跨服服务器状态变更: 是否正常开放中=%s" % isOpen)
@@ -121,8 +155,9 @@
             curPlayer = playerManager.GetActivePlayerAt(i)
             if curPlayer == None:
                 continue
-            PlayerControl.SetCrossRealmState(curPlayer, 0)
+            PlayerControl.SetCrossMapID(curPlayer, 0)
             
+    GameWorld.GetGameWorld().SendCrossServerStateToLoginServer(isOpen)
     # 通知地图
     GameWorld.SendMapServerMsgEx(ShareDefine.Def_Notify_WorldKey_CrossServerOpen, isOpen)
     return
@@ -139,7 +174,7 @@
     CrossRealmMsg.SendMsgToClientServer(ShareDefine.CrossServerMsg_ExitCrossServer, playerID, [serverGroupID])
     
     # 设置非跨服状态,踢下线
-    PlayerControl.SetCrossRealmState(curPlayer, 0)
+    PlayerControl.SetCrossMapID(curPlayer, 0)
     curPlayer.Kick(0)
     GameWorld.Log("PlayerExitCrossServer...serverGroupID=%s" % serverGroupID, playerID)
     return
@@ -152,7 +187,7 @@
     if not curPlayer:
         GameWorld.Log("    退出跨服时本服玩家不在线!", playerID)
         return
-    PlayerControl.SetCrossRealmState(curPlayer, 0)
+    PlayerControl.SetCrossMapID(curPlayer, 0)
     return
 
 def SendCrossRealmReg(curPlayer, registerMap, mapID=0, dataMapID=0, copyMapID=0, posX=0, posY=0):
@@ -226,7 +261,7 @@
     '''
     curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
     GameWorld.ErrLog("某些异常情况下,前端强制发包退出跨服状态! ", curPlayer.GetPlayerID())
-    PlayerControl.SetCrossRealmState(curPlayer, 0)
+    PlayerControl.SetCrossMapID(curPlayer, 0)
     return
 
 #// C0 02 查看跨服玩家信息 #tagCGViewCrossPlayerInfo
@@ -316,7 +351,6 @@
     sendPack.ItemDataSize = len(sendPack.ItemData)
     sendPack.PlusData = PlusData
     sendPack.PlusDataSize = len(sendPack.PlusData)
-    sendPack.CrossPlayer = 1
     NetPackCommon.SendFakePack(curPlayer, sendPack)
     return
 
@@ -352,5 +386,36 @@
     curPlayer.MapServer_QueryPlayerResult(0, 0, "CrossGiveMoney", msgInfo, len(msgInfo))
     return
 
+def SetCrossPlayerAttrValue(msgInfo, tick):
+    ## 设置跨服玩家属性值
+    playerID, setType, setDict, isDelay = msgInfo
+    if not PyGameData.g_crossSetPlayerAttr:
+        GameWorld.GetGameWorld().SetDict(ChConfig.Def_WorldKey_CrossSetPlayerAttrTick, tick)
+    playerSetInfoList = PyGameData.g_crossSetPlayerAttr.get(playerID, [])
+    playerSetInfoList.append([setType, setDict])
+    PyGameData.g_crossSetPlayerAttr[playerID] = playerSetInfoList
+    if not isDelay:
+        __SendCrossServerSetPlayerAttr(0)
+    return
+
+def OnCrossProcess(tick):
+    __SendCrossServerSetPlayerAttr(tick)
+    return
+
+def __SendCrossServerSetPlayerAttr(tick):
+    if not PyGameData.g_crossSetPlayerAttr:
+        return
+    
+    if tick:
+        # 延迟10秒一次性同步,主要是比如OnDay的时候当多个玩家同时跨服时,减少同步次数,延迟统一发送
+        if tick - GameWorld.GetGameWorld().GetDictByKey(ChConfig.Def_WorldKey_CrossSetPlayerAttrTick) < 10 * 1000:
+            return
+        GameWorld.GetGameWorld().SetDict(ChConfig.Def_WorldKey_CrossSetPlayerAttrTick, tick)
+        
+    CrossRealmMsg.SendMsgToCrossServer(ShareDefine.ClientServerMsg_SetPlayerAttrValue, PyGameData.g_crossSetPlayerAttr)
+    PyGameData.g_crossSetPlayerAttr = {}
+    return
+
+
 
     
\ No newline at end of file

--
Gitblit v1.8.0