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:493
static bool HandleAccountSet2FACommand(ChatHandler *handler, char const *args)
Definition cs_account.cpp:579
static bool HandleAccountSetGmLevelCommand(ChatHandler *handler, char const *args)
Definition cs_account.cpp:726
static bool HandleAccountLockCountryCommand(ChatHandler *handler, char const *args)
Definition cs_account.cpp:450
static bool HandleAccountOnlineListCommand(ChatHandler *handler, char const *)
Display info on users currently in the realm.
Definition cs_account.cpp:367
static bool HandleAccountDeleteCommand(ChatHandler *handler, char const *args)
Definition cs_account.cpp:316
static bool HandleAccountPasswordCommand(ChatHandler *handler, char const *args)
Definition cs_account.cpp:528
static bool HandleAccountRemoveLockCountryCommand(ChatHandler *handler, char const *args)
Definition cs_account.cpp:414
static bool HandleAccountSetPasswordCommand(ChatHandler *handler, char const *args)
Set password for account.
Definition cs_account.cpp:845
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:665
static bool HandleAccountCommand(ChatHandler *handler, char const *)
Definition cs_account.cpp:657
static bool HandleAccountSetEmailCommand(ChatHandler *handler, AccountIdentifier account, std::string email, std::string emailConfirmation)
Set email for account.
Definition cs_account.cpp:904
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:158
@ LOGIN_UPD_ACCOUNT_TOTP_SECRET
Definition LoginDatabase.h:125
@ LOGIN_SEL_ACCOUNT_TOTP_SECRET
Definition LoginDatabase.h:124
#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:380
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 }
@ LANG_IMPROPER_VALUE
Definition Language.h:94
@ LANG_ACCOUNT_ADDON
Definition Language.h:93
@ LOGIN_UPD_EXPANSION
Definition LoginDatabase.h:67
@ CONFIG_EXPANSION
Definition WorldConfig.h:225
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:320

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
658 {
659 AccountTypes gmLevel = handler->GetSession()->GetSecurity();
660 handler->PSendSysMessage(LANG_ACCOUNT_LEVEL, uint32(gmLevel));
661 return true;
662 }
AccountTypes
Definition Common.h:56
@ LANG_ACCOUNT_LEVEL
Definition Language.h:43
AccountTypes GetSecurity() const
Definition WorldSession.h:378

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 char* email = strtok(nullptr, " ");
275
276 if (!accountName || !password)
277 return false;
278
279 // if email is not specified, use empty string
280 std::string emailStr = email ? email : "";
281
282 AccountOpResult result = AccountMgr::CreateAccount(std::string(accountName), std::string(password), emailStr);
283 switch (result)
284 {
285 case AOR_OK:
286 handler->PSendSysMessage(LANG_ACCOUNT_CREATED, accountName);
287 if (handler->GetSession())
288 {
289 LOG_DEBUG("warden", "Account: {} (IP: {}) Character:[{}] ({}) Change Password.",
290 handler->GetSession()->GetAccountId(), handler->GetSession()->GetRemoteAddress(),
291 handler->GetSession()->GetPlayer()->GetName(), handler->GetSession()->GetPlayer()->GetGUID().ToString());
292 }
293 break;
296 return false;
299 return false;
302 return false;
305 return false;
306 default:
307 handler->SendErrorMessage(LANG_ACCOUNT_NOT_CREATED, accountName);
308 return false;
309 }
310
311 return true;
312 }
AccountOpResult
Definition AccountMgr.h:26
@ AOR_DB_INTERNAL_ERROR
Definition AccountMgr.h:33
@ AOR_OK
Definition AccountMgr.h:27
@ AOR_NAME_ALREADY_EXIST
Definition AccountMgr.h:31
@ AOR_NAME_TOO_LONG
Definition AccountMgr.h:28
@ AOR_PASS_TOO_LONG
Definition AccountMgr.h:29
@ LANG_ACCOUNT_ALREADY_EXIST
Definition Language.h:867
@ LANG_ACCOUNT_PASS_TOO_LONG
Definition Language.h:892
@ LANG_ACCOUNT_NOT_CREATED_SQL_ERROR
Definition Language.h:868
@ LANG_ACCOUNT_NOT_CREATED
Definition Language.h:869
@ LANG_ACCOUNT_TOO_LONG
Definition Language.h:866
@ LANG_ACCOUNT_CREATED
Definition Language.h:865
#define LOG_DEBUG(filterType__,...)
Definition Log.h:170
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:514
Player * GetPlayer() const
Definition WorldSession.h:381
std::string const & GetRemoteAddress()
Definition WorldSession.h:390
AccountOpResult CreateAccount(std::string username, std::string password, std::string email)
Definition AccountMgr.cpp:31

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

317 {
318 if (!*args)
319 return false;
320
322 char* account = strtok((char*)args, " ");
323 if (!account)
324 return false;
325
326 std::string accountName = account;
327 if (!Utf8ToUpperOnlyLatin(accountName))
328 {
329 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
330 return false;
331 }
332
333 uint32 accountId = AccountMgr::GetId(accountName);
334 if (!accountId)
335 {
336 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
337 return false;
338 }
339
343 if (handler->HasLowerSecurityAccount(nullptr, accountId, true))
344 return false;
345
346 AccountOpResult result = AccountMgr::DeleteAccount(accountId);
347 switch (result)
348 {
349 case AOR_OK:
350 handler->PSendSysMessage(LANG_ACCOUNT_DELETED, accountName);
351 break;
353 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
354 return false;
356 handler->SendErrorMessage(LANG_ACCOUNT_NOT_DELETED_SQL_ERROR, accountName.c_str());
357 return false;
358 default:
359 handler->SendErrorMessage(LANG_ACCOUNT_NOT_DELETED, accountName.c_str());
360 return false;
361 }
362
363 return true;
364 }
@ AOR_NAME_NOT_EXIST
Definition AccountMgr.h:32
@ LANG_ACCOUNT_NOT_DELETED_SQL_ERROR
Definition Language.h:863
@ LANG_ACCOUNT_NOT_EXIST
Definition Language.h:448
@ LANG_ACCOUNT_NOT_DELETED
Definition Language.h:864
@ LANG_ACCOUNT_DELETED
Definition Language.h:862
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:95
uint32 GetId(std::string const &username)
Definition AccountMgr.cpp:236

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
451 {
452 if (!*args)
453 {
455 return false;
456 }
457
458 std::string param = (char*)args;
459
460 if (!param.empty())
461 {
462 if (param == "on")
463 {
464 if (IpLocationRecord const* location = sIPLocation->GetLocationRecord(handler->GetSession()->GetRemoteAddress()))
465 {
466 auto* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_ACCOUNT_LOCK_COUNTRY);
467 stmt->SetData(0, location->CountryCode);
468 stmt->SetData(1, handler->GetSession()->GetAccountId());
469 LoginDatabase.Execute(stmt);
471 }
472 else
473 {
474 handler->SendErrorMessage("No IP2Location information - account not locked");
475 return false;
476 }
477 }
478 else if (param == "off")
479 {
480 auto* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_ACCOUNT_LOCK_COUNTRY);
481 stmt->SetData(0, "00");
482 stmt->SetData(1, handler->GetSession()->GetAccountId());
483 LoginDatabase.Execute(stmt);
485 }
486 return true;
487 }
488
490 return false;
491 }
#define sIPLocation
Definition IPLocation.h:49
@ LANG_COMMAND_ACCLOCKLOCKED
Definition Language.h:60
@ LANG_USE_BOL
Definition Language.h:308
@ 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
494 {
495 if (!*args)
496 {
498 return false;
499 }
500
501 std::string param = (char*)args;
502
503 if (!param.empty())
504 {
506
507 if (param == "on")
508 {
509 stmt->SetData(0, true); // locked
511 }
512 else if (param == "off")
513 {
514 stmt->SetData(0, false); // unlocked
516 }
517
518 stmt->SetData(1, handler->GetSession()->GetAccountId());
519
520 LoginDatabase.Execute(stmt);
521 return true;
522 }
523
525 return false;
526 }
@ 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
368 {
371
372 PreparedQueryResult result = CharacterDatabase.Query(stmt);
373
374 if (!result)
375 {
377 return true;
378 }
379
384
386 do
387 {
388 Field* fieldsDB = result->Fetch();
389 std::string name = fieldsDB[0].Get<std::string>();
390 uint32 account = fieldsDB[1].Get<uint32>();
391
393 // No SQL injection. account is uint32.
395 loginStmt->SetData(0, account);
396 PreparedQueryResult resultLogin = LoginDatabase.Query(loginStmt);
397
398 if (resultLogin)
399 {
400 Field* fieldsLogin = resultLogin->Fetch();
402 fieldsLogin[0].Get<std::string>(), name, fieldsLogin[1].Get<std::string>(),
403 fieldsDB[2].Get<uint16>(), fieldsDB[3].Get<uint16>(), fieldsLogin[3].Get<uint8>(),
404 fieldsLogin[2].Get<uint8>());
405 }
406 else
408 } while (result->NextRow());
409
411 return true;
412 }
@ 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:872
@ LANG_ACCOUNT_LIST_EMPTY
Definition Language.h:875
@ LANG_ACCOUNT_LIST_LINE
Definition Language.h:874
@ LANG_ACCOUNT_LIST_HEADER
Definition Language.h:871
@ LANG_ACCOUNT_LIST_BAR
Definition Language.h:873
@ LANG_ACCOUNT_LIST_BAR_HEADER
Definition Language.h:876
@ LOGIN_SEL_ACCOUNT_INFO
Definition LoginDatabase.h:93

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
529 {
530 if (!*args)
531 {
533 return false;
534 }
535
536 char* oldPassword = strtok((char*)args, " ");
537 char* newPassword = strtok(nullptr, " ");
538 char* passwordConfirmation = strtok(nullptr, " ");
539
540 if (!oldPassword || !newPassword || !passwordConfirmation)
541 {
543 return false;
544 }
545
546 if (!AccountMgr::CheckPassword(handler->GetSession()->GetAccountId(), std::string(oldPassword)))
547 {
549 sScriptMgr->OnFailedPasswordChange(handler->GetSession()->GetAccountId());
550 return false;
551 }
552
553 if (strcmp(newPassword, passwordConfirmation) != 0)
554 {
556 sScriptMgr->OnFailedPasswordChange(handler->GetSession()->GetAccountId());
557 return false;
558 }
559
560 AccountOpResult result = AccountMgr::ChangePassword(handler->GetSession()->GetAccountId(), std::string(newPassword));
561 switch (result)
562 {
563 case AOR_OK:
565 sScriptMgr->OnPasswordChange(handler->GetSession()->GetAccountId());
566 break;
569 sScriptMgr->OnFailedPasswordChange(handler->GetSession()->GetAccountId());
570 return false;
571 default:
573 return false;
574 }
575
576 return true;
577 }
@ 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:279
AccountOpResult ChangePassword(uint32 accountId, std::string newPassword)
Definition AccountMgr.cpp:205

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

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
580 {
581 if (!*args)
582 {
584 return false;
585 }
586
587 char* _account = strtok((char*)args, " ");
588 char* _secret = strtok(nullptr, " ");
589
590 if (!_account || !_secret)
591 {
593 return false;
594 }
595
596 std::string accountName = _account;
597 std::string secret = _secret;
598
599 if (!Utf8ToUpperOnlyLatin(accountName))
600 {
601 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName);
602 return false;
603 }
604
605 uint32 targetAccountId = AccountMgr::GetId(accountName);
606 if (!targetAccountId)
607 {
608 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName);
609 return false;
610 }
611
612 if (handler->HasLowerSecurityAccount(nullptr, targetAccountId, true))
613 return false;
614
615 if (secret == "off")
616 {
617 auto* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_ACCOUNT_TOTP_SECRET);
618 stmt->SetData(0);
619 stmt->SetData(1, targetAccountId);
620 LoginDatabase.Execute(stmt);
622 return true;
623 }
624
625 auto const& masterKey = sSecretMgr->GetSecret(SECRET_TOTP_MASTER_KEY);
626 if (!masterKey.IsAvailable())
627 {
629 return false;
630 }
631
633 if (!decoded)
634 {
636 return false;
637 }
638
640 {
642 return false;
643 }
644
645 if (masterKey)
646 Acore::Crypto::AEEncryptWithRandomIV<Acore::Crypto::AES>(*decoded, *masterKey);
647
648 auto* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_ACCOUNT_TOTP_SECRET);
649 stmt->SetData(0, *decoded);
650 stmt->SetData(1, targetAccountId);
651 LoginDatabase.Execute(stmt);
652
653 handler->PSendSysMessage(LANG_2FA_SECRET_SET_COMPLETE, accountName);
654 return true;
655 }
@ LANG_2FA_SECRET_TOO_LONG
Definition Language.h:227
@ LANG_2FA_SECRET_INVALID
Definition Language.h:228
@ LANG_2FA_SECRET_SET_COMPLETE
Definition Language.h:229
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
666 {
668 char* account = strtok((char*)args, " ");
669 char* exp = strtok(nullptr, " ");
670
671 if (!account)
672 return false;
673
674 std::string accountName;
675 uint32 accountId;
676
677 if (!exp)
678 {
679 Player* player = handler->getSelectedPlayer();
680 if (!player)
681 return false;
682
683 accountId = player->GetSession()->GetAccountId();
684 AccountMgr::GetName(accountId, accountName);
685 exp = account;
686 }
687 else
688 {
690 accountName = account;
691 if (!Utf8ToUpperOnlyLatin(accountName))
692 {
693 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName);
694 return false;
695 }
696
697 accountId = AccountMgr::GetId(accountName);
698 if (!accountId)
699 {
700 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName);
701 return false;
702 }
703 }
704
705 // Let set addon state only for lesser (strong) security level
706 // or to self account
707 if (handler->GetSession() && handler->GetSession()->GetAccountId() != accountId &&
708 handler->HasLowerSecurityAccount(nullptr, accountId, true))
709 return false;
710
711 auto expansion = Acore::StringTo<uint8>(exp); //get int anyway (0 if error)
712 if (!expansion || *expansion > sWorld->getIntConfig(CONFIG_EXPANSION))
713 return false;
714
716
717 stmt->SetData(0, *expansion);
718 stmt->SetData(1, accountId);
719
720 LoginDatabase.Execute(stmt);
721
722 handler->PSendSysMessage(LANG_ACCOUNT_SETADDON, accountName, accountId, *expansion);
723 return true;
724 }
@ LANG_ACCOUNT_SETADDON
Definition Language.h:895
Player * getSelectedPlayer() const
Definition Chat.cpp:374
Definition Player.h:1083
WorldSession * GetSession() const
Definition Player.h:2016
bool GetName(uint32 accountId, std::string &name)
Definition AccountMgr.cpp:264

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.

906 {
907 if (!account || !email.data() || !emailConfirmation.data())
908 return false;
909
910 std::string accountName = account.GetName();
911 if (!Utf8ToUpperOnlyLatin(accountName))
912 {
913 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName);
914 return false;
915 }
916
917 uint32 targetAccountId = account.GetID();
918 if (!targetAccountId)
919 {
920 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName);
921 return false;
922 }
923
924 if (email != emailConfirmation)
925 {
927 return false;
928 }
929
930 AccountOpResult result = AccountMgr::ChangeEmail(targetAccountId, email.data());
931
932 switch (result)
933 {
934 case AOR_OK:
936 break;
938 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName);
939 return false;
942 return false;
943 default:
945 return false;
946 }
947 return true;
948 }
@ AOR_EMAIL_TOO_LONG
Definition AccountMgr.h:30
@ LANG_COMMAND_EMAIL
Definition Language.h:837
@ LANG_NEW_EMAILS_NOT_MATCH
Definition Language.h:836
@ LANG_COMMAND_NOTCHANGEEMAIL
Definition Language.h:839
@ LANG_EMAIL_TOO_LONG
Definition Language.h:838
AccountOpResult ChangeEmail(uint32 accountId, std::string newEmail)
Definition AccountMgr.cpp:68
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
727 {
728 if (!*args)
729 return false;
730
731 std::string targetAccountName;
732 uint32 targetAccountId = 0;
733 uint32 targetSecurity = 0;
734 uint32 gm = 0;
735 char* arg1 = strtok((char*)args, " ");
736 char* arg2 = strtok(nullptr, " ");
737 char* arg3 = strtok(nullptr, " ");
738 bool isAccountNameGiven = true;
739
740 if (arg1 && !arg3)
741 {
742 if (!handler->getSelectedPlayer())
743 return false;
744 isAccountNameGiven = false;
745 }
746
747 // Check for second parameter
748 if (!isAccountNameGiven && !arg2)
749 return false;
750
751 // Check for account
752 if (isAccountNameGiven)
753 {
754 targetAccountName = arg1;
755 if (!Utf8ToUpperOnlyLatin(targetAccountName))
756 {
757 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, targetAccountName);
758 return false;
759 }
760 }
761
762 // Check for invalid specified GM level.
763 gm = (isAccountNameGiven) ? Acore::StringTo<int32>(arg2).value_or(0) : Acore::StringTo<int32>(arg1).value_or(0);
764 if (gm > SEC_CONSOLE)
765 {
767 return false;
768 }
769
770 // handler->getSession() == nullptr only for console
771 targetAccountId = (isAccountNameGiven) ? AccountMgr::GetId(targetAccountName) : handler->getSelectedPlayer()->GetSession()->GetAccountId();
772 int32 gmRealmID = (isAccountNameGiven) ? Acore::StringTo<int32>(arg3).value_or(0) : Acore::StringTo<int32>(arg2).value_or(0);
773 uint32 playerSecurity;
774 if (handler->GetSession())
775 playerSecurity = AccountMgr::GetSecurity(handler->GetSession()->GetAccountId(), gmRealmID);
776 else
777 playerSecurity = SEC_CONSOLE;
778
779 // can set security level only for target with less security and to less security that we have
780 // This is also reject self apply in fact
781 targetSecurity = AccountMgr::GetSecurity(targetAccountId, gmRealmID);
782 if (targetSecurity >= playerSecurity || gm >= playerSecurity)
783 {
785 return false;
786 }
787
788 // Check and abort if the target gm has a higher rank on one of the realms and the new realm is -1
789 if (gmRealmID == -1 && !AccountMgr::IsConsoleAccount(playerSecurity))
790 {
792
793 stmt->SetData(0, targetAccountId);
794 stmt->SetData(1, uint8(gm));
795
796 PreparedQueryResult result = LoginDatabase.Query(stmt);
797
798 if (result)
799 {
801 return false;
802 }
803 }
804
805 // Check if provided realm.Id.Realm has a negative value other than -1
806 if (gmRealmID < -1)
807 {
809 return false;
810 }
811
812 // If gmRealmID is -1, delete all values for the account id, else, insert values for the specific realm.Id.Realm
814
815 if (gmRealmID == -1)
816 {
817 stmt = LoginDatabase.GetPreparedStatement(LOGIN_DEL_ACCOUNT_ACCESS);
818 stmt->SetData(0, targetAccountId);
819 }
820 else
821 {
822 stmt = LoginDatabase.GetPreparedStatement(LOGIN_DEL_ACCOUNT_ACCESS_BY_REALM);
823 stmt->SetData(0, targetAccountId);
824 stmt->SetData(1, realm.Id.Realm);
825 }
826
827 LoginDatabase.Execute(stmt);
828
829 if (gm != 0)
830 {
831 stmt = LoginDatabase.GetPreparedStatement(LOGIN_INS_ACCOUNT_ACCESS);
832
833 stmt->SetData(0, targetAccountId);
834 stmt->SetData(1, uint8(gm));
835 stmt->SetData(2, gmRealmID);
836
837 LoginDatabase.Execute(stmt);
838 }
839
840 handler->PSendSysMessage(LANG_YOU_CHANGE_SECURITY, targetAccountName, gm);
841 return true;
842 }
std::int32_t int32
Definition Define.h:103
@ LANG_YOU_CHANGE_SECURITY
Definition Language.h:433
@ LANG_YOURS_SECURITY_IS_LOW
Definition Language.h:435
@ LANG_INVALID_REALMID
Definition Language.h:1294
@ 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:94
Realm realm
Definition World.cpp:111
bool IsConsoleAccount(uint32 gmlevel)
Definition AccountMgr.cpp:327
uint32 GetSecurity(uint32 accountId)
Definition AccountMgr.cpp:245
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

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

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: