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

Functions

AccountOpResult CreateAccount (std::string username, std::string password)
 
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

◆ ChangePassword()

AccountOpResult AccountMgr::ChangePassword ( uint32  accountId,
std::string  newPassword 
)
170 {
171 std::string username;
172
173 if (!GetName(accountId, username))
174 {
175 sScriptMgr->OnFailedPasswordChange(accountId);
176 return AOR_NAME_NOT_EXIST; // account doesn't exist
177 }
178
179 if (utf8length(newPassword) > MAX_PASS_STR)
180 {
181 sScriptMgr->OnFailedEmailChange(accountId);
182 return AOR_PASS_TOO_LONG; // password's too long
183 }
184
185 Utf8ToUpperOnlyLatin(username);
186 Utf8ToUpperOnlyLatin(newPassword);
187
188 auto [salt, verifier] = Acore::Crypto::SRP6::MakeRegistrationData(username, newPassword);
189
191 stmt->SetData(0, salt);
192 stmt->SetData(1, verifier);
193 stmt->SetData(2, accountId);
194 LoginDatabase.Execute(stmt);
195
196 sScriptMgr->OnPasswordChange(accountId);
197 return AOR_OK;
198 }
bool Utf8ToUpperOnlyLatin(std::string &utf8String)
Definition: Util.cpp:528
size_t utf8length(std::string &utf8str)
Definition: Util.cpp:246
DatabaseWorkerPool< LoginDatabaseConnection > LoginDatabase
Accessor to the realm/login database.
Definition: DatabaseEnv.cpp:22
@ LOGIN_UPD_LOGON
Definition: LoginDatabase.h:42
@ AOR_NAME_NOT_EXIST
Definition: AccountMgr.h:30
@ AOR_OK
Definition: AccountMgr.h:26
@ AOR_PASS_TOO_LONG
Definition: AccountMgr.h:28
#define MAX_PASS_STR
Definition: AccountMgr.h:35
#define sScriptMgr
Definition: ScriptMgr.h:2690
bool GetName(uint32 accountId, std::string &name)
Definition: AccountMgr.cpp:228
static std::pair< Salt, Verifier > MakeRegistrationData(std::string const &username, std::string const &password)
Definition: SRP6.cpp:31
Definition: PreparedStatement.h:158
Acore::Types::is_default< T > SetData(const uint8 index, T value)
Definition: PreparedStatement.h:78

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 
)
136 {
137 // Check if accounts exists
139 stmt->SetData(0, accountId);
140 PreparedQueryResult result = LoginDatabase.Query(stmt);
141
142 if (!result)
143 return AOR_NAME_NOT_EXIST;
144
145 if (utf8length(newUsername) > MAX_ACCOUNT_STR)
146 return AOR_NAME_TOO_LONG;
147
148 if (utf8length(newPassword) > MAX_PASS_STR)
149 return AOR_PASS_TOO_LONG; // password's too long
150
151 Utf8ToUpperOnlyLatin(newUsername);
152 Utf8ToUpperOnlyLatin(newPassword);
153
154 stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_USERNAME);
155 stmt->SetData(0, newUsername);
156 stmt->SetData(1, accountId);
157 LoginDatabase.Execute(stmt);
158
159 auto [salt, verifier] = Acore::Crypto::SRP6::MakeRegistrationData(newUsername, newPassword);
160 stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_LOGON);
161 stmt->SetData(0, salt);
162 stmt->SetData(1, verifier);
163 stmt->SetData(2, accountId);
164 LoginDatabase.Execute(stmt);
165
166 return AOR_OK;
167 }
std::shared_ptr< PreparedResultSet > PreparedQueryResult
Definition: DatabaseEnvFwd.h:46
@ LOGIN_SEL_ACCOUNT_BY_ID
Definition: LoginDatabase.h:59
@ LOGIN_UPD_USERNAME
Definition: LoginDatabase.h:70
@ AOR_NAME_TOO_LONG
Definition: AccountMgr.h:27
#define MAX_ACCOUNT_STR
Definition: AccountMgr.h:34

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 
)
244 {
245 std::string username;
246
247 if (!GetName(accountId, username))
248 return false;
249
250 Utf8ToUpperOnlyLatin(username);
251 Utf8ToUpperOnlyLatin(password);
252
254 stmt->SetData(0, accountId);
255 if (PreparedQueryResult result = LoginDatabase.Query(stmt))
256 {
259 if (Acore::Crypto::SRP6::CheckLogin(username, password, salt, verifier))
260 return true;
261 }
262
263 return false;
264 }
std::vector< uint8 > Binary
Definition: Field.h:41
@ LOGIN_SEL_CHECK_PASSWORD
Definition: LoginDatabase.h:85
static constexpr size_t SALT_LENGTH
Definition: SRP6.h:34
std::array< uint8, SALT_LENGTH > Salt
Definition: SRP6.h:35
static bool CheckLogin(std::string const &username, std::string const &password, Salt const &salt, Verifier const &verifier)
Definition: SRP6.h:47
static constexpr size_t VERIFIER_LENGTH
Definition: SRP6.h:36
std::array< uint8, VERIFIER_LENGTH > Verifier
Definition: SRP6.h:37

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:110
@ LOGIN_INS_REALM_CHARACTERS_INIT
Definition: LoginDatabase.h:66
@ LOGIN_INS_ACCOUNT
Definition: LoginDatabase.h:65
@ AOR_NAME_ALREADY_EXIST
Definition: AccountMgr.h:29
@ CONFIG_EXPANSION
Definition: IWorld.h:281
#define sWorld
Definition: World.h:458
uint32 GetId(std::string const &username)
Definition: AccountMgr.cpp:200

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)
62 {
63 // Check if accounts exists
65 loginStmt->SetData(0, accountId);
66
67 PreparedQueryResult result = LoginDatabase.Query(loginStmt);
68 if (!result)
69 return AOR_NAME_NOT_EXIST;
70
71 // Obtain accounts characters
73 stmt->SetData(0, accountId);
74
75 result = CharacterDatabase.Query(stmt);
76
77 if (result)
78 {
79 do
80 {
81 ObjectGuid guid = ObjectGuid::Create<HighGuid::Player>((*result)[0].Get<uint32>());
82
83 // Kick if player is online
85 {
86 WorldSession* s = p->GetSession();
87 s->KickPlayer("Delete account"); // mark session to remove at next session list update
88 s->LogoutPlayer(false); // logout player without waiting next session list update
89 }
90
91 Player::DeleteFromDB(guid.GetCounter(), accountId, false, true); // no need to update realm characters
92 } while (result->NextRow());
93 }
94
95 // table realm specific but common for all characters of account for realm
96 stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_TUTORIALS);
97 stmt->SetData(0, accountId);
98 CharacterDatabase.Execute(stmt);
99
100 stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_ACCOUNT_DATA);
101 stmt->SetData(0, accountId);
102 CharacterDatabase.Execute(stmt);
103
104 stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_CHARACTER_BAN);
105 stmt->SetData(0, accountId);
106 CharacterDatabase.Execute(stmt);
107
108 LoginDatabaseTransaction trans = LoginDatabase.BeginTransaction();
109
110 loginStmt = LoginDatabase.GetPreparedStatement(LOGIN_DEL_ACCOUNT);
111 loginStmt->SetData(0, accountId);
112 trans->Append(loginStmt);
113
114 loginStmt = LoginDatabase.GetPreparedStatement(LOGIN_DEL_ACCOUNT_ACCESS);
115 loginStmt->SetData(0, accountId);
116 trans->Append(loginStmt);
117
118 loginStmt = LoginDatabase.GetPreparedStatement(LOGIN_DEL_REALM_CHARACTERS);
119 loginStmt->SetData(0, accountId);
120 trans->Append(loginStmt);
121
122 loginStmt = LoginDatabase.GetPreparedStatement(LOGIN_DEL_ACCOUNT_BANNED);
123 loginStmt->SetData(0, accountId);
124 trans->Append(loginStmt);
125
126 loginStmt = LoginDatabase.GetPreparedStatement(LOGIN_DEL_ACCOUNT_MUTED);
127 loginStmt->SetData(0, accountId);
128 trans->Append(loginStmt);
129
130 LoginDatabase.CommitTransaction(trans);
131
132 return AOR_OK;
133 }
DatabaseWorkerPool< CharacterDatabaseConnection > CharacterDatabase
Accessor to the character database.
Definition: DatabaseEnv.cpp:21
SQLTransaction< LoginDatabaseConnection > LoginDatabaseTransaction
Definition: DatabaseEnvFwd.h:71
@ 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:108
@ LOGIN_DEL_ACCOUNT_BANNED
Definition: LoginDatabase.h:41
@ LOGIN_DEL_ACCOUNT_ACCESS
Definition: LoginDatabase.h:78
@ LOGIN_DEL_ACCOUNT
Definition: LoginDatabase.h:97
@ LOGIN_DEL_REALM_CHARACTERS
Definition: LoginDatabase.h:62
Player * FindPlayer(ObjectGuid const guid)
Definition: ObjectAccessor.cpp:250
Definition: ObjectGuid.h:120
LowType GetCounter() const
Definition: ObjectGuid.h:147
Definition: Player.h:1046
static void DeleteFromDB(ObjectGuid::LowType lowGuid, uint32 accountId, bool updateRealmChars, bool deleteFinally)
Definition: Player.cpp:3908
Player session in the World.
Definition: WorldSession.h:330
void LogoutPlayer(bool save)
Log the player out
Definition: WorldSession.cpp:550
void KickPlayer(bool setKicked=true)
Definition: WorldSession.h:397

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(), and PreparedStatementBase::SetData().

