]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_hidelist.cpp
Expand searching in m_httpd_stats, add global handling of GET parameters (#1566)
[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         // Minimum rank required to view the list
25         const unsigned int minrank;
26
27  public:
28         ListWatcher(Module* mod, const std::string& modename, unsigned int rank)
29                 : ModeWatcher(mod, modename, MODETYPE_CHANNEL)
30                 , minrank(rank)
31         {
32         }
33
34         bool BeforeMode(User* user, User* destuser, Channel* chan, std::string& param, bool adding) CXX11_OVERRIDE
35         {
36                 // Only handle listmode list requests
37                 if (!param.empty())
38                         return true;
39
40                 // If the user requesting the list is a member of the channel see if they have the
41                 // rank required to view the list
42                 Membership* memb = chan->GetUser(user);
43                 if ((memb) && (memb->getRank() >= minrank))
44                         return true;
45
46                 if (user->HasPrivPermission("channels/auspex"))
47                         return true;
48
49                 user->WriteNumeric(ERR_CHANOPRIVSNEEDED, chan->name, InspIRCd::Format("You do not have access to view the %s list", GetModeName().c_str()));
50                 return false;
51         }
52 };
53
54 class ModuleHideList : public Module
55 {
56         std::vector<ListWatcher*> watchers;
57
58  public:
59         void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
60         {
61                 ConfigTagList tags = ServerInstance->Config->ConfTags("hidelist");
62                 typedef std::vector<std::pair<std::string, unsigned int> > NewConfigs;
63                 NewConfigs newconfigs;
64                 for (ConfigIter i = tags.first; i != tags.second; ++i)
65                 {
66                         ConfigTag* tag = i->second;
67                         std::string modename = tag->getString("mode");
68                         if (modename.empty())
69                                 throw ModuleException("Empty <hidelist:mode> at " + tag->getTagLocation());
70                         // If rank is set to 0 everyone inside the channel can view the list,
71                         // but non-members may not
72                         unsigned int rank = tag->getUInt("rank", HALFOP_VALUE);
73                         newconfigs.push_back(std::make_pair(modename, rank));
74                 }
75
76                 stdalgo::delete_all(watchers);
77                 watchers.clear();
78
79                 for (NewConfigs::const_iterator i = newconfigs.begin(); i != newconfigs.end(); ++i)
80                         watchers.push_back(new ListWatcher(this, i->first, i->second));
81         }
82
83         ~ModuleHideList()
84         {
85                 stdalgo::delete_all(watchers);
86         }
87
88         Version GetVersion() CXX11_OVERRIDE
89         {
90                 return Version("Provides support for hiding the list of listmodes", VF_VENDOR);
91         }
92 };
93
94 MODULE_INIT(ModuleHideList)