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 HandleAccountInfoCommand (ChatHandler *handler, Optional< AccountIdentifier > account)
 
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< uint8 > ParseAccountFlagBit (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
51: 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
1167 {
1168 if (handler->HasLowerSecurityAccount(nullptr, account.GetID(), true))
1169 return false;
1170
1171 Optional<uint8> bit = ParseAccountFlagBit(flagArg);
1172 if (!bit)
1173 {
1175 return false;
1176 }
1177
1178 // ACCOUNT_FLAG_GM is handled by GMLevel and should not be allowed to set manually
1179 uint32 const flag = uint32(1) << *bit;
1180 if (flag & ACCOUNT_FLAG_GM)
1181 {
1183 return false;
1184 }
1185
1186 if (WorldSession* session = sWorldSessionMgr->FindSession(account.GetID()))
1187 session->UpdateAccountFlag(flag, !add);
1188 else
1189 LoginDatabase.Execute("UPDATE account SET Flags = Flags {} {} WHERE id = {}",
1190 add ? "|" : "& ~", flag, account.GetID());
1191
1193 accountFlagNames[*bit].full, account.GetName(), account.GetID());
1194 return true;
1195 }
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:52
Player session in the World.
Definition WorldSession.h:430
static Optional< uint8 > ParseAccountFlagBit(std::string_view input)
Definition cs_account.cpp:1102

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.

54 {
55 static ChatCommandTable accountSetCommandTable =
56 {
62 };
63
64 static ChatCommandTable accountLockCommandTable
65 {
68 };
69
70 static ChatCommandTable account2faCommandTable
71 {
74 };
75
76 static ChatCommandTable accountRemoveCommandTable
77 {
79 };
80
81 static ChatCommandTable accountFlagCommandTable
82 {
86 };
87
88 static ChatCommandTable accountCommandTable =
89 {
90 { "2fa", account2faCommandTable },
94 { "flag", accountFlagCommandTable },
97 { "lock", accountLockCommandTable },
98 { "set", accountSetCommandTable },
100 { "remove", accountRemoveCommandTable },
102 };
103
104 static ChatCommandTable commandTable =
105 {
106 { "account", accountCommandTable }
107 };
108
109 return commandTable;
110 }
static bool HandleAccountFlagListCommand(ChatHandler *handler, Optional< AccountIdentifier > account)
Definition cs_account.cpp:1111
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:925
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:1044
static bool HandleAccountFlagAddCommand(ChatHandler *handler, AccountIdentifier account, std::string_view flagArg)
Definition cs_account.cpp:1197
static bool HandleAccount2FARemoveCommand(ChatHandler *handler, char const *args)
Definition cs_account.cpp:180
static bool HandleAccountInfoCommand(ChatHandler *handler, Optional< AccountIdentifier > account)
Definition cs_account.cpp:689
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:864
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:1208
static bool HandleAccount2FASetupCommand(ChatHandler *handler, char const *args)
Definition cs_account.cpp:112
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:1202
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_INFO
Definition RBAC.h:709
@ 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(), HandleAccountInfoCommand(), 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_INFO, 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
181 {
182 // no error message here: the framework then prints the command help, which names the token argument
183 if (!*args)
184 return false;
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:41
@ 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_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:135
@ LOGIN_SEL_ACCOUNT_TOTP_SECRET
Definition LoginDatabase.h:134
#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:99
bool IsNull() const
Definition Field.h:107
std::enable_if_t< std::is_arithmetic_v< T >, T > Get() const
Definition Field.h:113
uint32 GetAccountId() const
Definition WorldSession.h:502
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_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
113 {
114 // no error message here: the framework then prints the command help, which explains how to get the key
115 if (!*args)
116 return false;
117
118 auto token = Acore::StringTo<uint32>(args);
119
120 auto const& masterKey = sSecretMgr->GetSecret(SECRET_TOTP_MASTER_KEY);
121 if (!masterKey.IsAvailable())
122 {
124 return false;
125 }
126
127 uint32 const accountId = handler->GetSession()->GetAccountId();
128
129 { // check if 2FA already enabled
130 auto* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_ACCOUNT_TOTP_SECRET);
131 stmt->SetData(0, accountId);
132 PreparedQueryResult result = LoginDatabase.Query(stmt);
133
134 if (!result)
135 {
136 LOG_ERROR("misc", "Account {} not found in login database when processing .account 2fa setup command.", accountId);
138 return false;
139 }
140
141 if (!result->Fetch()->IsNull())
142 {
144 return false;
145 }
146 }
147
148 // store random suggested secrets
149 static std::unordered_map<uint32, Acore::Crypto::TOTP::Secret> suggestions;
150 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
151
152 if (pair.second) // no suggestion yet, generate random secret
153 Acore::Crypto::GetRandomBytes(pair.first->second);
154
155 if (!pair.second && token) // suggestion already existed and token specified - validate
156 {
157 if (Acore::Crypto::TOTP::ValidateToken(pair.first->second, *token))
158 {
159 if (masterKey)
160 Acore::Crypto::AEEncryptWithRandomIV<Acore::Crypto::AES>(pair.first->second, *masterKey);
161
162 auto* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_ACCOUNT_TOTP_SECRET);
163 stmt->SetData(0, pair.first->second);
164 stmt->SetData(1, accountId);
165 LoginDatabase.Execute(stmt);
166
167 suggestions.erase(pair.first);
169 return true;
170 }
171 else
173 }
174
175 // new suggestion, or no token specified, output TOTP parameters
177 return false;
178 }
@ 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_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
@ LANG_CMD_SYNTAX
Definition Language.h:42
@ 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:139
AccountTypes GetSecurity() const
Definition WorldSession.h:490
bool HasPermission(uint32 permissionId)
Definition WorldSession.cpp:1691
@ 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:120
std::string const & GetName() const
Definition Object.h:535
Player * GetPlayer() const
Definition WorldSession.h:503
std::string const & GetRemoteAddress()
Definition WorldSession.h:512

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
1198 {
1199 return ChangeAccountFlag(handler, account, flagArg, true);
1200 }
static bool ChangeAccountFlag(ChatHandler *handler, AccountIdentifier const &account, std::string_view flagArg, bool add)
Definition cs_account.cpp:1166

References ChangeAccountFlag().

Referenced by GetCommands().

◆ HandleAccountFlagListCommand()

static bool account_commandscript::HandleAccountFlagListCommand ( ChatHandler *  handler,
Optional< AccountIdentifier >  account 
)
inlinestatic
1112 {
1113 uint32 accountId;
1114 std::string accountName;
1115
1116 if (account)
1117 {
1118 accountId = account->GetID();
1119 accountName = account->GetName();
1120 }
1121 else if (WorldSession* session = handler->GetSession())
1122 {
1123 accountId = session->GetAccountId();
1124 AccountMgr::GetName(accountId, accountName);
1125 }
1126 else
1127 {
1129 return false;
1130 }
1131
1132 if (handler->HasLowerSecurityAccount(nullptr, accountId, true))
1133 return false;
1134
1135 uint32 flags;
1136 if (WorldSession* targetSession = sWorldSessionMgr->FindSession(accountId))
1137 flags = targetSession->GetAccountFlags();
1138 else
1139 {
1141 stmt->SetData(0, accountId);
1142 PreparedQueryResult result = LoginDatabase.Query(stmt);
1143 if (!result)
1144 {
1145 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName);
1146 return false;
1147 }
1148
1149 flags = (*result)[0].Get<uint32>();
1150 }
1151
1152 if (!flags)
1153 {
1154 handler->PSendSysMessage(LANG_ACCOUNT_FLAG_LIST_EMPTY, accountName, accountId);
1155 return true;
1156 }
1157
1158 handler->PSendSysMessage(LANG_ACCOUNT_FLAG_LIST_HEADER, accountName, accountId);
1159 for (uint8 i = 0; i < MAX_ACCOUNT_FLAG; ++i)
1160 if (flags & (uint32(1) << i))
1162
1163 return true;
1164 }
#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
1203 {
1204 return ChangeAccountFlag(handler, account, flagArg, false);
1205 }

