Added an extra hook (and #ifdef), MODULE_HOOK_REMOTEMSG
authorMatthew Wiggins <lithium@rubiks.net>
Sat, 15 Jan 2005 23:35:03 +0000 (23:35 +0000)
committerMatthew Wiggins <lithium@rubiks.net>
Sat, 15 Jan 2005 23:35:03 +0000 (23:35 +0000)
 in m_message() CHOOK_MSG fires if MyClient(sender) if not CHOOK_REMOTEMSG fires

include/config.h
include/hooks.h
src/modules.c
src/s_user.c

index e43bb29..011e067 100644 (file)
@@ -18,7 +18,7 @@
  *
  */
 
-/* $Id: config.h,v 1.11 2005/01/14 13:47:07 mmondor Exp $ */
+/* $Id: config.h,v 1.12 2005/01/15 23:35:02 mwiggins Exp $ */
 
 #ifndef        __config_include__
 #define        __config_include__
  */
 #define AOPER_AUTO
 
+/* MODULE_HOOK_REMOTEMSG
+ * Add an aditional hook for messages originating from other servers
+ */
+#define MODULE_HOOK_REMOTEMSG
+
 /* SSL
  * SSL support stolen from fqircd
  */
index 99ce288..fc68fe3 100644 (file)
@@ -30,6 +30,12 @@ enum c_hooktype {
                        * Params: 3: (aClient *, int isnotice, char *msgtext), 
                        * Returns int 
                        */
+#ifdef MODULE_HOOK_REMOTEMSG
+   CHOOK_REMOTEMSG,      /* called for privmsg or notice from !MyClient()
+                                          * Params: 5: (aClient *, aClient *,int isnotice,char *dest, char *msgtxt),
+                                          * Returns int
+                                          */
+#endif
    CHOOK_CHANMSG,     /* called for every privmsg or notice to a channel
                        * Params: 4: (aClient *source, aChannel *destination, 
 \                      *             int isnotice, char *msgtxt)
index fdced87..cd579e0 100644 (file)
@@ -3,7 +3,7 @@
  *   Copyright (C) 2003, Lucas Madar
  */
 
-/* $Id: modules.c,v 1.1 2005/01/12 07:44:56 mmondor Exp $ */
+/* $Id: modules.c,v 1.2 2005/01/15 23:35:03 mwiggins Exp $ */
 
 #include "struct.h"
 #include "common.h"
@@ -474,6 +474,9 @@ static DLink *preaccess_hooks = NULL;
 static DLink *postaccess_hooks = NULL;
 static DLink *postmotd_hooks = NULL;
 static DLink *msg_hooks = NULL;
+#ifdef MODULE_HOOK_REMOTEMSG
+static DLink *remotemsg_hooks = NULL;
+#endif
 static DLink *chanmsg_hooks = NULL;
 static DLink *usermsg_hooks = NULL;
 static DLink *mymsg_hooks = NULL;
@@ -505,6 +508,10 @@ get_texthooktype(enum c_hooktype hooktype)
 
         case CHOOK_MSG:
             return "Message";
+#ifdef MODULE_HOOK_REMOTEMSG
+               case CHOOK_REMOTEMSG:
+                       return "Remote Message";
+#endif
 
         case CHOOK_CHANMSG:
             return "Channel Message";
@@ -556,6 +563,11 @@ get_hooklist(enum c_hooktype hooktype)
         case CHOOK_MSG:
             hooklist = &msg_hooks;
             break;
+#ifdef MODULE_HOOK_REMOTEMSG
+               case CHOOK_REMOTEMSG:
+                       hooklist = &remotemsg_hooks;
+                       break;
+#endif
 
         case CHOOK_CHANMSG:
             hooklist = &chanmsg_hooks;
@@ -736,6 +748,24 @@ call_hooks(enum c_hooktype hooktype, ...)
                 }
                 break;
             }
+#ifdef MODULE_HOOK_REMOTEMSG
+               case CHOOK_REMOTEMSG:
+                       {
+                               aClient *acptr = va_arg(vl, aClient *);
+                               aClient *asptr = va_arg(vl, aClient *);
+                               int aint = va_arg(vl, int);
+                               char *destptr = va_arg(vl, char *);
+                               char *txtptr = va_arg(vl, char *);
+                               for (lp = remotemsg_hooks; lp; lp = lp->next)
+                               {
+                                       int (*rfunc) (aClient *, aClient *, int, char *, char *) =
+                                               ((aHook*)lp->value.cp)->funcptr;
+                                       if ((ret = (*rfunc)(acptr, asptr, aint, destptr, txtptr)) == FLUSH_BUFFER)
+                                               break;
+                               }
+                               break;
+                       }
+#endif
 
         case CHOOK_CHANMSG:
             {
index c41dd1a..a1129eb 100644 (file)
@@ -21,7 +21,7 @@
  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
-/* $Id: s_user.c,v 1.8 2005/01/14 13:15:33 mmondor Exp $ */
+/* $Id: s_user.c,v 1.9 2005/01/15 23:35:03 mwiggins Exp $ */
 
 #include "struct.h"
 #include "common.h"
@@ -1533,8 +1533,18 @@ m_message(aClient *cptr, aClient *sptr, int parc, char *parv[], int notice)
         parv[1] = canonize(parv[1]);
     }
 
-    if(ismine && call_hooks(CHOOK_MSG, sptr, notice, parv[2]) == FLUSH_BUFFER)
-        return FLUSH_BUFFER;
+       if (ismine)
+       {
+               if(call_hooks(CHOOK_MSG, sptr, notice, parv[2]) == FLUSH_BUFFER)
+                       return FLUSH_BUFFER;
+       }
+#ifdef MODULE_HOOK_REMOTEMSG
+       else
+       {
+               if(call_hooks(CHOOK_REMOTEMSG, cptr, sptr, notice, parv[1], parv[2]) == FLUSH_BUFFER)
+                       return FLUSH_BUFFER;
+       }
+#endif
 
     for (p = NULL, nick = strtoken(&p, parv[1], ","), i = 0; nick && i<20 ;
          nick = strtoken(&p, NULL, ","))