TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
AccountMgr Class Reference

#include <AccountMgr.h>

Public Member Functions

AccountOpResult CreateAccount (std::string username, std::string password, std::string email="", uint32 bnetAccountId=0, uint8 bnetIndex=0)
 
void UpdateAccountAccess (rbac::RBACData *rbac, uint32 accountId, uint8 securityLevel, int32 realmId)
 
void LoadRBAC ()
 
rbac::RBACPermission constGetRBACPermission (uint32 permission) const
 
rbac::RBACPermissionsContainer
const
GetRBACPermissionList () const
 
rbac::RBACPermissionContainer
const
GetRBACDefaultPermissions (uint8 secLevel)
 

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 newEmail)
 
static AccountOpResult ChangeRegEmail (uint32 accountId, std::string newEmail)
 
static bool CheckPassword (uint32 accountId, std::string password)
 
static bool CheckEmail (uint32 accountId, std::string newEmail)
 
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 bool GetEmail (uint32 accountId, std::string &email)
 
static uint32 GetCharactersCount (uint32 accountId)
 
static std::string CalculateShaPassHash (std::string const &name, std::string const &password)
 
static bool IsPlayerAccount (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
 

Constructor & Destructor Documentation

AccountMgr::AccountMgr ( )
private
29 { }
AccountMgr::~AccountMgr ( )
private
32 {
33  ClearRBAC();
34 }
void ClearRBAC()
Definition: AccountMgr.cpp:550

+ Here is the call graph for this function:

Member Function Documentation

std::string AccountMgr::CalculateShaPassHash ( std::string const name,
std::string const password 
)
static
379 {
380  SHA1Hash sha;
381  sha.Initialize();
382  sha.UpdateData(name);
383  sha.UpdateData(":");
384  sha.UpdateData(password);
385  sha.Finalize();
386 
387  return ByteArrayToHexStr(sha.GetDigest(), sha.GetLength());
388 }
void Initialize()
Definition: SHA1.cpp:60
void Finalize()
Definition: SHA1.cpp:65
void UpdateData(const uint8 *dta, int len)
Definition: SHA1.cpp:35
int GetLength(void) const
Definition: SHA1.h:46
Definition: SHA1.h:29
std::string ByteArrayToHexStr(uint8 const *bytes, uint32 arrayLen, bool reverse)
Definition: Util.cpp:509
uint8 * GetDigest(void)
Definition: SHA1.h:45

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

AccountOpResult AccountMgr::ChangeEmail ( uint32  accountId,
std::string  newEmail 
)
static
219 {
220  std::string username;
221 
222  if (!GetName(accountId, username))
223  {
224  sScriptMgr->OnFailedEmailChange(accountId);
225  return AccountOpResult::AOR_NAME_NOT_EXIST; // account doesn't exist
226  }
227 
228  if (utf8length(newEmail) > MAX_EMAIL_STR)
229  {
230  sScriptMgr->OnFailedEmailChange(accountId);
232  }
233 
234  Utf8ToUpperOnlyLatin(username);
235  Utf8ToUpperOnlyLatin(newEmail);
236 
238 
239  stmt->setString(0, newEmail);
240  stmt->setUInt32(1, accountId);
241 
242  LoginDatabase.Execute(stmt);
243 
244  sScriptMgr->OnEmailChange(accountId);
246 }
void Execute(const char *sql)
Definition: DatabaseWorkerPool.h:87
void setString(const uint8 index, const std::string &value)
Definition: PreparedStatement.cpp:187
size_t utf8length(std::string &utf8str)
Definition: Util.cpp:247
Definition: PreparedStatement.h:74
static bool GetName(uint32 accountId, std::string &name)
Definition: AccountMgr.cpp:303
LoginDatabaseWorkerPool LoginDatabase
Accessor to the realm/login database.
Definition: DatabaseEnv.cpp:22
PreparedStatement * GetPreparedStatement(PreparedStatementIndex index)
Definition: DatabaseWorkerPool.h:263
void setUInt32(const uint8 index, const uint32 value)
Definition: PreparedStatement.cpp:115
#define MAX_EMAIL_STR
Definition: AccountMgr.h:45
#define sScriptMgr
Definition: ScriptMgr.h:837
bool Utf8ToUpperOnlyLatin(std::string &utf8String)
Definition: Util.cpp:498
Definition: LoginDatabase.h:68

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

AccountOpResult AccountMgr::ChangePassword ( uint32  accountId,
std::string  newPassword 
)
static
181 {
182  std::string username;
183 
184  if (!GetName(accountId, username))
185  {
186  sScriptMgr->OnFailedPasswordChange(accountId);
187  return AccountOpResult::AOR_NAME_NOT_EXIST; // account doesn't exist
188  }
189 
190  if (utf8length(newPassword) > MAX_PASS_STR)
191  {
192  sScriptMgr->OnFailedPasswordChange(accountId);
194  }
195 
196  Utf8ToUpperOnlyLatin(username);
197  Utf8ToUpperOnlyLatin(newPassword);
198 
200 
201  stmt->setString(0, CalculateShaPassHash(username, newPassword));
202  stmt->setUInt32(1, accountId);
203 
204  LoginDatabase.Execute(stmt);
205 
207 
208  stmt->setString(0, "");
209  stmt->setString(1, "");
210  stmt->setString(2, username);
211 
212  LoginDatabase.Execute(stmt);
213 
214  sScriptMgr->OnPasswordChange(accountId);
216 }
void Execute(const char *sql)
Definition: DatabaseWorkerPool.h:87
void setString(const uint8 index, const std::string &value)
Definition: PreparedStatement.cpp:187
static std::string CalculateShaPassHash(std::string const &name, std::string const &password)
Definition: AccountMgr.cpp:378
size_t utf8length(std::string &utf8str)
Definition: Util.cpp:247
Definition: PreparedStatement.h:74
static bool GetName(uint32 accountId, std::string &name)
Definition: AccountMgr.cpp:303
LoginDatabaseWorkerPool LoginDatabase
Accessor to the realm/login database.
Definition: DatabaseEnv.cpp:22
Definition: LoginDatabase.h:67
PreparedStatement * GetPreparedStatement(PreparedStatementIndex index)
Definition: DatabaseWorkerPool.h:263
void setUInt32(const uint8 index, const uint32 value)
Definition: PreparedStatement.cpp:115
#define sScriptMgr
Definition: ScriptMgr.h:837
bool Utf8ToUpperOnlyLatin(std::string &utf8String)
Definition: Util.cpp:498
#define MAX_PASS_STR
Definition: AccountMgr.h:43
Definition: LoginDatabase.h:42

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

AccountOpResult AccountMgr::ChangeRegEmail ( uint32  accountId,
std::string  newEmail 
)
static
249 {
250  std::string username;
251 
252  if (!GetName(accountId, username))
253  return AccountOpResult::AOR_NAME_NOT_EXIST; // account doesn't exist
254 
255  if (utf8length(newEmail) > MAX_EMAIL_STR)
256  {
257  sScriptMgr->OnFailedEmailChange(accountId);
259  }
260 
261  Utf8ToUpperOnlyLatin(username);
262  Utf8ToUpperOnlyLatin(newEmail);
263 
265 
266  stmt->setString(0, newEmail);
267  stmt->setUInt32(1, accountId);
268 
269  LoginDatabase.Execute(stmt);
270 
271  sScriptMgr->OnEmailChange(accountId);
273 }
void Execute(const char *sql)
Definition: DatabaseWorkerPool.h:87
void setString(const uint8 index, const std::string &value)
Definition: PreparedStatement.cpp:187
size_t utf8length(std::string &utf8str)
Definition: Util.cpp:247
Definition: PreparedStatement.h:74
static bool GetName(uint32 accountId, std::string &name)
Definition: AccountMgr.cpp:303
LoginDatabaseWorkerPool LoginDatabase
Accessor to the realm/login database.
Definition: DatabaseEnv.cpp:22
PreparedStatement * GetPreparedStatement(PreparedStatementIndex index)
Definition: DatabaseWorkerPool.h:263
void setUInt32(const uint8 index, const uint32 value)
Definition: PreparedStatement.cpp:115
#define MAX_EMAIL_STR
Definition: AccountMgr.h:45
Definition: LoginDatabase.h:69
#define sScriptMgr
Definition: ScriptMgr.h:837
bool Utf8ToUpperOnlyLatin(std::string &utf8String)
Definition: Util.cpp:498

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

AccountOpResult AccountMgr::ChangeUsername ( uint32  accountId,
std::string  newUsername,
std::string  newPassword 
)
static
151 {
152  // Check if accounts exists
154  stmt->setUInt32(0, accountId);
155  PreparedQueryResult result = LoginDatabase.Query(stmt);
156 
157  if (!result)
159 
160  if (utf8length(newUsername) > MAX_ACCOUNT_STR)
162 
163  if (utf8length(newPassword) > MAX_PASS_STR)
165 
166  Utf8ToUpperOnlyLatin(newUsername);
167  Utf8ToUpperOnlyLatin(newPassword);
168 
170 
171  stmt->setString(0, newUsername);
172  stmt->setString(1, CalculateShaPassHash(newUsername, newPassword));
173  stmt->setUInt32(2, accountId);
174 
175  LoginDatabase.Execute(stmt);
176 
178 }
void Execute(const char *sql)
Definition: DatabaseWorkerPool.h:87
std::shared_ptr< PreparedResultSet > PreparedQueryResult
Definition: QueryResult.h:107
void setString(const uint8 index, const std::string &value)
Definition: PreparedStatement.cpp:187
static std::string CalculateShaPassHash(std::string const &name, std::string const &password)
Definition: AccountMgr.cpp:378
Definition: LoginDatabase.h:53
size_t utf8length(std::string &utf8str)
Definition: Util.cpp:247
Definition: PreparedStatement.h:74
LoginDatabaseWorkerPool LoginDatabase
Accessor to the realm/login database.
Definition: DatabaseEnv.cpp:22
#define MAX_ACCOUNT_STR
Definition: AccountMgr.h:44
Definition: LoginDatabase.h:66
PreparedStatement * GetPreparedStatement(PreparedStatementIndex index)
Definition: DatabaseWorkerPool.h:263
void setUInt32(const uint8 index, const uint32 value)
Definition: PreparedStatement.cpp:115
QueryResult Query(const char *sql, T *connection=nullptr)
Definition: DatabaseWorkerPool.cpp:113
bool Utf8ToUpperOnlyLatin(std::string &utf8String)
Definition: Util.cpp:498
#define MAX_PASS_STR
Definition: AccountMgr.h:43

+ Here is the call graph for this function:

bool AccountMgr::CheckEmail ( uint32  accountId,
std::string  newEmail 
)
static
352 {
353  std::string oldEmail;
354 
355  // We simply return false for a non-existing email
356  if (!GetEmail(accountId, oldEmail))
357  return false;
358 
359  Utf8ToUpperOnlyLatin(oldEmail);
360  Utf8ToUpperOnlyLatin(newEmail);
361 
362  if (strcmp(oldEmail.c_str(), newEmail.c_str()) == 0)
363  return true;
364 
365  return false;
366 }
static bool GetEmail(uint32 accountId, std::string &email)
Definition: AccountMgr.cpp:318
bool Utf8ToUpperOnlyLatin(std::string &utf8String)
Definition: Util.cpp:498

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool AccountMgr::CheckPassword ( uint32  accountId,
std::string  password 
)
static
334 {
335  std::string username;
336 
337  if (!GetName(accountId, username))
338  return false;
339 
340  Utf8ToUpperOnlyLatin(username);
341  Utf8ToUpperOnlyLatin(password);
342 
344  stmt->setUInt32(0, accountId);
345  stmt->setString(1, CalculateShaPassHash(username, password));
346  PreparedQueryResult result = LoginDatabase.Query(stmt);
347 
348  return (result) ? true : false;
349 }
std::shared_ptr< PreparedResultSet > PreparedQueryResult
Definition: QueryResult.h:107
void setString(const uint8 index, const std::string &value)
Definition: PreparedStatement.cpp:187
static std::string CalculateShaPassHash(std::string const &name, std::string const &password)
Definition: AccountMgr.cpp:378
Definition: PreparedStatement.h:74
static bool GetName(uint32 accountId, std::string &name)
Definition: AccountMgr.cpp:303
LoginDatabaseWorkerPool LoginDatabase
Accessor to the realm/login database.
Definition: DatabaseEnv.cpp:22
PreparedStatement * GetPreparedStatement(PreparedStatementIndex index)
Definition: DatabaseWorkerPool.h:263
void setUInt32(const uint8 index, const uint32 value)
Definition: PreparedStatement.cpp:115
QueryResult Query(const char *sql, T *connection=nullptr)
Definition: DatabaseWorkerPool.cpp:113
bool Utf8ToUpperOnlyLatin(std::string &utf8String)
Definition: Util.cpp:498
Definition: LoginDatabase.h:84

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void AccountMgr::ClearRBAC ( )
private
551 {
552  for (rbac::RBACPermissionsContainer::iterator itr = _permissions.begin(); itr != _permissions.end(); ++itr)
553  delete itr->second;
554 
555  _permissions.clear();
556  _defaultPermissions.clear();
557 }
rbac::RBACDefaultPermissionsContainer _defaultPermissions
Definition: AccountMgr.h:95
rbac::RBACPermissionsContainer _permissions
Definition: AccountMgr.h:94

+ Here is the caller graph for this function:

AccountOpResult AccountMgr::CreateAccount ( std::string  username,
std::string  password,
std::string  email = "",
uint32  bnetAccountId = 0,
uint8  bnetIndex = 0 
)
43 {
44  if (utf8length(username) > MAX_ACCOUNT_STR)
45  return AccountOpResult::AOR_NAME_TOO_LONG; // username's too long
46 
47  Utf8ToUpperOnlyLatin(username);
48  Utf8ToUpperOnlyLatin(password);
49  Utf8ToUpperOnlyLatin(email);
50 
51  if (GetId(username))
52  return AccountOpResult::AOR_NAME_ALREADY_EXIST; // username does already exist
53 
55 
56  stmt->setString(0, username);
57  stmt->setString(1, CalculateShaPassHash(username, password));
58  stmt->setString(2, email);
59  stmt->setString(3, email);
60  if (bnetAccountId && bnetIndex)
61  {
62  stmt->setUInt32(4, bnetAccountId);
63  stmt->setUInt8(5, bnetIndex);
64  }
65  else
66  {
67  stmt->setNull(4);
68  stmt->setNull(5);
69  }
70 
71  LoginDatabase.DirectExecute(stmt); // Enforce saving, otherwise AddGroup can fail
72 
74  LoginDatabase.Execute(stmt);
75 
76  return AccountOpResult::AOR_OK; // everything's fine
77 }
void Execute(const char *sql)
Definition: DatabaseWorkerPool.h:87
Definition: LoginDatabase.h:60
void setUInt8(const uint8 index, const uint8 value)
Definition: PreparedStatement.cpp:97
void setString(const uint8 index, const std::string &value)
Definition: PreparedStatement.cpp:187
static std::string CalculateShaPassHash(std::string const &name, std::string const &password)
Definition: AccountMgr.cpp:378
size_t utf8length(std::string &utf8str)
Definition: Util.cpp:247
Definition: PreparedStatement.h:74
LoginDatabaseWorkerPool LoginDatabase
Accessor to the realm/login database.
Definition: DatabaseEnv.cpp:22
#define MAX_ACCOUNT_STR
Definition: AccountMgr.h:44
static uint32 GetId(std::string const &username)
Definition: AccountMgr.cpp:275
PreparedStatement * GetPreparedStatement(PreparedStatementIndex index)
Definition: DatabaseWorkerPool.h:263
void setUInt32(const uint8 index, const uint32 value)
Definition: PreparedStatement.cpp:115
void setNull(const uint8 index)
Definition: PreparedStatement.cpp:206
Definition: LoginDatabase.h:61
bool Utf8ToUpperOnlyLatin(std::string &utf8String)
Definition: Util.cpp:498
void DirectExecute(const char *sql)
Definition: DatabaseWorkerPool.h:121

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

AccountOpResult AccountMgr::DeleteAccount ( uint32  accountId)
static
80 {
81  // Check if accounts exists
83  stmt->setUInt32(0, accountId);
85 
86  if (!result)
88 
89  // Obtain accounts characters
91 
92  stmt->setUInt32(0, accountId);
93 
94  result = CharacterDatabase.Query(stmt);
95 
96  if (result)
97  {
98  do
99  {
100  ObjectGuid guid = ObjectGuid::Create<HighGuid::Player>((*result)[0].GetUInt64());
101 
102  // Kick if player is online
104  {
105  WorldSession* s = p->GetSession();
106  s->KickPlayer(); // mark session to remove at next session list update
107  s->LogoutPlayer(false); // logout player without waiting next session list update
108  }
109 
110  Player::DeleteFromDB(guid, accountId, false); // no need to update realm characters
111  } while (result->NextRow());
112  }
113 
114  // table realm specific but common for all characters of account for realm
116  stmt->setUInt32(0, accountId);
118 
120  stmt->setUInt32(0, accountId);
122 
124  stmt->setUInt32(0, accountId);
126 
128 
130  stmt->setUInt32(0, accountId);
131  trans->Append(stmt);
132 
134  stmt->setUInt32(0, accountId);
135  trans->Append(stmt);
136 
138  stmt->setUInt32(0, accountId);
139  trans->Append(stmt);
140 
142  stmt->setUInt32(0, accountId);
143  trans->Append(stmt);
144 
146 
148 }
Definition: LoginDatabase.h:39
Definition: CharacterDatabase.h:230
void Execute(const char *sql)
Definition: DatabaseWorkerPool.h:87
std::shared_ptr< PreparedResultSet > PreparedQueryResult
Definition: QueryResult.h:107
Definition: LoginDatabase.h:94
SQLTransaction BeginTransaction()
Begins an automanaged transaction pointer that will automatically rollback if not commited...
Definition: DatabaseWorkerPool.h:221
Definition: LoginDatabase.h:53
Definition: CharacterDatabase.h:381
void KickPlayer()
Kick a player out of the World.
Definition: WorldSession.cpp:646
Definition: PreparedStatement.h:74
void CommitTransaction(SQLTransaction transaction)
Definition: DatabaseWorkerPool.cpp:179
LoginDatabaseWorkerPool LoginDatabase
Accessor to the realm/login database.
Definition: DatabaseEnv.cpp:22
Definition: CharacterDatabase.h:239
void LogoutPlayer(bool save)
Log the player out
Definition: WorldSession.cpp:498
Definition: LoginDatabase.h:77
PreparedStatement * GetPreparedStatement(PreparedStatementIndex index)
Definition: DatabaseWorkerPool.h:263
void setUInt32(const uint8 index, const uint32 value)
Definition: PreparedStatement.cpp:115
Definition: CharacterDatabase.h:43
Definition: LoginDatabase.h:57
QueryResult Query(const char *sql, T *connection=nullptr)
Definition: DatabaseWorkerPool.cpp:113
CharacterDatabaseWorkerPool CharacterDatabase
Accessor to the character database.
Definition: DatabaseEnv.cpp:21
Player session in the World.
Definition: WorldSession.h:882
Definition: ObjectGuid.h:189
TC_GAME_API Player * FindConnectedPlayer(ObjectGuid const &)
Definition: ObjectAccessor.cpp:215
std::shared_ptr< Transaction > SQLTransaction
Definition: Transaction.h:58

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

uint32 AccountMgr::GetCharactersCount ( uint32  accountId)
static
369 {
370  // check character count
372  stmt->setUInt32(0, accountId);
374 
375  return (result) ? (*result)[0].GetUInt64() : 0;
376 }
std::shared_ptr< PreparedResultSet > PreparedQueryResult
Definition: QueryResult.h:107
Definition: CharacterDatabase.h:39
Definition: PreparedStatement.h:74
PreparedStatement * GetPreparedStatement(PreparedStatementIndex index)
Definition: DatabaseWorkerPool.h:263
void setUInt32(const uint8 index, const uint32 value)
Definition: PreparedStatement.cpp:115
QueryResult Query(const char *sql, T *connection=nullptr)
Definition: DatabaseWorkerPool.cpp:113
CharacterDatabaseWorkerPool CharacterDatabase
Accessor to the character database.
Definition: DatabaseEnv.cpp:21

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool AccountMgr::GetEmail ( uint32  accountId,
std::string &  email 
)
static
319 {
321  stmt->setUInt32(0, accountId);
322  PreparedQueryResult result = LoginDatabase.Query(stmt);
323 
324  if (result)
325  {
326  email = (*result)[0].GetString();
327  return true;
328  }
329 
330  return false;
331 }
std::shared_ptr< PreparedResultSet > PreparedQueryResult
Definition: QueryResult.h:107
Definition: PreparedStatement.h:74
LoginDatabaseWorkerPool LoginDatabase
Accessor to the realm/login database.
Definition: DatabaseEnv.cpp:22
PreparedStatement * GetPreparedStatement(PreparedStatementIndex index)
Definition: DatabaseWorkerPool.h:263
void setUInt32(const uint8 index, const uint32 value)
Definition: PreparedStatement.cpp:115
QueryResult Query(const char *sql, T *connection=nullptr)
Definition: DatabaseWorkerPool.cpp:113
Definition: LoginDatabase.h:99

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

uint32 AccountMgr::GetId ( std::string const username)
static
276 {
278  stmt->setString(0, username);
279  PreparedQueryResult result = LoginDatabase.Query(stmt);
280 
281  return (result) ? (*result)[0].GetUInt32() : 0;
282 }
std::shared_ptr< PreparedResultSet > PreparedQueryResult
Definition: QueryResult.h:107
void setString(const uint8 index, const std::string &value)
Definition: PreparedStatement.cpp:187
Definition: PreparedStatement.h:74
LoginDatabaseWorkerPool LoginDatabase
Accessor to the realm/login database.
Definition: DatabaseEnv.cpp:22
Definition: LoginDatabase.h:80
PreparedStatement * GetPreparedStatement(PreparedStatementIndex index)
Definition: DatabaseWorkerPool.h:263
QueryResult Query(const char *sql, T *connection=nullptr)
Definition: DatabaseWorkerPool.cpp:113

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool AccountMgr::GetName ( uint32  accountId,
std::string &  name 
)
static
304 {
306  stmt->setUInt32(0, accountId);
307  PreparedQueryResult result = LoginDatabase.Query(stmt);
308 
309  if (result)
310  {
311  name = (*result)[0].GetString();
312  return true;
313  }
314 
315  return false;
316 }
Definition: LoginDatabase.h:83
std::shared_ptr< PreparedResultSet > PreparedQueryResult
Definition: QueryResult.h:107
Definition: PreparedStatement.h:74
LoginDatabaseWorkerPool LoginDatabase
Accessor to the realm/login database.
Definition: DatabaseEnv.cpp:22
PreparedStatement * GetPreparedStatement(PreparedStatementIndex index)
Definition: DatabaseWorkerPool.h:263
void setUInt32(const uint8 index, const uint32 value)
Definition: PreparedStatement.cpp:115
QueryResult Query(const char *sql, T *connection=nullptr)
Definition: DatabaseWorkerPool.cpp:113

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

rbac::RBACPermissionContainer const & AccountMgr::GetRBACDefaultPermissions ( uint8  secLevel)
560 {
561  TC_LOG_TRACE("rbac", "AccountMgr::GetRBACDefaultPermissions: secLevel %u - size: %u", secLevel, uint32(_defaultPermissions[secLevel].size()));
562  return _defaultPermissions[secLevel];
563 }
rbac::RBACDefaultPermissionsContainer _defaultPermissions
Definition: AccountMgr.h:95
#define TC_LOG_TRACE(filterType__,...)
Definition: Log.h:195
uint32_t uint32
Definition: g3dmath.h:168
rbac::RBACPermission const * AccountMgr::GetRBACPermission ( uint32  permission) const
524 {
525  TC_LOG_TRACE("rbac", "AccountMgr::GetRBACPermission: %u", permissionId);
526  rbac::RBACPermissionsContainer::const_iterator it = _permissions.find(permissionId);
527  if (it != _permissions.end())
528  return it->second;
529 
530  return NULL;
531 }
arena_t NULL
Definition: jemalloc_internal.h:624
#define TC_LOG_TRACE(filterType__,...)
Definition: Log.h:195
rbac::RBACPermissionsContainer _permissions
Definition: AccountMgr.h:94
rbac::RBACPermissionsContainer const& AccountMgr::GetRBACPermissionList ( ) const
inline
89 { return _permissions; }
rbac::RBACPermissionsContainer _permissions
Definition: AccountMgr.h:94
uint32 AccountMgr::GetSecurity ( uint32  accountId)
static
285 {
287  stmt->setUInt32(0, accountId);
288  PreparedQueryResult result = LoginDatabase.Query(stmt);
289 
290  return (result) ? (*result)[0].GetUInt8() : uint32(SEC_PLAYER);
291 }
std::shared_ptr< PreparedResultSet > PreparedQueryResult
Definition: QueryResult.h:107
Definition: Common.h:108
Definition: LoginDatabase.h:81
Definition: PreparedStatement.h:74
LoginDatabaseWorkerPool LoginDatabase
Accessor to the realm/login database.
Definition: DatabaseEnv.cpp:22
PreparedStatement * GetPreparedStatement(PreparedStatementIndex index)
Definition: DatabaseWorkerPool.h:263
void setUInt32(const uint8 index, const uint32 value)
Definition: PreparedStatement.cpp:115
QueryResult Query(const char *sql, T *connection=nullptr)
Definition: DatabaseWorkerPool.cpp:113
uint32_t uint32
Definition: g3dmath.h:168

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

uint32 AccountMgr::GetSecurity ( uint32  accountId,
int32  realmId 
)
static
294 {
296  stmt->setUInt32(0, accountId);
297  stmt->setInt32(1, realmId);
298  PreparedQueryResult result = LoginDatabase.Query(stmt);
299 
300  return (result) ? (*result)[0].GetUInt8() : uint32(SEC_PLAYER);
301 }
Definition: LoginDatabase.h:82
std::shared_ptr< PreparedResultSet > PreparedQueryResult
Definition: QueryResult.h:107
Definition: Common.h:108
Definition: PreparedStatement.h:74
LoginDatabaseWorkerPool LoginDatabase
Accessor to the realm/login database.
Definition: DatabaseEnv.cpp:22
PreparedStatement * GetPreparedStatement(PreparedStatementIndex index)
Definition: DatabaseWorkerPool.h:263
void setInt32(const uint8 index, const int32 value)
Definition: PreparedStatement.cpp:151
void setUInt32(const uint8 index, const uint32 value)
Definition: PreparedStatement.cpp:115
QueryResult Query(const char *sql, T *connection=nullptr)
Definition: DatabaseWorkerPool.cpp:113
uint32_t uint32
Definition: g3dmath.h:168

+ Here is the call graph for this function:

bool AccountMgr::HasPermission ( uint32  accountId,
uint32  permission,
uint32  realmId 
)
static
534 {
535  if (!accountId)
536  {
537  TC_LOG_ERROR("rbac", "AccountMgr::HasPermission: Wrong accountId 0");
538  return false;
539  }
540 
541  rbac::RBACData rbac(accountId, "", realmId, GetSecurity(accountId));
542  rbac.LoadFromDB();
543  bool hasPermission = rbac.HasPermission(permissionId);
544 
545  TC_LOG_DEBUG("rbac", "AccountMgr::HasPermission [AccountId: %u, PermissionId: %u, realmId: %d]: %u",
546  accountId, permissionId, realmId, hasPermission);
547  return hasPermission;
548 }
Definition: AccountMgr.h:47
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:198
Definition: RBAC.h:783
static uint32 GetSecurity(uint32 accountId)
Definition: AccountMgr.cpp:284
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

+ Here is the caller graph for this function:

bool AccountMgr::IsAdminAccount ( uint32  gmlevel)
static
396 {
397  return gmlevel >= SEC_ADMINISTRATOR && gmlevel <= SEC_CONSOLE;
398 }
Definition: Common.h:111
Definition: Common.h:112
bool AccountMgr::IsConsoleAccount ( uint32  gmlevel)
static
401 {
402  return gmlevel == SEC_CONSOLE;
403 }
Definition: Common.h:112

+ Here is the caller graph for this function:

bool AccountMgr::IsPlayerAccount ( uint32  gmlevel)
static
391 {
392  return gmlevel == SEC_PLAYER;
393 }
Definition: Common.h:108

+ Here is the caller graph for this function:

void AccountMgr::LoadRBAC ( )
406 {
407  ClearRBAC();
408 
409  TC_LOG_DEBUG("rbac", "AccountMgr::LoadRBAC");
410  uint32 oldMSTime = getMSTime();
411  uint32 count1 = 0;
412  uint32 count2 = 0;
413  uint32 count3 = 0;
414 
415  TC_LOG_DEBUG("rbac", "AccountMgr::LoadRBAC: Loading permissions");
416  QueryResult result = LoginDatabase.Query("SELECT id, name FROM rbac_permissions");
417  if (!result)
418  {
419  TC_LOG_INFO("server.loading", ">> Loaded 0 account permission definitions. DB table `rbac_permissions` is empty.");
420  return;
421  }
422 
423  do
424  {
425  Field* field = result->Fetch();
426  uint32 id = field[0].GetUInt32();
427  _permissions[id] = new rbac::RBACPermission(id, field[1].GetString());
428  ++count1;
429  }
430  while (result->NextRow());
431 
432  TC_LOG_DEBUG("rbac", "AccountMgr::LoadRBAC: Loading linked permissions");
433  result = LoginDatabase.Query("SELECT id, linkedId FROM rbac_linked_permissions ORDER BY id ASC");
434  if (!result)
435  {
436  TC_LOG_INFO("server.loading", ">> Loaded 0 linked permissions. DB table `rbac_linked_permissions` is empty.");
437  return;
438  }
439 
440  uint32 permissionId = 0;
441  rbac::RBACPermission* permission = NULL;
442 
443  do
444  {
445  Field* field = result->Fetch();
446  uint32 newId = field[0].GetUInt32();
447  if (permissionId != newId)
448  {
449  permissionId = newId;
450  permission = _permissions[newId];
451  }
452 
453  uint32 linkedPermissionId = field[1].GetUInt32();
454  if (linkedPermissionId == permissionId)
455  {
456  TC_LOG_ERROR("sql.sql", "RBAC Permission %u has itself as linked permission. Ignored", permissionId);
457  continue;
458  }
459  permission->AddLinkedPermission(linkedPermissionId);
460  ++count2;
461  }
462  while (result->NextRow());
463 
464  TC_LOG_DEBUG("rbac", "AccountMgr::LoadRBAC: Loading default permissions");
465  result = LoginDatabase.PQuery("SELECT secId, permissionId FROM rbac_default_permissions WHERE (realmId = %u OR realmId = -1) ORDER BY secId ASC", realm.Id.Realm);
466  if (!result)
467  {
468  TC_LOG_INFO("server.loading", ">> Loaded 0 default permission definitions. DB table `rbac_default_permissions` is empty.");
469  return;
470  }
471 
472  uint8 secId = 255;
473  rbac::RBACPermissionContainer* permissions = NULL;
474  do
475  {
476  Field* field = result->Fetch();
477  uint32 newId = field[0].GetUInt32();
478  if (secId != newId || permissions == NULL)
479  {
480  secId = newId;
481  permissions = &_defaultPermissions[secId];
482  }
483 
484  permissions->insert(field[1].GetUInt32());
485  ++count3;
486  }
487  while (result->NextRow());
488 
489  TC_LOG_INFO("server.loading", ">> Loaded %u permission definitions, %u linked permissions and %u default permissions in %u ms", count1, count2, count3, GetMSTimeDiffToNow(oldMSTime));
490 }
uint32 Realm
Definition: Realm.h:53
QueryResult PQuery(Format &&sql, T *conn, Args &&...args)
Definition: DatabaseWorkerPool.h:165
rbac::RBACDefaultPermissionsContainer _defaultPermissions
Definition: AccountMgr.h:95
void ClearRBAC()
Definition: AccountMgr.cpp:550
Realm realm
Definition: World.cpp:3485
Class used to access individual fields of database query result.
Definition: Field.h:56
uint32 getMSTime()
Definition: Timer.h:24
arena_t NULL
Definition: jemalloc_internal.h:624
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:198
LoginDatabaseWorkerPool LoginDatabase
Accessor to the realm/login database.
Definition: DatabaseEnv.cpp:22
void AddLinkedPermission(uint32 id)
Adds a new linked Permission.
Definition: RBAC.h:762
Battlenet::RealmHandle Id
Definition: Realm.h:86
uint32_t uint32
Definition: Define.h:150
std::shared_ptr< ResultSet > QueryResult
Definition: QueryResult.h:61
Definition: RBAC.h:748
uint32 GetMSTimeDiffToNow(uint32 oldMSTime)
Definition: Timer.h:42
QueryResult Query(const char *sql, T *connection=nullptr)
Definition: DatabaseWorkerPool.cpp:113
uint32 GetUInt32() const
Definition: Field.h:146
uint8_t uint8
Definition: Define.h:152
#define TC_LOG_INFO(filterType__,...)
Definition: Log.h:201
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207
std::set< uint32 > RBACPermissionContainer
Definition: RBAC.h:746
rbac::RBACPermissionsContainer _permissions
Definition: AccountMgr.h:94

+ Here is the call graph for this function:

void AccountMgr::UpdateAccountAccess ( rbac::RBACData rbac,
uint32  accountId,
uint8  securityLevel,
int32  realmId 
)
493 {
494  if (rbac && securityLevel == rbac->GetSecurityLevel())
495  rbac->SetSecurityLevel(securityLevel);
496 
497  // Delete old security level from DB
498  if (realmId == -1)
499  {
501  stmt->setUInt32(0, accountId);
502  LoginDatabase.Execute(stmt);
503  }
504  else
505  {
507  stmt->setUInt32(0, accountId);
508  stmt->setUInt32(1, realmId);
509  LoginDatabase.Execute(stmt);
510  }
511 
512  // Add new security level
513  if (securityLevel)
514  {
516  stmt->setUInt32(0, accountId);
517  stmt->setUInt8(1, securityLevel);
518  stmt->setInt32(2, realmId);
519  LoginDatabase.Execute(stmt);
520  }
521 }
void SetSecurityLevel(uint8 id)
Sets security level.
Definition: RBAC.h:903
void Execute(const char *sql)
Definition: DatabaseWorkerPool.h:87
uint8 GetSecurityLevel() const
Returns the security level assigned.
Definition: RBAC.h:910
void setUInt8(const uint8 index, const uint8 value)
Definition: PreparedStatement.cpp:97
Definition: PreparedStatement.h:74
Definition: LoginDatabase.h:78
LoginDatabaseWorkerPool LoginDatabase
Accessor to the realm/login database.
Definition: DatabaseEnv.cpp:22
Definition: LoginDatabase.h:77
Definition: LoginDatabase.h:79
PreparedStatement * GetPreparedStatement(PreparedStatementIndex index)
Definition: DatabaseWorkerPool.h:263
void setInt32(const uint8 index, const int32 value)
Definition: PreparedStatement.cpp:151
void setUInt32(const uint8 index, const uint32 value)
Definition: PreparedStatement.cpp:115

+ Here is the call graph for this function:

Member Data Documentation

rbac::RBACDefaultPermissionsContainer AccountMgr::_defaultPermissions
private
rbac::RBACPermissionsContainer AccountMgr::_permissions
private

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