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

Functions

AccountOpResult CreateAccount (std::string username, std::string password)
 
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 IsAdminAccount (uint32 gmlevel)
 
bool IsConsoleAccount (uint32 gmlevel)
 

Function Documentation

◆ ChangeEmail()

AccountOpResult AccountMgr::ChangeEmail ( uint32  accountId,
std::string  newEmail 
)
62 {
63 std::string username;
64
65 if (!GetName(accountId, username))
66 {
67 sScriptMgr->OnFailedEmailChange(accountId);
68 return AOR_NAME_NOT_EXIST; // account doesn't exist
69 }
70
71 if (utf8length(newEmail) > MAX_EMAIL_STR)
72 {
73 sScriptMgr->OnFailedEmailChange(accountId);
74 return AOR_EMAIL_TOO_LONG; // email's too long
75 }
76
77 Utf8ToUpperOnlyLatin(newEmail);
78
80 stmt->SetData(0, newEmail);
81 stmt->SetData(1, accountId);
82 LoginDatabase.Execute(stmt);
83
84 sScriptMgr->OnEmailChange(accountId);
85 return AOR_OK;
86 }
bool Utf8ToUpperOnlyLatin(std::string &utf8String)
Definition: Util.cpp:532
std::size_t utf8length(std::string &utf8str)
Definition: Util.cpp:245
@ AOR_NAME_NOT_EXIST
Definition: AccountMgr.h:31
@ AOR_OK
Definition: AccountMgr.h:26
@ AOR_EMAIL_TOO_LONG
Definition: AccountMgr.h:29
#define MAX_EMAIL_STR
Definition: AccountMgr.h:37
#define sScriptMgr
Definition: ScriptMgr.h:709
@ LOGIN_UPD_EMAIL
Definition: LoginDatabase.h:70
DatabaseWorkerPool< LoginDatabaseConnection > LoginDatabase
Accessor to the realm/login database.
Definition: DatabaseEnv.cpp:22
bool GetName(uint32 accountId, std::string &name)
Definition: AccountMgr.cpp:257
Definition: PreparedStatement.h:157
Acore::Types::is_default< T > SetData(const uint8 index, T value)
Definition: PreparedStatement.h:77

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 
)
199 {
200 std::string username;
201
202 if (!GetName(accountId, username))
203 {
204 sScriptMgr->OnFailedPasswordChange(accountId);
205 return AOR_NAME_NOT_EXIST; // account doesn't exist
206 }
207
208 if (utf8length(newPassword) > MAX_PASS_STR)
209 {
210 sScriptMgr->OnFailedEmailChange(accountId);
211 return AOR_PASS_TOO_LONG; // password's too long
212 }
213
214 Utf8ToUpperOnlyLatin(username);
215 Utf8ToUpperOnlyLatin(newPassword);
216
217 auto [salt, verifier] = Acore::Crypto::SRP6::MakeRegistrationData(username, newPassword);
218
220 stmt->SetData(0, salt);
221 stmt->SetData(1, verifier);
222 stmt->SetData(2, accountId);
223 LoginDatabase.Execute(stmt);
224
225 sScriptMgr->OnPasswordChange(accountId);
226 return AOR_OK;
227 }
@ AOR_PASS_TOO_LONG
Definition: AccountMgr.h:28
#define MAX_PASS_STR
Definition: AccountMgr.h:36
@ 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 
)
165 {
166 // Check if accounts exists
168 stmt->SetData(0, accountId);
169 PreparedQueryResult result = LoginDatabase.Query(stmt);
170
171 if (!result)
172 return AOR_NAME_NOT_EXIST;
173
174 if (utf8length(newUsername) > MAX_ACCOUNT_STR)
175 return AOR_NAME_TOO_LONG;
176
177 if (utf8length(newPassword) > MAX_PASS_STR)
178 return AOR_PASS_TOO_LONG; // password's too long
179
180 Utf8ToUpperOnlyLatin(newUsername);
181 Utf8ToUpperOnlyLatin(newPassword);
182
183 stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_USERNAME);
184 stmt->SetData(0, newUsername);
185 stmt->SetData(1, accountId);
186 LoginDatabase.Execute(stmt);
187
188 auto [salt, verifier] = Acore::Crypto::SRP6::MakeRegistrationData(newUsername, newPassword);
189 stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_LOGON);
190 stmt->SetData(0, salt);
191 stmt->SetData(1, verifier);
192 stmt->SetData(2, accountId);
193 LoginDatabase.Execute(stmt);
194
195 return AOR_OK;
196 }
@ AOR_NAME_TOO_LONG
Definition: AccountMgr.h:27
#define MAX_ACCOUNT_STR
Definition: AccountMgr.h:35
@ LOGIN_SEL_ACCOUNT_BY_ID
Definition: LoginDatabase.h:59
@ LOGIN_UPD_USERNAME
Definition: LoginDatabase.h:71
std::shared_ptr< PreparedResultSet > PreparedQueryResult
Definition: DatabaseEnvFwd.h:45

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 
)
273 {
274 std::string username;
275
276 if (!GetName(accountId, username))
277 return false;
278
279 Utf8ToUpperOnlyLatin(username);
280 Utf8ToUpperOnlyLatin(password);
281
283 stmt->SetData(0, accountId);
284 if (PreparedQueryResult result = LoginDatabase.Query(stmt))
285 {
288 if (Acore::Crypto::SRP6::CheckLogin(username, password, salt, verifier))
289 return true;
290 }
291
292 return false;
293 }
@ LOGIN_SEL_CHECK_PASSWORD
Definition: LoginDatabase.h:86
std::vector< uint8 > Binary
Definition: Field.h:40
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 
)
31 {
32 if (utf8length(username) > MAX_ACCOUNT_STR)
33 return AOR_NAME_TOO_LONG; // username's too long
34
35 if (utf8length(password) > MAX_PASS_STR)
36 return AOR_PASS_TOO_LONG; // password's too long
37
38 Utf8ToUpperOnlyLatin(username);
39 Utf8ToUpperOnlyLatin(password);
40
41 if (GetId(username))
42 return AOR_NAME_ALREADY_EXIST; // username does already exist
43
45
46 stmt->SetData(0, username);
47 auto [salt, verifier] = Acore::Crypto::SRP6::MakeRegistrationData(username, password);
48 stmt->SetData(1, salt);
49 stmt->SetData(2, verifier);
50 stmt->SetData(3, uint8(sWorld->getIntConfig(CONFIG_EXPANSION)));
51
52 LoginDatabase.Execute(stmt);
53
54 stmt = LoginDatabase.GetPreparedStatement(LOGIN_INS_REALM_CHARACTERS_INIT);
55
56 LoginDatabase.Execute(stmt);
57
58 return AOR_OK; // everything's fine
59 }
std::uint8_t uint8
Definition: Define.h:109
@ AOR_NAME_ALREADY_EXIST
Definition: AccountMgr.h:30
@ CONFIG_EXPANSION
Definition: IWorld.h:276
@ LOGIN_INS_REALM_CHARACTERS_INIT
Definition: LoginDatabase.h:66
@ LOGIN_INS_ACCOUNT
Definition: LoginDatabase.h:65
#define sWorld
Definition: World.h:443
uint32 GetId(std::string const &username)
Definition: AccountMgr.cpp:229

References 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_PASS_STR, PreparedStatementBase::SetData(), sWorld, utf8length(), and Utf8ToUpperOnlyLatin().

Referenced by account_commandscript::HandleAccountCreateCommand().

◆ DeleteAccount()

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

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)
296 {
297 // check character count
299 stmt->SetData(0, accountId);
300 PreparedQueryResult result = CharacterDatabase.Query(stmt);
301
302 return (result) ? (*result)[0].Get<uint64>() : 0;
303 }
std::uint64_t uint64
Definition: Define.h:106
@ CHAR_SEL_SUM_CHARS
Definition: CharacterDatabase.h:39

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 
)
248 {
250 stmt->SetData(0, accountId);
251 stmt->SetData(1, realmId);
252 PreparedQueryResult result = LoginDatabase.Query(stmt);
253
254 return (result) ? (*result)[0].Get<uint8>() : uint32(SEC_PLAYER);
255 }
@ 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)
311 {
312 return gmlevel >= SEC_ADMINISTRATOR && gmlevel <= SEC_CONSOLE;
313 }
@ 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)
316 {
317 return gmlevel == SEC_CONSOLE;
318 }

References SEC_CONSOLE.

Referenced by account_commandscript::HandleAccountSetGmLevelCommand().

◆ IsPlayerAccount()