moved cmd_move to global.mod and fixed crash in bot_SpamServ.c
[NeonServV5.git] / src / modules / NeonSpam.mod / bot_NeonSpam.c
index 5784f6338ce24f44ee3691baf4661612fa1b2f4a..89aeb92be68236a07f30438667c517c56e4855ba 100644 (file)
@@ -1,4 +1,4 @@
-/* bot_NeonSpam.c - NeonServ v5.3
+/* bot_NeonSpam.c - NeonServ v5.4
  * Copyright (C) 2011-2012  Philipp Kreil (pk910)
  * 
  * This program is free software: you can redistribute it and/or modify
 #include "../module.h"
 
 #include "bot_NeonSpam.h"
-#include "modcmd.h"
-#include "IRCParser.h"
-#include "IRCEvents.h"
-#include "UserNode.h"
-#include "ChanNode.h"
-#include "ChanUser.h"
-#include "ModeNode.h"
-#include "BanNode.h"
-#include "ClientSocket.h"
-#include "mysqlConn.h"
-#include "lang.h"
-#include "HandleInfoHandler.h"
-#include "WHOHandler.h"
-#include "DBHelper.h"
-#include "tools.h"
-#include "timeq.h"
-#include "version.h"
-#include "EventLogger.h"
-#include "bots.h"
-#include "cmd_neonserv.h"
+#include "../../modcmd.h"
+#include "../../IRCParser.h"
+#include "../../IRCEvents.h"
+#include "../../UserNode.h"
+#include "../../ChanNode.h"
+#include "../../ChanUser.h"
+#include "../../ModeNode.h"
+#include "../../BanNode.h"
+#include "../../ClientSocket.h"
+#include "../../mysqlConn.h"
+#include "../../lang.h"
+#include "../../HandleInfoHandler.h"
+#include "../../WHOHandler.h"
+#include "../../DBHelper.h"
+#include "../../tools.h"
+#include "../../timeq.h"
+#include "../../version.h"
+#include "../../EventLogger.h"
+#include "../../bots.h"
 #include "cmd_neonspam.h"
 
 #define BOTID 2
@@ -235,6 +234,8 @@ int loadNeonSpamSettings(struct ChanNode *chan) {
     MYSQL_RES *res;
     MYSQL_ROW row, defaults = NULL;
     loadChannelSettings(chan);
+    if(!(chan->flags & CHANFLAG_CHAN_REGISTERED))
+        return 0;
     printf_mysql_query("SELECT `channel_scanner`, `channel_spam_limit`, `channel_spam_except`, `channel_flood_limit`, `channel_flood_time`, `channel_flood_except`, `channel_join_limit`, `channel_join_time`, `channel_join_except`, `channel_caps_percent`, `channel_caps_except`, `channel_digit_percent`, `channel_digit_except` FROM `channels` WHERE `channel_id` = '%d'", chan->channel_id);
     res = mysql_use();
     row = mysql_fetch_row(res);
@@ -325,6 +326,12 @@ static void createSpamNode(struct ChanUser *chanuser) {
     chanuser->spamnode = spamnode;
 }
 
+static int neonspam_event_freechan(struct ChanNode *chan) {
+    if(chan->spam_settings)
+        freeNeonSpamSettings(chan->spam_settings);
+    return 1;
+}
+
 void init_NeonSpam(int type) {
     
     set_bot_alias(BOTID, BOTALIAS);
@@ -333,13 +340,14 @@ void init_NeonSpam(int type) {
     if(type == MODSTATE_REBIND) return;
     
     //register events
-    bind_bot_ready(neonspam_bot_ready);
-    bind_join(neonspam_event_join);
-    bind_chanmsg(neonspam_event_chanmsg);
-    bind_privctcp(general_event_privctcp);
-    bind_kick(neonspam_event_kick);
+    bind_bot_ready(neonspam_bot_ready, module_id);
+    bind_join(neonspam_event_join, module_id);
+    bind_chanmsg(neonspam_event_chanmsg, module_id);
+    bind_privctcp(general_event_privctcp, module_id);
+    bind_kick(neonspam_event_kick, module_id);
+    bind_freechan(neonspam_event_freechan, module_id);
     
-    set_trigger_callback(BOTID, neonspam_trigger_callback);
+    set_trigger_callback(BOTID, module_id, neonspam_trigger_callback);
     
     register_default_language_table(msgtab);
 }