aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Sadie Powell2024-02-27 17:07:58 +0000
committerGravatar Sadie Powell2024-02-27 17:44:31 +0000
commitc8a892005d53d22fdae3b565ebc033afa680568e (patch)
tree1d204d4c6e438717263098be54a410170b0259e4 /src
parentMerge the mlock module into the services module. (diff)
Merge the topiclock module into the services module.
Diffstat (limited to 'src')
-rw-r--r--src/configreader.cpp2
-rw-r--r--src/modules/m_services.cpp65
-rw-r--r--src/modules/m_spanningtree/capab.cpp6
-rw-r--r--src/modules/m_topiclock.cpp108
4 files changed, 72 insertions, 109 deletions
diff --git a/src/configreader.cpp b/src/configreader.cpp
index 144ad00d0..d18b86c99 100644
--- a/src/configreader.cpp
+++ b/src/configreader.cpp
@@ -700,6 +700,8 @@ std::vector<std::string> ServerConfig::GetModules() const
modules.push_back("services");
else if (insp::equalsci(shortname, "svshold"))
modules.push_back("services");
+ else if (insp::equalsci(shortname, "topiclock"))
+ modules.push_back("services");
else
{
// No need to rewrite this module name.
diff --git a/src/modules/m_services.cpp b/src/modules/m_services.cpp
index 3a1b27e90..1cb827c7a 100644
--- a/src/modules/m_services.cpp
+++ b/src/modules/m_services.cpp
@@ -32,6 +32,9 @@ enum
// From Charybdis.
ERR_MLOCKRESTRICTED = 742,
+
+ // InspIRCd-specific.
+ ERR_TOPICLOCK = 744,
};
class RegisteredChannel final
@@ -424,6 +427,55 @@ public:
}
};
+class CommandSVSTopic final
+ : public Command
+{
+public:
+ CommandSVSTopic(Module* mod)
+ : Command(mod, "SVSTOPIC", 1, 4)
+ {
+ access_needed = CmdAccess::SERVER;
+ allow_empty_last_param = true;
+ }
+
+ CmdResult Handle(User* user, const Params& parameters) override
+ {
+ // The command can only be executed by remote services servers.
+ if (IS_LOCAL(user) || !user->server->IsService())
+ return CmdResult::FAILURE;
+
+ auto* chan = ServerInstance->Channels.Find(parameters[0]);
+ if (!chan)
+ return CmdResult::FAILURE;
+
+ if (parameters.size() == 4)
+ {
+ // 4 parameter version, set all topic data on the channel to the ones given in the parameters.
+ time_t topicts = ConvToNum<time_t>(parameters[1]);
+ if (!topicts)
+ {
+ ServerInstance->Logs.Debug(MODNAME, "Received SVSTOPIC with a 0 topicts; dropped.");
+ return CmdResult::INVALID;
+ }
+
+ chan->SetTopic(user, parameters[3], topicts, &parameters[2]);
+ }
+ else
+ {
+ // 1 parameter version, nuke the topic
+ chan->SetTopic(user, std::string(), 0);
+ chan->setby.clear();
+ }
+
+ return CmdResult::SUCCESS;
+ }
+
+ RouteDescriptor GetRouting(User* user, const Params& parameters) override
+ {
+ return ROUTE_BROADCAST;
+ }
+};
+
class ModuleServices final
: public Module
, public Stats::EventListener
@@ -436,11 +488,13 @@ private:
ServProtect servprotectmode;
SVSHoldFactory svsholdfactory;
StringExtItem mlockext;
+ BoolExtItem topiclockext;
CommandSVSCMode svscmodecmd;
CommandSVSHold svsholdcmd;
CommandSVSJoin svsjoincmd;
CommandSVSNick svsnickcmd;
CommandSVSPart svspartcmd;
+ CommandSVSTopic svstopiccmd;
bool accountoverrideshold;
bool HandleModeLock(User* user, Channel* chan, const Modes::Change& change)
@@ -491,11 +545,13 @@ public:
, servicetag(this)
, servprotectmode(this)
, mlockext(this, "mlock", ExtensionType::CHANNEL, true)
+ , topiclockext(this, "topiclock", ExtensionType::CHANNEL, true)
, svscmodecmd(this)
, svsholdcmd(this)
, svsjoincmd(this)
, svsnickcmd(this)
, svspartcmd(this)
+ , svstopiccmd(this)
{
}
@@ -529,6 +585,15 @@ public:
return MOD_RES_PASSTHRU;
}
+ ModResult OnPreTopicChange(User* user, Channel* chan, const std::string& topic) override
+ {
+ if (!IS_LOCAL(user) || !topiclockext.Get(chan))
+ return MOD_RES_PASSTHRU; // Remote user or no topiclock.
+
+ user->WriteNumeric(ERR_TOPICLOCK, chan->name, "Topic cannot be changed as it has been locked by services!");
+ return MOD_RES_DENY;
+ }
+
ModResult OnRawMode(User* user, Channel* chan, const Modes::Change& change) override
{
if (!IS_LOCAL(user) || !chan)
diff --git a/src/modules/m_spanningtree/capab.cpp b/src/modules/m_spanningtree/capab.cpp
index 06d89e53b..84311e192 100644
--- a/src/modules/m_spanningtree/capab.cpp
+++ b/src/modules/m_spanningtree/capab.cpp
@@ -64,7 +64,11 @@ namespace
else if (insp::equalsci(modname, "m_account.so") && ServerInstance->Modules.Find("services"))
modname = "m_services_account.so";
else if (insp::equalsci(modname, "m_services.so"))
- modname = "m_svshold.so";
+ {
+ modules["m_svshold.so"];
+ modules["m_topiclock.so"];
+ continue;
+ }
// Handle modules with changed properties.
else if (insp::equalsci(modname, "m_globops.so"))
diff --git a/src/modules/m_topiclock.cpp b/src/modules/m_topiclock.cpp
deleted file mode 100644
index 7eb7f4754..000000000
--- a/src/modules/m_topiclock.cpp
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * InspIRCd -- Internet Relay Chat Daemon
- *
- * Copyright (C) 2013, 2017-2019 Sadie Powell <sadie@witchery.services>
- * Copyright (C) 2012, 2014-2016 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 "extension.h"
-
-enum
-{
- // InspIRCd-specific.
- ERR_TOPICLOCK = 744
-};
-
-class CommandSVSTOPIC final
- : public Command
-{
-public:
- CommandSVSTOPIC(Module* Creator)
- : Command(Creator, "SVSTOPIC", 1, 4)
- {
- access_needed = CmdAccess::SERVER;
- allow_empty_last_param = true;
- }
-
- CmdResult Handle(User* user, const Params& parameters) override
- {
- if (!user->server->IsService())
- {
- // Ulines only
- return CmdResult::FAILURE;
- }
-
- auto* chan = ServerInstance->Channels.Find(parameters[0]);
- if (!chan)
- return CmdResult::FAILURE;
-
- if (parameters.size() == 4)
- {
- // 4 parameter version, set all topic data on the channel to the ones given in the parameters
- time_t topicts = ConvToNum<time_t>(parameters[1]);
- if (!topicts)
- {
- ServerInstance->Logs.Debug(MODNAME, "Received SVSTOPIC with a 0 topicts, dropped.");
- return CmdResult::INVALID;
- }
-
- chan->SetTopic(user, parameters[3], topicts, &parameters[2]);
- }
- else
- {
- // 1 parameter version, nuke the topic
- chan->SetTopic(user, std::string(), 0);
- chan->setby.clear();
- }
-
- return CmdResult::SUCCESS;
- }
-
- RouteDescriptor GetRouting(User* user, const Params& parameters) override
- {
- return ROUTE_BROADCAST;
- }
-};
-
-class ModuleTopicLock final
- : public Module
-{
-private:
- CommandSVSTOPIC cmd;
- BoolExtItem topiclock;
-
-public:
- ModuleTopicLock()
- : Module(VF_VENDOR | VF_COMMON, "Allows services to lock the channel topic so that it can not be changed.")
- , cmd(this)
- , topiclock(this, "topiclock", ExtensionType::CHANNEL)
- {
- }
-
- ModResult OnPreTopicChange(User* user, Channel* chan, const std::string& topic) override
- {
- // Only fired for local users currently, but added a check anyway
- if ((IS_LOCAL(user)) && (topiclock.Get(chan)))
- {
- user->WriteNumeric(ERR_TOPICLOCK, chan->name, "TOPIC cannot be changed due to topic lock being active on the channel");
- return MOD_RES_DENY;
- }
-
- return MOD_RES_PASSTHRU;
- }
-};
-
-MODULE_INIT(ModuleTopicLock)