*** VERSION 5.2.0 ***
[NeonServV5.git] / src / ChanNode.c
index 73adbf6b3881ee6d17c505cb6eb48101a49c3519..55f1302720f0684fb2bdc6cb7fab4ac8518d3ea7 100644 (file)
@@ -1,9 +1,26 @@
+/* ChanNode.c - NeonServ v5.2
+ * Copyright (C) 2011  Philipp Kreil (pk910)
+ * 
+ * This program 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 3 of the License, or
+ * (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
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * 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, see <http://www.gnu.org/licenses/>. 
+ */
 #include "ChanNode.h"
 #include "ChanUser.h"
 #include "UserNode.h"
 #include "BanNode.h"
 #include "modcmd.h"
 #include "ModeNode.h"
+#include "bot_NeonSpam.h"
 
 static struct ChanNode **chanList;
 
@@ -31,7 +48,7 @@ void free_ChanNode() {
             next = chan->next;
             for(chanuser = getChannelUsers(chan, NULL); chanuser; chanuser = next_chanuser) {
                 next_chanuser = getChannelUsers(chan, chanuser);
-                free(chanuser);
+                freeChanUser(chanuser);
             }
             freeChanNode(chan);
         }
@@ -76,6 +93,21 @@ static int get_chanlist_entry(int name) {
     return 46;
 }
 
+struct ChanNode* getAllChans(struct ChanNode *last) {
+    if(last == NULL || last->next == NULL) {
+        int cindex;
+        if(last == NULL)
+            cindex = 0;
+        else
+            cindex = get_chanlist_entry(last->name[1]) + 1;
+        while(chanList[cindex] == NULL && cindex < CHANNEL_LIST_SIZE)
+            cindex++;
+        if(cindex >= CHANNEL_LIST_SIZE) return NULL;
+        return chanList[cindex];
+    } else
+        return last->next;
+}
+
 struct ChanNode* getChanByName(const char *name) { //case insensitive
     int chanListIndex = get_chanlist_entry(name[1]);
     if(chanListIndex == -1 || chanList[chanListIndex] == NULL)
@@ -101,6 +133,7 @@ struct ChanNode* addChannel(const char *name) {
     strcpy(chan->name, name);
     chan->user = NULL;
     chan->bans = NULL;
+    chan->spam_settings = NULL;
     chan->usercount = 0;
     chan->chanbot = NULL;
     chan->topic[0] = 0;
@@ -189,6 +222,8 @@ void freeChanNode(struct ChanNode* chan) {
     freeModeNode(chan->modes);
     if(chan->bans)
         removeChannelBans(chan);
+    if(chan->spam_settings)
+        freeNeonSpamSettings(chan->spam_settings);
     free(chan);
 }
 
@@ -209,7 +244,7 @@ void checkChannelVisibility(struct ChanNode* chan) {
             //free the user (no more channels)
             delUser(chanuser->user, 1);
         }
-        free(chanuser);
+        freeChanUser(chanuser);
     }
     chan->user = NULL;
     delChannel(chan, 1);