]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_hidelist.cpp
Convert WriteNumeric() calls to pass the parameters of the numeric as method parameters
[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)
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                 stdalgo::delete_all(watchers);
62                 watchers.clear();
63
64                 ConfigTagList tags = ServerInstance->Config->ConfTags("hidelist");
65                 for (ConfigIter i = tags.first; i != tags.second; ++i)
66                 {
67                         ConfigTag* tag = i->second;
68                         std::string modename = tag->getString("mode");
69                         // If rank is set to 0 everyone inside the channel can view the list,
70                         // but non-members may not
71                         unsigned int rank = tag->getInt("rank", HALFOP_VALUE, 0);
72                         watchers.push_back(new ListWatcher(this, modename, rank));
73                 }
74         }
75
76         ~ModuleHideList()
77         {
78                 stdalgo::delete_all(watchers);
79         }
80
81         Version GetVersion() CXX11_OVERRIDE
82         {
83                 return Version("Provides support for hiding the list of listmodes", VF_VENDOR);
84         }
85 };
86
87 MODULE_INIT(ModuleHideList)