diff options
| author | 2024-07-17 00:06:50 +0100 | |
|---|---|---|
| committer | 2024-07-17 00:06:50 +0100 | |
| commit | 889d521e05f2e922683d48c74eb00290e7a2f548 (patch) | |
| tree | b4c56bd4cdf0881601c7e4d6ff571e491af10bf4 /modules/hidelist.cpp | |
| parent | Use std::endian from C++20 in the sha1 module. (diff) | |
Shuffle the modules about a bit.
Diffstat (limited to 'modules/hidelist.cpp')
| -rw-r--r-- | modules/hidelist.cpp | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/modules/hidelist.cpp b/modules/hidelist.cpp new file mode 100644 index 000000000..c165cd8f1 --- /dev/null +++ b/modules/hidelist.cpp @@ -0,0 +1,96 @@ +/* + * InspIRCd -- Internet Relay Chat Daemon + * + * Copyright (C) 2019-2023 Sadie Powell <sadie@witchery.services> + * Copyright (C) 2018 linuxdaemon <linuxdaemon.irc@gmail.com> + * Copyright (C) 2014 Attila Molnar <attilamolnar@hush.com> + * + * This file is part of InspIRCd. InspIRCd is free software: you can + * redistribute it and/or modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation, version 2. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + + +#include "inspircd.h" +#include "numerichelper.h" + +class ListWatcher final + : public ModeWatcher +{ + // Minimum rank required to view the list + const ModeHandler::Rank minrank; + +public: + ListWatcher(Module* mod, const std::string& modename, ModeHandler::Rank rank) + : ModeWatcher(mod, modename, MODETYPE_CHANNEL) + , minrank(rank) + { + } + + bool BeforeMode(User* user, User* destuser, Channel* chan, Modes::Change& change) override + { + // Only handle listmode list requests + if (!change.param.empty()) + return true; + + // If the user requesting the list is a member of the channel see if they have the + // rank required to view the list + Membership* memb = chan->GetUser(user); + if ((memb) && (memb->GetRank() >= minrank)) + return true; + + if (user->HasPrivPermission("channels/auspex")) + return true; + + user->WriteNumeric(Numerics::ChannelPrivilegesNeeded(chan, minrank, fmt::format("view the channel {} list", GetModeName()))); + return false; + } +}; + +class ModuleHideList final + : public Module +{ + std::vector<ListWatcher*> watchers; + +public: + void ReadConfig(ConfigStatus& status) override + { + std::vector<std::pair<std::string, unsigned int>> newconfigs; + for (const auto& [_, tag] : ServerInstance->Config->ConfTags("hidelist")) + { + std::string modename = tag->getString("mode"); + if (modename.empty()) + throw ModuleException(this, "Empty <hidelist:mode> at " + tag->source.str()); + // If rank is set to 0 everyone inside the channel can view the list, + // but non-members may not + ModeHandler::Rank rank = tag->getNum<ModeHandler::Rank>("rank", HALFOP_VALUE); + newconfigs.emplace_back(modename, rank); + } + + stdalgo::delete_all(watchers); + watchers.clear(); + + for (const auto& [mode, rank] : newconfigs) + watchers.push_back(new ListWatcher(this, mode, rank)); + } + + ModuleHideList() + : Module(VF_VENDOR, "Allows list mode lists to be hidden from users without a prefix mode ranked equal to or higher than a defined level.") + { + } + + ~ModuleHideList() override + { + stdalgo::delete_all(watchers); + } +}; + +MODULE_INIT(ModuleHideList) |
