summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2004-04-06 19:22:11 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2004-04-06 19:22:11 +0000
commit05e460e96cdd03f94587c0e0c5792c75d3dfa440 (patch)
treef62fee5c6107de87d3062eeff778ac28b27af345
parent32aa3afffaee0aabfd2aa295ae029af8cddba472 (diff)
Added OnUserPreMessage and OnUserPreNotice events (not tested yet)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@407 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r--include/inspircd.h5
-rw-r--r--include/modules.h22
-rw-r--r--src/inspircd.cpp31
-rw-r--r--src/modules.cpp2
4 files changed, 59 insertions, 1 deletions
diff --git a/include/inspircd.h b/include/inspircd.h
index 7d7971532..f38ee47be 100644
--- a/include/inspircd.h
+++ b/include/inspircd.h
@@ -64,6 +64,11 @@
#define WM_AND 1
#define WM_OR 2
+// flags for use with OnUserPreMessage and OnUserPreNotice
+
+#define TYPE_USER 1
+#define TYPE_CHANNEL 2
+
typedef std::deque<std::string> file_cache;
/* prototypes */
diff --git a/include/modules.h b/include/modules.h
index d2c578b04..d0195bd1b 100644
--- a/include/modules.h
+++ b/include/modules.h
@@ -207,7 +207,27 @@ class Module : public classbase
* The source parameter contains the details of the user who issued the WHOIS command, and
* the dest parameter contains the information of the user they are whoising.
*/
- void Module::OnWhois(userrec* source, userrec* dest);
+ virtual void Module::OnWhois(userrec* source, userrec* dest);
+
+ /** Called whenever a user is about to PRIVMSG A user or a channel, before any processing is done.
+ * Returning any nonzero value from this function stops the process immediately, causing no
+ * output to be sent to the user by the core. If you do this you must produce your own numerics,
+ * notices etc. This is useful for modules which may want to filter or redirect messages.
+ * target_type can be one of TYPE_USER or TYPE_CHANNEL. If the target_type value is a user,
+ * you must cast dest to a userrec* otherwise you must cast it to a chanrec*, this is the details
+ * of where the message is destined to be sent.
+ */
+ virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::String text);
+
+ /** Called whenever a user is about to NOTICE A user or a channel, before any processing is done.
+ * Returning any nonzero value from this function stops the process immediately, causing no
+ * output to be sent to the user by the core. If you do this you must produce your own numerics,
+ * notices etc. This is useful for modules which may want to filter or redirect messages.
+ * target_type can be one of TYPE_USER or TYPE_CHANNEL. If the target_type value is a user,
+ * you must cast dest to a userrec* otherwise you must cast it to a chanrec*, this is the details
+ * of where the message is destined to be sent.
+ */
+ virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::String text);
};
diff --git a/src/inspircd.cpp b/src/inspircd.cpp
index 214cb969c..e3fe29ab4 100644
--- a/src/inspircd.cpp
+++ b/src/inspircd.cpp
@@ -3639,6 +3639,14 @@ void handle_privmsg(char **parameters, int pcnt, userrec *user)
WriteServ(user->fd,"404 %s %s :Cannot send to channel (+m)", user->nick, chan->name);
return;
}
+
+ int MOD_RESULT = 0;
+
+ FOREACH_RESULT(OnUserPreMessage(user,chan,TYPE_USER,std::string(parameters[1]));
+ if (MOD_RESULT) {
+ return;
+ }
+
ChanExceptSender(chan, user, "PRIVMSG %s :%s", chan->name, parameters[1]);
}
else
@@ -3657,6 +3665,14 @@ void handle_privmsg(char **parameters, int pcnt, userrec *user)
/* auto respond with aweh msg */
WriteServ(user->fd,"301 %s %s :%s",user->nick,dest->nick,dest->awaymsg);
}
+
+ int MOD_RESULT = 0;
+
+ FOREACH_RESULT(OnUserPreMessage(user,dest,TYPE_USER,std::string(parameters[1]));
+ if (MOD_RESULT) {
+ return;
+ }
+
WriteTo(user, dest, "PRIVMSG %s :%s", dest->nick, parameters[1]);
}
else
@@ -3690,6 +3706,14 @@ void handle_notice(char **parameters, int pcnt, userrec *user)
WriteServ(user->fd,"404 %s %s :Cannot send to channel (+m)", user->nick, chan->name);
return;
}
+
+ int MOD_RESULT = 0;
+
+ FOREACH_RESULT(OnUserPreNotice(user,chan,TYPE_CHANNEL,std::string(parameters[1]));
+ if (MOD_RESULT) {
+ return;
+ }
+
WriteChannel(chan, user, "NOTICE %s :%s", chan->name, parameters[1]);
}
else
@@ -3703,6 +3727,13 @@ void handle_notice(char **parameters, int pcnt, userrec *user)
dest = Find(parameters[0]);
if (dest)
{
+ int MOD_RESULT = 0;
+
+ FOREACH_RESULT(OnUserPreNotice(user,dest,TYPE_USER,std::string(parameters[1]));
+ if (MOD_RESULT) {
+ return;
+ }
+
WriteTo(user, dest, "NOTICE %s :%s", dest->nick, parameters[1]);
}
else
diff --git a/src/modules.cpp b/src/modules.cpp
index caacd9afc..2065f4c6c 100644
--- a/src/modules.cpp
+++ b/src/modules.cpp
@@ -120,6 +120,8 @@ Version Module::GetVersion() { return Version(1,0,0,0); }
void Module::OnOper(userrec* user) { };
void Module::OnInfo(userrec* user) { };
void Module::OnWhois(userrec* source, userrec* dest) { };
+int OnUserPreMessage(userrec* user,void* dest,int target_type, std::String text) { return 0; };
+int OnUserPreNotice(userrec* user,void* dest,int target_type, std::String text) { return 0; };
// server is a wrapper class that provides methods to all of the C-style
// exports in the core