X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_auditorium.cpp;h=0e18d3e36444f22348016b125b48416964a6723f;hb=7cfeb971666b3a6709fe61bd01478697e6433f50;hp=cd257eff3237ebb1c294e4fb0be881f6c80d9aa0;hpb=81027f3a0888ac4c8e3fb6ea90081492defce946;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_auditorium.cpp b/src/modules/m_auditorium.cpp index cd257eff3..0e18d3e36 100644 --- a/src/modules/m_auditorium.cpp +++ b/src/modules/m_auditorium.cpp @@ -1,10 +1,13 @@ /* * InspIRCd -- Internet Relay Chat Daemon * + * Copyright (C) 2013-2014, 2016, 2018 Attila Molnar + * Copyright (C) 2013, 2017-2019 Sadie Powell + * Copyright (C) 2012, 2019 Robby * Copyright (C) 2009-2010 Daniel De Graaf - * Copyright (C) 2007-2008 Craig Edwards - * Copyright (C) 2007 Dennis Friis - * Copyright (C) 2007 Robin Burchell + * Copyright (C) 2008 Robin Burchell + * Copyright (C) 2007-2008, 2010 Craig Edwards + * Copyright (C) 2007, 2009 Dennis Friis * * This file is part of InspIRCd. InspIRCd is free software: you can * redistribute it and/or modify it under the terms of the GNU General Public @@ -22,28 +25,60 @@ #include "inspircd.h" #include "modules/exemption.h" +#include "modules/names.h" +#include "modules/who.h" class AuditoriumMode : public SimpleChannelModeHandler { public: AuditoriumMode(Module* Creator) : SimpleChannelModeHandler(Creator, "auditorium", 'u') { - levelrequired = OP_VALUE; + ranktoset = ranktounset = OP_VALUE; } }; -class ModuleAuditorium : public Module +class ModuleAuditorium; + +namespace +{ + +/** Hook handler for join client protocol events. + * This allows us to block join protocol events completely, including all associated messages (e.g. MODE, away-notify AWAY). + * This is not the same as OnUserJoin() because that runs only when a real join happens but this runs also when a module + * such as delayjoin or hostcycle generates a join. + */ +class JoinHook : public ClientProtocol::EventHook +{ + ModuleAuditorium* const parentmod; + bool active; + + public: + JoinHook(ModuleAuditorium* mod); + void OnEventInit(const ClientProtocol::Event& ev) CXX11_OVERRIDE; + ModResult OnPreEventSend(LocalUser* user, const ClientProtocol::Event& ev, ClientProtocol::MessageList& messagelist) CXX11_OVERRIDE; +}; + +} + +class ModuleAuditorium + : public Module + , public Names::EventListener + , public Who::EventListener { CheckExemption::EventProvider exemptionprov; AuditoriumMode aum; bool OpsVisible; bool OpsCanSee; bool OperCanSee; + JoinHook joinhook; public: ModuleAuditorium() - : exemptionprov(this) + : Names::EventListener(this) + , Who::EventListener(this) + , exemptionprov(this) , aum(this) + , joinhook(this) { } @@ -57,7 +92,7 @@ class ModuleAuditorium : public Module Version GetVersion() CXX11_OVERRIDE { - return Version("Allows for auditorium channels (+u) where nobody can see others joining and parting or the nick list", VF_VENDOR); + return Version("Adds channel mode u (auditorium) which hides unprivileged users in a channel from each other.", VF_VENDOR); } /* Can they be seen by everyone? */ @@ -66,8 +101,7 @@ class ModuleAuditorium : public Module if (!memb->chan->IsModeSet(&aum)) return true; - ModResult res; - FIRST_MOD_RESULT_CUSTOM(exemptionprov, CheckExemption::EventListener, OnCheckExemption, res, (memb->user, memb->chan, "auditorium-vis")); + ModResult res = CheckExemption::Call(exemptionprov, memb->user, memb->chan, "auditorium-vis"); return res.check(OpsVisible && memb->getRank() >= OP_VALUE); } @@ -83,15 +117,14 @@ class ModuleAuditorium : public Module return true; // Can you see the list by permission? - ModResult res; - FIRST_MOD_RESULT_CUSTOM(exemptionprov, CheckExemption::EventListener, OnCheckExemption, res, (issuer, memb->chan, "auditorium-see")); + ModResult res = CheckExemption::Call(exemptionprov, issuer, memb->chan, "auditorium-see"); if (res.check(OpsCanSee && memb->chan->GetPrefixValue(issuer) >= OP_VALUE)) return true; return false; } - ModResult OnNamesListItem(User* issuer, Membership* memb, std::string& prefixes, std::string& nick) CXX11_OVERRIDE + ModResult OnNamesListItem(LocalUser* issuer, Membership* memb, std::string& prefixes, std::string& nick) CXX11_OVERRIDE { if (IsVisible(memb)) return MOD_RES_PASSTHRU; @@ -117,11 +150,6 @@ class ModuleAuditorium : public Module } } - void OnUserJoin(Membership* memb, bool sync, bool created, CUList& excepts) CXX11_OVERRIDE - { - BuildExcept(memb, excepts); - } - void OnUserPart(Membership* memb, std::string &partmessage, CUList& excepts) CXX11_OVERRIDE { BuildExcept(memb, excepts); @@ -155,7 +183,7 @@ class ModuleAuditorium : public Module } } - ModResult OnSendWhoLine(User* source, const std::vector& params, User* user, Membership* memb, Numeric::Numeric& numeric) CXX11_OVERRIDE + ModResult OnWhoLine(const Who::Request& request, LocalUser* source, User* user, Membership* memb, Numeric::Numeric& numeric) CXX11_OVERRIDE { if (!memb) return MOD_RES_PASSTHRU; @@ -167,4 +195,25 @@ class ModuleAuditorium : public Module } }; +JoinHook::JoinHook(ModuleAuditorium* mod) + : ClientProtocol::EventHook(mod, "JOIN", 10) + , parentmod(mod) +{ +} + +void JoinHook::OnEventInit(const ClientProtocol::Event& ev) +{ + const ClientProtocol::Events::Join& join = static_cast(ev); + active = !parentmod->IsVisible(join.GetMember()); +} + +ModResult JoinHook::OnPreEventSend(LocalUser* user, const ClientProtocol::Event& ev, ClientProtocol::MessageList& messagelist) +{ + if (!active) + return MOD_RES_PASSTHRU; + + const ClientProtocol::Events::Join& join = static_cast(ev); + return ((parentmod->CanSee(user, join.GetMember())) ? MOD_RES_PASSTHRU : MOD_RES_DENY); +} + MODULE_INIT(ModuleAuditorium)