AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
account_commandscript Class Reference
Inheritance diagram for account_commandscript:
CommandScript ScriptObject

Public Member Functions

 account_commandscript ()
 
ChatCommandTable GetCommands () const override
 
virtual std::vector< Acore::ChatCommands::ChatCommandBuilderGetCommands () const =0
 
- Public Member Functions inherited from ScriptObject
virtual bool IsDatabaseBound () const
 
virtual bool isAfterLoadScript () const
 
virtual void checkValidity ()
 
const std::string & GetName () const
 

Static Public Member Functions

static bool HandleAccount2FASetupCommand (ChatHandler *handler, char const *args)
 
static bool HandleAccount2FARemoveCommand (ChatHandler *handler, char const *args)
 
static bool HandleAccountAddonCommand (ChatHandler *handler, char const *args)
 
static bool HandleAccountCreateCommand (ChatHandler *handler, char const *args)
 Create an account.
 
static bool HandleAccountDeleteCommand (ChatHandler *handler, char const *args)
 
static bool HandleAccountOnlineListCommand (ChatHandler *handler, char const *)
 Display info on users currently in the realm.
 
static bool HandleAccountRemoveLockCountryCommand (ChatHandler *handler, char const *args)
 
static bool HandleAccountLockCountryCommand (ChatHandler *handler, char const *args)
 
static bool HandleAccountLockIpCommand (ChatHandler *handler, char const *args)
 
static bool HandleAccountPasswordCommand (ChatHandler *handler, char const *args)
 
static bool HandleAccountSet2FACommand (ChatHandler *handler, char const *args)
 
static bool HandleAccountCommand (ChatHandler *handler, char const *)
 
static bool HandleAccountSetAddonCommand (ChatHandler *handler, char const *args)
 Set/Unset the expansion level for an account.
 
static bool HandleAccountSetGmLevelCommand (ChatHandler *handler, char const *args)
 
static bool HandleAccountSetPasswordCommand (ChatHandler *handler, char const *args)
 Set password for account.
 

Additional Inherited Members

- Protected Member Functions inherited from CommandScript
 CommandScript (const char *name)
 
- Protected Member Functions inherited from ScriptObject
 ScriptObject (const char *name)
 
virtual ~ScriptObject ()=default
 

Detailed Description

Constructor & Destructor Documentation

◆ account_commandscript()

account_commandscript::account_commandscript ( )
inline
49: CommandScript("account_commandscript") { }
Definition: CommandScript.h:25

Member Function Documentation

◆ GetCommands()

ChatCommandTable account_commandscript::GetCommands ( ) const
inlineoverridevirtual

Implements CommandScript.

52 {
53 static ChatCommandTable accountSetCommandTable =
54 {
55 { "addon", SEC_GAMEMASTER, true, &HandleAccountSetAddonCommand, "" },
56 { "gmlevel", SEC_CONSOLE, true, &HandleAccountSetGmLevelCommand, "" },
57 { "password", SEC_CONSOLE, true, &HandleAccountSetPasswordCommand, "" },
58 { "2fa", SEC_PLAYER, true, &HandleAccountSet2FACommand, "" }
59 };
60
61 static ChatCommandTable accountLockCommandTable
62 {
63 { "country", SEC_PLAYER, true, &HandleAccountLockCountryCommand, "" },
64 { "ip", SEC_PLAYER, true, &HandleAccountLockIpCommand, "" }
65 };
66
67 static ChatCommandTable account2faCommandTable
68 {
69 { "setup", SEC_PLAYER, false, &HandleAccount2FASetupCommand, "" },
70 { "remove", SEC_PLAYER, false, &HandleAccount2FARemoveCommand, "" },
71 };
72
73 static ChatCommandTable accountRemoveCommandTable
74 {
76 };
77
78 static ChatCommandTable accountCommandTable =
79 {
80 { "2fa", SEC_PLAYER, true, nullptr, "", account2faCommandTable },
81 { "addon", SEC_MODERATOR, false, &HandleAccountAddonCommand, "" },
82 { "create", SEC_CONSOLE, true, &HandleAccountCreateCommand, "" },
83 { "delete", SEC_CONSOLE, true, &HandleAccountDeleteCommand, "" },
84 { "onlinelist", SEC_CONSOLE, true, &HandleAccountOnlineListCommand, "" },
85 { "lock", SEC_PLAYER, false, nullptr, "", accountLockCommandTable },
86 { "set", SEC_ADMINISTRATOR, true, nullptr, "", accountSetCommandTable },
87 { "password", SEC_PLAYER, false, &HandleAccountPasswordCommand, "" },
88 { "remove", SEC_ADMINISTRATOR, true, nullptr, "", accountRemoveCommandTable },
89 { "", SEC_PLAYER, false, &HandleAccountCommand, "" }
90 };
91
92 static ChatCommandTable commandTable =
93 {
94 { "account", SEC_PLAYER, true, nullptr, "", accountCommandTable }
95 };
96
97 return commandTable;
98 }
@ SEC_PLAYER
Definition: Common.h:59
@ SEC_ADMINISTRATOR
Definition: Common.h:62
@ SEC_GAMEMASTER
Definition: Common.h:61
@ SEC_MODERATOR
Definition: Common.h:60
@ SEC_CONSOLE
Definition: Common.h:63
std::vector< ChatCommandBuilder > ChatCommandTable
Definition: ChatCommand.h:49
static bool HandleAccountLockIpCommand(ChatHandler *handler, char const *args)
Definition: cs_account.cpp:494
static bool HandleAccountSet2FACommand(ChatHandler *handler, char const *args)
Definition: cs_account.cpp:580
static bool HandleAccountSetGmLevelCommand(ChatHandler *handler, char const *args)
Definition: cs_account.cpp:727
static bool HandleAccountLockCountryCommand(ChatHandler *handler, char const *args)
Definition: cs_account.cpp:451
static bool HandleAccountOnlineListCommand(ChatHandler *handler, char const *)
Display info on users currently in the realm.
Definition: cs_account.cpp:368
static bool HandleAccountDeleteCommand(ChatHandler *handler, char const *args)
Definition: cs_account.cpp:317
static bool HandleAccountPasswordCommand(ChatHandler *handler, char const *args)
Definition: cs_account.cpp:529
static bool HandleAccountRemoveLockCountryCommand(ChatHandler *handler, char const *args)
Definition: cs_account.cpp:415
static bool HandleAccountSetPasswordCommand(ChatHandler *handler, char const *args)
Set password for account.
Definition: cs_account.cpp:846
static bool HandleAccount2FARemoveCommand(ChatHandler *handler, char const *args)
Definition: cs_account.cpp:170
static bool HandleAccountAddonCommand(ChatHandler *handler, char const *args)
Definition: cs_account.cpp:241
static bool HandleAccountSetAddonCommand(ChatHandler *handler, char const *args)
Set/Unset the expansion level for an account.
Definition: cs_account.cpp:666
static bool HandleAccountCommand(ChatHandler *handler, char const *)
Definition: cs_account.cpp:658
static bool HandleAccount2FASetupCommand(ChatHandler *handler, char const *args)
Definition: cs_account.cpp:100
static bool HandleAccountCreateCommand(ChatHandler *handler, char const *args)
Create an account.
Definition: cs_account.cpp:272

References HandleAccount2FARemoveCommand(), HandleAccount2FASetupCommand(), HandleAccountAddonCommand(), HandleAccountCommand(), HandleAccountCreateCommand(), HandleAccountDeleteCommand(), HandleAccountLockCountryCommand(), HandleAccountLockIpCommand(), HandleAccountOnlineListCommand(), HandleAccountPasswordCommand(), HandleAccountRemoveLockCountryCommand(), HandleAccountSet2FACommand(), HandleAccountSetAddonCommand(), HandleAccountSetGmLevelCommand(), HandleAccountSetPasswordCommand(), SEC_ADMINISTRATOR, SEC_CONSOLE, SEC_GAMEMASTER, SEC_MODERATOR, and SEC_PLAYER.

◆ HandleAccount2FARemoveCommand()

static bool account_commandscript::HandleAccount2FARemoveCommand ( ChatHandler handler,
char const *  args 
)
inlinestatic
171 {
172 if (!*args)
173 {
175 return false;
176 }
177
178 auto token = Acore::StringTo<uint32>(args);
179
180 auto const& masterKey = sSecretMgr->GetSecret(SECRET_TOTP_MASTER_KEY);
181 if (!masterKey.IsAvailable())
182 {
184 return false;
185 }
186
187 uint32 const accountId = handler->GetSession()->GetAccountId();
189 { // get current TOTP secret
190 auto* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_ACCOUNT_TOTP_SECRET);
191 stmt->SetData(0, accountId);
192 PreparedQueryResult result = LoginDatabase.Query(stmt);
193
194 if (!result)
195 {
196 LOG_ERROR("misc", "Account {} not found in login database when processing .account 2fa setup command.", accountId);
198 return false;
199 }
200
201 Field* field = result->Fetch();
202 if (field->IsNull())
203 { // 2FA not enabled
205 return false;
206 }
207
208 secret = field->Get<Binary>();
209 }
210
211 if (token)
212 {
213 if (masterKey)
214 {
215 bool success = Acore::Crypto::AEDecrypt<Acore::Crypto::AES>(secret, *masterKey);
216 if (!success)
217 {
218 LOG_ERROR("misc", "Account {} has invalid ciphertext in TOTP token.", accountId);
220 return false;
221 }
222 }
223
224 if (Acore::Crypto::TOTP::ValidateToken(secret, *token))
225 {
226 auto* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_ACCOUNT_TOTP_SECRET);
227 stmt->SetData(0);
228 stmt->SetData(1, accountId);
229 LoginDatabase.Execute(stmt);
231 return true;
232 }
233 else
235 }
236
238 return false;
239 }
std::uint32_t uint32
Definition: Define.h:108
#define LOG_ERROR(filterType__,...)
Definition: Log.h:157
DatabaseWorkerPool< LoginDatabaseConnection > LoginDatabase
Accessor to the realm/login database.
Definition: DatabaseEnv.cpp:22
std::shared_ptr< PreparedResultSet > PreparedQueryResult
Definition: DatabaseEnvFwd.h:46
std::vector< uint8 > Binary
Definition: Field.h:41
@ LOGIN_UPD_ACCOUNT_TOTP_SECRET
Definition: LoginDatabase.h:119
@ LOGIN_SEL_ACCOUNT_TOTP_SECRET
Definition: LoginDatabase.h:118
@ LANG_UNKNOWN_ERROR
Definition: Language.h:116
@ LANG_2FA_REMOVE_NEED_TOKEN
Definition: Language.h:123
@ LANG_2FA_NOT_SETUP
Definition: Language.h:122
@ LANG_2FA_INVALID_TOKEN
Definition: Language.h:119
@ LANG_CMD_SYNTAX
Definition: Language.h:42
@ LANG_2FA_COMMANDS_NOT_SETUP
Definition: Language.h:117
@ LANG_2FA_REMOVE_COMPLETE
Definition: Language.h:124
#define sSecretMgr
Definition: SecretMgr.h:73
@ SECRET_TOTP_MASTER_KEY
Definition: SecretMgr.h:31
std::vector< uint8 > Secret
Definition: TOTP.h:30
static bool ValidateToken(Secret const &key, uint32 token)
Definition: TOTP.cpp:44
Class used to access individual fields of database query result.
Definition: Field.h:99
bool IsNull() const
Definition: Field.h:107
std::enable_if_t< std::is_arithmetic_v< T >, T > Get() const
Definition: Field.h:113
WorldSession * GetSession()
Definition: Chat.h:139
void SendErrorMessage(uint32 entry)
Definition: Chat.cpp:152
virtual void SendSysMessage(std::string_view str, bool escapeCharacters=false)
Definition: Chat.cpp:101
uint32 GetAccountId() const
Definition: WorldSession.h:363

References Field::Get(), WorldSession::GetAccountId(), ChatHandler::GetSession(), Field::IsNull(), LANG_2FA_COMMANDS_NOT_SETUP, LANG_2FA_INVALID_TOKEN, LANG_2FA_NOT_SETUP, LANG_2FA_REMOVE_COMPLETE, LANG_2FA_REMOVE_NEED_TOKEN, LANG_CMD_SYNTAX, LANG_UNKNOWN_ERROR, LOG_ERROR, LOGIN_SEL_ACCOUNT_TOTP_SECRET, LOGIN_UPD_ACCOUNT_TOTP_SECRET, LoginDatabase, SECRET_TOTP_MASTER_KEY, ChatHandler::SendErrorMessage(), ChatHandler::SendSysMessage(), sSecretMgr, and Acore::Crypto::TOTP::ValidateToken().

Referenced by GetCommands().

◆ HandleAccount2FASetupCommand()

static bool account_commandscript::HandleAccount2FASetupCommand ( ChatHandler handler,
char const *  args 
)
inlinestatic
101 {
102 if (!*args)
103 {
105 return false;
106 }
107
108 auto token = Acore::StringTo<uint32>(args);
109
110 auto const& masterKey = sSecretMgr->GetSecret(SECRET_TOTP_MASTER_KEY);
111 if (!masterKey.IsAvailable())
112 {
114 return false;
115 }
116
117 uint32 const accountId = handler->GetSession()->GetAccountId();
118
119 { // check if 2FA already enabled
120 auto* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_ACCOUNT_TOTP_SECRET);
121 stmt->SetData(0, accountId);
122 PreparedQueryResult result = LoginDatabase.Query(stmt);
123
124 if (!result)
125 {
126 LOG_ERROR("misc", "Account {} not found in login database when processing .account 2fa setup command.", accountId);
128 return false;
129 }
130
131 if (!result->Fetch()->IsNull())
132 {
134 return false;
135 }
136 }
137
138 // store random suggested secrets
139 static std::unordered_map<uint32, Acore::Crypto::TOTP::Secret> suggestions;
140 auto pair = suggestions.emplace(std::piecewise_construct, std::make_tuple(accountId), std::make_tuple(Acore::Crypto::TOTP::RECOMMENDED_SECRET_LENGTH)); // std::vector 1-argument size_t constructor invokes resize
141
142 if (pair.second) // no suggestion yet, generate random secret
143 Acore::Crypto::GetRandomBytes(pair.first->second);
144
145 if (!pair.second && token) // suggestion already existed and token specified - validate
146 {
147 if (Acore::Crypto::TOTP::ValidateToken(pair.first->second, *token))
148 {
149 if (masterKey)
150 Acore::Crypto::AEEncryptWithRandomIV<Acore::Crypto::AES>(pair.first->second, *masterKey);
151
152 auto* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_ACCOUNT_TOTP_SECRET);
153 stmt->SetData(0, pair.first->second);
154 stmt->SetData(1, accountId);
155 LoginDatabase.Execute(stmt);
156
157 suggestions.erase(pair.first);
159 return true;
160 }
161 else
163 }
164
165 // new suggestion, or no token specified, output TOTP parameters
167 return false;
168 }
@ LANG_2FA_ALREADY_SETUP
Definition: Language.h:118
@ LANG_2FA_SECRET_SUGGESTION
Definition: Language.h:120
@ LANG_2FA_SETUP_COMPLETE
Definition: Language.h:121
std::array< uint8, S > GetRandomBytes()
Definition: CryptoRandom.h:35
static constexpr size_t RECOMMENDED_SECRET_LENGTH
Definition: TOTP.h:29
static std::string Encode(std::vector< uint8 > const &data)
Definition: Base32.cpp:47

References Acore::Encoding::Base32::Encode(), WorldSession::GetAccountId(), Acore::Crypto::GetRandomBytes(), ChatHandler::GetSession(), LANG_2FA_ALREADY_SETUP, LANG_2FA_COMMANDS_NOT_SETUP, LANG_2FA_INVALID_TOKEN, LANG_2FA_SECRET_SUGGESTION, LANG_2FA_SETUP_COMPLETE, LANG_CMD_SYNTAX, LANG_UNKNOWN_ERROR, LOG_ERROR, LOGIN_SEL_ACCOUNT_TOTP_SECRET, LOGIN_UPD_ACCOUNT_TOTP_SECRET, LoginDatabase, Acore::Crypto::TOTP::RECOMMENDED_SECRET_LENGTH, SECRET_TOTP_MASTER_KEY, ChatHandler::SendErrorMessage(), ChatHandler::SendSysMessage(), sSecretMgr, and Acore::Crypto::TOTP::ValidateToken().

Referenced by GetCommands().

◆ HandleAccountAddonCommand()

static bool account_commandscript::HandleAccountAddonCommand ( ChatHandler handler,
char const *  args 
)
inlinestatic
242 {
243 if (!*args)
244 {
246 return false;
247 }
248
249 char* exp = strtok((char*)args, " ");
250
251 uint32 accountId = handler->GetSession()->GetAccountId();
252
253 auto expansion = Acore::StringTo<uint8>(exp); //get int anyway (0 if error)
254 if (!expansion || *expansion > sWorld->getIntConfig(CONFIG_EXPANSION))
255 {
257 return false;
258 }
259
261
262 stmt->SetData(0, *expansion);
263 stmt->SetData(1, accountId);
264
265 LoginDatabase.Execute(stmt);
266
267 handler->PSendSysMessage(LANG_ACCOUNT_ADDON, *expansion);
268 return true;
269 }
@ LOGIN_UPD_EXPANSION
Definition: LoginDatabase.h:67
@ LANG_IMPROPER_VALUE
Definition: Language.h:94
@ LANG_ACCOUNT_ADDON
Definition: Language.h:93
@ CONFIG_EXPANSION
Definition: IWorld.h:276
#define sWorld
Definition: World.h:447
Definition: PreparedStatement.h:158
Acore::Types::is_default< T > SetData(const uint8 index, T value)
Definition: PreparedStatement.h:78
void PSendSysMessage(char const *fmt, Args &&... args)
Definition: Chat.h:60

References CONFIG_EXPANSION, WorldSession::GetAccountId(), ChatHandler::GetSession(), LANG_ACCOUNT_ADDON, LANG_CMD_SYNTAX, LANG_IMPROPER_VALUE, LOGIN_UPD_EXPANSION, LoginDatabase, ChatHandler::PSendSysMessage(), ChatHandler::SendErrorMessage(), PreparedStatementBase::SetData(), and sWorld.

Referenced by GetCommands().

◆ HandleAccountCommand()

static bool account_commandscript::HandleAccountCommand ( ChatHandler handler,
char const *   
)
inlinestatic
659 {
660 AccountTypes gmLevel = handler->GetSession()->GetSecurity();
661 handler->PSendSysMessage(LANG_ACCOUNT_LEVEL, uint32(gmLevel));
662 return true;
663 }
AccountTypes
Definition: Common.h:58
@ LANG_ACCOUNT_LEVEL
Definition: Language.h:43
AccountTypes GetSecurity() const
Definition: WorldSession.h:361

References WorldSession::GetSecurity(), ChatHandler::GetSession(), LANG_ACCOUNT_LEVEL, and ChatHandler::PSendSysMessage().

Referenced by GetCommands().

◆ HandleAccountCreateCommand()

static bool account_commandscript::HandleAccountCreateCommand ( ChatHandler handler,
char const *  args 
)
inlinestatic

Create an account.

  • Parse the command line arguments
273 {
274 if (!*args)
275 return false;
276
278 char* accountName = strtok((char*)args, " ");
279 char* password = strtok(nullptr, " ");
280 if (!accountName || !password)
281 return false;
282
283 AccountOpResult result = AccountMgr::CreateAccount(std::string(accountName), std::string(password));
284 switch (result)
285 {
286 case AOR_OK:
287 handler->PSendSysMessage(LANG_ACCOUNT_CREATED, accountName);
288 if (handler->GetSession())
289 {
290 LOG_DEBUG("warden", "Account: {} (IP: {}) Character:[{}] ({}) Change Password.",
291 handler->GetSession()->GetAccountId(), handler->GetSession()->GetRemoteAddress(),
292 handler->GetSession()->GetPlayer()->GetName(), handler->GetSession()->GetPlayer()->GetGUID().ToString());
293 }
294 break;
297 return false;
300 return false;
303 return false;
306 return false;
307 default:
308 handler->SendErrorMessage(LANG_ACCOUNT_NOT_CREATED, accountName);
309 return false;
310 }
311
312 return true;
313 }
#define LOG_DEBUG(filterType__,...)
Definition: Log.h:169
AccountOpResult
Definition: AccountMgr.h:25
@ AOR_DB_INTERNAL_ERROR
Definition: AccountMgr.h:31
@ AOR_OK
Definition: AccountMgr.h:26
@ AOR_NAME_ALREADY_EXIST
Definition: AccountMgr.h:29
@ AOR_NAME_TOO_LONG
Definition: AccountMgr.h:27
@ AOR_PASS_TOO_LONG
Definition: AccountMgr.h:28
@ LANG_ACCOUNT_ALREADY_EXIST
Definition: Language.h:843
@ LANG_ACCOUNT_PASS_TOO_LONG
Definition: Language.h:868
@ LANG_ACCOUNT_NOT_CREATED_SQL_ERROR
Definition: Language.h:844
@ LANG_ACCOUNT_NOT_CREATED
Definition: Language.h:845
@ LANG_ACCOUNT_TOO_LONG
Definition: Language.h:842
@ LANG_ACCOUNT_CREATED
Definition: Language.h:841
AccountOpResult CreateAccount(std::string username, std::string password)
Definition: AccountMgr.cpp:30
static ObjectGuid GetGUID(Object const *o)
Definition: Object.h:106
std::string const & GetName() const
Definition: Object.h:446
std::string ToString() const
Definition: ObjectGuid.cpp:47
Player * GetPlayer() const
Definition: WorldSession.h:364
std::string const & GetRemoteAddress()
Definition: WorldSession.h:373

References AOR_DB_INTERNAL_ERROR, AOR_NAME_ALREADY_EXIST, AOR_NAME_TOO_LONG, AOR_OK, AOR_PASS_TOO_LONG, AccountMgr::CreateAccount(), WorldSession::GetAccountId(), Object::GetGUID(), WorldObject::GetName(), WorldSession::GetPlayer(), WorldSession::GetRemoteAddress(), ChatHandler::GetSession(), LANG_ACCOUNT_ALREADY_EXIST, LANG_ACCOUNT_CREATED, LANG_ACCOUNT_NOT_CREATED, LANG_ACCOUNT_NOT_CREATED_SQL_ERROR, LANG_ACCOUNT_PASS_TOO_LONG, LANG_ACCOUNT_TOO_LONG, LOG_DEBUG, ChatHandler::PSendSysMessage(), ChatHandler::SendErrorMessage(), and ObjectGuid::ToString().

Referenced by GetCommands().

◆ HandleAccountDeleteCommand()

static bool account_commandscript::HandleAccountDeleteCommand ( ChatHandler handler,
char const *  args 
)
inlinestatic

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)
  • Get the account name from the command line

Commands not recommended call from chat, but support anyway can delete only for account with less security This is also reject self apply in fact

318 {
319 if (!*args)
320 return false;
321
323 char* account = strtok((char*)args, " ");
324 if (!account)
325 return false;
326
327 std::string accountName = account;
328 if (!Utf8ToUpperOnlyLatin(accountName))
329 {
330 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
331 return false;
332 }
333
334 uint32 accountId = AccountMgr::GetId(accountName);
335 if (!accountId)
336 {
337 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
338 return false;
339 }
340
344 if (handler->HasLowerSecurityAccount(nullptr, accountId, true))
345 return false;
346
347 AccountOpResult result = AccountMgr::DeleteAccount(accountId);
348 switch (result)
349 {
350 case AOR_OK:
351 handler->PSendSysMessage(LANG_ACCOUNT_DELETED, accountName.c_str());
352 break;
354 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
355 return false;
357 handler->SendErrorMessage(LANG_ACCOUNT_NOT_DELETED_SQL_ERROR, accountName.c_str());
358 return false;
359 default:
360 handler->SendErrorMessage(LANG_ACCOUNT_NOT_DELETED, accountName.c_str());
361 return false;
362 }
363
364 return true;
365 }
bool Utf8ToUpperOnlyLatin(std::string &utf8String)
Definition: Util.cpp:527
@ AOR_NAME_NOT_EXIST
Definition: AccountMgr.h:30
@ LANG_ACCOUNT_NOT_DELETED_SQL_ERROR
Definition: Language.h:839
@ LANG_ACCOUNT_NOT_EXIST
Definition: Language.h:425
@ LANG_ACCOUNT_NOT_DELETED
Definition: Language.h:840
@ LANG_ACCOUNT_DELETED
Definition: Language.h:838
AccountOpResult DeleteAccount(uint32 accountId)
Definition: AccountMgr.cpp:61
uint32 GetId(std::string const &username)
Definition: AccountMgr.cpp:200
bool HasLowerSecurityAccount(WorldSession *target, uint32 account, bool strong=false)
Definition: Chat.cpp:72

References AOR_DB_INTERNAL_ERROR, AOR_NAME_NOT_EXIST, AOR_OK, AccountMgr::DeleteAccount(), AccountMgr::GetId(), ChatHandler::HasLowerSecurityAccount(), LANG_ACCOUNT_DELETED, LANG_ACCOUNT_NOT_DELETED, LANG_ACCOUNT_NOT_DELETED_SQL_ERROR, LANG_ACCOUNT_NOT_EXIST, ChatHandler::PSendSysMessage(), ChatHandler::SendErrorMessage(), and Utf8ToUpperOnlyLatin().

Referenced by GetCommands().

◆ HandleAccountLockCountryCommand()

static bool account_commandscript::HandleAccountLockCountryCommand ( ChatHandler handler,
char const *  args 
)
inlinestatic
452 {
453 if (!*args)
454 {
456 return false;
457 }
458
459 std::string param = (char*)args;
460
461 if (!param.empty())
462 {
463 if (param == "on")
464 {
465 if (IpLocationRecord const* location = sIPLocation->GetLocationRecord(handler->GetSession()->GetRemoteAddress()))
466 {
467 auto* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_ACCOUNT_LOCK_COUNTRY);
468 stmt->SetData(0, location->CountryCode);
469 stmt->SetData(1, handler->GetSession()->GetAccountId());
470 LoginDatabase.Execute(stmt);
472 }
473 else
474 {
475 handler->SendErrorMessage("No IP2Location information - account not locked");
476 return false;
477 }
478 }
479 else if (param == "off")
480 {
481 auto* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_ACCOUNT_LOCK_COUNTRY);
482 stmt->SetData(0, "00");
483 stmt->SetData(1, handler->GetSession()->GetAccountId());
484 LoginDatabase.Execute(stmt);
486 }
487 return true;
488 }
489
491 return false;
492 }
#define sIPLocation
Definition: IPLocation.h:49
@ LOGIN_UPD_ACCOUNT_LOCK_COUNTRY
Definition: LoginDatabase.h:69
@ LANG_COMMAND_ACCLOCKLOCKED
Definition: Language.h:60
@ LANG_USE_BOL
Definition: Language.h:303
@ LANG_COMMAND_ACCLOCKUNLOCKED
Definition: Language.h:61
Definition: IPLocation.h:23

References WorldSession::GetAccountId(), WorldSession::GetRemoteAddress(), ChatHandler::GetSession(), LANG_COMMAND_ACCLOCKLOCKED, LANG_COMMAND_ACCLOCKUNLOCKED, LANG_USE_BOL, LOGIN_UPD_ACCOUNT_LOCK_COUNTRY, LoginDatabase, ChatHandler::PSendSysMessage(), ChatHandler::SendErrorMessage(), and sIPLocation.

Referenced by GetCommands().

◆ HandleAccountLockIpCommand()

static bool account_commandscript::HandleAccountLockIpCommand ( ChatHandler handler,
char const *  args 
)
inlinestatic
495 {
496 if (!*args)
497 {
499 return false;
500 }
501
502 std::string param = (char*)args;
503
504 if (!param.empty())
505 {
507
508 if (param == "on")
509 {
510 stmt->SetData(0, true); // locked
512 }
513 else if (param == "off")
514 {
515 stmt->SetData(0, false); // unlocked
517 }
518
519 stmt->SetData(1, handler->GetSession()->GetAccountId());
520
521 LoginDatabase.Execute(stmt);
522 return true;
523 }
524
526 return false;
527 }
@ LOGIN_UPD_ACCOUNT_LOCK
Definition: LoginDatabase.h:68

References WorldSession::GetAccountId(), ChatHandler::GetSession(), LANG_COMMAND_ACCLOCKLOCKED, LANG_COMMAND_ACCLOCKUNLOCKED, LANG_USE_BOL, LOGIN_UPD_ACCOUNT_LOCK, LoginDatabase, ChatHandler::PSendSysMessage(), ChatHandler::SendErrorMessage(), and PreparedStatementBase::SetData().

Referenced by GetCommands().

◆ HandleAccountOnlineListCommand()

static bool account_commandscript::HandleAccountOnlineListCommand ( ChatHandler handler,
char const *   
)
inlinestatic

Display info on users currently in the realm.

  • Get the list of accounts ID logged to the realm
  • Display the list of account/characters online
  • Cycle through accounts
  • Get the username, last IP and GM level of each account
369 {
372
373 PreparedQueryResult result = CharacterDatabase.Query(stmt);
374
375 if (!result)
376 {
378 return true;
379 }
380
385
387 do
388 {
389 Field* fieldsDB = result->Fetch();
390 std::string name = fieldsDB[0].Get<std::string>();
391 uint32 account = fieldsDB[1].Get<uint32>();
392
394 // No SQL injection. account is uint32.
396 loginStmt->SetData(0, account);
397 PreparedQueryResult resultLogin = LoginDatabase.Query(loginStmt);
398
399 if (resultLogin)
400 {
401 Field* fieldsLogin = resultLogin->Fetch();
403 fieldsLogin[0].Get<std::string>().c_str(), name.c_str(), fieldsLogin[1].Get<std::string>().c_str(),
404 fieldsDB[2].Get<uint16>(), fieldsDB[3].Get<uint16>(), fieldsLogin[3].Get<uint8>(),
405 fieldsLogin[2].Get<uint8>());
406 }
407 else
408 handler->PSendSysMessage(LANG_ACCOUNT_LIST_ERROR, name.c_str());
409 } while (result->NextRow());
410
412 return true;
413 }
std::uint8_t uint8
Definition: Define.h:110
std::uint16_t uint16
Definition: Define.h:109
DatabaseWorkerPool< CharacterDatabaseConnection > CharacterDatabase
Accessor to the character database.
Definition: DatabaseEnv.cpp:21
@ CHAR_SEL_CHARACTER_ONLINE
Definition: CharacterDatabase.h:328
@ LOGIN_SEL_ACCOUNT_INFO
Definition: LoginDatabase.h:90
@ LANG_ACCOUNT_LIST_ERROR
Definition: Language.h:848
@ LANG_ACCOUNT_LIST_EMPTY
Definition: Language.h:851
@ LANG_ACCOUNT_LIST_LINE
Definition: Language.h:850
@ LANG_ACCOUNT_LIST_HEADER
Definition: Language.h:847
@ LANG_ACCOUNT_LIST_BAR
Definition: Language.h:849
@ LANG_ACCOUNT_LIST_BAR_HEADER
Definition: Language.h:852

References CHAR_SEL_CHARACTER_ONLINE, CharacterDatabase, Field::Get(), LANG_ACCOUNT_LIST_BAR, LANG_ACCOUNT_LIST_BAR_HEADER, LANG_ACCOUNT_LIST_EMPTY, LANG_ACCOUNT_LIST_ERROR, LANG_ACCOUNT_LIST_HEADER, LANG_ACCOUNT_LIST_LINE, LOGIN_SEL_ACCOUNT_INFO, LoginDatabase, ChatHandler::PSendSysMessage(), and ChatHandler::SendSysMessage().

Referenced by GetCommands().

◆ HandleAccountPasswordCommand()

static bool account_commandscript::HandleAccountPasswordCommand ( ChatHandler handler,
char const *  args 
)
inlinestatic
530 {
531 if (!*args)
532 {
534 return false;
535 }
536
537 char* oldPassword = strtok((char*)args, " ");
538 char* newPassword = strtok(nullptr, " ");
539 char* passwordConfirmation = strtok(nullptr, " ");
540
541 if (!oldPassword || !newPassword || !passwordConfirmation)
542 {
544 return false;
545 }
546
547 if (!AccountMgr::CheckPassword(handler->GetSession()->GetAccountId(), std::string(oldPassword)))
548 {
550 sScriptMgr->OnFailedPasswordChange(handler->GetSession()->GetAccountId());
551 return false;
552 }
553
554 if (strcmp(newPassword, passwordConfirmation) != 0)
555 {
557 sScriptMgr->OnFailedPasswordChange(handler->GetSession()->GetAccountId());
558 return false;
559 }
560
561 AccountOpResult result = AccountMgr::ChangePassword(handler->GetSession()->GetAccountId(), std::string(newPassword));
562 switch (result)
563 {
564 case AOR_OK:
566 sScriptMgr->OnPasswordChange(handler->GetSession()->GetAccountId());
567 break;
570 sScriptMgr->OnFailedPasswordChange(handler->GetSession()->GetAccountId());
571 return false;
572 default:
574 return false;
575 }
576
577 return true;
578 }
@ LANG_COMMAND_NOTCHANGEPASSWORD
Definition: Language.h:57
@ LANG_PASSWORD_TOO_LONG
Definition: Language.h:87
@ LANG_COMMAND_WRONGOLDPASSWORD
Definition: Language.h:59
@ LANG_NEW_PASSWORDS_NOT_MATCH
Definition: Language.h:86
@ LANG_COMMAND_PASSWORD
Definition: Language.h:58
#define sScriptMgr
Definition: ScriptMgr.h:698
bool CheckPassword(uint32 accountId, std::string password)
Definition: AccountMgr.cpp:243
AccountOpResult ChangePassword(uint32 accountId, std::string newPassword)
Definition: AccountMgr.cpp:169

References AOR_OK, AOR_PASS_TOO_LONG, AccountMgr::ChangePassword(), AccountMgr::CheckPassword(), WorldSession::GetAccountId(), ChatHandler::GetSession(), LANG_CMD_SYNTAX, LANG_COMMAND_NOTCHANGEPASSWORD, LANG_COMMAND_PASSWORD, LANG_COMMAND_WRONGOLDPASSWORD, LANG_NEW_PASSWORDS_NOT_MATCH, LANG_PASSWORD_TOO_LONG, ChatHandler::SendErrorMessage(), ChatHandler::SendSysMessage(), and sScriptMgr.

Referenced by GetCommands().

◆ HandleAccountRemoveLockCountryCommand()

static bool account_commandscript::HandleAccountRemoveLockCountryCommand ( ChatHandler handler,
char const *  args 
)
inlinestatic
  • Parse the command line arguments
416 {
417 if (!*args)
418 {
420 return false;
421 }
422
424 char* _accountName = strtok((char*)args, " ");
425 if (!_accountName)
426 return false;
427
428 std::string accountName = _accountName;
429 if (!Utf8ToUpperOnlyLatin(accountName))
430 {
431 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
432 return false;
433 }
434
435 uint32 accountId = AccountMgr::GetId(accountName);
436 if (!accountId)
437 {
438 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
439 return false;
440 }
441
442 auto* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_ACCOUNT_LOCK_COUNTRY);
443 stmt->SetData(0, "00");
444 stmt->SetData(1, accountId);
445 LoginDatabase.Execute(stmt);
447
448 return true;
449 }

References AccountMgr::GetId(), LANG_ACCOUNT_NOT_EXIST, LANG_CMD_SYNTAX, LANG_COMMAND_ACCLOCKUNLOCKED, LOGIN_UPD_ACCOUNT_LOCK_COUNTRY, LoginDatabase, ChatHandler::PSendSysMessage(), ChatHandler::SendErrorMessage(), and Utf8ToUpperOnlyLatin().

Referenced by GetCommands().

◆ HandleAccountSet2FACommand()

static bool account_commandscript::HandleAccountSet2FACommand ( ChatHandler handler,
char const *  args 
)
inlinestatic
581 {
582 if (!*args)
583 {
585 return false;
586 }
587
588 char* _account = strtok((char*)args, " ");
589 char* _secret = strtok(nullptr, " ");
590
591 if (!_account || !_secret)
592 {
594 return false;
595 }
596
597 std::string accountName = _account;
598 std::string secret = _secret;
599
600 if (!Utf8ToUpperOnlyLatin(accountName))
601 {
602 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
603 return false;
604 }
605
606 uint32 targetAccountId = AccountMgr::GetId(accountName);
607 if (!targetAccountId)
608 {
609 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
610 return false;
611 }
612
613 if (handler->HasLowerSecurityAccount(nullptr, targetAccountId, true))
614 return false;
615
616 if (secret == "off")
617 {
618 auto* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_ACCOUNT_TOTP_SECRET);
619 stmt->SetData(0);
620 stmt->SetData(1, targetAccountId);
621 LoginDatabase.Execute(stmt);
623 return true;
624 }
625
626 auto const& masterKey = sSecretMgr->GetSecret(SECRET_TOTP_MASTER_KEY);
627 if (!masterKey.IsAvailable())
628 {
630 return false;
631 }
632
634 if (!decoded)
635 {
637 return false;
638 }
639
641 {
643 return false;
644 }
645
646 if (masterKey)
647 Acore::Crypto::AEEncryptWithRandomIV<Acore::Crypto::AES>(*decoded, *masterKey);
648
649 auto* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_ACCOUNT_TOTP_SECRET);
650 stmt->SetData(0, *decoded);
651 stmt->SetData(1, targetAccountId);
652 LoginDatabase.Execute(stmt);
653
654 handler->PSendSysMessage(LANG_2FA_SECRET_SET_COMPLETE, accountName.c_str());
655 return true;
656 }
std::optional< T > Optional
Optional helper class to wrap optional values within.
Definition: Optional.h:24
@ LANG_2FA_SECRET_TOO_LONG
Definition: Language.h:222
@ LANG_2FA_SECRET_INVALID
Definition: Language.h:223
@ LANG_2FA_SECRET_SET_COMPLETE
Definition: Language.h:224
static constexpr size_t TAG_SIZE_BYTES
Definition: AES.h:32
static constexpr size_t IV_SIZE_BYTES
Definition: AES.h:30
static Optional< std::vector< uint8 > > Decode(std::string const &data)
Definition: Base32.cpp:52

References Acore::Encoding::Base32::Decode(), AccountMgr::GetId(), ChatHandler::HasLowerSecurityAccount(), Acore::Crypto::AES::IV_SIZE_BYTES, LANG_2FA_COMMANDS_NOT_SETUP, LANG_2FA_REMOVE_COMPLETE, LANG_2FA_SECRET_INVALID, LANG_2FA_SECRET_SET_COMPLETE, LANG_2FA_SECRET_TOO_LONG, LANG_ACCOUNT_NOT_EXIST, LANG_CMD_SYNTAX, LOGIN_UPD_ACCOUNT_TOTP_SECRET, LoginDatabase, ChatHandler::PSendSysMessage(), SECRET_TOTP_MASTER_KEY, ChatHandler::SendErrorMessage(), sSecretMgr, Acore::Crypto::AES::TAG_SIZE_BYTES, and Utf8ToUpperOnlyLatin().

Referenced by GetCommands().

◆ HandleAccountSetAddonCommand()

static bool account_commandscript::HandleAccountSetAddonCommand ( ChatHandler handler,
char const *  args 
)
inlinestatic

Set/Unset the expansion level for an account.

  • Get the command line arguments
  • Convert Account name to Upper Format
667 {
669 char* account = strtok((char*)args, " ");
670 char* exp = strtok(nullptr, " ");
671
672 if (!account)
673 return false;
674
675 std::string accountName;
676 uint32 accountId;
677
678 if (!exp)
679 {
680 Player* player = handler->getSelectedPlayer();
681 if (!player)
682 return false;
683
684 accountId = player->GetSession()->GetAccountId();
685 AccountMgr::GetName(accountId, accountName);
686 exp = account;
687 }
688 else
689 {
691 accountName = account;
692 if (!Utf8ToUpperOnlyLatin(accountName))
693 {
694 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
695 return false;
696 }
697
698 accountId = AccountMgr::GetId(accountName);
699 if (!accountId)
700 {
701 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
702 return false;
703 }
704 }
705
706 // Let set addon state only for lesser (strong) security level
707 // or to self account
708 if (handler->GetSession() && handler->GetSession()->GetAccountId() != accountId &&
709 handler->HasLowerSecurityAccount(nullptr, accountId, true))
710 return false;
711
712 auto expansion = Acore::StringTo<uint8>(exp); //get int anyway (0 if error)
713 if (!expansion || *expansion > sWorld->getIntConfig(CONFIG_EXPANSION))
714 return false;
715
717
718 stmt->SetData(0, *expansion);
719 stmt->SetData(1, accountId);
720
721 LoginDatabase.Execute(stmt);
722
723 handler->PSendSysMessage(LANG_ACCOUNT_SETADDON, accountName.c_str(), accountId, *expansion);
724 return true;
725 }
@ LANG_ACCOUNT_SETADDON
Definition: Language.h:871
bool GetName(uint32 accountId, std::string &name)
Definition: AccountMgr.cpp:228
Player * getSelectedPlayer() const
Definition: Chat.cpp:310
Definition: Player.h:1056
WorldSession * GetSession() const
Definition: Player.h:1961

References CONFIG_EXPANSION, WorldSession::GetAccountId(), AccountMgr::GetId(), AccountMgr::GetName(), ChatHandler::getSelectedPlayer(), ChatHandler::GetSession(), Player::GetSession(), ChatHandler::HasLowerSecurityAccount(), LANG_ACCOUNT_NOT_EXIST, LANG_ACCOUNT_SETADDON, LOGIN_UPD_EXPANSION, LoginDatabase, ChatHandler::PSendSysMessage(), ChatHandler::SendErrorMessage(), PreparedStatementBase::SetData(), sWorld, and Utf8ToUpperOnlyLatin().

Referenced by GetCommands().

◆ HandleAccountSetGmLevelCommand()

