From 5f735b2570979592f61c866396f11c169b3ffb85 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Tue, 27 Feb 2024 20:32:22 +0000 Subject: Fix matching extbans on InspIRCd and implement missing matchers. --- modules/protocol/inspircd20.cpp | 4 ++-- modules/protocol/inspircd3.cpp | 38 +++++++++++++++++++++++++++++++++++--- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/modules/protocol/inspircd20.cpp b/modules/protocol/inspircd20.cpp index 361d9bf6a..9dbaf69c0 100644 --- a/modules/protocol/inspircd20.cpp +++ b/modules/protocol/inspircd20.cpp @@ -139,7 +139,7 @@ namespace InspIRCdExtban bool Matches(User *u, const Entry *e) anope_override { const Anope::string &mask = e->GetMask(); - Anope::string real_mask = mask.substr(3); + Anope::string real_mask = mask.substr(2); return Entry(this->name, real_mask).Matches(u); } @@ -156,7 +156,7 @@ namespace InspIRCdExtban { const Anope::string &mask = e->GetMask(); - Anope::string channel = mask.substr(3); + Anope::string channel = mask.substr(2); ChannelMode *cm = NULL; if (channel[0] != '#') diff --git a/modules/protocol/inspircd3.cpp b/modules/protocol/inspircd3.cpp index 55bf50735..9c11f98c5 100644 --- a/modules/protocol/inspircd3.cpp +++ b/modules/protocol/inspircd3.cpp @@ -539,6 +539,12 @@ class InspIRCdAutoOpMode : public ChannelModeList } }; +// NOTE: matchers for the following extbans have not been implemented: +// +// * class(n): data not available +// * country(G): data not available +// * gateway(w): data not available in v3 +// * realmask(a): todo class InspIRCdExtBan : public ChannelModeVirtual { char ext; @@ -577,7 +583,7 @@ namespace InspIRCdExtban bool Matches(User *u, const Entry *e) anope_override { const Anope::string &mask = e->GetMask(); - Anope::string real_mask = mask.substr(3); + Anope::string real_mask = mask.substr(2); return Entry(this->name, real_mask).Matches(u); } @@ -594,7 +600,7 @@ namespace InspIRCdExtban { const Anope::string &mask = e->GetMask(); - Anope::string channel = mask.substr(3); + Anope::string channel = mask.substr(2); ChannelMode *cm = NULL; if (channel[0] != '#') @@ -694,6 +700,25 @@ namespace InspIRCdExtban return !u->Account() && Entry("BAN", real_mask).Matches(u); } }; + + class OperTypeMatcher : public InspIRCdExtBan + { + public: + OperTypeMatcher(const Anope::string &mname, const Anope::string &mbase, char c) : InspIRCdExtBan(mname, mbase, c) + { + } + + bool Matches(User *u, const Entry *e) anope_override + { + Anope::string *opertype = u->GetExt("opertype"); + if (!opertype) + return false; // Not an operator. + + const Anope::string &mask = e->GetMask(); + Anope::string real_mask = mask.substr(2); + return Anope::Match(opertype->replace_all_cs(' ', '_'), real_mask); + } + }; } class ColonDelimitedParamMode : public ChannelModeParam @@ -1012,7 +1037,10 @@ struct IRCDMessageCapab : Message::Capab else if (mode.name.equals_cs("op")) cm = new ChannelModeStatus("OP", mode.letter, mode.symbol, mode.level); else if (mode.name.equals_cs("operonly")) + { cm = new ChannelModeOperOnly("OPERONLY", mode.letter); + ModeManager::AddChannelMode(new InspIRCdExtban::OperTypeMatcher("OPERTYPEBAN", "BAN", 'O')); + } else if (mode.name.equals_cs("operprefix")) cm = new ChannelModeStatus("OPERPREFIX", mode.letter, mode.symbol, mode.level); else if (mode.name.equals_cs("permanent")) @@ -1702,7 +1730,9 @@ struct IRCDMessageNick : IRCDMessage struct IRCDMessageOperType : IRCDMessage { - IRCDMessageOperType(Module *creator) : IRCDMessage(creator, "OPERTYPE", 0) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); SetFlag(IRCDMESSAGE_REQUIRE_USER); } + PrimitiveExtensibleItem opertype; + + IRCDMessageOperType(Module *creator) : IRCDMessage(creator, "OPERTYPE", 1), opertype(creator, "opertype") { SetFlag(IRCDMESSAGE_REQUIRE_USER); } void Run(MessageSource &source, const std::vector ¶ms) anope_override { @@ -1711,6 +1741,8 @@ struct IRCDMessageOperType : IRCDMessage User *u = source.GetUser(); if (!u->HasMode("OPER")) u->SetModesInternal(source, "+o"); + + opertype.Set(u, params[0]); } }; -- cgit