feat(Core/Scripting): Add hook during command security evaluation. (#20564)

This commit is contained in:
Benjamin Jackson
2024-11-14 15:14:28 -05:00
committed by GitHub
parent e1766eb87f
commit 53cd41b938
4 changed files with 15 additions and 0 deletions

View File

@@ -16,6 +16,7 @@
*/
#include "AllCommandScript.h"
#include "ChatCommand.h"
#include "ScriptMgr.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));
}
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)
: ScriptObject(name, ALLCOMMANDHOOK_END)
{

View File

@@ -19,12 +19,14 @@
#define SCRIPT_OBJECT_ALL_COMMAND_SCRIPT_H_
#include "ScriptObject.h"
#include "ChatCommand.h"
#include <vector>
enum AllCommandHook
{
ALLCOMMANDHOOK_ON_HANDLE_DEV_COMMAND,
ALLCOMMANDHOOK_ON_TRY_EXECUTE_COMMAND,
ALLCOMMANDHOOK_ON_BEFORE_IS_INVOKER_VISIBLE,
ALLCOMMANDHOOK_END
};
@@ -45,6 +47,8 @@ public:
* @param cmdStr Contains information about the command name
*/
[[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

View File

@@ -22,6 +22,7 @@
#include "ArenaTeam.h"
#include "AuctionHouseMgr.h"
#include "Battleground.h"
#include "ChatCommand.h"
#include "Common.h"
#include "DBCStores.h"
#include "DynamicObject.h"
@@ -672,6 +673,7 @@ public: /* CommandSC */
void OnHandleDevCommand(Player* player, bool& enable);
bool OnTryExecuteCommand(ChatHandler& handler, std::string_view cmdStr);
bool OnBeforeIsInvokerVisible(std::string name, Acore::Impl::ChatCommands::CommandPermissions permissions, ChatHandler const& who);
public: /* DatabaseScript */