From c0b86c757c02e4bc8a28ea4b16a5a4b9d14478a4 Mon Sep 17 00:00:00 2001 From: Bram Matthys Date: Sat, 22 May 2021 14:41:57 +0200 Subject: [PATCH] Change chanmode +H parameter to show hours and days when needed and possible if it rounds off nicely, eg +H 100:7d. Note that the existing syntax is still accepted, eg +H 20:1440 and +H 20:1440m are both converted to 20:1d. With potentially higher time values this change makes the mode parameter a lot more readable. Support for translating timevalues is already in UnrealIRCd 5.0.2 and higher, so should be fine for nearly everyone. --- src/modules/chanmodes/history.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/modules/chanmodes/history.c b/src/modules/chanmodes/history.c index 94e831d4c..ee7e3b60e 100644 --- a/src/modules/chanmodes/history.c +++ b/src/modules/chanmodes/history.c @@ -410,6 +410,24 @@ int history_chanmode_is_ok(Client *client, Channel *channel, char mode, char *pa return EX_DENY; } +static void history_chanmode_helper(char *buf, size_t bufsize, int lines, long t) +{ + if ((t % 86400) == 0) + { + /* Can be represented in full days, eg "1d" */ + snprintf(buf, bufsize, "%d:%ldd", lines, t / 86400); + } else + if ((t % 3600) == 0) + { + /* Can be represented in hours, eg "8h" */ + snprintf(buf, bufsize, "%d:%ldh", lines, t / 3600); + } else + { + /* Otherwise, stick to minutes */ + snprintf(buf, bufsize, "%d:%ldm", lines, t / 60); + } +} + /** Convert channel parameter to something proper. * NOTE: client may be NULL if called for e.g. set::modes-playback-on-join */ @@ -422,7 +440,7 @@ char *history_chanmode_conv_param(char *param, Client *client) if (!history_parse_chanmode(param, &lines, &t)) return NULL; - snprintf(buf, sizeof(buf), "%d:%ldm", lines, t / 60); + history_chanmode_helper(buf, sizeof(buf), lines, t); return buf; } @@ -457,13 +475,7 @@ char *history_chanmode_get_param(void *h_in) if (!h_in) return NULL; - /* For now we convert the time to minutes for displaying purposes - * and show it as eg 5:10m. - * In a later release we can have a go at converting to '1h', '1d' - * and such, but not before most people run 5.0.2+ as otherwise you - * get desyncs in channel history retention times. - */ - snprintf(buf, sizeof(buf), "%d:%ldm", h->max_lines, h->max_time / 60); + history_chanmode_helper(buf, sizeof(buf), h->max_lines, h->max_time); return buf; }