AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
AccountMgr Namespace Reference

Functions

AccountOpResult CreateAccount (std::string username, std::string password, std::string email)
 
AccountOpResult ChangeEmail (uint32 accountId, std::string newEmail)
 
AccountOpResult DeleteAccount (uint32 accountId)
 
AccountOpResult ChangeUsername (uint32 accountId, std::string newUsername, std::string newPassword)
 
AccountOpResult ChangePassword (uint32 accountId, std::string newPassword)
 
uint32 GetId (std::string const &username)
 
uint32 GetSecurity (uint32 accountId)
 
uint32 GetSecurity (uint32 accountId, int32 realmId)
 
bool GetName (uint32 accountId, std::string &name)
 
bool CheckPassword (uint32 accountId, std::string password)
 
uint32 GetCharactersCount (uint32 accountId)
 
bool IsPlayerAccount (uint32 gmlevel)
 
bool IsGMAccount (uint32 gmlevel)
 
bool IsAdminAccount (uint32 gmlevel)
 
bool IsConsoleAccount (uint32 gmlevel)
 

Function Documentation

◆ ChangeEmail()

AccountOpResult AccountMgr::ChangeEmail ( uint32  accountId,
std::string  newEmail 
)
69 {
70 std::string username;
71
72 if (!GetName(accountId, username))
73 {
74 sScriptMgr->OnFailedEmailChange(accountId);
75 return AOR_NAME_NOT_EXIST; // account doesn't exist
76 }
77
78 if (utf8length(newEmail) > MAX_EMAIL_STR)
79 {
80 sScriptMgr->OnFailedEmailChange(accountId);
81 return AOR_EMAIL_TOO_LONG; // email's too long
82 }
83
84 Utf8ToUpperOnlyLatin(newEmail);
85
87 stmt->SetData(0, newEmail);
88 stmt->SetData(1, accountId);
89 LoginDatabase.Execute(stmt);
90
91 sScriptMgr->OnEmailChange(accountId);
92 return AOR_OK;
93 }
@ AOR_NAME_NOT_EXIST
Definition AccountMgr.h:32
@ AOR_OK
Definition AccountMgr.h:27
@ AOR_EMAIL_TOO_LONG
Definition AccountMgr.h:30
#define MAX_EMAIL_STR
Definition AccountMgr.h:38
DatabaseWorkerPool< LoginDatabaseConnection > LoginDatabase
Accessor to the realm/login database.
Definition DatabaseEnv.cpp:22
@ LOGIN_UPD_EMAIL
Definition LoginDatabase.h:70
#define sScriptMgr
Definition ScriptMgr.h:727
bool Utf8ToUpperOnlyLatin(std::string &utf8String)
Definition Util.cpp:532
std::size_t utf8length(std::string &utf8str)
Definition Util.cpp:245
Acore::Types::is_default< T > SetData(const uint8 index, T value)
Definition PreparedStatement.h:77
Definition PreparedStatement.h:157
bool GetName(uint32 accountId, std::string &name)
Definition AccountMgr.cpp:264

References AOR_EMAIL_TOO_LONG, AOR_NAME_NOT_EXIST, AOR_OK, GetName(), LOGIN_UPD_EMAIL, LoginDatabase, MAX_EMAIL_STR, PreparedStatementBase::SetData(), sScriptMgr, utf8length(), and Utf8ToUpperOnlyLatin().

Referenced by account_commandscript::HandleAccountSetEmailCommand().

◆ ChangePassword()

