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
43: CommandScript("account_commandscript") { }
Definition CommandScript.h:25

Member Function Documentation

◆ GetCommands()

ChatCommandTable account_commandscript::GetCommands ( ) const
inlineoverridevirtual

Implements CommandScript.

46 {
47 static ChatCommandTable accountSetCommandTable =
48 {
54 };
55
56 static ChatCommandTable accountLockCommandTable
57 {
60 };
61
62 static ChatCommandTable account2faCommandTable
63 {
66 };
67
68 static ChatCommandTable accountRemoveCommandTable
69 {
71 };
72
73 static ChatCommandTable accountCommandTable =
74 {
75 { "2fa", account2faCommandTable },
80 { "lock", accountLockCommandTable },
81 { "set", accountSetCommandTable },
83 { "remove", accountRemoveCommandTable },
85 };
86
87 static ChatCommandTable commandTable =
88 {
89 { "account", accountCommandTable }
90 };
91
92 return commandTable;
93 }
static bool HandleAccountLockIpCommand(ChatHandler *handler, char const *args)
Definition cs_account.cpp:494
static bool HandleAccountSet2FACommand(ChatHandler *handler, char const *args)
Definition cs_account.cpp:580
static bool HandleAccountSetGmLevelCommand(ChatHandler *handler, char const *args)
Definition cs_account.cpp:737
static bool HandleAccountLockCountryCommand(ChatHandler *handler, char const *args)
Definition cs_account.cpp:451
static bool HandleAccountOnlineListCommand(ChatHandler *handler, char const *)
Display info on users currently in the realm.
Definition cs_account.cpp:368
static bool HandleAccountDeleteCommand(ChatHandler *handler, char const *args)
Definition cs_account.cpp:317
static bool HandleAccountPasswordCommand(ChatHandler *handler, char const *args)
Definition cs_account.cpp:529
static bool HandleAccountRemoveLockCountryCommand(ChatHandler *handler, char const *args)
Definition cs_account.cpp:415
static bool HandleAccountSetPasswordCommand(ChatHandler *handler, char const *args)
Set password for account.
Definition cs_account.cpp:856
static bool HandleAccount2FARemoveCommand(ChatHandler *handler, char const *args)
Definition cs_account.cpp:165
static bool HandleAccountAddonCommand(ChatHandler *handler, char const *args)
Definition cs_account.cpp:236
static bool HandleAccountSetAddonCommand(ChatHandler *handler, char const *args)
Set/Unset the expansion level for an account.
Definition cs_account.cpp:676
static bool HandleAccountCommand(ChatHandler *handler, char const *)
Definition cs_account.cpp:658
static bool HandleAccountSetEmailCommand(ChatHandler *handler, AccountIdentifier account, std::string email, std::string emailConfirmation)
Set email for account.
Definition cs_account.cpp:915
static bool HandleAccount2FASetupCommand(ChatHandler *handler, char const *args)
Definition cs_account.cpp:95
static bool HandleAccountCreateCommand(ChatHandler *handler, char const *args)
Create an account.
Definition cs_account.cpp:267
std::vector< ChatCommandBuilder > ChatCommandTable
Definition ChatCommand.h:46
@ RBAC_PERM_COMMAND_ACCOUNT_DELETE
Definition RBAC.h:124
@ RBAC_PERM_COMMAND_ACCOUNT_SET_ADDON
Definition RBAC.h:131
@ RBAC_PERM_COMMAND_ACCOUNT_SET_SECLEVEL
Definition RBAC.h:132
@ RBAC_PERM_COMMAND_ACCOUNT_SET
Definition RBAC.h:130
@ RBAC_PERM_COMMAND_ACCOUNT_ADDON
Definition RBAC.h:122
@ RBAC_PERM_COMMAND_ACCOUNT_ONLINE_LIST
Definition RBAC.h:128
@ RBAC_PERM_COMMAND_ACCOUNT
Definition RBAC.h:121
@ RBAC_PERM_COMMAND_ACCOUNT_CREATE
Definition RBAC.h:123
@ RBAC_PERM_COMMAND_ACCOUNT_SET_SEC_EMAIL
Definition RBAC.h:162
@ RBAC_PERM_COMMAND_ACCOUNT_PASSWORD
Definition RBAC.h:129
@ RBAC_PERM_COMMAND_ACCOUNT_LOCK_COUNTRY
Definition RBAC.h:126
@ RBAC_PERM_COMMAND_ACCOUNT_LOCK_IP
Definition RBAC.h:127
@ RBAC_PERM_COMMAND_ACCOUNT_SET_PASSWORD
Definition RBAC.h:133

