summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2005-04-14 12:09:53 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2005-04-14 12:09:53 +0000
commit9a3475ed584b09c221219b306611c0b691161a08 (patch)
tree2525e19a856b31c01dc2d6b2226a6a336c52e621
parentb6b58df62aa2fea0b286b69971140cdec17afa61 (diff)
Added OnPreCommand
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@1080 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r--include/modules.h11
-rw-r--r--src/inspircd.cpp7
-rw-r--r--src/modules.cpp1
3 files changed, 19 insertions, 0 deletions
diff --git a/include/modules.h b/include/modules.h
index a7a42991e..7f4cc96be 100644
--- a/include/modules.h
+++ b/include/modules.h
@@ -384,6 +384,17 @@ class Module : public classbase
*/
virtual void OnSendList(userrec* user, chanrec* channel, char mode);
+ /** Called whenever any command is about to be executed.
+ * This event occurs for all registered commands, wether they are registered in the core,
+ * or another module, but it will not occur for invalid commands (e.g. ones which do not
+ * exist within the command table). By returning 1 from this method you may prevent the
+ * command being executed. If you do this, no output is created by the core, and it is
+ * down to your module to produce any output neccessary.
+ * Note that unless you return 1, you should not destroy any structures (e.g. by using
+ * Server::QuitUser) otherwise when the command's handler function executes after your
+ * method returns, it will be passed an invalid pointer to the user object and crash!)
+ */
+ virtual int OnPreCommand(std::string command, char **parameters, int pcnt, userrec *user);
};
diff --git a/src/inspircd.cpp b/src/inspircd.cpp
index 7b0babd91..273259019 100644
--- a/src/inspircd.cpp
+++ b/src/inspircd.cpp
@@ -3020,6 +3020,7 @@ void process_command(userrec *user, char* cmd)
log(DEBUG,"process_command: handler: %s %s %d",user->nick,command,items);
if (cmdlist[i].handler_function)
{
+
/* ikky /stats counters */
if (temp)
{
@@ -3034,6 +3035,12 @@ void process_command(userrec *user, char* cmd)
cmdlist[i].total_bytes+=strlen(temp);
}
+ int MOD_RESULT = 0;
+ FOREACH_RESULT(OnPreCommand(command,command_p,items,user));
+ if (MOD_RESULT == 1) {
+ return;
+ }
+
/* WARNING: nothing may come after the
* command handler call, as the handler
* may free the user structure! */
diff --git a/src/modules.cpp b/src/modules.cpp
index 3d4972a2d..6ff60b208 100644
--- a/src/modules.cpp
+++ b/src/modules.cpp
@@ -332,6 +332,7 @@ int Module::OnKill(userrec* source, userrec* dest, std::string reason) { return
void Module::OnLoadModule(Module* mod,std::string name) { };
void Module::OnBackgroundTimer(time_t curtime) { };
void Module::OnSendList(userrec* user, chanrec* channel, char mode) { };
+int Module::OnPreCommand(std::string command, char **parameters, int pcnt, userrec *user) { return 0; };
// server is a wrapper class that provides methods to all of the C-style
// exports in the core