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

Public Member Functions

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

Static Public Member Functions

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

Additional Inherited Members

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

Detailed Description

Constructor & Destructor Documentation

◆ account_commandscript()

account_commandscript::account_commandscript ( )
inline
50: CommandScript("account_commandscript") { }
Definition: ScriptMgr.h:850

Member Function Documentation

◆ GetCommands()

ChatCommandTable account_commandscript::GetCommands ( ) const
inlineoverridevirtual

Implements CommandScript.

53 {
54 static ChatCommandTable accountSetCommandTable =
55 {
56 { "addon", SEC_GAMEMASTER, true, &HandleAccountSetAddonCommand, "" },
57 { "gmlevel", SEC_CONSOLE, true, &HandleAccountSetGmLevelCommand, "" },
58 { "password", SEC_CONSOLE, true, &HandleAccountSetPasswordCommand, "" },
59 { "2fa", SEC_PLAYER, true, &HandleAccountSet2FACommand, "" }
60 };
61
62 static ChatCommandTable accountLockCommandTable
63 {
64 { "country", SEC_PLAYER, true, &HandleAccountLockCountryCommand, "" },
65 { "ip", SEC_PLAYER, true, &HandleAccountLockIpCommand, "" }
66 };
67
68 static ChatCommandTable account2faCommandTable
69 {
70 { "setup", SEC_PLAYER, false, &HandleAccount2FASetupCommand, "" },
71 { "remove", SEC_PLAYER, false, &HandleAccount2FARemoveCommand, "" },
72 };
73
74 static ChatCommandTable accountRemoveCommandTable
75 {
77 };
78
79 static ChatCommandTable accountCommandTable =
80 {
81 { "2fa", SEC_PLAYER, true, nullptr, "", account2faCommandTable },
82 { "addon", SEC_MODERATOR, false, &HandleAccountAddonCommand, "" },
83 { "create", SEC_CONSOLE, true, &HandleAccountCreateCommand, "" },
84 { "delete", SEC_CONSOLE, true, &HandleAccountDeleteCommand, "" },
85 { "onlinelist", SEC_CONSOLE, true, &HandleAccountOnlineListCommand, "" },
86 { "lock", SEC_PLAYER, false, nullptr, "", accountLockCommandTable },
87 { "set", SEC_ADMINISTRATOR, true, nullptr, "", accountSetCommandTable },
88 { "password", SEC_PLAYER, false, &HandleAccountPasswordCommand, "" },
89 { "remove", SEC_ADMINISTRATOR, true, nullptr, "", accountRemoveCommandTable },
90 { "", SEC_PLAYER, false, &HandleAccountCommand, "" }
91 };
92
93 static ChatCommandTable commandTable =
94 {
95 { "account", SEC_PLAYER, true, nullptr, "", accountCommandTable }
96 };
97
98 return commandTable;
99 }
@ SEC_PLAYER
Definition: Common.h:66
@ SEC_ADMINISTRATOR
Definition: Common.h:69
@ SEC_GAMEMASTER
Definition: Common.h:68
@ SEC_MODERATOR
Definition: Common.h:67
@ SEC_CONSOLE
Definition: Common.h:70
std::vector< ChatCommandBuilder > ChatCommandTable
Definition: ChatCommand.h:50
static bool HandleAccountLockIpCommand(ChatHandler *handler, char const *args)
Definition: cs_account.cpp:524
static bool HandleAccountSet2FACommand(ChatHandler *handler, char const *args)
Definition: cs_account.cpp:618
static bool HandleAccountSetGmLevelCommand(ChatHandler *handler, char const *args)
Definition: cs_account.cpp:774
static bool HandleAccountLockCountryCommand(ChatHandler *handler, char const *args)
Definition: cs_account.cpp:478
static bool HandleAccountOnlineListCommand(ChatHandler *handler, char const *)
Display info on users currently in the realm.
Definition: cs_account.cpp:392
static bool HandleAccountDeleteCommand(ChatHandler *handler, char const *args)
Definition: cs_account.cpp:336
static bool HandleAccountPasswordCommand(ChatHandler *handler, char const *args)
Definition: cs_account.cpp:561
static bool HandleAccountRemoveLockCountryCommand(ChatHandler *handler, char const *args)
Definition: cs_account.cpp:439
static bool HandleAccountSetPasswordCommand(ChatHandler *handler, char const *args)
Set password for account.
Definition: cs_account.cpp:898
static bool HandleAccount2FARemoveCommand(ChatHandler *handler, char const *args)
Definition: cs_account.cpp:176
static bool HandleAccountAddonCommand(ChatHandler *handler, char const *args)
Definition: cs_account.cpp:253
static bool HandleAccountSetAddonCommand(ChatHandler *handler, char const *args)
Set/Unset the expansion level for an account.
Definition: cs_account.cpp:711
static bool HandleAccountCommand(ChatHandler *handler, char const *)
Definition: cs_account.cpp:703
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:286

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

◆ HandleAccount2FARemoveCommand()

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

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

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, ChatHandler::PSendSysMessage(), Acore::Crypto::TOTP::RECOMMENDED_SECRET_LENGTH, SECRET_TOTP_MASTER_KEY, ChatHandler::SendSysMessage(), ChatHandler::SetSentErrorMessage(), sSecretMgr, and Acore::Crypto::TOTP::ValidateToken().

Referenced by GetCommands().

◆ HandleAccountAddonCommand()

static bool account_commandscript::HandleAccountAddonCommand ( ChatHandler handler,
char const *  args 
)
inlinestatic
254 {
255 if (!*args)
256 {
258 handler->SetSentErrorMessage(true);
259 return false;
260 }
261
262 char* exp = strtok((char*)args, " ");
263
264 uint32 accountId = handler->GetSession()->GetAccountId();
265
266 auto expansion = Acore::StringTo<uint8>(exp); //get int anyway (0 if error)
267 if (!expansion || *expansion > sWorld->getIntConfig(CONFIG_EXPANSION))
268 {
270 handler->SetSentErrorMessage(true);
271 return false;
272 }
273
275
276 stmt->SetData(0, *expansion);
277 stmt->SetData(1, accountId);
278
279 LoginDatabase.Execute(stmt);
280
281 handler->PSendSysMessage(LANG_ACCOUNT_ADDON, *expansion);
282 return true;
283 }
@ LOGIN_UPD_EXPANSION
Definition: LoginDatabase.h:67
@ LANG_IMPROPER_VALUE
Definition: Language.h:94
@ LANG_ACCOUNT_ADDON
Definition: Language.h:93
@ CONFIG_EXPANSION
Definition: IWorld.h:274
#define sWorld
Definition: World.h:451
Definition: PreparedStatement.h:158
Acore::Types::is_default< T > SetData(const uint8 index, T value)
Definition: PreparedStatement.h:78

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

Referenced by GetCommands().

◆ HandleAccountCommand()

