Core/Commands: Improve .character rename [name], now can force rename .character rename [name] [newName]

This commit is contained in:
xjose93
2013-04-23 15:33:42 +02:00
parent c33b811829
commit f2b6b2f95e
5 changed files with 125 additions and 18 deletions

View File

@@ -0,0 +1,11 @@
DELETE FROM `command` WHERE `name` = 'character rename';
INSERT INTO `command` (`name`, `security`, `help`) VALUES
('character rename', 2, 'Syntax: .character rename [$name] [$newName] \n\nMark selected in game or by $name in command character for rename at next login.\n\nIf $newName then the player will be forced rename.');
SET @ENTRY := 98;
SET @ENTRY1 := 167;
DELETE FROM `trinity_string` WHERE `entry` IN (@ENTRY, @ENTRY+1, @ENTRY1);
INSERT INTO `trinity_string` (`entry`, `content_default`) VALUES
(@ENTRY, '\'%s\' already exists as character name, choose another one'),
(@ENTRY+1, 'Player \'%s\' forced rename to \'%s\''),
(@ENTRY1, 'This name is reserved, choose another one');

View File

@@ -121,7 +121,8 @@ enum TrinityStrings
LANG_RBAC_LIST_PERMISSIONS_HEADER = 95,
LANG_GUILD_RENAME_ALREADY_EXISTS = 96,
LANG_GUILD_RENAME_DONE = 97,
// Room for more level 0 98-99 not used
LANG_RENAME_PLAYER_ALREADY_EXISTS = 98,
LANG_RENAME_PLAYER_WITH_NEW_NAME = 99,
// level 1 chat
LANG_GLOBAL_NOTIFY = 100,
@@ -198,7 +199,7 @@ enum TrinityStrings
LANG_COMMAND_TELE_NOTFOUND = 164,
LANG_COMMAND_TELE_PARAMETER = 165,
LANG_COMMAND_TELE_NOLOCATION = 166,
// 167 // not used
LANG_RESERVED_NAME = 167,
LANG_COMMAND_TELE_LOCATION = 168,
LANG_MAIL_SENT = 169,

View File

