2 * InspIRCd -- Internet Relay Chat Daemon
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>
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.
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
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/>.
24 class ListWatcher : public ModeWatcher
26 // Minimum rank required to view the list
27 const unsigned int minrank;
30 ListWatcher(Module* mod, const std::string& modename, unsigned int rank)
31 : ModeWatcher(mod, modename, MODETYPE_CHANNEL)
36 bool BeforeMode(User* user, User* destuser, Channel* chan, std::string& param, bool adding) CXX11_OVERRIDE
38 // Only handle listmode list requests
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))
48 if (user->HasPrivPermission("channels/auspex"))
51 user->WriteNumeric(ERR_CHANOPRIVSNEEDED, chan->name, InspIRCd::Format("You do not have access to view the %s list", GetModeName().c_str()));
56 class ModuleHideList : public Module
58 std::vector<ListWatcher*> watchers;
61 void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
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)
68 ConfigTag* tag = i->second;
69 std::string modename = tag->getString("mode");
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));
78 stdalgo::delete_all(watchers);
81 for (NewConfigs::const_iterator i = newconfigs.begin(); i != newconfigs.end(); ++i)
82 watchers.push_back(new ListWatcher(this, i->first, i->second));
87 stdalgo::delete_all(watchers);
90 Version GetVersion() CXX11_OVERRIDE
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);
96 MODULE_INIT(ModuleHideList)