From 08e3e6cea67b249564abac36ea1e8aefa17982e4 Mon Sep 17 00:00:00 2001
From: hch <305670599@qq.com>
Date: 星期二, 12 三月 2019 16:36:47 +0800
Subject: [PATCH] Merge branch 'master' of http://192.168.0.87:10010/r/SnxxServerCode
---
ServerPython/CoreServerGroup/GameServer/Script/GameWorldLogic/CrossRealmMsg.py | 66 ++++++++++++++++++++++++---------
1 files changed, 48 insertions(+), 18 deletions(-)
diff --git a/ServerPython/CoreServerGroup/GameServer/Script/GameWorldLogic/CrossRealmMsg.py b/ServerPython/CoreServerGroup/GameServer/Script/GameWorldLogic/CrossRealmMsg.py
index 8291317..456a8e5 100644
--- a/ServerPython/CoreServerGroup/GameServer/Script/GameWorldLogic/CrossRealmMsg.py
+++ b/ServerPython/CoreServerGroup/GameServer/Script/GameWorldLogic/CrossRealmMsg.py
@@ -29,7 +29,7 @@
import GMShell
import traceback
-import json
+import cPickle
def SendMsgToCrossServer(msgType, dataMsg):
## 发送信息到跨服服务器上
@@ -37,7 +37,12 @@
return
if not dataMsg:
return
- sendMsg = str({"MsgType":msgType, "Data":dataMsg, "ServerGroupID":GameWorld.GetServerGroupID()})
+
+ # 协议要用最高级2,可减少长度
+ sendMsg = cPickle.dumps({"MsgType":msgType, "Data":dataMsg, "ServerGroupID":GameWorld.GetServerGroupID()}, 2)
+ if not GameWorld.GetGameWorld().GetDictByKey(ChConfig.Def_WorldKey_GameWorldInitOK):
+ GameWorld.ErrLog("服务器未启动好,不允许向跨服服务器发送数据! %s" % (sendMsg))
+ return
GameWorld.Log("SendMsgToCrossServer => %s" % (sendMsg))
GameWorld.GetGameWorld().SendMergerChildToCenterStringData(sendMsg, len(sendMsg))
return
@@ -45,8 +50,11 @@
def OnCrossServerReceiveMsg(recvMsg, tick):
## 跨服服务器收到信息处理
try:
- #GameWorld.Log("OnCrossServerReceiveMsg: %s" % recvMsg)
- msgDict = eval(recvMsg)
+ GameWorld.Log("OnCrossServerReceiveMsg: %s" % recvMsg)
+ if not GameWorld.GetGameWorld().GetDictByKey(ChConfig.Def_WorldKey_GameWorldInitOK):
+ GameWorld.Log("服务器未启动好,不处理子服信息!")
+ return
+ msgDict = cPickle.loads(recvMsg)
msgType = msgDict.get("MsgType", -1)
msgData = msgDict.get("Data", "")
@@ -71,7 +79,7 @@
GMShell.ClientServerMsg_GMCMD(msgData, tick)
elif msgType == ShareDefine.ClientServerMsg_ServerInitOK:
- ClientServerMsg_ServerInitOK(serverGroupID, msgData, tick)
+ ClientServerMsg_ServerInitOK(serverGroupID, tick)
elif msgType == ShareDefine.ClientServerMsg_ViewPlayerCache:
CrossRealmPlayer.ClientServerMsg_ViewPlayerCache(serverGroupID, msgData)
@@ -95,14 +103,25 @@
raise BaseException(str(traceback.format_exc()))
return
-def ClientServerMsg_ServerInitOK(serverGroupID, msgData, tick):
+def ClientServerMsg_ServerInitOK(serverGroupID, tick):
''' 收到子服连接成功通知
当子服启动成功后,可同步一次跨服服务器活动状态及活动数据给子服
'''
- GameWorld.Log("收到跨服子服连接成功通知!")
- CrossRealmPlayer.ClientServerMsg_ServerInitOK(serverGroupID)
- CrossRealmPK.ClientServerMsg_ServerInitOK(serverGroupID, tick)
- CrossBoss.ClientServerMsg_ServerInitOK(serverGroupID)
+ GameWorld.Log("收到跨服子服连接成功通知! serverGroupID=%s" % serverGroupID)
+ Sync_CrossServerInitDataToClientServer(tick, serverGroupID)
+ return
+
+def Sync_CrossServerInitDataToClientServer(tick, serverGroupID=0):
+ ''' 同步跨服功能数据到子服服务器
+ 本函数调用时机:
+ 1.跨服服务器启动成功,主动广播同步所有子服,此时设置 serverGroupID 为 0
+ 2.子服启动成功,由子服主动发起请求同步最新数据,此时有指定子服 serverGroupID
+ 3.子服重新连接跨服服务器成功,逻辑同2
+ @param serverGroupID: 子服服务器组ID,为0时为全部子服务器组
+ '''
+ CrossRealmPlayer.Sync_CrossCommInitDataToClientServer(serverGroupID)
+ CrossRealmPK.Sync_CrossPKInitDataToClientServer(tick, serverGroupID)
+ CrossBoss.Sync_CrossBossInitDataToClientServer(serverGroupID)
return
def MapServer_CrossServerReceiveMsg(msgType, msgData, serverGroupID):
@@ -140,7 +159,10 @@
return
if not dataMsg:
return
- sendMsg = str({"MsgType":msgType, "Data":dataMsg})
+ sendMsg = cPickle.dumps({"MsgType":msgType, "Data":dataMsg}, 2)
+ if not GameWorld.GetGameWorld().GetDictByKey(ChConfig.Def_WorldKey_GameWorldInitOK):
+ GameWorld.ErrLog("跨服服务器未启动好,不允许向子服发送数据! serverGroupIDList=%s, sendMsg=%s" % (serverGroupIDList, sendMsg))
+ return
GameWorld.Log("SendMsgToClientServer => serverGroupIDList=%s, sendMsg=%s" % (serverGroupIDList, sendMsg))
if not serverGroupIDList:
GameWorld.GetGameWorld().SendBroadcastMergeClient(sendMsg)
@@ -148,7 +170,7 @@
serverGroupIDList = list(set(serverGroupIDList)) # 去重
#for serverGroupID in serverGroupIDList:
# GameWorld.GetGameWorld().SendMergeMsgToClientByGroupID(serverGroupID, sendMsg)
- jsonGroupIDInfo = json.dumps(serverGroupIDList, ensure_ascii=False)
+ jsonGroupIDInfo = cPickle.dumps(serverGroupIDList, 2)
GameWorld.GetGameWorld().SendMergeMsgToClientByGroupList(jsonGroupIDInfo, sendMsg)
return
@@ -156,10 +178,14 @@
## 子服收到跨服服务器信息
dataPack = IPY_GameServer.IPY_MGBroadcastMergeClient()
dataMsg = dataPack.GetData()
- #GameWorld.Log("OnClientServerReceiveMsg: %s" % dataMsg)
try:
- msgDict = eval(dataMsg)
+ GameWorld.Log("OnClientServerReceiveMsg: %s" % dataMsg)
+ if not GameWorld.GetGameWorld().GetDictByKey(ChConfig.Def_WorldKey_GameWorldInitOK):
+ GameWorld.Log("服务器未启动好,不处理跨服信息!")
+ return
+
+ msgDict = cPickle.loads(dataMsg)
msgType = msgDict.get("MsgType", -1)
msgData = msgDict.get("Data", "")
@@ -256,12 +282,12 @@
GameWorld.GetGameWorld().SetDict(ShareDefine.Def_Notify_WorldKey_CrossServerConnState, connState)
if result != 1:
- GameWorld.Log("--OnClientServerReceiveMsg disconn")
+ GameWorld.Log("===与跨服服务器断开连接!")
CrossRealmPlayer.CrossServerMsg_CrossServerState({"isOpen":0})
return
- GameWorld.Log("OnConnCorossServer conn success!!!")
- if not GameWorld.GetGameWorld().GetDictByKey(ChConfig.Def_WorldKey_IsGameWorldInit):
+ GameWorld.Log("===与跨服服务器连接成功!")
+ if not GameWorld.GetGameWorld().GetDictByKey(ChConfig.Def_WorldKey_GameWorldInitOK):
GameWorld.Log(" 服务器还未启动好,暂不处理! 等服务器启动好后再处理!")
return
@@ -274,8 +300,12 @@
return
def OnGameServerInitOK():
- ## 子服启动成功
+ ## 服务器启动成功
+
+ tick = GameWorld.GetGameWorld().GetTick()
+
if GameWorld.IsCrossServer():
+ Sync_CrossServerInitDataToClientServer(tick, serverGroupID=0) # 这里设置为0,广播所有子服务器组
return
serverGroupID = GameWorld.GetServerGroupID()
--
Gitblit v1.8.0