ServerPython/CoreServerGroup/GameServer/Script/Player/CrossRealmPlayer.py
@@ -21,13 +21,13 @@
import ReadChConfig
import ChConfig
import PlayerControl
import PlayerViewCache
import PlayerCompensation
import ChPyNetSendPack
import PlayerDBGSEvent
import NetPackCommon
import IpyGameDataPY
import PyGameData
import PlayerDBOper
# 获取玩家跨服服务器上的名字
#===============================================================================
@@ -56,16 +56,17 @@
    
    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:
@@ -74,34 +75,43 @@
            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 GetServerCommCrossZoneID(serverGroupID):
    ## 获取跨服常规分区
    zoneTypeName = "CrossZoneComm"
    crossZoneName = GameWorld.GetCrossZoneName()
    ipyDataList = IpyGameDataPY.GetIpyGameDataByCondition(zoneTypeName, {"CrossZoneName":crossZoneName}, True)
    if not ipyDataList:
        return 0
    for ipyData in ipyDataList:
        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.GetZoneID()
    return 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():
    ## 跨服服务器是否开放中
@@ -158,6 +168,7 @@
                continue
            PlayerControl.SetCrossMapID(curPlayer, 0)
            
    GameWorld.GetGameWorld().SendCrossServerStateToLoginServer(isOpen)
    # 通知地图
    GameWorld.SendMapServerMsgEx(ShareDefine.Def_Notify_WorldKey_CrossServerOpen, isOpen)
    return
@@ -186,16 +197,25 @@
    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):
    # 发送跨服账号注册上传数据
    # @param mapID: 真实场景地图ID
    # @param dataMapID: 真实场景地图ID对应场景数据地图ID
    
    # 设置上传数据的活动类型
    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())
@@ -264,96 +284,6 @@
    PlayerControl.SetCrossMapID(curPlayer, 0)
    return
#// C0 02 查看跨服玩家信息 #tagCGViewCrossPlayerInfo
#
#struct    tagCGViewCrossPlayerInfo
#{
#    tagHead        Head;
#    DWORD        PlayerID;    // 跨服玩家ID
#};
def OnViewCrossPlayerInfo(index, clientData, tick):
    if GameWorld.IsCrossServer():
        return
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    playerID = curPlayer.GetPlayerID()
    tagPlayerID = clientData.PlayerID
    curCache = PlayerViewCache.ViewCacheMgr.FindCache(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)
        return
    if tagPlayerID in PyGameData.g_crossPlayerViewCache:
        validChaheTime = 5 * 60 * 1000
        cacheInfo, updTick = PyGameData.g_crossPlayerViewCache[tagPlayerID]
        if tick - updTick <= validChaheTime:
            GameWorld.DebugLog("查看跨服玩家数据同步CD中,直接用缓存数据回复!tagPlayerID=%s" % (tagPlayerID), playerID)
            SyncPlayerViewCrossPlayerInfo(curPlayer, tagPlayerID, cacheInfo)
            return
        for crossPlayerID, cacheInfoList in PyGameData.g_crossPlayerViewCache.items():
            if tick - cacheInfoList[1] > validChaheTime:
                PyGameData.g_crossPlayerViewCache.pop(crossPlayerID)
    # 发送跨服服务器查询
    dataMsg = {"tagPlayerID":tagPlayerID, "playerID":playerID}
    CrossRealmMsg.SendMsgToCrossServer(ShareDefine.ClientServerMsg_ViewPlayerCache, dataMsg)
    return
def ClientServerMsg_ViewPlayerCache(serverGroupID, msgData):
    tagPlayerID = msgData["tagPlayerID"]
    playerID = msgData["playerID"]
    GameWorld.Log("收到子服查看跨服玩家信息: serverGroupID=%s,playerID=%s,tagPlayerID=%s" % (serverGroupID, playerID, tagPlayerID))
    cacheInfo = []
    curCache = PlayerViewCache.ViewCacheMgr.FindCache(tagPlayerID)
    if curCache:
        cacheInfo = [curCache.GetPropData(), PlayerViewCache.GetItemData(curCache), PlayerViewCache.GetPlusData(curCache)]
    viewPlayerCacheRet = [playerID, tagPlayerID, cacheInfo]
    CrossRealmMsg.SendMsgToClientServer(ShareDefine.CrossServerMsg_ViewPlayerCacheRet, viewPlayerCacheRet, [serverGroupID])
    return
def CrossServerMsg_ViewPlayerCacheRet(msgData, tick):
    playerID, tagPlayerID, 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)
    return
def SyncPlayerViewCrossPlayerInfo(curPlayer, tagPlayerID, cacheInfo):
    if not cacheInfo:
        PlayerControl.NotifyCode(curPlayer, "ViewPlayer_OffLine")
        return
    PropData, ItemData, PlusData = cacheInfo
    sendPack = ChPyNetSendPack.tagSCQueryPlayerCacheResult()
    sendPack.PlayerID = tagPlayerID
    sendPack.PropData = PropData
    sendPack.PropDataSize = len(sendPack.PropData)
    sendPack.ItemData = ItemData
    sendPack.ItemDataSize = len(sendPack.ItemData)
    sendPack.PlusData = PlusData
    sendPack.PlusDataSize = len(sendPack.PlusData)
    NetPackCommon.SendFakePack(curPlayer, sendPack)
    return
def CrossServerMsg_PutInItem(itemInfo):
    ## 跨服获得物品
    
@@ -370,7 +300,7 @@
    # 离线的话直接发邮件
    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
@@ -416,6 +346,46 @@
    PyGameData.g_crossSetPlayerAttr = {}
    return
def OnPlayerLogin(curPlayer):
    if not IsCrossServerOpen():
        return
    Sync_CrossZoneInfo(curPlayer)
    LoginDoUnNotifyCrossMsg(curPlayer)
    return
def MapServer_QueryCrossPlayerResult(playerID, callName, msgInfo, offlineExitCross=False):
    ## 同步地图跨服玩家处理信息,玩家可能不在线,缓存后等玩家上线处理,暂不考虑存档问题,服务器维护后未处理的命令将失效
    curPlayer = GameWorld.GetPlayerManager().FindPlayerByID(playerID)
    if curPlayer and curPlayer.GetInitOK():
        msgInfo = str(msgInfo)
        curPlayer.MapServer_QueryPlayerResult(0, 0, callName, msgInfo, len(msgInfo))
        return curPlayer
    else:
        # 缓存起来,等上线后处理
        if playerID not in PyGameData.g_unNotifyPlayerCrossMsgDict:
            PyGameData.g_unNotifyPlayerCrossMsgDict[playerID] = []
        msgList = PyGameData.g_unNotifyPlayerCrossMsgDict[playerID]
        msgList.append([callName, msgInfo])
        GameWorld.Log("玩家不在线,添加未通知的跨服命令: %s, msgInfo=%s" % (callName, msgInfo), playerID)
        if offlineExitCross:
            DoOfflinePlayerExitCrossServer(playerID)
    return
def LoginDoUnNotifyCrossMsg(curPlayer):
    playerID = curPlayer.GetPlayerID()
    msgList = PyGameData.g_unNotifyPlayerCrossMsgDict.pop(playerID, [])
    if not msgList:
        return
    for callName, msgInfo in msgList:
        GameWorld.Log("上线处理未通知的跨服命令: %s, msgInfo=%s" % (callName, msgInfo), playerID)
        msgInfo = str(msgInfo)
        curPlayer.MapServer_QueryPlayerResult(0, 0, callName, msgInfo, len(msgInfo))
    return
def Sync_CrossZoneInfo(curPlayer):
    clientPack = ChPyNetSendPack.tagGCCrossZoneInfo()
    clientPack.CommZoneID = GetServerCommCrossZoneID(GameWorld.GetServerGroupID())
    NetPackCommon.SendFakePack(curPlayer, clientPack)
    return