diff options
author | Luke Bratch <luke@bratch.co.uk> | 2019-06-11 22:54:50 +0100 |
---|---|---|
committer | Luke Bratch <luke@bratch.co.uk> | 2019-06-11 22:54:50 +0100 |
commit | 511e258e901e5248e1706609ba1099507fd750ae (patch) | |
tree | 4c7ee92fbe3634e7c78579657a023948a1a6bbae /functions.c | |
parent | 9db9fb396aaf601bd00f2b62face2693307a0e16 (diff) |
Implement configurable auto replay modes. So far there is "none", "time" (auto replay the last X seconds), and "lastspoke" (auto replay everything since you last spoke).
Diffstat (limited to 'functions.c')
-rw-r--r-- | functions.c | 44 |
1 files changed, 42 insertions, 2 deletions
diff --git a/functions.c b/functions.c index 93fd52b..31dce90 100644 --- a/functions.c +++ b/functions.c @@ -734,9 +734,9 @@ int channelindex(struct channel *channels, char *name) { return -1; } -// Send the requested number of lines of replay log to the requested client +// 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 -// seconds of replay to replay. +// 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) { char outgoingmsg[MAXDATASIZE]; @@ -822,6 +822,46 @@ int doreplay(int sourcefd, int replayseconds, struct client *clients, struct set return 1; } +// Send the auto replay to the requested client, where 'sourcefd' is the client +// to send to. The type of replay will depend on the user's settings. +// Returns 1 for success or 0 for failure. +int doautoreplay(int sourcefd, struct client *clients, struct settings *settings, struct ircdstate *ircdstate, struct channel *channels) { + // If replaymode = "none" then don't send anything + if (!strncmp(settings->replaymode, "none", strlen("none"))) { + debugprint(DEBUG_FULL, "doautoreplay() requested but replaymode = \"none\".\n"); + return 1; + } + + // If replaymode = "time" then send whatever replayseconds is set to + if (!strncmp(settings->replaymode, "time", strlen("time"))) { + debugprint(DEBUG_FULL, "doautoreplay(): replaymode = \"time\", calling doreplay() with '%d' seconds.\n", settings->replayseconds); + if (!doreplay(sourcefd, settings->replayseconds, clients, settings, ircdstate, channels)) { + debugprint(DEBUG_SOME, "doautoreplay(): doreplay() returned 0, returning 0 to caller...\n"); + return 0; + } + return 1; + } + + // If replaymode = "lastspoke" then send whatever replayseconds is set to + if (!strncmp(settings->replaymode, "lastspoke", strlen("lastspoke"))) { + debugprint(DEBUG_FULL, "doautoreplay(): replaymode = \"lastspoke\".\n", settings->replayseconds); + int secondsago = lastspokesecondsago(ircdstate->ircnick, settings->basedir); + if (secondsago < 1) { + debugprint(DEBUG_SOME, "doautoreplay(): lastspokesecondsago() returned < 1, returning 0 to caller...\n"); + return 0; + } + debugprint(DEBUG_FULL, "doautoreplay(): replaymode = \"lastspoke\", sending lines from '%d' seconds ago to sourcefd '%d'.\n", secondsago, sourcefd); + if (!doreplay(sourcefd, secondsago, clients, settings, ircdstate, channels)) { + debugprint(DEBUG_SOME, "doautoreplay(): doreplay() returned 0, returning 0 to caller...\n"); + return 0; + } + return 1; + } + + // We shouldn't get here + return 0; +} + // Return a count of the number of connected clients int numclients(struct client *clients) { int count = 0; |