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 AccountMgrinstance ()
 
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:510

References ClearRBAC().

Member Function Documentation

◆ AddDefaultPermissionForTest()

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

References _defaultPermissions.

◆ AddLinkedPermissionForTest()

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

References _permissions.

◆ AddPermissionForTest()

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

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:737
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 Utf8ToUpperOnlyLatin(username);
299 Utf8ToUpperOnlyLatin(password);
300
302 stmt->SetData(0, accountId);
303 if (PreparedQueryResult result = LoginDatabase.Query(stmt))
304 {
307 if (Acore::Crypto::SRP6::CheckLogin(username, password, salt, verifier))
308 return true;
309 }
310
311 return false;
312}
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().

◆ ClearPermissionsForTest()

void AccountMgr::ClearPermissionsForTest ( )
540{
541 ClearRBAC();
542}

References ClearRBAC().

◆ ClearRBAC()

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

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:228
static uint32 GetId(std::string const &username)
Definition AccountMgr.cpp:248
#define sWorld
Definition World.h:317

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:209
@ CHAR_DEL_ACCOUNT_DATA
Definition CharacterDatabase.h:200
@ CHAR_SEL_CHARS_BY_ACCOUNT_ID
Definition CharacterDatabase.h:338
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:123
@ 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:1084
static void DeleteFromDB(ObjectGuid::LowType lowGuid, uint32 accountId, bool updateRealmChars, bool deleteFinally)
Definition Player.cpp:3909
Player session in the World.
Definition WorldSession.h:384
void LogoutPlayer(bool save)
Log the player out
Definition WorldSession.cpp:614
void KickPlayer(bool setKicked=true)
Definition WorldSession.h:492
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)
static
315{
316 // check character count
318 stmt->SetData(0, accountId);
319 PreparedQueryResult result = CharacterDatabase.Query(stmt);
320
321 return (result) ? (*result)[0].Get<uint64>() : 0;
322}
@ 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)
505{
506 LOG_TRACE("rbac", "AccountMgr::GetRBACDefaultPermissions: secLevel {} - size: {}", secLevel, uint32(_defaultPermissions[secLevel].size()));
507 return _defaultPermissions[secLevel];
508}
#define LOG_TRACE(filterType__,...)
Definition Log.h:161

References _defaultPermissions, and LOG_TRACE.

◆ GetRBACPermission()

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

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:84

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

◆ HasPermission()

bool AccountMgr::HasPermission ( uint32  accountId,
uint32  permission,
uint32  realmId 
)
static
345{
346 if (!accountId)
347 {
348 LOG_ERROR("rbac", "AccountMgr::HasPermission: Wrong accountId 0");
349 return false;
350 }
351
352 rbac::RBACData rbac(accountId, "", realmId, GetSecurity(accountId, realmId));
353 rbac.LoadFromDB();
354 bool hasPermission = rbac.HasPermission(permission);
355
356 LOG_DEBUG("rbac", "AccountMgr::HasPermission [AccountId: {}, PermissionId: {}, realmId: {}]: {}",
357 accountId, permission, realmId, hasPermission);
358
359 return hasPermission;
360}
#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:732
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
335{
336 return gmlevel >= SEC_ADMINISTRATOR && gmlevel <= SEC_CONSOLE;
337}
@ 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
340{
341 return gmlevel == SEC_CONSOLE;
342}

References SEC_CONSOLE.

Referenced by account_commandscript::HandleAccountSetGmLevelCommand().

◆ IsGMAccount()

bool AccountMgr::IsGMAccount ( uint32  gmlevel)
static
330{
331 return gmlevel >= SEC_GAMEMASTER;
332}
@ SEC_GAMEMASTER
Definition Common.h:59

References SEC_GAMEMASTER.

◆ IsPlayerAccount()

◆ LoadRBAC()

