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 class AuditoriumMode : public SimpleChannelModeHandler
28 AuditoriumMode(Module* Creator) : SimpleChannelModeHandler(Creator, "auditorium", 'u')
30 levelrequired = OP_VALUE;
34 class ModuleAuditorium : public Module
42 ModuleAuditorium() : aum(this)
46 void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
48 ConfigTag* tag = ServerInstance->Config->ConfValue("auditorium");
49 OpsVisible = tag->getBool("opvisible");
50 OpsCanSee = tag->getBool("opcansee");
51 OperCanSee = tag->getBool("opercansee", true);
54 Version GetVersion() CXX11_OVERRIDE
56 return Version("Allows for auditorium channels (+u) where nobody can see others joining and parting or the nick list", VF_VENDOR);
59 /* Can they be seen by everyone? */
60 bool IsVisible(Membership* memb)
62 if (!memb->chan->IsModeSet(&aum))
65 ModResult res = ServerInstance->OnCheckExemption(memb->user, memb->chan, "auditorium-vis");
66 return res.check(OpsVisible && memb->getRank() >= OP_VALUE);
69 /* Can they see this specific membership? */
70 bool CanSee(User* issuer, Membership* memb)
72 // If user is oper and operoverride is on, don't touch the list
73 if (OperCanSee && issuer->HasPrivPermission("channels/auspex"))
76 // You can always see yourself
77 if (issuer == memb->user)
80 // Can you see the list by permission?
81 ModResult res = ServerInstance->OnCheckExemption(issuer,memb->chan,"auditorium-see");
82 if (res.check(OpsCanSee && memb->chan->GetPrefixValue(issuer) >= OP_VALUE))
88 ModResult OnNamesListItem(User* issuer, Membership* memb, std::string& prefixes, std::string& nick) CXX11_OVERRIDE
91 return MOD_RES_PASSTHRU;
93 if (CanSee(issuer, memb))
94 return MOD_RES_PASSTHRU;
96 // Don't display this user in the NAMES list
100 /** Build CUList for showing this join/part/kick */
101 void BuildExcept(Membership* memb, CUList& excepts)
106 const Channel::MemberMap& users = memb->chan->GetUsers();
107 for (Channel::MemberMap::const_iterator i = users.begin(); i != users.end(); ++i)
109 if (IS_LOCAL(i->first) && !CanSee(i->first, memb))
110 excepts.insert(i->first);
114 void OnUserJoin(Membership* memb, bool sync, bool created, CUList& excepts) CXX11_OVERRIDE
116 BuildExcept(memb, excepts);
119 void OnUserPart(Membership* memb, std::string &partmessage, CUList& excepts) CXX11_OVERRIDE
121 BuildExcept(memb, excepts);
124 void OnUserKick(User* source, Membership* memb, const std::string &reason, CUList& excepts) CXX11_OVERRIDE
126 BuildExcept(memb, excepts);
129 void OnBuildNeighborList(User* source, IncludeChanList& include, std::map<User*, bool>& exception) CXX11_OVERRIDE
131 for (IncludeChanList::iterator i = include.begin(); i != include.end(); )
133 Membership* memb = *i;
140 // this channel should not be considered when listing my neighbors
141 i = include.erase(i);
142 // however, that might hide me from ops that can see me...
143 const Channel::MemberMap& users = memb->chan->GetUsers();
144 for(Channel::MemberMap::const_iterator j = users.begin(); j != users.end(); ++j)
146 if (IS_LOCAL(j->first) && CanSee(j->first, memb))
147 exception[j->first] = true;
152 void OnSendWhoLine(User* source, const std::vector<std::string>& params, User* user, Membership* memb, std::string& line) CXX11_OVERRIDE
158 if (CanSee(source, memb))
164 MODULE_INIT(ModuleAuditorium)