--- a/src/irc.c
+++ b/src/irc.c
@@ -20,6 +20,19 @@
#include <compat.h>
#include <irc.h>
+#define NOTICE 0
+#define MODE 1
+#define JOIN 2
+#define PART 3
+#define TOPIC 4
+#define PING 5
+#define ENOMEM 6
+#define ERROR 7
+#define VERSION 8
+#define PRIVMSG 9
+#define QUIT 10
+#define NICK 11
+
#define VERSION_STRING "MCBOT on GNU/LINUX"
const char *IRC_Commands[] = {
@@ -163,10 +176,7 @@
message->channel = message->line = NULL;
token = strtok (theLine, " ");
- if (*token != ':') {
- /*
- * SERVER MESSAGES
- */
+ if (*token != ':') { /* SERVER MESSAGES */
if ((ptr = strtok (NULL, "\r\n")) != NULL)
++ptr;
message->line = ptr;
@@ -175,7 +185,6 @@
message->user = ++token;
message->command = strtok (NULL, " ");
-
message->line = strtok (NULL, "\r\n");
return message->command;
@@ -197,7 +206,7 @@
while (IRC_Commands[i] != NULL) {
if (strcmp (IRC_Commands[i], command) == 0) {
switch (i) {
- case 0: /* NOTICE */
+ case NOTICE:
if (message->line == NULL) {
message->channel = "*";
message->line = "*";
@@ -207,22 +216,22 @@
++message->line;
}
return command;
- case 1: /* MODE */
+ case MODE:
message->channel = strtok (message->line, " ");
message->line = strtok (NULL, "\r\n");
return command;
- case 2: /* JOIN */
- case 3: /* PART */
+ case JOIN:
+ case PART:
if ((message->channel = strchr (message->line, ':')))
++message->channel;
message->line = message->user;
return command;
- case 4: /* TOPIC */
+ case TOPIC:
message->channel = strtok (message->line, " ");
if ((message->line = strtok (NULL, "\r\n")))
++message->line;
return command;
- case 5: /* PING */
+ case PING:
#ifdef DEBUG
/*
* DONT NERVE WITH PING PONG MESSAGES
@@ -236,29 +245,29 @@
#else
return NULL;
#endif
- case 6: /* ENOMEM */
- case 7: /* ERROR */
+ case ENOMEM:
+ case ERROR:
return command;
- case 8: /* VERSION */
+ case VERSION:
if ((ptr = strchr (message->user, ' ')))
*ptr = '\0';
return command;
- case 9: /* PRIVMSG */
+ case PRIVMSG:
if ((message->email = strchr (message->user, '=')))
++message->email;
if ((ptr = strchr (message->user, '!')))
*ptr = '\0';
message->channel = strtok (message->line, " ");
- message->current_channel = message->channel;
+ strncpy (message->current_channel, message->channel, 40);
message->line = strtok (NULL, "\r\n");
message->line++;
printf ("%10s %s %s :%s\n", "READ", message->command, message->channel, message->line);
return NULL;
- case 10: /* QUIT */
+ case QUIT:
message->channel = message->user;
return command;
- case 11: /* NICK */
+ case NICK:
message->channel = message->user;
return command;
}
@@ -300,20 +309,8 @@
case 328: /* INFORMATION */
case 332: /* TOPIC OF CHANNEL */
case 333: /* NAMES IN CHANNEL */
- message->channel = strtok (message->line, " ");
- message->line = strtok (NULL, "\r\n");
- return command;
case 351: /* SVERSION */
- message->channel = strtok (message->line, " ");
- message->line = strtok (NULL, "\r\n");
- return command;
case 352: /* WHO LIST */
- message->channel = strtok (message->line, " ");
- message->line = strtok (NULL, "\r\n");
- /*
- * MORE THAN 3 LINES AND YOU WILL be KICKED
- */
- return command;
case 353:
case 365:
case 366: /* END OF NAMES */
@@ -328,18 +325,19 @@
case 403: /* THAT CHANNEL DOESN'T EXIST */
case 412: /* NO TEXT TO SEND */
case 441: /* THEY AREN'T ON THIS CHANNEL */
+ message->channel = strtok (message->line, " ");
+ message->line = strtok (NULL, "\r\n");
+ fprintf (message->stream, "PRIVMSG %s :%s\r\n", message->current_channel, message->line);
return command;
case 474:
case 475:
case 476:
case 477:
case 482:
- message->channel = strtok (message->line, " ");
- message->line = strtok (NULL, "\r\n");
- return command;
case 901: /* notify or some crap */
message->channel = strtok (message->line, " ");
message->line = strtok (NULL, "\r\n");
+ fprintf (message->stream, "PRIVMSG %s :%s\r\n", message->current_channel, message->line);
return command;
default:
printf ("DEBUG %s", line);