fix possible crash on user deletion
[srvx.git] / src / mod-snoop.c
index e69161bc339ed5b9c0379483bd45f1b0ca59b5d7..1ca24c826ac1c83aaf9aa294c1a3e393a1296161 100644 (file)
@@ -1,11 +1,12 @@
 /* mod-snoop.c - User surveillance module (per pomac's spec)
  * Copyright 2002-2004 srvx Development Team
  *
- * This program is free software; you can redistribute it and/or modify
+ * This file is part of srvx.
+ *
+ * srvx 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
- * (at your option) any later version.  Important limitations are
- * listed in the COPYING file that accompanies this software.
+ * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -13,7 +14,8 @@
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
- * along with this program; if not, email srvx-maintainers@srvx.net.
+ * along with srvx; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
  */
 
 /* Adds new section to srvx.conf:
@@ -40,7 +42,6 @@
 #include <arpa/inet.h>
 #endif
 
-extern time_t now;
 static struct {
     struct chanNode *channel;
     struct userNode *bot;
@@ -53,8 +54,12 @@ 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)
-#define UPDATE_TIMESTAMP() strftime(timestamp, sizeof(timestamp), "[%H:%M:%S]", localtime(&now))
+#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() do { time_t feh = now; strftime(timestamp, sizeof(timestamp), "[%H:%M:%S]", localtime(&feh)); } while (0)
 
 static void
 snoop_nick_change(struct userNode *user, const char *old_nick) {
@@ -79,11 +84,11 @@ snoop_join(struct modeNode *mNode) {
 }
 
 static void
-snoop_part(struct userNode *user, struct chanNode *chan, const char *reason) {
+snoop_part(struct modeNode *mn, const char *reason) {
     if (!snoop_cfg.enabled) return;
-    if (user->dead) return;
+    if (mn->user->dead) return;
     UPDATE_TIMESTAMP();
-    SNOOP("$bPART$b %s by %s (%s)", chan->name, user->nick, reason ? reason : "");
+    SNOOP("$bPART$b %s by %s (%s)", mn->channel->name, mn->user->nick, reason ? reason : "");
 }
 
 static void
@@ -93,13 +98,12 @@ snoop_kick(struct userNode *kicker, struct userNode *victim, struct chanNode *ch
     SNOOP("$bKICK$b %s from %s by %s", victim->nick, chan->name, (kicker ? kicker->nick : "some server"));
 }
 
-static int
+static void
 snoop_new_user(struct userNode *user) {
-    if (!snoop_cfg.enabled) return 0;
-    if (user->uplink->burst && !snoop_cfg.show_bursts) return 0;
+    if (!snoop_cfg.enabled) return;
+    if (user->uplink->burst && !snoop_cfg.show_bursts) return;
     UPDATE_TIMESTAMP();
-    SNOOP("$bNICK$b %s %s@%s [%s] on %s", user->nick, user->ident, user->hostname, inet_ntoa(user->ip), user->uplink->name);
-    return 0;
+    SNOOP("$bNICK$b %s %s@%s [%s] on %s", user->nick, user->ident, user->hostname, irc_ntoa(&user->ip), user->uplink->name);
 }
 
 static void
@@ -187,7 +191,7 @@ snoop_finalize(void) {
     mod_chanmode_init(&change);
     change.argc = 1;
     change.args[0].mode = MODE_CHANOP;
-    change.args[0].member = AddChannelUser(snoop_cfg.bot, snoop_cfg.channel);
+    change.args[0].u.member = AddChannelUser(snoop_cfg.bot, snoop_cfg.channel);
     mod_chanmode_announce(snoop_cfg.bot, snoop_cfg.channel, &change);
     return 1;
 }