#!/usr/bin/python # -*- coding: GBK -*- #------------------------------------------------------------------------------- # ##@package Player.UpdatePlayerName # # @todo:¸ÄÃû # @author hxp # @date 2025-10-15 # @version 1.0 # # ÏêϸÃèÊö: ¸ÄÃû # #------------------------------------------------------------------------------- #"""Version = 2025-10-15 19:30""" #------------------------------------------------------------------------------- import ChConfig import GameWorld import PlayerControl import ChPyNetSendPack import PlayerBillboard import NetPackCommon import IpyGameDataPY import PlayerFamily import PyMongoMain import DirtyList import ObjPool def OnPlayerLogin(curPlayer): if curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Rename): Sync_UpdatePlayerNameCount(curPlayer) return #//A1 22 ½ÇÉ«¸ÄÃû #tagUpdatePlayerName # #struct tagUpdatePlayerName #{ # tagHead Head; # BYTE NewNameLen; # char NewName[NewNameLen]; # BYTE ItemIndex; //¸ÄÃûÎïÆ·ÔÚ±³°üÖеÄλÖà # DWORD ServerID; #}; def UpdatePlayerName(index, clientData, tick): curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index) 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", 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) #ͬ²½ÆäËû¹¦ÄÜÍæ¼ÒÃû 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) NetPackCommon.SendFakePack(curPlayer, clientPack) return