]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_hidelist.cpp
Add m_hidelist that allows hiding the lists of listmodes
[user/henk/code/inspircd.git] / src / modules / m_hidelist.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2014 Attila Molnar <attilamolnar@hush.com>
5  *
6  * This file is part of InspIRCd.  InspIRCd is free software: you can
7  * redistribute it and/or modify it under the terms of the GNU General Public
8  * License as published by the Free Software Foundation, version 2.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
13  * details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18
19
20 #include "inspircd.h"
21
22 class ListWatcher : public ModeWatcher
23 {
24  public:
25         ListWatcher(Module* mod, const std::string& modename)
26                 : ModeWatcher(mod, modename, MODETYPE_CHANNEL)
27         {
28         }
29
30         bool BeforeMode(User* user, User* destuser, Channel* chan, std::string& param, bool adding)
31         {
32                 // Only handle listmode list requests
33                 if (!param.empty())
34                         return true;
35
36                 // If the user requesting the list is a member of the channel see if they have the
37                 // rank required to view the list
38                 Membership* memb = chan->GetUser(user);
39                 if ((memb) && (memb->getRank() >= HALFOP_VALUE))
40                         return true;
41
42                 if (user->HasPrivPermission("channels/auspex"))
43                         return true;
44
45                 user->WriteNumeric(ERR_CHANOPRIVSNEEDED, "%s :You do not have access to view the %s list", chan->name.c_str(), GetModeName().c_str());
46                 return false;
47         }
48 };
49
50 class ModuleHideList : public Module
51 {
52         std::vector<ListWatcher*> watchers;
53
54  public:
55         void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
56         {
57                 stdalgo::delete_all(watchers);
58                 watchers.clear();
59
60                 ConfigTagList tags = ServerInstance->Config->ConfTags("hidelist");
61                 for (ConfigIter i = tags.first; i != tags.second; ++i)
62                 {
63                         ConfigTag* tag = i->second;
64                         std::string modename = tag->getString("mode");
65                         watchers.push_back(new ListWatcher(this, modename));
66                 }
67         }
68
69         ~ModuleHideList()
70         {
71                 stdalgo::delete_all(watchers);
72         }
73
74         Version GetVersion() CXX11_OVERRIDE
75         {
76                 return Version("Provides support for hiding the list of listmodes", VF_VENDOR);
77         }
78 };
79
80 MODULE_INIT(ModuleHideList)