65 auto [salt, verifier] = Trinity::Crypto::SRP6::MakeRegistrationData<AccountSRP6>(username, password);
71 if (bnetAccountId && bnetIndex)
111 ObjectGuid guid = ObjectGuid::Create<HighGuid::Player>((*result)[0].GetUInt64());
117 s->
KickPlayer(
"AccountMgr::DeleteAccount Deleting the account");
122 }
while (result->NextRow());
146 trans->Append(loginStmt);
150 trans->Append(loginStmt);
154 trans->Append(loginStmt);
158 trans->Append(loginStmt);
162 trans->Append(loginStmt);
193 auto [salt, verifier] = Trinity::Crypto::SRP6::MakeRegistrationData<AccountSRP6>(newUsername, newPassword);
205 std::string username;
207 if (!
GetName(accountId, username))
209 sScriptMgr->OnFailedPasswordChange(accountId);
215 sScriptMgr->OnFailedPasswordChange(accountId);
221 auto [salt, verifier] = Trinity::Crypto::SRP6::MakeRegistrationData<AccountSRP6>(username, newPassword);
235 std::string username;
237 if (!
GetName(accountId, username))
265 std::string username;
267 if (!
GetName(accountId, username))
299 return (result) ? (*result)[0].GetUInt32() : 0;
331 name = (*result)[0].GetString();
346 email = (*result)[0].GetString();
374 std::string username;
376 if (!
GetName(accountId, username))
398 std::string oldEmail;
407 if (strcmp(oldEmail.c_str(), newEmail.c_str()) == 0)
420 return (result) ? (*result)[0].GetUInt64() : 0;
460 TC_LOG_DEBUG(
"rbac",
"AccountMgr::LoadRBAC: Loading permissions");
464 TC_LOG_INFO(
"server.loading",
">> Loaded 0 account permission definitions. DB table `rbac_permissions` is empty.");
470 Field* field = result->Fetch();
475 while (result->NextRow());
477 TC_LOG_DEBUG(
"rbac",
"AccountMgr::LoadRBAC: Loading linked permissions");
478 result =
LoginDatabase.Query(
"SELECT id, linkedId FROM rbac_linked_permissions ORDER BY id ASC");
481 TC_LOG_INFO(
"server.loading",
">> Loaded 0 linked permissions. DB table `rbac_linked_permissions` is empty.");
490 Field* field = result->Fetch();
492 if (permissionId != newId)
494 permissionId = newId;
499 if (linkedPermissionId == permissionId)
501 TC_LOG_ERROR(
"sql.sql",
"RBAC Permission {} has itself as linked permission. Ignored", permissionId);
507 while (result->NextRow());
509 TC_LOG_DEBUG(
"rbac",
"AccountMgr::LoadRBAC: Loading default permissions");
510 result =
LoginDatabase.PQuery(
"SELECT secId, permissionId FROM rbac_default_permissions WHERE (realmId = {} OR realmId = -1) ORDER BY secId ASC",
sRealmList->GetCurrentRealmId().Realm);
513 TC_LOG_INFO(
"server.loading",
">> Loaded 0 default permission definitions. DB table `rbac_default_permissions` is empty.");
521 Field* field = result->Fetch();
523 if (secId != newId || permissions ==
nullptr)
529 permissions->insert(field[1].GetUInt32());
532 while (result->NextRow());
534 TC_LOG_INFO(
"server.loading",
">> Loaded {} permission definitions, {} linked permissions and {} default permissions in {} ms", count1, count2, count3,
GetMSTimeDiffToNow(oldMSTime));
539 if (
rbac && securityLevel !=
rbac->GetSecurityLevel())
540 rbac->SetSecurityLevel(securityLevel);
573 TC_LOG_TRACE(
"rbac",
"AccountMgr::GetRBACPermission: {}", permissionId);
574 rbac::RBACPermissionsContainer::const_iterator it =
_permissions.find(permissionId);
585 TC_LOG_ERROR(
"rbac",
"AccountMgr::HasPermission: Wrong accountId 0");
591 bool hasPermission =
rbac.HasPermission(permissionId);
593 TC_LOG_DEBUG(
"rbac",
"AccountMgr::HasPermission [AccountId: {}, PermissionId: {}, realmId: {}]: {}",
594 accountId, permissionId, realmId, hasPermission);
595 return hasPermission;
600 for (std::pair<uint32 const, rbac::RBACPermission*>& permission :
_permissions)
601 delete permission.second;
Trinity::Crypto::SRP::GruntSRP6 AccountSRP6
constexpr std::size_t MAX_PASS_STR
constexpr std::size_t MAX_ACCOUNT_NAME_BYTES
constexpr std::size_t MAX_EMAIL_STR
constexpr std::size_t MAX_ACCOUNT_STR[2]
@ CHAR_SEL_CHARS_BY_ACCOUNT_ID
@ CHAR_DEL_ACCOUNT_INSTANCE_LOCK_TIMES
SQLTransaction< LoginDatabaseConnection > LoginDatabaseTransaction
std::shared_ptr< ResultSet > QueryResult
std::shared_ptr< PreparedResultSet > PreparedQueryResult
DatabaseWorkerPool< LoginDatabaseConnection > LoginDatabase
Accessor to the realm/login database.
DatabaseWorkerPool< CharacterDatabaseConnection > CharacterDatabase
Accessor to the character database.
#define TC_LOG_DEBUG(filterType__, message__,...)
#define TC_LOG_ERROR(filterType__, message__,...)
#define TC_LOG_INFO(filterType__, message__,...)
#define TC_LOG_TRACE(filterType__, message__,...)
@ LOGIN_DEL_ACCOUNT_ACCESS_BY_REALM
@ LOGIN_GET_ACCOUNT_ID_BY_USERNAME
@ LOGIN_SEL_ACCOUNT_BY_ID
@ LOGIN_DEL_ACCOUNT_MUTED
@ LOGIN_DEL_ACCOUNT_BANNED
@ LOGIN_SEL_CHECK_PASSWORD_BY_NAME
@ LOGIN_DEL_ACCOUNT_ACCESS
@ LOGIN_GET_GMLEVEL_BY_REALMID
@ LOGIN_GET_USERNAME_BY_ID
@ LOGIN_INS_REALM_CHARACTERS_INIT
@ LOGIN_SEL_ACCOUNT_BANNED_BY_USERNAME
@ LOGIN_INS_ACCOUNT_ACCESS
@ LOGIN_DEL_REALM_CHARACTERS
@ LOGIN_SEL_CHECK_PASSWORD
uint32 GetMSTimeDiffToNow(uint32 oldMSTime)
bool Utf8ToUpperOnlyLatin(std::string &utf8String)
size_t utf8length(std::string &utf8str)
static AccountOpResult ChangeRegEmail(uint32 accountId, std::string newEmail)
static AccountOpResult DeleteAccount(uint32 accountId)
AccountOpResult CreateAccount(std::string username, std::string password, std::string email="", uint32 bnetAccountId=0, uint8 bnetIndex=0)
rbac::RBACPermissionsContainer _permissions
static AccountOpResult ChangeEmail(uint32 accountId, std::string newEmail)
static uint32 GetSecurity(uint32 accountId, int32 realmId)
static AccountOpResult ChangeUsername(uint32 accountId, std::string newUsername, std::string newPassword)
static uint32 GetCharactersCount(uint32 accountId)
void UpdateAccountAccess(rbac::RBACData *rbac, uint32 accountId, uint8 securityLevel, int32 realmId)
static bool IsPlayerAccount(uint32 gmlevel)
static AccountOpResult ChangePassword(uint32 accountId, std::string newPassword)
static QueryCallback GetSecurityAsync(uint32 accountId, int32 realmId, std::function< void(uint32)> callback)
static bool IsConsoleAccount(uint32 gmlevel)
static AccountMgr * instance()
rbac::RBACPermissionContainer const & GetRBACDefaultPermissions(uint8 secLevel)
static bool HasPermission(uint32 accountId, uint32 permission, uint32 realmId)
static bool CheckPassword(std::string username, std::string password)
static bool GetEmail(uint32 accountId, std::string &email)
rbac::RBACDefaultPermissionsContainer _defaultPermissions
static bool CheckEmail(uint32 accountId, std::string newEmail)
static bool IsBannedAccount(std::string const &name)
rbac::RBACPermission const * GetRBACPermission(uint32 permission) const
static bool IsAdminAccount(uint32 gmlevel)
static uint32 GetId(std::string_view username)
static bool GetName(uint32 accountId, std::string &name)
Class used to access individual fields of database query result.
uint32 GetUInt32() const noexcept
static void DeleteFromDB(ObjectGuid playerguid, uint32 accountId, bool updateRealmChars=true, bool deleteFinally=false)
void setBinary(uint8 index, std::vector< uint8 > &&value)
void setString(uint8 index, std::string &&value)
void setUInt32(uint8 index, uint32 value)
void setInt32(uint8 index, int32 value)
void setUInt8(uint8 index, uint8 value)
void setNull(uint8 index)
bool CheckCredentials(std::string const &username, std::string const &password) const
Player session in the World.
void LogoutPlayer(bool save)
Log the player out
void KickPlayer(std::string_view reason)
Kick a player out of the World.
void AddLinkedPermission(uint32 id)
Adds a new linked Permission.
@ CONFIG_EXTENDED_ACCOUNT_NAME_LENGTH_LIMIT
TC_GAME_API Player * FindConnectedPlayer(ObjectGuid const &)
std::array< uint8, SALT_LENGTH > Salt
std::vector< uint8 > Verifier
static constexpr size_t SALT_LENGTH
std::set< uint32 > RBACPermissionContainer