References HandleAccount2FARemoveCommand(), HandleAccount2FASetupCommand(), HandleAccountAddonCommand(), HandleAccountCommand(), HandleAccountCreateCommand(), HandleAccountDeleteCommand(), HandleAccountLockCountryCommand(), HandleAccountLockIpCommand(), HandleAccountOnlineListCommand(), HandleAccountPasswordCommand(), HandleAccountRemoveLockCountryCommand(), HandleAccountSet2FACommand(), HandleAccountSetAddonCommand(), HandleAccountSetEmailCommand(), HandleAccountSetGmLevelCommand(), HandleAccountSetPasswordCommand(), rbac::RBAC_PERM_COMMAND_ACCOUNT, rbac::RBAC_PERM_COMMAND_ACCOUNT_ADDON, rbac::RBAC_PERM_COMMAND_ACCOUNT_CREATE, rbac::RBAC_PERM_COMMAND_ACCOUNT_DELETE, rbac::RBAC_PERM_COMMAND_ACCOUNT_LOCK_COUNTRY, rbac::RBAC_PERM_COMMAND_ACCOUNT_LOCK_IP, rbac::RBAC_PERM_COMMAND_ACCOUNT_ONLINE_LIST, rbac::RBAC_PERM_COMMAND_ACCOUNT_PASSWORD, rbac::RBAC_PERM_COMMAND_ACCOUNT_SET, rbac::RBAC_PERM_COMMAND_ACCOUNT_SET_ADDON, rbac::RBAC_PERM_COMMAND_ACCOUNT_SET_PASSWORD, rbac::RBAC_PERM_COMMAND_ACCOUNT_SET_SEC_EMAIL, and rbac::RBAC_PERM_COMMAND_ACCOUNT_SET_SECLEVEL.

◆ HandleAccount2FARemoveCommand()

