mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-18 19:35:42 +00:00
feat(Core/Scripting): Add hook during command security evaluation. (#20564)
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user