mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-19 08:55:32 +01:00
Core/Scripts: added command to move characters across accounts
(cherry-picked from f7f865f818)
This commit is contained in:
@@ -61,6 +61,7 @@ public:
|
||||
{ "customize", rbac::RBAC_PERM_COMMAND_CHARACTER_CUSTOMIZE, true, &HandleCharacterCustomizeCommand, "", },
|
||||
{ "changefaction", rbac::RBAC_PERM_COMMAND_CHARACTER_CHANGEFACTION, true, &HandleCharacterChangeFactionCommand, "", },
|
||||
{ "changerace", rbac::RBAC_PERM_COMMAND_CHARACTER_CHANGERACE, true, &HandleCharacterChangeRaceCommand, "", },
|
||||
{ "changeaccount", rbac::RBAC_PERM_COMMAND_CHARACTER_CHANGEACCOUNT, true, &HandleCharacterChangeAccountCommand, "", },
|
||||
{ "deleted", rbac::RBAC_PERM_COMMAND_CHARACTER_DELETED, true, NULL, "", characterDeletedCommandTable },
|
||||
{ "erase", rbac::RBAC_PERM_COMMAND_CHARACTER_ERASE, true, &HandleCharacterEraseCommand, "", },
|
||||
{ "level", rbac::RBAC_PERM_COMMAND_CHARACTER_LEVEL, true, &HandleCharacterLevelCommand, "", },
|
||||
@@ -551,6 +552,86 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandleCharacterChangeAccountCommand(ChatHandler* handler, char const* args)
|
||||
{
|
||||
char* playerNameStr;
|
||||
char* accountNameStr;
|
||||
handler->extractOptFirstArg(const_cast<char*>(args), &playerNameStr, &accountNameStr);
|
||||
if (!accountNameStr)
|
||||
return false;
|
||||
|
||||
ObjectGuid targetGuid;
|
||||
std::string targetName;
|
||||
if (!handler->extractPlayerTarget(playerNameStr, nullptr, &targetGuid, &targetName))
|
||||
return false;
|
||||
|
||||
CharacterInfo const* characterInfo = sWorld->GetCharacterInfo(targetGuid);
|
||||
if (!characterInfo)
|
||||
{
|
||||
handler->SendSysMessage(LANG_PLAYER_NOT_FOUND);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32 oldAccountId = characterInfo->AccountId;
|
||||
uint32 newAccountId = oldAccountId;
|
||||
|
||||
std::string accountName(accountNameStr);
|
||||
if (!Utf8ToUpperOnlyLatin(accountName))
|
||||
{
|
||||
handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_ACCOUNT_ID_BY_NAME);
|
||||
stmt->setString(0, accountName);
|
||||
if (PreparedQueryResult result = LoginDatabase.Query(stmt))
|
||||
newAccountId = (*result)[0].GetUInt32();
|
||||
else
|
||||
{
|
||||
handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
// nothing to do :)
|
||||
if (newAccountId == oldAccountId)
|
||||
return true;
|
||||
|
||||
if (uint32 charCount = AccountMgr::GetCharactersCount(newAccountId))
|
||||
{
|
||||
if (charCount >= sWorld->getIntConfig(CONFIG_CHARACTERS_PER_REALM))
|
||||
{
|
||||
handler->PSendSysMessage(LANG_ACCOUNT_CHARACTER_LIST_FULL, accountName.c_str(), newAccountId);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_ACCOUNT_BY_GUID);
|
||||
stmt->setUInt32(0, newAccountId);
|
||||
stmt->setUInt32(1, targetGuid.GetCounter());
|
||||
CharacterDatabase.DirectExecute(stmt);
|
||||
|
||||
sWorld->UpdateRealmCharCount(oldAccountId);
|
||||
sWorld->UpdateRealmCharCount(newAccountId);
|
||||
|
||||
sWorld->UpdateCharacterInfoAccount(targetGuid, newAccountId);
|
||||
|
||||
handler->PSendSysMessage(LANG_CHANGEACCOUNT_SUCCESS, targetName.c_str(), accountName.c_str());
|
||||
|
||||
std::string logString = Trinity::StringFormat("changed ownership of player %s (%s) from account %u to account %u", targetName.c_str(), targetGuid.ToString().c_str(), oldAccountId, newAccountId);
|
||||
if (WorldSession* session = handler->GetSession())
|
||||
{
|
||||
if (Player* player = session->GetPlayer())
|
||||
sLog->outCommand(session->GetAccountId(), "GM %s (Account: %u) %s", player->GetName().c_str(), session->GetAccountId(), logString.c_str());
|
||||
}
|
||||
else
|
||||
sLog->outCommand(0, "%s %s", handler->GetTrinityString(LANG_CONSOLE), logString.c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandleCharacterReputationCommand(ChatHandler* handler, char const* args)
|
||||
{
|
||||
Player* target;
|
||||
|
||||
Reference in New Issue
Block a user