diff --git a/botthread.c b/botthread.c index cebf136..c7e4130 100644 --- a/botthread.c +++ b/botthread.c @@ -38,10 +38,10 @@ sprintf(output,"SELECT username,gid,uid FROM users WHERE username = '%s' AND password = '%s'",tmp,tmp2); res = dbQuery(output,1); if (res == 0x0) { - sSendData(userConnection,"MSG:TUveD:STATUS:Sorry I'm Having MySQL Troubles.\n"); + sSendData(userConnection,"MSG:TUveD:STATUS:Sorry I'm Having MySQL Troubles."); } else if (mysql_num_rows(res) == 1) { - sSendData(userConnection,"MSG:TUveD:%s:You have successfully logged in.\n",chan); + sSendData(userConnection,"MSG:TUveD:%s:You have successfully logged in.",chan); row = mysql_fetch_row(res); sprintf(output,"INSERT INTO active (gid,uid,userid) VALUES(%s,%s,%lld)",row[1],row[2],userConnection->userInfo.uid); dbQuery(output,0); @@ -52,14 +52,14 @@ } } else { - sSendData(userConnection,"MSG:TUveD:%s:You have failed login.\n",chan); + sSendData(userConnection,"MSG:TUveD:%s:You have failed login.",chan); //tuveDelUserChans(userConnection,"This Mother Fucker Tried To Login With The Wrong Password!"); //userConnection->userInfo.status = -1; } } } /* End login */ else if (tuveFindChanLevel(chan,userConnection,0) == 0) { - sSendData(userConnection,"MSG:TUveD:STATUS:You do not have permission to set channel mode\n"); + sSendData(userConnection,"MSG:TUveD:STATUS:You do not have permission to set channel mode."); return(0x0); } /* Commands Stop Here If You Channel Level Isn't >= 1 */ else if (strcasecmp(cmd,"pause") == 0x0) { @@ -90,7 +90,7 @@ else if (modeString[0] == '+') dM = 1; else { - sSendData(userConnection,"MSG:TUveD:STATUS:Invalid Mode String\n"); + sSendData(userConnection,"MSG:TUveD:STATUS:Invalid Mode String."); return(0x0); } @@ -113,7 +113,7 @@ } } else { - sSendData(userConnection,"MSG:TUveD:STATUS:Missing +O Opperators\n"); + sSendData(userConnection,"MSG:TUveD:STATUS:Missing +O Opperators"); } break; case 'a': @@ -180,7 +180,7 @@ } break; default: - sSendData(userConnection,"MSG:TUveD:STATUS:Invalid Channel Mode\n"); + sSendData(userConnection,"MSG:TUveD:STATUS:Invalid Channel Mode"); break; } } @@ -360,7 +360,7 @@ else { gotUser: if (tmpChans->nextUser->user->userInfo.queue == 0x1) { - sSendData(tmpChans->nextUser->user,"GETVIDEO\n"); + sSendData(tmpChans->nextUser->user,"GETVIDEO"); writeLog(0,"Need To Find Next Song For: %s, From User: %s\n",tmpChans->channel,tmpChans->nextUser->user->userInfo.username); tmpChans->count++; } diff --git a/channel.c b/channel.c index 891e027..8179155 100644 --- a/channel.c +++ b/channel.c @@ -30,10 +30,10 @@ tuveChanList_t *tmpChan = 0x0; /* The first line is header information for the data set */ - sSendData(userConnection,"LIST:Channel:users:Topic\n"); + sSendData(userConnection,"LIST:Channel:users:Topic"); for (tmpChan = channels;tmpChan != 0x0;tmpChan = tmpChan->next) { - sprintf(data,"LIST:%s:%i:%s:%s\n",tmpChan->channel,tmpChan->userCount,tmpChan->topic,tmpChan->videoTitle); + sprintf(data,"LIST:%s:%i:%s:%s",tmpChan->channel,tmpChan->userCount,tmpChan->topic,tmpChan->videoTitle); sSendData(userConnection,data); } @@ -115,7 +115,7 @@ if (tmpChan != 0x0) { for (i = 0x0;i < CHAN_MAX_BANS;i++) { if (tmpChan->bans[i][0] == userConnection->userInfo.uid) { - sprintf(output,"MSG:TUveD:%s:You are banned from %s\n",channel,channel); + sprintf(output,"MSG:TUveD:%s:You are banned from %s",channel,channel); sSendData(userConnection,output); return(0x1); } @@ -132,15 +132,15 @@ assert(tmpChan); if (tmpChan->modes[CHAN_LIVE] == 1) { - sSendData(userConnection,"CURPOS:%s:-1:%s:Live Stream:0:0\n",tmpChan->channel,tmpChan->liveStream); + sSendData(userConnection,"CURPOS:%s:-1:%s:Live Stream:0:0",tmpChan->channel,tmpChan->liveStream); } else { - sSendData(userConnection,"CURPOS:%s:%i:%s:%s:%i:%i\n",tmpChan->channel,tmpChan->videoTime - (tmpChan->videoEnd - (time(NULL) + VIDE_PAD_TIME)),tmpChan->videoFile,tmpChan->videoTitle,tmpChan->videoTime,tmpChan->vid); + sSendData(userConnection,"CURPOS:%s:%i:%s:%s:%i:%i",tmpChan->channel,tmpChan->videoTime - (tmpChan->videoEnd - (time(NULL) + VIDE_PAD_TIME)),tmpChan->videoFile,tmpChan->videoTitle,tmpChan->videoTime,tmpChan->vid); min = tmpChan->videoTime / 60; sec = tmpChan->videoTime % 60; - sSendData(userConnection,"MSG:TUveD:%s:Playing %s (%i:%.2i)\n",channel,tmpChan->videoChanTitle,min,sec); + sSendData(userConnection,"MSG:TUveD:%s:Playing %s (%i:%.2i)",channel,tmpChan->videoChanTitle,min,sec); } /* Notify people in the channel that someone has joined */ @@ -279,6 +279,8 @@ char output[1024]; char nick[MAX_USER_LEN + 1]; + + int len = 0; tmpChannel = findChan(channel); @@ -338,45 +340,46 @@ } if (strlen(output) > 0) { - sprintf(output,"%s\n",output); + sprintf(output,"%s",output); sSendData(userConnection,output); } - sprintf(output,"TOPIC:%s:%s\n",tmpChannel->channel,tmpChannel->topic); + sprintf(output,"TOPIC:%s:%s",tmpChannel->channel,tmpChannel->topic); sSendData(userConnection,output); - sprintf(output,"MSG:TUveD:%s:Topic for %s: %s\n",tmpChannel->channel,tmpChannel->channel,tmpChannel->topic); + sprintf(output,"MSG:TUveD:%s:Topic for %s: %s",tmpChannel->channel,tmpChannel->channel,tmpChannel->topic); sSendData(userConnection,output); - sprintf(output,"MSG:TUveD:%s:Topic was set by %s on %s.\n",tmpChannel->channel,tmpChannel->topicSetBy, ctime(&tmpChannel->topicSet)); + len = sprintf(output,"MSG:TUveD:%s:Topic was set by %s on %s",tmpChannel->channel,tmpChannel->topicSetBy, ctime(&tmpChannel->topicSet)); + output[len-1] = '\0'; sSendData(userConnection,output); if (tmpChannel->modes[CHAN_TIME] == 1) { - sprintf(output,"MSG:TUveD:%s:This channel has a time limit of %i seconds for songs.\n",tmpChannel->channel,tmpChannel->maxTime); + sprintf(output,"MSG:TUveD:%s:This channel has a time limit of %i seconds for songs.",tmpChannel->channel,tmpChannel->maxTime); sSendData(userConnection,output); - sprintf(output,"MODE:%s:T:1:%i\n",tmpChannel->channel,tmpChannel->maxTime); + sprintf(output,"MODE:%s:T:1:%i",tmpChannel->channel,tmpChannel->maxTime); sSendData(userConnection,output); } else { - sprintf(output,"MODE:%s:T:0\n",tmpChannel->channel); + sprintf(output,"MODE:%s:T:0",tmpChannel->channel); sSendData(userConnection,output); } if (tmpChannel->modes[CHAN_QUEUE] == 1) - sprintf(output,"MODE:%s:Q:1\n",tmpChannel->channel); + sprintf(output,"MODE:%s:Q:1",tmpChannel->channel); else - sprintf(output,"MODE:%s:Q:0\n",tmpChannel->channel); + sprintf(output,"MODE:%s:Q:0",tmpChannel->channel); sSendData(userConnection,output); if (tmpChannel->modes[CHAN_RANDOM] == 1) - sprintf(output,"MODE:%s:R:1\n",tmpChannel->channel); + sprintf(output,"MODE:%s:R:1",tmpChannel->channel); else - sprintf(output,"MODE:%s:R:0\n",tmpChannel->channel); + sprintf(output,"MODE:%s:R:0",tmpChannel->channel); sSendData(userConnection,output); - sprintf(output,"MODE:%s:A:%i\n",tmpChannel->channel,tmpChannel->modes[CHAN_RATING]); + sprintf(output,"MODE:%s:A:%i",tmpChannel->channel,tmpChannel->modes[CHAN_RATING]); sSendData(userConnection,output); - sprintf(output,"MODE:%s:C:%i\n",tmpChannel->channel,tmpChannel->modes[CHAN_CLASS]); + sprintf(output,"MODE:%s:C:%i",tmpChannel->channel,tmpChannel->modes[CHAN_CLASS]); sSendData(userConnection,output); @@ -472,6 +475,7 @@ tuveUserList_t *tmpUsers = 0x0; char data[2048]; va_list ap; + int len = 0; tmpChannel = findChan(channel); @@ -486,8 +490,10 @@ tmpUsers = tmpChannel->users; va_start(ap,fmt); - vsnprintf(data,2048,fmt,ap); + len = vsnprintf(data,2046,fmt,ap); va_end(ap); + data[len++] = '\r'; + data[len++] = '\n'; //THIS IS A TEMP SOLUTION I HATE IT! @@ -539,12 +545,11 @@ userConnection = findNickOnChan(nick,chan); if (userConnection == 0x0) { - sSendData(byConnection,"MSG:TUveD:STATUS:%s Not On %s\n",nick,chan); + sSendData(byConnection,"MSG:TUveD:STATUS:%s Not On %s",nick,chan); return(0x1); } - sprintf(output,"KICK:%s:%s:%s\n",chan,byConnection->userInfo.username,msg); - sSendData(userConnection,output); + sSendData(userConnection,"KICK:%s:%s:%s",chan,byConnection->userInfo.username,msg); nick = userConnection->userInfo.username; @@ -582,7 +587,7 @@ } if (tuveFindChanLevel(channel,byConnection,0) < 1) { - sSendData(byConnection,"MSG:TUveD:STATUS:You do not have permission to ban.\n"); + sSendData(byConnection,"MSG:TUveD:STATUS:You do not have permission to ban."); return(0x0); } @@ -593,7 +598,7 @@ return(0x1); } - sSendData(userConnection,"BAN\n"); + sSendData(userConnection,"BAN"); for (i = 0x0;i < CHAN_MAX_BANS;i++) { if (tmpChannel->bans[i][0] == 0x0) { diff --git a/nick.c b/nick.c index 6913ad3..6f1bfd3 100644 --- a/nick.c +++ b/nick.c @@ -52,21 +52,21 @@ user = findNick(nick); if (user == 0x0) { - sprintf(output,"MSG:TUveD:STATUS:%s Not Found\n",nick); + sprintf(output,"MSG:TUveD:STATUS:%s Not Found",nick); sSendData(userConnection,output); return(0x0); } - sprintf(output,"MSG:TUveD:STATUS:%s is %s\n",user->userInfo.username,user->host); + sprintf(output,"MSG:TUveD:STATUS:%s is %s",user->userInfo.username,user->host); sSendData(userConnection,output); sprintf(output,"MSG:TUveD:STATUS:%s Signed On %s",user->userInfo.username,ctime(&user->signedOn)); sSendData(userConnection,output); if (user->userInfo.modes[USER_OVERLORD] == 1) { - sprintf(output,"MSG:TUveD:STATUS:%s Is an Evil Overlord\n",user->userInfo.username); + sprintf(output,"MSG:TUveD:STATUS:%s Is an Evil Overlord",user->userInfo.username); sSendData(userConnection,output); } if ((time(NULL) - user->userInfo.idle) > 30) { - sprintf(output,"MSG:TUveD:STATUS:%s Has been idle for %i seconds.\n",user->userInfo.username,time(NULL) - user->userInfo.idle); + sprintf(output,"MSG:TUveD:STATUS:%s Has been idle for %i seconds.",user->userInfo.username,time(NULL) - user->userInfo.idle); sSendData(userConnection,output); } @@ -84,7 +84,6 @@ else sprintf(output,"%s,%s",output,channel); } - sprintf(output,"%s\n",output); sSendData(userConnection,output); } diff --git a/server.c b/server.c index 06b386c..6a49e76 100644 --- a/server.c +++ b/server.c @@ -11,7 +11,7 @@ curTime = time(NULL); - sprintf(output,"MSG:TUveD:STATUS:Server on-line since: %s\n",ctime(&startTime)); + sprintf(output,"MSG:TUveD:STATUS:Server on-line since: %s",ctime(&startTime)); sSendData(userConnection,output); curTime -= startTime; day = curTime / 86400; @@ -21,13 +21,13 @@ min = curTime / 60; curTime -= (60 * min); sec = curTime; - sprintf(output,"MSG:TUveD:STATUS:Server is running TUveD %s\n",VERSION); + sprintf(output,"MSG:TUveD:STATUS:Server is running TUveD %s",VERSION); sSendData(userConnection,output); - sprintf(output,"MSG:TUveD:STATUS:Server has been running for %i days %i hours %i min %.2i sec\n",day,hour,min,sec); + sprintf(output,"MSG:TUveD:STATUS:Server has been running for %i days %i hours %i min %.2i sec",day,hour,min,sec); sSendData(userConnection,output); - sprintf(output,"MSG:TUveD:STATUS:There are currently %i users online.\n",userCount); + sprintf(output,"MSG:TUveD:STATUS:There are currently %i users online.",userCount); sSendData(userConnection,output); - sprintf(output,"MSG:TUveD:STATUS:There are currently %i channels active.\n",channelCount); + sprintf(output,"MSG:TUveD:STATUS:There are currently %i channels active.",channelCount); sSendData(userConnection,output); curTime = playCount; day = curTime / 86400; @@ -37,7 +37,7 @@ min = curTime / 60; curTime -= (60 * min); sec = curTime; - sprintf(output,"MSG:TUveD:STATUS:There have been %i videos played. For a total Playtime of %i days %i hours %i min %.2i sec\n",songCount,day,hour,min,sec); + sprintf(output,"MSG:TUveD:STATUS:There have been %i videos played. For a total Playtime of %i days %i hours %i min %.2i secs",songCount,day,hour,min,sec); sSendData(userConnection,output); return(0x0); diff --git a/socket.c b/socket.c index 82a184b..daf2d02 100644 --- a/socket.c +++ b/socket.c @@ -239,18 +239,21 @@ ************************************/ int sSendPing(time_t ping) { myConnections_t *tmpConnection = 0x0; + char sPing[32]; for (tmpConnection = connections->next;tmpConnection != 0x0;tmpConnection = tmpConnection->next) { if (tmpConnection->userInfo.pfailed < MAX_PING) { if (tmpConnection->userInfo.pong < ping) { tmpConnection->userInfo.pfailed++; tmpConnection->userInfo.pong = ping; - if (tmpConnection->userInfo.ident == 0x1) - send(tmpConnection->fd,"PING\n",sizeof("PING\n"),MSG_NOSIGNAL); + if (tmpConnection->userInfo.ident == 0x1) { + sprintf(sPing,"PING %i\r\n", time(NULL)); + send(tmpConnection->fd,sPing,strlen(sPing),MSG_NOSIGNAL); + } } } else { - send(tmpConnection->fd,"TIMEOUT\n",sizeof("TIMEOUT\n"),MSG_NOSIGNAL); + send(tmpConnection->fd,"TIMEOUT\r\n",sizeof("TIMEOUT\r\n"),MSG_NOSIGNAL); tuveDelUserChans(tmpConnection,"TIMEOUT"); tmpConnection->userInfo.status = -1; } @@ -260,6 +263,7 @@ } /* End sSendPing() */ int sSendData(myConnections_t *con,char const * __restrict fmt, ...) { + int len = 0; char data[2048]; va_list ap; @@ -273,10 +277,14 @@ } va_start(ap,fmt); - vsnprintf(data,2048,fmt,ap); + len = vsnprintf(data,2046,fmt,ap); va_end(ap); - send(con->fd,data,strlen(data),MSG_NOSIGNAL); + data[len++] = '\r'; + data[len++] = '\n'; + + + send(con->fd,data,len,MSG_NOSIGNAL); return(0x0); } diff --git a/tuve.c b/tuve.c index 13cdfec..dc9a972 100644 --- a/tuve.c +++ b/tuve.c @@ -87,13 +87,13 @@ userConnection->userInfo.uid = atoll(msg); userConnection->userInfo.ident = 0x1; - sSendData(userConnection,"IDENT:0:Success\n"); + sSendData(userConnection,"IDENT:0:Success"); } else - sSendData(userConnection,"IDENT:1:Nick In Use.\n"); + sSendData(userConnection,"IDENT:1:Nick In Use."); } else { - sSendData(userConnection,"IDENT:1:Invalid Ident.\n"); + sSendData(userConnection,"IDENT:1:Invalid Ident."); } return(0x0); } @@ -123,10 +123,10 @@ else if (!strcasecmp(cmd,"JOIN")) { /* Function Checked Tested And Approved */ if (data == 0x0) { - sSendData(userConnection,"JOIN:ERROR:Invalid Channel Information\n"); + sSendData(userConnection,"JOIN:ERROR:Invalid Channel Information"); } else if (!strstr(data,"#") || strlen(data) > MAX_CHAN_LEN) - sSendData(userConnection,"JOIN:ERROR:Invalid channel.\n"); + sSendData(userConnection,"JOIN:ERROR:Invalid channel."); else tuveChanJoin(data,userConnection); } @@ -150,12 +150,12 @@ output[strlen(output)+1] = '\n'; */ //%s\n",userConnection->userInfo.username,msg); - sSendData(tmpConnection,"MSG:%s:PRIVMSG:%s\n",userConnection->userInfo.username,msg); + sSendData(tmpConnection,"MSG:%s:PRIVMSG:%s",userConnection->userInfo.username,msg); } } } else if (tuveVerifyBan(chan,userConnection->userInfo.username) == 0x1) { - sprintf(output,"MSG:TUveD:%s:You can not send text to the channel.\n",chan); + sprintf(output,"MSG:TUveD:%s:You can not send text to the channel.",chan); sSendData(userConnection,output); } else if (msg != 0x0) { @@ -174,12 +174,12 @@ chan = strtok_r(data,":",&tok_last); msg = strtok_r(NULL,"\n",&tok_last); if (tuveVerifyBan(chan,userConnection->userInfo.username) == 0x1) { - sprintf(output,"MSG:TUveD:%s:You can not send text to the channel.\n",chan); + sprintf(output,"MSG:TUveD:%s:You can not send text to the channel.",chan); sSendData(userConnection,output); } else if (msg != 0x0) { strncpy(buffer,msg,1024); - sprintf(output,"EMOTE:%s:%s:%s\n",userConnection->userInfo.username,chan,buffer); + sprintf(output,"EMOTE:%s:%s:%s",userConnection->userInfo.username,chan,buffer); tuveSendAllInChan(chan,userConnection,output); } } @@ -191,7 +191,7 @@ msg = strtok_r(NULL,"\n",&tok_last); if (tuveVerifyBan(chan,userConnection->userInfo.username) == 0x1) { - sSendData(userConnection,"MSG:TUveD:STATUS:You can not set topic to this channel.\n"); + sSendData(userConnection,"MSG:TUveD:STATUS:You can not set topic to this channel."); } else { tuveSetTopic(userConnection,chan,msg); @@ -201,7 +201,7 @@ else if (strcasecmp(cmd,"NICK") == 0x0) { if (data != 0x0) { if (tuveVerifyNick(data) == 0x0) { - sprintf(output,"NICK:%s:%s\n",userConnection->userInfo.username,data); + sprintf(output,"NICK:%s:%s",userConnection->userInfo.username,data); sSendData(userConnection,output); tuveSendAllInUsersChans(userConnection,output); sprintf(output,"MSG:TUveD:STATUS:%s is now know as %s\n",userConnection->userInfo.username,data); @@ -209,21 +209,21 @@ sprintf(userConnection->userInfo.username,data); } else - sSendData(userConnection,"MSG:TUveD:STATUS:Nick In Use\n"); + sSendData(userConnection,"MSG:TUveD:STATUS:Nick In Use"); } else { - sSendData(userConnection,"MSG:TUveD:STATUS:Invalid Nick\n"); + sSendData(userConnection,"MSG:TUveD:STATUS:Invalid Nick"); } } else if (strcasecmp(cmd,"KICK") == 0x0) { tok_last = 0x0; if (userConnection->userInfo.modes[USER_OVERLORD] != 1) { - sSendData(userConnection,"MSG:TUveD:KICK:You do not have permission to kick!\n"); + sSendData(userConnection,"MSG:TUveD:KICK:You do not have permission to kick!"); } else { if (data == 0x0) - sSendData(userConnection,"KICK:Invalid Information\n"); + sSendData(userConnection,"KICK:Invalid Information"); else { chan = strtok_r(data,":",&tok_last); nick = strtok_r(NULL,":",&tok_last); @@ -234,7 +234,7 @@ else tuveKick(userConnection,chan,nick,"I'm Too Lame To Give A Good Reason!"); else - sSendData(userConnection,"KICK:Invalid Information.\n"); + sSendData(userConnection,"KICK:Invalid Information."); } } @@ -245,22 +245,22 @@ chan = strtok_r(data,":",&tok_last); msg = strtok_r(NULL,"\n",&tok_last); if (msg == 0x0) - sSendData(userConnection,"MSG:TuveD:STATUS:Missing VID\n"); + sSendData(userConnection,"MSG:TuveD:STATUS:Missing VID"); else tuveBotSetVideo(chan,userConnection->userInfo.username,atoi(msg)); } else - sSendData(userConnection,"MSG:TUveD:STATUS:Invalid VIDEO syntax.\n"); + sSendData(userConnection,"MSG:TUveD:STATUS:Invalid VIDEO syntax."); } else if (strcasecmp(cmd,"PART") == 0x0) { if (data != 0x0) { if (tuveChanPart(data,userConnection) == 0x1) { writeLog(0,"ERROR: Unable to remove user from channel: %s list\n",data); - sSendData(userConnection,"PART:Not In Chan\n"); + sSendData(userConnection,"PART:Not In Chan"); } } else - sSendData(userConnection,"PART:Not In Chan\n"); + sSendData(userConnection,"PART:Not In Chan"); } else if (strcasecmp(cmd,"WHOIS") == 0x0) { if (data != 0x0) @@ -283,7 +283,7 @@ } else if (strcasecmp(cmd,"UNBAN") == 0x0) { if (userConnection->userInfo.modes[USER_OVERLORD] != 1) { - sSendData(userConnection,"MSG:TUveD:STATUS:You do not have permission to unban.\n"); + sSendData(userConnection,"MSG:TUveD:STATUS:You do not have permission to unban."); } else if (data != 0x0) { tok_last = 0x0; @@ -307,16 +307,16 @@ msg = strtok_r(NULL,"\n",&tok_last); if (msg[0] == '0') { if (tuveChanResume(chan) == 0x1) - sSendData(userConnection,"MSG:TUveD:STATUS:Sorry Invalid Live Parameters\n"); + sSendData(userConnection,"MSG:TUveD:STATUS:Sorry Invalid Live Parameters"); } else { if (tuveChanLive(chan,msg) == 0x1) - sSendData(userConnection,"MSG:TUveD:STATUS:Sorry Invalid Live Parameters.\n"); + sSendData(userConnection,"MSG:TUveD:STATUS:Sorry Invalid Live Parameters."); } } } else { - sSendData(userConnection,"invalid command\n"); + sSendData(userConnection,"invalid command"); writeLog(1,"Invalid CMD: [%s]\n",cmd); }