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/>.
25 /* $ModDesc: Allows for auditorium channels (+u) where nobody can see others joining and parting or the nick list */
27 class AuditoriumMode : public ModeHandler
30 AuditoriumMode(Module* Creator) : ModeHandler(Creator, "auditorium", 'u', PARAM_NONE, MODETYPE_CHANNEL)
32 levelrequired = OP_VALUE;
35 ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding)
37 if (channel->IsModeSet(this) == adding)
38 return MODEACTION_DENY;
39 channel->SetMode(this, adding);
40 return MODEACTION_ALLOW;
44 class ModuleAuditorium : public Module
52 ModuleAuditorium() : aum(this)
56 void init() CXX11_OVERRIDE
58 ServerInstance->Modules->AddService(aum);
62 Implementation eventlist[] = {
63 I_OnUserJoin, I_OnUserPart, I_OnUserKick,
64 I_OnBuildNeighborList, I_OnNamesListItem, I_OnSendWhoLine,
66 ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
69 void OnRehash(User* user) CXX11_OVERRIDE
71 ConfigTag* tag = ServerInstance->Config->ConfValue("auditorium");
72 OpsVisible = tag->getBool("opvisible");
73 OpsCanSee = tag->getBool("opcansee");
74 OperCanSee = tag->getBool("opercansee", true);
77 Version GetVersion() CXX11_OVERRIDE
79 return Version("Allows for auditorium channels (+u) where nobody can see others joining and parting or the nick list", VF_VENDOR);
82 /* Can they be seen by everyone? */
83 bool IsVisible(Membership* memb)
85 if (!memb->chan->IsModeSet(&aum))
88 ModResult res = ServerInstance->OnCheckExemption(memb->user, memb->chan, "auditorium-vis");
89 return res.check(OpsVisible && memb->getRank() >= OP_VALUE);
92 /* Can they see this specific membership? */
93 bool CanSee(User* issuer, Membership* memb)
95 // If user is oper and operoverride is on, don't touch the list
96 if (OperCanSee && issuer->HasPrivPermission("channels/auspex"))
99 // You can always see yourself
100 if (issuer == memb->user)
103 // Can you see the list by permission?
104 ModResult res = ServerInstance->OnCheckExemption(issuer,memb->chan,"auditorium-see");
105 if (res.check(OpsCanSee && memb->chan->GetPrefixValue(issuer) >= OP_VALUE))
111 void OnNamesListItem(User* issuer, Membership* memb, std::string &prefixes, std::string &nick) CXX11_OVERRIDE
113 // Some module already hid this from being displayed, don't bother
120 if (CanSee(issuer, memb))
126 /** Build CUList for showing this join/part/kick */
127 void BuildExcept(Membership* memb, CUList& excepts)
132 const UserMembList* users = memb->chan->GetUsers();
133 for(UserMembCIter i = users->begin(); i != users->end(); i++)
135 if (IS_LOCAL(i->first) && !CanSee(i->first, memb))
136 excepts.insert(i->first);
140 void OnUserJoin(Membership* memb, bool sync, bool created, CUList& excepts) CXX11_OVERRIDE
142 BuildExcept(memb, excepts);
145 void OnUserPart(Membership* memb, std::string &partmessage, CUList& excepts) CXX11_OVERRIDE
147 BuildExcept(memb, excepts);
150 void OnUserKick(User* source, Membership* memb, const std::string &reason, CUList& excepts) CXX11_OVERRIDE
152 BuildExcept(memb, excepts);
155 void OnBuildNeighborList(User* source, UserChanList &include, std::map<User*,bool> &exception) CXX11_OVERRIDE
157 UCListIter i = include.begin();
158 while (i != include.end())
161 Membership* memb = c->GetUser(source);
162 if (!memb || IsVisible(memb))
164 // this channel should not be considered when listing my neighbors
166 // however, that might hide me from ops that can see me...
167 const UserMembList* users = c->GetUsers();
168 for(UserMembCIter j = users->begin(); j != users->end(); j++)
170 if (IS_LOCAL(j->first) && CanSee(j->first, memb))
171 exception[j->first] = true;
176 void OnSendWhoLine(User* source, const std::vector<std::string>& params, User* user, std::string& line) CXX11_OVERRIDE
178 Channel* channel = ServerInstance->FindChan(params[0]);
181 Membership* memb = channel->GetUser(user);
184 if (CanSee(source, memb))
190 MODULE_INIT(ModuleAuditorium)