aboutsummaryrefslogtreecommitdiffstats
path: root/src/modules/m_sharebans.cpp
diff options
context:
space:
mode:
authorGravatar Sadie Powell2026-03-06 16:06:27 +0000
committerGravatar Sadie Powell2026-03-06 16:06:27 +0000
commit398fa0c4e626d768e7a28d4b0a0b1181b1d86a23 (patch)
tree223e4c21733f5366dd48babdf4dd9333ac61461b /src/modules/m_sharebans.cpp
parentBackport the abbreviation module checking IsUsableBy from master. (diff)
Add the sharebans module.
Diffstat (limited to 'src/modules/m_sharebans.cpp')
-rw-r--r--src/modules/m_sharebans.cpp116
1 files changed, 116 insertions, 0 deletions
diff --git a/src/modules/m_sharebans.cpp b/src/modules/m_sharebans.cpp
new file mode 100644
index 000000000..3d066bc13
--- /dev/null
+++ b/src/modules/m_sharebans.cpp
@@ -0,0 +1,116 @@
+/*
+ * InspIRCd -- Internet Relay Chat Daemon
+ *
+ * Copyright (C) 2026 Sadie Powell <sadie@witchery.services>
+ *
+ * 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 "listmode.h"
+#include "modules/extban.h"
+#include "numerichelper.h"
+
+enum
+{
+ // InspIRCd-specific.
+ ERR_BADCHANNEL = 926
+};
+
+class ShareExtBan final
+ : public ExtBan::MatchingBase
+{
+private:
+ ChanModeReference secretmode;
+ std::vector<Channel*> seen;
+
+public:
+ size_t maxdepth;
+
+ ShareExtBan(Module* mod)
+ : ExtBan::MatchingBase(mod, "share", 'b')
+ , secretmode(mod, "secret")
+ {
+ }
+
+ bool IsMatch(User* user, Channel* channel, const std::string& text) override
+ {
+ if (seen.size() >= maxdepth)
+ return false;
+
+ auto banned = false;
+ auto* targetchan = ServerInstance->Channels.Find(text);
+ if (targetchan && targetchan != channel)
+ {
+ seen.push_back(channel);
+ banned = targetchan->IsBanned(user);
+ stdalgo::erase(seen, channel);
+ }
+ return banned;
+ }
+
+ bool Validate(ListModeBase* lm, LocalUser* user, Channel* channel, std::string& text, bool inverted) override
+ {
+ auto* targetchan = ServerInstance->Channels.Find(text);
+ if (!targetchan || (targetchan->IsModeSet(secretmode) && (!targetchan->HasUser(user) && !user->HasPrivPermission("channels/auspex"))))
+ {
+ user->WriteNumeric(Numerics::NoSuchChannel(text));
+ return false;
+ }
+
+ if (targetchan == channel)
+ {
+ user->WriteNumeric(ERR_BADCHANNEL, text, "You can not create a channel ban loop.");
+ return false;
+ }
+
+ auto* memb = targetchan->GetUser(user);
+ if (!memb)
+ {
+ user->WriteNumeric(ERR_NOTONCHANNEL, targetchan->name, "You're not on that channel!");
+ return false;
+ }
+
+ const auto rank = lm->GetLevelRequired(true);
+ if (memb->GetRank() < rank)
+ {
+ user->WriteNumeric(Numerics::ChannelPrivilegesNeeded(targetchan, rank, "share bans between channels"));
+ return false;
+ }
+
+ return true;
+ }
+};
+
+class ModuleShareBans final
+ : public Module
+{
+private:
+ ShareExtBan extban;
+
+public:
+ ModuleShareBans()
+ : Module(VF_VENDOR | VF_OPTCOMMON, "Adds extended ban b: (share) which allows sharing bans between channels.")
+ , extban(this)
+ {
+ }
+
+ void ReadConfig(ConfigStatus& status) override
+ {
+ const auto& tag = ServerInstance->Config->ConfValue("sharebans");
+ extban.maxdepth = tag->getNum<size_t>("maxdepth", 2, 1, 100);
+ }
+};
+
+MODULE_INIT(ModuleShareBans)