summaryrefslogtreecommitdiffstats
path: root/src/Bindings/PluginManager.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/Bindings/PluginManager.h')
-rw-r--r--src/Bindings/PluginManager.h49
1 files changed, 45 insertions, 4 deletions
diff --git a/src/Bindings/PluginManager.h b/src/Bindings/PluginManager.h
index a97582fbe..0423d6af1 100644
--- a/src/Bindings/PluginManager.h
+++ b/src/Bindings/PluginManager.h
@@ -152,6 +152,7 @@ public:
HOOK_MAX = HOOK_NUM_HOOKS - 1,
} ; // tolua_export
+
/** Used as a callback for enumerating bound commands */
class cCommandEnumCallback
{
@@ -164,6 +165,30 @@ public:
virtual bool Command(const AString & a_Command, const cPlugin * a_Plugin, const AString & a_Permission, const AString & a_HelpString) = 0;
} ;
+
+ /** Interface that must be provided by any class that implements a command handler, either in-game or console command. */
+ class cCommandHandler
+ {
+ public:
+ // Force a virtual destructor in descendants
+ virtual ~cCommandHandler() {}
+
+ /** Executes the specified in-game command.
+ a_Split is the command string, split at the spaces.
+ a_Player is the player executing the command, nullptr in case of the console.
+ a_Command is the entire command string.
+ a_Output is the sink into which the additional text returned by the command handler should be sent; only used for console commands. */
+ virtual bool ExecuteCommand(
+ const AStringVector & a_Split,
+ cPlayer * a_Player,
+ const AString & a_Command,
+ cCommandOutputCallback * a_Output = nullptr
+ ) = 0;
+ };
+
+ typedef SharedPtr<cCommandHandler> cCommandHandlerPtr;
+
+
/** The interface used for enumerating and extern-calling plugins */
typedef cItemCallback<cPlugin> cPluginCallback;
@@ -281,8 +306,16 @@ public:
/** Returns true if the specified plugin is loaded. */
bool IsPluginLoaded(const AString & a_PluginName); // tolua_export
- /** Binds a command to the specified plugin. Returns true if successful, false if command already bound. */
- bool BindCommand(const AString & a_Command, cPlugin * a_Plugin, const AString & a_Permission, const AString & a_HelpString); // Exported in ManualBindings.cpp, without the a_Plugin param
+ /** Binds a command to the specified handler.
+ Returns true if successful, false if command already bound.
+ Exported in ManualBindings.cpp. */
+ bool BindCommand(
+ const AString & a_Command,
+ cPlugin * a_Plugin,
+ cCommandHandlerPtr a_Handler,
+ const AString & a_Permission,
+ const AString & a_HelpString
+ );
/** Calls a_Callback for each bound command, returns true if all commands were enumerated */
bool ForEachCommand(cCommandEnumCallback & a_Callback); // Exported in ManualBindings.cpp
@@ -302,8 +335,15 @@ public:
/** Removes all console command bindings that the specified plugin has made */
void RemovePluginConsoleCommands(cPlugin * a_Plugin);
- /** Binds a console command to the specified plugin. Returns true if successful, false if command already bound. */
- bool BindConsoleCommand(const AString & a_Command, cPlugin * a_Plugin, const AString & a_HelpString); // Exported in ManualBindings.cpp, without the a_Plugin param
+ /** Binds a console command to the specified handler.
+ Returns true if successful, false if command already bound.
+ Exported in ManualBindings.cpp. */
+ bool BindConsoleCommand(
+ const AString & a_Command,
+ cPlugin * a_Plugin,
+ cCommandHandlerPtr a_Handler,
+ const AString & a_HelpString
+ );
/** Calls a_Callback for each bound console command, returns true if all commands were enumerated */
bool ForEachConsoleCommand(cCommandEnumCallback & a_Callback); // Exported in ManualBindings.cpp
@@ -348,6 +388,7 @@ private:
cPlugin * m_Plugin;
AString m_Permission; // Not used for console commands
AString m_HelpString;
+ cCommandHandlerPtr m_Handler;
} ;
typedef std::map<int, cPluginManager::PluginList> HookMap;