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

#include "AccountMgr.h"

Public Member Functions

AccountOpResult CreateAccount (std::string username, std::string password, std::string email="")
 
void UpdateAccountAccess (rbac::RBACData *rbac, uint32 accountId, uint8 securityLevel, int32 realmId)
 
void LoadRBAC ()
 
rbac::RBACPermission const * GetRBACPermission (uint32 permission) const
 
rbac::RBACPermissionsContainer const & GetRBACPermissionList () const
 
rbac::RBACPermissionContainer const & GetRBACDefaultPermissions (uint8 secLevel)
 
void AddPermissionForTest (uint32 permissionId, std::string const &name)
 
void AddLinkedPermissionForTest (uint32 permissionId, uint32 linkedPermissionId)
 
void AddDefaultPermissionForTest (uint8 secLevel, uint32 permissionId)
 
void ClearPermissionsForTest ()
 

Static Public Member Functions

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

Private Member Functions

 AccountMgr ()
 
 ~AccountMgr ()
 
void ClearRBAC ()
 

Private Attributes

rbac::RBACPermissionsContainer _permissions
 
rbac::RBACDefaultPermissionsContainer _defaultPermissions
 

Detailed Description

Constructor & Destructor Documentation

◆ AccountMgr()

AccountMgr::AccountMgr ( )
private
30{ }

◆ ~AccountMgr()

AccountMgr::~AccountMgr ( )
private
33{
34 ClearRBAC();
35}
void ClearRBAC()
Definition AccountMgr.cpp:513

References ClearRBAC().

Member Function Documentation

◆ AddDefaultPermissionForTest()

void AccountMgr::AddDefaultPermissionForTest ( uint8  secLevel,
uint32  permissionId 
)
538{
539 _defaultPermissions[secLevel].insert(permissionId);
540}
rbac::RBACDefaultPermissionsContainer _defaultPermissions
Definition AccountMgr.h:90

References _defaultPermissions.

◆ AddLinkedPermissionForTest()

void AccountMgr::AddLinkedPermissionForTest ( uint32  permissionId,
uint32  linkedPermissionId 
)
531{
532 auto it = _permissions.find(permissionId);
533 if (it != _permissions.end())
534 it->second->AddLinkedPermission(linkedPermissionId);
535}
rbac::RBACPermissionsContainer _permissions
Definition AccountMgr.h:89

References _permissions.

◆ AddPermissionForTest()

void AccountMgr::AddPermissionForTest ( uint32  permissionId,
std::string const &  name 
)
523{
524 if (_permissions.find(permissionId) != _permissions.end())
525 return;
526
527 _permissions[permissionId] = new rbac::RBACPermission(permissionId, name);
528}
Definition RBAC.h:727

References _permissions.

◆ ChangeEmail()

AccountOpResult AccountMgr::ChangeEmail ( uint32  accountId,
std::string  email 
)
static
81{
82 std::string username;
83
84 if (!GetName(accountId, username))
85 {
86 sScriptMgr->OnFailedEmailChange(accountId);
87 return AOR_NAME_NOT_EXIST; // account doesn't exist
88 }
89
90 if (utf8length(newEmail) > MAX_EMAIL_STR)
91 {
92 sScriptMgr->OnFailedEmailChange(accountId);
93 return AOR_EMAIL_TOO_LONG; // email's too long
94 }
95
96 Utf8ToUpperOnlyLatin(newEmail);
97
99 stmt->SetData(0, newEmail);
100 stmt->SetData(1, accountId);
101 LoginDatabase.Execute(stmt);
102
103 sScriptMgr->OnEmailChange(accountId);
104 return AOR_OK;
105}
@ AOR_NAME_NOT_EXIST
Definition AccountMgr.h:30
@ AOR_OK
Definition AccountMgr.h:25
@ AOR_EMAIL_TOO_LONG
Definition AccountMgr.h:28
#define MAX_EMAIL_STR
Definition AccountMgr.h:36
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:769
bool Utf8ToUpperOnlyLatin(std::string &utf8String)
Definition Util.cpp:532
std::size_t utf8length(std::string &utf8str)
Definition Util.cpp:245
static bool GetName(uint32 accountId, std::string &name)
Definition AccountMgr.cpp:276
Acore::Types::is_default< T > SetData(const uint8 index, T value)
Definition PreparedStatement.h:77
Definition PreparedStatement.h:157

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 
)
static
218{
219 std::string username;
220
221 if (!GetName(accountId, username))
222 {
223 sScriptMgr->OnFailedPasswordChange(accountId);
224 return AOR_NAME_NOT_EXIST; // account doesn't exist
225 }
226
227 if (utf8length(newPassword) > MAX_PASS_STR)
228 {
229 sScriptMgr->OnFailedEmailChange(accountId);
230 return AOR_PASS_TOO_LONG; // password's too long
231 }
232
233 Utf8ToUpperOnlyLatin(username);
234 Utf8ToUpperOnlyLatin(newPassword);
235
236 auto [salt, verifier] = Acore::Crypto::SRP6::MakeRegistrationData(username, newPassword);
237
239 stmt->SetData(0, salt);
240 stmt->SetData(1, verifier);
241 stmt->SetData(2, accountId);
242 LoginDatabase.Execute(stmt);
243
244 sScriptMgr->OnPasswordChange(accountId);
245 return AOR_OK;
246}
@ AOR_PASS_TOO_LONG
Definition AccountMgr.h:27
#define MAX_PASS_STR
Definition AccountMgr.h:35
@ 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 
)
static
184{
185 // Check if accounts exists
187 stmt->SetData(0, accountId);
188 PreparedQueryResult result = LoginDatabase.Query(stmt);
189
190 if (!result)
191 return AOR_NAME_NOT_EXIST;
192
193 if (utf8length(newUsername) > MAX_ACCOUNT_STR)
194 return AOR_NAME_TOO_LONG;
195
196 if (utf8length(newPassword) > MAX_PASS_STR)
197 return AOR_PASS_TOO_LONG; // password's too long
198
199 Utf8ToUpperOnlyLatin(newUsername);
200 Utf8ToUpperOnlyLatin(newPassword);
201
202 stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_USERNAME);
203 stmt->SetData(0, newUsername);
204 stmt->SetData(1, accountId);
205 LoginDatabase.Execute(stmt);
206
207 auto [salt, verifier] = Acore::Crypto::SRP6::MakeRegistrationData(newUsername, newPassword);
208 stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_LOGON);
209 stmt->SetData(0, salt);
210 stmt->SetData(1, verifier);
211 stmt->SetData(2, accountId);
212 LoginDatabase.Execute(stmt);
213
214 return AOR_OK;
215}
@ AOR_NAME_TOO_LONG
Definition AccountMgr.h:26
#define MAX_ACCOUNT_STR
Definition AccountMgr.h:34
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 
)
static
292{
293 std::string username;
294
295 if (!GetName(accountId, username))
296 return false;
297
298 if (utf8length(password) > MAX_PASS_STR)
299 return false;
300
301 Utf8ToUpperOnlyLatin(username);
302 Utf8ToUpperOnlyLatin(password);
303
305 stmt->SetData(0, accountId);
306 if (PreparedQueryResult result = LoginDatabase.Query(stmt))
307 {
310 if (Acore::Crypto::SRP6::CheckLogin(username, password, salt, verifier))
311 return true;
312 }
313
314 return false;
315}
std::vector< uint8 > Binary
Definition Field.h:41
@ LOGIN_SEL_CHECK_PASSWORD
Definition LoginDatabase.h:87
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, MAX_PASS_STR, Acore::Crypto::SRP6::SALT_LENGTH, PreparedStatementBase::SetData(), utf8length(), Utf8ToUpperOnlyLatin(), and Acore::Crypto::SRP6::VERIFIER_LENGTH.

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

◆ ClearPermissionsForTest()

void AccountMgr::ClearPermissionsForTest ( )
543{
544 ClearRBAC();
545}

References ClearRBAC().

◆ ClearRBAC()

void AccountMgr::ClearRBAC ( )
private
514{
515 for (std::pair<uint32 const, rbac::RBACPermission*>& permission : _permissions)
516 delete permission.second;
517
518 _permissions.clear();
519 _defaultPermissions.clear();
520}

References _defaultPermissions, and _permissions.

Referenced by ClearPermissionsForTest(), LoadRBAC(), and ~AccountMgr().

◆ CreateAccount()

AccountOpResult AccountMgr::CreateAccount ( std::string  username,
std::string  password,
std::string  email = "" 
)
44{
45 if (utf8length(username) > MAX_ACCOUNT_STR)
46 return AOR_NAME_TOO_LONG; // username's too long
47
48 if (utf8length(password) > MAX_PASS_STR)
49 return AOR_PASS_TOO_LONG; // password's too long
50
51 if (utf8length(email) > MAX_EMAIL_STR)
52 return AOR_EMAIL_TOO_LONG; // email is too long
53
54 Utf8ToUpperOnlyLatin(username);
55 Utf8ToUpperOnlyLatin(password);
57
58 if (GetId(username))
59 return AOR_NAME_ALREADY_EXIST; // username does already exist
60
62
63 stmt->SetData(0, username);
64 auto [salt, verifier] = Acore::Crypto::SRP6::MakeRegistrationData(username, password);
65 stmt->SetData(1, salt);
66 stmt->SetData(2, verifier);
67 stmt->SetData(3, uint8(sWorld->getIntConfig(CONFIG_EXPANSION)));
68 stmt->SetData(4, email);
69 stmt->SetData(5, email);
70
71 LoginDatabase.Execute(stmt);
72
73 stmt = LoginDatabase.GetPreparedStatement(LOGIN_INS_REALM_CHARACTERS_INIT);
74
75 LoginDatabase.Execute(stmt);
76
77 return AOR_OK; // everything's fine
78}
@ AOR_NAME_ALREADY_EXIST
Definition AccountMgr.h:29
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:235
static uint32 GetId(std::string const &username)
Definition AccountMgr.cpp:248
#define sWorld
Definition World.h:337

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

◆ DeleteAccount()

AccountOpResult AccountMgr::DeleteAccount ( uint32  accountId)
static
108{
109 // Check if accounts exists
111 loginStmt->SetData(0, accountId);
112
113 PreparedQueryResult result = LoginDatabase.Query(loginStmt);
114 if (!result)
115 return AOR_NAME_NOT_EXIST;
116
117 sScriptMgr->OnBeforeAccountDelete(accountId);
118
119 // Obtain accounts characters
121 stmt->SetData(0, accountId);
122
123 result = CharacterDatabase.Query(stmt);
124
125 if (result)
126 {
127 do
128 {
129 ObjectGuid guid = ObjectGuid::Create<HighGuid::Player>((*result)[0].Get<uint32>());
130
131 // Kick if player is online
132 if (Player* p = ObjectAccessor::FindPlayer(guid))
133 {
134 WorldSession* s = p->GetSession();
135 s->KickPlayer("Delete account"); // mark session to remove at next session list update
136 s->LogoutPlayer(false); // logout player without waiting next session list update
137 }
138
139 Player::DeleteFromDB(guid.GetCounter(), accountId, false, true); // no need to update realm characters
140 } while (result->NextRow());
141 }
142
143 // table realm specific but common for all characters of account for realm
144 stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_TUTORIALS);
145 stmt->SetData(0, accountId);
146 CharacterDatabase.Execute(stmt);
147
148 stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_ACCOUNT_DATA);
149 stmt->SetData(0, accountId);
150 CharacterDatabase.Execute(stmt);
151
152 stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_CHARACTER_BAN);
153 stmt->SetData(0, accountId);
154 CharacterDatabase.Execute(stmt);
155
156 LoginDatabaseTransaction trans = LoginDatabase.BeginTransaction();
157
158 loginStmt = LoginDatabase.GetPreparedStatement(LOGIN_DEL_ACCOUNT);
159 loginStmt->SetData(0, accountId);
160 trans->Append(loginStmt);
161
162 loginStmt = LoginDatabase.GetPreparedStatement(LOGIN_DEL_ACCOUNT_ACCESS);
163 loginStmt->SetData(0, accountId);
164 trans->Append(loginStmt);
165
166 loginStmt = LoginDatabase.GetPreparedStatement(LOGIN_DEL_REALM_CHARACTERS);
167 loginStmt->SetData(0, accountId);
168 trans->Append(loginStmt);
169
170 loginStmt = LoginDatabase.GetPreparedStatement(LOGIN_DEL_ACCOUNT_BANNED);
171 loginStmt->SetData(0, accountId);
172 trans->Append(loginStmt);
173
174 loginStmt = LoginDatabase.GetPreparedStatement(LOGIN_DEL_ACCOUNT_MUTED);
175 loginStmt->SetData(0, accountId);
176 trans->Append(loginStmt);
177
178 LoginDatabase.CommitTransaction(trans);
179
180 return AOR_OK;
181}
@ CHAR_DEL_CHARACTER_BAN
Definition CharacterDatabase.h:43
@ CHAR_DEL_TUTORIALS
Definition CharacterDatabase.h:210
@ CHAR_DEL_ACCOUNT_DATA
Definition CharacterDatabase.h:201
@ CHAR_SEL_CHARS_BY_ACCOUNT_ID
Definition CharacterDatabase.h:340
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:126
@ LOGIN_DEL_ACCOUNT_BANNED
Definition LoginDatabase.h:41
@ LOGIN_DEL_ACCOUNT_ACCESS
Definition LoginDatabase.h:80
@ LOGIN_DEL_ACCOUNT
Definition LoginDatabase.h:103
@ LOGIN_DEL_REALM_CHARACTERS
Definition LoginDatabase.h:62
Definition ObjectGuid.h:121
LowType GetCounter() const
Definition ObjectGuid.h:149
Definition Player.h:1086
static void DeleteFromDB(ObjectGuid::LowType lowGuid, uint32 accountId, bool updateRealmChars, bool deleteFinally)
Definition Player.cpp:4089
Player session in the World.
Definition WorldSession.h:430
void LogoutPlayer(bool save, bool redirecting=false)
Log the player out
Definition WorldSession.cpp:687
void KickPlayer(bool setKicked=true)
Definition WorldSession.h:551
Player * FindPlayer(ObjectGuid const guid)
Definition ObjectAccessor.cpp:269

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)
static
318{
319 // check character count
321 stmt->SetData(0, accountId);
322 PreparedQueryResult result = CharacterDatabase.Query(stmt);
323
324 return (result) ? (*result)[0].Get<uint64>() : 0;
325}
@ 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()

◆ GetRBACDefaultPermissions()

rbac::RBACPermissionContainer const & AccountMgr::GetRBACDefaultPermissions ( uint8  secLevel)
508{
509 LOG_TRACE("rbac", "AccountMgr::GetRBACDefaultPermissions: secLevel {} - size: {}", secLevel, uint32(_defaultPermissions[secLevel].size()));
510 return _defaultPermissions[secLevel];
511}
#define LOG_TRACE(filterType__,...)
Definition Log.h:161

References _defaultPermissions, and LOG_TRACE.

◆ GetRBACPermission()

rbac::RBACPermission const * AccountMgr::GetRBACPermission ( uint32  permission) const
498{
499 LOG_TRACE("rbac", "AccountMgr::GetRBACPermission: {}", permissionId);
500 rbac::RBACPermissionsContainer::const_iterator it = _permissions.find(permissionId);
501 if (it != _permissions.end())
502 return it->second;
503
504 return nullptr;
505}

References _permissions, and LOG_TRACE.

◆ GetRBACPermissionList()

rbac::RBACPermissionsContainer const & AccountMgr::GetRBACPermissionList ( ) const
inline
78{ return _permissions; }

◆ GetSecurity() [1/2]

◆ GetSecurity() [2/2]

uint32 AccountMgr::GetSecurity ( uint32  accountId,
int32  realmId 
)
static
267{
269 stmt->SetData(0, accountId);
270 stmt->SetData(1, realmId);
271 PreparedQueryResult result = LoginDatabase.Query(stmt);
272
273 return (result) ? (*result)[0].Get<uint8>() : uint32(SEC_PLAYER);
274}
@ LOGIN_GET_GMLEVEL_BY_REALMID
Definition LoginDatabase.h:85

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

◆ HasPermission()

bool AccountMgr::HasPermission ( uint32  accountId,
uint32  permission,
uint32  realmId 
)
static
348{
349 if (!accountId)
350 {
351 LOG_ERROR("rbac", "AccountMgr::HasPermission: Wrong accountId 0");
352 return false;
353 }
354
355 rbac::RBACData rbac(accountId, "", realmId, GetSecurity(accountId, realmId));
356 rbac.LoadFromDB();
357 bool hasPermission = rbac.HasPermission(permission);
358
359 LOG_DEBUG("rbac", "AccountMgr::HasPermission [AccountId: {}, PermissionId: {}, realmId: {}]: {}",
360 accountId, permission, realmId, hasPermission);
361
362 return hasPermission;
363}
#define LOG_ERROR(filterType__,...)
Definition Log.h:145
#define LOG_DEBUG(filterType__,...)
Definition Log.h:157
static uint32 GetSecurity(uint32 accountId)
Definition AccountMgr.cpp:257
Definition RBAC.h:762
Definition AccountMgr.h:39

References GetSecurity(), LOG_DEBUG, and LOG_ERROR.

◆ instance()

AccountMgr * AccountMgr::instance ( )
static
38{
39 static AccountMgr instance;
40 return &instance;
41}
Definition AccountMgr.h:45
static AccountMgr * instance()
Definition AccountMgr.cpp:37

References instance().

Referenced by instance().

◆ IsAdminAccount()

bool AccountMgr::IsAdminAccount ( uint32  gmlevel)
static
338{
339 return gmlevel >= SEC_ADMINISTRATOR && gmlevel <= SEC_CONSOLE;
340}
@ SEC_ADMINISTRATOR
Definition Common.h:60
@ SEC_CONSOLE
Definition Common.h:61

References SEC_ADMINISTRATOR, and SEC_CONSOLE.

Referenced by ticket_commandscript::HandleGMTicketAssignToCommand().

◆ IsConsoleAccount()

bool AccountMgr::IsConsoleAccount ( uint32  gmlevel)
static
343{
344 return gmlevel == SEC_CONSOLE;
345}

References SEC_CONSOLE.

Referenced by account_commandscript::HandleAccountSetGmLevelCommand().

◆ IsGMAccount()

bool AccountMgr::IsGMAccount ( uint32  gmlevel)
static
333{
334 return gmlevel >= SEC_GAMEMASTER;
335}
@ SEC_GAMEMASTER
Definition Common.h:59

References SEC_GAMEMASTER.

◆ IsPlayerAccount()

◆ LoadRBAC()

void AccountMgr::LoadRBAC ( )
401{
402 ClearRBAC();
403
404 LOG_DEBUG("rbac", "AccountMgr::LoadRBAC");
405 uint32 oldMSTime = getMSTime();
406 uint32 count1 = 0;
407 uint32 count2 = 0;
408 uint32 count3 = 0;
409
410 LOG_DEBUG("rbac", "AccountMgr::LoadRBAC: Loading permissions");
411 QueryResult result = LoginDatabase.Query("SELECT id, name FROM rbac_permissions");
412 if (!result)
413 {
414 LOG_INFO("server.loading", ">> Loaded 0 RBAC permissions. DB table `rbac_permissions` is empty.");
415 LOG_INFO("server.loading", " ");
416 return;
417 }
418
419 do
420 {
421 Field* field = result->Fetch();
422 uint32 id = field[0].Get<uint32>();
423 _permissions[id] = new rbac::RBACPermission(id, field[1].Get<std::string>());
424 ++count1;
425 }
426 while (result->NextRow());
427
428 LOG_DEBUG("rbac", "AccountMgr::LoadRBAC: Loading linked permissions");
429 result = LoginDatabase.Query("SELECT id, linkedId FROM rbac_linked_permissions ORDER BY id ASC");
430 if (!result)
431 {
432 LOG_INFO("server.loading", ">> Loaded {} RBAC permissions", count1);
433 LOG_INFO("server.loading", " ");
434 }
435 else
436 {
437 uint32 permissionId = 0;
438 rbac::RBACPermission* permission = nullptr;
439
440 do
441 {
442 Field* field = result->Fetch();
443 uint32 newId = field[0].Get<uint32>();
444 if (permissionId != newId)
445 {
446 permissionId = newId;
447 permission = _permissions[newId];
448 }
449
450 uint32 linkedPermissionId = field[1].Get<uint32>();
451 if (linkedPermissionId == permissionId)
452 {
453 LOG_ERROR("sql.sql", "RBAC Permission {} has itself as linked permission. Ignored", permissionId);
454 continue;
455 }
456 permission->AddLinkedPermission(linkedPermissionId);
457 ++count2;
458 }
459 while (result->NextRow());
460
461 LOG_INFO("server.loading", ">> Loaded {} RBAC permissions and {} linked permissions in {} ms", count1, count2, GetMSTimeDiffToNow(oldMSTime));
462 LOG_INFO("server.loading", " ");
463 }
464
465 LOG_DEBUG("rbac", "AccountMgr::LoadRBAC: Loading default permissions");
467 stmt->SetData(0, int32(realm.Id.Realm));
468 PreparedQueryResult defaultPermResult = LoginDatabase.Query(stmt);
469 if (!defaultPermResult)
470 {
471 LOG_INFO("server.loading", ">> Loaded 0 RBAC default permissions. DB table `rbac_default_permissions` is empty.");
472 LOG_INFO("server.loading", " ");
473 return;
474 }
475
476 uint8 secId = 255;
477 rbac::RBACPermissionContainer* permissions = nullptr;
478 do
479 {
480 Field* field = defaultPermResult->Fetch();
481 uint8 newId = field[0].Get<uint8>();
482 if (secId != newId || permissions == nullptr)
483 {
484 secId = newId;
485 permissions = &_defaultPermissions[secId];
486 }
487
488 permissions->insert(field[1].Get<uint32>());
489 ++count3;
490 }
491 while (defaultPermResult->NextRow());
492
493 LOG_INFO("server.loading", ">> Loaded {} RBAC default permissions in {} ms", count3, GetMSTimeDiffToNow(oldMSTime));
494 LOG_INFO("server.loading", " ");
495}
std::shared_ptr< ResultSet > QueryResult
Definition DatabaseEnvFwd.h:27
std::int32_t int32
Definition Define.h:103
#define LOG_INFO(filterType__,...)
Definition Log.h:153
@ LOGIN_SEL_RBAC_DEFAULT_PERMISSIONS
Definition LoginDatabase.h:148
uint32 GetMSTimeDiffToNow(uint32 oldMSTime)
Definition Timer.h:131
uint32 getMSTime()
Definition Timer.h:103
Class used to access individual fields of database query result.
Definition Field.h:99
std::enable_if_t< std::is_arithmetic_v< T >, T > Get() const
Definition Field.h:113
void AddLinkedPermission(uint32 id)
Adds a new linked Permission.
Definition RBAC.h:740
Realm realm
Definition World.cpp:117
std::set< uint32 > RBACPermissionContainer
Definition RBAC.h:724
uint32 Realm
Definition Realm.h:43
RealmHandle Id
Definition Realm.h:69

References _defaultPermissions, _permissions, rbac::RBACPermission::AddLinkedPermission(), ClearRBAC(), Field::Get(), getMSTime(), GetMSTimeDiffToNow(), Realm::Id, LOG_DEBUG, LOG_ERROR, LOG_INFO, LOGIN_SEL_RBAC_DEFAULT_PERMISSIONS, LoginDatabase, realm, RealmHandle::Realm, and PreparedStatementBase::SetData().

◆ UpdateAccountAccess()

void AccountMgr::UpdateAccountAccess ( rbac::RBACData *  rbac,
uint32  accountId,
uint8  securityLevel,
int32  realmId 
)
366{
367 if (rbac && securityLevel != rbac->GetSecurityLevel())
368 rbac->SetSecurityLevel(securityLevel);
369
370 LoginDatabaseTransaction trans = LoginDatabase.BeginTransaction();
371
372 // Delete old security level from DB
373 if (realmId == -1)
374 {
376 stmt->SetData(0, accountId);
377 trans->Append(stmt);
378 }
379 else
380 {
382 stmt->SetData(0, accountId);
383 stmt->SetData(1, realmId);
384 trans->Append(stmt);
385 }
386
387 // Add new security level
388 if (securityLevel)
389 {
391 stmt->SetData(0, accountId);
392 stmt->SetData(1, securityLevel);
393 stmt->SetData(2, realmId);
394 trans->Append(stmt);
395 }
396
397 LoginDatabase.CommitTransaction(trans);
398}
@ LOGIN_DEL_ACCOUNT_ACCESS_BY_REALM
Definition LoginDatabase.h:81
@ LOGIN_INS_ACCOUNT_ACCESS
Definition LoginDatabase.h:82

References LOGIN_DEL_ACCOUNT_ACCESS, LOGIN_DEL_ACCOUNT_ACCESS_BY_REALM, LOGIN_INS_ACCOUNT_ACCESS, LoginDatabase, and PreparedStatementBase::SetData().

Member Data Documentation

◆ _defaultPermissions

◆ _permissions


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