From ba674caa1427c6dbe0246b27f85262a44fbb7a2b Mon Sep 17 00:00:00 2001
From: hch <305670599@qq.com>
Date: 星期四, 13 六月 2019 19:23:41 +0800
Subject: [PATCH] 860312 副本地图上线切换才加无敌buff

---
 ServerPython/CoreServerGroup/GameServer/Script/GameWorldLogic/CrossRealmMsg.py |   92 +++++++++++++++++++++++++++++++++++++---------
 1 files changed, 74 insertions(+), 18 deletions(-)

diff --git a/ServerPython/CoreServerGroup/GameServer/Script/GameWorldLogic/CrossRealmMsg.py b/ServerPython/CoreServerGroup/GameServer/Script/GameWorldLogic/CrossRealmMsg.py
index b67d031..c6afb53 100644
--- a/ServerPython/CoreServerGroup/GameServer/Script/GameWorldLogic/CrossRealmMsg.py
+++ b/ServerPython/CoreServerGroup/GameServer/Script/GameWorldLogic/CrossRealmMsg.py
@@ -20,16 +20,18 @@
 import PlayerControl
 import IPY_GameServer
 import CrossRealmPlayer
+import PlayerCompensation
 import GameWorldBoss
 import CrossRealmPK
 import PlayerQuery
 import PlayerTalk
 import CrossBoss
 import ChConfig
+import PlayerFB
 import GMShell
 
 import traceback
-import json
+import cPickle
 
 def SendMsgToCrossServer(msgType, dataMsg):
     ## 发送信息到跨服服务器上
@@ -37,22 +39,27 @@
         return
     if not dataMsg:
         return
-    sendMsg = str({"MsgType":msgType, "Data":dataMsg, "ServerGroupID":GameWorld.GetServerGroupID()})
+    
+    # 协议要用最高级2,可减少长度
+    srcMsg = {"MsgType":msgType, "Data":dataMsg, "ServerGroupID":GameWorld.GetServerGroupID()}
+    sendMsg = cPickle.dumps(srcMsg, 2)
     if not GameWorld.GetGameWorld().GetDictByKey(ChConfig.Def_WorldKey_GameWorldInitOK):
-        GameWorld.ErrLog("服务器未启动好,不允许向跨服服务器发送数据! %s" % (sendMsg))
+        GameWorld.ErrLog("服务器未启动好,不允许向跨服服务器发送数据! %s" % (srcMsg))
         return
-    GameWorld.Log("SendMsgToCrossServer => %s" % (sendMsg))   
+    GameWorld.Log("SendMsgToCrossServer => %s" % (srcMsg))   
     GameWorld.GetGameWorld().SendMergerChildToCenterStringData(sendMsg, len(sendMsg))
     return
 
 def OnCrossServerReceiveMsg(recvMsg, tick):
     ## 跨服服务器收到信息处理
     try:
-        GameWorld.Log("OnCrossServerReceiveMsg: %s" % recvMsg)
+        GameWorld.Log("收到OnCrossServerReceiveMsg" )
         if not GameWorld.GetGameWorld().GetDictByKey(ChConfig.Def_WorldKey_GameWorldInitOK):
             GameWorld.Log("服务器未启动好,不处理子服信息!")
             return
-        msgDict = eval(recvMsg)
+        msgDict = cPickle.loads(recvMsg)
+        
+        GameWorld.Log("OnCrossServerReceiveMsg: %s" % msgDict)
         
         msgType = msgDict.get("MsgType", -1)    
         msgData = msgDict.get("Data", "")
@@ -85,8 +92,14 @@
         elif msgType == ShareDefine.ClientServerMsg_QueryNPCInfo:
             PlayerQuery.ClientServerMsg_QueryNPCInfo(serverGroupID, msgData)
             
+        elif msgType == ShareDefine.ClientServerMsg_EnterFB:
+            PlayerFB.ClientServerMsg_EnterFB(serverGroupID, msgData, tick)
+            
         elif msgType == ShareDefine.ClientServerMsg_SetPlayerAttrValue:
             MapServer_CrossSetPlayerAttrValue(msgData)
+            
+        elif msgType == ShareDefine.ClientServerMsg_AddBuff:
+            MapServer_CrossAddBuff(msgData)
             
         # 需要发送到地图服务器处理的
         elif msgType in [ShareDefine.ClientServerMsg_Reborn, ShareDefine.ClientServerMsg_CollectNPC]:
@@ -96,7 +109,7 @@
             GameWorld.ErrLog("没有该信息类型逻辑处理!")
             
     except:
-        GameWorld.ErrLog("OnCrossServerReceiveMsg:%s; except:%s" % (recvMsg, traceback.format_exc()))
+        GameWorld.ErrLog("OnCrossServerReceiveMsg:%s; except:%s" % (cPickle.loads(recvMsg), traceback.format_exc()))
         if GameWorld.GetGameWorld().GetDebugLevel():
             raise BaseException(str(traceback.format_exc()))
     return
@@ -146,6 +159,20 @@
         player.MapServer_QueryPlayerResult(0, 0, "CrossSetPlayerAttrValue", msgInfo, len(msgInfo))
     return
 
+def MapServer_CrossAddBuff(msgData):
+    ## 收到子服信息,添加buff
+    tagPlayerID = msgData.get("PlayerID")
+    if not tagPlayerID:
+        return
+    tagPlayer = GameWorld.GetPlayerManager().FindPlayerByID(tagPlayerID)
+    if not tagPlayer:
+        return
+    buffID = msgData.get("buffID")
+    if not buffID:
+        return
+    sendMsg = str(buffID)
+    tagPlayer.MapServer_QueryPlayerResult(0, 0, 'AddBuff', sendMsg, len(sendMsg))
+    return
 ## ================================================================================================
 
 def SendMsgToClientServer(msgType, dataMsg, serverGroupIDList=[]):
@@ -157,19 +184,21 @@
         return
     if not dataMsg:
         return
-    sendMsg = str({"MsgType":msgType, "Data":dataMsg})
+    
+    srcMsg = {"MsgType":msgType, "Data":dataMsg}
+    sendMsg = cPickle.dumps(srcMsg, 2)
     if not GameWorld.GetGameWorld().GetDictByKey(ChConfig.Def_WorldKey_GameWorldInitOK):
-        GameWorld.ErrLog("跨服服务器未启动好,不允许向子服发送数据! serverGroupIDList=%s, sendMsg=%s" % (serverGroupIDList, sendMsg))
+        GameWorld.ErrLog("跨服服务器未启动好,不允许向子服发送数据! serverGroupIDList=%s, srcMsg=%s" % (serverGroupIDList, srcMsg))
         return
-    GameWorld.Log("SendMsgToClientServer => serverGroupIDList=%s, sendMsg=%s" % (serverGroupIDList, sendMsg))
+    GameWorld.Log("SendMsgToClientServer => serverGroupIDList=%s, srcMsg=%s" % (serverGroupIDList, srcMsg))
     if not serverGroupIDList:
-        GameWorld.GetGameWorld().SendBroadcastMergeClient(sendMsg)
+        GameWorld.GetGameWorld().SendBroadcastMergeClient(sendMsg, len(sendMsg))
     else:
         serverGroupIDList = list(set(serverGroupIDList)) # 去重
         #for serverGroupID in serverGroupIDList:
-        #    GameWorld.GetGameWorld().SendMergeMsgToClientByGroupID(serverGroupID, sendMsg)
-        jsonGroupIDInfo = json.dumps(serverGroupIDList, ensure_ascii=False)
-        GameWorld.GetGameWorld().SendMergeMsgToClientByGroupList(jsonGroupIDInfo, sendMsg)
+        #    GameWorld.GetGameWorld().SendMergeMsgToClientByGroupID(serverGroupID, sendMsg, len(sendMsg))
+        jsonGroupIDInfo = cPickle.dumps(serverGroupIDList, 2)
+        GameWorld.GetGameWorld().SendMergeMsgToClientByGroupList(jsonGroupIDInfo, len(jsonGroupIDInfo), sendMsg, len(sendMsg))
     return
 
 def OnClientServerReceiveMsg(index, tick):
@@ -178,14 +207,15 @@
     dataMsg = dataPack.GetData()
     
     try:
-        GameWorld.Log("OnClientServerReceiveMsg: %s" % dataMsg)
+        GameWorld.Log("收到OnClientServerReceiveMsg" )
         if not GameWorld.GetGameWorld().GetDictByKey(ChConfig.Def_WorldKey_GameWorldInitOK):
             GameWorld.Log("服务器未启动好,不处理跨服信息!")
             return
         
-        msgDict = eval(dataMsg)
+        msgDict = cPickle.loads(dataMsg)
         msgType = msgDict.get("MsgType", -1)    
         msgData = msgDict.get("Data", "")
+        GameWorld.Log("OnClientServerReceiveMsg: %s" % msgDict)
         
         if msgType == ShareDefine.CrossServerMsg_ExitCrossServer:
             CrossRealmPlayer.CrossServerMsg_ExitCrossServer(msgData)
@@ -238,8 +268,18 @@
         elif msgType == ShareDefine.CrossServerMsg_NPCInfoRet:
             PlayerQuery.CrossServerMsg_NPCInfoRet(msgData, tick)
             
+        elif msgType == ShareDefine.CrossServerMsg_EnterFBRet:
+            PlayerFB.CrossServerMsg_EnterFBRet(msgData, tick)
+            
+        elif msgType == ShareDefine.CrossServerMsg_SendMail:
+            PlayerCompensation.CrossServerMsg_SendMail(msgData)
+            
+        elif msgType == ShareDefine.CrossServerMsg_FBPlayerCount:
+            PlayerFB.CrossServerMsg_FBPlayerCount(msgData)
+            
         # 需要发送到地图服务器处理的
-        elif msgType in [ShareDefine.CrossServerMsg_RebornRet, ShareDefine.CrossServerMsg_CollectNPCOK]:
+        elif msgType in [ShareDefine.CrossServerMsg_RebornRet, ShareDefine.CrossServerMsg_CollectNPCOK, ShareDefine.CrossServerMsg_FBEnd,
+                         ShareDefine.CrossServerMsg_NPCAttackCount]:
             MapServer_ClientServerReceiveMsg(msgType, msgData)
             
         elif msgType == ShareDefine.CrossServerMsg_CrossServerState:
@@ -249,7 +289,7 @@
             GameWorld.ErrLog("没有该信息类型逻辑处理!")
             
     except:
-        GameWorld.ErrLog("OnClientServerReceiveMsg:%s; except:%s" % (dataMsg, traceback.format_exc()))
+        GameWorld.ErrLog("OnClientServerReceiveMsg:%s; except:%s" % (cPickle.loads(dataMsg), traceback.format_exc()))
         if GameWorld.GetGameWorld().GetDebugLevel():
             raise BaseException(str(traceback.format_exc()))
         
@@ -258,6 +298,22 @@
 def MapServer_ClientServerReceiveMsg(msgType, msgData):
     ## 收到跨服服务器信息,需要发送到地图服务器处理
     
+    if msgType in [ShareDefine.CrossServerMsg_FBEnd]:
+        curServerGroupID = GameWorld.GetServerGroupID()
+        for tagPlayerID, msgInfo in msgData.items():
+            if not msgInfo:
+                continue
+            serverGroupID = msgInfo[0]
+            if curServerGroupID != serverGroupID:
+                continue
+            tagPlayer = GameWorld.GetPlayerManager().FindPlayerByID(tagPlayerID)
+            if not tagPlayer:
+                continue
+            msgInfo = str([msgType, msgInfo[1:]])
+            tagPlayer.MapServer_QueryPlayerResult(0, 0, "ClientServerReceiveMsg", msgInfo, len(msgInfo))
+            
+        return
+    
     if not isinstance(msgData, dict):
         return
     tagPlayerID = msgData.get("PlayerID")

--
Gitblit v1.8.0