References ChangeAccountFlag().

Referenced by GetCommands().

◆ HandleAccountInfoCommand()

static bool account_commandscript::HandleAccountInfoCommand ( ChatHandler *  handler,
Optional< AccountIdentifier >  account 
)
inlinestatic
690 {
691 uint32 accountId;
692 std::string accountName;
693
694 if (account)
695 {
696 accountId = account->GetID();
697 accountName = account->GetName();
698 }
699 else if (Player* target = handler->getSelectedPlayerOrSelf())
700 {
701 accountId = target->GetSession()->GetAccountId();
702 AccountMgr::GetName(accountId, accountName);
703 }
704 else
705 {
707 return false;
708 }
709
710 // The strong check rejects equal security, so inspecting your own account has to be exempted
711 if (handler->GetSession() && handler->GetSession()->GetAccountId() != accountId &&
712 handler->HasLowerSecurityAccount(nullptr, accountId, true))
713 return false;
714
716 stmt->SetData(0, int32(realm.Id.Realm));
717 stmt->SetData(1, accountId);
718
719 PreparedQueryResult result = LoginDatabase.Query(stmt);
720 if (!result)
721 {
722 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName);
723 return false;
724 }
725
726 Field* fields = result->Fetch();
727 accountName = fields[0].Get<std::string>();
728 uint32 security = fields[1].Get<uint8>();
729 std::string eMail = fields[2].Get<std::string>();
730 std::string regMail = fields[3].Get<std::string>();
731 std::string lastIp = fields[4].Get<std::string>();
732 std::string lastLogin = fields[5].Get<std::string>();
733 int64 muteTime = fields[6].Get<uint64>();
734 std::string muteReason = fields[7].Get<std::string>();
735 std::string muteBy = fields[8].Get<std::string>();
736 uint32 failedLogins = fields[9].Get<uint32>();
737 uint8 locked = fields[10].Get<uint8>();
738 std::string OS = fields[11].Get<std::string>();
739 uint32 expansion = fields[12].Get<uint8>();
740 uint32 accountFlags = fields[13].Get<uint32>();
741 std::string joinDate = fields[14].Get<std::string>();
742 uint32 totalTime = fields[15].Get<uint32>();
743 std::string lockCountry = fields[16].Get<std::string>();
744
745 // Empty unless the account is online, in which case it holds the address of the live connection
746 std::string currentIp;
747 uint32 latency = 0;
748
749 if (WorldSession* targetSession = sWorldSessionMgr->FindSession(accountId))
750 {
751 latency = targetSession->GetLatency();
752 muteTime = targetSession->m_muteTime;
753 accountFlags = targetSession->GetAccountFlags();
754 currentIp = targetSession->GetRemoteAddress();
755 }
756
757 if (!handler->GetSession() || handler->GetSession()->GetSecurity() >= AccountTypes(security))
758 {
759 if (IpLocationRecord const* location = sIPLocation->GetLocationRecord(lastIp))
760 lastIp.append(" (").append(location->CountryName).append(")");
761
762 if (!currentIp.empty())
763 if (IpLocationRecord const* location = sIPLocation->GetLocationRecord(currentIp))
764 currentIp.append(" (").append(location->CountryName).append(")");
765 }
766 else
767 {
768 eMail = handler->GetAcoreString(LANG_UNAUTHORIZED);
769 regMail = handler->GetAcoreString(LANG_UNAUTHORIZED);
770 lastIp = handler->GetAcoreString(LANG_UNAUTHORIZED);
771 lastLogin = handler->GetAcoreString(LANG_UNAUTHORIZED);
772
773 if (!currentIp.empty())
774 currentIp = handler->GetAcoreString(LANG_UNAUTHORIZED);
775 }
776
777 int64 banTime = -1;
778 std::string banReason = handler->GetAcoreString(LANG_NO_REASON);
779 std::string bannedBy = handler->GetAcoreString(LANG_UNKNOWN);
780
782 banStmt->SetData(0, accountId);
783
784 if (PreparedQueryResult banResult = LoginDatabase.Query(banStmt))
785 {
786 Field* banFields = banResult->Fetch();
787 banTime = int64(banFields[1].Get<uint64>() ? 0 : banFields[0].Get<uint32>());
788 bannedBy = banFields[2].Get<std::string>();
789 banReason = banFields[3].Get<std::string>();
790 }
791
792 handler->PSendSysMessage(LANG_PINFO_ACC_ACCOUNT, accountName, accountId, security);
793
794 if (accountFlags)
795 {
797 for (uint8 i = 0; i < MAX_ACCOUNT_FLAG; ++i)
798 if (accountFlags & (uint32(1) << i))
800 }
801
802 if (banTime >= 0)
803 handler->PSendSysMessage(LANG_ACCOUNT_INFO_BANNED, banReason,
804 banTime > 0 ? secsToTimeString(banTime - GameTime::GetGameTime().count(), true) : handler->GetAcoreString(LANG_PERMANENTLY), bannedBy);
805
806 // mutetime is only cleared once the muted player logs back in, so an expired mute can still be stored
807 if (muteTime > GameTime::GetGameTime().count())
808 handler->PSendSysMessage(LANG_PINFO_MUTED, muteReason, secsToTimeString(muteTime - GameTime::GetGameTime().count(), true), muteBy);
809
811 handler->PSendSysMessage(LANG_PINFO_ACC_LASTLOGIN, lastLogin, failedLogins);
812 handler->PSendSysMessage(LANG_PINFO_ACC_OS, OS, latency);
813 handler->PSendSysMessage(LANG_PINFO_ACC_REGMAILS, regMail, eMail);
814 handler->PSendSysMessage(LANG_PINFO_ACC_IP, lastIp, locked ? handler->GetAcoreString(LANG_YES) : handler->GetAcoreString(LANG_NO));
815
816 if (!currentIp.empty())
818
819 // "00" is the default value meaning no country lock is set
820 if (lockCountry != "00")
821 handler->PSendSysMessage(LANG_ACCOUNT_INFO_LOCK_COUNTRY, lockCountry);
822
823 handler->PSendSysMessage(LANG_ACCOUNT_INFO_EXPANSION, expansion);
825
827 charStmt->SetData(0, accountId);
828
829 PreparedQueryResult charResult = CharacterDatabase.Query(charStmt);
830 if (!charResult)
831 {
833 return true;
834 }
835
836 handler->PSendSysMessage(LANG_ACCOUNT_INFO_CHARS, uint32(charResult->GetRowCount()));
837
838 LocaleConstant locale = handler->GetSessionDbcLocale();
839
840 do
841 {
842 Field* charFields = charResult->Fetch();
843 ObjectGuid::LowType guid = charFields[0].Get<uint32>();
844 std::string name = charFields[1].Get<std::string>();
845 uint8 level = charFields[2].Get<uint8>();
846 uint8 raceId = charFields[3].Get<uint8>();
847 uint8 classId = charFields[4].Get<uint8>();
848 bool online = charFields[5].Get<bool>();
849
850 ChrRacesEntry const* race = sChrRacesStore.LookupEntry(raceId);
851 ChrClassesEntry const* cls = sChrClassesStore.LookupEntry(classId);
852
853 // Own marker rather than LANG_OFFLINE, whose leading space is missing in some locales
855 online ? "" : handler->GetAcoreString(LANG_ACCOUNT_INFO_CHAR_OFFLINE), guid, uint32(level),
856 race ? race->name[locale] : handler->GetAcoreString(LANG_UNKNOWN),
857 cls ? cls->name[locale] : handler->GetAcoreString(LANG_UNKNOWN));
858 } while (charResult->NextRow());
859
860 return true;
861 }
@ CHAR_SEL_ACCOUNT_INFO_CHARS
Definition CharacterDatabase.h:341
LocaleConstant
Definition Common.h:125
DBCStorage< ChrRacesEntry > sChrRacesStore(ChrRacesEntryfmt)
DBCStorage< ChrClassesEntry > sChrClassesStore(ChrClassesEntryfmt)
DatabaseWorkerPool< CharacterDatabaseConnection > CharacterDatabase
Accessor to the character database.
Definition DatabaseEnv.cpp:21
std::int32_t int32
Definition Define.h:103
std::uint64_t uint64
Definition Define.h:106
std::int64_t int64
Definition Define.h:102
#define sIPLocation
Definition IPLocation.h:49
@ LANG_YES
Definition Language.h:460
@ LANG_NO_REASON
Definition Language.h:818
@ LANG_PINFO_ACC_LASTLOGIN
Definition Language.h:801
@ LANG_UNKNOWN
Definition Language.h:77
@ LANG_ACCOUNT_INFO_CHAR_OFFLINE
Definition Language.h:1559
@ LANG_PERMANENTLY
Definition Language.h:1103
@ LANG_ACCOUNT_INFO_LOCK_COUNTRY
Definition Language.h:1553
@ LANG_PINFO_CHR_PLAYEDTIME
Definition Language.h:815
@ LANG_UNAUTHORIZED
Definition Language.h:819
@ LANG_ACCOUNT_INFO_NO_CHARS
Definition Language.h:1557
@ LANG_PINFO_ACC_OS
Definition Language.h:802
@ LANG_ACCOUNT_INFO_BANNED
Definition Language.h:1554
@ LANG_ACCOUNT_INFO_CURRENT_IP
Definition Language.h:1558
@ LANG_NO
Definition Language.h:461
@ LANG_PINFO_ACC_IP
Definition Language.h:804
@ LANG_ACCOUNT_INFO_EXPANSION
Definition Language.h:1552
@ LANG_PINFO_ACC_ACCOUNT
Definition Language.h:800
@ LANG_PINFO_ACC_REGMAILS
Definition Language.h:803
@ LANG_ACCOUNT_INFO_CHAR_ENTRY
Definition Language.h:1556
@ LANG_ACCOUNT_INFO_CHARS
Definition Language.h:1555
@ LANG_ACCOUNT_FLAGS_PINFO
Definition Language.h:224
@ LANG_ACCOUNT_INFO_JOINDATE
Definition Language.h:1551
@ LANG_PINFO_MUTED
Definition Language.h:799
@ LOGIN_SEL_ACCOUNT_INFO_DETAILED
Definition LoginDatabase.h:93
@ LOGIN_SEL_PINFO_BANS
Definition LoginDatabase.h:92
std::string secsToTimeString(uint64 timeInSecs, bool shortText)
Definition Util.cpp:73
std::string playerLink(std::string const &name) const
Definition Chat.h:231
virtual LocaleConstant GetSessionDbcLocale() const
Definition Chat.cpp:878
Player * getSelectedPlayerOrSelf() const
Definition Chat.cpp:426
virtual std::string GetAcoreString(uint32 entry) const
Definition Chat.cpp:42
uint32 LowType
Definition ObjectGuid.h:125
Definition Player.h:1086
Realm realm
Definition World.cpp:115
AC_GAME_API std::string GetAcoreString(ChatHandler const *handler, AcoreStrings which)
Definition ChatCommandHelpers.cpp:27
Seconds GetGameTime()
Definition GameTime.cpp:38
Definition DBCStructure.h:680
char const * name[16]
Definition DBCStructure.h:685
Definition DBCStructure.h:706
Definition IPLocation.h:23
uint32 Realm
Definition Realm.h:43
RealmHandle Id
Definition Realm.h:69

References accountFlagNames, CHAR_SEL_ACCOUNT_INFO_CHARS, CharacterDatabase, Field::Get(), WorldSession::GetAccountId(), ChatHandler::GetAcoreString(), GameTime::GetGameTime(), AccountMgr::GetName(), WorldSession::GetSecurity(), ChatHandler::getSelectedPlayerOrSelf(), ChatHandler::GetSession(), ChatHandler::GetSessionDbcLocale(), ChatHandler::HasLowerSecurityAccount(), Realm::Id, LANG_ACCOUNT_FLAGS_PINFO, LANG_ACCOUNT_INFO_BANNED, LANG_ACCOUNT_INFO_CHAR_ENTRY, LANG_ACCOUNT_INFO_CHAR_OFFLINE, LANG_ACCOUNT_INFO_CHARS, LANG_ACCOUNT_INFO_CURRENT_IP, LANG_ACCOUNT_INFO_EXPANSION, LANG_ACCOUNT_INFO_JOINDATE, LANG_ACCOUNT_INFO_LOCK_COUNTRY, LANG_ACCOUNT_INFO_NO_CHARS, LANG_ACCOUNT_NOT_EXIST, LANG_CMD_SYNTAX, LANG_NO, LANG_NO_REASON, LANG_PERMANENTLY, LANG_PINFO_ACC_ACCOUNT, LANG_PINFO_ACC_IP, LANG_PINFO_ACC_LASTLOGIN, LANG_PINFO_ACC_OS, LANG_PINFO_ACC_REGMAILS, LANG_PINFO_CHR_PLAYEDTIME, LANG_PINFO_MUTED, LANG_SUBCMDS_LIST_ENTRY, LANG_UNAUTHORIZED, LANG_UNKNOWN, LANG_YES, LOGIN_SEL_ACCOUNT_INFO_DETAILED, LOGIN_SEL_PINFO_BANS, LoginDatabase, MAX_ACCOUNT_FLAG, ChrClassesEntry::name, ChatHandler::playerLink(), ChatHandler::PSendSysMessage(), realm, RealmHandle::Realm, sChrClassesStore, sChrRacesStore, secsToTimeString(), ChatHandler::SendErrorMessage(), PreparedStatementBase::SetData(), sIPLocation, and sWorldSessionMgr.

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 }
@ 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

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:333
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:95

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:766
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
865 {
867 char* account = strtok((char*)args, " ");
868 char* exp = strtok(nullptr, " ");
869
870 if (!account)
871 return false;
872
873 std::string accountName;
874 uint32 accountId;
875
876 if (!exp)
877 {
878 Player* player = handler->getSelectedPlayer();
879 if (!player)
880 return false;
881
882 accountId = player->GetSession()->GetAccountId();
883 AccountMgr::GetName(accountId, accountName);
884 exp = account;
885 }
886 else
887 {
889 accountName = account;
890 if (!Utf8ToUpperOnlyLatin(accountName))
891 {
892 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName);
893 return false;
894 }
895
896 accountId = AccountMgr::GetId(accountName);
897 if (!accountId)
898 {
899 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName);
900 return false;
901 }
902 }
903
904 // Let set addon state only for lesser (strong) security level
905 // or to self account
906 if (handler->GetSession() && handler->GetSession()->GetAccountId() != accountId &&
907 handler->HasLowerSecurityAccount(nullptr, accountId, true))
908 return false;
909
910 auto expansion = Acore::StringTo<uint8>(exp); //get int anyway (0 if error)
911 if (!expansion || *expansion > sWorld->getIntConfig(CONFIG_EXPANSION))
912 return false;
913
915
916 stmt->SetData(0, *expansion);
917 stmt->SetData(1, accountId);
918
919 LoginDatabase.Execute(stmt);
920
921 handler->PSendSysMessage(LANG_ACCOUNT_SETADDON, accountName, accountId, *expansion);
922 return true;
923 }
@ LANG_ACCOUNT_SETADDON
Definition Language.h:901
Player * getSelectedPlayer() const
Definition Chat.cpp:382
WorldSession * GetSession() const
Definition Player.h:2031

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.

1210 {
1211 if (!account || !email.data() || !emailConfirmation.data())
1212 return false;
1213
1214 std::string accountName = account.GetName();
1215 if (!Utf8ToUpperOnlyLatin(accountName))
1216 {
1217 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName);
1218 return false;
1219 }
1220
1221 uint32 targetAccountId = account.GetID();
1222 if (!targetAccountId)
1223 {
1224 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName);
1225 return false;
1226 }
1227
1228 if (email != emailConfirmation)
1229 {
1231 return false;
1232 }
1233
1234 AccountOpResult result = AccountMgr::ChangeEmail(targetAccountId, email.data());
1235
1236 switch (result)
1237 {
1238 case AOR_OK:
1240 break;
1241 case AOR_NAME_NOT_EXIST:
1242 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName);
1243 return false;
1244 case AOR_EMAIL_TOO_LONG:
1246 return false;
1247 default:
1249 return false;
1250 }
1251 return true;
1252 }
@ 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
926 {
927 if (!*args)
928 return false;
929
930 std::string targetAccountName;
931 uint32 targetAccountId = 0;
932 uint32 targetSecurity = 0;
933 uint32 gm = 0;
934 char* arg1 = strtok((char*)args, " ");
935 char* arg2 = strtok(nullptr, " ");
936 char* arg3 = strtok(nullptr, " ");
937 bool isAccountNameGiven = true;
938
939 if (arg1 && !arg3)
940 {
941 if (!handler->getSelectedPlayer())
942 return false;
943 isAccountNameGiven = false;
944 }
945
946 // Check for second parameter
947 if (!isAccountNameGiven && !arg2)
948 return false;
949
950 // Check for account
951 if (isAccountNameGiven)
952 {
953 targetAccountName = arg1;
954 if (!Utf8ToUpperOnlyLatin(targetAccountName))
955 {
956 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, targetAccountName);
957 return false;
958 }
959 }
960
961 // Check for invalid specified GM level.
962 gm = (isAccountNameGiven) ? Acore::StringTo<int32>(arg2).value_or(0) : Acore::StringTo<int32>(arg1).value_or(0);
963 if (gm > SEC_CONSOLE)
964 {
966 return false;
967 }
968
969 // handler->getSession() == nullptr only for console
970 targetAccountId = (isAccountNameGiven) ? AccountMgr::GetId(targetAccountName) : handler->getSelectedPlayer()->GetSession()->GetAccountId();
971 int32 gmRealmID = (isAccountNameGiven) ? Acore::StringTo<int32>(arg3).value_or(0) : Acore::StringTo<int32>(arg2).value_or(0);
972 uint32 playerSecurity;
973 if (handler->GetSession())
974 playerSecurity = AccountMgr::GetSecurity(handler->GetSession()->GetAccountId(), gmRealmID);
975 else
976 playerSecurity = SEC_CONSOLE;
977
978 // can set security level only for target with less security and to less security that we have
979 // This is also reject self apply in fact
980 targetSecurity = AccountMgr::GetSecurity(targetAccountId, gmRealmID);
981 if (targetSecurity >= playerSecurity || gm >= playerSecurity)
982 {
984 return false;
985 }
986
987 // Check and abort if the target gm has a higher rank on one of the realms and the new realm is -1
988 if (gmRealmID == -1 && !AccountMgr::IsConsoleAccount(playerSecurity))
989 {
991
992 stmt->SetData(0, targetAccountId);
993 stmt->SetData(1, uint8(gm));
994
995 PreparedQueryResult result = LoginDatabase.Query(stmt);
996
997 if (result)
998 {
1000 return false;
1001 }
1002 }
1003
1004 // Check if provided gmRealmID has a negative value other than -1
1005 if (gmRealmID < -1)
1006 {
1008 return false;
1009 }
1010
1011 // If gmRealmID is -1, delete access on every realm, else on the requested one and any all-realms row
1013
1014 if (gmRealmID == -1)
1015 {
1016 stmt = LoginDatabase.GetPreparedStatement(LOGIN_DEL_ACCOUNT_ACCESS);
1017 stmt->SetData(0, targetAccountId);
1018 }
1019 else
1020 {
1021 stmt = LoginDatabase.GetPreparedStatement(LOGIN_DEL_ACCOUNT_ACCESS_BY_REALM);
1022 stmt->SetData(0, targetAccountId);
1023 stmt->SetData(1, gmRealmID);
1024 }
1025
1026 LoginDatabase.Execute(stmt);
1027
1028 if (gm != 0)
1029 {
1030 stmt = LoginDatabase.GetPreparedStatement(LOGIN_INS_ACCOUNT_ACCESS);
1031
1032 stmt->SetData(0, targetAccountId);
1033 stmt->SetData(1, uint8(gm));
1034 stmt->SetData(2, gmRealmID);
1035
1036 LoginDatabase.Execute(stmt);
1037 }
1038
1039 handler->PSendSysMessage(LANG_YOU_CHANGE_SECURITY, targetAccountName, gm);
1040 return true;
1041 }
@ SEC_CONSOLE
Definition Common.h:61
@ 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:96
static bool IsConsoleAccount(uint32 gmlevel)
Definition AccountMgr.cpp:339
static uint32 GetSecurity(uint32 accountId)
Definition AccountMgr.cpp:257

References WorldSession::GetAccountId(), AccountMgr::GetId(), AccountMgr::GetSecurity(), ChatHandler::getSelectedPlayer(), ChatHandler::GetSession(), Player::GetSession(), 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(), 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

1045 {
1046 if (!*args)
1047 return false;
1048
1050 char* account = strtok((char*)args, " ");
1051 char* password = strtok(nullptr, " ");
1052 char* passwordConfirmation = strtok(nullptr, " ");
1053
1054 if (!account || !password || !passwordConfirmation)
1055 return false;
1056
1057 std::string accountName = account;
1058 if (!Utf8ToUpperOnlyLatin(accountName))
1059 {
1060 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName);
1061 return false;
1062 }
1063
1064 uint32 targetAccountId = AccountMgr::GetId(accountName);
1065 if (!targetAccountId)
1066 {
1067 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName);
1068 return false;
1069 }
1070
1073 if (handler->HasLowerSecurityAccount(nullptr, targetAccountId, true))
1074 return false;
1075
1076 if (strcmp(password, passwordConfirmation))
1077 {
1079 return false;
1080 }
1081
1082 AccountOpResult result = AccountMgr::ChangePassword(targetAccountId, password);
1083
1084 switch (result)
1085 {
1086 case AOR_OK:
1088 break;
1089 case AOR_NAME_NOT_EXIST:
1090 handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName);
1091 return false;
1092 case AOR_PASS_TOO_LONG:
1094 return false;
1095 default:
1097 return false;
1098 }
1099 return true;
1100 }

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
1103 {
1104 for (uint8 i = 0; i < MAX_ACCOUNT_FLAG; ++i)
1105 if (StringEqualI(input, accountFlagNames[i].full) || StringEqualI(input, accountFlagNames[i].shortName))
1106 return i;
1107
1108 return std::nullopt;
1109 }
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: