From 2a1039feedbd432ddadb8bc7d01bf1a173b77142 Mon Sep 17 00:00:00 2001 From: hxp <ale99527@vip.qq.com> Date: 星期四, 31 一月 2019 14:09:50 +0800 Subject: [PATCH] 6087 【后端】【1.5.200】春节红包雨活动(增加配置未用完的次数过天可否累加) --- ServerPython/CoreServerGroup/GameServer/Script/Player/CrossRealmPlayer.py | 214 ++++++++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 195 insertions(+), 19 deletions(-) diff --git a/ServerPython/CoreServerGroup/GameServer/Script/Player/CrossRealmPlayer.py b/ServerPython/CoreServerGroup/GameServer/Script/Player/CrossRealmPlayer.py index 35f6bf2..ec033a1 100644 --- a/ServerPython/CoreServerGroup/GameServer/Script/Player/CrossRealmPlayer.py +++ b/ServerPython/CoreServerGroup/GameServer/Script/Player/CrossRealmPlayer.py @@ -22,40 +22,148 @@ import ChConfig import PlayerControl import PlayerViewCache +import PlayerCompensation import ChPyNetSendPack +import PlayerDBGSEvent import NetPackCommon +import IpyGameDataPY import PyGameData + +# 获取玩家跨服服务器上的名字 +#=============================================================================== +# def GetCrossPlayerName(curPlayer): +# # 通过游戏账号中的平台标志获取名称,目前为spid +# playerName = curPlayer.GetPlayerName() +# nameFormat = ReadChConfig.GetPyMongoConfig("Merge", "NameFormat", True) +# if not nameFormat: +# return playerName +# +# opName = ReadChConfig.GetPyMongoConfig("Merge", "OpName_%s" % GameWorld.GetPlayerPlatform(curPlayer)) +# +# return (nameFormat%{"opname":opName, "sid":GameWorld.GetPlayerServerID(curPlayer)}).decode('gbk').encode(GameWorld.GetCharacterEncoding()) + playerName +#=============================================================================== # 获取玩家跨服服务器上的名字 def GetCrossPlayerName(curPlayer): # 通过游戏账号中的平台标志获取名称,目前为spid - playerName = curPlayer.GetPlayerName() - nameFormat = ReadChConfig.GetPyMongoConfig("Merge", "NameFormat", True) - if not nameFormat: + playerName = curPlayer.GetName() + + opName = ReadChConfig.GetPyMongoConfig("Merge", "OpName_%s_%s" % (GameWorld.GetPlayerPlatform(curPlayer), + GameWorld.GetPlayerServerSID(curPlayer))) + + if not opName: return playerName - opName = ReadChConfig.GetPyMongoConfig("Merge", "OpName_%s" % GameWorld.GetPlayerPlatform(curPlayer)) + return opName.decode('gbk').encode(GameWorld.GetCharacterEncoding()) + playerName - return (nameFormat%{"opname":opName, "sid":GameWorld.GetPlayerServerID(curPlayer)}).decode('gbk').encode(GameWorld.GetCharacterEncoding()) + playerName +def GetServerCrossZoneIpyData(mapID, serverGroupID=0): + ## 获取本服对应跨服玩法分区地图信息 + if mapID not in ChConfig.Def_CrossZoneTableName: + 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) + serverGroupIDList = ipyData.GetServerGroupIDList() + for serverGroupIDInfo in serverGroupIDList: + if (isinstance(serverGroupIDInfo, tuple) and serverGroupIDInfo[0] <= serverGroupID <= serverGroupIDInfo[1]) \ + or (isinstance(serverGroupIDInfo, int) and serverGroupIDInfo == serverGroupID): + return ipyData + return + +def IsCrossServerOpen(): + ## 跨服服务器是否开放中 + return GameWorld.GetGameWorld().GetDictByKey(ShareDefine.Def_Notify_WorldKey_CrossServerOpen) + +def ClientServerMsg_ServerInitOK(serverGroupID): + ## 子服连接成功 + isOpen = GameWorld.GetGameWorld().GetDictByKey(ShareDefine.Def_Notify_WorldKey_CrossServerOpen) + GameWorld.Log("子服连接成功,通知当前跨服服务器状态: isOpen=%s" % isOpen) + CrossRealmMsg.SendMsgToClientServer(ShareDefine.CrossServerMsg_CrossServerState, {"isOpen":isOpen}, [serverGroupID]) + return + +def DoChangeCrossServerState(isOpen): + ## 跨服服务器状态变更 + + PlayerDBGSEvent.SetDBGSTrig_ByKey(PlayerDBGSEvent.Def_CrossServerClose, 0 if isOpen else 1) # 存DB的反着存 + GameWorld.GetGameWorld().SetDict(ShareDefine.Def_Notify_WorldKey_CrossServerOpen, isOpen) + + if not isOpen: + # 踢掉所有玩家 + playerManager = GameWorld.GetPlayerManager() + for i in xrange(playerManager.GetActivePlayerCount()): + curPlayer = playerManager.GetActivePlayerAt(i) + if curPlayer == None: + continue + PlayerControl.SetCrossMapID(curPlayer, 0) + curPlayer.Kick(0) + + # 广播所有子服,本服务器进入维护 + CrossRealmMsg.SendMsgToClientServer(ShareDefine.CrossServerMsg_CrossServerState, {"isOpen":isOpen}) + return + +def CrossServerMsg_CrossServerState(msgData): + ## 子服收到跨服服务器状态变更,子服不存DB,默认跨服维护中,连接跨服成功后由跨服同步状态直接更新到字典即可,没连上就默认维护中 + isOpen = msgData["isOpen"] + isOpen = 1 if isOpen else 0 + GameWorld.Log("收到跨服服务器状态变更: 是否正常开放中=%s" % isOpen) + GameWorld.GetGameWorld().SetDict(ShareDefine.Def_Notify_WorldKey_CrossServerOpen, isOpen) + + if not isOpen: + playerManager = GameWorld.GetPlayerManager() + for i in xrange(playerManager.GetActivePlayerCount()): + curPlayer = playerManager.GetActivePlayerAt(i) + if curPlayer == None: + continue + PlayerControl.SetCrossMapID(curPlayer, 0) + + # 通知地图 + GameWorld.SendMapServerMsgEx(ShareDefine.Def_Notify_WorldKey_CrossServerOpen, isOpen) + return + +def PlayerExitCrossServer(curPlayer): + ## 玩家退出跨服服务器 + + if not GameWorld.IsCrossServer(): + return + + # 通知子服玩家退出跨服服务器 + playerID = curPlayer.GetPlayerID() + serverGroupID = PlayerControl.GetPlayerServerGroupID(curPlayer) + CrossRealmMsg.SendMsgToClientServer(ShareDefine.CrossServerMsg_ExitCrossServer, playerID, [serverGroupID]) + + # 设置非跨服状态,踢下线 + PlayerControl.SetCrossMapID(curPlayer, 0) + curPlayer.Kick(0) + GameWorld.Log("PlayerExitCrossServer...serverGroupID=%s" % serverGroupID, playerID) + return def CrossServerMsg_ExitCrossServer(msgData): ## 收到跨服服务器同步的玩家退出跨服服务器 playerID = msgData + GameWorld.Log("收到跨服服务器同步的玩家退出跨服服务器: playerID=%s" % playerID) curPlayer = GameWorld.GetPlayerManager().FindPlayerByID(playerID) if not curPlayer: + GameWorld.Log(" 退出跨服时本服玩家不在线!", playerID) return - PlayerControl.SetCrossRealmState(curPlayer, 0) + PlayerControl.SetCrossMapID(curPlayer, 0) return -def SendCrossRealmReg(curPlayer, actionType, mapID=0, dataMapID=0, copyMapID=0, posX=0, posY=0): +def SendCrossRealmReg(curPlayer, registerMap, mapID=0, dataMapID=0, copyMapID=0, posX=0, posY=0): # 发送跨服账号注册上传数据 # 设置上传数据的活动类型 - curPlayer.SetDict(ChConfig.Def_PlayerKey_MergeRegisterType, actionType) - sysMsg = str([actionType, mapID, dataMapID, copyMapID, posX, posY]) + curPlayer.SetDict(ChConfig.Def_PlayerKey_CrossRegisterMap, registerMap) + sysMsg = str([registerMap, mapID, dataMapID, copyMapID, posX, posY]) curPlayer.MapServer_QueryPlayerResult(0, 0, "CrossRealmReg", sysMsg, len(sysMsg)) - GameWorld.Log("SendCrossRealmReg actionType=%s,mapID=%s,dataMapID=%s,copyMapID=%s,posX=%s,posY=%s" - % (actionType, mapID, dataMapID, copyMapID, posX, posY), curPlayer.GetPlayerID()) + GameWorld.Log("SendCrossRealmReg registerMap=%s,mapID=%s,dataMapID=%s,copyMapID=%s,posX=%s,posY=%s" + % (registerMap, mapID, dataMapID, copyMapID, posX, posY), curPlayer.GetPlayerID()) return def OnCrossRealmRegOK(playerID, msgList, tick): @@ -65,13 +173,19 @@ if not curPlayer: return - #newAccount, newName = msgList + if not IsCrossServerOpen(): + return - actionType = curPlayer.GetDictByKey(ChConfig.Def_PlayerKey_MergeRegisterType) - GameWorld.Log("跨服报名成功 , actionType=%s" % (actionType), playerID) + registerMap = msgList[0] + playerRegisterMap = curPlayer.GetDictByKey(ChConfig.Def_PlayerKey_CrossRegisterMap) + if playerRegisterMap and registerMap != playerRegisterMap: + return + curPlayer.SetDict(ChConfig.Def_PlayerKey_CrossRegisterMap, 0) + + GameWorld.Log("跨服报名成功 , registerMap=%s" % (registerMap), playerID) # 跨服PK上传数据完毕,通知跨服服务器,准备完毕 - if actionType == ShareDefine.Def_CrossAction_PK: + if registerMap == ChConfig.Def_FBMapID_CrossRealmPK: regVSRoomID = curPlayer.GetDictByKey(ChConfig.Def_PlayerKey_MergeRegisterRoomID) vsRoomID = curPlayer.GetVsRoomId() @@ -90,13 +204,13 @@ # 其他的,在上传数据完毕后,使用通用的通知可进入跨服 else: - NotifyCanEnterMergeServer(curPlayer, actionType) + NotifyCanEnterMergeServer(curPlayer, registerMap) # hxp 2015.09.10 跨服boss,后面的暂时不需要 return -def NotifyCanEnterMergeServer(curPlayer, actionType): +def NotifyCanEnterMergeServer(curPlayer, registerMap): # 通用包,通知客户端可进入跨服服务器 return @@ -112,7 +226,7 @@ ''' curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index) GameWorld.ErrLog("某些异常情况下,前端强制发包退出跨服状态! ", curPlayer.GetPlayerID()) - PlayerControl.SetCrossRealmState(curPlayer, 0) + PlayerControl.SetCrossMapID(curPlayer, 0) return #// C0 02 查看跨服玩家信息 #tagCGViewCrossPlayerInfo @@ -205,6 +319,68 @@ NetPackCommon.SendFakePack(curPlayer, sendPack) return - +def CrossServerMsg_PutInItem(itemInfo): + ## 跨服获得物品 + GameWorld.DebugLog("收到跨服服务器获得物品!") + playerID = itemInfo["PlayerID"] + itemData = itemInfo["ItemData"] + event = itemInfo["Event"] + curPlayer = GameWorld.GetPlayerManager().FindPlayerByID(playerID) + if curPlayer: + # 在线的话推到MapServer处理 + itemMsg = str(itemInfo) + curPlayer.MapServer_QueryPlayerResult(0, 0, "CrossPutInItem", itemMsg, len(itemMsg)) + return + # 离线的话直接发邮件 + GameWorld.Log("收到跨服获得物品,玩家不在线,直接发邮件! itemInfo=%s" % str(itemInfo), playerID) + itemID, itemCount, isBind, itemUserData = itemData + addItemList = [{"ItemID":itemID, "Count":itemCount, "IsBind":isBind, "UserData":itemUserData}] + PlayerCompensation.SendMailByKey("", [playerID], addItemList, detail={"CrossPutInItem":1, "Event":event}) + return + +def CrossServerMsg_GiveMoney(msgInfo): + ## 跨服获得货币 + + playerID = msgInfo["PlayerID"] + curPlayer = GameWorld.GetPlayerManager().FindPlayerByID(playerID) + if not curPlayer: + GameWorld.ErrLog("跨服获得货币时玩家不在线! msgInfo=%s" % str(msgInfo), playerID) + return + msgInfo = str(msgInfo) + 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