feat(Core/Scripting): Add hook during command security evaluation. (#20564)
This commit is contained in:
@@ -506,6 +506,9 @@ bool Acore::Impl::ChatCommands::ChatCommandNode::IsInvokerVisible(ChatHandler co
|
|||||||
if (!_invoker)
|
if (!_invoker)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
if (!sScriptMgr->OnBeforeIsInvokerVisible(_name, _permission, who))
|
||||||
|
return true;
|
||||||
|
|
||||||
if (who.IsConsole() && (_permission.AllowConsole == Acore::ChatCommands::Console::No))
|
if (who.IsConsole() && (_permission.AllowConsole == Acore::ChatCommands::Console::No))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "AllCommandScript.h"
|
#include "AllCommandScript.h"
|
||||||
|
#include "ChatCommand.h"
|
||||||
#include "ScriptMgr.h"
|
#include "ScriptMgr.h"
|
||||||
#include "ScriptMgrMacros.h"
|
#include "ScriptMgrMacros.h"
|
||||||
|
|
||||||
@@ -29,6 +30,11 @@ bool ScriptMgr::OnTryExecuteCommand(ChatHandler& handler, std::string_view cmdSt
|
|||||||
CALL_ENABLED_BOOLEAN_HOOKS(AllCommandScript, ALLCOMMANDHOOK_ON_TRY_EXECUTE_COMMAND, !script->OnTryExecuteCommand(handler, cmdStr));
|
CALL_ENABLED_BOOLEAN_HOOKS(AllCommandScript, ALLCOMMANDHOOK_ON_TRY_EXECUTE_COMMAND, !script->OnTryExecuteCommand(handler, cmdStr));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ScriptMgr::OnBeforeIsInvokerVisible(std::string name, Acore::Impl::ChatCommands::CommandPermissions permissions, ChatHandler const& who)
|
||||||
|
{
|
||||||
|
CALL_ENABLED_BOOLEAN_HOOKS(AllCommandScript, ALLCOMMANDHOOK_ON_BEFORE_IS_INVOKER_VISIBLE, !script->OnBeforeIsInvokerVisible(name, permissions, who));
|
||||||
|
}
|
||||||
|
|
||||||
AllCommandScript::AllCommandScript(const char* name, std::vector<uint16> enabledHooks)
|
AllCommandScript::AllCommandScript(const char* name, std::vector<uint16> enabledHooks)
|
||||||
: ScriptObject(name, ALLCOMMANDHOOK_END)
|
: ScriptObject(name, ALLCOMMANDHOOK_END)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -19,12 +19,14 @@
|
|||||||
#define SCRIPT_OBJECT_ALL_COMMAND_SCRIPT_H_
|
#define SCRIPT_OBJECT_ALL_COMMAND_SCRIPT_H_
|
||||||
|
|
||||||
#include "ScriptObject.h"
|
#include "ScriptObject.h"
|
||||||
|
#include "ChatCommand.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
enum AllCommandHook
|
enum AllCommandHook
|
||||||
{
|
{
|
||||||
ALLCOMMANDHOOK_ON_HANDLE_DEV_COMMAND,
|
ALLCOMMANDHOOK_ON_HANDLE_DEV_COMMAND,
|
||||||
ALLCOMMANDHOOK_ON_TRY_EXECUTE_COMMAND,
|
ALLCOMMANDHOOK_ON_TRY_EXECUTE_COMMAND,
|
||||||
|
ALLCOMMANDHOOK_ON_BEFORE_IS_INVOKER_VISIBLE,
|
||||||
ALLCOMMANDHOOK_END
|
ALLCOMMANDHOOK_END
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -45,6 +47,8 @@ public:
|
|||||||
* @param cmdStr Contains information about the command name
|
* @param cmdStr Contains information about the command name
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] virtual bool OnTryExecuteCommand(ChatHandler& /*handler*/, std::string_view /*cmdStr*/) { return true; }
|
[[nodiscard]] virtual bool OnTryExecuteCommand(ChatHandler& /*handler*/, std::string_view /*cmdStr*/) { return true; }
|
||||||
|
|
||||||
|
[[nodiscard]] virtual bool OnBeforeIsInvokerVisible(std::string /*name*/, Acore::Impl::ChatCommands::CommandPermissions /*permissions*/, ChatHandler const& /*who*/) { return true; }
|
||||||
};
|
};
|
||||||
|
|
||||||
// Compatibility for old scripts
|
// Compatibility for old scripts
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
#include "ArenaTeam.h"
|
#include "ArenaTeam.h"
|
||||||
#include "AuctionHouseMgr.h"
|
#include "AuctionHouseMgr.h"
|
||||||
#include "Battleground.h"
|
#include "Battleground.h"
|
||||||
|
#include "ChatCommand.h"
|
||||||
#include "Common.h"
|
#include "Common.h"
|
||||||
#include "DBCStores.h"
|
#include "DBCStores.h"
|
||||||
#include "DynamicObject.h"
|
#include "DynamicObject.h"
|
||||||
@@ -672,6 +673,7 @@ public: /* CommandSC */
|
|||||||
|
|
||||||
void OnHandleDevCommand(Player* player, bool& enable);
|
void OnHandleDevCommand(Player* player, bool& enable);
|
||||||
bool OnTryExecuteCommand(ChatHandler& handler, std::string_view cmdStr);
|
bool OnTryExecuteCommand(ChatHandler& handler, std::string_view cmdStr);
|
||||||
|
bool OnBeforeIsInvokerVisible(std::string name, Acore::Impl::ChatCommands::CommandPermissions permissions, ChatHandler const& who);
|
||||||
|
|
||||||
public: /* DatabaseScript */
|
public: /* DatabaseScript */
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user