diff --git a/Makefile b/Makefile
index f03ef5e..c8818bf 100644
--- a/Makefile
+++ b/Makefile
@@ -18,7 +18,7 @@
OBJS = main.o socket.o tuve.o channel.o
LIBRARIES =
-CFLAGS = -Wall -O -ggdb
+CFLAGS = -Wall -O2
# Link The Binary
$(BINARY) : $(OBJS)
diff --git a/channel.c b/channel.c
index fd9381d..d2125b6 100644
--- a/channel.c
+++ b/channel.c
@@ -25,6 +25,10 @@
/* Send JOIN to all users in the channel */
sprintf(output,"JOIN:%s:%s\n",channel,userConnection->userInfo.username);
tuveSendAllInChan(channel,userConnection,output);
+
+ sprintf(output,"SEEK:67\n");
+ send(userConnection->fd,output,strlen(output),MSG_NOSIGNAL);
+
/* Notify people in the channel that someone has joined */
sprintf(output,"CHANMSG:TUveD:%s:%s has joined the channel.\n",channel,userConnection->userInfo.username);
@@ -87,13 +91,13 @@
tmpChannel = findChan(channel);
if (tmpChannel == 0x0) {
- writeLog("findChan failed!\n");
+ writeLog(1,"findChan failed!\n");
return(0x1);
}
tmpUsers = tmpChannel->users;
- writeLog("Freeing User From Chan: %s\n",channel);
+ writeLog(2,"Freeing User From Chan: %s\n",channel);
for (;tmpUsers != 0x0;tmpUsers = tmpUsers->next) {
if (!strcasecmp(tmpUsers->user->userInfo.username,userConnection->userInfo.username)) {
@@ -123,13 +127,13 @@
tmpChannel = findChan(channel);
if (tmpChannel == 0x0) {
- writeLog("Channel %s Does Not Exist Adding To List\n",channel);
+ writeLog(2,"Channel %s Does Not Exist Adding To List\n",channel);
tmpChannel = addChan(channel);
}
for (tmpUsers = tmpChannel->users;tmpUsers != 0x0;tmpUsers = tmpUsers->next) {
if (!strcasecmp(tmpUsers->user->userInfo.username,userConnection->userInfo.username)) {
- writeLog("User: %s already in channel %s\n",userConnection->userInfo.username,channel);
+ writeLog(2,"User: %s already in channel %s\n",userConnection->userInfo.username,channel);
return(0x0);
}
}
@@ -167,7 +171,7 @@
sprintf(output,"TOPIC:%s:%s\n",tmpChannel->channel,tmpChannel->topic);
send(userConnection->fd,output,strlen(output),MSG_NOSIGNAL);
- writeLog("Added user: %s to Channel: %s\n",userConnection->userInfo.username,channel);
+ writeLog(2,"Added user: %s to Channel: %s\n",userConnection->userInfo.username,channel);
return(0x0);
}
@@ -195,7 +199,7 @@
channels->users = 0x0;
sprintf(channels->channel,channel);
sprintf(channels->topic,"No Topic Set");
- writeLog("ADDED CHAN1\n");
+ writeLog(2,"ADDED CHAN1\n");
tmpChannel = channels;
}
else {
@@ -207,11 +211,20 @@
tmpChannel->users = 0x0;
channels->prev = tmpChannel;
channels = tmpChannel;
- writeLog("ADDED CHAN2\n");
+ writeLog(2,"ADDED CHAN2\n");
}
return(tmpChannel);
}
+int tuveSendAllInUsersChans(myConnections_t *userConnection,char *output) {
+ tuveUserChans_t *tmpChans = userConnection->userInfo.chans;
+
+ for (;tmpChans != 0x0;tmpChans = tmpChans->next) {
+ tuveSendAllInChan(tmpChans->channel,0x0,output);
+ }
+ return(0x0);
+ }
+
int tuveSendAllInChan(char *channel,myConnections_t *userConnection,char *output) {
tuveChanList_t *tmpChannel = 0x0;
tuveUserList_t *tmpUsers = 0x0;
@@ -219,7 +232,7 @@
tmpChannel = findChan(channel);
if (tmpChannel == 0x0) {
- writeLog("findChan Failed!\n");
+ writeLog(1,"findChan Failed!\n");
return(0x1);
}
@@ -243,7 +256,7 @@
tmpChannel = findChan(chan);
if (tmpChannel == 0x0) {
- writeLog("findChan Failed: SetTopic\n");
+ writeLog(1,"findChan Failed: SetTopic\n");
return(0x1);
}
diff --git a/main.c b/main.c
index 0ba3285..7febdb8 100644
--- a/main.c
+++ b/main.c
@@ -14,6 +14,7 @@
#include "tuved.h"
FILE *logFile = 0x0;
+int logLevel = 1;
void usage();
@@ -28,7 +29,7 @@
/* Get our start time */
seconds = time(NULL);
- while ((ch = getopt(argc,argv,"sl:n")) != -1) {
+ while ((ch = getopt(argc,argv,"sl:nd:")) != -1) {
switch (ch) {
case 's':
logFile = stdout;
@@ -39,6 +40,11 @@
case 'n':
doFork = 0;
break;
+ case 'd':
+ logLevel = atoi(optarg);
+ if (logLevel < 1)
+ logLevel = 1;
+ break;
default:
usage();
}
@@ -56,7 +62,7 @@
if (fork() != 0x0)
exit(1);
- writeLog("Podz Daemon Starting: %i\n",seconds);
+ writeLog(0,"Podz Daemon Starting: %i\n",seconds);
sStartListener();
@@ -65,9 +71,7 @@
readSocks = select(highSock+1,&readset,0x0,0x0,&timeout);
- #ifdef DEBUG
- writeLog("readSocks: [%i]\n",readSocks);
- #endif
+ writeLog(3,"readSocks: [%i]\n",readSocks);
if (readSocks < 0) {
perror("select failed");
@@ -93,15 +97,18 @@
}
void usage() {
- printf("%s\n","usage: podzd -n [-l logfile]");
+ printf("%s\n","usage: podzd -n -s [-l logfile] [-d debuglevel]");
exit(1);
}
-int writeLog(char const * __restrict fmt, ...) {
+int writeLog(int level,char const * __restrict fmt, ...) {
int ret;
va_list ap;
+ if (level > logLevel)
+ return(0x0);
+
va_start(ap, fmt);
ret = vfprintf(logFile, fmt, ap);
va_end(ap);
diff --git a/podzd.log b/podzd.log
deleted file mode 100644
index ce1cdac..0000000
--- a/podzd.log
+++ /dev/null
@@ -1,4 +0,0 @@
-Podz Daemon Starting: 1191341432
-Adding Socket: [4]
-Socket Added
-Listener FD: [4]
diff --git a/socket.c b/socket.c
index bbee55f..d9ea717 100644
--- a/socket.c
+++ b/socket.c
@@ -58,7 +58,7 @@
highSock = listenerFD;
sAddConnection(listenerFD);
- writeLog("Listener FD: [%i]\n",listenerFD);
+ writeLog(2,"Listener FD: [%i]\n",listenerFD);
return(0x0);
}
@@ -104,7 +104,7 @@
int sAddConnection(int socketFD) {
myConnections_t *tmpConnection = 0x0;
- writeLog("Adding Socket: [%i]\n",socketFD);
+ writeLog(2,"Adding Socket: [%i]\n",socketFD);
if (connections == 0x0) {
connections = (myConnections_t *)malloc(sizeof(myConnections_t));
@@ -124,7 +124,7 @@
connections->next = tmpConnection;
}
- writeLog("Socket Added\n");
+ writeLog(2,"Socket Added\n");
return(0x0);
}
@@ -152,7 +152,7 @@
// Hard close the socket so it doesn't linger
close(tmpConnection->fd);
- writeLog("Removed User: [%s]\n",tmpConnection->userInfo.username);
+ writeLog(2,"Removed User: [%s]\n",tmpConnection->userInfo.username);
// If connection has a previous pointer which it always should adjust it's next pointer to match current next
if (tmpConnection->prev != 0x0)
@@ -170,7 +170,7 @@
//Free the bad connection
free(delConnection);
- writeLog("Remove Completed\n");
+ writeLog(2,"Remove Completed\n");
}
}
return(0x0);
@@ -178,7 +178,7 @@
int sRemoveConnection(int socketFD) {
myConnections_t *tmpConnection = 0x0;
- writeLog("Removing Socket: socketFD\n");
+ writeLog(2,"Removing Socket: socketFD\n");
for (tmpConnection = connections->next;tmpConnection != 0x0;tmpConnection = tmpConnection->next) {
if (tmpConnection->fd == socketFD) {
@@ -187,14 +187,14 @@
if (tmpConnection->next != 0x0)
tmpConnection->next->prev = tmpConnection->prev;
- writeLog("Removed Socket: [%i]\n",tmpConnection->fd);
+ writeLog(2,"Removed Socket: [%i]\n",tmpConnection->fd);
free(tmpConnection);
return(0x0);
}
}
- writeLog("Error: No Socket Removed\n");
+ writeLog(2,"Error: No Socket Removed\n");
return(-1);
}
@@ -242,14 +242,12 @@
myConnections_t *tmpConnection = 0x0;
for (tmpConnection = connections;tmpConnection != 0x0;tmpConnection = tmpConnection->next) {
- #ifdef DEBUG
- writeLog("socketFD: [%i]\n",tmpConnection->fd);
- #endif
+ writeLog(3,"socketFD: [%i]\n",tmpConnection->fd);
if (FD_ISSET(tmpConnection->fd,readset) != 0x0) {
- writeLog("FD_ISSET\n");
+ writeLog(2,"FD_ISSET\n");
if (tmpConnection->fd == listenerFD) {
sGetConnection();
- writeLog("Listen Socket Was Ready?\n");
+ writeLog(2,"Listen Socket Was Ready?\n");
}
else {
if (podzGetData(tmpConnection) == -1) {
diff --git a/tuve.c b/tuve.c
index ca3cd48..13119ab 100644
--- a/tuve.c
+++ b/tuve.c
@@ -13,7 +13,7 @@
int podzGetData(myConnections_t *userConnection) {
- writeLog("Getting Data\n");
+ writeLog(2,"Getting Data\n");
memset(&userConnection->data,0x0,1024);
userConnection->recLen = sReadSocket(userConnection->fd,&userConnection->data,1024);
@@ -22,12 +22,10 @@
userConnection->userInfo.pong = time(NULL);
- #ifdef DEBUG
- writeLog("Got: [%i][%s]\n",userConnection->recLen,userConnection->data);
- #endif
+ writeLog(3,"Got: [%i][%s]\n",userConnection->recLen,userConnection->data);
if (userConnection->recLen == 1) {
- writeLog("[%i][%c]\n",userConnection->data[0],userConnection->data[0]);
+ writeLog(2,"[%i][%c]\n",userConnection->data[0],userConnection->data[0]);
while(1);
}
@@ -50,6 +48,8 @@
int podzProcessData(myConnections_t *userConnection) {
myConnections_t *tmpConnection = 0x0;
+ char *chan = 0x0;
+ char *nick = 0x0;
char *cmd = 0x0;
char *msg = 0x0;
char *data = 0x0;
@@ -70,15 +70,15 @@
if (strstr(userConnection->data," ")) {
cmd = strtok_r(userConnection->data," ",&tok_last);
data = strtok_r(NULL,"\n",&tok_last);
- writeLog("DATA[%s:%s]\n",cmd,data);
+ writeLog(2,"DATA[%s:%s]\n",cmd,data);
tok_last = 0x0;
}
else {
- writeLog("DATA[%s]\n",cmd);
+ writeLog(2,"DATA[%s]\n",cmd);
}
if (!strcasecmp(cmd,"ident")) {
- writeLog("(ident)\n");
+ 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;
@@ -89,13 +89,13 @@
else if (strcasecmp(cmd,"") == 0x0) {
sprintf(output,"\n\n\n\n");
send(userConnection->fd,output,strlen(output) + 1,MSG_NOSIGNAL);
- writeLog("Send CROSSDOMAIN\n");
+ writeLog(2,"Send CROSSDOMAIN\n");
}
else if (userConnection->userInfo.ident != 0x1) {
send(userConnection->fd,"Please Auth",sizeof("Please Auth"),0);
}
else if (strcasecmp(cmd,"whoson") == 0x0) {
- writeLog("(whoson)\n");
+ writeLog(2,"(whoson)\n");
for (tmpConnection = connections->next;tmpConnection != 0x0;tmpConnection = tmpConnection->next) {
sprintf(output,"User: [%s:%i]\n",tmpConnection->userInfo.username,tmpConnection->userInfo.uid);
send(userConnection->fd,output,strlen(output),MSG_NOSIGNAL);
@@ -104,7 +104,7 @@
else if (strcasecmp(cmd,"mail") == 0x0) {
for (tmpConnection = connections->next;tmpConnection != 0x0;tmpConnection = tmpConnection->next) {
if (tmpConnection->userInfo.uid == atoi(data)) {
- writeLog("Found User\n");
+ writeLog(2,"Found User\n");
break;
}
}
@@ -155,12 +155,12 @@
}
}
else if (strcasecmp(cmd,"!die") == 0x0) {
- writeLog("Podz Daemon Shutting Down\n");
+ writeLog(1,"Podz Daemon Shutting Down\n");
fflush(logFile);
exit(0);
}
else if (strcasecmp(cmd,"PONG!") == 0x0) {
- writeLog("(PONG! :NULL)\n");
+ writeLog(2,"(PONG! :NULL)\n");
userConnection->userInfo.pfailed = 0x0;
}
else if (strcasecmp(cmd,"chanmsg") == 0x0) {
@@ -172,9 +172,37 @@
msg = strtok_r(data,":",&tok_last);
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);
+ }
+ else if (strcasecmp(cmd,"KICK") == 0x0) {
+ tok_last = 0x0;
+ chan = strtok_r(data,":",&tok_last);
+ nick = strtok_r(NULL,":",&tok_last);
+ msg = strtok_r(NULL,"\n",&tok_last);
+ sprintf(output,"CHANMSG:TUveD:%s:%s Has Been Kick By %s, Reason: %s\n",chan,nick,userConnection->userInfo.username,msg);
+ tuveSendAllInChan(chan,0x0,output);
+ }
+ else if (strcasecmp(cmd,"GETPOS") == 0x0) {
+ sprintf(output,"GETPOS\n");
+ if (data != 0x0)
+ tuveSendAllInChan(data,userConnection,output);
+ }
+ else if (strcasecmp(cmd,"CURPOS") == 0x0) {
+ tok_last = 0x0;
+ chan = strtok_r(data,":",&tok_last);
+ 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);
+ tuveSendAllInChan(chan,userConnection,output);
+ }
+ }
else {
- send(userConnection->fd,"invalid command",sizeof("invalid command"),MSG_NOSIGNAL);
- writeLog("Invalid CMD: [%s]\n",cmd);
+ send(userConnection->fd,"invalid command\n",sizeof("invalid command\n"),MSG_NOSIGNAL);
+ writeLog(1,"Invalid CMD: [%s]\n",cmd);
}
return(0x0);
diff --git a/tuved.h b/tuved.h
index 9a0bc01..025b79f 100644
--- a/tuved.h
+++ b/tuved.h
@@ -7,7 +7,7 @@
#define MYPORT 9999 // the port users will be connecting to
#define BACKLOG 10 // how many pending connections queue will hold
-#define LOG_FILE "./podzd.log"
+#define LOG_FILE "./tuved.log"
typedef struct tuveUserList {
struct tuveUserList *prev;
@@ -73,7 +73,7 @@
int podzSendAll(char *,int);
/* Log Functions */
-int writeLog(char const * __restrict, ...);
+int writeLog(int level,char const * __restrict, ...);
/* Channel Functions */
int tuveChanJoin(char *channel,myConnections_t *userConnection);
@@ -83,3 +83,4 @@
int tuveDelUserChans(myConnections_t *userConnection,char *msg);
int tuveRemoveFromChanList(char *channel,myConnections_t *userConnection);
int tuveSetTopic(myConnections_t *userConnection,char *chan,char *topic);
+int tuveSendAllInUsersChans(myConnections_t *userConnection,char *output);