]> jfr.im git - irc/evilnet/x3.git/blobdiff - src/mod-snoop.c
mod-python: improve error logic for pyobj_from_usernode
[irc/evilnet/x3.git] / src / mod-snoop.c
index 87f0f36698c79712fb6e125f7e48ea69c5bc1379..fa067a4565396ec9a8cd1191994eab0509871674 100644 (file)
@@ -3,9 +3,9 @@
  *
  * This file is part of x3.
  *
- * srvx is free software; you can redistribute it and/or modify
+ * x3 is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * the Free Software Foundation; either version 3 of the License, or
  * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
@@ -55,7 +55,11 @@ const char *snoop_module_deps[] = { NULL };
 static int finalized;
 int snoop_finalize(void);
 
-#define SNOOP(FORMAT, ARGS...) send_channel_message(snoop_cfg.channel, snoop_cfg.bot, "%s "FORMAT, timestamp , ## ARGS)
+#if defined(GCC_VARMACROS)
+# define SNOOP(FORMAT, ARGS...) send_channel_message(snoop_cfg.channel, snoop_cfg.bot, "%s "FORMAT, timestamp, ARGS)
+#elif defined(C99_VARMACROS)
+# define SNOOP(FORMAT, ...) send_channel_message(snoop_cfg.channel, snoop_cfg.bot, "%s "FORMAT, timestamp, __VA_ARGS__)
+#endif
 #define UPDATE_TIMESTAMP() strftime(timestamp, sizeof(timestamp), "[%H:%M:%S]", localtime(&now))
 
 static void
@@ -121,10 +125,164 @@ snoop_auth(struct userNode *user, UNUSED_ARG(struct handle_info *old_handle)) {
     if (user->uplink->burst && !snoop_cfg.show_bursts) return;
     if (user->handle_info) {
         UPDATE_TIMESTAMP();
+        /* TODO: show old_handle info -> new handle info if they
+         * re-authed or something.
+         */
         SNOOP("$bAUTH$b %s as %s", user->nick, user->handle_info->handle);
     }
 }
 
+static void
+snoop_user_mode(struct userNode *user, const char *mode_change) {
+    if (!snoop_cfg.enabled) return;
+    if (user->uplink->burst && !snoop_cfg.show_bursts) return;
+    if (!mode_change[1]) return; /* warning there has to be atleast one char in the buffer */
+    UPDATE_TIMESTAMP();
+    SNOOP("$bUMODE$b %s %s", user->nick, mode_change);
+}
+
+static void
+snoop_oper(struct userNode *user) {
+    if (!snoop_cfg.enabled) return;
+    if (user->uplink->burst && !snoop_cfg.show_bursts) return;
+    UPDATE_TIMESTAMP();
+    SNOOP("$bOPER$b %s!%s@%s [%s] on %s", user->nick, user->ident, user->hostname, irc_ntoa(&user->ip), user->uplink->name);
+}
+
+static void
+snoop_channel_mode(struct userNode *who, struct chanNode *channel, char **modes, unsigned int argc)
+{
+       if (!snoop_cfg.enabled) return;
+       if(who) {
+            if (who->uplink->burst && !snoop_cfg.show_bursts) {
+                return;
+            }
+       } else {
+              return; /* Dont show X3 etc modes */
+       }
+
+       static char targets[MAXLEN], string[MAXLEN];
+       struct userNode *un = NULL;
+       char *tmp = NULL, *tg = NULL, *md = NULL;
+       int add = 0;
+
+       string[0] = 0;
+       targets[0] = 0;
+
+       if (argc > 0)
+               unsplit_string(modes, argc, string);
+       else
+               strcpy(string, *modes);
+
+       if((tg = strchr(string, ' ')))
+       {
+               *tg++ = 0;
+               for(md = string; *md; md++)
+               {
+                       if (*md == '+')
+                       {
+                               add = 1;
+                               md++;
+                       }
+                       if (*md == '-')
+                       {
+                               add = 0;
+                               md++;
+                       }
+                       switch(*md)
+                       {
+                               case 'k':
+                                       {
+                                               strcat(targets, " ");
+                                               if ((tmp = strchr(tg, ' ')))
+                                                       *tmp++ = 0;
+                                               strcat(targets, tg);
+                                               if(tmp)
+                                                       tg = tmp;
+                                               break;
+                                       }
+                               case 'l':
+                                       {
+                                               if(add)
+                                               {
+                                                       strcat(targets, " ");
+                                                       if ((tmp = strchr(tg, ' ')))
+                                                               *tmp++ = 0;
+                                                       strcat(targets, tg);
+                                                       if(tmp)
+                                                               tg = tmp;
+                                                       break;
+                                               }
+                                       }
+                               case 'b':
+                                       {
+                                               strcat(targets, " ");
+                                               if ((tmp = strchr(tg, ' ')))
+                                                       *tmp++ = 0;
+                                               strcat(targets, tg);
+                                               if(tmp)
+                                                       tg = tmp;
+                                               break;
+                                       }
+                               case 'e':
+                                       {
+                                               strcat(targets, " ");
+                                               if ((tmp = strchr(tg, ' ')))
+                                                       *tmp++ = 0;
+                                               strcat(targets, tg);
+                                               if(tmp)
+                                                       tg = tmp;
+                                               break;
+                                       }
+                               case 'o':
+                                       {
+                                               strcat(targets, " ");
+                                               if ((tmp = strchr(tg, ' ')))
+                                                       *tmp++ = 0;
+                                               if((un = GetUserN(tg)))
+                                                       strcat(targets, un->nick);
+                                               else
+                                                       strcat(targets, tg);
+                                               if(tmp)
+                                                       tg = tmp;
+                                               break;
+                                       }
+                               case 'h':
+                                       {
+                                               strcat(targets, " ");
+                                               if ((tmp = strchr(tg, ' ')))
+                                                       *tmp++ = 0;
+                                               if((un = GetUserN(tg)))
+                                                       strcat(targets, un->nick);
+                                               else
+                                                       strcat(targets, tg);
+                                               if(tmp)
+                                                       tg = tmp;
+                                               break;
+                                       }
+                               case 'v':
+                                       {
+                                               strcat(targets, " ");
+                                               if ((tmp = strchr(tg, ' ')))
+                                                       *tmp++ = 0;
+                                               if((un = GetUserN(tg)))
+                                                       strcat(targets, un->nick);
+                                               else
+                                                       strcat(targets, tg);
+                                               if(tmp)
+                                                       tg = tmp;
+                                               break;
+                                       }
+                       }
+               }
+       }
+       UPDATE_TIMESTAMP();
+       if (who)
+               SNOOP("$bMODE$b %s %s%s by %s", channel->name, string, targets, who->nick);
+       else
+               SNOOP("$bMODE$b %s %s%s", channel->name, string, targets);
+}
+
 static void
 snoop_conf_read(void) {
     dict_t node;
@@ -163,10 +321,10 @@ snoop_init(void) {
     reg_new_user_func(snoop_new_user);
     reg_del_user_func(snoop_del_user);
     reg_auth_func(snoop_auth);
-    /* Not implemented since hooks don't exist or lack data desired:
-     * chanmode (issuing user not listed)
-     * usermode (no hook)
-     */
+    reg_channel_mode_func(snoop_channel_mode);
+    reg_user_mode_func(snoop_user_mode);
+    reg_oper_func(snoop_oper);
+
     return 1;
 }