]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_auditorium.cpp
Remove VF_COMMON from mode-provider modules (no longer needed due to better CAPAB...
[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('u') != adding)
29                 {
30                         channel->SetMode('u', adding);
31                         return MODEACTION_ALLOW;
32                 }
33                 else
34                 {
35                         return MODEACTION_DENY;
36                 }
37         }
38 };
39
40 class ModuleAuditorium : public Module
41 {
42  private:
43         AuditoriumMode aum;
44         bool ShowOps;
45         bool OperOverride;
46  public:
47         ModuleAuditorium()
48                 : aum(this)
49         {
50                 if (!ServerInstance->Modes->AddMode(&aum))
51                         throw ModuleException("Could not add new modes!");
52
53                 OnRehash(NULL);
54
55                 Implementation eventlist[] = { I_OnUserJoin, I_OnUserPart, I_OnUserKick, I_OnBuildNeighborList, I_OnNamesListItem, I_OnRehash };
56                 ServerInstance->Modules->Attach(eventlist, this, 6);
57
58         }
59
60         ~ModuleAuditorium()
61         {
62         }
63
64         void OnRehash(User* user)
65         {
66                 ConfigReader conf;
67                 ShowOps = conf.ReadFlag("auditorium", "showops", 0);
68                 OperOverride = conf.ReadFlag("auditorium", "operoverride", 0);
69         }
70
71         Version GetVersion()
72         {
73                 return Version("Allows for auditorium channels (+u) where nobody can see others joining and parting or the nick list", VF_VENDOR);
74         }
75
76         void OnNamesListItem(User* issuer, Membership* memb, std::string &prefixes, std::string &nick)
77         {
78                 if (!memb->chan->IsModeSet('u'))
79                         return;
80
81                 /* Some module hid this from being displayed, dont bother */
82                 if (nick.empty())
83                         return;
84
85                 /* If user is oper and operoverride is on, don't touch the list */
86                 if (OperOverride && issuer->HasPrivPermission("channels/auspex"))
87                         return;
88
89                 if (ShowOps && (issuer != memb->user) && (memb->getRank() < OP_VALUE))
90                 {
91                         /* Showops is set, hide all non-ops from the user, except themselves */
92                         nick.clear();
93                         return;
94                 }
95
96                 if (!ShowOps && (issuer != memb->user))
97                 {
98                         /* ShowOps is not set, hide everyone except the user whos requesting NAMES */
99                         nick.clear();
100                         return;
101                 }
102         }
103
104         void BuildExcept(Membership* memb, CUList& excepts)
105         {
106                 if (!memb->chan->IsModeSet('u'))
107                         return;
108                 if (ShowOps && memb->getRank() >= OP_VALUE)
109                         return;
110
111                 const UserMembList* users = memb->chan->GetUsers();
112                 for(UserMembCIter i = users->begin(); i != users->end(); i++)
113                 {
114                         if (i->first == memb->user || !IS_LOCAL(i->first))
115                                 continue;
116                         if (ShowOps && i->second->getRank() >= OP_VALUE)
117                                 continue;
118                         if (OperOverride && i->first->HasPrivPermission("channels/auspex"))
119                                 continue;
120                         // This is a different user in the channel, local, and not op/oper
121                         // so, hide the join from them
122                         excepts.insert(i->first);
123                 }
124         }
125         void OnUserJoin(Membership* memb, bool sync, bool created, CUList& excepts)
126         {
127                 BuildExcept(memb, excepts);
128         }
129
130         void OnUserPart(Membership* memb, std::string &partmessage, CUList& excepts)
131         {
132                 BuildExcept(memb, excepts);
133         }
134
135         void OnUserKick(User* source, Membership* memb, const std::string &reason, CUList& excepts)
136         {
137                 BuildExcept(memb, excepts);
138         }
139
140         void OnBuildNeighborList(User* source, UserChanList &include, std::map<User*,bool> &exception)
141         {
142                 UCListIter i = include.begin();
143                 while (i != include.end())
144                 {
145                         Channel* c = *i++;
146                         if (c->IsModeSet('u'))
147                                 include.erase(c);
148                 }
149         }
150 };
151
152 MODULE_INIT(ModuleAuditorium)