diff options
| author | 2022-10-07 18:12:49 +0100 | |
|---|---|---|
| committer | 2022-10-12 08:50:06 +0100 | |
| commit | 59ec1f6eb623626ecd8ba69a929a696be2339ffc (patch) | |
| tree | 379af4a22e54fc07a8edfc2462fbb87cb5abd0af /src/modules | |
| parent | Add the matched channel to the WHO request data. (diff) | |
Allow modules to control the visible channel in a WHO request.
Diffstat (limited to 'src/modules')
| -rw-r--r-- | src/modules/m_hidechans.cpp | 50 |
1 files changed, 29 insertions, 21 deletions
diff --git a/src/modules/m_hidechans.cpp b/src/modules/m_hidechans.cpp index 9a9d70507..ff8c4152a 100644 --- a/src/modules/m_hidechans.cpp +++ b/src/modules/m_hidechans.cpp @@ -24,6 +24,7 @@ #include "inspircd.h" +#include "modules/who.h" #include "modules/whois.h" /** Handles user mode +I @@ -34,13 +35,33 @@ class HideChans : public SimpleUserModeHandler HideChans(Module* Creator) : SimpleUserModeHandler(Creator, "hidechans", 'I') { } }; -class ModuleHideChans : public Module, public Whois::LineEventListener +class ModuleHideChans CXX11_FINAL + : public Module + , public Who::VisibleEventListener + , public Whois::LineEventListener { + private: bool AffectsOpers; HideChans hm; + + ModResult ShouldHideChans(LocalUser* source, User* target) + { + if (source == target) + return MOD_RES_PASSTHRU; // User is targeting themself. + + if (!target->IsModeSet(hm)) + return MOD_RES_PASSTHRU; // Mode not set on the target. + + if (!AffectsOpers && source->HasPrivPermission("users/auspex")) + return MOD_RES_PASSTHRU; // Opers aren't exempt or the oper doesn't have the right priv. + + return MOD_RES_DENY; + } + public: ModuleHideChans() - : Whois::LineEventListener(this) + : Who::VisibleEventListener(this) + , Whois::LineEventListener(this) , hm(this) { } @@ -55,30 +76,17 @@ class ModuleHideChans : public Module, public Whois::LineEventListener AffectsOpers = ServerInstance->Config->ConfValue("hidechans")->getBool("affectsopers"); } - ModResult OnWhoisLine(Whois::Context& whois, Numeric::Numeric& numeric) CXX11_OVERRIDE + ModResult OnWhoVisible(const Who::Request& request, LocalUser* source, Membership* memb) CXX11_OVERRIDE { - /* always show to self */ - if (whois.IsSelfWhois()) - return MOD_RES_PASSTHRU; + return ShouldHideChans(source, memb->user); + } - /* don't touch anything except 319 */ + ModResult OnWhoisLine(Whois::Context& whois, Numeric::Numeric& numeric) CXX11_OVERRIDE + { if (numeric.GetNumeric() != RPL_WHOISCHANNELS) return MOD_RES_PASSTHRU; - /* don't touch if -I */ - if (!whois.GetTarget()->IsModeSet(hm)) - return MOD_RES_PASSTHRU; - - /* if it affects opers, we don't care if they are opered */ - if (AffectsOpers) - return MOD_RES_DENY; - - /* doesn't affect opers, sender is opered */ - if (whois.GetSource()->HasPrivPermission("users/auspex")) - return MOD_RES_PASSTHRU; - - /* user must be opered, boned. */ - return MOD_RES_DENY; + return ShouldHideChans(whois.GetSource(), whois.GetTarget()); } }; |