static bool account_commandscript::HandleAccountCommand ( ChatHandler handler,
char const *   
)
inlinestatic
704 {
705 AccountTypes gmLevel = handler->GetSession()->GetSecurity();
706 handler->PSendSysMessage(LANG_ACCOUNT_LEVEL, uint32(gmLevel));
707 return true;
708 }
AccountTypes
Definition: Common.h:65
@ LANG_ACCOUNT_LEVEL
Definition: Language.h:43
AccountTypes GetSecurity() const
Definition: WorldSession.h:358

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
287 {
288 if (!*args)
289 return false;
290
292 char* accountName = strtok((char*)args, " ");
293 char* password = strtok(nullptr, " ");
294 if (!accountName || !password)
295 return false;
296
297 AccountOpResult result = AccountMgr::CreateAccount(std::string(accountName), std::string(password));
298 switch (result)
299 {
300 case AOR_OK:
301 handler->PSendSysMessage(LANG_ACCOUNT_CREATED, accountName);
302 if (handler->GetSession())
303 {
304 LOG_DEBUG("warden", "Account: {} (IP: {}) Character:[{}] ({}) Change Password.",
305 handler->GetSession()->GetAccountId(), handler->GetSession()->GetRemoteAddress(),
306 handler->GetSession()->GetPlayer()->GetName(), handler->GetSession()->GetPlayer()->GetGUID().ToString());
307 }
308 break;
311 handler->SetSentErrorMessage(true);
312 return false;
315 handler->SetSentErrorMessage(true);
316 return false;
319 handler->SetSentErrorMessage(true);
320 return false;
323 handler->SetSentErrorMessage(true);
324 return false;
325 default:
326 handler->PSendSysMessage(LANG_ACCOUNT_NOT_CREATED, accountName);
327 handler->SetSentErrorMessage(true);
328 return false;
329 }
330
331 return true;
332 }
#define LOG_DEBUG(filterType__,...)
Definition: Log.h:171
AccountOpResult
Definition: AccountMgr.h:25
@ AOR_DB_INTERNAL_ERROR
Definition: AccountMgr.h:31
@ AOR_OK
Definition: AccountMgr.h:26
@ AOR_NAME_ALREADY_EXIST
Definition: AccountMgr.h:29
@ AOR_NAME_TOO_LONG
Definition: AccountMgr.h:27
@ AOR_PASS_TOO_LONG
Definition: AccountMgr.h:28
@ LANG_ACCOUNT_ALREADY_EXIST
Definition: Language.h:834
@ LANG_ACCOUNT_PASS_TOO_LONG
Definition: Language.h:859
@ LANG_ACCOUNT_NOT_CREATED_SQL_ERROR
Definition: Language.h:835
@ LANG_ACCOUNT_NOT_CREATED
Definition: Language.h:836
@ LANG_ACCOUNT_TOO_LONG
Definition: Language.h:833
@ LANG_ACCOUNT_CREATED
Definition: Language.h:832
AccountOpResult CreateAccount(std::string username, std::string password)
Definition: AccountMgr.cpp:30
static ObjectGuid GetGUID(Object const *o)
Definition: Object.h:106
std::string const & GetName() const
Definition: Object.h:446
std::string ToString() const
Definition: ObjectGuid.cpp:47
Player * GetPlayer() const
Definition: WorldSession.h:361
std::string const & GetRemoteAddress()
Definition: WorldSession.h:370

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::SendSysMessage(), ChatHandler::SetSentErrorMessage(), 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

337 {
338 if (!*args)
339 return false;
340
342 char* account = strtok((char*)args, " ");
343 if (!account)
344 return false;
345
346 std::string accountName = account;
347 if (!Utf8ToUpperOnlyLatin(accountName))
348 {
349 handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
350 handler->SetSentErrorMessage(true);
351 return false;
352 }
353
354 uint32 accountId = AccountMgr::GetId(accountName);
355 if (!accountId)
356 {
357 handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
358 handler->SetSentErrorMessage(true);
359 return false;
360 }
361
365 if (handler->HasLowerSecurityAccount(nullptr, accountId, true))
366 return false;
367
368 AccountOpResult result = AccountMgr::DeleteAccount(accountId);
369 switch (result)
370 {
371 case AOR_OK:
372 handler->PSendSysMessage(LANG_ACCOUNT_DELETED, accountName.c_str());
373 break;
375 handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
376 handler->SetSentErrorMessage(true);
377 return false;
379 handler->PSendSysMessage(LANG_ACCOUNT_NOT_DELETED_SQL_ERROR, accountName.c_str());
380 handler->SetSentErrorMessage(true);
381 return false;
382 default:
383 handler->PSendSysMessage(LANG_ACCOUNT_NOT_DELETED, accountName.c_str());
384 handler->SetSentErrorMessage(true);
385 return false;
386 }
387
388 return true;
389 }
bool Utf8ToUpperOnlyLatin(std::string &utf8String)
Definition: Util.cpp:528
@ AOR_NAME_NOT_EXIST
Definition: AccountMgr.h:30
@ LANG_ACCOUNT_NOT_DELETED_SQL_ERROR
Definition: Language.h:830
@ LANG_ACCOUNT_NOT_EXIST
Definition: Language.h:425
@ LANG_ACCOUNT_NOT_DELETED
Definition: Language.h:831
@ LANG_ACCOUNT_DELETED
Definition: Language.h:829
AccountOpResult DeleteAccount(uint32 accountId)
Definition: AccountMgr.cpp:61
uint32 GetId(std::string const &username)
Definition: AccountMgr.cpp:200
bool HasLowerSecurityAccount(WorldSession *target, uint32 account, bool strong=false)
Definition: Chat.cpp:73

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::SetSentErrorMessage(), and Utf8ToUpperOnlyLatin().

Referenced by GetCommands().

◆ HandleAccountLockCountryCommand()

static bool account_commandscript::HandleAccountLockCountryCommand ( ChatHandler handler,
char const *  args 
)
inlinestatic
479 {
480 if (!*args)
481 {
483 handler->SetSentErrorMessage(true);
484 return false;
485 }
486
487 std::string param = (char*)args;
488
489 if (!param.empty())
490 {
491 if (param == "on")
492 {
493 if (IpLocationRecord const* location = sIPLocation->GetLocationRecord(handler->GetSession()->GetRemoteAddress()))
494 {
495 auto* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_ACCOUNT_LOCK_COUNTRY);
496 stmt->SetData(0, location->CountryCode);
497 stmt->SetData(1, handler->GetSession()->GetAccountId());
498 LoginDatabase.Execute(stmt);
500 }
501 else
502 {
503 handler->PSendSysMessage("No IP2Location information - account not locked");
504 handler->SetSentErrorMessage(true);
505 return false;
506 }
507 }
508 else if (param == "off")
509 {
510 auto* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_ACCOUNT_LOCK_COUNTRY);
511 stmt->SetData(0, "00");
512 stmt->SetData(1, handler->GetSession()->GetAccountId());
513 LoginDatabase.Execute(stmt);
515 }
516 return true;
517 }
518
520 handler->SetSentErrorMessage(true);
521 return false;
522 }
#define sIPLocation
Definition: IPLocation.h:49
@ LOGIN_UPD_ACCOUNT_LOCK_COUNTRY
Definition: LoginDatabase.h:69
@ LANG_COMMAND_ACCLOCKLOCKED
Definition: Language.h:60
@ LANG_USE_BOL
Definition: Language.h:303
@ LANG_COMMAND_ACCLOCKUNLOCKED
Definition: Language.h:61
Definition: IPLocation.h:23

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

Referenced by GetCommands().

◆ HandleAccountLockIpCommand()

