From 9d5ec7599f3abe0cebb76ce1df3c3b8c4e0aa51e Mon Sep 17 00:00:00 2001
From: hxp <ale99527@vip.qq.com>
Date: 星期二, 10 二月 2026 11:40:15 +0800
Subject: [PATCH] 66 【公会】基础主体-服务端(跨服聊天;)
---
ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerTalk.py | 7 +--
ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerFamily.py | 42 ++++++++++++++++++++
ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/DB/StructData/DBFamily.py | 4 +-
ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/PyMongoDB/LogicProcess/UserCtrlDB.py | 6 ++
ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/CrossPlayer.py | 20 ++++++++++
5 files changed, 71 insertions(+), 8 deletions(-)
diff --git a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/DB/StructData/DBFamily.py b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/DB/StructData/DBFamily.py
index de1ac31..312ce65 100644
--- a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/DB/StructData/DBFamily.py
+++ b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/DB/StructData/DBFamily.py
@@ -230,7 +230,7 @@
self.__dbData.FightPower = fightPowerTotal % ChConfig.Def_PerPointValue
self.__dbData.FightPowerEx = fightPowerTotal / ChConfig.Def_PerPointValue
return
- def GetServerID(self): return self.__dbData.ServerID
+ def GetServerID(self): return int(self.__dbData.ServerID)
def SetServerID(self, serverID): self.__dbData.ServerID = serverID
def GetOffTime(self): return self.__dbData.OffTime
def SetOffTime(self, offTime): self.__dbData.OffTime = offTime
@@ -287,7 +287,7 @@
def GetID(self): return self.__dbData.ID
def GetCreateTime(self): return self.__dbData.CreateTime
- def GetServerID(self): return self.__dbData.ServerID
+ def GetServerID(self): return int(self.__dbData.ServerID)
def GetName(self): return self.__dbData.Name
def SetName(self, name): self.__dbData.Name = name
def GetLeaderID(self): return self.__dbData.LeaderID
diff --git a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/CrossPlayer.py b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/CrossPlayer.py
index 9271569..46e21cb 100644
--- a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/CrossPlayer.py
+++ b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/CrossPlayer.py
@@ -101,6 +101,8 @@
self.__crossPlayerDict.pop(playerID, None)
return
+ def GetPlayerIDList(self): return self.__crossPlayerDict.keys()
+
def GetCrossPlayerMgr():
mgr = PyGameData.g_crossPlayerMgr
if mgr == None:
@@ -147,6 +149,24 @@
SendFakePackToPlayerList(crossPlayerList, clientPack)
return
+def SendFackPackToServerList(clientPack, serverIDList):
+ ## 给服务器范围的在线玩家发送封包
+ toCrossPlayerList = []
+ crossPlayerMgr = GetCrossPlayerMgr()
+ playerIDList = crossPlayerMgr.GetPlayerIDList()
+ for playerID in playerIDList:
+ crossPlayer = crossPlayerMgr.FindCrossPlayer(playerID)
+ mainServerID = crossPlayer.GetMainServerID()
+ if not GameWorld.CheckServerIDInList(mainServerID, serverIDList):
+ continue
+ curPlayer = crossPlayer.GetPlayer()
+ if curPlayer: # 有玩家,一般只有游戏服有,可视为游戏服在线,直接发送
+ curPlayer.SendFakePack(clientPack.GetBuffer(), clientPack.GetLength())
+ continue
+ toCrossPlayerList.append(crossPlayer)
+ SendFakePackToPlayerList(toCrossPlayerList, clientPack)
+ return
+
def SendFakePackToPlayerList(crossPlayerList, clientPack):
'''给crossPlayer玩家发送封包,适用于接受的玩家封包数据一致的,跨服、游戏服通用
'''
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 de7090b..9e5032a 100644
--- a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerFamily.py
+++ b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerFamily.py
@@ -165,6 +165,8 @@
PlayerLoginRefreshFamily(crossPlayer) # 必须先刷新
Sync_RequestAddFamilyInfo(crossPlayer, False)
PlayerTalk.NotifyTalkCache(crossPlayer, [IPY_GameWorld.tcFamily]) # 公会聊天缓存
+ if GameWorld.IsCrossServer():
+ PlayerTalk.NotifyTalkCache(crossPlayer, [IPY_GameWorld.tcCountry]) # 跨服公会聊天缓存
PlayerFamilyTaofa.OnCrossPlayerLogin(crossPlayer)
return
@@ -2023,7 +2025,7 @@
def OnFamilyTalk(curPlayer, familyID, talkPack, tick):
clientData, tick = None, 0
reqDataEx = {"talkBuffer":talkPack.GetBuffer()}
- FamilyPyPackForwarding(curPlayer, clientData, tick, "__OnFamilyTalk", reqCD=0, reqDataEx=reqDataEx)
+ FamilyPyPackForwarding(curPlayer, clientData, tick, "__OnFamilyTalk", reqDataEx=reqDataEx)
return
def __OnFamilyTalk(crossPlayer, clientData, tick, fromServerID=0, reqDataEx=None):
talkBuffer = reqDataEx["talkBuffer"]
@@ -2043,6 +2045,44 @@
PlayerTalk.DoTalkCache(channelType, playerID, content, bubbleBox, familyID)
return
+def OnCrossFamilyTalk(curPlayer, talkPack, tick):
+ ## 跨服公会聊天,与跨服公会互通范围一致
+ crossServerID = DBDataMgr.GetFamilyMgr().GetCurCrossServerID()
+ if crossServerID <= 0:
+ GameWorld.DebugLog("本服公会未互通,不允许跨服聊天")
+ return
+ clientData, tick = None, 0
+ reqDataEx = {"talkBuffer":talkPack.GetBuffer()}
+ FamilyPyPackForwarding(curPlayer, clientData, tick, "__OnCrossTalk", reqDataEx=reqDataEx)
+ return
+def __OnCrossTalk(crossPlayer, clientData, tick, fromServerID=0, reqDataEx=None):
+ talkBuffer = reqDataEx["talkBuffer"]
+ playerID = crossPlayer.GetPlayerID()
+
+ if not talkBuffer:
+ return
+
+ familyMgr = DBDataMgr.GetFamilyMgr()
+ zoneID = familyMgr.GetZoneIDInThisServer(fromServerID)
+ if zoneID < 0:
+ GameWorld.ErrLog("找不到服务器ID在跨服中的公会分区! fromServerID=%s" % fromServerID)
+ return
+ zoneMgr = familyMgr.GetZoneFamilyMgr(zoneID)
+ serverIDList = zoneMgr.GetZoneServerIDList()
+ if not serverIDList:
+ return
+
+ clientPack = ChPyNetSendPack.tagMCTalk()
+ clientPack.ReadData(talkBuffer)
+ CrossPlayer.SendFackPackToServerList(clientPack, serverIDList)
+
+ # 聊天缓存
+ channelType = clientPack.ChannelType
+ content = clientPack.Content
+ bubbleBox = clientPack.BubbleBox
+ PlayerTalk.DoTalkCache(channelType, playerID, content, bubbleBox)
+ return
+
## -------------------------------------- 游戏服本服处理 --------------------------------------------
'''
为方便本服、跨服互通公会逻辑统一,公会相关数据处理统一使用 CrossPlayer,视为以前的GameServer处理,这样本服跨服的公会管理通用
diff --git a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerTalk.py b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerTalk.py
index 8d4e576..e48de7e 100644
--- a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerTalk.py
+++ b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerTalk.py
@@ -33,6 +33,7 @@
#需要记录聊天缓存的频道对应限制最大条数
ChannelCacheMax = {IPY_GameWorld.tcFamily:30,
IPY_GameWorld.tcWorld:100,
+ IPY_GameWorld.tcCountry:200,
}
def OnPlayerLogin(curPlayer):
@@ -72,10 +73,6 @@
curPlayer.SetLastChatTick(tick)
curPlayer.SetDict(ChConfig.Def_ChannelTalkTick % channelType, tick)
- if channelType == IPY_GameWorld.tcCountry:
- #发送到跨服,待扩展
- return
-
bubbleBox = PlayerControl.GetChatBox(curPlayer) # 气泡框
clientPack = ChPyNetSendPack.tagMCTalk()
@@ -99,6 +96,8 @@
DoTalkCache(channelType, playerID, content, bubbleBox, familyID)
elif channelType == IPY_GameWorld.tcFamily:
PlayerFamily.OnFamilyTalk(curPlayer, familyID, clientPack, tick)
+ elif channelType == IPY_GameWorld.tcCountry:
+ PlayerFamily.OnCrossFamilyTalk(curPlayer, clientPack, tick)
return
diff --git a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/PyMongoDB/LogicProcess/UserCtrlDB.py b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/PyMongoDB/LogicProcess/UserCtrlDB.py
index cfd3f55..ac345e7 100644
--- a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/PyMongoDB/LogicProcess/UserCtrlDB.py
+++ b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/PyMongoDB/LogicProcess/UserCtrlDB.py
@@ -943,7 +943,11 @@
NetPackCommon.RecCrossServerNetPack(recvPack.Data)
except:
msg = error.formatMsg('error', error.ERROR_NO_172, "LogicProcessThread::OnCrossServerToServerPack Catch a unexpetcted exception, error = %s"%traceback.format_exc())
- mylog.error(msg)
+ if GameWorld.GetGameWorld().GetDebugLevel():
+ # debug下让其抛出异常报错,方便测试时发现排查问题
+ raise Exception(msg)
+ else:
+ mylog.error(msg)
--
Gitblit v1.8.0