fix possible crash on user deletion
[srvx.git] / src / mod-watchdog.c
index 26bee0434ea06bcbeb4c491d8dbdca3e0e93e73e..0edf09dfb5cec806111b9e91cf6809ab70f38d03 100644 (file)
@@ -49,6 +49,7 @@
 
 static const struct message_entry msgtab[] = {
     { "WDMSG_REGISTER_SUCCESS", "$b%s$b is now registered with %s." },
+    { "WDMSG_UNREG_SUCCESS", "$b%s$b is now unregistered." },
     { "WDMSG_NOT_REGISTERED", "$b%s$b is not registered with %s." },
     { "WDMSG_ALREADY_ADDED", "$b%s$b is already added. (ID: %s)" },
     { "WDMSG_BADWORD_ADDED", "added '$b%s$b' to the badword list with ID %s." },
@@ -83,7 +84,9 @@ struct watchdog_channel {
 #define BADACTION_KILL   2
 #define BADACTION_GLINE  3
 
-#define WDMSG_BADWORD_ALERT "%s used badword '%s' in channel: %s"
+#define WDMSG_BADWORD_ALERT "%s used badword '%s' in channel: %s."
+#define WDMSG_REGISTER_SUCCESS "$b%s$b is now registered with %s by %s."
+#define WDMSG_UNREG_SUCCESS "$b%s$b is now unregistered by %s."
 
 static struct {
     const char *nick;
@@ -92,6 +95,7 @@ static struct {
     unsigned long ban_duration;
     unsigned long gline_duration;
     struct chanNode *alert_channel;
+    struct chanNode *oper_channel;
 } watchdog_conf;
 
 const char *watchdog_module_deps[] = { NULL };
@@ -107,6 +111,7 @@ static struct watchdog_channel *add_channel(const char *name);
 static struct badword *add_badword(const char *badword_mask, unsigned int triggered, unsigned int action, unsigned int alert, const char *id);
 #define watchdog_notice(target, format...) send_message(target , watchdog , ## format)
 #define watchdog_debug(format...) do { if(watchdog_conf.alert_channel) send_channel_message(watchdog_conf.alert_channel , watchdog , ## format); } while(0)
+#define watchdog_oper_message(format...) do { if(watchdog_conf.oper_channel) send_channel_message(watchdog_conf.oper_channel , watchdog , ## format); } while(0)
 
 static MODCMD_FUNC(cmd_addbad)
 {
@@ -353,6 +358,7 @@ static MODCMD_FUNC(cmd_register)
 
     add_channel(channel->name);
     reply("WDMSG_REGISTER_SUCCESS", channel->name, watchdog->nick);
+    watchdog_oper_message(WDMSG_REGISTER_SUCCESS, channel->name, watchdog->nick, user->handle_info->handle);
     return 1;
 }
 
@@ -374,6 +380,7 @@ static MODCMD_FUNC(cmd_unregister)
         DelChannelUser(watchdog, channel, reason, 0);
         dict_remove(chanlist, channel->name);
         reply("CSMSG_UNREG_SUCCESS", channel->name);
+        watchdog_oper_message(WDMSG_UNREG_SUCCESS, channel->name, user->handle_info->handle);
         return 1;
     } else {
         reply("WDMSG_NOT_REGISTERED", channel->name, watchdog->nick);
@@ -546,6 +553,15 @@ watchdog_conf_read(void)
                watchdog_conf.alert_channel = NULL;
        }
     
+       str = database_get_data(conf_node, "oper_channel", RECDB_QSTRING);
+       if(str)
+       {
+               watchdog_conf.oper_channel = AddChannel(str, now, "+tinms", NULL);
+       }
+       else
+       {
+               watchdog_conf.oper_channel = NULL;
+       }
 }
 
 static int