static bool account_commandscript::HandleAccountLockIpCommand ( ChatHandler handler,
char const *  args 
)
inlinestatic
525 {
526 if (!*args)
527 {
529 handler->SetSentErrorMessage(true);
530 return false;
531 }
532
533 std::string param = (char*)args;
534
535 if (!param.empty())
536 {
538
539 if (param == "on")
540 {
541 stmt->SetData(0, true); // locked
543 }
544 else if (param == "off")
545 {
546 stmt->SetData(0, false); // unlocked
548 }
549
550 stmt->SetData(1, handler->GetSession()->GetAccountId());
551
552 LoginDatabase.Execute(stmt);
553 return true;
554 }
555
557 handler->SetSentErrorMessage(true);
558 return false;
559 }
@ 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::SendSysMessage(), PreparedStatementBase::SetData(), and ChatHandler::SetSentErrorMessage().

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
393 {
396
397 PreparedQueryResult result = CharacterDatabase.Query(stmt);
398
399 if (!result)
400 {
402 return true;
403 }
404
409
411 do
412 {
413 Field* fieldsDB = result->Fetch();
414 std::string name = fieldsDB[0].Get<std::string>();
415 uint32 account = fieldsDB[1].Get<uint32>();
416
418 // No SQL injection. account is uint32.
420 loginStmt->SetData(0, account);
421 PreparedQueryResult resultLogin = LoginDatabase.Query(loginStmt);
422
423 if (resultLogin)
424 {
425 Field* fieldsLogin = resultLogin->Fetch();
427 fieldsLogin[0].Get<std::string>().c_str(), name.c_str(), fieldsLogin[1].Get<std::string>().c_str(),
428 fieldsDB[2].Get<uint16>(), fieldsDB[3].Get<uint16>(), fieldsLogin[3].Get<uint8>(),
429 fieldsLogin[2].Get<uint8>());
430 }
431 else
432 handler->PSendSysMessage(LANG_ACCOUNT_LIST_ERROR, name.c_str());
433 } while (result->NextRow());
434
436 return true;
437 }
std::uint8_t uint8
Definition: Define.h:110
std::uint16_t uint16
Definition: Define.h:109
DatabaseWorkerPool< CharacterDatabaseConnection > CharacterDatabase
Accessor to the character database.
Definition: DatabaseEnv.cpp:21
@ CHAR_SEL_CHARACTER_ONLINE
Definition: CharacterDatabase.h:328
@ LOGIN_SEL_ACCOUNT_INFO
Definition: LoginDatabase.h:90
@ LANG_ACCOUNT_LIST_ERROR
Definition: Language.h:839
@ LANG_ACCOUNT_LIST_EMPTY
Definition: Language.h:842
@ LANG_ACCOUNT_LIST_LINE
Definition: Language.h:841
@ LANG_ACCOUNT_LIST_HEADER
Definition: Language.h:838
@ LANG_ACCOUNT_LIST_BAR
Definition: Language.h:840
@ LANG_ACCOUNT_LIST_BAR_HEADER
Definition: Language.h:843

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
562 {
563 if (!*args)
564 {
566 handler->SetSentErrorMessage(true);
567 return false;
568 }
569
570 char* oldPassword = strtok((char*)args, " ");
571 char* newPassword = strtok(nullptr, " ");
572 char* passwordConfirmation = strtok(nullptr, " ");
573
574 if (!oldPassword || !newPassword || !passwordConfirmation)
575 {
577 handler->SetSentErrorMessage(true);
578 return false;
579 }
580
581 if (!AccountMgr::CheckPassword(handler->GetSession()->GetAccountId(), std::string(oldPassword)))
582 {
584 sScriptMgr->OnFailedPasswordChange(handler->GetSession()->GetAccountId());
585 handler->SetSentErrorMessage(true);
586 return false;
587 }
588
589 if (strcmp(newPassword, passwordConfirmation) != 0)
590 {
592 sScriptMgr->OnFailedPasswordChange(handler->GetSession()->GetAccountId());
593 handler->SetSentErrorMessage(true);
594 return false;
595 }
596
597 AccountOpResult result = AccountMgr::ChangePassword(handler->GetSession()->GetAccountId(), std::string(newPassword));
598 switch (result)
599 {
600 case AOR_OK:
602 sScriptMgr->OnPasswordChange(handler->GetSession()->GetAccountId());
603 break;
606 sScriptMgr->OnFailedPasswordChange(handler->GetSession()->GetAccountId());
607 handler->SetSentErrorMessage(true);
608 return false;
609 default:
611 handler->SetSentErrorMessage(true);
612 return false;
613 }
614
615 return true;
616 }
@ 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:2702
bool CheckPassword(uint32 accountId, std::string password)
Definition: AccountMgr.cpp:243
AccountOpResult ChangePassword(uint32 accountId, std::string newPassword)
Definition: AccountMgr.cpp:169

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

Referenced by GetCommands().

◆ HandleAccountRemoveLockCountryCommand()

static bool account_commandscript::HandleAccountRemoveLockCountryCommand ( ChatHandler handler,
char const *  args 
)
inlinestatic
  • Parse the command line arguments
440 {
441 if (!*args)
442 {
444 handler->SetSentErrorMessage(true);
445 return false;
446 }
447
449 char* _accountName = strtok((char*)args, " ");
450 if (!_accountName)
451 return false;
452
453 std::string accountName = _accountName;
454 if (!Utf8ToUpperOnlyLatin(accountName))
455 {
456 handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
457 handler->SetSentErrorMessage(true);
458 return false;
459 }
460
461 uint32 accountId = AccountMgr::GetId(accountName);
462 if (!accountId)
463 {
464 handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
465 handler->SetSentErrorMessage(true);
466 return false;
467 }
468
469 auto* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_ACCOUNT_LOCK_COUNTRY);
470 stmt->SetData(0, "00");
471 stmt->SetData(1, accountId);
472 LoginDatabase.Execute(stmt);
474
475 return true;
476 }

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

Referenced by GetCommands().

◆ HandleAccountSet2FACommand()

