diff --git a/botthread.c b/botthread.c index 1309f3c..4d4285e 100644 --- a/botthread.c +++ b/botthread.c @@ -2,11 +2,42 @@ #include "tuved.h" +char nextSong[256]; + +int tuveBotCMD(char *chan,char *data) { + char output[512]; + char *cmd = 0x0; + char *cmdData = 0x0; + + cmd = strtok(data," "); + cmdData = strtok(NULL,"\n"); + + if (strcasecmp(cmd,"setvid") == 0x0) { + sprintf(output,"CURPOS:1:%s\n",cmdData); + tuveSendAllInChan(chan,0x0,output); + } + else if (strcasecmp(cmd,"echo") == 0x0) { + sprintf(output,"CHANMSG:TUveBOT:%s:%s\n",chan,cmdData); + tuveSendAllInChan(chan,0x0,output); + } + + return(0x0); + } + void *tuveBotThread(void *threadid) { int tid; + char output[512]; tid = (int)threadid; writeLog(0,"Starting Bot Thread: [%d]\n", tid); + while (1) { + sleep(90); + if (strlen(nextSong) > 0) { + sprintf(output,"CURPOS:1:%s\n",nextSong); + tuveSendAllInChan("#general",0x0,output); + } + //tuveSendAllInChan("#general",0x0,"CHANMSG:TUveBOT:#general:TCA will touch my silly spot?\n"); + } pthread_exit(NULL); } diff --git a/channel.c b/channel.c index fbccf90..bc29323 100644 --- a/channel.c +++ b/channel.c @@ -6,8 +6,6 @@ #include #include #include -#include -#include #include "tuved.h" @@ -123,7 +121,7 @@ tuveChanList_t *tmpChannel = 0x0; tuveUserList_t *tmpUsers = 0x0; - char output[256]; + char output[1024]; tmpChannel = findChan(channel); if (tmpChannel == 0x0) { @@ -154,6 +152,7 @@ } memset(output,0x0,256); + sprintf(output,"JOIN:%s:TUveBOT",tmpChannel->channel); /* Send the new user the channel list */ for (tmpUsers = tmpChannel->users->next;tmpUsers != 0x0;tmpUsers = tmpUsers->next) { diff --git a/main.c b/main.c index 29d52ec..5622653 100644 --- a/main.c +++ b/main.c @@ -5,10 +5,8 @@ */ #include -#include #include #include -#include #include #include "tuved.h" @@ -23,7 +21,8 @@ int ch; int readSocks = 0x0; int doFork = 0x1; - int rc, t; + int rc = 0x0; + int t = 0x0; time_t seconds; struct timeval timeout = {30,0}; diff --git a/socket.c b/socket.c index facc43a..24f5361 100644 --- a/socket.c +++ b/socket.c @@ -11,9 +11,6 @@ #include #include #include -#include -#include -#include #include #include "tuved.h" diff --git a/tuve.c b/tuve.c index 5d27475..038264b 100644 --- a/tuve.c +++ b/tuve.c @@ -5,8 +5,6 @@ #include #include #include -#include -#include #include #include "tuved.h" @@ -82,7 +80,7 @@ userConnection->userInfo.uid = time(NULL); //atoi(strtok_r(NULL,"\n",&tok_last)); userConnection->userInfo.ident = 0x1; } - else if (!strcasecmp(cmd,"join")) { + else if (!strcasecmp(cmd,"JOIN")) { tuveChanJoin(data,userConnection); } else if (strcasecmp(cmd,"") == 0x0) { @@ -98,9 +96,13 @@ userConnection->userInfo.pfailed = 0x0; } else if (strcasecmp(cmd,"chanmsg") == 0x0) { - msg = strtok_r(data,":",&tok_last); - sprintf(output,"CHANMSG:%s:%s:%s\n",userConnection->userInfo.username,msg,strtok_r(NULL,"\n",&tok_last)); - tuveSendAllInChan(msg,userConnection,output); + chan = strtok_r(data,":",&tok_last); + msg = strtok_r(NULL,"\n",&tok_last); + if (msg[0] == '.' && msg[1] == 't' && msg[2] == 'v') + tuveBotCMD(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); @@ -130,7 +132,7 @@ msg = strtok_r(NULL,":",&tok_last); nick = strtok_r(NULL,"\n",&tok_last); if ((nick != 0x0) && (msg != 0x0)) { - sprintf(output,"CURPOS:%s:%s:%s\n",chan,msg,nick); + sprintf(output,"CURPOS:%s:%s\n",msg,nick); tuveSendAllInChan(chan,userConnection,output); writeLog(1,"%s Has Sent CURPOS\n",userConnection->userInfo.username); } diff --git a/tuved.h b/tuved.h index 0d698dc..2c1d2f2 100644 --- a/tuved.h +++ b/tuved.h @@ -5,7 +5,10 @@ */ #include +#include +#include #include +#include #define NUM_THREADS 1 #define MYPORT 9999 // the port users will be connecting to @@ -89,3 +92,7 @@ int tuveRemoveFromChanList(char *channel,myConnections_t *userConnection); int tuveSetTopic(myConnections_t *userConnection,char *chan,char *topic); int tuveSendAllInUsersChans(myConnections_t *userConnection,char *output); + +/* Bot Functions */ +void *tuveBotThread(void *threadid); +int tuveBotCMD(char *chan,char *data);