static bool account_commandscript::HandleAccount2FARemoveCommand ( ChatHandler handler,
char const *  args 
)
inlinestatic
166 {
167 if (!*args)
168 {
170 return false;
171 }
172
173 auto token = Acore::StringTo<uint32>(args);
174
175 auto const& masterKey = sSecretMgr->GetSecret(SECRET_TOTP_MASTER_KEY);
176 if (!masterKey.IsAvailable())
177 {
179 return false;
180 }
181
182 uint32 const accountId = handler->GetSession()->GetAccountId();
184 { // get current TOTP secret
185 auto* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_ACCOUNT_TOTP_SECRET);
186 stmt->SetData(0, accountId);
187 PreparedQueryResult result = LoginDatabase.Query(stmt);
188
189 if (!result)
190 {
191 LOG_ERROR("misc", "Account {} not found in login database when processing .account 2fa setup command.", accountId);
193 return false;
194 }
195
196 Field* field = result->Fetch();
197 if (field->IsNull())
198 { // 2FA not enabled
200 return false;
201 }
202
203 secret = field->Get<Binary>();
204 }
205
206 if (token)
207 {
208 if (masterKey)
209 {
210 bool success = Acore::Crypto::AEDecrypt<Acore::Crypto::AES>(secret, *masterKey);
211 if (!success)
212 {
213 LOG_ERROR("misc", "Account {} has invalid ciphertext in TOTP token.", accountId);
215 return false;
216 }
217 }
218
219 if (Acore::Crypto::TOTP::ValidateToken(secret, *token))
220 {
221 auto* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_ACCOUNT_TOTP_SECRET);
222 stmt->SetData(0);
223 stmt->SetData(1, accountId);
224 LoginDatabase.Execute(stmt);
226 return true;
227 }
228 else
230 }
231
233 return false;
234 }
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:120
@ LANG_2FA_REMOVE_NEED_TOKEN
Definition Language.h:127
@ LANG_2FA_NOT_SETUP
Definition Language.h:126
@ LANG_2FA_INVALID_TOKEN
Definition Language.h:123
@ LANG_CMD_SYNTAX
Definition Language.h:42
@ LANG_2FA_COMMANDS_NOT_SETUP
Definition Language.h:121
@ LANG_2FA_REMOVE_COMPLETE
Definition Language.h:128
#define LOG_ERROR(filterType__,...)
Definition Log.h:145
@ LOGIN_UPD_ACCOUNT_TOTP_SECRET
Definition LoginDatabase.h:132
@ LOGIN_SEL_ACCOUNT_TOTP_SECRET
Definition LoginDatabase.h:131
#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:224
virtual void SendSysMessage(std::string_view str, bool escapeCharacters=false)
Definition Chat.cpp:168
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:453
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
96 {
97 if (!*args)
98 {
100 return false;
101 }
102
103 auto token = Acore::StringTo<uint32>(args);
104
105 auto const& masterKey = sSecretMgr->GetSecret(SECRET_TOTP_MASTER_KEY);
106 if (!masterKey.IsAvailable())
107 {
109 return false;
110 }
111
112 uint32 const accountId = handler->GetSession()->GetAccountId();
113
114 { // check if 2FA already enabled
115 auto* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_ACCOUNT_TOTP_SECRET);
116 stmt->SetData(0, accountId);
117 PreparedQueryResult result = LoginDatabase.Query(stmt);
118
119 if (!result)
120 {
121 LOG_ERROR("misc", "Account {} not found in login database when processing .account 2fa setup command.", accountId);
123 return false;
124 }
125
126 if (!result->Fetch()->IsNull())
127 {
129 return false;
130 }
131 }
132
133 // store random suggested secrets
134 static std::unordered_map<uint32, Acore::Crypto::TOTP::Secret> suggestions;
135 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
136
137 if (pair.second) // no suggestion yet, generate random secret
138 Acore::Crypto::GetRandomBytes(pair.first->second);
139
140 if (!pair.second && token) // suggestion already existed and token specified - validate
141 {
142 if (Acore::Crypto::TOTP::ValidateToken(pair.first->second, *token))
143 {
144 if (masterKey)
145 Acore::Crypto::AEEncryptWithRandomIV<Acore::Crypto::AES>(pair.first->second, *masterKey);
146
147 auto* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_ACCOUNT_TOTP_SECRET);
148 stmt->SetData(0, pair.first->second);
149 stmt->SetData(1, accountId);
150 LoginDatabase.Execute(stmt);
151
152 suggestions.erase(pair.first);
154 return true;
155 }
156 else
158 }
159
160 // new suggestion, or no token specified, output TOTP parameters
162 return false;
163 }
@ LANG_2FA_ALREADY_SETUP
Definition Language.h:122
@ LANG_2FA_SECRET_SUGGESTION
Definition Language.h:124
@ LANG_2FA_SETUP_COMPLETE
Definition Language.h:125
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
237 {
238 if (!*args)
239 {
241 return false;
242 }
243
244 char* exp = strtok((char*)args, " ");
245
246 uint32 accountId = handler->GetSession()->GetAccountId();
247
248 auto expansion = Acore::StringTo<uint8>(exp); //get int anyway (0 if error)
249 if (!expansion || *expansion > sWorld->getIntConfig(CONFIG_EXPANSION))
250 {
252 return false;
253 }
254
256
257 stmt->SetData(0, *expansion);
258 stmt->SetData(1, accountId);
259
260 LoginDatabase.Execute(stmt);
261
262 handler->PSendSysMessage(LANG_ACCOUNT_ADDON, *expansion);
263 return true;
264 }
@ 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:228
void PSendSysMessage(std::string_view str, bool escapeCharacters=false)
Definition Chat.cpp:219
Acore::Types::is_default< T > SetData(const uint8 index, T value)
Definition PreparedStatement.h:77
Definition PreparedStatement.h:157
#define sWorld
Definition World.h:317

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

Referenced by GetCommands().

◆ HandleAccountCommand()

static bool account_commandscript::HandleAccountCommand ( ChatHandler handler,
char const *   
)
inlinestatic
659 {
660 AccountTypes gmLevel = handler->GetSession()->GetSecurity();
661 handler->PSendSysMessage(LANG_ACCOUNT_LEVEL, uint32(gmLevel));
662
664 {
666 stmt->SetData(0, handler->GetSession()->GetAccountId());
667 PreparedQueryResult result = LoginDatabase.Query(stmt);
668 if (result)
669 handler->PSendSysMessage(LANG_COMMAND_EMAIL_OUTPUT, (*result)[0].Get<std::string>());
670 }
671
672 return true;
673 }
AccountTypes
Definition Common.h:56
@ LANG_COMMAND_EMAIL_OUTPUT
Definition Language.h:847
@ LANG_ACCOUNT_LEVEL
Definition Language.h:43
@ LOGIN_GET_EMAIL_BY_ID
Definition LoginDatabase.h:136
AccountTypes GetSecurity() const
Definition WorldSession.h:441
bool HasPermission(uint32 permissionId)
Definition WorldSession.cpp:1551
@ RBAC_PERM_MAY_CHECK_OWN_EMAIL
Definition RBAC.h:101

References WorldSession::GetAccountId(), WorldSession::GetSecurity(), ChatHandler::GetSession(), WorldSession::HasPermission(), LANG_ACCOUNT_LEVEL, LANG_COMMAND_EMAIL_OUTPUT, LOGIN_GET_EMAIL_BY_ID, LoginDatabase, ChatHandler::PSendSysMessage(), rbac::RBAC_PERM_MAY_CHECK_OWN_EMAIL, and PreparedStatementBase::SetData().

Referenced by GetCommands().

◆ HandleAccountCreateCommand()

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

Create an account.

  • Parse the command line arguments
268 {
269 if (!*args)
270 return false;
271
273 char* accountName = strtok((char*)args, " ");
274 char* password = strtok(nullptr, " ");
275 char* email = strtok(nullptr, " ");
276
277 if (!accountName || !password)
278 return false;
279
280 // if email is not specified, use empty string
281 std::string emailStr = email ? email : "";
282
283 AccountOpResult result = sAccountMgr->CreateAccount(std::string(accountName), std::string(password), emailStr);
284 switch (result)
285 {
286 case AOR_OK:
287 handler->PSendSysMessage(LANG_ACCOUNT_CREATED, accountName);
288 if (handler->GetSession())
289 {
290 LOG_DEBUG("warden", "Account: {} (IP: {}) Character:[{}] ({}) Change Password.",
291 handler->GetSession()->GetAccountId(), handler->GetSession()->GetRemoteAddress(),
292 handler->GetSession()->GetPlayer()->GetName(), handler->GetSession()->GetPlayer()->GetGUID().ToString());
293 }
294 break;
297 return false;
300 return false;
303 return false;
306 return false;
307 default:
308 handler->SendErrorMessage(LANG_ACCOUNT_NOT_CREATED, accountName);
309 return false;
310 }
311
312 return true;
313 }
AccountOpResult
Definition AccountMgr.h:24
@ AOR_DB_INTERNAL_ERROR
Definition AccountMgr.h:31
@ AOR_OK
Definition AccountMgr.h:25
@ AOR_NAME_ALREADY_EXIST
Definition AccountMgr.h:29
@ AOR_NAME_TOO_LONG
Definition AccountMgr.h:26
@ AOR_PASS_TOO_LONG
Definition AccountMgr.h:27
#define sAccountMgr
Definition AccountMgr.h:93
@ LANG_ACCOUNT_ALREADY_EXIST
Definition Language.h:873
@ LANG_ACCOUNT_PASS_TOO_LONG
Definition Language.h:898
@ LANG_ACCOUNT_NOT_CREATED_SQL_ERROR
Definition Language.h:874
@ LANG_ACCOUNT_NOT_CREATED
Definition Language.h:875
@ LANG_ACCOUNT_TOO_LONG
Definition Language.h:872
@ LANG_ACCOUNT_CREATED
Definition Language.h:871
#define LOG_DEBUG(filterType__,...)
Definition Log.h:157
std::string ToString() const
Definition ObjectGuid.cpp:47
static ObjectGuid GetGUID(Object const *o)
Definition Object.h:114
std::string const & GetName() const
Definition Object.h:528
Player * GetPlayer() const
Definition WorldSession.h:454
std::string const & GetRemoteAddress()
Definition WorldSession.h:463

References AOR_DB_INTERNAL_ERROR, AOR_NAME_ALREADY_EXIST, AOR_NAME_TOO_LONG, AOR_OK, AOR_PASS_TOO_LONG, 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(), sAccountMgr, ChatHandler::SendErrorMessage(), and ObjectGuid::ToString().

Referenced by GetCommands().

◆ HandleAccountDeleteCommand()

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

Delete a user account and all associated characters in this realm

Todo:
This function has to be enhanced to respect the login/realm split (delete char, delete account chars in realm then delete account)
  • Get the account name from the command line

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

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

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

Referenced by GetCommands().

◆ HandleAccountLockCountryCommand()

static bool account_commandscript::HandleAccountLockCountryCommand ( ChatHandler handler,
char const *  args 
)
inlinestatic
452 {
453 if (!*args)
454 {
456 return false;
457 }
458
459 std::string param = (char*)args;
460
461 if (!param.empty())
462 {
463 if (param == "on")
464 {
465 if (IpLocationRecord const* location = sIPLocation->GetLocationRecord(handler->GetSession()->GetRemoteAddress()))
466 {
467 auto* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_ACCOUNT_LOCK_COUNTRY);
468 stmt->SetData(0, location->CountryCode);
469 stmt->SetData(1, handler->GetSession()->GetAccountId());
470 LoginDatabase.Execute(stmt);
472 }
473 else
474 {
475 handler->SendErrorMessage("No IP2Location information - account not locked");
476 return false;
477 }
478 }
479 else if (param == "off")
480 {
481 auto* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_ACCOUNT_LOCK_COUNTRY);
482 stmt->SetData(0, "00");
483 stmt->SetData(1, handler->GetSession()->GetAccountId());
484 LoginDatabase.Execute(stmt);
486 }
487 return true;
488 }
489
491 return false;
492 }
#define sIPLocation
Definition IPLocation.h:49
@ LANG_COMMAND_ACCLOCKLOCKED
Definition Language.h:60
@ LANG_USE_BOL
Definition Language.h:311
@ 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
495 {
496 if (!*args)
497 {
499 return false;
500 }
501
502 std::string param = (char*)args;
503
504 if (!param.empty())
505 {
507
508 if (param == "on")
509 {
510 stmt->SetData(0, true); // locked
512 }
513 else if (param == "off")
514 {
515 stmt->SetData(0, false); // unlocked
517 }
518
519 stmt->SetData(1, handler->GetSession()->GetAccountId());
520
521 LoginDatabase.Execute(stmt);
522 return true;
523 }
524
526 return false;
527 }
@ LOGIN_UPD_ACCOUNT_LOCK
Definition LoginDatabase.h:68

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

Referenced by GetCommands().

◆ HandleAccountOnlineListCommand()

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

Display info on users currently in the realm.

  • Get the list of accounts ID logged to the realm
  • Display the list of account/characters online
  • Cycle through accounts
  • Get the username, last IP and GM level of each account
369 {
372
373 PreparedQueryResult result = CharacterDatabase.Query(stmt);
374
375 if (!result)
376 {
378 return true;
379 }
380
385
387 do
388 {
389 Field* fieldsDB = result->Fetch();
390 std::string name = fieldsDB[0].Get<std::string>();
391 uint32 account = fieldsDB[1].Get<uint32>();
392
394 // No SQL injection. account is uint32.
396 loginStmt->SetData(0, account);
397 PreparedQueryResult resultLogin = LoginDatabase.Query(loginStmt);
398
399 if (resultLogin)
400 {
401 Field* fieldsLogin = resultLogin->Fetch();
403 fieldsLogin[0].Get<std::string>(), name, fieldsLogin[1].Get<std::string>(),
404 fieldsDB[2].Get<uint16>(), fieldsDB[3].Get<uint16>(), fieldsLogin[3].Get<uint8>(),
405 fieldsLogin[2].Get<uint8>());
406 }
407 else
409 } while (result->NextRow());
410
412 return true;
413 }
@ CHAR_SEL_CHARACTER_ONLINE
Definition CharacterDatabase.h:331
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:878
@ LANG_ACCOUNT_LIST_EMPTY
Definition Language.h:881
@ LANG_ACCOUNT_LIST_LINE
Definition Language.h:880
@ LANG_ACCOUNT_LIST_HEADER
Definition Language.h:877
@ LANG_ACCOUNT_LIST_BAR
Definition Language.h:879
@ LANG_ACCOUNT_LIST_BAR_HEADER
Definition Language.h:882
@ 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
530 {
531 if (!*args)
532 {
534 return false;
535 }
536
537 char* oldPassword = strtok((char*)args, " ");
538 char* newPassword = strtok(nullptr, " ");
539 char* passwordConfirmation = strtok(nullptr, " ");
540
541 if (!oldPassword || !newPassword || !passwordConfirmation)
542 {
544 return false;
545 }
546
547 if (!AccountMgr::CheckPassword(handler->GetSession()->GetAccountId(), std::string(oldPassword)))
548 {
550 sScriptMgr->OnFailedPasswordChange(handler->GetSession()->GetAccountId());
551 return false;
552 }
553
554 if (strcmp(newPassword, passwordConfirmation) != 0)
555 {
557 sScriptMgr->OnFailedPasswordChange(handler->GetSession()->GetAccountId());
558 return false;
559 }
560
561 AccountOpResult result = AccountMgr::ChangePassword(handler->GetSession()->GetAccountId(), std::string(newPassword));
562 switch (result)
563 {
564 case AOR_OK:
566 sScriptMgr->OnPasswordChange(handler->GetSession()->GetAccountId());
567 break;
570 sScriptMgr->OnFailedPasswordChange(handler->GetSession()->GetAccountId());
571 return false;
572 default:
574 return false;
575 }
576
577 return true;
578 }
@ LANG_COMMAND_NOTCHANGEPASSWORD
Definition Language.h:57
@ LANG_PASSWORD_TOO_LONG
Definition Language.h:87
@ LANG_COMMAND_WRONGOLDPASSWORD
Definition Language.h:59
@ LANG_NEW_PASSWORDS_NOT_MATCH
Definition Language.h:86
@ LANG_COMMAND_PASSWORD
Definition Language.h:58
#define sScriptMgr
Definition ScriptMgr.h:737
static bool CheckPassword(uint32 accountId, std::string password)
Definition AccountMgr.cpp:291
static AccountOpResult ChangePassword(uint32 accountId, std::string newPassword)
Definition AccountMgr.cpp:217

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

