|  |  | 
 |  |  | import NetPackCommon
 | 
 |  |  | import IpyGameDataPY
 | 
 |  |  | import PyGameData
 | 
 |  |  | import PlayerDBOper
 | 
 |  |  | 
 | 
 |  |  | # 获取玩家跨服服务器上的名字
 | 
 |  |  | #===============================================================================
 | 
 |  |  | 
 |  |  |     
 | 
 |  |  |     return opName.decode('gbk').encode(GameWorld.GetCharacterEncoding()) + playerName
 | 
 |  |  | 
 | 
 |  |  | def GetCrossCommZoneIpyDataByZoneID(zoneID):
 | 
 |  |  |     ## 获取跨服常规分区  | 
 |  |  | def GetCrossZoneIpyDataByZoneID(mapID, zoneID):
 | 
 |  |  |     ## 获取跨服分区
 | 
 |  |  |     zoneTypeName = ChConfig.Def_CrossZoneTypeName.get(mapID, "CrossZoneComm")
 | 
 |  |  |     crossZoneName = GameWorld.GetCrossZoneName()
 | 
 |  |  |     ipyData = IpyGameDataPY.GetIpyGameDataNotLog("CrossZoneComm", crossZoneName, zoneID)
 | 
 |  |  |     return ipyData
 | 
 |  |  |     return IpyGameDataPY.GetIpyGameData(zoneTypeName, crossZoneName, zoneID)
 | 
 |  |  | 
 | 
 |  |  | def GetCrossCommZoneIpyDataByServerGroupID(serverGroupID):
 | 
 |  |  |     ## 获取跨服常规分区
 | 
 |  |  | def GetCrossZoneIpyDataByServerGroupID(mapID, serverGroupID):
 | 
 |  |  |     ## 获取跨服分区
 | 
 |  |  |     zoneTypeName = ChConfig.Def_CrossZoneTypeName.get(mapID, "CrossZoneComm")
 | 
 |  |  |     crossZoneName = GameWorld.GetCrossZoneName()
 | 
 |  |  |     ipyDataList = IpyGameDataPY.GetIpyGameDataByCondition("CrossZoneComm", {"CrossZoneName":crossZoneName}, True)
 | 
 |  |  |     ipyDataList = IpyGameDataPY.GetIpyGameDataByCondition(zoneTypeName, {"CrossZoneName":crossZoneName}, True)
 | 
 |  |  |     if not ipyDataList:
 | 
 |  |  |         return
 | 
 |  |  |     for ipyData in ipyDataList:
 | 
 |  |  | 
 |  |  |             if (isinstance(serverGroupIDInfo, tuple) and serverGroupIDInfo[0] <= serverGroupID <= serverGroupIDInfo[1]) \
 | 
 |  |  |                 or (isinstance(serverGroupIDInfo, int) and serverGroupIDInfo == serverGroupID):
 | 
 |  |  |                 return ipyData
 | 
 |  |  |     GameWorld.ErrLog("没有找到跨服玩法对应分区! mapID=%s, serverGroupID=%s, zoneTypeName=%s" % (mapID, serverGroupID, zoneTypeName))
 | 
 |  |  |     return
 | 
 |  |  | 
 | 
 |  |  | def GetCrossCommZoneIpyDataListByServerGroupID(serverGroupID):
 | 
 |  |  | def GetCrossZoneIpyDataListByServerGroupID(mapID, serverGroupID):
 | 
 |  |  |     ## 获取跨服常规分区列表
 | 
 |  |  |     if serverGroupID:
 | 
 |  |  |         ipyData = GetCrossCommZoneIpyDataByServerGroupID(serverGroupID)
 | 
 |  |  |         ipyData = GetCrossZoneIpyDataByServerGroupID(mapID, serverGroupID)
 | 
 |  |  |         if not ipyData:
 | 
 |  |  |             return
 | 
 |  |  |         ipyDataList = [ipyData]
 | 
 |  |  |     else:
 | 
 |  |  |         crossZoneName = GameWorld.GetCrossZoneName()
 | 
 |  |  |         ipyDataList = IpyGameDataPY.GetIpyGameDataByCondition("CrossZoneComm", {"CrossZoneName":crossZoneName}, True)
 | 
 |  |  |         zoneTypeName = ChConfig.Def_CrossZoneTypeName.get(mapID, "CrossZoneComm")
 | 
 |  |  |         ipyDataList = IpyGameDataPY.GetIpyGameDataByCondition(zoneTypeName, {"CrossZoneName":crossZoneName}, True)
 | 
 |  |  |     return ipyDataList
 | 
 |  |  | 
 | 
 |  |  | def GetServerCrossZoneMapIpyData(mapID, serverGroupID=0):
 | 
 |  |  |     ## 获取本服对应跨服玩法分区地图信息
 | 
 |  |  | def GetServerCrossZoneMapIpyData(zoneID, mapID):
 | 
 |  |  |     ## 获取本服对应跨服玩法分区地图信息 - 仅适用于固定地图及虚拟分线的跨服玩法
 | 
 |  |  |     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})
 | 
 |  |  |     return IpyGameDataPY.GetIpyGameDataByCondition(tableName, {"ZoneID":zoneID})
 | 
 |  |  | 
 | 
 |  |  | def IsCrossServerOpen():
 | 
 |  |  |     ## 跨服服务器是否开放中
 | 
 |  |  | 
 |  |  |     curPlayer = GameWorld.GetPlayerManager().FindPlayerByID(playerID)
 | 
 |  |  |     if not curPlayer:
 | 
 |  |  |         GameWorld.Log("    退出跨服时本服玩家不在线!", playerID)
 | 
 |  |  |         DoOfflinePlayerExitCrossServer(playerID)
 | 
 |  |  |         return
 | 
 |  |  |     PlayerControl.SetCrossMapID(curPlayer, 0)
 | 
 |  |  |     return
 | 
 |  |  | 
 | 
 |  |  | def SendCrossRealmReg(curPlayer, registerMap, mapID=0, dataMapID=0, copyMapID=0, posX=0, posY=0):
 | 
 |  |  | def DoOfflinePlayerExitCrossServer(playerID):
 | 
 |  |  |     ## 处理离线玩家退出跨服服务器更新DB数据逻辑
 | 
 |  |  |      | 
 |  |  |     PlayerDBOper.UpdateDBOper(PlayerDBOper.Table_DBPlayer, {"PlayerID":playerID}, {"ExAttr5":0})
 | 
 |  |  |     return
 | 
 |  |  | 
 | 
 |  |  | def SendCrossRealmReg(curPlayer, registerMap, mapID=0, dataMapID=0, copyMapID=0, posX=0, posY=0, lineID=0):
 | 
 |  |  |     # 发送跨服账号注册上传数据
 | 
 |  |  |     
 | 
 |  |  |     # 设置上传数据的活动类型
 | 
 |  |  |     curPlayer.SetDict(ChConfig.Def_PlayerKey_CrossRegisterMap, registerMap)
 | 
 |  |  |     sysMsg = str([registerMap, mapID, dataMapID, copyMapID, posX, posY])
 | 
 |  |  |     sysMsg = str([registerMap, mapID, dataMapID, copyMapID, posX, posY, lineID])
 | 
 |  |  |     curPlayer.MapServer_QueryPlayerResult(0, 0, "CrossRealmReg", sysMsg, len(sysMsg))            
 | 
 |  |  |     GameWorld.Log("SendCrossRealmReg registerMap=%s,mapID=%s,dataMapID=%s,copyMapID=%s,posX=%s,posY=%s" 
 | 
 |  |  |                   % (registerMap, mapID, dataMapID, copyMapID, posX, posY), curPlayer.GetPlayerID())
 | 
 |  |  | 
 |  |  | #{
 | 
 |  |  | #    tagHead        Head;
 | 
 |  |  | #    DWORD        PlayerID;    // 跨服玩家ID
 | 
 |  |  | #    BYTE        EquipClassLV;    //大于0为查看指定境界阶装备信息,  0为查看默认信息
 | 
 |  |  | #};
 | 
 |  |  | def OnViewCrossPlayerInfo(index, clientData, tick):
 | 
 |  |  |     if GameWorld.IsCrossServer():
 | 
 |  |  | 
 |  |  |     curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
 | 
 |  |  |     playerID = curPlayer.GetPlayerID()
 | 
 |  |  |     tagPlayerID = clientData.PlayerID
 | 
 |  |  |     curCache = PlayerViewCache.ViewCacheMgr.FindCache(tagPlayerID)
 | 
 |  |  |     equipClassLV = clientData.EquipClassLV
 | 
 |  |  |     curCache = PlayerViewCache.FindViewCache(tagPlayerID)
 | 
 |  |  |     ## 本服有,直接回客户端
 | 
 |  |  |     if curCache:
 | 
 |  |  |         GameWorld.DebugLog("查看跨服玩家,是本服玩家,直接回复!tagPlayerID=%s" % (tagPlayerID), playerID)
 | 
 |  |  |         sendPack = ChPyNetSendPack.tagSCQueryPlayerCacheResult()
 | 
 |  |  |         sendPack.PlayerID = tagPlayerID
 | 
 |  |  |         sendPack.PropData = curCache.GetPropData()
 | 
 |  |  |         sendPack.PropDataSize = len(sendPack.PropData)
 | 
 |  |  |         sendPack.ItemData = PlayerViewCache.GetItemData(curCache)
 | 
 |  |  |         sendPack.ItemDataSize = len(sendPack.ItemData)
 | 
 |  |  |         sendPack.PlusData = PlayerViewCache.GetPlusData(curCache)
 | 
 |  |  |         sendPack.PlusDataSize = len(sendPack.PlusData)
 | 
 |  |  |         NetPackCommon.SendFakePack(curPlayer, sendPack)
 | 
 |  |  |         PlayerViewCache.Sync_PlayerCache(curPlayer, curCache, equipClassLV)
 | 
 |  |  |         return
 | 
 |  |  |     
 | 
 |  |  |     if tagPlayerID in PyGameData.g_crossPlayerViewCache:
 | 
 |  |  |         validChaheTime = 5 * 60 * 1000
 | 
 |  |  |         validChaheTime = 10 * 60 * 1000
 | 
 |  |  |         cacheInfo, updTick = PyGameData.g_crossPlayerViewCache[tagPlayerID]
 | 
 |  |  |         if tick - updTick <= validChaheTime:
 | 
 |  |  |             GameWorld.DebugLog("查看跨服玩家数据同步CD中,直接用缓存数据回复!tagPlayerID=%s" % (tagPlayerID), playerID)
 | 
 |  |  |             SyncPlayerViewCrossPlayerInfo(curPlayer, tagPlayerID, cacheInfo)
 | 
 |  |  |             SyncPlayerViewCrossPlayerInfo(curPlayer, tagPlayerID, equipClassLV, cacheInfo)
 | 
 |  |  |             return
 | 
 |  |  |         
 | 
 |  |  |         for crossPlayerID, cacheInfoList in PyGameData.g_crossPlayerViewCache.items():
 | 
 |  |  | 
 |  |  |                 PyGameData.g_crossPlayerViewCache.pop(crossPlayerID)
 | 
 |  |  |                 
 | 
 |  |  |     # 发送跨服服务器查询
 | 
 |  |  |     dataMsg = {"tagPlayerID":tagPlayerID, "playerID":playerID}
 | 
 |  |  |     dataMsg = {"tagPlayerID":tagPlayerID, "playerID":playerID, "equipClassLV":equipClassLV}
 | 
 |  |  |     CrossRealmMsg.SendMsgToCrossServer(ShareDefine.ClientServerMsg_ViewPlayerCache, dataMsg)
 | 
 |  |  |     return
 | 
 |  |  | 
 | 
 |  |  | def ClientServerMsg_ViewPlayerCache(serverGroupID, msgData):
 | 
 |  |  |     tagPlayerID = msgData["tagPlayerID"]
 | 
 |  |  |     playerID = msgData["playerID"]
 | 
 |  |  |     equipClassLV = msgData["equipClassLV"]
 | 
 |  |  |     
 | 
 |  |  |     GameWorld.Log("收到子服查看跨服玩家信息: serverGroupID=%s,playerID=%s,tagPlayerID=%s" % (serverGroupID, playerID, tagPlayerID))
 | 
 |  |  |     
 | 
 |  |  |     cacheInfo = []
 | 
 |  |  |     curCache = PlayerViewCache.ViewCacheMgr.FindCache(tagPlayerID)
 | 
 |  |  |     cacheInfo = {}
 | 
 |  |  |     curCache = PlayerViewCache.FindViewCache(tagPlayerID)
 | 
 |  |  |     if curCache:
 | 
 |  |  |         cacheInfo = [curCache.GetPropData(), PlayerViewCache.GetItemData(curCache), PlayerViewCache.GetPlusData(curCache)]
 | 
 |  |  |          | 
 |  |  |     viewPlayerCacheRet = [playerID, tagPlayerID, cacheInfo]
 | 
 |  |  |         cacheInfo = {"PropData":curCache.PropData, "PlusData":curCache.PlusData}
 | 
 |  |  |         for classLV in xrange(1, 15 + 1):
 | 
 |  |  |             attrName = "ItemData%s" % classLV
 | 
 |  |  |             if hasattr(curCache, attrName):
 | 
 |  |  |                 cacheInfo[attrName] = getattr(curCache, attrName)
 | 
 |  |  |                  | 
 |  |  |     viewPlayerCacheRet = [playerID, tagPlayerID, equipClassLV, cacheInfo]
 | 
 |  |  |     CrossRealmMsg.SendMsgToClientServer(ShareDefine.CrossServerMsg_ViewPlayerCacheRet, viewPlayerCacheRet, [serverGroupID])
 | 
 |  |  |     return
 | 
 |  |  | 
 | 
 |  |  | def CrossServerMsg_ViewPlayerCacheRet(msgData, tick):
 | 
 |  |  |     
 | 
 |  |  |     playerID, tagPlayerID, cacheInfo = msgData
 | 
 |  |  |     playerID, tagPlayerID, equipClassLV, cacheInfo = msgData
 | 
 |  |  |     GameWorld.Log("收到跨服服务器回复的查看玩家信息: playerID=%s,tagPlayerID=%s" % (playerID, tagPlayerID))
 | 
 |  |  |     
 | 
 |  |  |     PyGameData.g_crossPlayerViewCache[tagPlayerID] = [cacheInfo, tick] # 更新信息
 | 
 |  |  |     
 | 
 |  |  |     curPlayer = GameWorld.GetPlayerManager().FindPlayerByID(playerID)
 | 
 |  |  |     if curPlayer:
 | 
 |  |  |         SyncPlayerViewCrossPlayerInfo(curPlayer, tagPlayerID, cacheInfo)
 | 
 |  |  |         SyncPlayerViewCrossPlayerInfo(curPlayer, tagPlayerID, equipClassLV, cacheInfo)
 | 
 |  |  |         
 | 
 |  |  |     return
 | 
 |  |  | 
 | 
 |  |  | def SyncPlayerViewCrossPlayerInfo(curPlayer, tagPlayerID, cacheInfo):
 | 
 |  |  | def SyncPlayerViewCrossPlayerInfo(curPlayer, tagPlayerID, equipClassLV, cacheInfo):
 | 
 |  |  |     if not cacheInfo:
 | 
 |  |  |         PlayerControl.NotifyCode(curPlayer, "ViewPlayer_OffLine")
 | 
 |  |  |         return
 | 
 |  |  |     PropData, ItemData, PlusData = cacheInfo
 | 
 |  |  |      | 
 |  |  |     if equipClassLV:
 | 
 |  |  |         itemData = cacheInfo.get("ItemData%s" % equipClassLV, "")
 | 
 |  |  |         sendPack = ChPyNetSendPack.tagSCPlayerEquipCacheResult()
 | 
 |  |  |         sendPack.PlayerID = tagPlayerID
 | 
 |  |  |         sendPack.EquipClassLV = equipClassLV
 | 
 |  |  |         sendPack.ItemData = itemData
 | 
 |  |  |         sendPack.ItemDataSize = len(sendPack.ItemData)
 | 
 |  |  |         NetPackCommon.SendFakePack(curPlayer, sendPack)
 | 
 |  |  |         return
 | 
 |  |  |      | 
 |  |  |     #回包客户端
 | 
 |  |  |     sendPack = ChPyNetSendPack.tagSCQueryPlayerCacheResult()
 | 
 |  |  |     sendPack.PlayerID = tagPlayerID
 | 
 |  |  |     sendPack.PropData = PropData
 | 
 |  |  |     sendPack.PropData = cacheInfo.get("PropData", "")
 | 
 |  |  |     sendPack.PropDataSize = len(sendPack.PropData)
 | 
 |  |  |     sendPack.ItemData = ItemData
 | 
 |  |  |     sendPack.ItemDataSize = len(sendPack.ItemData)
 | 
 |  |  |     sendPack.PlusData = PlusData
 | 
 |  |  |     sendPack.PlusData = cacheInfo.get("PlusData", "")
 | 
 |  |  |     sendPack.PlusDataSize = len(sendPack.PlusData)
 | 
 |  |  |     NetPackCommon.SendFakePack(curPlayer, sendPack)
 | 
 |  |  |     return
 | 
 |  |  | 
 |  |  |     # 离线的话直接发邮件
 | 
 |  |  |     GameWorld.Log("收到跨服获得物品,玩家不在线,直接发邮件! itemInfo=%s" % str(itemInfo), playerID)
 | 
 |  |  |     itemID, itemCount, isBind, itemUserData = itemData
 | 
 |  |  |     addItemList = [{"ItemID":itemID, "Count":itemCount, "IsBind":isBind, "UserData":itemUserData}]
 | 
 |  |  |     addItemList = [{"ItemID":itemID, "Count":itemCount, "IsAuctionItem":isBind, "UserData":itemUserData}]
 | 
 |  |  |     PlayerCompensation.SendMailByKey("", [playerID], addItemList, detail={"CrossPutInItem":1, "Event":event})
 | 
 |  |  |     return
 | 
 |  |  | 
 |