@@ -308,28 +308,121 @@ public:
if (!handler->extractPlayerTarget((char*)args, &target, &targetGuid, &targetName))
return false;
if (target)
{
// check online security
if (handler->HasLowerSecurity(target, 0))
return false;
char const* newNameStr = strtok(NULL, " ");
handler->PSendSysMessage(LANG_RENAME_PLAYER, handler->GetNameLink(target).c_str());
target->SetAtLoginFlag(AT_LOGIN_RENAME);
if (newNameStr)
{
std::string playerOldName;
std::string newName = newNameStr;
if (target)
{
// check online security
if (handler->HasLowerSecurity(target, 0))
return false;
playerOldName = target->GetName();
}
else
{
// check offline security
if (handler->HasLowerSecurity(NULL, targetGuid))
return false;
sObjectMgr->GetPlayerNameByGUID(targetGuid, playerOldName);
}
if (!normalizePlayerName(newName))
{
handler->SendSysMessage(LANG_BAD_VALUE);
handler->SetSentErrorMessage(true);
return false;
}
if (ObjectMgr::CheckPlayerName(newName, true) != CHAR_NAME_SUCCESS)
{
handler->SendSysMessage(LANG_BAD_VALUE);
handler->SetSentErrorMessage(true);
return false;
}
if (WorldSession* session = handler->GetSession())
{
if (!session->HasPermission(RBAC_PERM_SKIP_CHECK_CHARACTER_CREATION_RESERVEDNAME) && sObjectMgr->IsReservedName(newName))
{
handler->SendSysMessage(LANG_RESERVED_NAME);
handler->SetSentErrorMessage(true);
return false;
}
}
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHECK_NAME);
stmt->setString(0, newName);
PreparedQueryResult result = CharacterDatabase.Query(stmt);
if (result)
{
handler->PSendSysMessage(LANG_RENAME_PLAYER_ALREADY_EXISTS, newName.c_str());
handler->SetSentErrorMessage(true);
return false;
}
// Remove declined name from db
stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_DECLINED_NAME);
stmt->setUInt32(0, targetGuid);
CharacterDatabase.Execute(stmt);
if (target)
{
target->SetName(newName);
if (WorldSession* session = target->GetSession())
session->KickPlayer();
}
else
{
stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_NAME_BY_GUID);
stmt->setString(0, newName);
stmt->setUInt32(1, GUID_LOPART(targetGuid));
CharacterDatabase.Execute(stmt);
}
sWorld->UpdateCharacterNameData(targetGuid, newName);
handler->PSendSysMessage(LANG_RENAME_PLAYER_WITH_NEW_NAME, playerOldName.c_str(), newName.c_str());
if (WorldSession* session = handler->GetSession())
{
if (Player* player = session->GetPlayer())
sLog->outCommand(session->GetAccountId(), "GM %s (Account: %u) forced rename %s to player %s (Account: %u)", player->GetName().c_str(), session->GetAccountId(), newName.c_str(), playerOldName.c_str(), sObjectMgr->GetPlayerAccountIdByGUID(targetGuid));
}
else
sLog->outCommand(0, "CONSOLE forced rename '%s' to '%s' (GUID: %u)", playerOldName.c_str(), newName.c_str(), GUID_LOPART(targetGuid));
}
else
{
// check offline security
if (handler->HasLowerSecurity(NULL, targetGuid))
return false;
if (target)
{
// check online security
if (handler->HasLowerSecurity(target, 0))
return false;
std::string oldNameLink = handler->playerLink(targetName);
handler->PSendSysMessage(LANG_RENAME_PLAYER_GUID, oldNameLink.c_str(), GUID_LOPART(targetGuid));
handler->PSendSysMessage(LANG_RENAME_PLAYER, handler->GetNameLink(target).c_str());
target->SetAtLoginFlag(AT_LOGIN_RENAME);
}
else
{
// check offline security
if (handler->HasLowerSecurity(NULL, targetGuid))
return false;
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_ADD_AT_LOGIN_FLAG);
stmt->setUInt16(0, uint16(AT_LOGIN_RENAME));
stmt->setUInt32(1, GUID_LOPART(targetGuid));
CharacterDatabase.Execute(stmt);
std::string oldNameLink = handler->playerLink(targetName);
handler->PSendSysMessage(LANG_RENAME_PLAYER_GUID, oldNameLink.c_str(), GUID_LOPART(targetGuid));
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_ADD_AT_LOGIN_FLAG);
stmt->setUInt16(0, uint16(AT_LOGIN_RENAME));
stmt->setUInt32(1, GUID_LOPART(targetGuid));
CharacterDatabase.Execute(stmt);
}
}
return true;

View File

@@ -165,6 +165,7 @@ void CharacterDatabaseConnection::DoPrepareStatements()
PrepareStatement(CHAR_SEL_MATCH_MAKER_RATING, "SELECT matchMakerRating FROM character_arena_stats WHERE guid = ? AND slot = ?", CONNECTION_SYNCH);
PrepareStatement(CHAR_SEL_CHARACTER_COUNT, "SELECT account, COUNT(guid) FROM characters WHERE account = ? GROUP BY account", CONNECTION_ASYNC);
PrepareStatement(CHAR_UPD_NAME, "UPDATE characters set name = ?, at_login = at_login & ~ ? WHERE guid = ?", CONNECTION_ASYNC);
PrepareStatement(CHAR_UPD_NAME_BY_GUID, "UPDATE characters SET name = ? WHERE guid = ?", CONNECTION_ASYNC);
PrepareStatement(CHAR_DEL_DECLINED_NAME, "DELETE FROM character_declinedname WHERE guid = ?", CONNECTION_ASYNC);
// Guild handling

View File

@@ -161,6 +161,7 @@ enum CharacterDatabaseStatements
CHAR_SEL_MATCH_MAKER_RATING,
CHAR_SEL_CHARACTER_COUNT,
CHAR_UPD_NAME,
CHAR_UPD_NAME_BY_GUID,
CHAR_DEL_DECLINED_NAME,
CHAR_SEL_CHARACTER_DATA_BY_GUID,