feat(Core/RBAC): Role Based Access Controls (#24641)
Co-authored-by: blinkysc <blinkysc@users.noreply.github.com> Co-authored-by: Spp <spp@jorge.gr> Co-authored-by: Spp <spp@tc.plus> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Co-authored-by: Andrew <47818697+Nyeriah@users.noreply.github.com>
This commit is contained in:
@@ -24,6 +24,7 @@
|
||||
#include "ObjectMgr.h"
|
||||
#include "Opcodes.h"
|
||||
#include "Player.h"
|
||||
#include "RBAC.h"
|
||||
#include "Realm.h"
|
||||
#include "ScriptMgr.h"
|
||||
#include "Tokenize.h"
|
||||
@@ -54,6 +55,13 @@ bool ChatHandler::IsAvailable(uint32 securityLevel) const
|
||||
return IsConsole() ? true : m_session->GetSecurity() >= AccountTypes(securityLevel);
|
||||
}
|
||||
|
||||
bool ChatHandler::HasPermission(uint32 permissionId) const
|
||||
{
|
||||
if (IsConsole())
|
||||
return true;
|
||||
return m_session && m_session->HasPermission(permissionId);
|
||||
}
|
||||
|
||||
bool ChatHandler::HasLowerSecurity(Player* target, ObjectGuid guid, bool strong)
|
||||
{
|
||||
WorldSession* target_session = nullptr;
|
||||
@@ -82,7 +90,7 @@ bool ChatHandler::HasLowerSecurityAccount(WorldSession* target, uint32 target_ac
|
||||
return false;
|
||||
|
||||
// ignore only for non-players for non strong checks (when allow apply command at least to same sec level)
|
||||
if (!AccountMgr::IsPlayerAccount(m_session->GetSecurity()) && !strong && sWorld->getBoolConfig(CONFIG_GM_LOWER_SECURITY))
|
||||
if (m_session->HasPermission(rbac::RBAC_PERM_CAN_IGNORE_LOWER_SECURITY_CHECK) && !strong && sWorld->getBoolConfig(CONFIG_GM_LOWER_SECURITY))
|
||||
return false;
|
||||
|
||||
if (target)
|
||||
@@ -117,7 +125,7 @@ void ChatHandler::SendGMText(std::string_view str)
|
||||
{
|
||||
std::vector<std::string_view> lines = Acore::Tokenize(str, '\n', true);
|
||||
// Session should have permissions to receive global gm messages
|
||||
if (AccountMgr::IsPlayerAccount(m_session->GetSecurity()))
|
||||
if (!m_session->HasPermission(rbac::RBAC_PERM_RECEIVE_GLOBAL_GM_TEXTMESSAGE))
|
||||
return;
|
||||
|
||||
for (std::string_view line : lines)
|
||||
@@ -231,7 +239,7 @@ bool ChatHandler::_ParseCommands(std::string_view text)
|
||||
return true;
|
||||
|
||||
// Pretend commands don't exist for regular players
|
||||
if (m_session && AccountMgr::IsPlayerAccount(m_session->GetSecurity()) && !sWorld->getBoolConfig(CONFIG_ALLOW_PLAYER_COMMANDS))
|
||||
if (m_session && !m_session->HasPermission(rbac::RBAC_PERM_COMMANDS_NOTIFY_COMMAND_NOT_FOUND_ERROR) && !sWorld->getBoolConfig(CONFIG_ALLOW_PLAYER_COMMANDS))
|
||||
return false;
|
||||
|
||||
// Send error message for GMs
|
||||
@@ -358,7 +366,7 @@ std::size_t ChatHandler::BuildChatPacket(WorldPacket& data, ChatMsg chatType, La
|
||||
if (Player const* playerSender = sender->ToPlayer())
|
||||
{
|
||||
chatTag = playerSender->GetChatTag();
|
||||
gmMessage = playerSender->IsGameMaster();
|
||||
gmMessage = playerSender->GetSession()->HasPermission(rbac::RBAC_PERM_COMMAND_GM_CHAT);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user