static bool account_commandscript::HandleAccountSet2FACommand ( ChatHandler handler,
char const *  args 
)
inlinestatic
619 {
620 if (!*args)
621 {
623 handler->SetSentErrorMessage(true);
624 return false;
625 }
626
627 char* _account = strtok((char*)args, " ");
628 char* _secret = strtok(nullptr, " ");
629
630 if (!_account || !_secret)
631 {
633 handler->SetSentErrorMessage(true);
634 return false;
635 }
636
637 std::string accountName = _account;
638 std::string secret = _secret;
639
640 if (!Utf8ToUpperOnlyLatin(accountName))
641 {
642 handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
643 handler->SetSentErrorMessage(true);
644 return false;
645 }
646
647 uint32 targetAccountId = AccountMgr::GetId(accountName);
648 if (!targetAccountId)
649 {
650 handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
651 handler->SetSentErrorMessage(true);
652 return false;
653 }
654
655 if (handler->HasLowerSecurityAccount(nullptr, targetAccountId, true))
656 return false;
657
658 if (secret == "off")
659 {
660 auto* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_ACCOUNT_TOTP_SECRET);
661 stmt->SetData(0);
662 stmt->SetData(1, targetAccountId);
663 LoginDatabase.Execute(stmt);
665 return true;
666 }
667
668 auto const& masterKey = sSecretMgr->GetSecret(SECRET_TOTP_MASTER_KEY);
669 if (!masterKey.IsAvailable())
670 {
672 handler->SetSentErrorMessage(true);
673 return false;
674 }
675
677 if (!decoded)
678 {
680 handler->SetSentErrorMessage(true);
681 return false;
682 }
683
685 {
687 handler->SetSentErrorMessage(true);
688 return false;
689 }
690
691 if (masterKey)
692 Acore::Crypto::AEEncryptWithRandomIV<Acore::Crypto::AES>(*decoded, *masterKey);
693
694 auto* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_ACCOUNT_TOTP_SECRET);
695 stmt->SetData(0, *decoded);
696 stmt->SetData(1, targetAccountId);
697 LoginDatabase.Execute(stmt);
698
699 handler->PSendSysMessage(LANG_2FA_SECRET_SET_COMPLETE, accountName.c_str());
700 return true;
701 }
std::optional< T > Optional
Optional helper class to wrap optional values within.
Definition: Optional.h:24
@ LANG_2FA_SECRET_TOO_LONG
Definition: Language.h:222
@ LANG_2FA_SECRET_INVALID
Definition: Language.h:223
@ LANG_2FA_SECRET_SET_COMPLETE
Definition: Language.h:224
static constexpr size_t TAG_SIZE_BYTES
Definition: AES.h:32
static constexpr size_t IV_SIZE_BYTES
Definition: AES.h:30
static Optional< std::vector< uint8 > > Decode(std::string const &data)
Definition: Base32.cpp:40

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::SendSysMessage(), ChatHandler::SetSentErrorMessage(), 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
712 {
714 char* account = strtok((char*)args, " ");
715 char* exp = strtok(nullptr, " ");
716
717 if (!account)
718 return false;
719
720 std::string accountName;
721 uint32 accountId;
722
723 if (!exp)
724 {
725 Player* player = handler->getSelectedPlayer();
726 if (!player)
727 return false;
728
729 accountId = player->GetSession()->GetAccountId();
730 AccountMgr::GetName(accountId, accountName);
731 exp = account;
732 }
733 else
734 {
736 accountName = account;
737 if (!Utf8ToUpperOnlyLatin(accountName))
738 {
739 handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
740 handler->SetSentErrorMessage(true);
741 return false;
742 }
743
744 accountId = AccountMgr::GetId(accountName);
745 if (!accountId)
746 {
747 handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
748 handler->SetSentErrorMessage(true);
749 return false;
750 }
751 }
752
753 // Let set addon state only for lesser (strong) security level
754 // or to self account
755 if (handler->GetSession() && handler->GetSession()->GetAccountId() != accountId &&
756 handler->HasLowerSecurityAccount(nullptr, accountId, true))
757 return false;
758
759 auto expansion = Acore::StringTo<uint8>(exp); //get int anyway (0 if error)
760 if (!expansion || *expansion > sWorld->getIntConfig(CONFIG_EXPANSION))
761 return false;
762
764
765 stmt->SetData(0, *expansion);
766 stmt->SetData(1, accountId);
767
768 LoginDatabase.Execute(stmt);
769
770 handler->PSendSysMessage(LANG_ACCOUNT_SETADDON, accountName.c_str(), accountId, *expansion);
771 return true;
772 }
@ LANG_ACCOUNT_SETADDON
Definition: Language.h:862
bool GetName(uint32 accountId, std::string &name)
Definition: AccountMgr.cpp:228
Player * getSelectedPlayer() const
Definition: Chat.cpp:301
Definition: Player.h:1046
WorldSession * GetSession() const
Definition: Player.h:1948

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

