From 52d426544ce976f81cbd626fbba343c066ed88d0 Mon Sep 17 00:00:00 2001 From: Luke Bratch Date: Sun, 19 May 2019 14:30:08 +0100 Subject: Handle server MODEs more intelligently, in particular so we can relay our user MODE to new clients correctly. --- blabouncer.c | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) (limited to 'blabouncer.c') diff --git a/blabouncer.c b/blabouncer.c index 2c210b1..f85e58c 100644 --- a/blabouncer.c +++ b/blabouncer.c @@ -903,14 +903,40 @@ int processircmessage(SSL *server_ssl, char *str, int source, struct client *cli return 1; } - // Server MODE received? Store in ircdstrings for when clients connect and relay to current clients. + // Server MODE received? See what sort it is and act accordingly. if (strncmp(tokens[1], "MODE", strlen(tokens[1])) == 0) { - printf("Server MODE found and it is: %s with length %zd! Mode is '%s'. Storing for later.\n", tokens[1], strlen(tokens[1]), tokens[3]); + printf("Server MODE found and it is: %s with length %zd! Next token is '%s'. Analysing...\n", tokens[1], strlen(tokens[1]), tokens[2]); + + // 4 tokens could be either our initial mode or a channel mode (or something else - TODO - what else?) + if (counter == 4) { + // Might be our initial mode (e.g. ":nick MODE nick :+iwz") + char comparison[MAXDATASIZE]; + snprintf(comparison, MAXDATASIZE, ":%s MODE %s :", ircdstrings->ircnick, ircdstrings->ircnick); + if (strncmp(str, comparison, strlen(comparison)) == 0) { + // Looks like it! + printf("Our initial MODE found (%s), storing for later.\n", tokens[3]); + // Store in ircdstrings for when clients connect and relay to current clients. + strcpy(ircdstrings->mode, tokens[3]); + + // Relay to all current clients anyway - TODO - Necessary? + sendtoallclients(clients, str, sourcefd, settings); + + free(strcopyPtr); + return 1; + } + + // Might be a channel mode (e.g. ":nick!user@host MODE #channel +s") + if (tokens[2][0] == '#') { + // Looks like it! Tell all clients. + printf("Channel MODE found (%s %s), telling all clients.\n", tokens[2], tokens[3]); + sendtoallclients(clients, str, sourcefd, settings); - // Store for new clients - strcpy(ircdstrings->mode, tokens[3]); + free(strcopyPtr); + return 1; + } + } - // Relay to all current clients + // Relay to all current clients if not processed by the above sendtoallclients(clients, str, sourcefd, settings); free(strcopyPtr); -- cgit v1.2.3