DB/Account: update account_access table cherry-pick take 2 (with refactors)

(cherry picked from commit 8e0365d8a6)
This commit is contained in:
ForesterDev
2020-06-20 23:49:18 +04:00
committed by Shauren
parent e38b2e8f5a
commit 69cadae38a
2 changed files with 14 additions and 10 deletions

View File

@@ -58,7 +58,7 @@ public:
static std::vector<ChatCommand> accountSetCommandTable =
{
{ "addon", rbac::RBAC_PERM_COMMAND_ACCOUNT_SET_ADDON, true, &HandleAccountSetAddonCommand, "" },
{ "sec", rbac::RBAC_PERM_COMMAND_ACCOUNT_SET_SEC, true, nullptr, "", accountSetSecTable },
{ "sec", rbac::RBAC_PERM_COMMAND_ACCOUNT_SET_SEC, true, nullptr, "", accountSetSecTable },
{ "gmlevel", rbac::RBAC_PERM_COMMAND_ACCOUNT_SET_SECLEVEL, true, &HandleAccountSetSecLevelCommand, "" }, // temp for a transition period
{ "seclevel", rbac::RBAC_PERM_COMMAND_ACCOUNT_SET_SECLEVEL, true, &HandleAccountSetSecLevelCommand, "" },
{ "password", rbac::RBAC_PERM_COMMAND_ACCOUNT_SET_PASSWORD, true, &HandleAccountSetPasswordCommand, "" },
@@ -665,7 +665,7 @@ public:
return true;
}
static bool HandleAccountSetSecLevelCommand(ChatHandler* handler, Optional<std::string> accountName, uint8 securityLevel, int32 realmId)
static bool HandleAccountSetSecLevelCommand(ChatHandler* handler, Optional<std::string> accountName, uint8 securityLevel, Optional<int32> realmId)
{
uint32 accountId;
if (accountName)
@@ -702,16 +702,20 @@ public:
return false;
}
int32 realmID = -1;
if (realmId)
realmID = *realmId;
// handler->getSession() == nullptr only for console
uint32 playerSecurity;
if (handler->GetSession())
playerSecurity = AccountMgr::GetSecurity(handler->GetSession()->GetAccountId(), realmId);
playerSecurity = AccountMgr::GetSecurity(handler->GetSession()->GetAccountId(), realmID);
else
playerSecurity = SEC_CONSOLE;
// can set security level only for target with less security and to less security that we have
// This also restricts setting handler's own security.
uint32 targetSecurity = AccountMgr::GetSecurity(accountId, realmId);
uint32 targetSecurity = AccountMgr::GetSecurity(accountId, realmID);
if (targetSecurity >= playerSecurity || securityLevel >= playerSecurity)
{
handler->SendSysMessage(LANG_YOURS_SECURITY_IS_LOW);
@@ -720,7 +724,7 @@ public:
}
// Check and abort if the target gm has a higher rank on one of the realms and the new realm is -1
if (realmId == -1 && !AccountMgr::IsConsoleAccount(playerSecurity))
if (realmID == -1 && !AccountMgr::IsConsoleAccount(playerSecurity))
{
LoginDatabasePreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_ACCOUNT_ACCESS_SECLEVEL_TEST);
@@ -738,14 +742,14 @@ public:
}
// Check if provided realmID has a negative value other than -1
if (realmId < -1)
if (realmID < -1)
{
handler->SendSysMessage(LANG_INVALID_REALMID);
handler->SetSentErrorMessage(true);
return false;
}
sAccountMgr->UpdateAccountAccess(nullptr, accountId, securityLevel, realmId);
sAccountMgr->UpdateAccountAccess(nullptr, accountId, securityLevel, realmID);
handler->PSendSysMessage(LANG_YOU_CHANGE_SECURITY, accountName->c_str(), securityLevel);
return true;