Referenced by GetCommands().

◆ HandleAccountSetGmLevelCommand()

static bool account_commandscript::HandleAccountSetGmLevelCommand ( ChatHandler handler,
char const *  args 
)
inlinestatic
775 {
776 if (!*args)
777 return false;
778
779 std::string targetAccountName;
780 uint32 targetAccountId = 0;
781 uint32 targetSecurity = 0;
782 uint32 gm = 0;
783 char* arg1 = strtok((char*)args, " ");
784 char* arg2 = strtok(nullptr, " ");
785 char* arg3 = strtok(nullptr, " ");
786 bool isAccountNameGiven = true;
787
788 if (arg1 && !arg3)
789 {
790 if (!handler->getSelectedPlayer())
791 return false;
792 isAccountNameGiven = false;
793 }
794
795 // Check for second parameter
796 if (!isAccountNameGiven && !arg2)
797 return false;
798
799 // Check for account
800 if (isAccountNameGiven)
801 {
802 targetAccountName = arg1;
803 if (!Utf8ToUpperOnlyLatin(targetAccountName))
804 {
805 handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, targetAccountName.c_str());
806 handler->SetSentErrorMessage(true);
807 return false;
808 }
809 }
810
811 // Check for invalid specified GM level.
812 gm = (isAccountNameGiven) ? Acore::StringTo<int32>(arg2).value_or(0) : Acore::StringTo<int32>(arg1).value_or(0);
813 if (gm > SEC_CONSOLE)
814 {
816 handler->SetSentErrorMessage(true);
817 return false;
818 }
819
820 // handler->getSession() == nullptr only for console
821 targetAccountId = (isAccountNameGiven) ? AccountMgr::GetId(targetAccountName) : handler->getSelectedPlayer()->GetSession()->GetAccountId();
822 int32 gmRealmID = (isAccountNameGiven) ? Acore::StringTo<int32>(arg3).value_or(0) : Acore::StringTo<int32>(arg2).value_or(0);
823 uint32 playerSecurity;
824 if (handler->GetSession())
825 playerSecurity = AccountMgr::GetSecurity(handler->GetSession()->GetAccountId(), gmRealmID);
826 else
827 playerSecurity = SEC_CONSOLE;
828
829 // can set security level only for target with less security and to less security that we have
830 // This is also reject self apply in fact
831 targetSecurity = AccountMgr::GetSecurity(targetAccountId, gmRealmID);
832 if (targetSecurity >= playerSecurity || gm >= playerSecurity)
833 {
835 handler->SetSentErrorMessage(true);
836 return false;
837 }
838
839 // Check and abort if the target gm has a higher rank on one of the realms and the new realm is -1
840 if (gmRealmID == -1 && !AccountMgr::IsConsoleAccount(playerSecurity))
841 {
843
844 stmt->SetData(0, targetAccountId);
845 stmt->SetData(1, uint8(gm));
846
847 PreparedQueryResult result = LoginDatabase.Query(stmt);
848
849 if (result)
850 {
852 handler->SetSentErrorMessage(true);
853 return false;
854 }
855 }
856
857 // Check if provided realm.Id.Realm has a negative value other than -1
858 if (gmRealmID < -1)
859 {
861 handler->SetSentErrorMessage(true);
862 return false;
863 }
864
865 // If gmRealmID is -1, delete all values for the account id, else, insert values for the specific realm.Id.Realm
867
868 if (gmRealmID == -1)
869 {
870 stmt = LoginDatabase.GetPreparedStatement(LOGIN_DEL_ACCOUNT_ACCESS);
871 stmt->SetData(0, targetAccountId);
872 }
873 else
874 {
875 stmt = LoginDatabase.GetPreparedStatement(LOGIN_DEL_ACCOUNT_ACCESS_BY_REALM);
876 stmt->SetData(0, targetAccountId);
877 stmt->SetData(1, realm.Id.Realm);
878 }
879
880 LoginDatabase.Execute(stmt);
881
882 if (gm != 0)
883 {
884 stmt = LoginDatabase.GetPreparedStatement(LOGIN_INS_ACCOUNT_ACCESS);
885
886 stmt->SetData(0, targetAccountId);
887 stmt->SetData(1, uint8(gm));
888 stmt->SetData(2, gmRealmID);
889
890 LoginDatabase.Execute(stmt);
891 }
892
893 handler->PSendSysMessage(LANG_YOU_CHANGE_SECURITY, targetAccountName.c_str(), gm);
894 return true;
895 }
std::int32_t int32
Definition: Define.h:104
@ LOGIN_DEL_ACCOUNT_ACCESS_BY_REALM
Definition: LoginDatabase.h:79
@ LOGIN_DEL_ACCOUNT_ACCESS
Definition: LoginDatabase.h:78
@ LOGIN_INS_ACCOUNT_ACCESS
Definition: LoginDatabase.h:80
@ LOGIN_SEL_ACCOUNT_ACCESS_GMLEVEL_TEST
Definition: LoginDatabase.h:91
@ LANG_YOU_CHANGE_SECURITY
Definition: Language.h:410
@ LANG_YOURS_SECURITY_IS_LOW
Definition: Language.h:412
@ LANG_INVALID_REALMID
Definition: Language.h:1286
@ LANG_BAD_VALUE
Definition: Language.h:147
Realm realm
Definition: World.cpp:113
bool IsConsoleAccount(uint32 gmlevel)
Definition: AccountMgr.cpp:291
uint32 GetSecurity(uint32 accountId)
Definition: AccountMgr.cpp:209
uint32 Realm
Definition: Realm.h:42
RealmHandle Id
Definition: Realm.h:68