Referenced by account_commandscript::HandleAccountDeleteCommand().

◆ GetCharactersCount()

uint32 AccountMgr::GetCharactersCount ( uint32  accountId)
267 {
268 // check character count
270 stmt->SetData(0, accountId);
271 PreparedQueryResult result = CharacterDatabase.Query(stmt);
272
273 return (result) ? (*result)[0].Get<uint64>() : 0;
274 }
std::uint64_t uint64
Definition: Define.h:107
@ 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 
)
219 {
221 stmt->SetData(0, accountId);
222 stmt->SetData(1, realmId);
223 PreparedQueryResult result = LoginDatabase.Query(stmt);
224
225 return (result) ? (*result)[0].Get<uint8>() : uint32(SEC_PLAYER);
226 }
@ LOGIN_GET_GMLEVEL_BY_REALMID
Definition: LoginDatabase.h:83

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

◆ IsAdminAccount()

bool AccountMgr::IsAdminAccount ( uint32  gmlevel)
287 {
288 return gmlevel >= SEC_ADMINISTRATOR && gmlevel <= SEC_CONSOLE;
289 }
@ SEC_ADMINISTRATOR
Definition: Common.h:69
@ SEC_CONSOLE
Definition: Common.h:70

References SEC_ADMINISTRATOR, and SEC_CONSOLE.

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

◆ IsConsoleAccount()

bool AccountMgr::IsConsoleAccount ( uint32  gmlevel)
292 {
293 return gmlevel == SEC_CONSOLE;
294 }

References SEC_CONSOLE.

Referenced by account_commandscript::HandleAccountSetGmLevelCommand().

◆ IsGMAccount()

◆ IsPlayerAccount()