From ab84512bc06ade328169d38ffb64f3820aa80dc4 Mon Sep 17 00:00:00 2001 From: Luke Bratch Date: Mon, 27 May 2019 11:09:36 +0100 Subject: Only compare nick instead of full nick!user@host when processing server JOIN/PART/NICK. Also handle the "new" nick already being set in greeting strings during a server NICK if it's changing our nick. --- blabouncer.c | 26 ++++++++++++++++++++------ functions.c | 10 ++++++++++ 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/blabouncer.c b/blabouncer.c index 8f2e975..db0d384 100644 --- a/blabouncer.c +++ b/blabouncer.c @@ -768,11 +768,15 @@ int processircmessage(SSL *server_ssl, char *str, int source, struct client *cli // If the user JOINing is us, then we must have joined a channel, so add to our local channel array. // Copy to a temporary string so we still have the original in case we need it char *prefixcopy = strdup(tokens[0]); - if (strncmp(prefixcopy, ircdstrings->nickuserhost, strlen(tokens[0])) == 0) { - printf("Server JOIN: nickuserhost is ours ('%s' vs '%s').\n", prefixcopy, ircdstrings->nickuserhost); + // Just get the nick for comparison + extractnickfromprefix(prefixcopy); + if (strncmp(prefixcopy, ircdstrings->ircnick, strlen(tokens[0])) == 0) { + printf("Server JOIN: nick is ours ('%s' vs '%s').\n", prefixcopy, ircdstrings->ircnick); // TODO - Saner way to initialise this since we don't have the variables yet? // TODO - Defaulting to type '=' which is "public" since I don't know what else to guess. createchannel(channels, tokens[2], "TOPIC", "TOPICWHO", "0"); + } else { + printf("Server JOIN: nick is NOT ours ('%s' vs '%s').\n", prefixcopy, ircdstrings->ircnick); } // And then send to all clients @@ -795,15 +799,19 @@ int processircmessage(SSL *server_ssl, char *str, int source, struct client *cli // Server PART received? Remove from our local channel list if it's us. if (strncmp(tokens[1], "PART", strlen(tokens[1])) == 0) { - printf("Server PART found and it is: %s with length %zd! Next token is '%s'. Adding to local channel list if it's us.\n", tokens[0], strlen(tokens[0]), tokens[2]); + printf("Server PART found and it is: %s with length %zd! Next token is '%s'. Removing from local channel list if it's us.\n", tokens[0], strlen(tokens[0]), tokens[2]); // If the user PARTing is us, then we must have left a channel, so remove it from our local channel array. // (If it's not us, then it's another user PARTing a channel, so just pass straight through to letting all our clients know.) // Copy to a temporary string so we still have the original in case we need it char *prefixcopy = strdup(tokens[0]); - if (strncmp(prefixcopy, ircdstrings->nickuserhost, strlen(tokens[0])) == 0) { - printf("Server PART: nickuserhost is ours ('%s' vs '%s').\n", prefixcopy, ircdstrings->nickuserhost); + // Just get the nick for comparison + extractnickfromprefix(prefixcopy); + if (strncmp(prefixcopy, ircdstrings->ircnick, strlen(tokens[0])) == 0) { + printf("Server PART: nick is ours ('%s' vs '%s').\n", prefixcopy, ircdstrings->ircnick); removechannel(channels, tokens[2]); + } else { + printf("Server PART: nick is NOT ours ('%s' vs '%s').\n", prefixcopy, ircdstrings->ircnick); } // And then send to all clients @@ -969,7 +977,12 @@ int processircmessage(SSL *server_ssl, char *str, int source, struct client *cli printf("Server NICK found and it is: %s with length %zd! Next token is '%s'. Updating records and relaying to all clients.\n", tokens[0], strlen(tokens[0]), tokens[2]); // Was it us? - if (strncmp(ircdstrings->nickuserhost, tokens[0], strlen(ircdstrings->nickuserhost)) == 0) { + // Copy to a temporary string so we still have the original in case we need it + char *svrprefixcopy = strdup(tokens[0]); + // Just get the nick for comparison + extractnickfromprefix(svrprefixcopy); + if (strncmp(ircdstrings->ircnick, svrprefixcopy, strlen(ircdstrings->ircnick)) == 0) { + printf("Server NICK: nick is ours ('%s' vs '%s').\n", svrprefixcopy, ircdstrings->ircnick); // Make a copy of the old nickuserhost for updategreetings() below char *nickuserhostcpy = strdup(ircdstrings->nickuserhost); // Update nickuserhost with the new :nick!user@host @@ -992,6 +1005,7 @@ int processircmessage(SSL *server_ssl, char *str, int source, struct client *cli // Relay to all clients sendtoallclients(clients, str, sourcefd, settings); + free(svrprefixcopy); free(strcopyPtr); return 1; } diff --git a/functions.c b/functions.c index 94c653e..3ca7b06 100644 --- a/functions.c +++ b/functions.c @@ -17,6 +17,16 @@ void updategreetingnick(char *greeting, char *greetingnum, char *newnick, char * ret = strstr(greeting, searchstr); } + // Perhaps the new nick is already present (seen for instance when connecting to another bouncer like Miau) + if (ret == NULL) { + snprintf(searchstr, MAXDATASIZE, " %s %s ", greetingnum, newnick); + ret = strstr(greeting, searchstr); + if (ret != NULL) { + printf("updategreetingnick(): newnick is already present, returning.\n"); + return; + } + } + // If ret *still* not found, abandon ship if (ret == NULL) { printf("Error updating greeting string, substring not found. Exiting!\n"); -- cgit v1.2.3