X-Git-Url: http://git.pk910.de/?p=NeonServV5.git;a=blobdiff_plain;f=src%2FChanNode.c;h=44a335f1cb822f2d7c414ebeef955781c93601c1;hp=73adbf6b3881ee6d17c505cb6eb48101a49c3519;hb=HEAD;hpb=0f1dc61921eef1db8e404a5a82372e2d1cd55daa diff --git a/src/ChanNode.c b/src/ChanNode.c index 73adbf6..44a335f 100644 --- a/src/ChanNode.c +++ b/src/ChanNode.c @@ -1,9 +1,28 @@ +/* ChanNode.c - NeonServ v5.6 + * Copyright (C) 2011-2012 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 . + */ #include "ChanNode.h" #include "ChanUser.h" #include "UserNode.h" #include "BanNode.h" #include "modcmd.h" #include "ModeNode.h" +#include "IRCEvents.h" +#include "tools.h" +#include "log.h" static struct ChanNode **chanList; @@ -22,6 +41,7 @@ void init_ChanNode() { } void free_ChanNode() { + SYNCHRONIZE(cache_sync); //kamikaze free all channels and chanusers int i; struct ChanNode *chan, *next; @@ -31,12 +51,13 @@ 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); } } free(chanList); + DESYNCHRONIZE(cache_sync); } int is_valid_chan(const char *name) { @@ -76,6 +97,22 @@ 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) @@ -95,22 +132,25 @@ struct ChanNode* addChannel(const char *name) { struct ChanNode *chan = malloc(sizeof(*chan)); if (!chan) { - perror("malloc() failed"); + printf_log("main", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__); return NULL; } strcpy(chan->name, name); chan->user = NULL; chan->bans = NULL; + chan->spam_settings = NULL; chan->usercount = 0; - chan->chanbot = NULL; + chan->botcount = 0; chan->topic[0] = 0; chan->flags = 0; /* mode lists */ chan->modes = createModeNode(chan); chan->trigger = NULL; + SYNCHRONIZE(cache_sync); chan->next = chanList[chanListIndex]; chanList[chanListIndex] = chan; + DESYNCHRONIZE(cache_sync); return chan; } @@ -152,6 +192,7 @@ int getChanBanCount() { void delChannel(struct ChanNode* chan, int freeChan) { int chanListIndex = get_chanlist_entry(chan->name[1]); if(chanListIndex == -1) return; + SYNCHRONIZE(cache_sync); struct ChanNode *cchan, *last_chan = NULL; for(cchan = chanList[chanListIndex]; cchan; cchan = cchan->next) { if(cchan == chan) { @@ -175,9 +216,11 @@ void delChannel(struct ChanNode* chan, int freeChan) { freeChanNode(chan); else chan->next = NULL; + DESYNCHRONIZE(cache_sync); } void freeChanNode(struct ChanNode* chan) { + event_freechan(chan); if(chan->trigger) { struct trigger_cache *trigger, *next_trigger; for(trigger = chan->trigger; trigger; trigger = next_trigger) { @@ -192,15 +235,14 @@ void freeChanNode(struct ChanNode* chan) { free(chan); } -void checkChannelVisibility(struct ChanNode* chan) { +int checkChannelVisibility(struct ChanNode* chan) { struct ChanUser *chanuser, *next; for(chanuser = getChannelUsers(chan, NULL); chanuser; chanuser = getChannelUsers(chan, chanuser)) { - if(chanuser->user->flags & USERFLAG_ISBOT) { - chan->chanbot = chanuser->user; - return; - } + if(chanuser->user->flags & USERFLAG_ISBOT) + return 1; } //free the channel... + SYNCHRONIZE(cache_sync); for(chanuser = getChannelUsers(chan, NULL); chanuser; chanuser = next) { next = getChannelUsers(chan, chanuser); //remove the channel from the user's channel-list @@ -209,8 +251,10 @@ 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); + DESYNCHRONIZE(cache_sync); + return 0; }