void AccountMgr::LoadRBAC ( )
398{
399 ClearRBAC();
400
401 LOG_DEBUG("rbac", "AccountMgr::LoadRBAC");
402 uint32 oldMSTime = getMSTime();
403 uint32 count1 = 0;
404 uint32 count2 = 0;
405 uint32 count3 = 0;
406
407 LOG_DEBUG("rbac", "AccountMgr::LoadRBAC: Loading permissions");
408 QueryResult result = LoginDatabase.Query("SELECT id, name FROM rbac_permissions");
409 if (!result)
410 {
411 LOG_INFO("server.loading", ">> Loaded 0 RBAC permissions. DB table `rbac_permissions` is empty.");
412 LOG_INFO("server.loading", " ");
413 return;
414 }
415
416 do
417 {
418 Field* field = result->Fetch();
419 uint32 id = field[0].Get<uint32>();
420 _permissions[id] = new rbac::RBACPermission(id, field[1].Get<std::string>());
421 ++count1;
422 }
423 while (result->NextRow());
424
425 LOG_DEBUG("rbac", "AccountMgr::LoadRBAC: Loading linked permissions");
426 result = LoginDatabase.Query("SELECT id, linkedId FROM rbac_linked_permissions ORDER BY id ASC");
427 if (!result)
428 {
429 LOG_INFO("server.loading", ">> Loaded {} RBAC permissions", count1);
430 LOG_INFO("server.loading", " ");
431 }
432 else
433 {
434 uint32 permissionId = 0;
435 rbac::RBACPermission* permission = nullptr;
436
437 do
438 {
439 Field* field = result->Fetch();
440 uint32 newId = field[0].Get<uint32>();
441 if (permissionId != newId)
442 {
443 permissionId = newId;
444 permission = _permissions[newId];
445 }
446
447 uint32 linkedPermissionId = field[1].Get<uint32>();
448 if (linkedPermissionId == permissionId)
449 {
450 LOG_ERROR("sql.sql", "RBAC Permission {} has itself as linked permission. Ignored", permissionId);
451 continue;
452 }
453 permission->AddLinkedPermission(linkedPermissionId);
454 ++count2;
455 }
456 while (result->NextRow());
457
458 LOG_INFO("server.loading", ">> Loaded {} RBAC permissions and {} linked permissions in {} ms", count1, count2, GetMSTimeDiffToNow(oldMSTime));
459 LOG_INFO("server.loading", " ");
460 }
461
462 LOG_DEBUG("rbac", "AccountMgr::LoadRBAC: Loading default permissions");
464 stmt->SetData(0, int32(realm.Id.Realm));
465 PreparedQueryResult defaultPermResult = LoginDatabase.Query(stmt);
466 if (!defaultPermResult)
467 {
468 LOG_INFO("server.loading", ">> Loaded 0 RBAC default permissions. DB table `rbac_default_permissions` is empty.");
469 LOG_INFO("server.loading", " ");
470 return;
471 }
472
473 uint8 secId = 255;
474 rbac::RBACPermissionContainer* permissions = nullptr;
475 do
476 {
477 Field* field = defaultPermResult->Fetch();
478 uint8 newId = field[0].Get<uint8>();
479 if (secId != newId || permissions == nullptr)
480 {
481 secId = newId;
482 permissions = &_defaultPermissions[secId];
483 }
484
485 permissions->insert(field[1].Get<uint32>());
486 ++count3;
487 }
488 while (defaultPermResult->NextRow());
489
490 LOG_INFO("server.loading", ">> Loaded {} RBAC default permissions in {} ms", count3, GetMSTimeDiffToNow(oldMSTime));
491 LOG_INFO("server.loading", " ");
492}
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:142
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:98
std::enable_if_t< std::is_arithmetic_v< T >, T > Get() const
Definition Field.h:112
void AddLinkedPermission(uint32 id)
Adds a new linked Permission.
Definition RBAC.h:710
Realm realm
Definition World.cpp:111
std::set< uint32 > RBACPermissionContainer
Definition RBAC.h:694
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 
)
363{
364 if (rbac && securityLevel != rbac->GetSecurityLevel())
365 rbac->SetSecurityLevel(securityLevel);
366
367 LoginDatabaseTransaction trans = LoginDatabase.BeginTransaction();
368
369 // Delete old security level from DB
370 if (realmId == -1)
371 {
373 stmt->SetData(0, accountId);
374 trans->Append(stmt);
375 }
376 else
377 {
379 stmt->SetData(0, accountId);
380 stmt->SetData(1, realmId);
381 trans->Append(stmt);
382 }
383
384 // Add new security level
385 if (securityLevel)
386 {
388 stmt->SetData(0, accountId);
389 stmt->SetData(1, securityLevel);
390 stmt->SetData(2, realmId);
391 trans->Append(stmt);
392 }
393
394 LoginDatabase.CommitTransaction(trans);
395}
@ LOGIN_DEL_ACCOUNT_ACCESS_BY_REALM
Definition LoginDatabase.h:80
@ LOGIN_INS_ACCOUNT_ACCESS
Definition LoginDatabase.h:81

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: