hxp
5 天以前 26958aff1b844a743a805b4f9075bee800b72a46
ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/UpdatePlayerName.py
@@ -23,6 +23,8 @@
import NetPackCommon
import IpyGameDataPY
import PlayerFamily
import PyMongoMain
import DirtyList
import ObjPool
def OnPlayerLogin(curPlayer):
@@ -41,36 +43,75 @@
#    DWORD        ServerID;
#};
def UpdatePlayerName(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    #新名字
    newName = clientData.NewName
    playerID = curPlayer.GetPlayerID()
    inputName = clientData.NewName
    inputName = GameWorld.GetGameWorld().GetCharTrim(inputName)
    newName = GetPlayerFullName(curPlayer, inputName)
    if not newName:
        return
    if DirtyList.IsWordForbidden(inputName):
        GameWorld.DebugLog("玩家改名存在敏感词! %s" % GameWorld.CodeToGbk(inputName), playerID)
        PlayerControl.NotifyCode(curPlayer, "NameSensitive")
        return
    ctrlDB = PyMongoMain.GetUserCtrlDB()
    if ctrlDB.findDBPlayerByName(newName):
        GameWorld.DebugLog("玩家改名已存在! %s" % GameWorld.CodeToGbk(newName), playerID)
        PlayerControl.NotifyCode(curPlayer, "NameExists")
        return
    
    renameState = curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Rename)
    if renameState:
        moneyType, moneyCount = IpyGameDataPY.GetFuncEvalCfg("PlayerRename", 1)
        if not PlayerControl.PayMoney(curPlayer, moneyType, moneyCount, "Rename"):
        moneyType, moneyCount = IpyGameDataPY.GetFuncEvalCfg("PlayerRename", 3)
        if not PlayerControl.HaveMoney(curPlayer, moneyType, moneyCount):
            return
    GameWorld.DebugLog("玩家改名: %s" % GameWorld.CodeToGbk(newName), playerID)
    if not ctrlDB.updateDBPlayerName(playerID, newName):
        return
    if renameState:
        PlayerControl.PayMoney(curPlayer, moneyType, moneyCount, "Rename")
    else:
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_Player_Rename, 1)
        Sync_UpdatePlayerNameCount(curPlayer)
        
    oldName = curPlayer.GetName()
    curPlayer.SetPlayerName(newName)
    GameWorld.GetPlayerManager().UpdatePlayerNameIndex(oldName, newName)
    GameWorld.GetMapCopyPlayerManager().UpdatePlayerNameIndex(oldName, newName)
    #改名结果
    clientPack = ChPyNetSendPack.tagSCRenameResult()
    clientPack.PlayerName = curPlayer.GetPlayerName()
    NetPackCommon.SendFakePack(curPlayer, clientPack)
    if not renameState:
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_Player_Rename, 1)
        Sync_UpdatePlayerNameCount(curPlayer)
    #同步其他功能玩家名
    PlayerFamily.RefreshFamilyMember(curPlayer)
    PlayerBillboard.UpdatePlayerBillboardName(curPlayer)
    #社交名待更新
    return
def GetPlayerFullName(curPlayer, playerName):
    ## 获取玩家全名
    serverID = GameWorld.GetPlayerServerID(curPlayer)
    nameFormatInfo = IpyGameDataPY.GetFuncEvalCfg("PlayerRename", 1)
    if not nameFormatInfo:
        return ""
    nameFormat = nameFormatInfo[0]
    paramList = [eval(pName) for pName in nameFormatInfo[1:]]
    fullName = nameFormat % tuple(paramList)
    maxLen = min(33, IpyGameDataPY.GetFuncCfg("PlayerRename", 2))
    if len(fullName) > maxLen:
        PlayerControl.NotifyCode(curPlayer, "NameLenLimit", [maxLen / 3, maxLen])
        GameWorld.DebugLog("玩家全名长度受限! %s len=%s > %s, serverID=%s" % (GameWorld.CodeToGbk(fullName), len(fullName), maxLen, serverID))
        return ""
    return fullName
def Sync_UpdatePlayerNameCount(curPlayer):
    clientPack = ObjPool.GetPoolMgr().acquire(ChPyNetSendPack.tagUpdatePlayerNameCount)
    clientPack.Count = curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Rename)