References WorldSession::GetAccountId(), AccountMgr::GetId(), AccountMgr::GetSecurity(), ChatHandler::getSelectedPlayer(), ChatHandler::GetSession(), Player::GetSession(), Realm::Id, AccountMgr::IsConsoleAccount(), LANG_ACCOUNT_NOT_EXIST, LANG_BAD_VALUE, LANG_INVALID_REALMID, LANG_YOU_CHANGE_SECURITY, LANG_YOURS_SECURITY_IS_LOW, LOGIN_DEL_ACCOUNT_ACCESS, LOGIN_DEL_ACCOUNT_ACCESS_BY_REALM, LOGIN_INS_ACCOUNT_ACCESS, LOGIN_SEL_ACCOUNT_ACCESS_GMLEVEL_TEST, LoginDatabase, ChatHandler::PSendSysMessage(), realm, RealmHandle::Realm, SEC_CONSOLE, ChatHandler::SendSysMessage(), PreparedStatementBase::SetData(), ChatHandler::SetSentErrorMessage(), 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

899 {
900 if (!*args)
901 return false;
902
904 char* account = strtok((char*)args, " ");
905 char* password = strtok(nullptr, " ");
906 char* passwordConfirmation = strtok(nullptr, " ");
907
908 if (!account || !password || !passwordConfirmation)
909 return false;
910
911 std::string accountName = account;
912 if (!Utf8ToUpperOnlyLatin(accountName))
913 {
914 handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
915 handler->SetSentErrorMessage(true);
916 return false;
917 }
918
919 uint32 targetAccountId = AccountMgr::GetId(accountName);
920 if (!targetAccountId)
921 {
922 handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
923 handler->SetSentErrorMessage(true);
924 return false;
925 }
926
929 if (handler->HasLowerSecurityAccount(nullptr, targetAccountId, true))
930 return false;
931
932 if (strcmp(password, passwordConfirmation))
933 {
935 handler->SetSentErrorMessage(true);
936 return false;
937 }
938
939 AccountOpResult result = AccountMgr::ChangePassword(targetAccountId, password);
940
941 switch (result)
942 {
943 case AOR_OK:
945 break;
947 handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
948 handler->SetSentErrorMessage(true);
949 return false;
952 handler->SetSentErrorMessage(true);
953 return false;
954 default:
956 handler->SetSentErrorMessage(true);
957 return false;
958 }
959 return true;
960 }

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::PSendSysMessage(), ChatHandler::SendSysMessage(), ChatHandler::SetSentErrorMessage(), and Utf8ToUpperOnlyLatin().

Referenced by GetCommands().