2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
5 * Copyright (C) 2007-2008 Craig Edwards <craigedwards@brainbox.cc>
6 * Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
7 * Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
9 * This file is part of InspIRCd. InspIRCd is free software: you can
10 * redistribute it and/or modify it under the terms of the GNU General Public
11 * License as published by the Free Software Foundation, version 2.
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include "modules/exemption.h"
25 #include "modules/names.h"
26 #include "modules/who.h"
28 class AuditoriumMode : public SimpleChannelModeHandler
31 AuditoriumMode(Module* Creator) : SimpleChannelModeHandler(Creator, "auditorium", 'u')
33 ranktoset = ranktounset = OP_VALUE;
37 class ModuleAuditorium;
42 /** Hook handler for join client protocol events.
43 * This allows us to block join protocol events completely, including all associated messages (e.g. MODE, away-notify AWAY).
44 * This is not the same as OnUserJoin() because that runs only when a real join happens but this runs also when a module
45 * such as delayjoin or hostcycle generates a join.
47 class JoinHook : public ClientProtocol::EventHook
49 ModuleAuditorium* const parentmod;
53 JoinHook(ModuleAuditorium* mod);
54 void OnEventInit(const ClientProtocol::Event& ev) CXX11_OVERRIDE;
55 ModResult OnPreEventSend(LocalUser* user, const ClientProtocol::Event& ev, ClientProtocol::MessageList& messagelist) CXX11_OVERRIDE;
60 class ModuleAuditorium
62 , public Names::EventListener
63 , public Who::EventListener
65 CheckExemption::EventProvider exemptionprov;
74 : Names::EventListener(this)
75 , Who::EventListener(this)
82 void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
84 ConfigTag* tag = ServerInstance->Config->ConfValue("auditorium");
85 OpsVisible = tag->getBool("opvisible");
86 OpsCanSee = tag->getBool("opcansee");
87 OperCanSee = tag->getBool("opercansee", true);
90 Version GetVersion() CXX11_OVERRIDE
92 return Version("Provides channel mode +u, auditorium channels where nobody can see others joining and parting or the nick list", VF_VENDOR);
95 /* Can they be seen by everyone? */
96 bool IsVisible(Membership* memb)
98 if (!memb->chan->IsModeSet(&aum))
101 ModResult res = CheckExemption::Call(exemptionprov, memb->user, memb->chan, "auditorium-vis");
102 return res.check(OpsVisible && memb->getRank() >= OP_VALUE);
105 /* Can they see this specific membership? */
106 bool CanSee(User* issuer, Membership* memb)
108 // If user is oper and operoverride is on, don't touch the list
109 if (OperCanSee && issuer->HasPrivPermission("channels/auspex"))
112 // You can always see yourself
113 if (issuer == memb->user)
116 // Can you see the list by permission?
117 ModResult res = CheckExemption::Call(exemptionprov, issuer, memb->chan, "auditorium-see");
118 if (res.check(OpsCanSee && memb->chan->GetPrefixValue(issuer) >= OP_VALUE))
124 ModResult OnNamesListItem(LocalUser* issuer, Membership* memb, std::string& prefixes, std::string& nick) CXX11_OVERRIDE
127 return MOD_RES_PASSTHRU;
129 if (CanSee(issuer, memb))
130 return MOD_RES_PASSTHRU;
132 // Don't display this user in the NAMES list
136 /** Build CUList for showing this join/part/kick */
137 void BuildExcept(Membership* memb, CUList& excepts)
142 const Channel::MemberMap& users = memb->chan->GetUsers();
143 for (Channel::MemberMap::const_iterator i = users.begin(); i != users.end(); ++i)
145 if (IS_LOCAL(i->first) && !CanSee(i->first, memb))
146 excepts.insert(i->first);
150 void OnUserPart(Membership* memb, std::string &partmessage, CUList& excepts) CXX11_OVERRIDE
152 BuildExcept(memb, excepts);
155 void OnUserKick(User* source, Membership* memb, const std::string &reason, CUList& excepts) CXX11_OVERRIDE
157 BuildExcept(memb, excepts);
160 void OnBuildNeighborList(User* source, IncludeChanList& include, std::map<User*, bool>& exception) CXX11_OVERRIDE
162 for (IncludeChanList::iterator i = include.begin(); i != include.end(); )
164 Membership* memb = *i;
171 // this channel should not be considered when listing my neighbors
172 i = include.erase(i);
173 // however, that might hide me from ops that can see me...
174 const Channel::MemberMap& users = memb->chan->GetUsers();
175 for(Channel::MemberMap::const_iterator j = users.begin(); j != users.end(); ++j)
177 if (IS_LOCAL(j->first) && CanSee(j->first, memb))
178 exception[j->first] = true;
183 ModResult OnWhoLine(const Who::Request& request, LocalUser* source, User* user, Membership* memb, Numeric::Numeric& numeric) CXX11_OVERRIDE
186 return MOD_RES_PASSTHRU;
188 return MOD_RES_PASSTHRU;
189 if (CanSee(source, memb))
190 return MOD_RES_PASSTHRU;
195 JoinHook::JoinHook(ModuleAuditorium* mod)
196 : ClientProtocol::EventHook(mod, "JOIN", 10)
201 void JoinHook::OnEventInit(const ClientProtocol::Event& ev)
203 const ClientProtocol::Events::Join& join = static_cast<const ClientProtocol::Events::Join&>(ev);
204 active = !parentmod->IsVisible(join.GetMember());
207 ModResult JoinHook::OnPreEventSend(LocalUser* user, const ClientProtocol::Event& ev, ClientProtocol::MessageList& messagelist)
210 return MOD_RES_PASSTHRU;
212 const ClientProtocol::Events::Join& join = static_cast<const ClientProtocol::Events::Join&>(ev);
213 return ((parentmod->CanSee(user, join.GetMember())) ? MOD_RES_PASSTHRU : MOD_RES_DENY);
216 MODULE_INIT(ModuleAuditorium)