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
 
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. More...
 
static bool HandleAccountDeleteCommand (ChatHandler *handler, char const *args)
 
static bool HandleAccountOnlineListCommand (ChatHandler *handler, char const *)
 Display info on users currently in the realm. More...
 
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. More...
 
static bool HandleAccountSetGmLevelCommand (ChatHandler *handler, char const *args)
 
static bool HandleAccountSetPasswordCommand (ChatHandler *handler, char const *args)
 Set password for account. More...
 
static bool HandleAccountSetEmailCommand (ChatHandler *handler, AccountIdentifier account, std::string email, std::string emailConfirmation)
 Set email for account. More...
 

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
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", HandleAccountSetAddonCommand, SEC_GAMEMASTER, Console::Yes },
56 { "gmlevel", HandleAccountSetGmLevelCommand, SEC_ADMINISTRATOR, Console::Yes },
57 { "password", HandleAccountSetPasswordCommand, SEC_ADMINISTRATOR, Console::Yes },
58 { "2fa", HandleAccountSet2FACommand, SEC_PLAYER, Console::Yes },
59 { "email", HandleAccountSetEmailCommand, SEC_ADMINISTRATOR, Console::Yes }
60 };
61
62 static ChatCommandTable accountLockCommandTable
63 {
64 { "country", HandleAccountLockCountryCommand, SEC_PLAYER, Console::Yes },
65 { "ip", HandleAccountLockIpCommand, SEC_PLAYER, Console::Yes }
66 };
67
68 static ChatCommandTable account2faCommandTable
69 {
70 { "setup", HandleAccount2FASetupCommand, SEC_PLAYER, Console::No },
71 { "remove", HandleAccount2FARemoveCommand, SEC_PLAYER, Console::No }
72 };
73
74 static ChatCommandTable accountRemoveCommandTable
75 {
76 { "country", HandleAccountRemoveLockCountryCommand, SEC_ADMINISTRATOR, Console::Yes },
77 };
78
79 static ChatCommandTable accountCommandTable =
80 {
81 { "2fa", account2faCommandTable },
82 { "addon", HandleAccountAddonCommand, SEC_MODERATOR, Console::No },
83 { "create", HandleAccountCreateCommand, SEC_CONSOLE, Console::Yes },
84 { "delete", HandleAccountDeleteCommand, SEC_CONSOLE, Console::Yes },
85 { "onlinelist", HandleAccountOnlineListCommand, SEC_CONSOLE, Console::Yes },
86 { "lock", accountLockCommandTable },
87 { "set", accountSetCommandTable },
88 { "password", HandleAccountPasswordCommand, SEC_PLAYER, Console::No },
89 { "remove", accountRemoveCommandTable },
90 { "", HandleAccountCommand, SEC_PLAYER, Console::No }
91 };
92
93 static ChatCommandTable commandTable =
94 {
95 { "account", accountCommandTable }
96 };
97
98 return commandTable;
99 }
@ 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
std::vector< ChatCommandBuilder > ChatCommandTable
Definition: ChatCommand.h:46
static bool HandleAccountLockIpCommand(ChatHandler *handler, char const *args)
Definition: cs_account.cpp:495
static bool HandleAccountSet2FACommand(ChatHandler *handler, char const *args)
Definition: cs_account.cpp:581
static bool HandleAccountSetGmLevelCommand(ChatHandler *handler, char const *args)
Definition: cs_account.cpp:728
static bool HandleAccountLockCountryCommand(ChatHandler *handler, char const *args)
Definition: cs_account.cpp:452
static bool HandleAccountOnlineListCommand(ChatHandler *handler, char const *)
Display info on users currently in the realm.
Definition: cs_account.cpp:369
static bool HandleAccountDeleteCommand(ChatHandler *handler, char const *args)
Definition: cs_account.cpp:318
static bool HandleAccountPasswordCommand(ChatHandler *handler, char const *args)
Definition: cs_account.cpp:530
static bool HandleAccountRemoveLockCountryCommand(ChatHandler *handler, char const *args)
Definition: cs_account.cpp:416
static bool HandleAccountSetPasswordCommand(ChatHandler *handler, char const *args)
Set password for account.
Definition: cs_account.cpp:847
static bool HandleAccount2FARemoveCommand(ChatHandler *handler, char const *args)
Definition: cs_account.cpp:171
static bool HandleAccountAddonCommand(ChatHandler *handler, char const *args)
Definition: cs_account.cpp:242
static bool HandleAccountSetAddonCommand(ChatHandler *handler, char const *args)
Set/Unset the expansion level for an account.
Definition: cs_account.cpp:667
static bool HandleAccountCommand(ChatHandler *handler, char const *)
Definition: cs_account.cpp:659
static bool HandleAccountSetEmailCommand(ChatHandler *handler, AccountIdentifier account, std::string email, std::string emailConfirmation)
Set email for account.
Definition: cs_account.cpp:906
static bool HandleAccount2FASetupCommand(ChatHandler *handler, char const *args)
Definition: cs_account.cpp:101
static bool HandleAccountCreateCommand(ChatHandler *handler, char const *args)
Create an account.
Definition: cs_account.cpp:273

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
172 {
173 if (!*args)
174 {
176 return false;
177 }
178
179 auto token = Acore::StringTo<uint32>(args);
180
181 auto const& masterKey = sSecretMgr->GetSecret(SECRET_TOTP_MASTER_KEY);
182 if (!masterKey.IsAvailable())
183 {
185 return false;
186 }
187
188 uint32 const accountId = handler->GetSession()->GetAccountId();
190 { // get current TOTP secret
191 auto* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_ACCOUNT_TOTP_SECRET);
192 stmt->SetData(0, accountId);
193 PreparedQueryResult result = LoginDatabase.Query(stmt);
194
195 if (!result)
196 {
197 LOG_ERROR("misc", "Account {} not found in login database when processing .account 2fa setup command.", accountId);
199 return false;
200 }
201
202 Field* field = result->Fetch();
203 if (field->IsNull())
204 { // 2FA not enabled
206 return false;
207 }
208
209 secret = field->Get<Binary>();
210 }
211
212 if (token)
213 {
214 if (masterKey)
215 {
216 bool success = Acore::Crypto::AEDecrypt<Acore::Crypto::AES>(secret, *masterKey);
217 if (!success)
218 {
219 LOG_ERROR("misc", "Account {} has invalid ciphertext in TOTP token.", accountId);
221 return false;
222 }
223 }
224
225 if (Acore::Crypto::TOTP::ValidateToken(secret, *token))
226 {
227 auto* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_ACCOUNT_TOTP_SECRET);
228 stmt->SetData(0);
229 stmt->SetData(1, accountId);
230 LoginDatabase.Execute(stmt);
232 return true;
233 }
234 else
236 }
237
239 return false;
240 }
#define LOG_ERROR(filterType__,...)
Definition: Log.h:157
std::uint32_t uint32
Definition: Define.h:107
#define sSecretMgr
Definition: SecretMgr.h:72
@ SECRET_TOTP_MASTER_KEY
Definition: SecretMgr.h:30
@ 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
@ LOGIN_UPD_ACCOUNT_TOTP_SECRET
Definition: LoginDatabase.h:120
@ LOGIN_SEL_ACCOUNT_TOTP_SECRET
Definition: LoginDatabase.h:119
std::shared_ptr< PreparedResultSet > PreparedQueryResult
Definition: DatabaseEnvFwd.h:45
std::vector< uint8 > Binary
Definition: Field.h:40
DatabaseWorkerPool< LoginDatabaseConnection > LoginDatabase
Accessor to the realm/login database.
Definition: DatabaseEnv.cpp:22
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:98
bool IsNull() const
Definition: Field.h:106
std::enable_if_t< std::is_arithmetic_v< T >, T > Get() const
Definition: Field.h:112
WorldSession * GetSession()
Definition: Chat.h:242
void SendErrorMessage(uint32 entry)
Definition: Chat.cpp:215
virtual void SendSysMessage(std::string_view str, bool escapeCharacters=false)
Definition: Chat.cpp:159
uint32 GetAccountId() const
Definition: WorldSession.h:361

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
102 {
103 if (!*args)
104 {
106 return false;
107 }
108
109 auto token = Acore::StringTo<uint32>(args);
110
111 auto const& masterKey = sSecretMgr->GetSecret(SECRET_TOTP_MASTER_KEY);
112 if (!masterKey.IsAvailable())
113 {
115 return false;
116 }
117
118 uint32 const accountId = handler->GetSession()->GetAccountId();
119
120 { // check if 2FA already enabled
121 auto* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_ACCOUNT_TOTP_SECRET);
122 stmt->SetData(0, accountId);
123 PreparedQueryResult result = LoginDatabase.Query(stmt);
124
125 if (!result)
126 {
127 LOG_ERROR("misc", "Account {} not found in login database when processing .account 2fa setup command.", accountId);
129 return false;
130 }
131
132 if (!result->Fetch()->IsNull())
133 {
135 return false;
136 }
137 }
138
139 // store random suggested secrets
140 static std::unordered_map<uint32, Acore::Crypto::TOTP::Secret> suggestions;
141 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
142
143 if (pair.second) // no suggestion yet, generate random secret
144 Acore::Crypto::GetRandomBytes(pair.first->second);
145
146 if (!pair.second && token) // suggestion already existed and token specified - validate
147 {
148 if (Acore::Crypto::TOTP::ValidateToken(pair.first->second, *token))
149 {
150 if (masterKey)
151 Acore::Crypto::AEEncryptWithRandomIV<Acore::Crypto::AES>(pair.first->second, *masterKey);
152
153 auto* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_ACCOUNT_TOTP_SECRET);
154 stmt->SetData(0, pair.first->second);
155 stmt->SetData(1, accountId);
156 LoginDatabase.Execute(stmt);
157
158 suggestions.erase(pair.first);
160 return true;
161 }
162 else
164 }
165
166 // new suggestion, or no token specified, output TOTP parameters
168 return false;
169 }
@ 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 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
243 {
244 if (!*args)
245 {
247 return false;
248 }
249
250 char* exp = strtok((char*)args, " ");
251
252 uint32 accountId = handler->GetSession()->GetAccountId();
253
254 auto expansion = Acore::StringTo<uint8>(exp); //get int anyway (0 if error)
255 if (!expansion || *expansion > sWorld->getIntConfig(CONFIG_EXPANSION))
256 {
258 return false;
259 }
260
262
263 stmt->SetData(0, *expansion);
264 stmt->SetData(1, accountId);
265
266 LoginDatabase.Execute(stmt);
267
268 handler->PSendSysMessage(LANG_ACCOUNT_ADDON, *expansion);
269 return true;
270 }
@ LANG_IMPROPER_VALUE
Definition: Language.h:94
@ LANG_ACCOUNT_ADDON
Definition: Language.h:93
@ CONFIG_EXPANSION
Definition: IWorld.h:275
@ LOGIN_UPD_EXPANSION
Definition: LoginDatabase.h:67
#define sWorld
Definition: World.h:443
Definition: PreparedStatement.h:157
Acore::Types::is_default< T > SetData(const uint8 index, T value)
Definition: PreparedStatement.h:77
void PSendSysMessage(std::string_view str, bool escapeCharacters=false)
Definition: Chat.cpp:210

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

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
274 {
275 if (!*args)
276 return false;
277
279 char* accountName = strtok((char*)args, " ");
280 char* password = strtok(nullptr, " ");
281 if (!accountName || !password)
282 return false;
283
284 AccountOpResult result = AccountMgr::CreateAccount(std::string(accountName), std::string(password));
285 switch (result)
286 {
287 case AOR_OK:
288 handler->PSendSysMessage(LANG_ACCOUNT_CREATED, accountName);
289 if (handler->GetSession())
290 {
291 LOG_DEBUG("warden", "Account: {} (IP: {}) Character:[{}] ({}) Change Password.",
292 handler->GetSession()->GetAccountId(), handler->GetSession()->GetRemoteAddress(),
293 handler->GetSession()->GetPlayer()->GetName(), handler->GetSession()->GetPlayer()->GetGUID().ToString());
294 }
295 break;
298 return false;
301 return false;
304 return false;
307 return false;
308 default:
309 handler->SendErrorMessage(LANG_ACCOUNT_NOT_CREATED, accountName);
310 return false;
311 }
312
313 return true;
314 }
#define LOG_DEBUG(filterType__,...)
Definition: Log.h:169
@ LANG_ACCOUNT_ALREADY_EXIST
Definition: Language.h:861
@ LANG_ACCOUNT_PASS_TOO_LONG
Definition: Language.h:886
@ LANG_ACCOUNT_NOT_CREATED_SQL_ERROR
Definition: Language.h:862
@ LANG_ACCOUNT_NOT_CREATED
Definition: Language.h:863
@ LANG_ACCOUNT_TOO_LONG
Definition: Language.h:860
@ LANG_ACCOUNT_CREATED
Definition: Language.h:859
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
AccountOpResult CreateAccount(std::string username, std::string password)
Definition: AccountMgr.cpp:30
static ObjectGuid GetGUID(Object const *o)
Definition: Object.h:109
std::string const & GetName() const
Definition: Object.h:458
std::string ToString() const
Definition: ObjectGuid.cpp:47
Player * GetPlayer() const
Definition: WorldSession.h:362
std::string const & GetRemoteAddress()
Definition: WorldSession.h:371

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

