src/irc.c
changeset 11 a769385a59c6
parent 10 311ea5fa60dd
child 12 213c3d4abc66
equal deleted inserted replaced
10:311ea5fa60dd 11:a769385a59c6
    23 
    23 
    24 const char *IRC_Commands[] = {
    24 const char *IRC_Commands[] = {
    25     "NOTICE", "MODE", "JOIN", "PART",
    25     "NOTICE", "MODE", "JOIN", "PART",
    26     "TOPIC", "PING", "ENOMEM", "ERROR",
    26     "TOPIC", "PING", "ENOMEM", "ERROR",
    27     "VERSION", "PRIVMSG", "QUIT", "NICK",
    27     "VERSION", "PRIVMSG", "QUIT", "NICK",
       
    28     NULL
    28 };
    29 };
    29 
    30 
    30 FILE *irc_connect (char *server, unsigned int port)
    31 FILE *irc_connect (char *server, unsigned int port)
    31 {
    32 {
    32     struct hostent *he;
    33     struct hostent *he;
   101     fprintf (stream, "NICK %s\r\n", nick);
   102     fprintf (stream, "NICK %s\r\n", nick);
   102     fprintf (stream, "USER %s 0 %s %s\r\n", user, server, pwd->pw_gecos);
   103     fprintf (stream, "USER %s 0 %s %s\r\n", user, server, pwd->pw_gecos);
   103     fprintf (stream, "PRIVMSG NICKSERV :IDENTIFY %s\r\n", password);
   104     fprintf (stream, "PRIVMSG NICKSERV :IDENTIFY %s\r\n", password);
   104 
   105 
   105     for (;;) {
   106     for (;;) {
   106         *msg = 0;
   107         *msg = '\0';
   107         fgets (msg, 512, stream);
   108         fgets (msg, 512, stream);
   108         if ((user = irc_parsemessage (msg, &message)) != NULL)
   109         if ((user = irc_parsemessage (msg, &message)) != NULL)
   109             printf ("%10s %s\n", user, message.line);
   110             printf ("%10s %s\n", user, message.line);
   110 
   111 
   111         if (strstr (msg, "VERSION") != NULL) {
   112         if (strstr (msg, "VERSION") != NULL) {
   229                 case 6:        /* ENOMEM */
   230                 case 6:        /* ENOMEM */
   230                 case 7:        /* ERROR */
   231                 case 7:        /* ERROR */
   231                     return command;
   232                     return command;
   232                 case 8:        /* VERSION */
   233                 case 8:        /* VERSION */
   233                     if ((ptr = strchr (message->user, ' ')))
   234                     if ((ptr = strchr (message->user, ' ')))
   234                         *ptr = 0;
   235                         *ptr = '\0';
   235                     return command;
   236                     return command;
   236                 case 9:        /* PRIVMSG */
   237                 case 9:        /* PRIVMSG */
   237                     if ((message->email = strchr (message->user, '=')))
   238                     if ((message->email = strchr (message->user, '=')))
   238                         ++message->email;
   239                         ++message->email;
   239                     if ((ptr = strchr (message->user, '!')))
   240                     if ((ptr = strchr (message->user, '!')))
   240                         *ptr = 0;
   241                         *ptr = '\0';
   241 
   242 
   242                     message->channel = strtok (message->line, " ");
   243                     message->channel = strtok (message->line, " ");
   243                     message->current_channel = message->channel;
   244                     message->current_channel = message->channel;
   244                     message->line = strtok (NULL, "\r\n");
   245                     message->line = strtok (NULL, "\r\n");
   245                     message->line++;
   246                     message->line++;
   312                 return command;
   313                 return command;
   313             case 372:          /* MOTD MESSAGES */
   314             case 372:          /* MOTD MESSAGES */
   314             case 375:
   315             case 375:
   315             case 376:          /* END OF MOTD */
   316             case 376:          /* END OF MOTD */
   316                 return command;
   317                 return command;
   317                 break;
       
   318             case 401:          /* NO SUCH NICK/CHANNEL */
   318             case 401:          /* NO SUCH NICK/CHANNEL */
   319             case 403:          /* THAT CHANNEL DOESN'T EXIST */
   319             case 403:          /* THAT CHANNEL DOESN'T EXIST */
   320             case 441:          /* THEY AREN'T ON THIS CHANNEL */
   320             case 441:          /* THEY AREN'T ON THIS CHANNEL */
   321                 return command;
   321                 return command;
   322             case 474:
   322             case 474: