Core/Misc: ported cryptography updates and all that entrails from 335/master and killed bnetserver
This commit is contained in:
1 parent
a576c8328b
commit
64b77e359d
413 files changed
+8953
-56006
No files matched your search
@@ -23,7 +23,10 @@ Category: commandscripts
|
||||
EndScriptData */
|
||||
|
||||
#include "AccountMgr.h"
|
||||
#include "AES.h"
|
||||
#include "Base32.h"
|
||||
#include "Chat.h"
|
||||
#include "CryptoGenerics.h"
|
||||
#include "DatabaseEnv.h"
|
||||
#include "IpAddress.h"
|
||||
#include "IPLocation.h"
|
||||
@@ -31,8 +34,12 @@ EndScriptData */
|
||||
#include "Log.h"
|
||||
#include "Player.h"
|
||||
#include "ScriptMgr.h"
|
||||
#include "SecretMgr.h"
|
||||
#include "TOTP.h"
|
||||
#include "World.h"
|
||||
#include "WorldSession.h"
|
||||
#include <unordered_map>
|
||||
#include <openssl/rand.h>
|
||||
|
||||
using namespace Trinity::ChatCommands;
|
||||
|
||||
@@ -54,6 +61,12 @@ public:
|
||||
{ "sec", rbac::RBAC_PERM_COMMAND_ACCOUNT_SET_SEC, true, nullptr, "", accountSetSecTable },
|
||||
{ "gmlevel", rbac::RBAC_PERM_COMMAND_ACCOUNT_SET_GMLEVEL, true, &HandleAccountSetGmLevelCommand, "" },
|
||||
{ "password", rbac::RBAC_PERM_COMMAND_ACCOUNT_SET_PASSWORD, true, &HandleAccountSetPasswordCommand, "" },
|
||||
{ "2fa", rbac::RBAC_PERM_COMMAND_ACCOUNT_SET_2FA, true, &HandleAccountSet2FACommand, "" },
|
||||
};
|
||||
static std::vector<ChatCommand> account2FACommandTable =
|
||||
{
|
||||
{ "setup", rbac::RBAC_PERM_COMMAND_ACCOUNT_2FA_SETUP, false, &HandleAccount2FASetupCommand, "" },
|
||||
{ "remove", rbac::RBAC_PERM_COMMAND_ACCOUNT_2FA_REMOVE, false, &HandleAccount2FARemoveCommand, "" },
|
||||
};
|
||||
static std::vector<ChatCommand> accountLockCommandTable =
|
||||
{
|
||||
@@ -62,6 +75,7 @@ public:
|
||||
};
|
||||
static std::vector<ChatCommand> accountCommandTable =
|
||||
{
|
||||
{ "2fa", rbac::RBAC_PERM_COMMAND_ACCOUNT_2FA, false, nullptr, "", account2FACommandTable },
|
||||
{ "addon", rbac::RBAC_PERM_COMMAND_ACCOUNT_ADDON, false, &HandleAccountAddonCommand, "" },
|
||||
{ "create", rbac::RBAC_PERM_COMMAND_ACCOUNT_CREATE, true, &HandleAccountCreateCommand, "" },
|
||||
{ "delete", rbac::RBAC_PERM_COMMAND_ACCOUNT_DELETE, true, &HandleAccountDeleteCommand, "" },
|
||||
@@ -79,6 +93,138 @@ public:
|
||||
return commandTable;
|
||||
}
|
||||
|
||||
static bool HandleAccount2FASetupCommand(ChatHandler* handler, Optional<uint32> token)
|
||||
{
|
||||
auto const& masterKey = sSecretMgr->GetSecret(SECRET_TOTP_MASTER_KEY);
|
||||
if (!masterKey.IsAvailable())
|
||||
{
|
||||
handler->SendSysMessage(LANG_2FA_COMMANDS_NOT_SETUP);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32 const accountId = handler->GetSession()->GetAccountId();
|
||||
|
||||
{ // check if 2FA already enabled
|
||||
LoginDatabasePreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_ACCOUNT_TOTP_SECRET);
|
||||
stmt->setUInt32(0, accountId);
|
||||
PreparedQueryResult result = LoginDatabase.Query(stmt);
|
||||
|
||||
if (!result)
|
||||
{
|
||||
TC_LOG_ERROR("misc", "Account %u not found in login database when processing .account 2fa setup command.", accountId);
|
||||
handler->SendSysMessage(LANG_UNKNOWN_ERROR);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!result->Fetch()->IsNull())
|
||||
{
|
||||
handler->SendSysMessage(LANG_2FA_ALREADY_SETUP);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// store random suggested secrets
|
||||
static std::unordered_map<uint32, Trinity::Crypto::TOTP::Secret> suggestions;
|
||||
auto pair = suggestions.emplace(std::piecewise_construct, std::make_tuple(accountId), std::make_tuple(Trinity::Crypto::TOTP::RECOMMENDED_SECRET_LENGTH)); // std::vector 1-argument size_t constructor invokes resize
|
||||
if (pair.second) // no suggestion yet, generate random secret
|
||||
RAND_bytes(pair.first->second.data(), pair.first->second.size());
|
||||
|
||||
if (!pair.second && token) // suggestion already existed and token specified - validate
|
||||
{
|
||||
if (Trinity::Crypto::TOTP::ValidateToken(pair.first->second, *token))
|
||||
{
|
||||
if (masterKey)
|
||||
Trinity::Crypto::AEEncryptWithRandomIV<Trinity::Crypto::AES>(pair.first->second, *masterKey);
|
||||
|
||||
LoginDatabasePreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_ACCOUNT_TOTP_SECRET);
|
||||
stmt->setBinary(0, pair.first->second);
|
||||
stmt->setUInt32(1, accountId);
|
||||
LoginDatabase.Execute(stmt);
|
||||
suggestions.erase(pair.first);
|
||||
handler->SendSysMessage(LANG_2FA_SETUP_COMPLETE);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
handler->SendSysMessage(LANG_2FA_INVALID_TOKEN);
|
||||
}
|
||||
|
||||
// new suggestion, or no token specified, output TOTP parameters
|
||||
handler->PSendSysMessage(LANG_2FA_SECRET_SUGGESTION, Trinity::Encoding::Base32::Encode(pair.first->second));
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool HandleAccount2FARemoveCommand(ChatHandler* handler, Optional<uint32> token)
|
||||
{
|
||||
auto const& masterKey = sSecretMgr->GetSecret(SECRET_TOTP_MASTER_KEY);
|
||||
if (!masterKey.IsAvailable())
|
||||
{
|
||||
handler->SendSysMessage(LANG_2FA_COMMANDS_NOT_SETUP);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32 const accountId = handler->GetSession()->GetAccountId();
|
||||
Trinity::Crypto::TOTP::Secret secret;
|
||||
{ // get current TOTP secret
|
||||
LoginDatabasePreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_ACCOUNT_TOTP_SECRET);
|
||||
stmt->setUInt32(0, accountId);
|
||||
PreparedQueryResult result = LoginDatabase.Query(stmt);
|
||||
|
||||
if (!result)
|
||||
{
|
||||
TC_LOG_ERROR("misc", "Account %u not found in login database when processing .account 2fa setup command.", accountId);
|
||||
handler->SendSysMessage(LANG_UNKNOWN_ERROR);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
Field* field = result->Fetch();
|
||||
if (field->IsNull())
|
||||
{ // 2FA not enabled
|
||||
handler->SendSysMessage(LANG_2FA_NOT_SETUP);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
secret = field->GetBinary();
|
||||
}
|
||||
|
||||
if (token)
|
||||
{
|
||||
if (masterKey)
|
||||
{
|
||||
bool success = Trinity::Crypto::AEDecrypt<Trinity::Crypto::AES>(secret, *masterKey);
|
||||
if (!success)
|
||||
{
|
||||
TC_LOG_ERROR("misc", "Account %u has invalid ciphertext in TOTP token.", accountId);
|
||||
handler->SendSysMessage(LANG_UNKNOWN_ERROR);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (Trinity::Crypto::TOTP::ValidateToken(secret, *token))
|
||||
{
|
||||
LoginDatabasePreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_ACCOUNT_TOTP_SECRET);
|
||||
stmt->setNull(0);
|
||||
stmt->setUInt32(1, accountId);
|
||||
LoginDatabase.Execute(stmt);
|
||||
handler->SendSysMessage(LANG_2FA_REMOVE_COMPLETE);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
handler->SendSysMessage(LANG_2FA_INVALID_TOKEN);
|
||||
}
|
||||
|
||||
handler->SendSysMessage(LANG_2FA_REMOVE_NEED_TOKEN);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool HandleAccountAddonCommand(ChatHandler* handler, uint8 expansion)
|
||||
{
|
||||
if (expansion > sWorld->getIntConfig(CONFIG_EXPANSION))
|
||||
@@ -658,6 +804,69 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandleAccountSet2FACommand(ChatHandler* handler, std::string accountName, std::string secret)
|
||||
{
|
||||
if (!Utf8ToUpperOnlyLatin(accountName))
|
||||
{
|
||||
handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32 targetAccountId = AccountMgr::GetId(accountName);
|
||||
if (!targetAccountId)
|
||||
{
|
||||
handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (handler->HasLowerSecurityAccount(nullptr, targetAccountId, true))
|
||||
return false;
|
||||
|
||||
if (secret == "off")
|
||||
{
|
||||
LoginDatabasePreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_ACCOUNT_TOTP_SECRET);
|
||||
stmt->setNull(0);
|
||||
stmt->setUInt32(1, targetAccountId);
|
||||
LoginDatabase.Execute(stmt);
|
||||
handler->PSendSysMessage(LANG_2FA_REMOVE_COMPLETE);
|
||||
return true;
|
||||
}
|
||||
|
||||
auto const& masterKey = sSecretMgr->GetSecret(SECRET_TOTP_MASTER_KEY);
|
||||
if (!masterKey.IsAvailable())
|
||||
{
|
||||
handler->SendSysMessage(LANG_2FA_COMMANDS_NOT_SETUP);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
Optional<std::vector<uint8>> decoded = Trinity::Encoding::Base32::Decode(secret);
|
||||
if (!decoded)
|
||||
{
|
||||
handler->SendSysMessage(LANG_2FA_SECRET_INVALID);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
if (128 < (decoded->size() + Trinity::Crypto::AES::IV_SIZE_BYTES + Trinity::Crypto::AES::TAG_SIZE_BYTES))
|
||||
{
|
||||
handler->SendSysMessage(LANG_2FA_SECRET_TOO_LONG);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (masterKey)
|
||||
Trinity::Crypto::AEEncryptWithRandomIV<Trinity::Crypto::AES>(*decoded, *masterKey);
|
||||
|
||||
LoginDatabasePreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_ACCOUNT_TOTP_SECRET);
|
||||
stmt->setBinary(0, *decoded);
|
||||
stmt->setUInt32(1, targetAccountId);
|
||||
LoginDatabase.Execute(stmt);
|
||||
handler->PSendSysMessage(LANG_2FA_SECRET_SET_COMPLETE, accountName.c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Set normal email for account
|
||||
static bool HandleAccountSetEmailCommand(ChatHandler* handler, std::string accountName, std::string const& email, std::string const& confirmEmail)
|
||||
{
|
||||
|
||||
@@ -1,506 +0,0 @@
|
||||
/*
|
||||
* This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "AccountMgr.h"
|
||||
#include "BattlenetAccountMgr.h"
|
||||
#include "BigNumber.h"
|
||||
#include "Chat.h"
|
||||
#include "DatabaseEnv.h"
|
||||
#include "IpAddress.h"
|
||||
#include "IPLocation.h"
|
||||
#include "Language.h"
|
||||
#include "Log.h"
|
||||
#include "Player.h"
|
||||
#include "ScriptMgr.h"
|
||||
#include "Util.h"
|
||||
#include "WorldSession.h"
|
||||
|
||||
class battlenet_account_commandscript : public CommandScript
|
||||
{
|
||||
public:
|
||||
battlenet_account_commandscript() : CommandScript("battlenet_account_commandscript") { }
|
||||
|
||||
std::vector<ChatCommand> GetCommands() const override
|
||||
{
|
||||
static std::vector<ChatCommand> accountSetCommandTable =
|
||||
{
|
||||
{ "password", rbac::RBAC_PERM_COMMAND_BNET_ACCOUNT_SET_PASSWORD, true, &HandleAccountSetPasswordCommand, "" },
|
||||
};
|
||||
|
||||
static std::vector<ChatCommand> accountLockCommandTable =
|
||||
{
|
||||
{ "country", rbac::RBAC_PERM_COMMAND_BNET_ACCOUNT_LOCK_COUNTRY, true, &HandleAccountLockCountryCommand, "" },
|
||||
{ "ip", rbac::RBAC_PERM_COMMAND_BNET_ACCOUNT_LOCK_IP, true, &HandleAccountLockIpCommand, "" },
|
||||
};
|
||||
|
||||
static std::vector<ChatCommand> accountCommandTable =
|
||||
{
|
||||
{ "create", rbac::RBAC_PERM_COMMAND_BNET_ACCOUNT_CREATE, true, &HandleAccountCreateCommand, "" },
|
||||
{ "gameaccountcreate", rbac::RBAC_PERM_COMMAND_BNET_ACCOUNT_CREATE_GAME, true, &HandleGameAccountCreateCommand, "", },
|
||||
{ "lock", rbac::RBAC_PERM_COMMAND_BNET_ACCOUNT, false, nullptr, "", accountLockCommandTable },
|
||||
{ "set", rbac::RBAC_PERM_COMMAND_BNET_ACCOUNT_SET, true, nullptr, "", accountSetCommandTable },
|
||||
{ "password", rbac::RBAC_PERM_COMMAND_BNET_ACCOUNT_PASSWORD, false, &HandleAccountPasswordCommand, "" },
|
||||
{ "link", rbac::RBAC_PERM_COMMAND_BNET_ACCOUNT_LINK, true, &HandleAccountLinkCommand, "", },
|
||||
{ "unlink", rbac::RBAC_PERM_COMMAND_BNET_ACCOUNT_UNLINK, true, &HandleAccountUnlinkCommand, "", },
|
||||
{ "listgameaccounts", rbac::RBAC_PERM_COMMAND_BNET_ACCOUNT_LIST_GAME_ACCOUNTS, true, &HandleListGameAccountsCommand, "" }
|
||||
};
|
||||
|
||||
static std::vector<ChatCommand> commandTable =
|
||||
{
|
||||
{ "bnetaccount", rbac::RBAC_PERM_COMMAND_BNET_ACCOUNT, true, nullptr, "", accountCommandTable },
|
||||
};
|
||||
|
||||
return commandTable;
|
||||
}
|
||||
|
||||
/// Create an account
|
||||
static bool HandleAccountCreateCommand(ChatHandler* handler, char const* args)
|
||||
{
|
||||
if (!*args)
|
||||
return false;
|
||||
|
||||
///- %Parse the command line arguments
|
||||
char* accountName = strtok((char*)args, " ");
|
||||
char* password = strtok(nullptr, " ");
|
||||
if (!accountName || !password)
|
||||
return false;
|
||||
|
||||
if (!strchr(accountName, '@'))
|
||||
{
|
||||
handler->SendSysMessage(LANG_ACCOUNT_INVALID_BNET_NAME);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
char* createGameAccountParam = strtok(nullptr, " ");
|
||||
bool createGameAccount = true;
|
||||
if (createGameAccountParam)
|
||||
createGameAccount = StringToBool(createGameAccountParam);
|
||||
|
||||
std::string gameAccountName;
|
||||
switch (Battlenet::AccountMgr::CreateBattlenetAccount(std::string(accountName), std::string(password), createGameAccount, &gameAccountName))
|
||||
{
|
||||
case AccountOpResult::AOR_OK:
|
||||
{
|
||||
if (createGameAccount)
|
||||
handler->PSendSysMessage(LANG_ACCOUNT_CREATED_BNET_WITH_GAME, accountName, gameAccountName.c_str());
|
||||
else
|
||||
handler->PSendSysMessage(LANG_ACCOUNT_CREATED_BNET, accountName);
|
||||
|
||||
if (handler->GetSession())
|
||||
{
|
||||
TC_LOG_INFO("entities.player.character", "Account: %u (IP: %s) Character:[%s] (%s) created Battle.net account %s%s%s",
|
||||
handler->GetSession()->GetAccountId(), handler->GetSession()->GetRemoteAddress().c_str(),
|
||||
handler->GetSession()->GetPlayer()->GetName().c_str(), handler->GetSession()->GetPlayer()->GetGUID().ToString().c_str(),
|
||||
accountName, createGameAccount ? " with game account " : "", createGameAccount ? gameAccountName.c_str() : "");
|
||||
}
|
||||
break;
|
||||
}
|
||||
case AccountOpResult::AOR_NAME_TOO_LONG:
|
||||
handler->SendSysMessage(LANG_ACCOUNT_NAME_TOO_LONG);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
case AccountOpResult::AOR_PASS_TOO_LONG:
|
||||
handler->SendSysMessage(LANG_PASSWORD_TOO_LONG);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
case AccountOpResult::AOR_NAME_ALREADY_EXIST:
|
||||
handler->SendSysMessage(LANG_ACCOUNT_ALREADY_EXIST);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Sets country lock on own account
|
||||
static bool HandleAccountLockCountryCommand(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())
|
||||
{
|
||||
if (param == "on")
|
||||
{
|
||||
if (IpLocationRecord const* location = sIPLocation->GetLocationRecord(handler->GetSession()->GetRemoteAddress()))
|
||||
{
|
||||
LoginDatabasePreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_BNET_ACCOUNT_LOCK_COUNTRY);
|
||||
stmt->setString(0, location->CountryCode);
|
||||
stmt->setUInt32(1, handler->GetSession()->GetBattlenetAccountId());
|
||||
LoginDatabase.Execute(stmt);
|
||||
handler->PSendSysMessage(LANG_COMMAND_ACCLOCKLOCKED);
|
||||
}
|
||||
else
|
||||
{
|
||||
handler->PSendSysMessage("IP2Location] No information");
|
||||
TC_LOG_DEBUG("server.authserver", "IP2Location] No information");
|
||||
}
|
||||
}
|
||||
else if (param == "off")
|
||||
{
|
||||
LoginDatabasePreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_BNET_ACCOUNT_LOCK_COUNTRY);
|
||||
stmt->setString(0, "00");
|
||||
stmt->setUInt32(1, handler->GetSession()->GetBattlenetAccountId());
|
||||
LoginDatabase.Execute(stmt);
|
||||
handler->PSendSysMessage(LANG_COMMAND_ACCLOCKUNLOCKED);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
handler->SendSysMessage(LANG_USE_BOL);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Sets ip lock on own account
|
||||
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_BNET_ACCOUNT_LOCK);
|
||||
|
||||
if (param == "on")
|
||||
{
|
||||
stmt->setBool(0, true); // locked
|
||||
handler->PSendSysMessage(LANG_COMMAND_ACCLOCKLOCKED);
|
||||
}
|
||||
else if (param == "off")
|
||||
{
|
||||
stmt->setBool(0, false); // unlocked
|
||||
handler->PSendSysMessage(LANG_COMMAND_ACCLOCKUNLOCKED);
|
||||
}
|
||||
|
||||
stmt->setUInt32(1, handler->GetSession()->GetBattlenetAccountId());
|
||||
|
||||
LoginDatabase.Execute(stmt);
|
||||
return true;
|
||||
}
|
||||
|
||||
handler->SendSysMessage(LANG_USE_BOL);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool HandleAccountPasswordCommand(ChatHandler* handler, char const* args)
|
||||
{
|
||||
// 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;
|
||||
}
|
||||
|
||||
// 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]
|
||||
|
||||
//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;
|
||||
}
|
||||
|
||||
// We compare the old, saved password to the entered old password - no chance for the unauthorized.
|
||||
if (!Battlenet::AccountMgr::CheckPassword(handler->GetSession()->GetBattlenetAccountId(), std::string(oldPassword)))
|
||||
{
|
||||
handler->SendSysMessage(LANG_COMMAND_WRONGOLDPASSWORD);
|
||||
handler->SetSentErrorMessage(true);
|
||||
TC_LOG_INFO("entities.player.character", "Battle.net account: %u (IP: %s) Character:[%s] (GUID: %u) Tried to change password, but the provided old password is wrong.",
|
||||
handler->GetSession()->GetBattlenetAccountId(), handler->GetSession()->GetRemoteAddress().c_str(),
|
||||
handler->GetSession()->GetPlayer()->GetName().c_str(), handler->GetSession()->GetPlayer()->GetGUID().GetCounter());
|
||||
return false;
|
||||
}
|
||||
|
||||
// Making sure that newly entered password is correctly entered.
|
||||
if (strcmp(newPassword, passwordConfirmation) != 0)
|
||||
{
|
||||
handler->SendSysMessage(LANG_NEW_PASSWORDS_NOT_MATCH);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Changes password and prints result.
|
||||
AccountOpResult result = Battlenet::AccountMgr::ChangePassword(handler->GetSession()->GetBattlenetAccountId(), std::string(newPassword));
|
||||
switch (result)
|
||||
{
|
||||
case AccountOpResult::AOR_OK:
|
||||
handler->SendSysMessage(LANG_COMMAND_PASSWORD);
|
||||
TC_LOG_INFO("entities.player.character", "Battle.net account: %u (IP: %s) Character:[%s] (GUID: %u) Changed Password.",
|
||||
handler->GetSession()->GetBattlenetAccountId(), handler->GetSession()->GetRemoteAddress().c_str(),
|
||||
handler->GetSession()->GetPlayer()->GetName().c_str(), handler->GetSession()->GetPlayer()->GetGUID().GetCounter());
|
||||
break;
|
||||
case AccountOpResult::AOR_PASS_TOO_LONG:
|
||||
handler->SendSysMessage(LANG_PASSWORD_TOO_LONG);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
default:
|
||||
handler->SendSysMessage(LANG_COMMAND_NOTCHANGEPASSWORD);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Set password for account
|
||||
static bool HandleAccountSetPasswordCommand(ChatHandler* handler, char const* args)
|
||||
{
|
||||
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());
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32 targetAccountId = Battlenet::AccountMgr::GetId(accountName);
|
||||
if (!targetAccountId)
|
||||
{
|
||||
handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (strcmp(password, passwordConfirmation))
|
||||
{
|
||||
handler->SendSysMessage(LANG_NEW_PASSWORDS_NOT_MATCH);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
AccountOpResult result = Battlenet::AccountMgr::ChangePassword(targetAccountId, password);
|
||||
|
||||
switch (result)
|
||||
{
|
||||
case AccountOpResult::AOR_OK:
|
||||
handler->SendSysMessage(LANG_COMMAND_PASSWORD);
|
||||
break;
|
||||
case AccountOpResult::AOR_NAME_NOT_EXIST:
|
||||
handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
case AccountOpResult::AOR_PASS_TOO_LONG:
|
||||
handler->SendSysMessage(LANG_PASSWORD_TOO_LONG);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandleAccountLinkCommand(ChatHandler* handler, char const* args)
|
||||
{
|
||||
Tokenizer tokens(args, ' ', 2);
|
||||
if (tokens.size() != 2)
|
||||
{
|
||||
handler->SendSysMessage(LANG_CMD_SYNTAX);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string bnetAccountName = tokens[0];
|
||||
std::string gameAccountName = tokens[1];
|
||||
|
||||
switch (Battlenet::AccountMgr::LinkWithGameAccount(bnetAccountName, gameAccountName))
|
||||
{
|
||||
case AccountOpResult::AOR_OK:
|
||||
handler->PSendSysMessage(LANG_ACCOUNT_BNET_LINKED, bnetAccountName.c_str(), gameAccountName.c_str());
|
||||
break;
|
||||
case AccountOpResult::AOR_NAME_NOT_EXIST:
|
||||
handler->PSendSysMessage(LANG_ACCOUNT_OR_BNET_DOES_NOT_EXIST, bnetAccountName.c_str(), gameAccountName.c_str());
|
||||
handler->SetSentErrorMessage(true);
|
||||
break;
|
||||
case AccountOpResult::AOR_ACCOUNT_BAD_LINK:
|
||||
handler->PSendSysMessage(LANG_ACCOUNT_ALREADY_LINKED, gameAccountName.c_str());
|
||||
handler->SetSentErrorMessage(true);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandleAccountUnlinkCommand(ChatHandler* handler, char const* args)
|
||||
{
|
||||
if (!*args)
|
||||
{
|
||||
handler->SendSysMessage(LANG_CMD_SYNTAX);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string gameAccountName = args;
|
||||
|
||||
switch (Battlenet::AccountMgr::UnlinkGameAccount(gameAccountName))
|
||||
{
|
||||
case AccountOpResult::AOR_OK:
|
||||
handler->PSendSysMessage(LANG_ACCOUNT_BNET_UNLINKED, gameAccountName.c_str());
|
||||
break;
|
||||
case AccountOpResult::AOR_NAME_NOT_EXIST:
|
||||
handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, gameAccountName.c_str());
|
||||
handler->SetSentErrorMessage(true);
|
||||
break;
|
||||
case AccountOpResult::AOR_ACCOUNT_BAD_LINK:
|
||||
handler->PSendSysMessage(LANG_ACCOUNT_BNET_NOT_LINKED, gameAccountName.c_str());
|
||||
handler->SetSentErrorMessage(true);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandleGameAccountCreateCommand(ChatHandler* handler, char const* args)
|
||||
{
|
||||
if (!*args)
|
||||
{
|
||||
handler->SendSysMessage(LANG_CMD_SYNTAX);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string bnetAccountName = args;
|
||||
uint32 accountId = Battlenet::AccountMgr::GetId(bnetAccountName);
|
||||
if (!accountId)
|
||||
{
|
||||
handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, bnetAccountName.c_str());
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8 index = Battlenet::AccountMgr::GetMaxIndex(accountId) + 1;
|
||||
std::string accountName = std::to_string(accountId) + '#' + std::to_string(uint32(index));
|
||||
|
||||
// Generate random hex string for password, these accounts must not be logged on with GRUNT
|
||||
BigNumber randPassword;
|
||||
randPassword.SetRand(8 * 16);
|
||||
|
||||
switch (sAccountMgr->CreateAccount(accountName, ByteArrayToHexStr(randPassword.AsByteArray().get(), randPassword.GetNumBytes()), bnetAccountName, accountId, index))
|
||||
{
|
||||
case AccountOpResult::AOR_OK:
|
||||
handler->PSendSysMessage(LANG_ACCOUNT_CREATED, accountName.c_str());
|
||||
if (handler->GetSession())
|
||||
{
|
||||
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.c_str(), bnetAccountName.c_str());
|
||||
}
|
||||
break;
|
||||
case AccountOpResult::AOR_NAME_TOO_LONG:
|
||||
handler->SendSysMessage(LANG_ACCOUNT_NAME_TOO_LONG);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
case AccountOpResult::AOR_PASS_TOO_LONG:
|
||||
handler->SendSysMessage(LANG_ACCOUNT_PASS_TOO_LONG);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
case AccountOpResult::AOR_NAME_ALREADY_EXIST:
|
||||
handler->SendSysMessage(LANG_ACCOUNT_ALREADY_EXIST);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
case AccountOpResult::AOR_DB_INTERNAL_ERROR:
|
||||
handler->PSendSysMessage(LANG_ACCOUNT_NOT_CREATED_SQL_ERROR, accountName.c_str());
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
default:
|
||||
handler->PSendSysMessage(LANG_ACCOUNT_NOT_CREATED, accountName.c_str());
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandleListGameAccountsCommand(ChatHandler* handler, char const* args)
|
||||
{
|
||||
if (!*args)
|
||||
return false;
|
||||
|
||||
char* battlenetAccountName = strtok((char*)args, " ");
|
||||
LoginDatabasePreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_BNET_GAME_ACCOUNT_LIST);
|
||||
stmt->setString(0, battlenetAccountName);
|
||||
if (PreparedQueryResult accountList = LoginDatabase.Query(stmt))
|
||||
{
|
||||
auto formatDisplayName = [](char const* name) -> std::string
|
||||
{
|
||||
if (char const* hashPos = strchr(name, '#'))
|
||||
return std::string("WoW") + ++hashPos;
|
||||
else
|
||||
return name;
|
||||
};
|
||||
|
||||
handler->SendSysMessage("----------------------------------------------------");
|
||||
handler->SendSysMessage(LANG_ACCOUNT_BNET_LIST_HEADER);
|
||||
handler->SendSysMessage("----------------------------------------------------");
|
||||
do
|
||||
{
|
||||
Field* fields = accountList->Fetch();
|
||||
handler->PSendSysMessage("| %10u | %-16.16s | %-16.16s |", fields[0].GetUInt32(), fields[1].GetCString(), formatDisplayName(fields[1].GetCString()).c_str());
|
||||
} while (accountList->NextRow());
|
||||
handler->SendSysMessage("----------------------------------------------------");
|
||||
}
|
||||
else
|
||||
handler->PSendSysMessage(LANG_ACCOUNT_BNET_LIST_NO_ACCOUNTS, battlenetAccountName);
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
void AddSC_battlenet_account_commandscript()
|
||||
{
|
||||
new battlenet_account_commandscript();
|
||||
}
|
||||
@@ -21,7 +21,6 @@ void AddSC_achievement_commandscript();
|
||||
void AddSC_ahbot_commandscript();
|
||||
void AddSC_arena_commandscript();
|
||||
void AddSC_ban_commandscript();
|
||||
void AddSC_battlenet_account_commandscript();
|
||||
void AddSC_bf_commandscript();
|
||||
void AddSC_cast_commandscript();
|
||||
void AddSC_character_commandscript();
|
||||
@@ -67,7 +66,6 @@ void AddCommandsScripts()
|
||||
AddSC_ahbot_commandscript();
|
||||
AddSC_arena_commandscript();
|
||||
AddSC_ban_commandscript();
|
||||
AddSC_battlenet_account_commandscript();
|
||||
AddSC_bf_commandscript();
|
||||
AddSC_cast_commandscript();
|
||||
AddSC_character_commandscript();
|
||||
|
||||
Reference in new issue
Block a user