src/irc.c
changeset 18 4435146391ae
parent 15 f19c1f9b4cd3
child 19 66114d944208
equal deleted inserted replaced
17:9a32b5242320 18:4435146391ae
   103         return IRC_GENERAL_ERROR;
   103         return IRC_GENERAL_ERROR;
   104 
   104 
   105     if ((pwd = getpwnam (user)) == NULL)
   105     if ((pwd = getpwnam (user)) == NULL)
   106         return IRC_GENERAL_ERROR;
   106         return IRC_GENERAL_ERROR;
   107 
   107 
   108     if (password == NULL)
       
   109         return IRC_LOGIN_ERROR;
       
   110 
       
   111     if (stream == NULL)
   108     if (stream == NULL)
   112         return IRC_GENERAL_ERROR;
   109         return IRC_GENERAL_ERROR;
   113     else
   110     else
   114         message.stream = stream;
   111         message.stream = stream;
   115 
   112 
   116     fprintf (stream, "NICK %s\r\n", nick);
   113     fprintf (stream, "NICK %s\r\n", nick);
   117     fprintf (stream, "USER %s 0 %s %s\r\n", user, server, pwd->pw_gecos);
   114     fprintf (stream, "USER %s 0 %s %s\r\n", user, server, pwd->pw_gecos);
   118     fprintf (stream, "PRIVMSG NICKSERV :IDENTIFY %s\r\n", password);
   115 
       
   116     if (password != NULL)
       
   117         fprintf (stream, "PRIVMSG NICKSERV :IDENTIFY %s\r\n", password);
   119 
   118 
   120     for (;;) {
   119     for (;;) {
   121         *msg = '\0';
   120         *msg = '\0';
   122         fgets (msg, 512, stream);
   121         fgets (msg, 512, stream);
   123         if ((user = irc_parsemessage (msg, &message)) != NULL)
   122         if ((user = irc_parsemessage (msg, &message)) != NULL)
   146         }
   145         }
   147 
   146 
   148         if (strstr (msg, "is not registered") != NULL) {
   147         if (strstr (msg, "is not registered") != NULL) {
   149             return IRC_LOGIN_ERROR;
   148             return IRC_LOGIN_ERROR;
   150         }
   149         }
       
   150         if (strstr (msg, ":Nickname is already in use") != NULL) {
       
   151             return IRC_LOGIN_ERROR;
       
   152         }
       
   153 
       
   154         if (password == NULL)
       
   155             break;
   151     }
   156     }
   152 
   157 
   153     sleep (2);
   158     sleep (2);
   154     return 0;
   159     return 0;
   155 }
   160 }
   327             case 441:          /* THEY AREN'T ON THIS CHANNEL */
   332             case 441:          /* THEY AREN'T ON THIS CHANNEL */
   328                 message->channel = strtok (message->line, " ");
   333                 message->channel = strtok (message->line, " ");
   329                 message->line = strtok (NULL, "\r\n");
   334                 message->line = strtok (NULL, "\r\n");
   330                 fprintf (message->stream, "PRIVMSG %s :%s\r\n", message->current_channel, message->line);
   335                 fprintf (message->stream, "PRIVMSG %s :%s\r\n", message->current_channel, message->line);
   331                 return command;
   336                 return command;
       
   337             case 433:          /* NICK ALREADY IN USE */
       
   338             case 451:          /* REGISTER FIRST */
       
   339                 return command;
   332             case 474:
   340             case 474:
   333             case 475:
   341             case 475:
   334             case 476:
   342             case 476:
   335             case 477:
   343             case 477:
   336             case 482:
   344             case 482: