aboutsummaryrefslogtreecommitdiff
path: root/src/server/scripts
diff options
context:
space:
mode:
authorariel- <ariel-@users.noreply.github.com>2017-01-06 02:13:27 -0300
committerariel- <ariel-@users.noreply.github.com>2017-01-06 02:34:52 -0300
commitf7f865f81803effa17b19ef79762a72fe726b1ac (patch)
treef91afd183510df8e7584fbeb14e4659042bf2e2b /src/server/scripts
parent829deec2bdda228cbf0144bfe7c639a1c1c0ee09 (diff)
Core/Scripts: added command to move characters across accounts
Diffstat (limited to 'src/server/scripts')
-rw-r--r--src/server/scripts/Commands/cs_character.cpp81
1 files changed, 81 insertions, 0 deletions
diff --git a/src/server/scripts/Commands/cs_character.cpp b/src/server/scripts/Commands/cs_character.cpp
index be151cbaae0..d6b06882810 100644
--- a/src/server/scripts/Commands/cs_character.cpp
+++ b/src/server/scripts/Commands/cs_character.cpp
@@ -55,6 +55,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, "", },
@@ -549,6 +550,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;