diff options
author | Luke Bratch <luke@bratch.co.uk> | 2019-05-29 23:01:40 +0100 |
---|---|---|
committer | Luke Bratch <luke@bratch.co.uk> | 2019-05-29 23:01:40 +0100 |
commit | ef93f4d61f03faa0edd60f11c7790ad3b67b44d4 (patch) | |
tree | 89eceef73515b78fbc2111bc7197730211d537b2 | |
parent | 013e8d87e979b121b1589ca9609e9b721e8f3a81 (diff) |
Include NOTICEs in the replay log and normal logs. Particularly useful for relaying NickServ IDENTIFY password warnings to clients shortly after connecting.
-rw-r--r-- | TODO | 2 | ||||
-rw-r--r-- | blabouncer.c | 45 | ||||
-rw-r--r-- | logging.c | 2 | ||||
-rw-r--r-- | logging.h | 2 |
4 files changed, 49 insertions, 2 deletions
@@ -10,5 +10,3 @@ Might need to #include <limits.h> in blabouncer.c to make some operating systems Send a PING to the server before assuming a timeout is definite. Implement daemon (background) mode. - -Include NOTICEs in the replay log. diff --git a/blabouncer.c b/blabouncer.c index e5f1723..8a718df 100644 --- a/blabouncer.c +++ b/blabouncer.c @@ -1479,6 +1479,32 @@ int processircmessage(SSL *server_ssl, char *str, int source, struct client *cli // We didn't handle it debugprint("Unhandled server CAP response.\n"); } + + // Server NOTICE received? Handle and log if it's from a user, otherwise let pass through to default handler. + if (strncmp(tokens[1], "NOTICE", strlen(tokens[1])) == 0) { + debugprint("Server NOTICE found and it is: %s with length %zd! Analysing...\n", tokens[1], strlen(tokens[1])); + // If the first token is a nick!user@host then it's probably from a user + if (strstr(tokens[0], "!") != NULL && strstr(tokens[0], "@") != NULL) { + debugprint("Server NOTICE appears to be from a user, sending to all clients and logging.\n"); + + sendtoallclients(clients, str, 0, settings); + + // Write to replay log if replay logging enabled + if (settings->replaylogging) { + writereplayline(str, settings->basedir); + } + + // Write to normal log if logging enabled + if (settings->logging) { + logline(str, settings->ircnick, settings->basedir, LOG_PRIVMSG); + } + + free(strcopyPtr); + return 1; + } else { + debugprint("Server NOTICE does not appear to be from a user, passing through.\n"); + } + } } // Don't return if we got here because this means we didn't process something above @@ -1877,6 +1903,25 @@ int processircmessage(SSL *server_ssl, char *str, int source, struct client *cli // Client NOTICE received if (strncasecmp(tokens[0], "NOTICE", strlen(tokens[0])) == 0) { + + // Rebuild to full NOTICE string including our nick!user@host for logging + char fullmsg[MAXDATASIZE]; + + if (!snprintf(fullmsg, MAXDATASIZE, "%s %s", ircdstrings->nickuserhost, str)) { + fprintf(stderr, "Error while preparing NOTICE string for logging.\n"); + exit(1); + } + + // Write to replay log if replay logging enabled + if (settings->replaylogging) { + writereplayline(fullmsg, settings->basedir); + } + + // Write to normal log if logging enabled + if (settings->logging) { + logline(fullmsg, settings->ircnick, settings->basedir, LOG_PRIVMSG); + } + // If it's a CTCP VERSION response then only send to the server (CTCP requests are delimited with \1) if (counter >= 3 && strncmp(tokens[2], ":\1VERSION", strlen(tokens[2])) == 0) { debugprint("Client NOTICE looked like a CTCP VERSION response, so just sending to the server.\n"); @@ -10,6 +10,8 @@ // If LOG_PRIVMSG then it expects a string in the format: // :from!bar@baz PRIVMSG to :hello world // +// LOG_PRIVMSG is also used for NOTICEs. +// // If LOG_JOINPART then it expects a string in the format: // :nick!bar@baz JOIN :#channel // or @@ -30,6 +30,8 @@ // If LOG_PRIVMSG then it expects a string in the format: // :from!bar@baz PRIVMSG to :hello world // +// LOG_PRIVMSG is also used for NOTICEs. +// // If LOG_JOINPART then it expects a string in the format: // :nick!bar@baz JOIN :#channel // or |