]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_auditorium.cpp
Add Channel* parameter to OnSendWhoLine
[user/henk/code/inspircd.git] / src / modules / m_auditorium.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
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>
8  *
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.
12  *
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
16  * details.
17  *
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/>.
20  */
21
22
23 #include "inspircd.h"
24
25 class AuditoriumMode : public SimpleChannelModeHandler
26 {
27  public:
28         AuditoriumMode(Module* Creator) : SimpleChannelModeHandler(Creator, "auditorium", 'u')
29         {
30                 levelrequired = OP_VALUE;
31         }
32 };
33
34 class ModuleAuditorium : public Module
35 {
36         AuditoriumMode aum;
37         bool OpsVisible;
38         bool OpsCanSee;
39         bool OperCanSee;
40
41  public:
42         ModuleAuditorium() : aum(this)
43         {
44         }
45
46         void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
47         {
48                 ConfigTag* tag = ServerInstance->Config->ConfValue("auditorium");
49                 OpsVisible = tag->getBool("opvisible");
50                 OpsCanSee = tag->getBool("opcansee");
51                 OperCanSee = tag->getBool("opercansee", true);
52         }
53
54         Version GetVersion() CXX11_OVERRIDE
55         {
56                 return Version("Allows for auditorium channels (+u) where nobody can see others joining and parting or the nick list", VF_VENDOR);
57         }
58
59         /* Can they be seen by everyone? */
60         bool IsVisible(Membership* memb)
61         {
62                 if (!memb->chan->IsModeSet(&aum))
63                         return true;
64
65                 ModResult res = ServerInstance->OnCheckExemption(memb->user, memb->chan, "auditorium-vis");
66                 return res.check(OpsVisible && memb->getRank() >= OP_VALUE);
67         }
68
69         /* Can they see this specific membership? */
70         bool CanSee(User* issuer, Membership* memb)
71         {
72                 // If user is oper and operoverride is on, don't touch the list
73                 if (OperCanSee && issuer->HasPrivPermission("channels/auspex"))
74                         return true;
75
76                 // You can always see yourself
77                 if (issuer == memb->user)
78                         return true;
79
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))
83                         return true;
84
85                 return false;
86         }
87
88         void OnNamesListItem(User* issuer, Membership* memb, std::string &prefixes, std::string &nick) CXX11_OVERRIDE
89         {
90                 // Some module already hid this from being displayed, don't bother
91                 if (nick.empty())
92                         return;
93
94                 if (IsVisible(memb))
95                         return;
96
97                 if (CanSee(issuer, memb))
98                         return;
99
100                 nick.clear();
101         }
102
103         /** Build CUList for showing this join/part/kick */
104         void BuildExcept(Membership* memb, CUList& excepts)
105         {
106                 if (IsVisible(memb))
107                         return;
108
109                 const UserMembList* users = memb->chan->GetUsers();
110                 for(UserMembCIter i = users->begin(); i != users->end(); i++)
111                 {
112                         if (IS_LOCAL(i->first) && !CanSee(i->first, memb))
113                                 excepts.insert(i->first);
114                 }
115         }
116
117         void OnUserJoin(Membership* memb, bool sync, bool created, CUList& excepts) CXX11_OVERRIDE
118         {
119                 BuildExcept(memb, excepts);
120         }
121
122         void OnUserPart(Membership* memb, std::string &partmessage, CUList& excepts) CXX11_OVERRIDE
123         {
124                 BuildExcept(memb, excepts);
125         }
126
127         void OnUserKick(User* source, Membership* memb, const std::string &reason, CUList& excepts) CXX11_OVERRIDE
128         {
129                 BuildExcept(memb, excepts);
130         }
131
132         void OnBuildNeighborList(User* source, IncludeChanList& include, std::map<User*, bool>& exception) CXX11_OVERRIDE
133         {
134                 for (IncludeChanList::iterator i = include.begin(); i != include.end(); )
135                 {
136                         Membership* memb = *i;
137                         if (IsVisible(memb))
138                         {
139                                 ++i;
140                                 continue;
141                         }
142
143                         // this channel should not be considered when listing my neighbors
144                         i = include.erase(i);
145                         // however, that might hide me from ops that can see me...
146                         const UserMembList* users = memb->chan->GetUsers();
147                         for(UserMembCIter j = users->begin(); j != users->end(); j++)
148                         {
149                                 if (IS_LOCAL(j->first) && CanSee(j->first, memb))
150                                         exception[j->first] = true;
151                         }
152                 }
153         }
154
155         void OnSendWhoLine(User* source, const std::vector<std::string>& params, User* user, Channel* channel, std::string& line) CXX11_OVERRIDE
156         {
157                 if (!channel)
158                         return;
159                 Membership* memb = channel->GetUser(user);
160                 if (IsVisible(memb))
161                         return;
162                 if (CanSee(source, memb))
163                         return;
164                 line.clear();
165         }
166 };
167
168 MODULE_INIT(ModuleAuditorium)