Private Messages will be send to the proper location
authorMarkus Bröker <mbroeker@largo.dyndns.tv>
Sat, 13 Dec 2008 15:40:11 +0100
changeset 9 aff6726b8b87
parent 8 3152de03758e
child 10 311ea5fa60dd
Private Messages will be send to the proper location committer: Markus Bröker <mbroeker@largo.homelinux.org>
include/irc.h
src/irc.c
src/main.c
--- a/include/irc.h
+++ b/include/irc.h
@@ -19,6 +19,7 @@
     char *command;
     char *channel;
     char *line;
+    char *current_channel;
 };
 
 typedef struct Message MSG;
--- a/src/irc.c
+++ b/src/irc.c
@@ -96,9 +96,7 @@
         return IRC_GENERAL_ERROR;
 
     fprintf (stream, "NICK %s\r\n", nick);
-
     fprintf (stream, "USER %s 0 %s %s\r\n", user, server, pwd->pw_gecos);
-
     fprintf (stream, "PRIVMSG NICKSERV :IDENTIFY %s\r\n", password);
 
     for (;;) {
@@ -169,11 +167,10 @@
     return message->command;
 }
 
-/*
+/**
  * Main prints ("%10s %s %s\n", MSG->command MSG->channel MSG->line).
  * This functions makes sure, that there will be someting to print...
  */
-
 char *irc_parsemessage (const char *line, MSG * message)
 {
     int i;
@@ -186,7 +183,6 @@
         while (IRC_Commands[i] != NULL) {
             if (strcmp (IRC_Commands[i], command) == 0) {
                 switch (i) {
-
                 case 0:        /* NOTICE */
                     if (message->line == NULL) {
                         message->channel = "*";
@@ -214,6 +210,9 @@
                     return command;
                 case 5:        /* PING */
 #ifdef DEBUG
+                    /*
+                     * DONT NERVE WITH PING PONG MESSAGES
+                     */
                     printf ("%10s %s localhost\n", "PING", message->line);
 #endif
                     fprintf (message->stream, "PONG :%s\r\n", message->line);
@@ -225,8 +224,7 @@
 #endif
                 case 6:        /* ENOMEM */
                 case 7:        /* ERROR */
-                    exit (-1);
-                    break;
+                    return command;
                 case 8:        /* VERSION */
                     if ((ptr = strchr (message->user, ' ')))
                         *ptr = 0;
@@ -238,6 +236,7 @@
                         *ptr = 0;
 
                     message->channel = strtok (message->line, " ");
+                    message->current_channel = message->channel;
                     message->line = strtok (NULL, "\r\n");
                     message->line++;
                     printf ("%10s %s %s :%s\n", "READ", message->command, message->channel, message->line);
@@ -271,7 +270,6 @@
                  * prints as is in irc_login
                  */
                 return command;
-                break;
             case 311:
             case 312:
             case 315:          /* END OF WHO */
@@ -282,7 +280,7 @@
             case 319:
                 message->channel = strtok (message->line, " ");
                 message->line = strtok (NULL, "\r\n");
-                fprintf (message->stream, "PRIVMSG %s :%s\r\n", "#mcbot", message->line);
+                fprintf (message->stream, "PRIVMSG %s :%s\r\n", message->current_channel, message->line);
                 return command;
             case 320:
             case 332:          /* TOPIC OF CHANNEL */
@@ -301,14 +299,12 @@
                  * MORE THAN 3 LINES AND YOU WILL be KICKED
                  */
                 return command;
-                break;
             case 353:
             case 365:
             case 366:          /* END OF NAMES */
                 message->channel = strtok (message->line, " ");
                 message->line = strtok (NULL, "\r\n");
                 return command;
-                break;
             case 372:          /* MOTD MESSAGES */
             case 375:
             case 376:          /* END OF MOTD */
@@ -316,30 +312,29 @@
                 break;
             case 401:          /* NO SUCH NICK/CHANNEL */
             case 403:          /* That CHANNEL doesnt exist */
+            case 441:          /* They aren't on this channel */
                 return command;
-                break;
             case 474:
             case 475:
             case 476:
             case 477:
+            case 482:
                 message->channel = strtok (message->line, " ");
                 message->line = strtok (NULL, "\r\n");
                 return command;
-                break;
             case 901:          /* notify or some crap */
                 message->channel = strtok (message->line, " ");
                 message->line = strtok (NULL, "\r\n");
                 return command;
-                break;
             default:
                 printf ("DEBUG   %s", line);
-                printf ("Unknown Value: %d\n", value);
+                printf ("Unknown Command Value: %d\n", value);
             }
         }
         printf ("DEBUG   %s", line);
         printf ("Unknown Command: %s\n", command);
         return command;
     }
-    printf ("DEBUG   %s", line);
+    printf ("NOT PARSEABLE   %s", line);
     return NULL;
 }
--- a/src/main.c
+++ b/src/main.c
@@ -90,6 +90,7 @@
 
     if (uc.channel) {
         fprintf (message.stream, "JOIN :%s\r\n", uc.channel);
+        message.current_channel = uc.channel;
         if (uc.topic)
             fprintf (message.stream, "TOPIC %s :%s\r\n", uc.channel, uc.topic);
     }
@@ -101,6 +102,8 @@
 
         if ((command = irc_parsemessage (buf, &message))) {
             printf ("%10s %s %s\n", command, message.channel, message.line);
+            if (!strcmp (command, "ERROR"))
+                break;
         } else {
             if ((msg = parse (&message)) != NULL) {
                 fprintf (message.stream, "%s\r\n", msg);