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 ()
 
std::string const & 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 Optional< uint8ParseAccountFlagBit (std::string_view input)
 
static bool HandleAccountFlagListCommand (ChatHandler *handler, Optional< AccountIdentifier > account)
 
static bool ChangeAccountFlag (ChatHandler *handler, AccountIdentifier const &account, std::string_view flagArg, bool add)
 
static bool HandleAccountFlagAddCommand (ChatHandler *handler, AccountIdentifier account, std::string_view flagArg)
 
static bool HandleAccountFlagRemoveCommand (ChatHandler *handler, AccountIdentifier account, std::string_view flagArg)
 
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 (char const *name)
 
- Protected Member Functions inherited from ScriptObject
 ScriptObject (char const *name, uint16 totalAvailableHooks=0)
 
virtual ~ScriptObject ()=default
 

Detailed Description

Constructor & Destructor Documentation

◆ account_commandscript()

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

Member Function Documentation

◆ ChangeAccountFlag()

static bool account_commandscript::ChangeAccountFlag ( ChatHandler handler,
AccountIdentifier const &  account,
std::string_view  flagArg,
bool  add 
)
inlinestatic
992 {
993 if (handler->HasLowerSecurityAccount(nullptr, account.GetID(), true))
994 return false;
995
997 if (!bit)
998 {
1000 return false;
1001 }
1002
1003 // ACCOUNT_FLAG_GM is handled by GMLevel and should not be allowed to set manually
1004 uint32 const flag = uint32(1) << *bit;
1005 if (flag & ACCOUNT_FLAG_GM)
1006 {
1008 return false;
1009 }
1010
1011 if (WorldSession* session = sWorldSessionMgr->FindSession(account.GetID()))
1012 session->UpdateAccountFlag(flag, !add);
1013 else
1014 LoginDatabase.Execute("UPDATE account SET Flags = Flags {} {} WHERE id = {}",
1015 add ? "|" : "& ~", flag, account.GetID());
1016
1018 accountFlagNames[*bit].full, account.GetName(), account.GetID());
1019 return true;
1020 }
AccountFlagName const accountFlagNames[MAX_ACCOUNT_FLAG]
Definition Common.cpp:33
@ ACCOUNT_FLAG_GM
Definition Common.h:67
DatabaseWorkerPool< LoginDatabaseConnection > LoginDatabase
Accessor to the realm/login database.
Definition DatabaseEnv.cpp:22
std::uint32_t uint32
Definition Define.h:107
@ LANG_ACCOUNT_FLAG_RESERVED
Definition Language.h:1546
@ LANG_ACCOUNT_FLAG_REMOVED
Definition Language.h:1548
@ LANG_ACCOUNT_FLAG_INVALID
Definition Language.h:1545
@ LANG_ACCOUNT_FLAG_ADDED
Definition Language.h:1547
std::optional< T > Optional
Optional helper class to wrap optional values within.
Definition Optional.h:24
#define sWorldSessionMgr
Definition WorldSessionMgr.h:118
void PSendSysMessage(std::string_view str, bool escapeCharacters=false)
Definition Chat.cpp:219
void SendErrorMessage(uint32 entry)
Definition Chat.cpp:224
bool HasLowerSecurityAccount(WorldSession *target, uint32 account, bool strong=false)
Definition Chat.cpp:84
std::string const & GetName() const
Definition ScriptObject.h:53
Player session in the World.
Definition WorldSession.h:409
static Optional< uint8 > ParseAccountFlagBit(std::string_view input)
Definition cs_account.cpp:927

References ACCOUNT_FLAG_GM, accountFlagNames, AccountFlagName::full, Acore::ChatCommands::AccountIdentifier::GetID(), Acore::ChatCommands::AccountIdentifier::GetName(), ChatHandler::HasLowerSecurityAccount(), LANG_ACCOUNT_FLAG_ADDED, LANG_ACCOUNT_FLAG_INVALID, LANG_ACCOUNT_FLAG_REMOVED, LANG_ACCOUNT_FLAG_RESERVED, LoginDatabase, ParseAccountFlagBit(), ChatHandler::PSendSysMessage(), ChatHandler::SendErrorMessage(), and sWorldSessionMgr.

Referenced by HandleAccountFlagAddCommand(), and HandleAccountFlagRemoveCommand().

◆ GetCommands()

ChatCommandTable account_commandscript::GetCommands ( ) const
inlineoverridevirtual

Implements CommandScript.

51 {
52 static ChatCommandTable accountSetCommandTable =
53 {
59 };
60
61 static ChatCommandTable accountLockCommandTable
62 {
65 };
66
67 static ChatCommandTable account2faCommandTable
68 {
71 };
72
73 static ChatCommandTable accountRemoveCommandTable
74 {
76 };
77
78 static ChatCommandTable accountFlagCommandTable
79 {
83 };
84
85 static ChatCommandTable accountCommandTable =
86 {
87 { "2fa", account2faCommandTable },
91 { "flag", accountFlagCommandTable },
93 { "lock", accountLockCommandTable },
94 { "set", accountSetCommandTable },
96 { "remove", accountRemoveCommandTable },
98 };
99
100 static ChatCommandTable commandTable =
101 {
102 { "account", accountCommandTable }
103 };
104
105 return commandTable;
106 }
static bool HandleAccountFlagListCommand(ChatHandler *handler, Optional< AccountIdentifier > account)
Definition cs_account.cpp:936
static bool HandleAccountLockIpCommand(ChatHandler *handler, char const *args)
Definition cs_account.cpp:507
static bool HandleAccountSet2FACommand(ChatHandler *handler, char const *args)
Definition cs_account.cpp:593
static bool HandleAccountSetGmLevelCommand(ChatHandler *handler, char const *args)
Definition cs_account.cpp:750
static bool HandleAccountLockCountryCommand(ChatHandler *handler, char const *args)
Definition cs_account.cpp:464
static bool HandleAccountOnlineListCommand(ChatHandler *handler, char const *)
Display info on users currently in the realm.
Definition cs_account.cpp:381
static bool HandleAccountDeleteCommand(ChatHandler *handler, char const *args)
Definition cs_account.cpp:330
static bool HandleAccountPasswordCommand(ChatHandler *handler, char const *args)
Definition cs_account.cpp:542
static bool HandleAccountRemoveLockCountryCommand(ChatHandler *handler, char const *args)
Definition cs_account.cpp:428
static bool HandleAccountSetPasswordCommand(ChatHandler *handler, char const *args)
Set password for account.
Definition cs_account.cpp:869
static bool HandleAccountFlagAddCommand(ChatHandler *handler, AccountIdentifier account, std::string_view flagArg)
Definition cs_account.cpp:1022
static bool HandleAccount2FARemoveCommand(ChatHandler *handler, char const *args)
Definition cs_account.cpp:178
static bool HandleAccountAddonCommand(ChatHandler *handler, char const *args)
Definition cs_account.cpp:249
static bool HandleAccountSetAddonCommand(ChatHandler *handler, char const *args)
Set/Unset the expansion level for an account.
Definition cs_account.cpp:689
static bool HandleAccountCommand(ChatHandler *handler, char const *)
Definition cs_account.cpp:671
static bool HandleAccountSetEmailCommand(ChatHandler *handler, AccountIdentifier account, std::string email, std::string emailConfirmation)
Set email for account.
Definition cs_account.cpp:1033
static bool HandleAccount2FASetupCommand(ChatHandler *handler, char const *args)
Definition cs_account.cpp:108
static bool HandleAccountCreateCommand(ChatHandler *handler, char const *args)
Create an account.
Definition cs_account.cpp:280
static bool HandleAccountFlagRemoveCommand(ChatHandler *handler, AccountIdentifier account, std::string_view flagArg)
Definition cs_account.cpp:1027
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_FLAG_LIST
Definition RBAC.h:706
@ RBAC_PERM_COMMAND_ACCOUNT_FLAG_REMOVE
Definition RBAC.h:708
@ RBAC_PERM_COMMAND_ACCOUNT_FLAG_ADD
Definition RBAC.h:707
@ 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(), HandleAccountFlagAddCommand(), HandleAccountFlagListCommand(), HandleAccountFlagRemoveCommand(), 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_FLAG_ADD, rbac::RBAC_PERM_COMMAND_ACCOUNT_FLAG_LIST, rbac::RBAC_PERM_COMMAND_ACCOUNT_FLAG_REMOVE, 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
179 {
180 if (!*args)
181 {
183 return false;
184 }
185
186 auto token = Acore::StringTo<uint32>(args);
187
188 auto const& masterKey = sSecretMgr->GetSecret(SECRET_TOTP_MASTER_KEY);
189 if (!masterKey.IsAvailable())
190 {
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 return false;
207 }
208
209 Field* field = result->Fetch();
210 if (field->IsNull())
211 { // 2FA not enabled
213 return false;
214 }
215
216 secret = field->Get<Binary>();
217 }
218
219 if (token)
220 {
221 if (masterKey)
222 {
223 bool success = Acore::Crypto::AEDecrypt<Acore::Crypto::AES>(secret, *masterKey);
224 if (!success)
225 {
226 LOG_ERROR("misc", "Account {} has invalid ciphertext in TOTP token.", accountId);
228 return false;
229 }
230 }
231
232 if (Acore::Crypto::TOTP::ValidateToken(secret, *token))
233 {
234 auto* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_ACCOUNT_TOTP_SECRET);
235 stmt->SetData(0);
236 stmt->SetData(1, accountId);
237 LoginDatabase.Execute(stmt);
239 return true;
240 }
241 else
243 }
244
246 return false;
247 }
std::shared_ptr< PreparedResultSet > PreparedQueryResult
Definition DatabaseEnvFwd.h:45
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:134
@ LOGIN_SEL_ACCOUNT_TOTP_SECRET
Definition LoginDatabase.h:133
#define sSecretMgr
Definition SecretMgr.h:72
@ SECRET_TOTP_MASTER_KEY
Definition SecretMgr.h:30
WorldSession * GetSession()
Definition Chat.h:242
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:479
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
109 {
110 if (!*args)
111 {
113 return false;
114 }
115
116 auto token = Acore::StringTo<uint32>(args);
117
118 auto const& masterKey = sSecretMgr->GetSecret(SECRET_TOTP_MASTER_KEY);
119 if (!masterKey.IsAvailable())
120 {
122 return false;
123 }
124
125 uint32 const accountId = handler->GetSession()->GetAccountId();
126
127 { // check if 2FA already enabled
128 auto* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_ACCOUNT_TOTP_SECRET);
129 stmt->SetData(0, accountId);
130 PreparedQueryResult result = LoginDatabase.Query(stmt);
131
132 if (!result)
133 {
134 LOG_ERROR("misc", "Account {} not found in login database when processing .account 2fa setup command.", accountId);
136 return false;
137 }
138
139 if (!result->Fetch()->IsNull())
140 {
142 return false;
143 }
144 }
145
146 // store random suggested secrets
147 static std::unordered_map<uint32, Acore::Crypto::TOTP::Secret> suggestions;
148 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
149
150 if (pair.second) // no suggestion yet, generate random secret
151 Acore::Crypto::GetRandomBytes(pair.first->second);
152
153 if (!pair.second && token) // suggestion already existed and token specified - validate
154 {
155 if (Acore::Crypto::TOTP::ValidateToken(pair.first->second, *token))
156 {
157 if (masterKey)
158 Acore::Crypto::AEEncryptWithRandomIV<Acore::Crypto::AES>(pair.first->second, *masterKey);
159
160 auto* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_ACCOUNT_TOTP_SECRET);
161 stmt->SetData(0, pair.first->second);
162 stmt->SetData(1, accountId);
163 LoginDatabase.Execute(stmt);
164
165 suggestions.erase(pair.first);
167 return true;
168 }
169 else
171 }
172
173 // new suggestion, or no token specified, output TOTP parameters
175 return false;
176 }
@ 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
250 {
251 if (!*args)
252 {
254 return false;
255 }
256
257 char* exp = strtok((char*)args, " ");
258
259 uint32 accountId = handler->GetSession()->GetAccountId();
260
261 auto expansion = Acore::StringTo<uint8>(exp); //get int anyway (0 if error)
262 if (!expansion || *expansion > sWorld->getIntConfig(CONFIG_EXPANSION))
263 {
265 return false;
266 }
267
269
270 stmt->SetData(0, *expansion);
271 stmt->SetData(1, accountId);
272
273 LoginDatabase.Execute(stmt);
274
275 handler->PSendSysMessage(LANG_ACCOUNT_ADDON, *expansion);
276 return true;
277 }
@ 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:234
Acore::Types::is_default< T > SetData(const uint8 index, T value)
Definition PreparedStatement.h:77
Definition PreparedStatement.h:157
#define sWorld
Definition World.h:318

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
672 {
673 AccountTypes gmLevel = handler->GetSession()->GetSecurity();
674 handler->PSendSysMessage(LANG_ACCOUNT_LEVEL, uint32(gmLevel));
675
677 {
679 stmt->SetData(0, handler->GetSession()->GetAccountId());
680 PreparedQueryResult result = LoginDatabase.Query(stmt);
681 if (result)
682 handler->PSendSysMessage(LANG_COMMAND_EMAIL_OUTPUT, (*result)[0].Get<std::string>());
683 }
684
685 return true;
686 }
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:138
AccountTypes GetSecurity() const
Definition WorldSession.h:467
bool HasPermission(uint32 permissionId)
Definition WorldSession.cpp:1671
@ 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
281 {
282 if (!*args)
283 return false;
284
286 char* accountName = strtok((char*)args, " ");
287 char* password = strtok(nullptr, " ");
288 char* email = strtok(nullptr, " ");
289
290 if (!accountName || !password)
291 return false;
292
293 // if email is not specified, use empty string
294 std::string emailStr = email ? email : "";
295
296 AccountOpResult result = sAccountMgr->CreateAccount(std::string(accountName), std::string(password), emailStr);
297 switch (result)
298 {
299 case AOR_OK:
300 handler->PSendSysMessage(LANG_ACCOUNT_CREATED, accountName);
301 if (handler->GetSession())
302 {
303 LOG_DEBUG("warden", "Account: {} (IP: {}) Character:[{}] ({}) Change Password.",
304 handler->GetSession()->GetAccountId(), handler->GetSession()->GetRemoteAddress(),
305 handler->GetSession()->GetPlayer()->GetName(), handler->GetSession()->GetPlayer()->GetGUID().ToString());
306 }
307 break;
310 return false;
313 return false;
316 return false;
319 return false;
320 default:
321 handler->SendErrorMessage(LANG_ACCOUNT_NOT_CREATED, accountName);
322 return false;
323 }
324
325 return true;
326 }
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:48
static ObjectGuid GetGUID(Object const *o)
Definition Object.h:114
std::string const & GetName() const
Definition Object.h:529
Player * GetPlayer() const
Definition WorldSession.h:480
std::string const & GetRemoteAddress()
Definition WorldSession.h:489

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