AccountOpResult AccountMgr::ChangePassword ( uint32  accountId,
std::string  newPassword 
)
206 {
207 std::string username;
208
209 if (!GetName(accountId, username))
210 {
211 sScriptMgr->OnFailedPasswordChange(accountId);
212 return AOR_NAME_NOT_EXIST; // account doesn't exist
213 }
214
215 if (utf8length(newPassword) > MAX_PASS_STR)
216 {
217 sScriptMgr->OnFailedEmailChange(accountId);
218 return AOR_PASS_TOO_LONG; // password's too long
219 }
220
221 Utf8ToUpperOnlyLatin(username);
222 Utf8ToUpperOnlyLatin(newPassword);
223
224 auto [salt, verifier] = Acore::Crypto::SRP6::MakeRegistrationData(username, newPassword);
225
227 stmt->SetData(0, salt);
228 stmt->SetData(1, verifier);
229 stmt->SetData(2, accountId);
230 LoginDatabase.Execute(stmt);
231
232 sScriptMgr->OnPasswordChange(accountId);
233 return AOR_OK;
234 }
@ AOR_PASS_TOO_LONG
Definition AccountMgr.h:29
#define MAX_PASS_STR
Definition AccountMgr.h:37
@ LOGIN_UPD_LOGON
Definition LoginDatabase.h:42
static std::pair< Salt, Verifier > MakeRegistrationData(std::string const &username, std::string const &password)
Definition SRP6.cpp:31

References AOR_NAME_NOT_EXIST, AOR_OK, AOR_PASS_TOO_LONG, GetName(), LOGIN_UPD_LOGON, LoginDatabase, Acore::Crypto::SRP6::MakeRegistrationData(), MAX_PASS_STR, PreparedStatementBase::SetData(), sScriptMgr, utf8length(), and Utf8ToUpperOnlyLatin().

Referenced by account_commandscript::HandleAccountPasswordCommand(), and account_commandscript::HandleAccountSetPasswordCommand().

◆ ChangeUsername()

AccountOpResult AccountMgr::ChangeUsername ( uint32  accountId,
std::string  newUsername,
std::string  newPassword 
)
172 {
173 // Check if accounts exists
175 stmt->SetData(0, accountId);
176 PreparedQueryResult result = LoginDatabase.Query(stmt);
177
178 if (!result)
179 return AOR_NAME_NOT_EXIST;
180
181 if (utf8length(newUsername) > MAX_ACCOUNT_STR)
182 return AOR_NAME_TOO_LONG;
183
184 if (utf8length(newPassword) > MAX_PASS_STR)
185 return AOR_PASS_TOO_LONG; // password's too long
186
187 Utf8ToUpperOnlyLatin(newUsername);
188 Utf8ToUpperOnlyLatin(newPassword);
189
190 stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_USERNAME);
191 stmt->SetData(0, newUsername);
192 stmt->SetData(1, accountId);
193 LoginDatabase.Execute(stmt);
194
195 auto [salt, verifier] = Acore::Crypto::SRP6::MakeRegistrationData(newUsername, newPassword);
196 stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_LOGON);
197 stmt->SetData(0, salt);
198 stmt->SetData(1, verifier);
199 stmt->SetData(2, accountId);
200 LoginDatabase.Execute(stmt);
201
202 return AOR_OK;
203 }
@ AOR_NAME_TOO_LONG
Definition AccountMgr.h:28
#define MAX_ACCOUNT_STR
Definition AccountMgr.h:36
std::shared_ptr< PreparedResultSet > PreparedQueryResult
Definition DatabaseEnvFwd.h:45
@ LOGIN_SEL_ACCOUNT_BY_ID
Definition LoginDatabase.h:59
@ LOGIN_UPD_USERNAME
Definition LoginDatabase.h:71

References AOR_NAME_NOT_EXIST, AOR_NAME_TOO_LONG, AOR_OK, AOR_PASS_TOO_LONG, LOGIN_SEL_ACCOUNT_BY_ID, LOGIN_UPD_LOGON, LOGIN_UPD_USERNAME, LoginDatabase, Acore::Crypto::SRP6::MakeRegistrationData(), MAX_ACCOUNT_STR, MAX_PASS_STR, PreparedStatementBase::SetData(), utf8length(), and Utf8ToUpperOnlyLatin().

◆ CheckPassword()

