From 27c0ae9433571f71521cda36beeb43a529637b57 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Sun, 17 Apr 2022 12:08:57 +0100 Subject: [PATCH] Allow normalising extbans to a specific format. Also, fix canonicalisation of acting extban values. --- docs/conf/inspircd.conf.example | 9 +++++++++ include/modules/extban.h | 15 +++++++++++++++ src/coremods/core_channel/core_channel.cpp | 7 +++++++ src/coremods/core_channel/core_channel.h | 3 +++ src/coremods/core_channel/extban.cpp | 20 ++++++++++++++++++++ 5 files changed, 54 insertions(+) diff --git a/docs/conf/inspircd.conf.example b/docs/conf/inspircd.conf.example index 299ccb467..c6520e8f7 100644 --- a/docs/conf/inspircd.conf.example +++ b/docs/conf/inspircd.conf.example @@ -637,6 +637,15 @@ # in the /LIST response. Defaults to yes. modesinlist="no" + # extbanformat: The method to use for normalising extbans. Can be set + # to one of: + # - any Do not perform any extban normalisation. + # - name Normalise extbans to use their name. + # - letter Normalise extbans to use their letter. This is useful for + # if you need to keep compatibility with v3. + # Defaults to "any" if not set. + extbanformat="name" + # exemptchanops: Allows users with with a status mode to be exempt # from various channel restrictions. Possible restrictions are: # - anticaps Channel mode +B - blocks messages with too many capital diff --git a/include/modules/extban.h b/include/modules/extban.h index b90829be9..8f636d201 100644 --- a/include/modules/extban.h +++ b/include/modules/extban.h @@ -28,6 +28,18 @@ namespace ExtBan class Manager; class ManagerRef; + enum class Format + { + /** Do not perform any normalisation of extbans. */ + ANY, + + /** Normalise extbans to use their name (e.g. mute). */ + NAME, + + /** Normalise extbans to use their letter (e.g. m). */ + LETTER, + }; + /** All possible types of extban. */ enum class Type { @@ -84,6 +96,9 @@ public: */ virtual void DelExtBan(Base* extban) = 0; + /** Retrieves the method used for normalising extbans. */ + virtual Format GetFormat() const = 0; + /** Retrieves a mapping of extban letters to their associated object. */ virtual const LetterMap& GetLetterMap() const = 0; diff --git a/src/coremods/core_channel/core_channel.cpp b/src/coremods/core_channel/core_channel.cpp index 0bdb894ac..d6e72b61c 100644 --- a/src/coremods/core_channel/core_channel.cpp +++ b/src/coremods/core_channel/core_channel.cpp @@ -178,6 +178,12 @@ public: exempts[restriction] = prefix; } + ExtBan::Format newformat = optionstag->getEnum("extbanformat", ExtBan::Format::ANY, { + { "any", ExtBan::Format::ANY }, + { "name", ExtBan::Format::NAME }, + { "letter", ExtBan::Format::LETTER }, + }); + auto securitytag = ServerInstance->Config->ConfValue("security"); Invite::AnnounceState newannouncestate = securitytag->getEnum("announceinvites", Invite::ANNOUNCE_DYNAMIC, { { "all", Invite::ANNOUNCE_ALL }, @@ -192,6 +198,7 @@ public: banmode.DoRehash(); exemptions.swap(exempts); + extbanmgr.format = newformat; invapi.announceinvites = newannouncestate; joinhook.modefromuser = optionstag->getBool("cyclehostsfromuser"); diff --git a/src/coremods/core_channel/core_channel.h b/src/coremods/core_channel/core_channel.h index 2e86a2988..2d71e18b5 100644 --- a/src/coremods/core_channel/core_channel.h +++ b/src/coremods/core_channel/core_channel.h @@ -163,6 +163,8 @@ private: NameMap byname; public: + ExtBan::Format format; + ExtBanManager(Module* Creator, ModeChannelBan& bm) : ExtBan::Manager(Creator) , banmode(bm) @@ -173,6 +175,7 @@ public: void AddExtBan(ExtBan::Base* extban) override; bool Canonicalize(std::string& text) const override; void DelExtBan(ExtBan::Base* extban) override; + ExtBan::Format GetFormat() const override { return format; } const LetterMap& GetLetterMap() const override { return byletter; } const NameMap& GetNameMap() const override { return byname; } ModResult GetStatus(ExtBan::Acting* extban, User* user, Channel* channel) const override; diff --git a/src/coremods/core_channel/extban.cpp b/src/coremods/core_channel/extban.cpp index 376b6febe..f42e49b68 100644 --- a/src/coremods/core_channel/extban.cpp +++ b/src/coremods/core_channel/extban.cpp @@ -42,7 +42,27 @@ bool ExtBanManager::Canonicalize(std::string& text) const if (!extban) return false; // Looks like an extban but it isn't. + // Canonicalize the extban. + text.assign(inverted ? "!" : ""); + + switch (format) + { + case ExtBan::Format::NAME: + text.append(extban->GetName()); + break; + + case ExtBan::Format::LETTER: + text.append(1, extban->GetLetter()); + break; + + default: + text.append(xbname); + break; + } + extban->Canonicalize(xbvalue); + text.append(":").append(xbvalue); + return true; }