summaryrefslogtreecommitdiff
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
parentc47b5a1531fe0e2a3b00c4a5ec80a4dc4cbe2428 (diff)
Handle nick in use or invalid nick, add multiple nicks to configuration file to automatically try.
-rw-r--r--blabouncer.c41
-rw-r--r--blabouncer.conf4
-rw-r--r--config.c4
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
diff --git a/config.c b/config.c
index 60bac19..2f790a5 100644
--- a/config.c
+++ b/config.c
@@ -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"