]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_auditorium.cpp
Fix variable shadowing warning
[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[] = { I_OnUserJoin, I_OnUserPart, I_OnUserKick, I_OnBuildNeighborList, I_OnNamesListItem, I_OnRehash };
54                 ServerInstance->Modules->Attach(eventlist, this, 6);
55         }
56
57         ~ModuleAuditorium()
58         {
59         }
60
61         void OnRehash(User* user)
62         {
63                 ConfigTag* tag = ServerInstance->Config->ConfValue("auditorium");
64                 OpsVisible = tag->getBool("opvisible");
65                 OpsCanSee = tag->getBool("opcansee");
66                 OperCanSee = tag->getBool("opercansee", true);
67         }
68
69         Version GetVersion()
70         {
71                 return Version("Allows for auditorium channels (+u) where nobody can see others joining and parting or the nick list", VF_VENDOR);
72         }
73
74         /* Can they be seen by everyone? */
75         bool IsVisible(Membership* memb)
76         {
77                 if (!memb->chan->IsModeSet(&aum))
78                         return true;
79
80                 ModResult res = ServerInstance->OnCheckExemption(memb->user, memb->chan, "auditorium-vis");
81                 return res.check(OpsVisible && memb->getRank() >= OP_VALUE);
82         }
83
84         /* Can they see this specific membership? */
85         bool CanSee(User* issuer, Membership* memb)
86         {
87                 // If user is oper and operoverride is on, don't touch the list
88                 if (OperCanSee && issuer->HasPrivPermission("channels/auspex"))
89                         return true;
90
91                 // You can always see yourself
92                 if (issuer == memb->user)
93                         return true;
94
95                 // Can you see the list by permission?
96                 ModResult res = ServerInstance->OnCheckExemption(issuer,memb->chan,"auditorium-see");
97                 if (res.check(OpsCanSee && memb->chan->GetPrefixValue(issuer) >= OP_VALUE))
98                         return true;
99
100                 return false;
101         }
102
103         void OnNamesListItem(User* issuer, Membership* memb, std::string &prefixes, std::string &nick)
104         {
105                 // Some module already hid this from being displayed, don't bother
106                 if (nick.empty())
107                         return;
108
109                 if (IsVisible(memb))
110                         return;
111
112                 if (CanSee(issuer, memb))
113                         return;
114
115                 nick.clear();
116         }
117
118         /** Build CUList for showing this join/part/kick */
119         void BuildExcept(Membership* memb, CUList& excepts)
120         {
121                 if (IsVisible(memb))
122                         return;
123
124                 const UserMembList* users = memb->chan->GetUsers();
125                 for(UserMembCIter i = users->begin(); i != users->end(); i++)
126                 {
127                         if (IS_LOCAL(i->first) && !CanSee(i->first, memb))
128                                 excepts.insert(i->first);
129                 }
130         }
131
132         void OnUserJoin(Membership* memb, bool sync, bool created, CUList& excepts)
133         {
134                 BuildExcept(memb, excepts);
135         }
136
137         void OnUserPart(Membership* memb, std::string &partmessage, CUList& excepts)
138         {
139                 BuildExcept(memb, excepts);
140         }
141
142         void OnUserKick(User* source, Membership* memb, const std::string &reason, CUList& excepts)
143         {
144                 BuildExcept(memb, excepts);
145         }
146
147         void OnBuildNeighborList(User* source, UserChanList &include, std::map<User*,bool> &exception)
148         {
149                 UCListIter i = include.begin();
150                 while (i != include.end())
151                 {
152                         Channel* c = *i++;
153                         Membership* memb = c->GetUser(source);
154                         if (!memb || IsVisible(memb))
155                                 continue;
156                         // this channel should not be considered when listing my neighbors
157                         include.erase(c);
158                         // however, that might hide me from ops that can see me...
159                         const UserMembList* users = c->GetUsers();
160                         for(UserMembCIter j = users->begin(); j != users->end(); j++)
161                         {
162                                 if (IS_LOCAL(j->first) && CanSee(j->first, memb))
163                                         exception[j->first] = true;
164                         }
165                 }
166         }
167 };
168
169 MODULE_INIT(ModuleAuditorium)