331 {
332 if (!*args)
333 return false;
334
336 char* account = strtok((char*)args, " ");
337 if (!account)
338 return false;
339
340 std::string accountName = account;
341 if (!Utf8ToUpperOnlyLatin(accountName))
342 {
343 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
344 return false;
345 }
346
347 uint32 accountId = AccountMgr::GetId(accountName);
348 if (!accountId)
349 {
350 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
351 return false;
352 }
353
357 if (handler->HasLowerSecurityAccount(nullptr, accountId, true))
358 return false;
359
360 AccountOpResult result = AccountMgr::DeleteAccount(accountId);
361 switch (result)
362 {
363 case AOR_OK:
364 handler->PSendSysMessage(LANG_ACCOUNT_DELETED, accountName);
365 break;
367 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
368 return false;
370 handler->SendErrorMessage(LANG_ACCOUNT_NOT_DELETED_SQL_ERROR, accountName.c_str());
371 return false;
372 default:
373 handler->SendErrorMessage(LANG_ACCOUNT_NOT_DELETED, accountName.c_str());
374 return false;
375 }
376
377 return true;
378 }
@ 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

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

◆ HandleAccountFlagAddCommand()

static bool account_commandscript::HandleAccountFlagAddCommand ( ChatHandler handler,
AccountIdentifier  account,
std::string_view  flagArg 
)
inlinestatic
1023 {
1024 return ChangeAccountFlag(handler, account, flagArg, true);
1025 }
static bool ChangeAccountFlag(ChatHandler *handler, AccountIdentifier const &account, std::string_view flagArg, bool add)
Definition cs_account.cpp:991

References ChangeAccountFlag().

Referenced by GetCommands().

◆ HandleAccountFlagListCommand()

static bool account_commandscript::HandleAccountFlagListCommand ( ChatHandler handler,
Optional< AccountIdentifier account 
)
inlinestatic
937 {
938 uint32 accountId;
939 std::string accountName;
940
941 if (account)
942 {
943 accountId = account->GetID();
944 accountName = account->GetName();
945 }
946 else if (WorldSession* session = handler->GetSession())
947 {
948 accountId = session->GetAccountId();
949 AccountMgr::GetName(accountId, accountName);
950 }
951 else
952 {
954 return false;
955 }
956
957 if (handler->HasLowerSecurityAccount(nullptr, accountId, true))
958 return false;
959
960 uint32 flags;
961 if (WorldSession* targetSession = sWorldSessionMgr->FindSession(accountId))
962 flags = targetSession->GetAccountFlags();
963 else
964 {
966 stmt->SetData(0, accountId);
967 PreparedQueryResult result = LoginDatabase.Query(stmt);
968 if (!result)
969 {
970 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName);
971 return false;
972 }
973
974 flags = (*result)[0].Get<uint32>();
975 }
976
977 if (!flags)
978 {
979 handler->PSendSysMessage(LANG_ACCOUNT_FLAG_LIST_EMPTY, accountName, accountId);
980 return true;
981 }
982
983 handler->PSendSysMessage(LANG_ACCOUNT_FLAG_LIST_HEADER, accountName, accountId);
984 for (uint8 i = 0; i < MAX_ACCOUNT_FLAG; ++i)
985 if (flags & (uint32(1) << i))
987
988 return true;
989 }
#define MAX_ACCOUNT_FLAG
Definition Common.h:64
std::uint8_t uint8
Definition Define.h:109
@ LANG_SUBCMDS_LIST_ENTRY
Definition Language.h:233
@ LANG_ACCOUNT_FLAG_LIST_EMPTY
Definition Language.h:1544
@ LANG_ACCOUNT_FLAG_LIST_HEADER
Definition Language.h:1543
@ LOGIN_SEL_ACCOUNT_FLAG
Definition LoginDatabase.h:89
static bool GetName(uint32 accountId, std::string &name)
Definition AccountMgr.cpp:276
char const * full
Definition Common.h:118

References accountFlagNames, AccountFlagName::full, AccountMgr::GetName(), ChatHandler::GetSession(), ChatHandler::HasLowerSecurityAccount(), LANG_ACCOUNT_FLAG_LIST_EMPTY, LANG_ACCOUNT_FLAG_LIST_HEADER, LANG_ACCOUNT_NOT_EXIST, LANG_CMD_SYNTAX, LANG_SUBCMDS_LIST_ENTRY, LOGIN_SEL_ACCOUNT_FLAG, LoginDatabase, MAX_ACCOUNT_FLAG, ChatHandler::PSendSysMessage(), ChatHandler::SendErrorMessage(), PreparedStatementBase::SetData(), and sWorldSessionMgr.

Referenced by GetCommands().

◆ HandleAccountFlagRemoveCommand()

static bool account_commandscript::HandleAccountFlagRemoveCommand ( ChatHandler handler,
AccountIdentifier  account,
std::string_view  flagArg 
)
inlinestatic
1028 {
1029 return ChangeAccountFlag(handler, account, flagArg, false);
1030 }

References ChangeAccountFlag().

Referenced by GetCommands().

◆ HandleAccountLockCountryCommand()

static bool account_commandscript::HandleAccountLockCountryCommand ( ChatHandler handler,
char const *  args 
)
inlinestatic
465 {
466 if (!*args)
467 {
469 return false;
470 }
471
472 std::string param = (char*)args;
473
474 if (!param.empty())
475 {
476 if (param == "on")
477 {
478 if (IpLocationRecord const* location = sIPLocation->GetLocationRecord(handler->GetSession()->GetRemoteAddress()))
479 {
480 auto* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_ACCOUNT_LOCK_COUNTRY);
481 stmt->SetData(0, location->CountryCode);
482 stmt->SetData(1, handler->GetSession()->GetAccountId());
483 LoginDatabase.Execute(stmt);
485 }
486 else
487 {
488 handler->SendErrorMessage("No IP2Location information - account not locked");
489 return false;
490 }
491 }
492 else if (param == "off")
493 {
494 auto* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_ACCOUNT_LOCK_COUNTRY);
495 stmt->SetData(0, "00");
496 stmt->SetData(1, handler->GetSession()->GetAccountId());
497 LoginDatabase.Execute(stmt);
499 }
500 return true;
501 }
502
504 return false;
505 }
#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
508 {
509 if (!*args)
510 {
512 return false;
513 }
514
515 std::string param = (char*)args;
516
517 if (!param.empty())
518 {
520
521 if (param == "on")
522 {
523 stmt->SetData(0, true); // locked
525 }
526 else if (param == "off")
527 {
528 stmt->SetData(0, false); // unlocked
530 }
531
532 stmt->SetData(1, handler->GetSession()->GetAccountId());
533
534 LoginDatabase.Execute(stmt);
535 return true;
536 }
537
539 return false;
540 }
@ 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
382 {
385
386 PreparedQueryResult result = CharacterDatabase.Query(stmt);
387
388 if (!result)
389 {
391 return true;
392 }
393
398
400 do
401 {
402 Field* fieldsDB = result->Fetch();
403 std::string name = fieldsDB[0].Get<std::string>();
404 uint32 account = fieldsDB[1].Get<uint32>();
405
407 // No SQL injection. account is uint32.
409 loginStmt->SetData(0, account);
410 PreparedQueryResult resultLogin = LoginDatabase.Query(loginStmt);
411
412 if (resultLogin)
413 {
414 Field* fieldsLogin = resultLogin->Fetch();
416 fieldsLogin[0].Get<std::string>(), name, fieldsLogin[1].Get<std::string>(),
417 fieldsDB[2].Get<uint16>(), fieldsDB[3].Get<uint16>(), fieldsLogin[3].Get<uint8>(),
418 fieldsLogin[2].Get<uint8>());
419 }
420 else
422 } while (result->NextRow());
423
425 return true;
426 }
@ CHAR_SEL_CHARACTER_ONLINE
Definition CharacterDatabase.h:332
DatabaseWorkerPool< CharacterDatabaseConnection > CharacterDatabase
Accessor to the character database.
Definition DatabaseEnv.cpp:21
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:94

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
543 {
544 if (!*args)
545 {
547 return false;
548 }
549
550 char* oldPassword = strtok((char*)args, " ");
551 char* newPassword = strtok(nullptr, " ");
552 char* passwordConfirmation = strtok(nullptr, " ");
553
554 if (!oldPassword || !newPassword || !passwordConfirmation)
555 {
557 return false;
558 }
559
560 if (!AccountMgr::CheckPassword(handler->GetSession()->GetAccountId(), std::string(oldPassword)))
561 {
563 sScriptMgr->OnFailedPasswordChange(handler->GetSession()->GetAccountId());
564 return false;
565 }
566
567 if (strcmp(newPassword, passwordConfirmation) != 0)
568 {
570 sScriptMgr->OnFailedPasswordChange(handler->GetSession()->GetAccountId());
571 return false;
572 }
573
574 AccountOpResult result = AccountMgr::ChangePassword(handler->GetSession()->GetAccountId(), std::string(newPassword));
575 switch (result)
576 {
577 case AOR_OK:
579 sScriptMgr->OnPasswordChange(handler->GetSession()->GetAccountId());
580 break;
583 sScriptMgr->OnFailedPasswordChange(handler->GetSession()->GetAccountId());
584 return false;
585 default:
587 return false;
588 }
589
590 return true;
591 }
@ 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:743
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
429 {
430 if (!*args)
431 {
433 return false;
434 }
435
437 char* _accountName = strtok((char*)args, " ");
438 if (!_accountName)
439 return false;
440
441 std::string accountName = _accountName;
442 if (!Utf8ToUpperOnlyLatin(accountName))
443 {
444 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName);
445 return false;
446 }
447
448 uint32 accountId = AccountMgr::GetId(accountName);
449 if (!accountId)
450 {
451 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName);
452 return false;
453 }
454
455 auto* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_ACCOUNT_LOCK_COUNTRY);
456 stmt->SetData(0, "00");
457 stmt->SetData(1, accountId);
458 LoginDatabase.Execute(stmt);
460
461 return true;
462 }

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
594 {
595 if (!*args)
596 {
598 return false;
599 }
600
601 char* _account = strtok((char*)args, " ");
602 char* _secret = strtok(nullptr, " ");
603
604 if (!_account || !_secret)
605 {
607 return false;
608 }
609
610 std::string accountName = _account;
611 std::string secret = _secret;
612
613 if (!Utf8ToUpperOnlyLatin(accountName))
614 {
615 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName);
616 return false;
617 }
618
619 uint32 targetAccountId = AccountMgr::GetId(accountName);
620 if (!targetAccountId)
621 {
622 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName);
623 return false;
624 }
625
626 if (handler->HasLowerSecurityAccount(nullptr, targetAccountId, true))
627 return false;
628
629 if (secret == "off")
630 {
631 auto* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_ACCOUNT_TOTP_SECRET);
632 stmt->SetData(0);
633 stmt->SetData(1, targetAccountId);
634 LoginDatabase.Execute(stmt);
636 return true;
637 }
638
639 auto const& masterKey = sSecretMgr->GetSecret(SECRET_TOTP_MASTER_KEY);
640 if (!masterKey.IsAvailable())
641 {
643 return false;
644 }
645
647 if (!decoded)
648 {
650 return false;
651 }
652
654 {
656 return false;
657 }
658
659 if (masterKey)
660 Acore::Crypto::AEEncryptWithRandomIV<Acore::Crypto::AES>(*decoded, *masterKey);
661
662 auto* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_ACCOUNT_TOTP_SECRET);
663 stmt->SetData(0, *decoded);
664 stmt->SetData(1, targetAccountId);
665 LoginDatabase.Execute(stmt);
666
667 handler->PSendSysMessage(LANG_2FA_SECRET_SET_COMPLETE, accountName);
668 return true;
669 }
@ 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
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
690 {
692 char* account = strtok((char*)args, " ");
693 char* exp = strtok(nullptr, " ");
694
695 if (!account)
696 return false;
697
698 std::string accountName;
699 uint32 accountId;
700
701 if (!exp)
702 {
703 Player* player = handler->getSelectedPlayer();
704 if (!player)
705 return false;
706
707 accountId = player->GetSession()->GetAccountId();
708 AccountMgr::GetName(accountId, accountName);
709 exp = account;
710 }
711 else
712 {
714 accountName = account;
715 if (!Utf8ToUpperOnlyLatin(accountName))
716 {
717 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName);
718 return false;
719 }
720
721 accountId = AccountMgr::GetId(accountName);
722 if (!accountId)
723 {
724 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName);
725 return false;
726 }
727 }
728
729 // Let set addon state only for lesser (strong) security level
730 // or to self account
731 if (handler->GetSession() && handler->GetSession()->GetAccountId() != accountId &&
732 handler->HasLowerSecurityAccount(nullptr, accountId, true))
733 return false;
734
735 auto expansion = Acore::StringTo<uint8>(exp); //get int anyway (0 if error)
736 if (!expansion || *expansion > sWorld->getIntConfig(CONFIG_EXPANSION))
737 return false;
738
740
741 stmt->SetData(0, *expansion);
742 stmt->SetData(1, accountId);
743
744 LoginDatabase.Execute(stmt);
745
746 handler->PSendSysMessage(LANG_ACCOUNT_SETADDON, accountName, accountId, *expansion);
747 return true;
748 }
@ LANG_ACCOUNT_SETADDON
Definition Language.h:901
Player * getSelectedPlayer() const
Definition Chat.cpp:382
Definition Player.h:1086
WorldSession * GetSession() const
Definition Player.h:2030

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.

1035 {
1036 if (!account || !email.data() || !emailConfirmation.data())
1037 return false;
1038
1039 std::string accountName = account.GetName();
1040 if (!Utf8ToUpperOnlyLatin(accountName))
1041 {
1042 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName);
1043 return false;
1044 }
1045
1046 uint32 targetAccountId = account.GetID();
1047 if (!targetAccountId)
1048 {
1049 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName);
1050 return false;
1051 }
1052
1053 if (email != emailConfirmation)
1054 {
1056 return false;
1057 }
1058
1059 AccountOpResult result = AccountMgr::ChangeEmail(targetAccountId, email.data());
1060
1061 switch (result)
1062 {
1063 case AOR_OK:
1065 break;
1066 case AOR_NAME_NOT_EXIST:
1067 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName);
1068 return false;
1069 case AOR_EMAIL_TOO_LONG:
1071 return false;
1072 default:
1074 return false;
1075 }
1076 return true;
1077 }
@ 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
751 {
752 if (!*args)
753 return false;
754
755 std::string targetAccountName;
756 uint32 targetAccountId = 0;
757 uint32 targetSecurity = 0;
758 uint32 gm = 0;
759 char* arg1 = strtok((char*)args, " ");
760 char* arg2 = strtok(nullptr, " ");
761 char* arg3 = strtok(nullptr, " ");
762 bool isAccountNameGiven = true;
763
764 if (arg1 && !arg3)
765 {
766 if (!handler->getSelectedPlayer())
767 return false;
768 isAccountNameGiven = false;
769 }
770
771 // Check for second parameter
772 if (!isAccountNameGiven && !arg2)
773 return false;
774
775 // Check for account
776 if (isAccountNameGiven)
777 {
778 targetAccountName = arg1;
779 if (!Utf8ToUpperOnlyLatin(targetAccountName))
780 {
781 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, targetAccountName);
782 return false;
783 }
784 }
785
786 // Check for invalid specified GM level.
787 gm = (isAccountNameGiven) ? Acore::StringTo<int32>(arg2).value_or(0) : Acore::StringTo<int32>(arg1).value_or(0);
788 if (gm > SEC_CONSOLE)
789 {
791 return false;
792 }
793
794 // handler->getSession() == nullptr only for console
795 targetAccountId = (isAccountNameGiven) ? AccountMgr::GetId(targetAccountName) : handler->getSelectedPlayer()->GetSession()->GetAccountId();
796 int32 gmRealmID = (isAccountNameGiven) ? Acore::StringTo<int32>(arg3).value_or(0) : Acore::StringTo<int32>(arg2).value_or(0);
797 uint32 playerSecurity;
798 if (handler->GetSession())
799 playerSecurity = AccountMgr::GetSecurity(handler->GetSession()->GetAccountId(), gmRealmID);
800 else
801 playerSecurity = SEC_CONSOLE;
802
803 // can set security level only for target with less security and to less security that we have
804 // This is also reject self apply in fact
805 targetSecurity = AccountMgr::GetSecurity(targetAccountId, gmRealmID);
806 if (targetSecurity >= playerSecurity || gm >= playerSecurity)
807 {
809 return false;
810 }
811
812 // Check and abort if the target gm has a higher rank on one of the realms and the new realm is -1
813 if (gmRealmID == -1 && !AccountMgr::IsConsoleAccount(playerSecurity))
814 {
816
817 stmt->SetData(0, targetAccountId);
818 stmt->SetData(1, uint8(gm));
819
820 PreparedQueryResult result = LoginDatabase.Query(stmt);
821
822 if (result)
823 {
825 return false;
826 }
827 }
828
829 // Check if provided realm.Id.Realm has a negative value other than -1
830 if (gmRealmID < -1)
831 {
833 return false;
834 }
835
836 // If gmRealmID is -1, delete all values for the account id, else, insert values for the specific realm.Id.Realm
838
839 if (gmRealmID == -1)
840 {
841 stmt = LoginDatabase.GetPreparedStatement(LOGIN_DEL_ACCOUNT_ACCESS);
842 stmt->SetData(0, targetAccountId);
843 }
844 else
845 {
846 stmt = LoginDatabase.GetPreparedStatement(LOGIN_DEL_ACCOUNT_ACCESS_BY_REALM);
847 stmt->SetData(0, targetAccountId);
848 stmt->SetData(1, realm.Id.Realm);
849 }
850
851 LoginDatabase.Execute(stmt);
852
853 if (gm != 0)
854 {
855 stmt = LoginDatabase.GetPreparedStatement(LOGIN_INS_ACCOUNT_ACCESS);
856
857 stmt->SetData(0, targetAccountId);
858 stmt->SetData(1, uint8(gm));
859 stmt->SetData(2, gmRealmID);
860
861 LoginDatabase.Execute(stmt);
862 }
863
864 handler->PSendSysMessage(LANG_YOU_CHANGE_SECURITY, targetAccountName, gm);
865 return true;
866 }
@ 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:1372
@ LANG_BAD_VALUE
Definition Language.h:151
@ LOGIN_DEL_ACCOUNT_ACCESS_BY_REALM
Definition LoginDatabase.h:81
@ LOGIN_DEL_ACCOUNT_ACCESS
Definition LoginDatabase.h:80
@ LOGIN_INS_ACCOUNT_ACCESS
Definition LoginDatabase.h:82
@ LOGIN_SEL_ACCOUNT_ACCESS_GMLEVEL_TEST
Definition LoginDatabase.h:95
static bool IsConsoleAccount(uint32 gmlevel)
Definition AccountMgr.cpp:339
static uint32 GetSecurity(uint32 accountId)
Definition AccountMgr.cpp:257
Realm realm
Definition World.cpp:115
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

870 {
871 if (!*args)
872 return false;
873
875 char* account = strtok((char*)args, " ");
876 char* password = strtok(nullptr, " ");
877 char* passwordConfirmation = strtok(nullptr, " ");
878
879 if (!account || !password || !passwordConfirmation)
880 return false;
881
882 std::string accountName = account;
883 if (!Utf8ToUpperOnlyLatin(accountName))
884 {
885 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName);
886 return false;
887 }
888
889 uint32 targetAccountId = AccountMgr::GetId(accountName);
890 if (!targetAccountId)
891 {
892 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName);
893 return false;
894 }
895
898 if (handler->HasLowerSecurityAccount(nullptr, targetAccountId, true))
899 return false;
900
901 if (strcmp(password, passwordConfirmation))
902 {
904 return false;
905 }
906
907 AccountOpResult result = AccountMgr::ChangePassword(targetAccountId, password);
908
909 switch (result)
910 {
911 case AOR_OK:
913 break;
915 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName);
916 return false;
919 return false;
920 default:
922 return false;
923 }
924 return true;
925 }

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

◆ ParseAccountFlagBit()

static Optional< uint8 > account_commandscript::ParseAccountFlagBit ( std::string_view  input)
inlinestatic
928 {
929 for (uint8 i = 0; i < MAX_ACCOUNT_FLAG; ++i)
930 if (StringEqualI(input, accountFlagNames[i].full) || StringEqualI(input, accountFlagNames[i].shortName))
931 return i;
932
933 return std::nullopt;
934 }
bool StringEqualI(std::string_view a, std::string_view b)
Definition Util.cpp:592

References accountFlagNames, MAX_ACCOUNT_FLAG, and StringEqualI().

Referenced by ChangeAccountFlag().


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