static bool account_commandscript::HandleAccountSetGmLevelCommand ( ChatHandler handler,
char const *  args 
)
inlinestatic
728 {
729 if (!*args)
730 return false;
731
732 std::string targetAccountName;
733 uint32 targetAccountId = 0;
734 uint32 targetSecurity = 0;
735 uint32 gm = 0;
736 char* arg1 = strtok((char*)args, " ");
737 char* arg2 = strtok(nullptr, " ");
738 char* arg3 = strtok(nullptr, " ");
739 bool isAccountNameGiven = true;
740
741 if (arg1 && !arg3)
742 {
743 if (!handler->getSelectedPlayer())
744 return false;
745 isAccountNameGiven = false;
746 }
747
748 // Check for second parameter
749 if (!isAccountNameGiven && !arg2)
750 return false;
751
752 // Check for account
753 if (isAccountNameGiven)
754 {
755 targetAccountName = arg1;
756 if (!Utf8ToUpperOnlyLatin(targetAccountName))
757 {
758 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, targetAccountName.c_str());
759 return false;
760 }
761 }
762
763 // Check for invalid specified GM level.
764 gm = (isAccountNameGiven) ? Acore::StringTo<int32>(arg2).value_or(0) : Acore::StringTo<int32>(arg1).value_or(0);
765 if (gm > SEC_CONSOLE)
766 {
768 return false;
769 }
770
771 // handler->getSession() == nullptr only for console
772 targetAccountId = (isAccountNameGiven) ? AccountMgr::GetId(targetAccountName) : handler->getSelectedPlayer()->GetSession()->GetAccountId();
773 int32 gmRealmID = (isAccountNameGiven) ? Acore::StringTo<int32>(arg3).value_or(0) : Acore::StringTo<int32>(arg2).value_or(0);
774 uint32 playerSecurity;
775 if (handler->GetSession())
776 playerSecurity = AccountMgr::GetSecurity(handler->GetSession()->GetAccountId(), gmRealmID);
777 else
778 playerSecurity = SEC_CONSOLE;
779
780 // can set security level only for target with less security and to less security that we have
781 // This is also reject self apply in fact
782 targetSecurity = AccountMgr::GetSecurity(targetAccountId, gmRealmID);
783 if (targetSecurity >= playerSecurity || gm >= playerSecurity)
784 {
786 return false;
787 }
788
789 // Check and abort if the target gm has a higher rank on one of the realms and the new realm is -1
790 if (gmRealmID == -1 && !AccountMgr::IsConsoleAccount(playerSecurity))
791 {
793
794 stmt->SetData(0, targetAccountId);
795 stmt->SetData(1, uint8(gm));
796
797 PreparedQueryResult result = LoginDatabase.Query(stmt);
798
799 if (result)
800 {
802 return false;
803 }
804 }
805
806 // Check if provided realm.Id.Realm has a negative value other than -1
807 if (gmRealmID < -1)
808 {
810 return false;
811 }
812
813 // If gmRealmID is -1, delete all values for the account id, else, insert values for the specific realm.Id.Realm
815
816 if (gmRealmID == -1)
817 {
818 stmt = LoginDatabase.GetPreparedStatement(LOGIN_DEL_ACCOUNT_ACCESS);
819 stmt->SetData(0, targetAccountId);
820 }
821 else
822 {
823 stmt = LoginDatabase.GetPreparedStatement(LOGIN_DEL_ACCOUNT_ACCESS_BY_REALM);
824 stmt->SetData(0, targetAccountId);
825 stmt->SetData(1, realm.Id.Realm);
826 }
827
828 LoginDatabase.Execute(stmt);
829
830 if (gm != 0)
831 {
832 stmt = LoginDatabase.GetPreparedStatement(LOGIN_INS_ACCOUNT_ACCESS);
833
834 stmt->SetData(0, targetAccountId);
835 stmt->SetData(1, uint8(gm));
836 stmt->SetData(2, gmRealmID);
837
838 LoginDatabase.Execute(stmt);
839 }
840
841 handler->PSendSysMessage(LANG_YOU_CHANGE_SECURITY, targetAccountName.c_str(), gm);
842 return true;
843 }
std::int32_t int32
Definition: Define.h:104
@ LOGIN_DEL_ACCOUNT_ACCESS_BY_REALM
Definition: LoginDatabase.h:79
@ LOGIN_DEL_ACCOUNT_ACCESS
Definition: LoginDatabase.h:78
@ LOGIN_INS_ACCOUNT_ACCESS
Definition: LoginDatabase.h:80
@ LOGIN_SEL_ACCOUNT_ACCESS_GMLEVEL_TEST
Definition: LoginDatabase.h:91
@ LANG_YOU_CHANGE_SECURITY
Definition: Language.h:410
@ LANG_YOURS_SECURITY_IS_LOW
Definition: Language.h:412
@ LANG_INVALID_REALMID
Definition: Language.h:1295
@ LANG_BAD_VALUE
Definition: Language.h:147
Realm realm
Definition: World.cpp:112
bool IsConsoleAccount(uint32 gmlevel)
Definition: AccountMgr.cpp:286
uint32 GetSecurity(uint32 accountId)
Definition: AccountMgr.cpp:209
uint32 Realm
Definition: Realm.h:42
RealmHandle Id
Definition: Realm.h:68

References WorldSession::GetAccountId(), AccountMgr::GetId(), AccountMgr::GetSecurity(), ChatHandler::getSelectedPlayer(), ChatHandler::GetSession(), Player::GetSession(), Realm::Id, AccountMgr::IsConsoleAccount(), LANG_ACCOUNT_NOT_EXIST, LANG_BAD_VALUE, LANG_INVALID_REALMID, LANG_YOU_CHANGE_SECURITY, LANG_YOURS_SECURITY_IS_LOW, LOGIN_DEL_ACCOUNT_ACCESS, LOGIN_DEL_ACCOUNT_ACCESS_BY_REALM, LOGIN_INS_ACCOUNT_ACCESS, LOGIN_SEL_ACCOUNT_ACCESS_GMLEVEL_TEST, LoginDatabase, ChatHandler::PSendSysMessage(), realm, RealmHandle::Realm, SEC_CONSOLE, ChatHandler::SendErrorMessage(), PreparedStatementBase::SetData(), and Utf8ToUpperOnlyLatin().

Referenced by GetCommands().

◆ HandleAccountSetPasswordCommand()

static bool account_commandscript::HandleAccountSetPasswordCommand ( ChatHandler handler,
char const *  args 
)
inlinestatic

Set password for account.

  • Get the command line arguments

can set password only for target with less security This is also reject self apply in fact

847 {
848 if (!*args)
849 return false;
850
852 char* account = strtok((char*)args, " ");
853 char* password = strtok(nullptr, " ");
854 char* passwordConfirmation = strtok(nullptr, " ");
855
856 if (!account || !password || !passwordConfirmation)
857 return false;
858
859 std::string accountName = account;
860 if (!Utf8ToUpperOnlyLatin(accountName))
861 {
862 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
863 return false;
864 }
865
866 uint32 targetAccountId = AccountMgr::GetId(accountName);
867 if (!targetAccountId)
868 {
869 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
870 return false;
871 }
872
875 if (handler->HasLowerSecurityAccount(nullptr, targetAccountId, true))
876 return false;
877
878 if (strcmp(password, passwordConfirmation))
879 {
881 return false;
882 }
883
884 AccountOpResult result = AccountMgr::ChangePassword(targetAccountId, password);
885
886 switch (result)
887 {
888 case AOR_OK:
890 break;
892 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
893 return false;
896 return false;
897 default:
899 return false;
900 }
901 return true;
902 }

References AOR_NAME_NOT_EXIST, AOR_OK, AOR_PASS_TOO_LONG, AccountMgr::ChangePassword(), AccountMgr::GetId(), ChatHandler::HasLowerSecurityAccount(), LANG_ACCOUNT_NOT_EXIST, LANG_COMMAND_NOTCHANGEPASSWORD, LANG_COMMAND_PASSWORD, LANG_NEW_PASSWORDS_NOT_MATCH, LANG_PASSWORD_TOO_LONG, ChatHandler::SendErrorMessage(), ChatHandler::SendSysMessage(), and Utf8ToUpperOnlyLatin().

Referenced by GetCommands().