Merge the topiclock module into the services module.

This commit is contained in:
Sadie Powell 2024-02-27 17:07:58 +00:00
parent 118f729e86
commit c8a892005d
5 changed files with 72 additions and 114 deletions

View File

@ -2597,11 +2597,6 @@
# To use, TLINE must be in one of your oper class blocks.
#<module name="tline">
#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
# Topiclock module: implements server-side topic locking to achieve deeper
# integration with services packages.
#<module name="topiclock">
#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
# UHNAMES support module: Adds support for the IRCv3 userhost-in-names
# capability which displays the username and hostname of users in the

View File

@ -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.

View File

@ -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)

View File

@ -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"))

View File

@ -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)