diff options
| author | 2026-03-12 02:46:14 +0000 | |
|---|---|---|
| committer | 2026-03-12 02:46:14 +0000 | |
| commit | 45f2a2ca06c8a058db1af1e41d6ee0dcfe2ab01d (patch) | |
| tree | b4cb6f88042d12df950182eda6ab35bbcacc63ae | |
| parent | Fix some missing module compat entries. (diff) | |
Rewrite old banredirect entries to the new extban form.
| -rw-r--r-- | modules/redirect.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
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) { } |
