From 45f2a2ca06c8a058db1af1e41d6ee0dcfe2ab01d Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Thu, 12 Mar 2026 02:46:14 +0000 Subject: Rewrite old banredirect entries to the new extban form. --- modules/redirect.cpp | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/modules/redirect.cpp b/modules/redirect.cpp index 06ffe6920..27ba422dc 100644 --- a/modules/redirect.cpp +++ b/modules/redirect.cpp @@ -149,6 +149,42 @@ public: } }; +class BanRedirect final + : public ModeWatcher +{ +private: + RedirectExtBan& redirectextban; + +public: + BanRedirect(Module* mod, RedirectExtBan& extban) + : ModeWatcher(mod, "ban", MODETYPE_CHANNEL) + , redirectextban(extban) + { + } + + bool BeforeMode(User* source, User* dest, Channel* channel, Modes::Change& change) override + { + if (!change.adding || change.param.empty() || !source->IsLocal()) + return true; // Nothing to do. + + bool xbinverted; // Unused + std::string xbname, xbvalue; // Unused + if (ExtBan::Parse(change.param, xbname, xbvalue, xbinverted)) + return true; // Don't touch extbans + + const auto pos_of_pling = change.param.find_first_of('!'); + const auto pos_of_at = change.param.find_first_of('@', pos_of_pling == std::string::npos ? 0 : pos_of_pling); + const auto pos_of_hash = change.param.find_first_of('#', pos_of_at == std::string::npos ? 0 : pos_of_at); + if (pos_of_hash != std::string::npos) + { + // Rewrite old banredirect entries from foo!bar@baz#chan to redirect:#chan:foo!bar@baz + change.param = FMT::format("{}:{}:{}", redirectextban.service_name, + change.param.substr(pos_of_hash), change.param.substr(0, pos_of_hash)); + } + return true; + } +}; + class ModuleRedirect final : public Module { @@ -165,6 +201,7 @@ private: ChanModeReference limitmode; RedirectExtBan redirectextban; RedirectMode redirectmode; + BanRedirect banredirect; ModResult HandleRedirect(LocalUser* user, Channel* chan, const std::string& reason, bool param = true) { @@ -208,6 +245,7 @@ public: , limitmode(this, "limit") , redirectextban(this) , redirectmode(this) + , banredirect(this, redirectextban) { } -- cgit v1.3.1-10-gc9f91