diff options
Diffstat (limited to 'replay.c')
-rw-r--r-- | replay.c | 23 |
1 files changed, 17 insertions, 6 deletions
@@ -219,19 +219,21 @@ int replaylines(int seconds, char *basedir) { } // Set 'str' to the line in the log with a timestamp of greater than 'seconds' -// seconds ago, plus however many lines 'linenum' is set to. 'basedir' is the -// directory in which to find 'replay.log'. +// 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 replaydates == 1. +// if settings.replaydates == 1. // Returns 1 on success, or 0 on failure. // TODO - This is horribly inefficient since it re-reads the entire file each call, rewrite this! -int readreplayline(int seconds, int linenum, char *str, char *basedir, int replaydates) { +int readreplayline(int seconds, int linenum, char *str, struct settings *settings, struct ircdstate *ircdstate) { FILE *fp; char line[MAXCHAR]; char filename[PATH_MAX]; // Build path - snprintf(filename, PATH_MAX, "%s/replay.log", basedir); + if (!snprintf(filename, PATH_MAX, "%s/replay.log", settings->basedir)) { + debugprint(DEBUG_CRIT, "debuglog(): Error while preparing replay path, exiting!\n"); + exit(1); + } int count = 0; @@ -257,10 +259,19 @@ int readreplayline(int seconds, int linenum, char *str, char *basedir, int repla // 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 if (count == linenum) { // Insert our formatted [HH:MM:SS] timestamp into the message - formattime(line, replaydates); + formattime(line, settings->replaydates); strncpy(str, line, strlen(line)); str[strlen(line)] = '\0'; |