diff --git a/botthread.c b/botthread.c index 8488ffc..76222e7 100644 --- a/botthread.c +++ b/botthread.c @@ -46,7 +46,7 @@ void *tuveBotThread(void *threadid) { int tid; - + tid = (int)threadid; writeLog(0,"Starting Bot Thread: [%d]\n", tid); while (1) { diff --git a/channel.c b/channel.c index 91bc3c1..a80eda4 100644 --- a/channel.c +++ b/channel.c @@ -151,9 +151,8 @@ tuveChanList_t *tmpChannel = 0x0; tuveUserList_t *tmpUsers = 0x0; -pthread_mutex_lock(&chanMutex); - tmpChannel = findChan(channel); + if (tmpChannel == 0x0) { writeLog(1,"tuveRemoveFromChanList: findChan failed!\n"); return(0x1); diff --git a/main.c b/main.c index e75a050..3e6f914 100644 --- a/main.c +++ b/main.c @@ -13,7 +13,7 @@ FILE *logFile = 0x0; int logLevel = 1; -pthread_mutex_t chanMutex; +pthread_mutex_t chanMutex = PTHREAD_MUTEX_INITIALIZER; void usage(); @@ -64,10 +64,13 @@ exit(1); writeLog(0,"Podz Daemon Starting: %i\n",seconds); + + pthread_mutex_init(&chanMutex, NULL); pthread_t threads[NUM_THREADS]; rc = pthread_create(&threads[t], NULL, tuveBotThread, (void *)t); + sStartListener(); while (1) { @@ -77,6 +80,10 @@ writeLog(3,"readSocks: [%i]\n",readSocks); + rc = pthread_mutex_lock(&chanMutex); + printf("MAIN LOCK: [%i]\n",rc); + + if (readSocks < 0) { perror("select failed"); exit(0x1); diff --git a/nick.c b/nick.c index 27bae8d..e056360 100644 --- a/nick.c +++ b/nick.c @@ -25,3 +25,36 @@ } return(0x0); } + +int tuveWhois(myConnections_t *userConnection,char *nick) { + myConnections_t *user = 0x0; + tuveUserChans_t *chans = 0x0; + char output[256]; + + user = findNick(nick); + + if (user == 0x0) { + sprintf(output,"CHANMSG:TUveD:WHOIS:%s Not Found\n",nick); + sSendData(userConnection,output); + return(0x0); + } + + sprintf(output,"CHANMSG:TUveD:WHOIS:%s is %s\n",nick,user->host); + sSendData(userConnection,output); + sprintf(output,"CHANMSG:TUveD:WHOIS:%s Signed On %s",nick,ctime(&user->signedOn)); + sSendData(userConnection,output); + + if (user->userInfo.chans != 0x0) { + memset(output,0x0,256); + for (chans = user->userInfo.chans;chans != 0x0;chans = chans->next) { + if (strlen(output) == 0) + sprintf(output,"CHANMSG:TUveD:WHOIS:%s Is On %s",nick,chans->channel); + else + sprintf(output,"%s,%s",output,chans->channel); + } + sprintf(output,"%s\n",output); + sSendData(userConnection,output); + } + + return(0x0); + } diff --git a/socket.c b/socket.c index 83a2332..528e303 100644 --- a/socket.c +++ b/socket.c @@ -101,6 +101,7 @@ connections->prev = 0x0; connections->next = 0x0; connections->fd = socketFD; + connections->signedOn = time(NULL); sprintf(connections->host,host); } else { @@ -109,6 +110,7 @@ tmpConnection->fd = socketFD; tmpConnection->prev = connections; tmpConnection->next = connections->next; + tmpConnection->signedOn = time(NULL); sprintf(tmpConnection->host,host); if (connections->next != 0x0) connections->next->prev = tmpConnection; diff --git a/tuve.c b/tuve.c index 867659a..be1b94c 100644 --- a/tuve.c +++ b/tuve.c @@ -110,13 +110,15 @@ userConnection->userInfo.pfailed = 0x0; } else if (strcasecmp(cmd,"chanmsg") == 0x0) { - chan = strtok_r(data,":",&tok_last); - msg = strtok_r(NULL,"\n",&tok_last); - if (msg[0] == '.' && msg[1] == 't' && msg[2] == 'v') - tuveBotCMD(userConnection,chan,msg+3); - else - sprintf(output,"CHANMSG:%s:%s:%s\n",userConnection->userInfo.username,chan,msg); - tuveSendAllInChan(chan,userConnection,output); + if (data != 0x0) { + chan = strtok_r(data,":",&tok_last); + msg = strtok_r(NULL,"\n",&tok_last); + if (msg[0] == '.' && msg[1] == 't' && msg[2] == 'v') + tuveBotCMD(userConnection,chan,msg+3); + else + sprintf(output,"CHANMSG:%s:%s:%s\n",userConnection->userInfo.username,chan,msg); + tuveSendAllInChan(chan,userConnection,output); + } } else if (strcasecmp(cmd,"topic") == 0x0) { msg = strtok_r(data,":",&tok_last); @@ -177,6 +179,10 @@ sSendData(userConnection,"PART:Not In Chan\n"); } } + else if (strcasecmp(cmd,"WHOIS") == 0x0) { + if (data != 0x0) + tuveWhois(userConnection,data); + } else { sSendData(userConnection,"invalid command\n"); writeLog(1,"Invalid CMD: [%s]\n",cmd); diff --git a/tuved.h b/tuved.h index 2a9d134..2a11e21 100644 --- a/tuved.h +++ b/tuved.h @@ -65,6 +65,7 @@ char data[1024]; char host[128]; podz_t userInfo; + time_t signedOn; } myConnections_t; /* @@ -120,3 +121,4 @@ /* Nick Functions */ int tuveVerifyNick(char *nick); myConnections_t *findNick(char *); +int tuveWhois(myConnections_t *userConnection,char *nick);