src/irc.c
changeset 18 4435146391ae
parent 15 f19c1f9b4cd3
child 19 66114d944208
--- a/src/irc.c
+++ b/src/irc.c
@@ -105,9 +105,6 @@
     if ((pwd = getpwnam (user)) == NULL)
         return IRC_GENERAL_ERROR;
 
-    if (password == NULL)
-        return IRC_LOGIN_ERROR;
-
     if (stream == NULL)
         return IRC_GENERAL_ERROR;
     else
@@ -115,7 +112,9 @@
 
     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);
+
+    if (password != NULL)
+        fprintf (stream, "PRIVMSG NICKSERV :IDENTIFY %s\r\n", password);
 
     for (;;) {
         *msg = '\0';
@@ -148,6 +147,12 @@
         if (strstr (msg, "is not registered") != NULL) {
             return IRC_LOGIN_ERROR;
         }
+        if (strstr (msg, ":Nickname is already in use") != NULL) {
+            return IRC_LOGIN_ERROR;
+        }
+
+        if (password == NULL)
+            break;
     }
 
     sleep (2);
@@ -329,6 +334,9 @@
                 message->line = strtok (NULL, "\r\n");
                 fprintf (message->stream, "PRIVMSG %s :%s\r\n", message->current_channel, message->line);
                 return command;
+            case 433:          /* NICK ALREADY IN USE */
+            case 451:          /* REGISTER FIRST */
+                return command;
             case 474:
             case 475:
             case 476: