From 04ce8f8ed71edbf7aa69737f84eb9859063acfe8 Mon Sep 17 00:00:00 2001 From: Bram Matthys Date: Sat, 25 Mar 2023 12:19:26 +0100 Subject: [PATCH] Add helper functions --- include/h.h | 1 + src/channel.c | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/include/h.h b/include/h.h index cac8758e6..6c6b0ac8e 100644 --- a/include/h.h +++ b/include/h.h @@ -227,6 +227,7 @@ extern const char *extban_conv_param_nuh(BanContext *b, Extban *extban); extern Ban *is_banned(Client *, Channel *, int, const char **, const char **); extern Ban *is_banned_with_nick(Client *, Channel *, int, const char *, const char **, const char **); extern int ban_exists(Ban *lst, const char *str); +extern int ban_exists_ignore_time(Ban *lst, const char *str); extern Client *find_client(const char *, Client *); extern Client *find_name(const char *, Client *); diff --git a/src/channel.c b/src/channel.c index b75fbcfdb..c36f71bf8 100644 --- a/src/channel.c +++ b/src/channel.c @@ -473,6 +473,46 @@ Ban *is_banned_with_nick(Client *client, Channel *channel, int type, const char return ban; } +/** Checks if a ban already exists */ +int ban_exists(Ban *lst, const char *str) +{ + for (; lst; lst = lst->next) + if (!mycmp(lst->banstr, str)) + return 1; + return 0; +} + +/** Checks if a ban already exists - special version. + * This ignores the "~time:xx:" suffixes in the banlist. + * So it will return 1 if a ban is there for ~time:5:blah!*@* + * and you call ban_exists_ignore_time(channel->banlist, "blah!*@*") + */ +int ban_exists_ignore_time(Ban *lst, const char *str) +{ + const char *p; + + for (; lst; lst = lst->next) + { + if (!strncmp(lst->banstr, "~time:", 6)) + { + /* Special treatment for ~time:xx: */ + p = strchr(lst->banstr+6, ':'); + if (p) + { + p++; + if (!mycmp(lst->banstr, p)) + return 1; + } + } else + { + /* The simple version */ + if (!mycmp(lst->banstr, str)) + return 1; + } + } + return 0; +} + /** Add user to the channel. * This adds both the Member struct to the channel->members linked list * and also the Membership struct to the client->user->channel linked list.