diff options
author | Luke Bratch <luke@bratch.co.uk> | 2019-09-14 13:11:20 +0100 |
---|---|---|
committer | Luke Bratch <luke@bratch.co.uk> | 2019-09-14 13:11:20 +0100 |
commit | e546de81cbecac2b02d29a02d6c6fd7d0785d739 (patch) | |
tree | e6afd5fcf595d43cae9df0417c112e537991b1d0 | |
parent | 5ea442d5b8d0b9101737c7c4b7ff7cb89a1f7821 (diff) |
Handle ignoring replay messages from before we launched better to avoid misleading error messages going to clients.
-rw-r--r-- | TODO | 4 | ||||
-rw-r--r-- | functions.c | 8 | ||||
-rw-r--r-- | replay.c | 23 |
3 files changed, 18 insertions, 17 deletions
@@ -4,10 +4,6 @@ Support arrays or similar in the configuration file (for nick(s), connectcommand All the TODOs sprinkled throughout the code! -PM replay chat in a channel (or perhaps a random channel?) e.g. replay on 06/09/2019 at 17:05 from 13:49 in #insomnia - maybe a client thing. - -Ensure replayed lines don't exceed IRC message maximum length due to inserted time/datestamp. - 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.) Log QUIT messages in channels if the quitting user was in them - requires tracking users in channels. diff --git a/functions.c b/functions.c index 0a03ca9..af8d5dd 100644 --- a/functions.c +++ b/functions.c @@ -786,7 +786,7 @@ int channelindex(struct channel *channels, char *name) { } // Send the requested number of lines of replay log to the requested client. -// 'sourcefd' is the client to send to, and replayseconds is the number of +// 'sourcefd' is the client to send to, and 'replayseconds' is the number of // seconds of replay log to replay. // Returns 1 for success or 0 for failure. int doreplay(int sourcefd, int replayseconds, struct client *clients, struct settings *settings, struct ircdstate *ircdstate, struct channel *channels) { @@ -811,9 +811,13 @@ int doreplay(int sourcefd, int replayseconds, struct client *clients, struct set // Replay those lines! for (int i = 0; i < numlines; i++) { - if (!readreplayline(replayseconds, i, outgoingmsg, settings, ircdstate)) { + int ret = readreplayline(replayseconds, i, outgoingmsg, settings, ircdstate); + if (ret == 0) { debugprint(DEBUG_CRIT, "Error requesting replay line.\n"); return 0; + } else if (ret == -1) { + debugprint(DEBUG_FULL, "doreplay(): readreplayline() said to ignore replay line.\n"); + continue; } // Check if the replay line is a TOPIC, a JOIN, or a PART so we don't @@ -221,7 +221,7 @@ int replaylines(int seconds, char *basedir) { // seconds ago, plus however many lines 'linenum' is set to. // Also modify the line to include a timestamp in the form "[HH:MM:SS]", or [DD/MM/YY HH:MM:SS] // if settings.replaydates == 1. -// Returns 1 on success, or 0 on failure. +// Returns 1 on success, 0 on failure, or -1 if the line should be ignored. // TODO - This is horribly inefficient since it re-reads the entire file each call, rewrite this! int readreplayline(int seconds, int linenum, char *str, struct settings *settings, struct ircdstate *ircdstate) { FILE *fp; @@ -257,17 +257,18 @@ int readreplayline(int seconds, int linenum, char *str, struct settings *setting // If the line is within range of the requested time... if (timestamp >= timenow - seconds) { - // ...and it wasn't before blabouncer launched... - if (timestamp <= ircdstate->launchtime) { - // Don't replay if this replay line happened before blabouncer launched, - // to avoid weird synchronisation issues with uncertain events from before - // we launched. - debugprint(DEBUG_FULL, "readreplayline(): Ignoring line '%s' from before we launched.\n", line); - continue; - } - - // ...and it is the current requested line then return it + // ...and it is the current requested line... if (count == linenum) { + // ...and it wasn't before blabouncer launched... + if (timestamp < ircdstate->launchtime) { + // Don't replay if this replay line happened before blabouncer launched, + // to avoid weird synchronisation issues with uncertain events from before + // we launched. + debugprint(DEBUG_FULL, "readreplayline(): Ignoring line '%s' from before we launched.\n", line); + fclose(fp); + return -1; + } + // ...then return it // Insert our formatted [HH:MM:SS] timestamp into the message formattime(line, settings->replaydates); |