From aab7a7000cff14afe4cb331721ad55dc139f80c7 Mon Sep 17 00:00:00 2001 From: Luke Bratch Date: Sun, 15 Sep 2019 15:11:55 +0100 Subject: Log nick changes to the normal log file(s). --- message.c | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) (limited to 'message.c') diff --git a/message.c b/message.c index 869a1ce..a7bef1e 100644 --- a/message.c +++ b/message.c @@ -270,7 +270,7 @@ int processservermessage(SSL *server_ssl, char *str, struct client *clients, int writereplayline(str, settings->basedir); } - // Get each channel the QUITting user was in, and log the quit from that channel + // Get each channel the QUITting user was in, and log the quit from that channel if enabled if (settings->logging) { char quitnick[MAXNICKLENGTH]; strcpy(quitnick, tokens[0]); @@ -475,11 +475,6 @@ int processservermessage(SSL *server_ssl, char *str, struct client *clients, int free(prefixcopy); } - // Update old nick to the new nick in our local channel struct - if (!updatenickinallchannels(tokens[0], tokens[2], channels)) { - debugprint(DEBUG_CRIT, "Failed to update old nick to new nick in channels.\n"); - } - // Relay to all clients sendtoallclients(clients, str, sourcefd, settings); @@ -488,8 +483,29 @@ int processservermessage(SSL *server_ssl, char *str, struct client *clients, int writereplayline(str, settings->basedir); } - // TODO - Is there a way to log nick changes to the normal log despite not tracking nicks in each channel? - // (We do track channel names themselves.) + // Get each channel the old nick was in, and log the NICK change in that channel if enabled + if (settings->logging) { + char oldnick[MAXNICKLENGTH]; + strcpy(oldnick, tokens[0]); + extractnickfromprefix(oldnick); + for (int i = 0; i < MAXCHANNELS; i++) { + if (channels[i].name[0]) { + for (int j = 0; j < MAXCHANNICKS; j++) { + if (strlen(channels[i].nicks[j]) == strlen(oldnick) && !strcmp(channels[i].nicks[j], oldnick)) { + char logstring[MAXDATASIZE]; + snprintf(logstring, MAXDATASIZE, "%s %s", channels[i].name, str); + logline(logstring, ircdstate, settings->basedir, LOG_NICK); + break; + } + } + } + } + } + + // Update old nick to the new nick in our local channel struct + if (!updatenickinallchannels(tokens[0], tokens[2], channels)) { + debugprint(DEBUG_CRIT, "Failed to update old nick to new nick in channels.\n"); + } free(svrprefixcopy); return 1; -- cgit v1.2.3