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
 
- Public Member Functions inherited from ScriptObject
virtual bool IsDatabaseBound () const
 
virtual bool isAfterLoadScript () const
 
virtual void checkValidity ()
 
const std::string & GetName () const
 
uint16 GetTotalAvailableHooks ()
 

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.
 
static bool HandleAccountSetEmailCommand (ChatHandler *handler, AccountIdentifier account, std::string email, std::string emailConfirmation)
 Set email 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, uint16 totalAvailableHooks=0)
 
virtual ~ScriptObject ()=default
 

Detailed Description

Constructor & Destructor Documentation

◆ account_commandscript()

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

Member Function Documentation

◆ GetCommands()

ChatCommandTable account_commandscript::GetCommands ( ) const
inlineoverridevirtual

Implements CommandScript.

45 {
46 static ChatCommandTable accountSetCommandTable =
47 {
48 { "addon", HandleAccountSetAddonCommand, SEC_GAMEMASTER, Console::Yes },
49 { "gmlevel", HandleAccountSetGmLevelCommand, SEC_ADMINISTRATOR, Console::Yes },
50 { "password", HandleAccountSetPasswordCommand, SEC_ADMINISTRATOR, Console::Yes },
51 { "2fa", HandleAccountSet2FACommand, SEC_PLAYER, Console::Yes },
52 { "email", HandleAccountSetEmailCommand, SEC_ADMINISTRATOR, Console::Yes }
53 };
54
55 static ChatCommandTable accountLockCommandTable
56 {
57 { "country", HandleAccountLockCountryCommand, SEC_PLAYER, Console::Yes },
58 { "ip", HandleAccountLockIpCommand, SEC_PLAYER, Console::Yes }
59 };
60
61 static ChatCommandTable account2faCommandTable
62 {
63 { "setup", HandleAccount2FASetupCommand, SEC_PLAYER, Console::No },
64 { "remove", HandleAccount2FARemoveCommand, SEC_PLAYER, Console::No }
65 };
66
67 static ChatCommandTable accountRemoveCommandTable
68 {
69 { "country", HandleAccountRemoveLockCountryCommand, SEC_ADMINISTRATOR, Console::Yes },
70 };
71
72 static ChatCommandTable accountCommandTable =
73 {
74 { "2fa", account2faCommandTable },
75 { "addon", HandleAccountAddonCommand, SEC_MODERATOR, Console::No },
76 { "create", HandleAccountCreateCommand, SEC_CONSOLE, Console::Yes },
77 { "delete", HandleAccountDeleteCommand, SEC_CONSOLE, Console::Yes },
78 { "onlinelist", HandleAccountOnlineListCommand, SEC_CONSOLE, Console::Yes },
79 { "lock", accountLockCommandTable },
80 { "set", accountSetCommandTable },
81 { "password", HandleAccountPasswordCommand, SEC_PLAYER, Console::No },
82 { "remove", accountRemoveCommandTable },
83 { "", HandleAccountCommand, SEC_PLAYER, Console::No }
84 };
85
86 static ChatCommandTable commandTable =
87 {
88 { "account", accountCommandTable }
89 };
90
91 return commandTable;
92 }
@ SEC_PLAYER
Definition Common.h:57
@ SEC_ADMINISTRATOR
Definition Common.h:60
@ SEC_GAMEMASTER
Definition Common.h:59
@ SEC_MODERATOR
Definition Common.h:58
@ SEC_CONSOLE
Definition Common.h:61
static bool HandleAccountLockIpCommand(ChatHandler *handler, char const *args)
Definition cs_account.cpp:488
static bool HandleAccountSet2FACommand(ChatHandler *handler, char const *args)
Definition cs_account.cpp:574
static bool HandleAccountSetGmLevelCommand(ChatHandler *handler, char const *args)
Definition cs_account.cpp:721
static bool HandleAccountLockCountryCommand(ChatHandler *handler, char const *args)
Definition cs_account.cpp:445
static bool HandleAccountOnlineListCommand(ChatHandler *handler, char const *)
Display info on users currently in the realm.
Definition cs_account.cpp:362
static bool HandleAccountDeleteCommand(ChatHandler *handler, char const *args)
Definition cs_account.cpp:311
static bool HandleAccountPasswordCommand(ChatHandler *handler, char const *args)
Definition cs_account.cpp:523
static bool HandleAccountRemoveLockCountryCommand(ChatHandler *handler, char const *args)
Definition cs_account.cpp:409
static bool HandleAccountSetPasswordCommand(ChatHandler *handler, char const *args)
Set password for account.
Definition cs_account.cpp:840
static bool HandleAccount2FARemoveCommand(ChatHandler *handler, char const *args)
Definition cs_account.cpp:164
static bool HandleAccountAddonCommand(ChatHandler *handler, char const *args)
Definition cs_account.cpp:235
static bool HandleAccountSetAddonCommand(ChatHandler *handler, char const *args)
Set/Unset the expansion level for an account.
Definition cs_account.cpp:660
static bool HandleAccountCommand(ChatHandler *handler, char const *)
Definition cs_account.cpp:652
static bool HandleAccountSetEmailCommand(ChatHandler *handler, AccountIdentifier account, std::string email, std::string emailConfirmation)
Set email for account.
Definition cs_account.cpp:899
static bool HandleAccount2FASetupCommand(ChatHandler *handler, char const *args)
Definition cs_account.cpp:94
static bool HandleAccountCreateCommand(ChatHandler *handler, char const *args)
Create an account.
Definition cs_account.cpp:266
std::vector< ChatCommandBuilder > ChatCommandTable
Definition ChatCommand.h:46

References HandleAccount2FARemoveCommand(), HandleAccount2FASetupCommand(), HandleAccountAddonCommand(), HandleAccountCommand(), HandleAccountCreateCommand(), HandleAccountDeleteCommand(), HandleAccountLockCountryCommand(), HandleAccountLockIpCommand(), HandleAccountOnlineListCommand(), HandleAccountPasswordCommand(), HandleAccountRemoveLockCountryCommand(), HandleAccountSet2FACommand(), HandleAccountSetAddonCommand(), HandleAccountSetEmailCommand(), 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
165 {
166 if (!*args)
167 {
169 return false;
170 }
171
172 auto token = Acore::StringTo<uint32>(args);
173
174 auto const& masterKey = sSecretMgr->GetSecret(SECRET_TOTP_MASTER_KEY);
175 if (!masterKey.IsAvailable())
176 {
178 return false;
179 }
180
181 uint32 const accountId = handler->GetSession()->GetAccountId();
183 { // get current TOTP secret
184 auto* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_ACCOUNT_TOTP_SECRET);
185 stmt->SetData(0, accountId);
186 PreparedQueryResult result = LoginDatabase.Query(stmt);
187
188 if (!result)
189 {
190 LOG_ERROR("misc", "Account {} not found in login database when processing .account 2fa setup command.", accountId);
192 return false;
193 }
194
195 Field* field = result->Fetch();
196 if (field->IsNull())
197 { // 2FA not enabled
199 return false;
200 }
201
202 secret = field->Get<Binary>();
203 }
204
205 if (token)
206 {
207 if (masterKey)
208 {
209 bool success = Acore::Crypto::AEDecrypt<Acore::Crypto::AES>(secret, *masterKey);
210 if (!success)
211 {
212 LOG_ERROR("misc", "Account {} has invalid ciphertext in TOTP token.", accountId);
214 return false;
215 }
216 }
217
218 if (Acore::Crypto::TOTP::ValidateToken(secret, *token))
219 {
220 auto* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_ACCOUNT_TOTP_SECRET);
221 stmt->SetData(0);
222 stmt->SetData(1, accountId);
223 LoginDatabase.Execute(stmt);
225 return true;
226 }
227 else
229 }
230
232 return false;
233 }
std::shared_ptr< PreparedResultSet > PreparedQueryResult
Definition DatabaseEnvFwd.h:45
DatabaseWorkerPool< LoginDatabaseConnection > LoginDatabase
Accessor to the realm/login database.
Definition DatabaseEnv.cpp:22
std::uint32_t uint32
Definition Define.h:107
std::vector< uint8 > Binary
Definition Field.h:40
@ LANG_UNKNOWN_ERROR
Definition Language.h:117
@ LANG_2FA_REMOVE_NEED_TOKEN
Definition Language.h:124
@ LANG_2FA_NOT_SETUP
Definition Language.h:123
@ LANG_2FA_INVALID_TOKEN
Definition Language.h:120
@ LANG_CMD_SYNTAX
Definition Language.h:42
@ LANG_2FA_COMMANDS_NOT_SETUP
Definition Language.h:118
@ LANG_2FA_REMOVE_COMPLETE
Definition Language.h:125
#define LOG_ERROR(filterType__,...)
Definition Log.h:157
@ LOGIN_UPD_ACCOUNT_TOTP_SECRET
Definition LoginDatabase.h:123
@ LOGIN_SEL_ACCOUNT_TOTP_SECRET
Definition LoginDatabase.h:122
#define sSecretMgr
Definition SecretMgr.h:72
@ SECRET_TOTP_MASTER_KEY
Definition SecretMgr.h:30
WorldSession * GetSession()
Definition Chat.h:242
void SendErrorMessage(uint32 entry)
Definition Chat.cpp:216
virtual void SendSysMessage(std::string_view str, bool escapeCharacters=false)
Definition Chat.cpp:160
Class used to access individual fields of database query result.
Definition Field.h:98
bool IsNull() const
Definition Field.h:106
std::enable_if_t< std::is_arithmetic_v< T >, T > Get() const
Definition Field.h:112
uint32 GetAccountId() const
Definition WorldSession.h:375
std::vector< uint8 > Secret
Definition TOTP.h:30
static bool ValidateToken(Secret const &key, uint32 token)
Definition TOTP.cpp:44

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
95 {
96 if (!*args)
97 {
99 return false;
100 }
101
102 auto token = Acore::StringTo<uint32>(args);
103
104 auto const& masterKey = sSecretMgr->GetSecret(SECRET_TOTP_MASTER_KEY);
105 if (!masterKey.IsAvailable())
106 {
108 return false;
109 }
110
111 uint32 const accountId = handler->GetSession()->GetAccountId();
112
113 { // check if 2FA already enabled
114 auto* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_ACCOUNT_TOTP_SECRET);
115 stmt->SetData(0, accountId);
116 PreparedQueryResult result = LoginDatabase.Query(stmt);
117
118 if (!result)
119 {
120 LOG_ERROR("misc", "Account {} not found in login database when processing .account 2fa setup command.", accountId);
122 return false;
123 }
124
125 if (!result->Fetch()->IsNull())
126 {
128 return false;
129 }
130 }
131
132 // store random suggested secrets
133 static std::unordered_map<uint32, Acore::Crypto::TOTP::Secret> suggestions;
134 auto pair = suggestions.emplace(std::piecewise_construct, std::make_tuple(accountId), std::make_tuple(Acore::Crypto::TOTP::RECOMMENDED_SECRET_LENGTH)); // std::vector 1-argument std::size_t constructor invokes resize
135
136 if (pair.second) // no suggestion yet, generate random secret
137 Acore::Crypto::GetRandomBytes(pair.first->second);
138
139 if (!pair.second && token) // suggestion already existed and token specified - validate
140 {
141 if (Acore::Crypto::TOTP::ValidateToken(pair.first->second, *token))
142 {
143 if (masterKey)
144 Acore::Crypto::AEEncryptWithRandomIV<Acore::Crypto::AES>(pair.first->second, *masterKey);
145
146 auto* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_ACCOUNT_TOTP_SECRET);
147 stmt->SetData(0, pair.first->second);
148 stmt->SetData(1, accountId);
149 LoginDatabase.Execute(stmt);
150
151 suggestions.erase(pair.first);
153 return true;
154 }
155 else
157 }
158
159 // new suggestion, or no token specified, output TOTP parameters
161 return false;
162 }
@ LANG_2FA_ALREADY_SETUP
Definition Language.h:119
@ LANG_2FA_SECRET_SUGGESTION
Definition Language.h:121
@ LANG_2FA_SETUP_COMPLETE
Definition Language.h:122
std::array< uint8, S > GetRandomBytes()
Definition CryptoRandom.h:35
static constexpr std::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
236 {
237 if (!*args)
238 {
240 return false;
241 }
242
243 char* exp = strtok((char*)args, " ");
244
245 uint32 accountId = handler->GetSession()->GetAccountId();
246
247 auto expansion = Acore::StringTo<uint8>(exp); //get int anyway (0 if error)
248 if (!expansion || *expansion > sWorld->getIntConfig(CONFIG_EXPANSION))
249 {
251 return false;
252 }
253
255
256 stmt->SetData(0, *expansion);
257 stmt->SetData(1, accountId);
258
259 LoginDatabase.Execute(stmt);
260
261 handler->PSendSysMessage(LANG_ACCOUNT_ADDON, *expansion);
262 return true;
263 }
@ CONFIG_EXPANSION
Definition IWorld.h:276
@ LANG_IMPROPER_VALUE
Definition Language.h:94
@ LANG_ACCOUNT_ADDON
Definition Language.h:93
@ LOGIN_UPD_EXPANSION
Definition LoginDatabase.h:67
void PSendSysMessage(std::string_view str, bool escapeCharacters=false)
Definition Chat.cpp:211
Acore::Types::is_default< T > SetData(const uint8 index, T value)
Definition PreparedStatement.h:77
Definition PreparedStatement.h:157
#define sWorld
Definition World.h:357

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
653 {
654 AccountTypes gmLevel = handler->GetSession()->GetSecurity();
655 handler->PSendSysMessage(LANG_ACCOUNT_LEVEL, uint32(gmLevel));
656 return true;
657 }
AccountTypes
Definition Common.h:56
@ LANG_ACCOUNT_LEVEL
Definition Language.h:43
AccountTypes GetSecurity() const
Definition WorldSession.h:373

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
267 {
268 if (!*args)
269 return false;
270
272 char* accountName = strtok((char*)args, " ");
273 char* password = strtok(nullptr, " ");
274 if (!accountName || !password)
275 return false;
276
277 AccountOpResult result = AccountMgr::CreateAccount(std::string(accountName), std::string(password));
278 switch (result)
279 {
280 case AOR_OK:
281 handler->PSendSysMessage(LANG_ACCOUNT_CREATED, accountName);
282 if (handler->GetSession())
283 {
284 LOG_DEBUG("warden", "Account: {} (IP: {}) Character:[{}] ({}) Change Password.",
285 handler->GetSession()->GetAccountId(), handler->GetSession()->GetRemoteAddress(),
286 handler->GetSession()->GetPlayer()->GetName(), handler->GetSession()->GetPlayer()->GetGUID().ToString());
287 }
288 break;
291 return false;
294 return false;
297 return false;
300 return false;
301 default:
302 handler->SendErrorMessage(LANG_ACCOUNT_NOT_CREATED, accountName);
303 return false;
304 }
305
306 return true;
307 }
AccountOpResult
Definition AccountMgr.h:25
@ AOR_DB_INTERNAL_ERROR
Definition AccountMgr.h:32
@ AOR_OK
Definition AccountMgr.h:26
@ AOR_NAME_ALREADY_EXIST
Definition AccountMgr.h:30
@ AOR_NAME_TOO_LONG
Definition AccountMgr.h:27
@ AOR_PASS_TOO_LONG
Definition AccountMgr.h:28
@ LANG_ACCOUNT_ALREADY_EXIST
Definition Language.h:862
@ LANG_ACCOUNT_PASS_TOO_LONG
Definition Language.h:887
@ LANG_ACCOUNT_NOT_CREATED_SQL_ERROR
Definition Language.h:863
@ LANG_ACCOUNT_NOT_CREATED
Definition Language.h:864
@ LANG_ACCOUNT_TOO_LONG
Definition Language.h:861
@ LANG_ACCOUNT_CREATED
Definition Language.h:860
#define LOG_DEBUG(filterType__,...)
Definition Log.h:169
std::string ToString() const
Definition ObjectGuid.cpp:47
static ObjectGuid GetGUID(Object const *o)
Definition Object.h:113
std::string const & GetName() const
Definition Object.h:464
Player * GetPlayer() const
Definition WorldSession.h:376
std::string const & GetRemoteAddress()
Definition WorldSession.h:385
AccountOpResult CreateAccount(std::string username, std::string password)
Definition AccountMgr.cpp:30

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

312 {
313 if (!*args)
314 return false;
315
317 char* account = strtok((char*)args, " ");
318 if (!account)
319 return false;
320
321 std::string accountName = account;
322 if (!Utf8ToUpperOnlyLatin(accountName))
323 {
324 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
325 return false;
326 }
327
328 uint32 accountId = AccountMgr::GetId(accountName);
329 if (!accountId)
330 {
331 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
332 return false;
333 }
334
338 if (handler->HasLowerSecurityAccount(nullptr, accountId, true))
339 return false;
340
341 AccountOpResult result = AccountMgr::DeleteAccount(accountId);
342 switch (result)
343 {
344 case AOR_OK:
345 handler->PSendSysMessage(LANG_ACCOUNT_DELETED, accountName);
346 break;
348 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
349 return false;
351 handler->SendErrorMessage(LANG_ACCOUNT_NOT_DELETED_SQL_ERROR, accountName.c_str());
352 return false;
353 default:
354 handler->SendErrorMessage(LANG_ACCOUNT_NOT_DELETED, accountName.c_str());
355 return false;
356 }
357
358 return true;
359 }
@ AOR_NAME_NOT_EXIST
Definition AccountMgr.h:31
@ LANG_ACCOUNT_NOT_DELETED_SQL_ERROR
Definition Language.h:858
@ LANG_ACCOUNT_NOT_EXIST
Definition Language.h:443
@ LANG_ACCOUNT_NOT_DELETED
Definition Language.h:859
@ LANG_ACCOUNT_DELETED
Definition Language.h:857
bool Utf8ToUpperOnlyLatin(std::string &utf8String)
Definition Util.cpp:532
bool HasLowerSecurityAccount(WorldSession *target, uint32 account, bool strong=false)
Definition Chat.cpp:76
AccountOpResult DeleteAccount(uint32 accountId)
Definition AccountMgr.cpp:88
uint32 GetId(std::string const &username)
Definition AccountMgr.cpp:229

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
446 {
447 if (!*args)
448 {
450 return false;
451 }
452
453 std::string param = (char*)args;
454
455 if (!param.empty())
456 {
457 if (param == "on")
458 {
459 if (IpLocationRecord const* location = sIPLocation->GetLocationRecord(handler->GetSession()->GetRemoteAddress()))
460 {
461 auto* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_ACCOUNT_LOCK_COUNTRY);
462 stmt->SetData(0, location->CountryCode);
463 stmt->SetData(1, handler->GetSession()->GetAccountId());
464 LoginDatabase.Execute(stmt);
466 }
467 else
468 {
469 handler->SendErrorMessage("No IP2Location information - account not locked");
470 return false;
471 }
472 }
473 else if (param == "off")
474 {
475 auto* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_ACCOUNT_LOCK_COUNTRY);
476 stmt->SetData(0, "00");
477 stmt->SetData(1, handler->GetSession()->GetAccountId());
478 LoginDatabase.Execute(stmt);
480 }
481 return true;
482 }
483
485 return false;
486 }
#define sIPLocation
Definition IPLocation.h:49
@ LANG_COMMAND_ACCLOCKLOCKED
Definition Language.h:60
@ LANG_USE_BOL
Definition Language.h:304
@ LANG_COMMAND_ACCLOCKUNLOCKED
Definition Language.h:61
@ LOGIN_UPD_ACCOUNT_LOCK_COUNTRY
Definition LoginDatabase.h:69
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
489 {
490 if (!*args)
491 {
493 return false;
494 }
495
496 std::string param = (char*)args;
497
498 if (!param.empty())
499 {
501
502 if (param == "on")
503 {
504 stmt->SetData(0, true); // locked
506 }
507 else if (param == "off")
508 {
509 stmt->SetData(0, false); // unlocked
511 }
512
513 stmt->SetData(1, handler->GetSession()->GetAccountId());
514
515 LoginDatabase.Execute(stmt);
516 return true;
517 }
518
520 return false;
521 }
@ 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
363 {
366
367 PreparedQueryResult result = CharacterDatabase.Query(stmt);
368
369 if (!result)
370 {
372 return true;
373 }
374
379
381 do
382 {
383 Field* fieldsDB = result->Fetch();
384 std::string name = fieldsDB[0].Get<std::string>();
385 uint32 account = fieldsDB[1].Get<uint32>();
386
388 // No SQL injection. account is uint32.
390 loginStmt->SetData(0, account);
391 PreparedQueryResult resultLogin = LoginDatabase.Query(loginStmt);
392
393 if (resultLogin)
394 {
395 Field* fieldsLogin = resultLogin->Fetch();
397 fieldsLogin[0].Get<std::string>(), name, fieldsLogin[1].Get<std::string>(),
398 fieldsDB[2].Get<uint16>(), fieldsDB[3].Get<uint16>(), fieldsLogin[3].Get<uint8>(),
399 fieldsLogin[2].Get<uint8>());
400 }
401 else
403 } while (result->NextRow());
404
406 return true;
407 }
@ CHAR_SEL_CHARACTER_ONLINE
Definition CharacterDatabase.h:330
DatabaseWorkerPool< CharacterDatabaseConnection > CharacterDatabase
Accessor to the character database.
Definition DatabaseEnv.cpp:21
std::uint8_t uint8
Definition Define.h:109
std::uint16_t uint16
Definition Define.h:108
@ LANG_ACCOUNT_LIST_ERROR
Definition Language.h:867
@ LANG_ACCOUNT_LIST_EMPTY
Definition Language.h:870
@ LANG_ACCOUNT_LIST_LINE
Definition Language.h:869
@ LANG_ACCOUNT_LIST_HEADER
Definition Language.h:866
@ LANG_ACCOUNT_LIST_BAR
Definition Language.h:868
@ LANG_ACCOUNT_LIST_BAR_HEADER
Definition Language.h:871
@ LOGIN_SEL_ACCOUNT_INFO
Definition LoginDatabase.h:91

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(), ChatHandler::SendSysMessage(), and PreparedStatementBase::SetData().

Referenced by GetCommands().

◆ HandleAccountPasswordCommand()

static bool account_commandscript::HandleAccountPasswordCommand ( ChatHandler handler,
char const *  args 
)
inlinestatic
524 {
525 if (!*args)
526 {
528 return false;
529 }
530
531 char* oldPassword = strtok((char*)args, " ");
532 char* newPassword = strtok(nullptr, " ");
533 char* passwordConfirmation = strtok(nullptr, " ");
534
535 if (!oldPassword || !newPassword || !passwordConfirmation)
536 {
538 return false;
539 }
540
541 if (!AccountMgr::CheckPassword(handler->GetSession()->GetAccountId(), std::string(oldPassword)))
542 {
544 sScriptMgr->OnFailedPasswordChange(handler->GetSession()->GetAccountId());
545 return false;
546 }
547
548 if (strcmp(newPassword, passwordConfirmation) != 0)
549 {
551 sScriptMgr->OnFailedPasswordChange(handler->GetSession()->GetAccountId());
552 return false;
553 }
554
555 AccountOpResult result = AccountMgr::ChangePassword(handler->GetSession()->GetAccountId(), std::string(newPassword));
556 switch (result)
557 {
558 case AOR_OK:
560 sScriptMgr->OnPasswordChange(handler->GetSession()->GetAccountId());
561 break;
564 sScriptMgr->OnFailedPasswordChange(handler->GetSession()->GetAccountId());
565 return false;
566 default:
568 return false;
569 }
570
571 return true;
572 }
@ 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:727
bool CheckPassword(uint32 accountId, std::string password)
Definition AccountMgr.cpp:272
AccountOpResult ChangePassword(uint32 accountId, std::string newPassword)
Definition AccountMgr.cpp:198

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
410 {
411 if (!*args)
412 {
414 return false;
415 }
416
418 char* _accountName = strtok((char*)args, " ");
419 if (!_accountName)
420 return false;
421
422 std::string accountName = _accountName;
423 if (!Utf8ToUpperOnlyLatin(accountName))
424 {
425 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName);
426 return false;
427 }
428
429 uint32 accountId = AccountMgr::GetId(accountName);
430 if (!accountId)
431 {
432 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName);
433 return false;
434 }
435
436 auto* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_ACCOUNT_LOCK_COUNTRY);
437 stmt->SetData(0, "00");
438 stmt->SetData(1, accountId);
439 LoginDatabase.Execute(stmt);
441
442 return true;
443 }

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
575 {
576 if (!*args)
577 {
579 return false;
580 }
581
582 char* _account = strtok((char*)args, " ");
583 char* _secret = strtok(nullptr, " ");
584
585 if (!_account || !_secret)
586 {
588 return false;
589 }
590
591 std::string accountName = _account;
592 std::string secret = _secret;
593
594 if (!Utf8ToUpperOnlyLatin(accountName))
595 {
596 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName);
597 return false;
598 }
599
600 uint32 targetAccountId = AccountMgr::GetId(accountName);
601 if (!targetAccountId)
602 {
603 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName);
604 return false;
605 }
606
607 if (handler->HasLowerSecurityAccount(nullptr, targetAccountId, true))
608 return false;
609
610 if (secret == "off")
611 {
612 auto* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_ACCOUNT_TOTP_SECRET);
613 stmt->SetData(0);
614 stmt->SetData(1, targetAccountId);
615 LoginDatabase.Execute(stmt);
617 return true;
618 }
619
620 auto const& masterKey = sSecretMgr->GetSecret(SECRET_TOTP_MASTER_KEY);
621 if (!masterKey.IsAvailable())
622 {
624 return false;
625 }
626
628 if (!decoded)
629 {
631 return false;
632 }
633
635 {
637 return false;
638 }
639
640 if (masterKey)
641 Acore::Crypto::AEEncryptWithRandomIV<Acore::Crypto::AES>(*decoded, *masterKey);
642
643 auto* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_ACCOUNT_TOTP_SECRET);
644 stmt->SetData(0, *decoded);
645 stmt->SetData(1, targetAccountId);
646 LoginDatabase.Execute(stmt);
647
648 handler->PSendSysMessage(LANG_2FA_SECRET_SET_COMPLETE, accountName);
649 return true;
650 }
@ LANG_2FA_SECRET_TOO_LONG
Definition Language.h:223
@ LANG_2FA_SECRET_INVALID
Definition Language.h:224
@ LANG_2FA_SECRET_SET_COMPLETE
Definition Language.h:225
std::optional< T > Optional
Optional helper class to wrap optional values within.
Definition Optional.h:24
static constexpr std::size_t TAG_SIZE_BYTES
Definition AES.h:32
static constexpr std::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
661 {
663 char* account = strtok((char*)args, " ");
664 char* exp = strtok(nullptr, " ");
665
666 if (!account)
667 return false;
668
669 std::string accountName;
670 uint32 accountId;
671
672 if (!exp)
673 {
674 Player* player = handler->getSelectedPlayer();
675 if (!player)
676 return false;
677
678 accountId = player->GetSession()->GetAccountId();
679 AccountMgr::GetName(accountId, accountName);
680 exp = account;
681 }
682 else
683 {
685 accountName = account;
686 if (!Utf8ToUpperOnlyLatin(accountName))
687 {
688 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName);
689 return false;
690 }
691
692 accountId = AccountMgr::GetId(accountName);
693 if (!accountId)
694 {
695 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName);
696 return false;
697 }
698 }
699
700 // Let set addon state only for lesser (strong) security level
701 // or to self account
702 if (handler->GetSession() && handler->GetSession()->GetAccountId() != accountId &&
703 handler->HasLowerSecurityAccount(nullptr, accountId, true))
704 return false;
705
706 auto expansion = Acore::StringTo<uint8>(exp); //get int anyway (0 if error)
707 if (!expansion || *expansion > sWorld->getIntConfig(CONFIG_EXPANSION))
708 return false;
709
711
712 stmt->SetData(0, *expansion);
713 stmt->SetData(1, accountId);
714
715 LoginDatabase.Execute(stmt);
716
717 handler->PSendSysMessage(LANG_ACCOUNT_SETADDON, accountName, accountId, *expansion);
718 return true;
719 }
@ LANG_ACCOUNT_SETADDON
Definition Language.h:890
Player * getSelectedPlayer() const
Definition Chat.cpp:374
Definition Player.h:1082
WorldSession * GetSession() const
Definition Player.h:2007
bool GetName(uint32 accountId, std::string &name)
Definition AccountMgr.cpp:257

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().

◆ HandleAccountSetEmailCommand()

static bool account_commandscript::HandleAccountSetEmailCommand ( ChatHandler handler,
AccountIdentifier  account,
std::string  email,
std::string  emailConfirmation 
)
inlinestatic

Set email for account.

901 {
902 if (!account || !email.data() || !emailConfirmation.data())
903 return false;
904
905 std::string accountName = account.GetName();
906 if (!Utf8ToUpperOnlyLatin(accountName))
907 {
908 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName);
909 return false;
910 }
911
912 uint32 targetAccountId = account.GetID();
913 if (!targetAccountId)
914 {
915 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName);
916 return false;
917 }
918
919 if (email != emailConfirmation)
920 {
922 return false;
923 }
924
925 AccountOpResult result = AccountMgr::ChangeEmail(targetAccountId, email.data());
926
927 switch (result)
928 {
929 case AOR_OK:
931 break;
933 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName);
934 return false;
937 return false;
938 default:
940 return false;
941 }
942 return true;
943 }
@ AOR_EMAIL_TOO_LONG
Definition AccountMgr.h:29
@ LANG_COMMAND_EMAIL
Definition Language.h:832
@ LANG_NEW_EMAILS_NOT_MATCH
Definition Language.h:831
@ LANG_COMMAND_NOTCHANGEEMAIL
Definition Language.h:834
@ LANG_EMAIL_TOO_LONG
Definition Language.h:833
AccountOpResult ChangeEmail(uint32 accountId, std::string newEmail)
Definition AccountMgr.cpp:61
uint32 GetID() const
Definition ChatCommandTags.h:154
std::string const & GetName() const
Definition ChatCommandTags.h:155

References AOR_EMAIL_TOO_LONG, AOR_NAME_NOT_EXIST, AOR_OK, AccountMgr::ChangeEmail(), Acore::ChatCommands::AccountIdentifier::GetID(), Acore::ChatCommands::AccountIdentifier::GetName(), LANG_ACCOUNT_NOT_EXIST, LANG_COMMAND_EMAIL, LANG_COMMAND_NOTCHANGEEMAIL, LANG_EMAIL_TOO_LONG, LANG_NEW_EMAILS_NOT_MATCH, ChatHandler::SendErrorMessage(), ChatHandler::SendSysMessage(), and Utf8ToUpperOnlyLatin().

Referenced by GetCommands().

◆ HandleAccountSetGmLevelCommand()

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

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

841 {
842 if (!*args)
843 return false;
844
846 char* account = strtok((char*)args, " ");
847 char* password = strtok(nullptr, " ");
848 char* passwordConfirmation = strtok(nullptr, " ");
849
850 if (!account || !password || !passwordConfirmation)
851 return false;
852
853 std::string accountName = account;
854 if (!Utf8ToUpperOnlyLatin(accountName))
855 {
856 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName);
857 return false;
858 }
859
860 uint32 targetAccountId = AccountMgr::GetId(accountName);
861 if (!targetAccountId)
862 {
863 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName);
864 return false;
865 }
866
869 if (handler->HasLowerSecurityAccount(nullptr, targetAccountId, true))
870 return false;
871
872 if (strcmp(password, passwordConfirmation))
873 {
875 return false;
876 }
877
878 AccountOpResult result = AccountMgr::ChangePassword(targetAccountId, password);
879
880 switch (result)
881 {
882 case AOR_OK:
884 break;
886 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName);
887 return false;
890 return false;
891 default:
893 return false;
894 }
895 return true;
896 }

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().


The documentation for this class was generated from the following file: