diff --git a/Makefile b/Makefile index a212088..e684b22 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,7 @@ REMOVE = rm -f #Objects -OBJS = botthread.o main.o socket.o tuve.o channel.o +OBJS = nick.o botthread.o main.o socket.o tuve.o channel.o LIBRARIES = -lthr CFLAGS = -Wall -O2 diff --git a/botthread.c b/botthread.c index f3e4ac3..731a6a7 100644 --- a/botthread.c +++ b/botthread.c @@ -70,7 +70,7 @@ tmpChan = findChan(chan); if (tmpChan == 0x0) { - writeLog(0,"ERROR: tuveBotNoSogn tmpChan Failed\n"); + writeLog(0,"ERROR: tuveBotNoSong tmpChan Failed\n"); return(0x1); } diff --git a/channel.c b/channel.c index a37a455..f2c5950 100644 --- a/channel.c +++ b/channel.c @@ -52,7 +52,7 @@ /* Notify people in the channel that someone has joined */ - sprintf(output,"CHANMSG:TUveD:%s:%s has joined the channel.\n",channel,userConnection->userInfo.username); + sprintf(output,"CHANMSG:TUveD:%s:%s (%s) has joined the channel.\n",channel,userConnection->userInfo.username,userConnection->host); tuveSendAllInChan(channel,userConnection,output); return(0x0); @@ -204,8 +204,10 @@ tmpChannel->users = tmpUsers; } - tmpChannel->nextUser = tmpUsers; - tmpChannel->count = 0x0; + if (tmpChannel->nextUser == 0x0) { + tmpChannel->nextUser = tmpUsers; + tmpChannel->count = 0x0; + } memset(output,0x0,256); sprintf(output,"JOIN:%s:@TUveBOT",tmpChannel->channel); diff --git a/socket.c b/socket.c index 04bdd88..bef9b72 100644 --- a/socket.c +++ b/socket.c @@ -52,8 +52,7 @@ fcntl(listenerFD, F_SETFL, fcntl(listenerFD, F_GETFL, 0) | O_NONBLOCK); - highSock = listenerFD; - sAddConnection(listenerFD); + sAddConnection(listenerFD,"127.0.0.1"); writeLog(2,"Listener FD: [%i]\n",listenerFD); @@ -83,6 +82,7 @@ int newFD = 0x0; // New Socket; socklen_t sin_size; struct sockaddr_in remoteAddr; + struct hostent *hp; sin_size = sizeof(struct sockaddr_in); if ((newFD = accept(listenerFD, (struct sockaddr *)&remoteAddr, &sin_size)) == -1) { @@ -91,14 +91,14 @@ /* Add Socket */ - sAddConnection(newFD); - highSock = newFD; + hp = gethostbyaddr((char *)&remoteAddr.sin_addr,sizeof(remoteAddr.sin_addr),AF_INET); + sAddConnection(newFD,(hp ? hp->h_name : inet_ntoa(remoteAddr.sin_addr))); /* Return */ return(0x0); } -int sAddConnection(int socketFD) { +int sAddConnection(int socketFD,char *host) { myConnections_t *tmpConnection = 0x0; writeLog(2,"Adding Socket: [%i]\n",socketFD); @@ -109,6 +109,7 @@ connections->prev = 0x0; connections->next = 0x0; connections->fd = socketFD; + sprintf(connections->host,host); } else { tmpConnection = (myConnections_t *)malloc(sizeof(myConnections_t)); @@ -116,6 +117,7 @@ tmpConnection->fd = socketFD; tmpConnection->prev = connections; tmpConnection->next = connections->next; + sprintf(tmpConnection->host,host); if (connections->next != 0x0) connections->next->prev = tmpConnection; @@ -203,9 +205,13 @@ // FD_SET(listenerFD,readset); + highSock = 0; + if (connections != 0x0) { for (tmpConnection = connections;tmpConnection != 0x0;tmpConnection = tmpConnection->next) { FD_SET(tmpConnection->fd,readset); + if (tmpConnection->fd > highSock) + highSock = tmpConnection->fd; } retVal = 1; } diff --git a/tuve.c b/tuve.c index b922fb0..bf416c0 100644 --- a/tuve.c +++ b/tuve.c @@ -67,11 +67,20 @@ tok_last = 0x0; } - if (!strcasecmp(cmd,"ident")) { + if (!strcasecmp(cmd,"IDENT")) { writeLog(2,"(ident)\n"); - sprintf(userConnection->userInfo.username,data); //strtok_r(data,":",&tok_last)); - userConnection->userInfo.uid = time(NULL); //atoi(strtok_r(NULL,"\n",&tok_last)); - userConnection->userInfo.ident = 0x1; + if (data != 0x0) { + if (tuveVerifyNick(data) == 0) { + sprintf(userConnection->userInfo.username,data); //strtok_r(data,":",&tok_last)); + userConnection->userInfo.uid = time(NULL); //atoi(strtok_r(NULL,"\n",&tok_last)); + userConnection->userInfo.ident = 0x1; + } + else + sSendData(userConnection,"Nick In Use\n"); + } + else { + sSendData(userConnection,"Invalid Ident\n"); + } } else if (!strcasecmp(cmd,"JOIN")) { tuveChanJoin(data,userConnection); @@ -102,9 +111,18 @@ tuveSetTopic(userConnection,msg,strtok_r(NULL,"\n",&tok_last)); } else if (strcasecmp(cmd,"NICK") == 0x0) { - sprintf(output,"NICK:%s:%s\n",userConnection->userInfo.username,data); - sprintf(userConnection->userInfo.username,data); - tuveSendAllInUsersChans(userConnection,output); + if (data != 0x0) { + if (tuveVerifyNick(data) == 0x0) { + sprintf(output,"NICK:%s:%s\n",userConnection->userInfo.username,data); + sprintf(userConnection->userInfo.username,data); + tuveSendAllInUsersChans(userConnection,output); + } + else + sSendData(userConnection,"Nick In Use\n"); + } + else { + sSendData(userConnection,"Invalid Nick\n"); + } } else if (strcasecmp(cmd,"KICK") == 0x0) { tok_last = 0x0; diff --git a/tuved.h b/tuved.h index 6ed443b..de45f70 100644 --- a/tuved.h +++ b/tuved.h @@ -10,6 +10,7 @@ #include #include #include +#include #define NUM_THREADS 1 #define MYPORT 9999 // the port users will be connecting to @@ -62,12 +63,14 @@ int fd; int recLen; char data[1024]; + char host[128]; podz_t userInfo; } myConnections_t; /* Global variables very not safe */ + extern int listenerFD; extern int highSock; extern myConnections_t *connections; @@ -78,7 +81,7 @@ ssize_t sReadSocket(int socketFD,void *buffer,size_t length); myConnections_t *sFindConnection(int fd); int sStartListener(); -int sAddConnection(int); +int sAddConnection(int,char *host); int sGetConnections(fd_set *); int sProcessConnections(fd_set *); int sSendPing(time_t); @@ -111,3 +114,6 @@ int tuveBotCMD(char *chan,char *data); int tuveBotSetSong(char *chan,char *playTime,char *file,char *title); int tuveBotNoSong(char *chan); + +/* Nick Functions */ +int tuveVerifyNick(char *nick);