diff options
-rw-r--r-- | src/server/scripts/Commands/cs_account.cpp | 412 |
1 files changed, 109 insertions, 303 deletions
diff --git a/src/server/scripts/Commands/cs_account.cpp b/src/server/scripts/Commands/cs_account.cpp index 64a781364b2..db34deb8c7b 100644 --- a/src/server/scripts/Commands/cs_account.cpp +++ b/src/server/scripts/Commands/cs_account.cpp @@ -34,6 +34,8 @@ EndScriptData */ #include "World.h" #include "WorldSession.h" +using namespace Trinity::ChatCommands; + class account_commandscript : public CommandScript { public: @@ -78,21 +80,9 @@ public: return commandTable; } - static bool HandleAccountAddonCommand(ChatHandler* handler, char const* args) + static bool HandleAccountAddonCommand(ChatHandler* handler, uint8 expansion) { - if (!*args) - { - handler->SendSysMessage(LANG_CMD_SYNTAX); - handler->SetSentErrorMessage(true); - return false; - } - - char* exp = strtok((char*)args, " "); - - uint32 accountId = handler->GetSession()->GetAccountId(); - - int expansion = atoi(exp); //get int anyway (0 if error) - if (expansion < 0 || uint8(expansion) > sWorld->getIntConfig(CONFIG_EXPANSION)) + if (expansion > sWorld->getIntConfig(CONFIG_EXPANSION)) { handler->SendSysMessage(LANG_IMPROPER_VALUE); handler->SetSentErrorMessage(true); @@ -101,8 +91,8 @@ public: LoginDatabasePreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_EXPANSION); - stmt->setUInt8(0, uint8(expansion)); - stmt->setUInt32(1, accountId); + stmt->setUInt8(0, expansion); + stmt->setUInt32(1, handler->GetSession()->GetAccountId()); LoginDatabase.Execute(stmt); @@ -111,31 +101,16 @@ public: } /// Create an account - static bool HandleAccountCreateCommand(ChatHandler* handler, char const* args) + static bool HandleAccountCreateCommand(ChatHandler* handler, std::string const& accountName, std::string const& password, Optional<std::string> const& email) { - if (!*args) - return false; - - std::string email; - - ///- %Parse the command line arguments - char* accountName = strtok((char*)args, " "); - char* password = strtok(nullptr, " "); - char* possibleEmail = strtok(nullptr, " ' "); - if (possibleEmail) - email = possibleEmail; - - if (!accountName || !password) - return false; - - if (strchr(accountName, '@')) + if (accountName.find('@') != std::string::npos) { handler->PSendSysMessage(LANG_ACCOUNT_USE_BNET_COMMANDS); handler->SetSentErrorMessage(true); return false; } - switch (sAccountMgr->CreateAccount(std::string(accountName), std::string(password), email)) + switch (sAccountMgr->CreateAccount(accountName, password, email.get_value_or(""))) { case AccountOpResult::AOR_OK: handler->PSendSysMessage(LANG_ACCOUNT_CREATED, accountName); @@ -144,7 +119,7 @@ public: TC_LOG_INFO("entities.player.character", "Account: %u (IP: %s) Character:[%s] (%s) created Account %s (Email: '%s')", handler->GetSession()->GetAccountId(), handler->GetSession()->GetRemoteAddress().c_str(), handler->GetSession()->GetPlayer()->GetName().c_str(), handler->GetSession()->GetPlayer()->GetGUID().ToString().c_str(), - accountName, email.c_str()); + accountName.c_str(), email.get_value_or("").c_str()); } break; case AccountOpResult::AOR_NAME_TOO_LONG: @@ -174,17 +149,8 @@ public: /// Delete a user account and all associated characters in this realm /// @todo This function has to be enhanced to respect the login/realm split (delete char, delete account chars in realm then delete account) - static bool HandleAccountDeleteCommand(ChatHandler* handler, char const* args) + static bool HandleAccountDeleteCommand(ChatHandler* handler, std::string accountName) { - if (!*args) - return false; - - ///- Get the account name from the command line - char* account = strtok((char*)args, " "); - if (!account) - return false; - - std::string accountName = account; if (!Utf8ToUpperOnlyLatin(accountName)) { handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str()); @@ -230,7 +196,7 @@ public: } /// Display info on users currently in the realm - static bool HandleAccountOnlineListCommand(ChatHandler* handler, char const* /*args*/) + static bool HandleAccountOnlineListCommand(ChatHandler* handler) { ///- Get the list of accounts ID logged to the realm PreparedQueryResult result = CharacterDatabase.Query(CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHARACTER_ONLINE)); @@ -276,108 +242,60 @@ public: return true; } - static bool HandleAccountLockCountryCommand(ChatHandler* handler, char const* args) + static bool HandleAccountLockCountryCommand(ChatHandler* handler, bool state) { - if (!*args) - { - handler->SendSysMessage(LANG_USE_BOL); - handler->SetSentErrorMessage(true); - return false; - } - std::string param = (char*)args; - - if (!param.empty()) + if (state) { - if (param == "on") - { - if (IpLocationRecord const* location = sIPLocation->GetLocationRecord(handler->GetSession()->GetRemoteAddress())) - { - LoginDatabasePreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_ACCOUNT_LOCK_COUNTRY); - stmt->setString(0, location->CountryCode); - stmt->setUInt32(1, handler->GetSession()->GetAccountId()); - LoginDatabase.Execute(stmt); - handler->PSendSysMessage(LANG_COMMAND_ACCLOCKLOCKED); - } - else - { - handler->PSendSysMessage("IP2Location] No information"); - TC_LOG_DEBUG("server.bnetserver", "IP2Location] No information"); - } - } - else if (param == "off") + if (IpLocationRecord const* location = sIPLocation->GetLocationRecord(handler->GetSession()->GetRemoteAddress())) { LoginDatabasePreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_ACCOUNT_LOCK_COUNTRY); - stmt->setString(0, "00"); + stmt->setString(0, location->CountryCode); stmt->setUInt32(1, handler->GetSession()->GetAccountId()); LoginDatabase.Execute(stmt); - handler->PSendSysMessage(LANG_COMMAND_ACCLOCKUNLOCKED); - } - return true; - } - handler->SendSysMessage(LANG_USE_BOL); - handler->SetSentErrorMessage(true); - return false; - } - - static bool HandleAccountLockIpCommand(ChatHandler* handler, char const* args) - { - if (!*args) - { - handler->SendSysMessage(LANG_USE_BOL); - handler->SetSentErrorMessage(true); - return false; - } - - std::string param = (char*)args; - - if (!param.empty()) - { - LoginDatabasePreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_ACCOUNT_LOCK); - - if (param == "on") - { - stmt->setBool(0, true); // locked handler->PSendSysMessage(LANG_COMMAND_ACCLOCKLOCKED); } - else if (param == "off") + else { - stmt->setBool(0, false); // unlocked - handler->PSendSysMessage(LANG_COMMAND_ACCLOCKUNLOCKED); + handler->PSendSysMessage("No IP2Location information - account not locked"); + handler->SetSentErrorMessage(true); + return false; } - + } + else + { + LoginDatabasePreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_ACCOUNT_LOCK_COUNTRY); + stmt->setString(0, "00"); stmt->setUInt32(1, handler->GetSession()->GetAccountId()); - LoginDatabase.Execute(stmt); - return true; + handler->PSendSysMessage(LANG_COMMAND_ACCLOCKUNLOCKED); } - - handler->SendSysMessage(LANG_USE_BOL); - handler->SetSentErrorMessage(true); - return false; + return true; } - static bool HandleAccountEmailCommand(ChatHandler* handler, char const* args) + static bool HandleAccountLockIpCommand(ChatHandler* handler, bool state) { - if (!*args) + LoginDatabasePreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_ACCOUNT_LOCK); + + if (state) { - handler->SendSysMessage(LANG_CMD_SYNTAX); - handler->SetSentErrorMessage(true); - return false; + stmt->setBool(0, true); // locked + handler->PSendSysMessage(LANG_COMMAND_ACCLOCKLOCKED); } - - char* oldEmail = strtok((char*)args, " "); - char* password = strtok(nullptr, " "); - char* email = strtok(nullptr, " "); - char* emailConfirmation = strtok(nullptr, " "); - - if (!oldEmail || !password || !email || !emailConfirmation) + else { - handler->SendSysMessage(LANG_CMD_SYNTAX); - handler->SetSentErrorMessage(true); - return false; + stmt->setBool(0, false); // unlocked + handler->PSendSysMessage(LANG_COMMAND_ACCLOCKUNLOCKED); } - if (!AccountMgr::CheckEmail(handler->GetSession()->GetAccountId(), std::string(oldEmail))) + stmt->setUInt32(1, handler->GetSession()->GetAccountId()); + + LoginDatabase.Execute(stmt); + return true; + } + + static bool HandleAccountEmailCommand(ChatHandler* handler, std::string const& oldEmail, std::string const& password, std::string const& email, std::string const& emailConfirm) + { + if (!AccountMgr::CheckEmail(handler->GetSession()->GetAccountId(), oldEmail)) { handler->SendSysMessage(LANG_COMMAND_WRONGEMAIL); sScriptMgr->OnFailedEmailChange(handler->GetSession()->GetAccountId()); @@ -385,11 +303,11 @@ public: TC_LOG_INFO("entities.player.character", "Account: %u (IP: %s) Character:[%s] (%s) Tried to change email, but the provided email [%s] is not equal to registration email [%s].", handler->GetSession()->GetAccountId(), handler->GetSession()->GetRemoteAddress().c_str(), handler->GetSession()->GetPlayer()->GetName().c_str(), handler->GetSession()->GetPlayer()->GetGUID().ToString().c_str(), - email, oldEmail); + email.c_str(), oldEmail.c_str()); return false; } - if (!AccountMgr::CheckPassword(handler->GetSession()->GetAccountId(), std::string(password))) + if (!AccountMgr::CheckPassword(handler->GetSession()->GetAccountId(), password)) { handler->SendSysMessage(LANG_COMMAND_WRONGOLDPASSWORD); sScriptMgr->OnFailedEmailChange(handler->GetSession()->GetAccountId()); @@ -400,7 +318,7 @@ public: return false; } - if (strcmp(email, oldEmail) == 0) + if (email == oldEmail) { handler->SendSysMessage(LANG_OLD_EMAIL_IS_NEW_EMAIL); sScriptMgr->OnFailedEmailChange(handler->GetSession()->GetAccountId()); @@ -408,19 +326,19 @@ public: return false; } - if (strcmp(email, emailConfirmation) != 0) + if (email != emailConfirm) { handler->SendSysMessage(LANG_NEW_EMAILS_NOT_MATCH); sScriptMgr->OnFailedEmailChange(handler->GetSession()->GetAccountId()); handler->SetSentErrorMessage(true); - TC_LOG_INFO("entities.player.character", "Account: %u (IP: %s) Character:[%s] (%s) Tried to change email, but the provided password is wrong.", + TC_LOG_INFO("entities.player.character", "Account: %u (IP: %s) Character:[%s] (%s) Tried to change email, but the confirm email does not match.", handler->GetSession()->GetAccountId(), handler->GetSession()->GetRemoteAddress().c_str(), handler->GetSession()->GetPlayer()->GetName().c_str(), handler->GetSession()->GetPlayer()->GetGUID().ToString().c_str()); return false; } - AccountOpResult result = AccountMgr::ChangeEmail(handler->GetSession()->GetAccountId(), std::string(email)); + AccountOpResult result = AccountMgr::ChangeEmail(handler->GetSession()->GetAccountId(), email); switch (result) { case AccountOpResult::AOR_OK: @@ -429,7 +347,7 @@ public: TC_LOG_INFO("entities.player.character", "Account: %u (IP: %s) Character:[%s] (%s) Changed Email from [%s] to [%s].", handler->GetSession()->GetAccountId(), handler->GetSession()->GetRemoteAddress().c_str(), handler->GetSession()->GetPlayer()->GetName().c_str(), handler->GetSession()->GetPlayer()->GetGUID().ToString().c_str(), - oldEmail, email); + oldEmail.c_str(), email.c_str()); break; case AccountOpResult::AOR_EMAIL_TOO_LONG: handler->SendSysMessage(LANG_EMAIL_TOO_LONG); @@ -445,37 +363,13 @@ public: return true; } - static bool HandleAccountPasswordCommand(ChatHandler* handler, char const* args) + static bool HandleAccountPasswordCommand(ChatHandler* handler, std::string const& oldPassword, std::string const& newPassword, std::string const& confirmPassword, Optional<std::string> const& confirmEmail) { - // If no args are given at all, we can return false right away. - if (!*args) - { - handler->SendSysMessage(LANG_CMD_SYNTAX); - handler->SetSentErrorMessage(true); - return false; - } - // First, we check config. What security type (sec type) is it ? Depending on it, the command branches out - uint32 pwConfig = sWorld->getIntConfig(CONFIG_ACC_PASSCHANGESEC); // 0 - PW_NONE, 1 - PW_EMAIL, 2 - PW_RBAC - - // Command is supposed to be: .account password [$oldpassword] [$newpassword] [$newpasswordconfirmation] [$emailconfirmation] - char* oldPassword = strtok((char*)args, " "); // This extracts [$oldpassword] - char* newPassword = strtok(nullptr, " "); // This extracts [$newpassword] - char* passwordConfirmation = strtok(nullptr, " "); // This extracts [$newpasswordconfirmation] - char const* emailConfirmation = strtok(nullptr, " "); // This defines the emailConfirmation variable, which is optional depending on sec type. - if (!emailConfirmation) // This extracts [$emailconfirmation]. If it doesn't exist, however... - emailConfirmation = ""; // ... it's simply "" for emailConfirmation. - - //Is any of those variables missing for any reason ? We return false. - if (!oldPassword || !newPassword || !passwordConfirmation) - { - handler->SendSysMessage(LANG_CMD_SYNTAX); - handler->SetSentErrorMessage(true); - return false; - } + uint32 const pwConfig = sWorld->getIntConfig(CONFIG_ACC_PASSCHANGESEC); // 0 - PW_NONE, 1 - PW_EMAIL, 2 - PW_RBAC // We compare the old, saved password to the entered old password - no chance for the unauthorized. - if (!AccountMgr::CheckPassword(handler->GetSession()->GetAccountId(), std::string(oldPassword))) + if (!AccountMgr::CheckPassword(handler->GetSession()->GetAccountId(), oldPassword)) { handler->SendSysMessage(LANG_COMMAND_WRONGOLDPASSWORD); sScriptMgr->OnFailedPasswordChange(handler->GetSession()->GetAccountId()); @@ -488,7 +382,7 @@ public: // This compares the old, current email to the entered email - however, only... if ((pwConfig == PW_EMAIL || (pwConfig == PW_RBAC && handler->HasPermission(rbac::RBAC_PERM_EMAIL_CONFIRM_FOR_PASS_CHANGE))) // ...if either PW_EMAIL or PW_RBAC with the Permission is active... - && !AccountMgr::CheckEmail(handler->GetSession()->GetAccountId(), std::string(emailConfirmation))) // ... and returns false if the comparison fails. + && !AccountMgr::CheckEmail(handler->GetSession()->GetAccountId(), confirmEmail.get_value_or(""))) // ... and returns false if the comparison fails. { handler->SendSysMessage(LANG_COMMAND_WRONGEMAIL); sScriptMgr->OnFailedPasswordChange(handler->GetSession()->GetAccountId()); @@ -496,12 +390,12 @@ public: TC_LOG_INFO("entities.player.character", "Account: %u (IP: %s) Character:[%s] (%s) Tried to change password, but the entered email [%s] is wrong.", handler->GetSession()->GetAccountId(), handler->GetSession()->GetRemoteAddress().c_str(), handler->GetSession()->GetPlayer()->GetName().c_str(), handler->GetSession()->GetPlayer()->GetGUID().ToString().c_str(), - emailConfirmation); + confirmEmail.get_value_or("").c_str()); return false; } // Making sure that newly entered password is correctly entered. - if (strcmp(newPassword, passwordConfirmation) != 0) + if (newPassword != confirmPassword) { handler->SendSysMessage(LANG_NEW_PASSWORDS_NOT_MATCH); sScriptMgr->OnFailedPasswordChange(handler->GetSession()->GetAccountId()); @@ -510,13 +404,13 @@ public: } // Changes password and prints result. - AccountOpResult result = AccountMgr::ChangePassword(handler->GetSession()->GetAccountId(), std::string(newPassword)); + AccountOpResult result = AccountMgr::ChangePassword(handler->GetSession()->GetAccountId(), newPassword); switch (result) { case AccountOpResult::AOR_OK: handler->SendSysMessage(LANG_COMMAND_PASSWORD); sScriptMgr->OnPasswordChange(handler->GetSession()->GetAccountId()); - TC_LOG_INFO("entities.player.character", "Account: %u (IP: %s) Character:[%s] (%s) Changed Password.", + TC_LOG_INFO("entities.player.character", "Account: %u (IP: %s) Character:[%s] (%s) changed cassword.", handler->GetSession()->GetAccountId(), handler->GetSession()->GetRemoteAddress().c_str(), handler->GetSession()->GetPlayer()->GetName().c_str(), handler->GetSession()->GetPlayer()->GetGUID().ToString().c_str()); break; @@ -534,7 +428,7 @@ public: return true; } - static bool HandleAccountCommand(ChatHandler* handler, char const* /*args*/) + static bool HandleAccountCommand(ChatHandler* handler) { // GM Level AccountTypes securityLevel = handler->GetSession()->GetSecurity(); @@ -546,8 +440,8 @@ public: handler->PSendSysMessage(LANG_ACCOUNT_SEC_TYPE, (pwConfig == PW_NONE ? "Lowest level: No Email input required." : pwConfig == PW_EMAIL ? "Highest level: Email input required." : - pwConfig == PW_RBAC ? "Special level: Your account may require email input depending on settings. That is the case if another lien is printed." : - "Unknown security level: Notify technician for details.")); + pwConfig == PW_RBAC ? "Special level: Your account may require email input depending on settings. That is the case if another line is printed." : + "Unknown security level: Config error?")); // RBAC required display - is not displayed for console if (pwConfig == PW_RBAC && handler->GetSession() && hasRBAC) @@ -574,47 +468,37 @@ public: } /// Set/Unset the expansion level for an account - static bool HandleAccountSetAddonCommand(ChatHandler* handler, char const* args) + static bool HandleAccountSetAddonCommand(ChatHandler* handler, Optional<std::string> accountName, uint8 expansion) { - ///- Get the command line arguments - char* account = strtok((char*)args, " "); - char* exp = strtok(nullptr, " "); - - if (!account) - return false; - - std::string accountName; uint32 accountId; - - if (!exp) - { - Player* player = handler->getSelectedPlayer(); - if (!player) - return false; - - accountId = player->GetSession()->GetAccountId(); - AccountMgr::GetName(accountId, accountName); - exp = account; - } - else + if (accountName) { ///- Convert Account name to Upper Format - accountName = account; - if (!Utf8ToUpperOnlyLatin(accountName)) + if (!Utf8ToUpperOnlyLatin(*accountName)) { - handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str()); + handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName->c_str()); handler->SetSentErrorMessage(true); return false; } - accountId = AccountMgr::GetId(accountName); + accountId = AccountMgr::GetId(*accountName); if (!accountId) { - handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str()); + handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName->c_str()); handler->SetSentErrorMessage(true); return false; } } + else + { + Player* player = handler->getSelectedPlayer(); + if (!player) + return false; + + accountId = player->GetSession()->GetAccountId(); + accountName.emplace(); + AccountMgr::GetName(accountId, *accountName); + } // Let set addon state only for lesser (strong) security level // or to self account @@ -622,7 +506,6 @@ public: handler->HasLowerSecurityAccount(nullptr, accountId, true)) return false; - uint8 expansion = static_cast<uint8>(atoul(exp)); if (expansion > sWorld->getIntConfig(CONFIG_EXPANSION)) return false; @@ -633,53 +516,33 @@ public: LoginDatabase.Execute(stmt); - handler->PSendSysMessage(LANG_ACCOUNT_SETADDON, accountName.c_str(), accountId, expansion); + handler->PSendSysMessage(LANG_ACCOUNT_SETADDON, accountName->c_str(), accountId, expansion); return true; } - static bool HandleAccountSetSecLevelCommand(ChatHandler* handler, char const* args) + static bool HandleAccountSetSecLevelCommand(ChatHandler* handler, Optional<std::string> accountName, uint8 securityLevel, int32 realmId) { - if (!*args) - { - handler->SendSysMessage(LANG_CMD_SYNTAX); - handler->SetSentErrorMessage(true); - return false; - } - - std::string accountName; - uint32 accountId = 0; - uint8 securityLevel = 0; - char* arg1 = strtok((char*)args, " "); - char* arg2 = strtok(nullptr, " "); - char* arg3 = strtok(nullptr, " "); - bool isAccountNameGiven = true; - - if (!arg3) - { - if (!handler->getSelectedPlayer()) - return false; - isAccountNameGiven = false; - } - - // Check for second parameter - if (!isAccountNameGiven && !arg2) - return false; - - // Check for account - if (isAccountNameGiven) + uint32 accountId; + if (accountName) { - accountName = arg1; - if (!Utf8ToUpperOnlyLatin(accountName) || !AccountMgr::GetId(accountName)) + if (!Utf8ToUpperOnlyLatin(*accountName) || !(accountId = AccountMgr::GetId(*accountName))) { - handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str()); + handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName->c_str()); handler->SetSentErrorMessage(true); return false; } } + else + { + Player* player = handler->getSelectedPlayer(); + if (!player) + return false; + accountId = player->GetSession()->GetAccountId(); + accountName.emplace(); + AccountMgr::GetName(accountId, *accountName); + } - // Check for invalid specified GM level. - securityLevel = (isAccountNameGiven) ? atoi(arg2) : atoi(arg1); - if (securityLevel > SEC_CONSOLE) + if (securityLevel >= SEC_CONSOLE) { handler->SendSysMessage(LANG_BAD_VALUE); handler->SetSentErrorMessage(true); @@ -687,17 +550,15 @@ public: } // handler->getSession() == nullptr only for console - accountId = (isAccountNameGiven) ? AccountMgr::GetId(accountName) : handler->getSelectedPlayer()->GetSession()->GetAccountId(); - int32 realmID = (isAccountNameGiven) ? atoi(arg3) : atoi(arg2); uint32 playerSecurity; if (handler->GetSession()) - playerSecurity = AccountMgr::GetSecurity(handler->GetSession()->GetAccountId(), realmID); + playerSecurity = AccountMgr::GetSecurity(handler->GetSession()->GetAccountId(), realmId); else playerSecurity = SEC_CONSOLE; // can set security level only for target with less security and to less security that we have // This also restricts setting handler's own security. - uint32 targetSecurity = AccountMgr::GetSecurity(accountId, realmID); + uint32 targetSecurity = AccountMgr::GetSecurity(accountId, realmId); if (targetSecurity >= playerSecurity || securityLevel >= playerSecurity) { handler->SendSysMessage(LANG_YOURS_SECURITY_IS_LOW); @@ -706,7 +567,7 @@ public: } // Check and abort if the target gm has a higher rank on one of the realms and the new realm is -1 - if (realmID == -1 && !AccountMgr::IsConsoleAccount(playerSecurity)) + if (realmId == -1 && !AccountMgr::IsConsoleAccount(playerSecurity)) { LoginDatabasePreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_ACCOUNT_ACCESS_SECLEVEL_TEST); @@ -724,39 +585,22 @@ public: } // Check if provided realmID has a negative value other than -1 - if (realmID < -1) + if (realmId < -1) { handler->SendSysMessage(LANG_INVALID_REALMID); handler->SetSentErrorMessage(true); return false; } - rbac::RBACData* rbac = isAccountNameGiven ? nullptr : handler->getSelectedPlayer()->GetSession()->GetRBACData(); - sAccountMgr->UpdateAccountAccess(rbac, accountId, securityLevel, realmID); + sAccountMgr->UpdateAccountAccess(nullptr, accountId, securityLevel, realmId); - handler->PSendSysMessage(LANG_YOU_CHANGE_SECURITY, accountName.c_str(), securityLevel); + handler->PSendSysMessage(LANG_YOU_CHANGE_SECURITY, accountName->c_str(), securityLevel); return true; } /// Set password for account - static bool HandleAccountSetPasswordCommand(ChatHandler* handler, char const* args) + static bool HandleAccountSetPasswordCommand(ChatHandler* handler, std::string accountName, std::string const& password, std::string const& confirmPassword) { - if (!*args) - { - handler->SendSysMessage(LANG_CMD_SYNTAX); - handler->SetSentErrorMessage(true); - return false; - } - - ///- Get the command line arguments - char* account = strtok((char*)args, " "); - char* password = strtok(nullptr, " "); - char* passwordConfirmation = strtok(nullptr, " "); - - if (!account || !password || !passwordConfirmation) - return false; - - std::string accountName = account; if (!Utf8ToUpperOnlyLatin(accountName)) { handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str()); @@ -777,7 +621,7 @@ public: if (handler->HasLowerSecurityAccount(nullptr, targetAccountId, true)) return false; - if (strcmp(password, passwordConfirmation) != 0) + if (password != confirmPassword) { handler->SendSysMessage(LANG_NEW_PASSWORDS_NOT_MATCH); handler->SetSentErrorMessage(true); @@ -785,7 +629,6 @@ public: } AccountOpResult result = AccountMgr::ChangePassword(targetAccountId, password); - switch (result) { case AccountOpResult::AOR_OK: @@ -808,24 +651,8 @@ public: } /// Set normal email for account - static bool HandleAccountSetEmailCommand(ChatHandler* handler, char const* args) + static bool HandleAccountSetEmailCommand(ChatHandler* handler, std::string accountName, std::string const& email, std::string const& confirmEmail) { - if (!*args) - return false; - - ///- Get the command line arguments - char* account = strtok((char*)args, " "); - char* email = strtok(nullptr, " "); - char* emailConfirmation = strtok(nullptr, " "); - - if (!account || !email || !emailConfirmation) - { - handler->SendSysMessage(LANG_CMD_SYNTAX); - handler->SetSentErrorMessage(true); - return false; - } - - std::string accountName = account; if (!Utf8ToUpperOnlyLatin(accountName)) { handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str()); @@ -846,7 +673,7 @@ public: if (handler->HasLowerSecurityAccount(nullptr, targetAccountId, true)) return false; - if (strcmp(email, emailConfirmation) != 0) + if (email != confirmEmail) { handler->SendSysMessage(LANG_NEW_EMAILS_NOT_MATCH); handler->SetSentErrorMessage(true); @@ -859,7 +686,7 @@ public: case AccountOpResult::AOR_OK: handler->SendSysMessage(LANG_COMMAND_EMAIL); TC_LOG_INFO("entities.player.character", "ChangeEmail: Account %s [Id: %u] had it's email changed to %s.", - accountName.c_str(), targetAccountId, email); + accountName.c_str(), targetAccountId, email.c_str()); break; case AccountOpResult::AOR_NAME_NOT_EXIST: handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str()); @@ -879,29 +706,8 @@ public: } /// Change registration email for account - static bool HandleAccountSetRegEmailCommand(ChatHandler* handler, char const* args) + static bool HandleAccountSetRegEmailCommand(ChatHandler* handler, std::string accountName, std::string const& email, std::string const& confirmEmail) { - if (!*args) - return false; - - //- We do not want anything short of console to use this by default. - //- So we force that. - if (handler->GetSession()) - return false; - - ///- Get the command line arguments - char* account = strtok((char*)args, " "); - char* email = strtok(nullptr, " "); - char* emailConfirmation = strtok(nullptr, " "); - - if (!account || !email || !emailConfirmation) - { - handler->SendSysMessage(LANG_CMD_SYNTAX); - handler->SetSentErrorMessage(true); - return false; - } - - std::string accountName = account; if (!Utf8ToUpperOnlyLatin(accountName)) { handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str()); @@ -922,7 +728,7 @@ public: if (handler->HasLowerSecurityAccount(nullptr, targetAccountId, true)) return false; - if (strcmp(email, emailConfirmation) != 0) + if (email != confirmEmail) { handler->SendSysMessage(LANG_NEW_EMAILS_NOT_MATCH); handler->SetSentErrorMessage(true); @@ -935,7 +741,7 @@ public: case AccountOpResult::AOR_OK: handler->SendSysMessage(LANG_COMMAND_EMAIL); TC_LOG_INFO("entities.player.character", "ChangeRegEmail: Account %s [Id: %u] had it's Registration Email changed to %s.", - accountName.c_str(), targetAccountId, email); + accountName.c_str(), targetAccountId, email.c_str()); break; case AccountOpResult::AOR_NAME_NOT_EXIST: handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str()); |