Referenced by GetCommands().

◆ HandleAccountRemoveLockCountryCommand()

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

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

Referenced by GetCommands().

◆ HandleAccountSet2FACommand()

static bool account_commandscript::HandleAccountSet2FACommand ( ChatHandler handler,
char const *  args 
)
inlinestatic
581 {
582 if (!*args)
583 {
585 return false;
586 }
587
588 char* _account = strtok((char*)args, " ");
589 char* _secret = strtok(nullptr, " ");
590
591 if (!_account || !_secret)
592 {
594 return false;
595 }
596
597 std::string accountName = _account;
598 std::string secret = _secret;
599
600 if (!Utf8ToUpperOnlyLatin(accountName))
601 {
602 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName);
603 return false;
604 }
605
606 uint32 targetAccountId = AccountMgr::GetId(accountName);
607 if (!targetAccountId)
608 {
609 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName);
610 return false;
611 }
612
613 if (handler->HasLowerSecurityAccount(nullptr, targetAccountId, true))
614 return false;
615
616 if (secret == "off")
617 {
618 auto* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_ACCOUNT_TOTP_SECRET);
619 stmt->SetData(0);
620 stmt->SetData(1, targetAccountId);
621 LoginDatabase.Execute(stmt);
623 return true;
624 }
625
626 auto const& masterKey = sSecretMgr->GetSecret(SECRET_TOTP_MASTER_KEY);
627 if (!masterKey.IsAvailable())
628 {
630 return false;
631 }
632
634 if (!decoded)
635 {
637 return false;
638 }
639
641 {
643 return false;
644 }
645
646 if (masterKey)
647 Acore::Crypto::AEEncryptWithRandomIV<Acore::Crypto::AES>(*decoded, *masterKey);
648
649 auto* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_ACCOUNT_TOTP_SECRET);
650 stmt->SetData(0, *decoded);
651 stmt->SetData(1, targetAccountId);
652 LoginDatabase.Execute(stmt);
653
654 handler->PSendSysMessage(LANG_2FA_SECRET_SET_COMPLETE, accountName);
655 return true;
656 }
@ LANG_2FA_SECRET_TOO_LONG
Definition Language.h:230
@ LANG_2FA_SECRET_INVALID
Definition Language.h:231
@ LANG_2FA_SECRET_SET_COMPLETE
Definition Language.h:232
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
677 {
679 char* account = strtok((char*)args, " ");
680 char* exp = strtok(nullptr, " ");
681
682 if (!account)
683 return false;
684
685 std::string accountName;
686 uint32 accountId;
687
688 if (!exp)
689 {
690 Player* player = handler->getSelectedPlayer();
691 if (!player)
692 return false;
693
694 accountId = player->GetSession()->GetAccountId();
695 AccountMgr::GetName(accountId, accountName);
696 exp = account;
697 }
698 else
699 {
701 accountName = account;
702 if (!Utf8ToUpperOnlyLatin(accountName))
703 {
704 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName);
705 return false;
706 }
707
708 accountId = AccountMgr::GetId(accountName);
709 if (!accountId)
710 {
711 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName);
712 return false;
713 }
714 }
715
716 // Let set addon state only for lesser (strong) security level
717 // or to self account
718 if (handler->GetSession() && handler->GetSession()->GetAccountId() != accountId &&
719 handler->HasLowerSecurityAccount(nullptr, accountId, true))
720 return false;
721
722 auto expansion = Acore::StringTo<uint8>(exp); //get int anyway (0 if error)
723 if (!expansion || *expansion > sWorld->getIntConfig(CONFIG_EXPANSION))
724 return false;
725
727
728 stmt->SetData(0, *expansion);
729 stmt->SetData(1, accountId);
730
731 LoginDatabase.Execute(stmt);
732
733 handler->PSendSysMessage(LANG_ACCOUNT_SETADDON, accountName, accountId, *expansion);
734 return true;
735 }
@ LANG_ACCOUNT_SETADDON
Definition Language.h:901
static bool GetName(uint32 accountId, std::string &name)
Definition AccountMgr.cpp:276
Player * getSelectedPlayer() const
Definition Chat.cpp:382
Definition Player.h:1084
WorldSession * GetSession() const
Definition Player.h:2020

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.

917 {
918 if (!account || !email.data() || !emailConfirmation.data())
919 return false;
920
921 std::string accountName = account.GetName();
922 if (!Utf8ToUpperOnlyLatin(accountName))
923 {
924 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName);
925 return false;
926 }
927
928 uint32 targetAccountId = account.GetID();
929 if (!targetAccountId)
930 {
931 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName);
932 return false;
933 }
934
935 if (email != emailConfirmation)
936 {
938 return false;
939 }
940
941 AccountOpResult result = AccountMgr::ChangeEmail(targetAccountId, email.data());
942
943 switch (result)
944 {
945 case AOR_OK:
947 break;
949 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName);
950 return false;
953 return false;
954 default:
956 return false;
957 }
958 return true;
959 }
@ AOR_EMAIL_TOO_LONG
Definition AccountMgr.h:28
@ LANG_COMMAND_EMAIL
Definition Language.h:843
@ LANG_NEW_EMAILS_NOT_MATCH
Definition Language.h:842
@ LANG_COMMAND_NOTCHANGEEMAIL
Definition Language.h:845
@ LANG_EMAIL_TOO_LONG
Definition Language.h:844
static AccountOpResult ChangeEmail(uint32 accountId, std::string email)
Definition AccountMgr.cpp:80
uint32 GetID() const
Definition ChatCommandTags.h:159
std::string const & GetName() const
Definition ChatCommandTags.h:160

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
738 {
739 if (!*args)
740 return false;
741
742 std::string targetAccountName;
743 uint32 targetAccountId = 0;
744 uint32 targetSecurity = 0;
745 uint32 gm = 0;
746 char* arg1 = strtok((char*)args, " ");
747 char* arg2 = strtok(nullptr, " ");
748 char* arg3 = strtok(nullptr, " ");
749 bool isAccountNameGiven = true;
750
751 if (arg1 && !arg3)
752 {
753 if (!handler->getSelectedPlayer())
754 return false;
755 isAccountNameGiven = false;
756 }
757
758 // Check for second parameter
759 if (!isAccountNameGiven && !arg2)
760 return false;
761
762 // Check for account
763 if (isAccountNameGiven)
764 {
765 targetAccountName = arg1;
766 if (!Utf8ToUpperOnlyLatin(targetAccountName))
767 {
768 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, targetAccountName);
769 return false;
770 }
771 }
772
773 // Check for invalid specified GM level.
774 gm = (isAccountNameGiven) ? Acore::StringTo<int32>(arg2).value_or(0) : Acore::StringTo<int32>(arg1).value_or(0);
775 if (gm > SEC_CONSOLE)
776 {
778 return false;
779 }
780
781 // handler->getSession() == nullptr only for console
782 targetAccountId = (isAccountNameGiven) ? AccountMgr::GetId(targetAccountName) : handler->getSelectedPlayer()->GetSession()->GetAccountId();
783 int32 gmRealmID = (isAccountNameGiven) ? Acore::StringTo<int32>(arg3).value_or(0) : Acore::StringTo<int32>(arg2).value_or(0);
784 uint32 playerSecurity;
785 if (handler->GetSession())
786 playerSecurity = AccountMgr::GetSecurity(handler->GetSession()->GetAccountId(), gmRealmID);
787 else
788 playerSecurity = SEC_CONSOLE;
789
790 // can set security level only for target with less security and to less security that we have
791 // This is also reject self apply in fact
792 targetSecurity = AccountMgr::GetSecurity(targetAccountId, gmRealmID);
793 if (targetSecurity >= playerSecurity || gm >= playerSecurity)
794 {
796 return false;
797 }
798
799 // Check and abort if the target gm has a higher rank on one of the realms and the new realm is -1
800 if (gmRealmID == -1 && !AccountMgr::IsConsoleAccount(playerSecurity))
801 {
803
804 stmt->SetData(0, targetAccountId);
805 stmt->SetData(1, uint8(gm));
806
807 PreparedQueryResult result = LoginDatabase.Query(stmt);
808
809 if (result)
810 {
812 return false;
813 }
814 }
815
816 // Check if provided realm.Id.Realm has a negative value other than -1
817 if (gmRealmID < -1)
818 {
820 return false;
821 }
822
823 // If gmRealmID is -1, delete all values for the account id, else, insert values for the specific realm.Id.Realm
825
826 if (gmRealmID == -1)
827 {
828 stmt = LoginDatabase.GetPreparedStatement(LOGIN_DEL_ACCOUNT_ACCESS);
829 stmt->SetData(0, targetAccountId);
830 }
831 else
832 {
833 stmt = LoginDatabase.GetPreparedStatement(LOGIN_DEL_ACCOUNT_ACCESS_BY_REALM);
834 stmt->SetData(0, targetAccountId);
835 stmt->SetData(1, realm.Id.Realm);
836 }
837
838 LoginDatabase.Execute(stmt);
839
840 if (gm != 0)
841 {
842 stmt = LoginDatabase.GetPreparedStatement(LOGIN_INS_ACCOUNT_ACCESS);
843
844 stmt->SetData(0, targetAccountId);
845 stmt->SetData(1, uint8(gm));
846 stmt->SetData(2, gmRealmID);
847
848 LoginDatabase.Execute(stmt);
849 }
850
851 handler->PSendSysMessage(LANG_YOU_CHANGE_SECURITY, targetAccountName, gm);
852 return true;
853 }
@ SEC_CONSOLE
Definition Common.h:61
std::int32_t int32
Definition Define.h:103
@ LANG_YOU_CHANGE_SECURITY
Definition Language.h:436
@ LANG_YOURS_SECURITY_IS_LOW
Definition Language.h:438
@ LANG_INVALID_REALMID
Definition Language.h:1367
@ LANG_BAD_VALUE
Definition Language.h:151
@ 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
static bool IsConsoleAccount(uint32 gmlevel)
Definition AccountMgr.cpp:339
static uint32 GetSecurity(uint32 accountId)
Definition AccountMgr.cpp:257
Realm realm
Definition World.cpp:111
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

857 {
858 if (!*args)
859 return false;
860
862 char* account = strtok((char*)args, " ");
863 char* password = strtok(nullptr, " ");
864 char* passwordConfirmation = strtok(nullptr, " ");
865
866 if (!account || !password || !passwordConfirmation)
867 return false;
868
869 std::string accountName = account;
870 if (!Utf8ToUpperOnlyLatin(accountName))
871 {
872 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName);
873 return false;
874 }
875
876 uint32 targetAccountId = AccountMgr::GetId(accountName);
877 if (!targetAccountId)
878 {
879 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName);
880 return false;
881 }
882
885 if (handler->HasLowerSecurityAccount(nullptr, targetAccountId, true))
886 return false;
887
888 if (strcmp(password, passwordConfirmation))
889 {
891 return false;
892 }
893
894 AccountOpResult result = AccountMgr::ChangePassword(targetAccountId, password);
895
896 switch (result)
897 {
898 case AOR_OK:
900 break;
902 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName);
903 return false;
906 return false;
907 default:
909 return false;
910 }
911 return true;
912 }

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: