2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2014 Attila Molnar <attilamolnar@hush.com>
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.
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
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/>.
22 class ListWatcher : public ModeWatcher
24 // Minimum rank required to view the list
25 const unsigned int minrank;
28 ListWatcher(Module* mod, const std::string& modename, unsigned int rank)
29 : ModeWatcher(mod, modename, MODETYPE_CHANNEL)
34 bool BeforeMode(User* user, User* destuser, Channel* chan, std::string& param, bool adding) CXX11_OVERRIDE
36 // Only handle listmode list requests
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))
46 if (user->HasPrivPermission("channels/auspex"))
49 user->WriteNumeric(ERR_CHANOPRIVSNEEDED, chan->name, InspIRCd::Format("You do not have access to view the %s list", GetModeName().c_str()));
54 class ModuleHideList : public Module
56 std::vector<ListWatcher*> watchers;
59 void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
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)
66 ConfigTag* tag = i->second;
67 std::string modename = tag->getString("mode");
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));
76 stdalgo::delete_all(watchers);
79 for (NewConfigs::const_iterator i = newconfigs.begin(); i != newconfigs.end(); ++i)
80 watchers.push_back(new ListWatcher(this, i->first, i->second));
85 stdalgo::delete_all(watchers);
88 Version GetVersion() CXX11_OVERRIDE
90 return Version("Provides support for hiding the list of listmodes", VF_VENDOR);
94 MODULE_INIT(ModuleHideList)