From 161aef18486a0852a6a1d63bba5d58f23558b429 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Wed, 9 Aug 2023 06:17:18 +0100 Subject: [PATCH] Add an extban for matching against an operator account. --- docs/conf/modules.conf.example | 8 +++----- src/modules/m_operchans.cpp | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/docs/conf/modules.conf.example b/docs/conf/modules.conf.example index aa9b4c4ee..77d35a8a5 100644 --- a/docs/conf/modules.conf.example +++ b/docs/conf/modules.conf.example @@ -1715,11 +1715,9 @@ # #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-# -# Oper channels mode: Adds the +O channel mode and extban O: -# to ban, except, etc. specific oper types. For example -# /MODE #channel +iI O:* is equivalent to channel mode +O, but you -# may also set +iI O:AdminTypeOnly to only allow admins. -# Modes +I and +e work in a similar fashion. +# Oper channels mode: Adds the +O channel mode which restricts channel +# access to server operators and extbans O: and o: that +# match against an oper type and oper account respectively. # #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-# diff --git a/src/modules/m_operchans.cpp b/src/modules/m_operchans.cpp index 663addb39..41995c14f 100644 --- a/src/modules/m_operchans.cpp +++ b/src/modules/m_operchans.cpp @@ -32,6 +32,28 @@ enum ERR_CANTJOINOPERSONLY = 520 }; +class OperAccountExtBan final + : public ExtBan::MatchingBase +{ +public: + OperAccountExtBan(Module* Creator) + : ExtBan::MatchingBase(Creator, "oper", 'o') + { + } + + bool IsMatch(User* user, Channel* channel, const std::string& text) override + { + // If the user is not an oper they can't match this. + if (!user->IsOper()) + return false; + + // Replace spaces with underscores as they're prohibited in mode parameters. + std::string opername(user->oper->GetName()); + std::replace(opername.begin(), opername.end(), ' ', '_'); + return InspIRCd::Match(opername, text); + } +}; + class OperTypeExtBan final : public ExtBan::MatchingBase { @@ -59,12 +81,14 @@ class ModuleOperChans final { private: SimpleChannelMode oc; + OperAccountExtBan operaccount; OperTypeExtBan opertype; public: ModuleOperChans() : Module(VF_VENDOR, "Adds channel mode O (operonly) which prevents non-server operators from joining the channel.") , oc(this, "operonly", 'O', true) + , operaccount(this) , opertype(this) { }