diff options
Diffstat (limited to 'message.c')
| -rw-r--r-- | message.c | 61 | 
1 files changed, 28 insertions, 33 deletions
@@ -64,6 +64,16 @@ int processservermessage(SSL *server_ssl, char *str, struct client *clients, int        // Null the end of the new string        ircdstate->nickuserhost[strlen(tokens[counter - 1]) + 1] = '\0'; // +1 for the inserted colon        debugprint(DEBUG_FULL, "nickuserhost '%s' stored.\n", ircdstate->nickuserhost); +      // Set our current ircnick based on whatever was in greeting 001 +      if (counter >= 3) { +        // Assuming there at least three tokens (:ircdname 001 nick etc.) then store the nick +        strcpy(ircdstate->ircnick, tokens[2]); +        debugprint(DEBUG_FULL, "Updated ircnick to '%s' from greeting 001.\n", ircdstate->ircnick); +      } else { +        // Something has gone fairly wrong with greeting 001 +        debugprint(DEBUG_CRIT, "Greeting 001 ('%s') is not long enough, don't know how to proceed, exiting...\n", str); +        exit(1); +      }        return 1;      } else if (strncmp(tokens[1], "002", strlen(tokens[1])) == 0) {        debugprint(DEBUG_FULL, "Found greeting 002 (%s), storing in ircdstate struct.\n", str); @@ -642,42 +652,27 @@ int processservermessage(SSL *server_ssl, char *str, struct client *clients, int        debugprint(DEBUG_SOME, "Server 432 (ERR_ERRONEUSNICKNAME) or 433 (ERR_NICKNAMEINUSE) found and it is: %s with length %zd!  Trying another nick...\n",                   tokens[1], strlen(tokens[1])); -      // Do we have both a nick2 and a nick3?  (And not tried autonick yet.) -      if (settings->ircnick2[0] && settings->ircnick3[0] && !ircdstate->autonicknum) { -        // Has nick3 already been tried? -        if (strncmp(ircdstate->ircnick, settings->ircnick3, strlen(settings->ircnick)) == 0) { -          // Then try autonick -          tryautonick(ircdstate); -        // Has nick2 already been tried? -        } else if (strncmp(ircdstate->ircnick, settings->ircnick2, strlen(settings->ircnick)) == 0) { -          // Then try nick3 -          debugprint(DEBUG_SOME, "Trying nick3, nick2 was already tried.\n"); -          strcpy(ircdstate->ircnick, settings->ircnick3); -        // Have neither been tried? -        } else { -          // Then try nick2 -          debugprint(DEBUG_SOME, "Trying nick2, nick3 is also configured.\n"); -          strcpy(ircdstate->ircnick, settings->ircnick2); -        } -      // Do we only have a nick2?  (And not tried autonick yet.) -      } else if (settings->ircnick2[0] && !ircdstate->autonicknum) { -        // Has it already been tried? -        if (strncmp(ircdstate->ircnick, settings->ircnick2, strlen(settings->ircnick)) == 0) { -          // Then try autonick -          tryautonick(ircdstate); -        } else { -          // Then try it -          debugprint(DEBUG_SOME, "Trying nick2, nick3 is not configured.\n"); -          strcpy(ircdstate->ircnick, settings->ircnick2); +      // Find the nick (its index in the nicks array) currently selected +      int nickindex = -1; // -1 used later if current nick isn't in the configuration array +      int nickcount = 0; // How many nicks are configured in the configuration array +      for (int i = 0; i < MAXCONFARR; i++) { +        if (settings->ircnicks[i][0]) { +          nickcount++; +          if (strncmp(ircdstate->ircnick, settings->ircnicks[i], strlen(settings->ircnicks[i])) == 0 && strlen(ircdstate->ircnick) == strlen(settings->ircnicks[i])) { +            nickindex = i; +          }          } -      // Do we have neither?  (Or have already started autonick.) -      } else { -        // Then try autonick -          tryautonick(ircdstate);        } -      // Set whichever one we settled on in the settings in case we reference settings later -      strcpy(settings->ircnick, ircdstate->ircnick); +      // If there are more nicks left to try, then try the next one +      if (nickindex < nickcount - 1) { +        strcpy(ircdstate->ircnick, settings->ircnicks[nickindex + 1]); +        debugprint(DEBUG_SOME, "Switched nick to '%s' and retrying...\n", ircdstate->ircnick); +      // Otherwise, give up on configured nicks and switch to autonick +      } else { +        debugprint(DEBUG_SOME, "Giving up on preconfigured nicks trying autonick...\n", ircdstate->ircnick); +        tryautonick(ircdstate); +      }        // Try it with the server        char outgoingmsg[MAXDATASIZE];  | 
