]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_hidelist.cpp
Sync helpop chmodes s and p with docs
[user/henk/code/inspircd.git] / src / modules / m_hidelist.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2018 linuxdaemon <linuxdaemon.irc@gmail.com>
5  *   Copyright (C) 2017-2018 Sadie Powell <sadie@witchery.services>
6  *   Copyright (C) 2014, 2016 Attila Molnar <attilamolnar@hush.com>
7  *
8  * This file is part of InspIRCd.  InspIRCd is free software: you can
9  * redistribute it and/or modify it under the terms of the GNU General Public
10  * License as published by the Free Software Foundation, version 2.
11  *
12  * This program is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
15  * details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19  */
20
21
22 #include "inspircd.h"
23
24 class ListWatcher : public ModeWatcher
25 {
26         // Minimum rank required to view the list
27         const unsigned int minrank;
28
29  public:
30         ListWatcher(Module* mod, const std::string& modename, unsigned int rank)
31                 : ModeWatcher(mod, modename, MODETYPE_CHANNEL)
32                 , minrank(rank)
33         {
34         }
35
36         bool BeforeMode(User* user, User* destuser, Channel* chan, std::string& param, bool adding) CXX11_OVERRIDE
37         {
38                 // Only handle listmode list requests
39                 if (!param.empty())
40                         return true;
41
42                 // If the user requesting the list is a member of the channel see if they have the
43                 // rank required to view the list
44                 Membership* memb = chan->GetUser(user);
45                 if ((memb) && (memb->getRank() >= minrank))
46                         return true;
47
48                 if (user->HasPrivPermission("channels/auspex"))
49                         return true;
50
51                 user->WriteNumeric(ERR_CHANOPRIVSNEEDED, chan->name, InspIRCd::Format("You do not have access to view the %s list", GetModeName().c_str()));
52                 return false;
53         }
54 };
55
56 class ModuleHideList : public Module
57 {
58         std::vector<ListWatcher*> watchers;
59
60  public:
61         void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
62         {
63                 ConfigTagList tags = ServerInstance->Config->ConfTags("hidelist");
64                 typedef std::vector<std::pair<std::string, unsigned int> > NewConfigs;
65                 NewConfigs newconfigs;
66                 for (ConfigIter i = tags.first; i != tags.second; ++i)
67                 {
68                         ConfigTag* tag = i->second;
69                         std::string modename = tag->getString("mode");
70                         if (modename.empty())
71                                 throw ModuleException("Empty <hidelist:mode> at " + tag->getTagLocation());
72                         // If rank is set to 0 everyone inside the channel can view the list,
73                         // but non-members may not
74                         unsigned int rank = tag->getUInt("rank", HALFOP_VALUE);
75                         newconfigs.push_back(std::make_pair(modename, rank));
76                 }
77
78                 stdalgo::delete_all(watchers);
79                 watchers.clear();
80
81                 for (NewConfigs::const_iterator i = newconfigs.begin(); i != newconfigs.end(); ++i)
82                         watchers.push_back(new ListWatcher(this, i->first, i->second));
83         }
84
85         ~ModuleHideList()
86         {
87                 stdalgo::delete_all(watchers);
88         }
89
90         Version GetVersion() CXX11_OVERRIDE
91         {
92                 return Version("Allows list mode lists to be hidden from users without a prefix mode ranked equal to or higher than a defined level.", VF_VENDOR);
93         }
94 };
95
96 MODULE_INIT(ModuleHideList)