diff options
-rw-r--r-- | blabouncer.c | 41 | ||||
-rw-r--r-- | blabouncer.conf | 4 | ||||
-rw-r--r-- | config.c | 4 |
3 files changed, 46 insertions, 3 deletions
diff --git a/blabouncer.c b/blabouncer.c index 0eb2519..ae62487 100644 --- a/blabouncer.c +++ b/blabouncer.c @@ -1,5 +1,4 @@ // TODO: -// - handle nick in use // - Might need to change channel struct nicks to be channel struct user struct with its own nick/modes/etc. // - Do we actually need to store the modes in the channel struct? // - Get CAP from server and relay to client @@ -946,6 +945,46 @@ int processircmessage(SSL *server_ssl, char *str, int source, struct client *cli return 1; } + // Server 432 (ERR_ERRONEUSNICKNAME) or 433 (ERR_NICKNAMEINUSE) received? See which nick we're on and try another. + if (strncmp(tokens[1], "432", strlen(tokens[1])) == 0 || strncmp(tokens[1], "433", strlen(tokens[1])) == 0) { + printf("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])); + + // Make sure nick3 hasn't already been tried + if (getconfstr("nick3", settings->conffile, settings->ircnick)) { + // If it's the current nick already then... + if (strncmp(ircdstrings->ircnick, settings->ircnick, strlen(settings->ircnick)) == 0) { + // ...give up + printf("error: server doesn't like any configured nicks, giving up.\n"); + exit(1); + } + } + + // Try nick2 + if (!getconfstr("nick2", settings->conffile, settings->ircnick)) { + printf("error: server doesn't like nick and can't get 'nick2' from configuration file.\n"); + exit(1); + } + // Have we already tried this one? (i.e. is it the current nick) + if (strncmp(ircdstrings->ircnick, settings->ircnick, strlen(settings->ircnick)) == 0) { + // Then try nick3 + if (!getconfstr("nick3", settings->conffile, settings->ircnick)) { + printf("error: server doesn't like nick or nick2 and can't get 'nick3' from configuration file.\n"); + exit(1); + } + } + + // Set whichever one we settled on as the current nick + strcpy(ircdstrings->ircnick, settings->ircnick); + + // Try it with the server + char outgoingmsg[MAXDATASIZE]; + snprintf(outgoingmsg, MAXDATASIZE, "NICK %s", ircdstrings->ircnick); + // sourcefd = 0 as this is a trusted message + sendtoserver(server_ssl, outgoingmsg, strlen(outgoingmsg), 0, clients, settings); + + free(strcopyPtr); + return 1; + } } // Don't return if we got here because this means we didn't process something above diff --git a/blabouncer.conf b/blabouncer.conf index b834c8e..7297f9b 100644 --- a/blabouncer.conf +++ b/blabouncer.conf @@ -5,7 +5,9 @@ # realname = "Mr Bla Bouncer" nick = "blabounce" -username = "blabounce" +nick2 = "bbounce2" +nick3 = "bbounce3" +username = "bounceusr" realname = "Mr Bla Bouncer" # How many seconds of replay log should be sent to connecting clients @@ -166,7 +166,9 @@ int createconfigfile(char *filename) { "# realname = \"Mr Bla Bouncer\"\n" "\n" "nick = \"blabounce\"\n" - "username = \"blabounce\"\n" + "nick2 = \"bbounce2\"\n" + "nick3 = \"bbounce3\"\n" + "username = \"bounceusr\"\n" "realname = \"Mr Bla Bouncer\"\n" "\n" "# How many seconds of replay log should be sent to connecting clients\n" |