319 {
320 if (!*args)
321 return false;
322
324 char* account = strtok((char*)args, " ");
325 if (!account)
326 return false;
327
328 std::string accountName = account;
329 if (!Utf8ToUpperOnlyLatin(accountName))
330 {
331 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
332 return false;
333 }
334
335 uint32 accountId = AccountMgr::GetId(accountName);
336 if (!accountId)
337 {
338 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
339 return false;
340 }
341
345 if (handler->HasLowerSecurityAccount(nullptr, accountId, true))
346 return false;
347
348 AccountOpResult result = AccountMgr::DeleteAccount(accountId);
349 switch (result)
350 {
351 case AOR_OK:
352 handler->PSendSysMessage(LANG_ACCOUNT_DELETED, accountName);
353 break;
355 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
356 return false;
358 handler->SendErrorMessage(LANG_ACCOUNT_NOT_DELETED_SQL_ERROR, accountName.c_str());
359 return false;
360 default:
361 handler->SendErrorMessage(LANG_ACCOUNT_NOT_DELETED, accountName.c_str());
362 return false;
363 }
364
365 return true;
366 }
bool Utf8ToUpperOnlyLatin(std::string &utf8String)
Definition: Util.cpp:532
@ LANG_ACCOUNT_NOT_DELETED_SQL_ERROR
Definition: Language.h:857
@ LANG_ACCOUNT_NOT_EXIST
Definition: Language.h:442
@ LANG_ACCOUNT_NOT_DELETED
Definition: Language.h:858
@ LANG_ACCOUNT_DELETED
Definition: Language.h:856
@ AOR_NAME_NOT_EXIST
Definition: AccountMgr.h:31
AccountOpResult DeleteAccount(uint32 accountId)
Definition: AccountMgr.cpp:88
uint32 GetId(std::string const &username)
Definition: AccountMgr.cpp:229
bool HasLowerSecurityAccount(WorldSession *target, uint32 account, bool strong=false)
Definition: Chat.cpp:75

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
453 {
454 if (!*args)
455 {
457 return false;
458 }
459
460 std::string param = (char*)args;
461
462 if (!param.empty())
463 {
464 if (param == "on")
465 {
466 if (IpLocationRecord const* location = sIPLocation->GetLocationRecord(handler->GetSession()->GetRemoteAddress()))
467 {
468 auto* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_ACCOUNT_LOCK_COUNTRY);
469 stmt->SetData(0, location->CountryCode);
470 stmt->SetData(1, handler->GetSession()->GetAccountId());
471 LoginDatabase.Execute(stmt);
473 }
474 else
475 {
476 handler->SendErrorMessage("No IP2Location information - account not locked");
477 return false;
478 }
479 }
480 else if (param == "off")
481 {
482 auto* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_ACCOUNT_LOCK_COUNTRY);
483 stmt->SetData(0, "00");
484 stmt->SetData(1, handler->GetSession()->GetAccountId());
485 LoginDatabase.Execute(stmt);
487 }
488 return true;
489 }
490
492 return false;
493 }
#define sIPLocation
Definition: IPLocation.h:49
@ LANG_COMMAND_ACCLOCKLOCKED
Definition: Language.h:60
@ LANG_USE_BOL
Definition: Language.h:303
@ 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
496 {
497 if (!*args)
498 {
500 return false;
501 }
502
503 std::string param = (char*)args;
504
505 if (!param.empty())
506 {
508
509 if (param == "on")
510 {
511 stmt->SetData(0, true); // locked
513 }
514 else if (param == "off")
515 {
516 stmt->SetData(0, false); // unlocked
518 }
519
520 stmt->SetData(1, handler->GetSession()->GetAccountId());
521
522 LoginDatabase.Execute(stmt);
523 return true;
524 }
525
527 return false;
528 }
@ 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
370 {
373
374 PreparedQueryResult result = CharacterDatabase.Query(stmt);
375
376 if (!result)
377 {
379 return true;
380 }
381
386
388 do
389 {
390 Field* fieldsDB = result->Fetch();
391 std::string name = fieldsDB[0].Get<std::string>();
392 uint32 account = fieldsDB[1].Get<uint32>();
393
395 // No SQL injection. account is uint32.
397 loginStmt->SetData(0, account);
398 PreparedQueryResult resultLogin = LoginDatabase.Query(loginStmt);
399
400 if (resultLogin)
401 {
402 Field* fieldsLogin = resultLogin->Fetch();
404 fieldsLogin[0].Get<std::string>(), name, fieldsLogin[1].Get<std::string>(),
405 fieldsDB[2].Get<uint16>(), fieldsDB[3].Get<uint16>(), fieldsLogin[3].Get<uint8>(),
406 fieldsLogin[2].Get<uint8>());
407 }
408 else
410 } while (result->NextRow());
411
413 return true;
414 }
std::uint8_t uint8
Definition: Define.h:109
std::uint16_t uint16
Definition: Define.h:108
@ LANG_ACCOUNT_LIST_ERROR
Definition: Language.h:866
@ LANG_ACCOUNT_LIST_EMPTY
Definition: Language.h:869
@ LANG_ACCOUNT_LIST_LINE
Definition: Language.h:868
@ LANG_ACCOUNT_LIST_HEADER
Definition: Language.h:865
@ LANG_ACCOUNT_LIST_BAR
Definition: Language.h:867
@ LANG_ACCOUNT_LIST_BAR_HEADER
Definition: Language.h:870
@ CHAR_SEL_CHARACTER_ONLINE
Definition: CharacterDatabase.h:328
@ LOGIN_SEL_ACCOUNT_INFO
Definition: LoginDatabase.h:91
DatabaseWorkerPool< CharacterDatabaseConnection > CharacterDatabase
Accessor to the character database.
Definition: DatabaseEnv.cpp:21

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
531 {
532 if (!*args)
533 {
535 return false;
536 }
537
538 char* oldPassword = strtok((char*)args, " ");
539 char* newPassword = strtok(nullptr, " ");
540 char* passwordConfirmation = strtok(nullptr, " ");
541
542 if (!oldPassword || !newPassword || !passwordConfirmation)
543 {
545 return false;
546 }
547
548 if (!AccountMgr::CheckPassword(handler->GetSession()->GetAccountId(), std::string(oldPassword)))
549 {
551 sScriptMgr->OnFailedPasswordChange(handler->GetSession()->GetAccountId());
552 return false;
553 }
554
555 if (strcmp(newPassword, passwordConfirmation) != 0)
556 {
558 sScriptMgr->OnFailedPasswordChange(handler->GetSession()->GetAccountId());
559 return false;
560 }
561
562 AccountOpResult result = AccountMgr::ChangePassword(handler->GetSession()->GetAccountId(), std::string(newPassword));
563 switch (result)
564 {
565 case AOR_OK:
567 sScriptMgr->OnPasswordChange(handler->GetSession()->GetAccountId());
568 break;
571 sScriptMgr->OnFailedPasswordChange(handler->GetSession()->GetAccountId());
572 return false;
573 default:
575 return false;
576 }
577
578 return true;
579 }
@ 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:709
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
417 {
418 if (!*args)
419 {
421 return false;
422 }
423
425 char* _accountName = strtok((char*)args, " ");
426 if (!_accountName)
427 return false;
428
429 std::string accountName = _accountName;
430 if (!Utf8ToUpperOnlyLatin(accountName))
431 {
432 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName);
433 return false;
434 }
435
436 uint32 accountId = AccountMgr::GetId(accountName);
437 if (!accountId)
438 {
439 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName);
440 return false;
441 }
442
443 auto* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_ACCOUNT_LOCK_COUNTRY);
444 stmt->SetData(0, "00");
445 stmt->SetData(1, accountId);
446 LoginDatabase.Execute(stmt);
448
449 return true;
450 }

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

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.

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

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

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