263 【主界面】头像系统(内政-幻境阁系统)-服务端(优化改名逻辑)
2个文件已修改
70 ■■■■ 已修改文件
ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/UpdatePlayerName.py 61 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/PyMongoDB/LogicProcess/UserCtrlDB.py 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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)
ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/PyMongoDB/LogicProcess/UserCtrlDB.py
@@ -455,6 +455,15 @@
            return dbPlayer
        return rec
    
    def updateDBPlayerName(self, playerID, newName):
        ## 根据玩家ID更新dbPlayer的玩家名,一般是改名用
        col = self.db[UCN_DBPlayer]
        dbPlayer = DataServerPlayerData.tagDBPlayer()
        if not dbPlayer.adoLoadCEx(col, {"PlayerID":playerID}):
            return
        dbPlayer.PlayerName = newName
        return dbPlayer.adoUpdateC(col)
    def requestLogicProcess(self, pack):
        db = self.db
        if self.IsMergeServer():