summaryrefslogtreecommitdiff
path: root/blabouncer.c
diff options
context:
space:
mode:
authorLuke Bratch <luke@bratch.co.uk>2019-05-18 22:50:18 +0100
committerLuke Bratch <luke@bratch.co.uk>2019-05-18 22:50:18 +0100
commit7764645c80ed542095b97eaa119d2df6340b0330 (patch)
treea6b9de19b51d67449d49edd760e8e7db1d734b9a /blabouncer.c
parentc47b5a1531fe0e2a3b00c4a5ec80a4dc4cbe2428 (diff)
Handle nick in use or invalid nick, add multiple nicks to configuration file to automatically try.
Diffstat (limited to 'blabouncer.c')
-rw-r--r--blabouncer.c41
1 files changed, 40 insertions, 1 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