diff --git a/Makefile b/Makefile index 3c1e36c..f03ef5e 100644 --- a/Makefile +++ b/Makefile @@ -18,7 +18,7 @@ OBJS = main.o socket.o tuve.o channel.o LIBRARIES = -CFLAGS = -Wall -O +CFLAGS = -Wall -O -ggdb # Link The Binary $(BINARY) : $(OBJS) diff --git a/channel.c b/channel.c index 3c5cf63..4b242c5 100644 --- a/channel.c +++ b/channel.c @@ -32,17 +32,29 @@ int tuveDelUserChans(myConnections_t *userConnection) { char output[256]; - tuveUserChans_t *tmpChan = 0x0; + tuveUserChans_t *tmpChan = 0x0; + tuveUserChans_t *tmpChan2 = 0x0; tmpChan = userConnection->userInfo.chans; + tmpChan2 = tmpChan; for (;tmpChan != 0x0;tmpChan = tmpChan->next) { - tuveRemoveFromChanList(tmpChan->channel,userConnection); sprintf(output,"chanmsg:EVIL NOTIFICATION:%s:%s Quit (Sig Pipe)\n",tmpChan->channel,userConnection->userInfo.username); tuveSendAllInChan(tmpChan->channel,userConnection,output); sprintf(output,"PART:%s:%s\n",tmpChan->channel,userConnection->userInfo.username); tuveSendAllInChan(tmpChan->channel,userConnection,output); + tuveRemoveFromChanList(tmpChan->channel,userConnection); /* Need to free */ + printf("A:[0x%X]",tmpChan2); + free(tmpChan2); + printf("B"); + tmpChan2 = tmpChan->next; + } + + if (tmpChan2 != 0x0) { + printf("a:[0x%X]",tmpChan2); + free(tmpChan2); + printf("b"); } return(0x0); @@ -76,20 +88,30 @@ tuveUserList_t *tmpUsers = 0x0; tmpChannel = findChan(channel); + if (tmpChannel == 0x0) { + writeLog("findChan failed!\n"); + return(0x1); + } + tmpUsers = tmpChannel->users; + writeLog("Freeing Chan: %s\n",channel); + for (;tmpUsers != 0x0;tmpUsers = tmpUsers->next) { if (!strcasecmp(tmpUsers->user->userInfo.username,userConnection->userInfo.username)) { printf("Found and removed user\n"); + if (tmpUsers->prev != 0x0) tmpUsers->prev->next = tmpUsers->next; if (tmpUsers->next != 0x0) tmpUsers->next->prev = tmpUsers->prev; - //free(tmpUsers); - break; + + free(tmpUsers); + printf("freed\n"); + return(0x0); } } - return(0x0); + return(0x1); } int tuveAddToChanList(char *channel,myConnections_t *userConnection) { @@ -111,6 +133,7 @@ if (!strcasecmp(tmpUsers->user->userInfo.username,userConnection->userInfo.username)) return(0x0); } + printf("ADDED USER"); tmpUsers = (tuveUserList_t *)malloc(sizeof(tuveUserList_t)); @@ -127,25 +150,25 @@ tmpChannel->users = tmpUsers; } - tmpUsers = tmpChannel->users->next; - memset(output,0x0,256); - for (;tmpUsers != 0x0;tmpUsers = tmpUsers->next) { + for (tmpUsers = tmpChannel->users->next;tmpUsers != 0x0;tmpUsers = tmpUsers->next) { if (strlen(output) > 0) sprintf(output,"%s:%s",output,tmpUsers->user->userInfo.username); else sprintf(output,"JOIN:%s:%s",tmpChannel->channel,tmpUsers->user->userInfo.username); } + send(userConnection->fd,output,strlen(output),MSG_NOSIGNAL); - return(0x0); } tuveChanList_t *findChan(char *channel) { - tuveChanList_t *tmpChannel = channels; - for (;tmpChannel != 0x0;tmpChannel = tmpChannel->next) { + tuveChanList_t *tmpChannel = 0x0; + + for (tmpChannel = channels;tmpChannel != 0x0;tmpChannel = tmpChannel->next) { + if (!strcasecmp(tmpChannel->channel,channel)) return(tmpChannel); } @@ -183,8 +206,10 @@ tmpChannel = findChan(channel); - if (tmpChannel == 0x0) + if (tmpChannel == 0x0) { + writeLog("findChan Failed!\n"); return(0x1); + } tmpUsers = tmpChannel->users; diff --git a/socket.c b/socket.c index 117be99..e55b734 100644 --- a/socket.c +++ b/socket.c @@ -238,7 +238,6 @@ int sProcessConnections(fd_set *readset) { myConnections_t *tmpConnection = 0x0; - char output[128]; for (tmpConnection = connections;tmpConnection != 0x0;tmpConnection = tmpConnection->next) { writeLog("socketFD: [%i]\n",tmpConnection->fd); @@ -252,8 +251,6 @@ if (podzGetData(tmpConnection) == -1) { close(tmpConnection->fd); tuveDelUserChans(tmpConnection); - //sprintf(output,"ison:%i:0",tmpConnection->userInfo.uid); - //podzSendAll(output,tmpConnection->fd); sRemoveConnection(tmpConnection->fd); } } diff --git a/tuved.h b/tuved.h index afaf5c6..b870402 100644 --- a/tuved.h +++ b/tuved.h @@ -80,3 +80,5 @@ int tuveAddChan(char *channel,myConnections_t *userConnection); int tuveAddToChanList(char *channel,myConnections_t *userConnection); int tuveSendAllInChan(char *channel,myConnections_t *userConnection,char *output); +int tuveDelUserChans(myConnections_t *userConnection); +int tuveRemoveFromChanList(char *channel,myConnections_t *userConnection);