| | |
| | | #!/usr/bin/python
|
| | | # -*- coding: GBK -*-
|
| | | #-------------------------------------------------------------------------------
|
| | | #
|
| | | ##@package Player.UpdatePlayerName
|
| | | #
|
| | | ##@package UpdatePlayerName.py
|
| | | # @todo:改名
|
| | | # @author hxp
|
| | | # @date 2025-10-15
|
| | | # @version 1.0
|
| | | #
|
| | | # @todo:玩家改名
|
| | | # 详细描述: 改名
|
| | | #
|
| | | # @author jiang
|
| | | # @date 2013-01-23 13:30
|
| | | # @version 1.5
|
| | | # @note:
|
| | | #
|
| | | # @change: "2013-03-13 17:00" wdb 删除封包
|
| | | # @change: "2014-05-22 10:20" xcc 恢复改名功能
|
| | | # @change: "2014-12-23 03:40" Alee 改名字典用内存key
|
| | | # @change: "2016-11-09 14:10" xdh 修改改名消耗
|
| | | # @change: "2017-07-04 20:10" xdh 玩家合服首次登录改名次数重置为0
|
| | | #------------------------------------------------------------------------------ |
| | | #"""Version = 2017-07-04 20:10"""
|
| | | #------------------------------------------------------------------------------ |
| | | # 导入
|
| | | import GameWorld
|
| | | import ChConfig
|
| | | import ReadChConfig
|
| | | import PlayerControl
|
| | | import IPY_GameWorld
|
| | | import ItemCommon
|
| | | import ChPyNetSendPack
|
| | | import NetPackCommon
|
| | | import EventReport
|
| | | import ItemControler
|
| | | #------------------------------------------------------------------------------ |
| | | #-------------------------------------------------------------------------------
|
| | | #"""Version = 2025-10-15 19:30"""
|
| | | #-------------------------------------------------------------------------------
|
| | |
|
| | | ## 合服首登
|
| | | def ResetChangeNameCnt(curPlayer):
|
| | | return #暂屏蔽
|
| | | GameWorld.DebugLog(' 玩家合服首次登录 改名次数重置为0')
|
| | | PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_Player_UpdatePlayerNameCnt, 0)
|
| | | Sync_UpdatePlayerNameCount(curPlayer)
|
| | | 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
|
| | | #struct tagUpdatePlayerName
|
| | | #{
|
| | | # tagHead Head;
|
| | | # BYTE NewNameLen;
|
| | | # BYTE NewNameLen; |
| | | # char NewName[NewNameLen];
|
| | | # BYTE ItemIndex; //改名物品在背包中的位置
|
| | | # DWORD ServerID;
|
| | | # BYTE ItemIndex; //改名物品在背包中的位置
|
| | | # DWORD ServerID;
|
| | | #};
|
| | | #===============================================================================
|
| | | ## 玩家更改名字
|
| | | # @param index: 玩家索引
|
| | | # @param clientData: 封包结构体
|
| | | # @param tick: 时间戳
|
| | | # @return: None
|
| | | def UpdatePlayerName(index, clientData, tick):
|
| | | |
| | | curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
|
| | | if GameWorld.IsCrossServer():
|
| | | #itemuse_lzxkoy_0:不可在跨服环境下使用改名功能。
|
| | | PlayerControl.NotifyCode(curPlayer, "itemuse_lzxkoy_0")
|
| | | playerID = curPlayer.GetPlayerID()
|
| | | inputName = clientData.NewName
|
| | | inputName = GameWorld.GetGameWorld().GetCharTrim(inputName)
|
| | | newName = GetPlayerFullName(curPlayer, inputName)
|
| | | if not newName:
|
| | | return
|
| | |
|
| | | if curPlayer.GetDictByKey(ChConfig.Def_Player_Dict_UpdatePlayerName):
|
| | | #正在改名中
|
| | | GameWorld.Log("已经在改名中...", curPlayer.GetID())
|
| | | if DirtyList.IsWordForbidden(inputName):
|
| | | GameWorld.DebugLog("玩家改名存在敏感词! %s" % GameWorld.CodeToGbk(inputName), playerID)
|
| | | PlayerControl.NotifyCode(curPlayer, "NameSensitive")
|
| | | return
|
| | |
|
| | | #新名字
|
| | | newName = clientData.NewName
|
| | | itemIndex = clientData.ItemIndex - 1 #客户端发的默认+了1
|
| | | serverID = clientData.ServerID
|
| | | if itemIndex == -1: #-1则默认扣钱否则扣道具
|
| | | ctrlDB = PyMongoMain.GetUserCtrlDB()
|
| | | if ctrlDB.findDBPlayerByName(newName):
|
| | | GameWorld.DebugLog("玩家改名已存在! %s" % GameWorld.CodeToGbk(newName), playerID)
|
| | | PlayerControl.NotifyCode(curPlayer, "NameExists")
|
| | | return
|
| | | moneyType, moneyCount = GetCostMoney(curPlayer)
|
| | | |
| | | renameState = curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Rename)
|
| | | if renameState:
|
| | | moneyType, moneyCount = IpyGameDataPY.GetFuncEvalCfg("PlayerRename", 3)
|
| | | if not PlayerControl.HaveMoney(curPlayer, moneyType, moneyCount):
|
| | | #金钱不足
|
| | | return False
|
| | | else:
|
| | | itemPack = curPlayer.GetItemManager().GetPack(IPY_GameWorld.rptItem)
|
| | | curItem = itemPack.GetAt(itemIndex)
|
| | | if not __CheckItemUpdatePlayerName(curPlayer, curItem):
|
| | | #物品错误
|
| | | return
|
| | | |
| | | #改名物品在背包的位置, 因为背包物品索引从0开始, 字典最小值只能0, 所以此次索引+1
|
| | | PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_Player_Dict_UpdatePlayerNameItemIndex, itemIndex + 1)
|
| | | |
| | | #设置正在改名中...
|
| | | curPlayer.SetDict(ChConfig.Def_Player_Dict_UpdatePlayerName, 1)
|
| | | |
| | | #通知GameServer正式改名
|
| | | newNameMsg = str([newName, serverID])
|
| | | GameWorld.Log("UpdatePlayerName 通知GameServer正式改名为:%s"%newNameMsg, curPlayer.GetID())
|
| | | curPlayer.GameServer_QueryPlayerByID(ChConfig.queryType_UpdatePlayerName, 0, '', newNameMsg, len(newNameMsg))
|
| | | return True
|
| | |
|
| | |
|
| | | ## 验证物品是否为改名贴
|
| | | # @param curPlayer 玩家实例
|
| | | # @param curItem 改名贴
|
| | | # @return 是否为改名贴
|
| | | def __CheckItemUpdatePlayerName(curPlayer, curItem):
|
| | | |
| | | if not ItemCommon.CheckItemCanUse(curItem):
|
| | | return False
|
| | | |
| | | return (curItem.GetType() == ChConfig.Def_ItemType_ChangePlayerName)
|
| | |
|
| | |
|
| | | ## 获取金钱消耗
|
| | | # @param curPlayer: 玩家实例
|
| | | # @return: 金钱类型, 金钱数量
|
| | | def GetCostMoney(curPlayer):
|
| | | #改名次数(公式参数)
|
| | | updatePlayerNameCnt = curPlayer.NomalDictGetProperty(ChConfig.Def_Player_UpdatePlayerNameCnt) |
| | | moneyType, moneyCount = ReadChConfig.GetEvalChConfig("UpdatePlayerNameMoney")
|
| | | return moneyType, eval(moneyCount)
|
| | | |
| | | #===============================================================================
|
| | | #//01 17 角色名同步#tagMUpdatePlayerName
|
| | | #tagMUpdatePlayerName * GettagMUpdatePlayerName();
|
| | | #
|
| | | #class IPY_MUpdatePlayerName
|
| | | #{
|
| | | #public:
|
| | | #
|
| | | # |
| | | # unsigned char GetNewNameLen();
|
| | | # |
| | | # std::string GetNewName();
|
| | | #};
|
| | | #===============================================================================
|
| | | ## 收到GameServer通知改名
|
| | | # @param index: 玩家索引
|
| | | # @param tick: 时间戳
|
| | | # @return
|
| | | def GameServer_UpdatePlayerName(index, tick):
|
| | | curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
|
| | | curPlayerName = curPlayer.GetName()
|
| | | |
| | | sendPack = IPY_GameWorld.IPY_MUpdatePlayerName()
|
| | | newName = sendPack.GetNewName()
|
| | | |
| | | curPlayer.SetPlayerName(newName)
|
| | | GameWorld.GetPlayerManager().UpdatePlayerNameIndex(curPlayerName, newName)
|
| | | GameWorld.GetMapCopyPlayerManager().UpdatePlayerNameIndex(curPlayerName, newName)
|
| | | #EventReport.WriteEvent_change_name(curPlayer, curPlayerName, newName)
|
| | | GameWorld.Log("UpdatePlayerName MapServer改名成功, newName = %s"%newName, curPlayer.GetID())
|
| | |
|
| | | #通知GameServer结果
|
| | | curPlayer.UpdatePlayerNameResult(True)
|
| | | return True
|
| | |
|
| | |
|
| | | ## 扣除改名消耗
|
| | | # @param curPlayer: 玩家实例
|
| | | # @return: None
|
| | | def PayUpdatePlayerNameCost(curPlayer): |
| | | itemIndex = curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Dict_UpdatePlayerNameItemIndex) - 1
|
| | | if itemIndex == -1: #-1则默认扣钱否则扣道具
|
| | | #扣除消耗
|
| | | moneyType, moneyCount = GetCostMoney(curPlayer)
|
| | | PlayerControl.PayMoney(curPlayer, moneyType, moneyCount, ChConfig.Def_Cost_Rename)
|
| | | GameWorld.DebugLog("玩家改名: %s" % GameWorld.CodeToGbk(newName), playerID)
|
| | | if not ctrlDB.updateDBPlayerName(playerID, newName):
|
| | | return
|
| | | |
| | | if renameState:
|
| | | PlayerControl.PayMoney(curPlayer, moneyType, moneyCount, "Rename")
|
| | | else:
|
| | | #扣除物品
|
| | | itemPack = curPlayer.GetItemManager().GetPack(IPY_GameWorld.rptItem)
|
| | | curItem = itemPack.GetAt(itemIndex)
|
| | | if not __CheckItemUpdatePlayerName(curPlayer, curItem):
|
| | | # 物品可能已经变更,不是改名道具了或为空,重新找一遍
|
| | | curItem = ItemControler.FindPlayerItemByType(curPlayer, IPY_GameWorld.rptItem, ChConfig.Def_ItemType_ChangePlayerName)
|
| | | if ItemCommon.CheckItemCanUse(curItem):
|
| | | ItemCommon.DelItem(curPlayer, curItem, 1, True, 'UpdatePlayerName')
|
| | | 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)
|
| | |
|
| | | #改名次数+1
|
| | | #updatePlayerNameCnt = curPlayer.NomalDictGetProperty(ChConfig.Def_Player_UpdatePlayerNameCnt)
|
| | | #PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_Player_UpdatePlayerNameCnt, updatePlayerNameCnt + 1) |
| | | #改名结果
|
| | | clientPack = ChPyNetSendPack.tagSCRenameResult()
|
| | | clientPack.PlayerName = curPlayer.GetPlayerName()
|
| | | NetPackCommon.SendFakePack(curPlayer, clientPack)
|
| | |
|
| | | PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_Player_Dict_UpdatePlayerNameItemIndex, 0)
|
| | | #同步其他功能玩家名
|
| | | 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
|
| | |
|
| | | ## 通知改名次数
|
| | | # @param curPlayer: 玩家实例
|
| | | # @return: None
|
| | | def Sync_UpdatePlayerNameCount(curPlayer):
|
| | | return
|
| | | updatePlayerNameCnt = curPlayer.NomalDictGetProperty(ChConfig.Def_Player_UpdatePlayerNameCnt)
|
| | | |
| | | pack = ChPyNetSendPack.tagUpdatePlayerNameCount()
|
| | | pack.Clear()
|
| | | pack.Count = updatePlayerNameCnt
|
| | | NetPackCommon.SendFakePack(curPlayer, pack)
|
| | | clientPack = ObjPool.GetPoolMgr().acquire(ChPyNetSendPack.tagUpdatePlayerNameCount)
|
| | | clientPack.Count = curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Rename)
|
| | | NetPackCommon.SendFakePack(curPlayer, clientPack)
|
| | | return
|