bool AccountMgr::CheckPassword ( uint32  accountId,
std::string  password 
)
280 {
281 std::string username;
282
283 if (!GetName(accountId, username))
284 return false;
285
286 Utf8ToUpperOnlyLatin(username);
287 Utf8ToUpperOnlyLatin(password);
288
290 stmt->SetData(0, accountId);
291 if (PreparedQueryResult result = LoginDatabase.Query(stmt))
292 {
295 if (Acore::Crypto::SRP6::CheckLogin(username, password, salt, verifier))
296 return true;
297 }
298
299 return false;
300 }
std::vector< uint8 > Binary
Definition Field.h:40
@ LOGIN_SEL_CHECK_PASSWORD
Definition LoginDatabase.h:86
static constexpr std::size_t VERIFIER_LENGTH
Definition SRP6.h:34
std::array< uint8, SALT_LENGTH > Salt
Definition SRP6.h:32
static bool CheckLogin(std::string const &username, std::string const &password, Salt const &salt, Verifier const &verifier)
Definition SRP6.h:47
std::array< uint8, VERIFIER_LENGTH > Verifier
Definition SRP6.h:35
static constexpr std::size_t SALT_LENGTH
Definition SRP6.h:31

References Acore::Crypto::SRP6::CheckLogin(), GetName(), LOGIN_SEL_CHECK_PASSWORD, LoginDatabase, Acore::Crypto::SRP6::SALT_LENGTH, PreparedStatementBase::SetData(), Utf8ToUpperOnlyLatin(), and Acore::Crypto::SRP6::VERIFIER_LENGTH.

Referenced by account_commandscript::HandleAccountPasswordCommand(), and ns1__executeCommand().

◆ CreateAccount()

AccountOpResult AccountMgr::CreateAccount ( std::string  username,
std::string  password,
std::string  email 
)
32 {
33 if (utf8length(username) > MAX_ACCOUNT_STR)
34 return AOR_NAME_TOO_LONG; // username's too long
35
36 if (utf8length(password) > MAX_PASS_STR)
37 return AOR_PASS_TOO_LONG; // password's too long
38
39 if (utf8length(email) > MAX_EMAIL_STR)
40 return AOR_EMAIL_TOO_LONG; // email is too long
41
42 Utf8ToUpperOnlyLatin(username);
43 Utf8ToUpperOnlyLatin(password);
45
46 if (GetId(username))
47 return AOR_NAME_ALREADY_EXIST; // username does already exist
48
50
51 stmt->SetData(0, username);
52 auto [salt, verifier] = Acore::Crypto::SRP6::MakeRegistrationData(username, password);
53 stmt->SetData(1, salt);
54 stmt->SetData(2, verifier);
55 stmt->SetData(3, uint8(sWorld->getIntConfig(CONFIG_EXPANSION)));
56 stmt->SetData(4, email);
57 stmt->SetData(5, email);
58
59 LoginDatabase.Execute(stmt);
60
61 stmt = LoginDatabase.GetPreparedStatement(LOGIN_INS_REALM_CHARACTERS_INIT);
62
63 LoginDatabase.Execute(stmt);
64
65 return AOR_OK; // everything's fine
66 }
@ AOR_NAME_ALREADY_EXIST
Definition AccountMgr.h:31
std::uint8_t uint8
Definition Define.h:109
@ LOGIN_INS_REALM_CHARACTERS_INIT
Definition LoginDatabase.h:66
@ LOGIN_INS_ACCOUNT
Definition LoginDatabase.h:65
@ CONFIG_EXPANSION
Definition WorldConfig.h:225
#define sWorld
Definition World.h:320
uint32 GetId(std::string const &username)
Definition AccountMgr.cpp:236

References AOR_EMAIL_TOO_LONG, AOR_NAME_ALREADY_EXIST, AOR_NAME_TOO_LONG, AOR_OK, AOR_PASS_TOO_LONG, CONFIG_EXPANSION, GetId(), LOGIN_INS_ACCOUNT, LOGIN_INS_REALM_CHARACTERS_INIT, LoginDatabase, Acore::Crypto::SRP6::MakeRegistrationData(), MAX_ACCOUNT_STR, MAX_EMAIL_STR, MAX_PASS_STR, PreparedStatementBase::SetData(), sWorld, utf8length(), and Utf8ToUpperOnlyLatin().

Referenced by account_commandscript::HandleAccountCreateCommand().

◆ DeleteAccount()

AccountOpResult AccountMgr::DeleteAccount ( uint32  accountId)
96 {
97 // Check if accounts exists
99 loginStmt->SetData(0, accountId);
100
101 PreparedQueryResult result = LoginDatabase.Query(loginStmt);
102 if (!result)
103 return AOR_NAME_NOT_EXIST;
104
105 sScriptMgr->OnBeforeAccountDelete(accountId);
106
107 // Obtain accounts characters
109 stmt->SetData(0, accountId);
110
111 result = CharacterDatabase.Query(stmt);
112
113 if (result)
114 {
115 do
116 {
117 ObjectGuid guid = ObjectGuid::Create<HighGuid::Player>((*result)[0].Get<uint32>());
118
119 // Kick if player is online
120 if (Player* p = ObjectAccessor::FindPlayer(guid))
121 {
122 WorldSession* s = p->GetSession();
123 s->KickPlayer("Delete account"); // mark session to remove at next session list update
124 s->LogoutPlayer(false); // logout player without waiting next session list update
125 }
126
127 Player::DeleteFromDB(guid.GetCounter(), accountId, false, true); // no need to update realm characters
128 } while (result->NextRow());
129 }
130
131 // table realm specific but common for all characters of account for realm
132 stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_TUTORIALS);
133 stmt->SetData(0, accountId);
134 CharacterDatabase.Execute(stmt);
135
136 stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_ACCOUNT_DATA);
137 stmt->SetData(0, accountId);
138 CharacterDatabase.Execute(stmt);
139
140 stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_CHARACTER_BAN);
141 stmt->SetData(0, accountId);
142 CharacterDatabase.Execute(stmt);
143
144 LoginDatabaseTransaction trans = LoginDatabase.BeginTransaction();
145
146 loginStmt = LoginDatabase.GetPreparedStatement(LOGIN_DEL_ACCOUNT);
147 loginStmt->SetData(0, accountId);
148 trans->Append(loginStmt);
149
150 loginStmt = LoginDatabase.GetPreparedStatement(LOGIN_DEL_ACCOUNT_ACCESS);
151 loginStmt->SetData(0, accountId);
152 trans->Append(loginStmt);
153
154 loginStmt = LoginDatabase.GetPreparedStatement(LOGIN_DEL_REALM_CHARACTERS);
155 loginStmt->SetData(0, accountId);
156 trans->Append(loginStmt);
157
158 loginStmt = LoginDatabase.GetPreparedStatement(LOGIN_DEL_ACCOUNT_BANNED);
159 loginStmt->SetData(0, accountId);
160 trans->Append(loginStmt);
161
162 loginStmt = LoginDatabase.GetPreparedStatement(LOGIN_DEL_ACCOUNT_MUTED);
163 loginStmt->SetData(0, accountId);
164 trans->Append(loginStmt);
165
166 LoginDatabase.CommitTransaction(trans);
167
168 return AOR_OK;
169 }
@ CHAR_DEL_CHARACTER_BAN
Definition CharacterDatabase.h:43
@ CHAR_DEL_TUTORIALS
Definition CharacterDatabase.h:209
@ CHAR_DEL_ACCOUNT_DATA
Definition CharacterDatabase.h:200
@ CHAR_SEL_CHARS_BY_ACCOUNT_ID
Definition CharacterDatabase.h:336
SQLTransaction< LoginDatabaseConnection > LoginDatabaseTransaction
Definition DatabaseEnvFwd.h:70
DatabaseWorkerPool< CharacterDatabaseConnection > CharacterDatabase
Accessor to the character database.
Definition DatabaseEnv.cpp:21
@ LOGIN_DEL_ACCOUNT_MUTED
Definition LoginDatabase.h:116
@ LOGIN_DEL_ACCOUNT_BANNED
Definition LoginDatabase.h:41
@ LOGIN_DEL_ACCOUNT_ACCESS
Definition LoginDatabase.h:79
@ LOGIN_DEL_ACCOUNT
Definition LoginDatabase.h:100
@ LOGIN_DEL_REALM_CHARACTERS
Definition LoginDatabase.h:62
Definition ObjectGuid.h:118
LowType GetCounter() const
Definition ObjectGuid.h:145
Definition Player.h:1083
static void DeleteFromDB(ObjectGuid::LowType lowGuid, uint32 accountId, bool updateRealmChars, bool deleteFinally)
Definition Player.cpp:3997
Player session in the World.
Definition WorldSession.h:330
void LogoutPlayer(bool save)
Log the player out
Definition WorldSession.cpp:610
void KickPlayer(bool setKicked=true)
Definition WorldSession.h:419
Player * FindPlayer(ObjectGuid const guid)
Definition ObjectAccessor.cpp:245

References AOR_NAME_NOT_EXIST, AOR_OK, CHAR_DEL_ACCOUNT_DATA, CHAR_DEL_CHARACTER_BAN, CHAR_DEL_TUTORIALS, CHAR_SEL_CHARS_BY_ACCOUNT_ID, CharacterDatabase, Player::DeleteFromDB(), ObjectAccessor::FindPlayer(), ObjectGuid::GetCounter(), WorldSession::KickPlayer(), LOGIN_DEL_ACCOUNT, LOGIN_DEL_ACCOUNT_ACCESS, LOGIN_DEL_ACCOUNT_BANNED, LOGIN_DEL_ACCOUNT_MUTED, LOGIN_DEL_REALM_CHARACTERS, LOGIN_SEL_ACCOUNT_BY_ID, LoginDatabase, WorldSession::LogoutPlayer(), PreparedStatementBase::SetData(), and sScriptMgr.

Referenced by account_commandscript::HandleAccountDeleteCommand().

◆ GetCharactersCount()

uint32 AccountMgr::GetCharactersCount ( uint32  accountId)
303 {
304 // check character count
306 stmt->SetData(0, accountId);
307 PreparedQueryResult result = CharacterDatabase.Query(stmt);
308
309 return (result) ? (*result)[0].Get<uint64>() : 0;
310 }
@ CHAR_SEL_SUM_CHARS
Definition CharacterDatabase.h:39
std::uint64_t uint64
Definition Define.h:106

References CHAR_SEL_SUM_CHARS, CharacterDatabase, and PreparedStatementBase::SetData().

Referenced by character_commandscript::HandleCharacterChangeAccountCommand(), character_commandscript::HandleCharacterDeletedRestoreHelper(), and PlayerDumpReader::LoadDump().

◆ GetId()

◆ GetName()

◆ GetSecurity() [1/2]

◆ GetSecurity() [2/2]

uint32 AccountMgr::GetSecurity ( uint32  accountId,
int32  realmId 
)
255 {
257 stmt->SetData(0, accountId);
258 stmt->SetData(1, realmId);
259 PreparedQueryResult result = LoginDatabase.Query(stmt);
260
261 return (result) ? (*result)[0].Get<uint8>() : uint32(SEC_PLAYER);
262 }
@ LOGIN_GET_GMLEVEL_BY_REALMID
Definition LoginDatabase.h:84

References LOGIN_GET_GMLEVEL_BY_REALMID, LoginDatabase, SEC_PLAYER, and PreparedStatementBase::SetData().

◆ IsAdminAccount()

bool AccountMgr::IsAdminAccount ( uint32  gmlevel)
323 {
324 return gmlevel >= SEC_ADMINISTRATOR && gmlevel <= SEC_CONSOLE;
325 }
@ SEC_ADMINISTRATOR
Definition Common.h:60
@ SEC_CONSOLE
Definition Common.h:61

References SEC_ADMINISTRATOR, and SEC_CONSOLE.

Referenced by ticket_commandscript::HandleGMTicketAssignToCommand(), WorldSession::HandleWhoisOpcode(), and WorldSession::HandleWorldTeleportOpcode().

◆ IsConsoleAccount()

bool AccountMgr::IsConsoleAccount ( uint32  gmlevel)
328 {
329 return gmlevel == SEC_CONSOLE;
330 }

References SEC_CONSOLE.

Referenced by account_commandscript::HandleAccountSetGmLevelCommand().

◆ IsGMAccount()

bool AccountMgr::IsGMAccount ( uint32  gmlevel)
318 {
319 return gmlevel >= SEC_GAMEMASTER;
320 }
@ SEC_GAMEMASTER
Definition Common.h:59

References SEC_GAMEMASTER.

◆ IsPlayerAccount()