aboutsummaryrefslogtreecommitdiff
path: root/src/modules/m_hidechans.cpp
diff options
context:
space:
mode:
authorGravatar Sadie Powell2022-10-13 08:35:02 +0100
committerGravatar Sadie Powell2022-10-13 08:35:02 +0100
commitf49cfd2f302354cc821ed3372af6fba200c16933 (patch)
tree43a5d48903681bf2c7e45641b1b0233d29497ea6 /src/modules/m_hidechans.cpp
parentClean up various socket-related code. (diff)
parentFix the default case in GetFirstVisibleChannel and document it. (diff)
Merge branch 'insp3' into master.
Diffstat (limited to 'src/modules/m_hidechans.cpp')
-rw-r--r--src/modules/m_hidechans.cpp42
1 files changed, 23 insertions, 19 deletions
diff --git a/src/modules/m_hidechans.cpp b/src/modules/m_hidechans.cpp
index d63da858b..312e80f67 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
@@ -40,15 +41,31 @@ public:
class ModuleHideChans 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()
: Module(VF_VENDOR, "Adds user mode I (hidechans) which hides the channels users with it set are in from their /WHOIS response.")
+ , Who::VisibleEventListener(this)
, Whois::LineEventListener(this)
, hm(this)
{
@@ -59,30 +76,17 @@ public:
AffectsOpers = ServerInstance->Config->ConfValue("hidechans")->getBool("affectsopers");
}
- ModResult OnWhoisLine(Whois::Context& whois, Numeric::Numeric& numeric) override
+ ModResult OnWhoVisible(const Who::Request& request, LocalUser* source, Membership* memb) 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) 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());
}
};