2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2013-2014, 2016-2018 Attila Molnar <attilamolnar@hush.com>
5 * Copyright (C) 2013, 2017-2019 Sadie Powell <sadie@witchery.services>
6 * Copyright (C) 2012, 2019 Robby <robby@chatbelgie.be>
7 * Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
8 * Copyright (C) 2008 Robin Burchell <robin+git@viroteck.net>
9 * Copyright (C) 2007-2008, 2010 Craig Edwards <brain@inspircd.org>
10 * Copyright (C) 2007, 2009 Dennis Friis <peavey@inspircd.org>
12 * This file is part of InspIRCd. InspIRCd is free software: you can
13 * redistribute it and/or modify it under the terms of the GNU General Public
14 * License as published by the Free Software Foundation, version 2.
16 * This program is distributed in the hope that it will be useful, but WITHOUT
17 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <http://www.gnu.org/licenses/>.
27 #include "modules/exemption.h"
28 #include "modules/names.h"
29 #include "modules/who.h"
31 class AuditoriumMode : public SimpleChannelModeHandler
34 AuditoriumMode(Module* Creator) : SimpleChannelModeHandler(Creator, "auditorium", 'u')
36 ranktoset = ranktounset = OP_VALUE;
40 class ModuleAuditorium;
45 /** Hook handler for join client protocol events.
46 * This allows us to block join protocol events completely, including all associated messages (e.g. MODE, away-notify AWAY).
47 * This is not the same as OnUserJoin() because that runs only when a real join happens but this runs also when a module
48 * such as delayjoin or hostcycle generates a join.
50 class JoinHook : public ClientProtocol::EventHook
52 ModuleAuditorium* const parentmod;
56 JoinHook(ModuleAuditorium* mod);
57 void OnEventInit(const ClientProtocol::Event& ev) CXX11_OVERRIDE;
58 ModResult OnPreEventSend(LocalUser* user, const ClientProtocol::Event& ev, ClientProtocol::MessageList& messagelist) CXX11_OVERRIDE;
63 class ModuleAuditorium
65 , public Names::EventListener
66 , public Who::EventListener
68 CheckExemption::EventProvider exemptionprov;
77 : Names::EventListener(this)
78 , Who::EventListener(this)
85 void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
87 ConfigTag* tag = ServerInstance->Config->ConfValue("auditorium");
88 OpsVisible = tag->getBool("opvisible");
89 OpsCanSee = tag->getBool("opcansee");
90 OperCanSee = tag->getBool("opercansee", true);
93 Version GetVersion() CXX11_OVERRIDE
95 return Version("Provides channel mode +u, auditorium channels where nobody can see others joining and parting or the nick list", VF_VENDOR);
98 /* Can they be seen by everyone? */
99 bool IsVisible(Membership* memb)
101 if (!memb->chan->IsModeSet(&aum))
104 ModResult res = CheckExemption::Call(exemptionprov, memb->user, memb->chan, "auditorium-vis");
105 return res.check(OpsVisible && memb->getRank() >= OP_VALUE);
108 /* Can they see this specific membership? */
109 bool CanSee(User* issuer, Membership* memb)
111 // If user is oper and operoverride is on, don't touch the list
112 if (OperCanSee && issuer->HasPrivPermission("channels/auspex"))
115 // You can always see yourself
116 if (issuer == memb->user)
119 // Can you see the list by permission?
120 ModResult res = CheckExemption::Call(exemptionprov, issuer, memb->chan, "auditorium-see");
121 if (res.check(OpsCanSee && memb->chan->GetPrefixValue(issuer) >= OP_VALUE))
127 ModResult OnNamesListItem(LocalUser* issuer, Membership* memb, std::string& prefixes, std::string& nick) CXX11_OVERRIDE
130 return MOD_RES_PASSTHRU;
132 if (CanSee(issuer, memb))
133 return MOD_RES_PASSTHRU;
135 // Don't display this user in the NAMES list
139 /** Build CUList for showing this join/part/kick */
140 void BuildExcept(Membership* memb, CUList& excepts)
145 const Channel::MemberMap& users = memb->chan->GetUsers();
146 for (Channel::MemberMap::const_iterator i = users.begin(); i != users.end(); ++i)
148 if (IS_LOCAL(i->first) && !CanSee(i->first, memb))
149 excepts.insert(i->first);
153 void OnUserPart(Membership* memb, std::string &partmessage, CUList& excepts) CXX11_OVERRIDE
155 BuildExcept(memb, excepts);
158 void OnUserKick(User* source, Membership* memb, const std::string &reason, CUList& excepts) CXX11_OVERRIDE
160 BuildExcept(memb, excepts);
163 void OnBuildNeighborList(User* source, IncludeChanList& include, std::map<User*, bool>& exception) CXX11_OVERRIDE
165 for (IncludeChanList::iterator i = include.begin(); i != include.end(); )
167 Membership* memb = *i;
174 // this channel should not be considered when listing my neighbors
175 i = include.erase(i);
176 // however, that might hide me from ops that can see me...
177 const Channel::MemberMap& users = memb->chan->GetUsers();
178 for(Channel::MemberMap::const_iterator j = users.begin(); j != users.end(); ++j)
180 if (IS_LOCAL(j->first) && CanSee(j->first, memb))
181 exception[j->first] = true;
186 ModResult OnWhoLine(const Who::Request& request, LocalUser* source, User* user, Membership* memb, Numeric::Numeric& numeric) CXX11_OVERRIDE
189 return MOD_RES_PASSTHRU;
191 return MOD_RES_PASSTHRU;
192 if (CanSee(source, memb))
193 return MOD_RES_PASSTHRU;
198 JoinHook::JoinHook(ModuleAuditorium* mod)
199 : ClientProtocol::EventHook(mod, "JOIN", 10)
204 void JoinHook::OnEventInit(const ClientProtocol::Event& ev)
206 const ClientProtocol::Events::Join& join = static_cast<const ClientProtocol::Events::Join&>(ev);
207 active = !parentmod->IsVisible(join.GetMember());
210 ModResult JoinHook::OnPreEventSend(LocalUser* user, const ClientProtocol::Event& ev, ClientProtocol::MessageList& messagelist)
213 return MOD_RES_PASSTHRU;
215 const ClientProtocol::Events::Join& join = static_cast<const ClientProtocol::Events::Join&>(ev);
216 return ((parentmod->CanSee(user, join.GetMember())) ? MOD_RES_PASSTHRU : MOD_RES_DENY);
219 MODULE_INIT(ModuleAuditorium)