summaryrefslogtreecommitdiff
path: root/replay.c
diff options
context:
space:
mode:
authorLuke Bratch <luke@bratch.co.uk>2019-09-07 17:25:01 +0100
committerLuke Bratch <luke@bratch.co.uk>2019-09-07 17:25:01 +0100
commit3b836818fe3626798924a56f1660ab5423998094 (patch)
tree3fe8a232fb6539ba881962d1e38a9e858fd654af /replay.c
parent6ae84b9245bfaa832f847a31952b2ae33daf2299 (diff)
Avoid more replay log NICK synchronisation issues by ignoring replay log nick changes from us if not our current nick, and by completely ignoring replaying any type of replay log line from before blabouncer was launched.
Diffstat (limited to 'replay.c')
-rw-r--r--replay.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/replay.c b/replay.c
index 412ed7c..654e170 100644
--- a/replay.c
+++ b/replay.c
@@ -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';