]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_auditorium.cpp
2aebc88da6c9c002ba9fd9481307f12a88057edf
[user/henk/code/inspircd.git] / src / modules / m_auditorium.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2010 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "inspircd.h"
15
16 /* $ModDesc: Allows for auditorium channels (+u) where nobody can see others joining and parting or the nick list */
17
18 class AuditoriumMode : public ModeHandler
19 {
20  public:
21         AuditoriumMode(Module* Creator) : ModeHandler(Creator, "auditorium", 'u', PARAM_NONE, MODETYPE_CHANNEL)
22         {
23                 levelrequired = OP_VALUE;
24         }
25
26         ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding)
27         {
28                 if (channel->IsModeSet(this) == adding)
29                         return MODEACTION_DENY;
30                 channel->SetMode(this, adding);
31                 return MODEACTION_ALLOW;
32         }
33 };
34
35 class ModuleAuditorium : public Module
36 {
37  private:
38         AuditoriumMode aum;
39         bool OpsVisible;
40         bool OpsCanSee;
41         bool OperCanSee;
42  public:
43         ModuleAuditorium() : aum(this)
44         {
45         }
46
47         void init()
48         {
49                 ServerInstance->Modules->AddService(aum);
50
51                 OnRehash(NULL);
52
53                 Implementation eventlist[] = {
54                         I_OnUserJoin, I_OnUserPart, I_OnUserKick,
55                         I_OnBuildNeighborList, I_OnNamesListItem, I_OnSendWhoLine,
56                         I_OnRehash };
57                 ServerInstance->Modules->Attach(eventlist, this, 7);
58         }
59
60         ~ModuleAuditorium()
61         {
62         }
63
64         void OnRehash(User* user)
65         {
66                 ConfigTag* tag = ServerInstance->Config->ConfValue("auditorium");
67                 OpsVisible = tag->getBool("opvisible");
68                 OpsCanSee = tag->getBool("opcansee");
69                 OperCanSee = tag->getBool("opercansee", true);
70         }
71
72         Version GetVersion()
73         {
74                 return Version("Allows for auditorium channels (+u) where nobody can see others joining and parting or the nick list", VF_VENDOR);
75         }
76
77         /* Can they be seen by everyone? */
78         bool IsVisible(Membership* memb)
79         {
80                 if (!memb->chan->IsModeSet(&aum))
81                         return true;
82
83                 ModResult res = ServerInstance->OnCheckExemption(memb->user, memb->chan, "auditorium-vis");
84                 return res.check(OpsVisible && memb->getRank() >= OP_VALUE);
85         }
86
87         /* Can they see this specific membership? */
88         bool CanSee(User* issuer, Membership* memb)
89         {
90                 // If user is oper and operoverride is on, don't touch the list
91                 if (OperCanSee && issuer->HasPrivPermission("channels/auspex"))
92                         return true;
93
94                 // You can always see yourself
95                 if (issuer == memb->user)
96                         return true;
97
98                 // Can you see the list by permission?
99                 ModResult res = ServerInstance->OnCheckExemption(issuer,memb->chan,"auditorium-see");
100                 if (res.check(OpsCanSee && memb->chan->GetPrefixValue(issuer) >= OP_VALUE))
101                         return true;
102
103                 return false;
104         }
105
106         void OnNamesListItem(User* issuer, Membership* memb, std::string &prefixes, std::string &nick)
107         {
108                 // Some module already hid this from being displayed, don't bother
109                 if (nick.empty())
110                         return;
111
112                 if (IsVisible(memb))
113                         return;
114
115                 if (CanSee(issuer, memb))
116                         return;
117
118                 nick.clear();
119         }
120
121         /** Build CUList for showing this join/part/kick */
122         void BuildExcept(Membership* memb, CUList& excepts)
123         {
124                 if (IsVisible(memb))
125                         return;
126
127                 const UserMembList* users = memb->chan->GetUsers();
128                 for(UserMembCIter i = users->begin(); i != users->end(); i++)
129                 {
130                         if (IS_LOCAL(i->first) && !CanSee(i->first, memb))
131                                 excepts.insert(i->first);
132                 }
133         }
134
135         void OnUserJoin(Membership* memb, bool sync, bool created, CUList& excepts)
136         {
137                 BuildExcept(memb, excepts);
138         }
139
140         void OnUserPart(Membership* memb, std::string &partmessage, CUList& excepts)
141         {
142                 BuildExcept(memb, excepts);
143         }
144
145         void OnUserKick(User* source, Membership* memb, const std::string &reason, CUList& excepts)
146         {
147                 BuildExcept(memb, excepts);
148         }
149
150         void OnBuildNeighborList(User* source, UserChanList &include, std::map<User*,bool> &exception)
151         {
152                 UCListIter i = include.begin();
153                 while (i != include.end())
154                 {
155                         Channel* c = *i++;
156                         Membership* memb = c->GetUser(source);
157                         if (!memb || IsVisible(memb))
158                                 continue;
159                         // this channel should not be considered when listing my neighbors
160                         include.erase(c);
161                         // however, that might hide me from ops that can see me...
162                         const UserMembList* users = c->GetUsers();
163                         for(UserMembCIter j = users->begin(); j != users->end(); j++)
164                         {
165                                 if (IS_LOCAL(j->first) && CanSee(j->first, memb))
166                                         exception[j->first] = true;
167                         }
168                 }
169         }
170
171         void OnSendWhoLine(User* source, const std::vector<std::string>& params, User* user, std::string& line)
172         {
173                 Channel* channel = ServerInstance->FindChan(params[0]);
174                 if (!channel)
175                         return;
176                 Membership* memb = channel->GetUser(user);
177                 if (IsVisible(memb))
178                         return;
179                 if (CanSee(source, memb))
180                         return;
181                 line.clear();
182         }
183 };
184
185 MODULE_INIT(ModuleAuditorium)