2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2019 Matt Schatz <genius3000@g3k.solutions>
5 * Copyright (C) 2018 linuxdaemon <linuxdaemon.irc@gmail.com>
6 * Copyright (C) 2013, 2017-2018, 2020 Sadie Powell <sadie@witchery.services>
7 * Copyright (C) 2012, 2018-2019 Robby <robby@chatbelgie.be>
8 * Copyright (C) 2012, 2014, 2016 Attila Molnar <attilamolnar@hush.com>
9 * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
10 * Copyright (C) 2007-2008 Robin Burchell <robin+git@viroteck.net>
11 * Copyright (C) 2007-2008 Dennis Friis <peavey@inspircd.org>
12 * Copyright (C) 2006 Craig Edwards <brain@inspircd.org>
14 * This file is part of InspIRCd. InspIRCd is free software: you can
15 * redistribute it and/or modify it under the terms of the GNU General Public
16 * License as published by the Free Software Foundation, version 2.
18 * This program is distributed in the hope that it will be useful, but WITHOUT
19 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <http://www.gnu.org/licenses/>.
30 #include "modules/stats.h"
37 /** Holds a SVSHold item
39 class SVSHold : public XLine
44 SVSHold(time_t s_time, unsigned long d, const std::string& src, const std::string& re, const std::string& nick)
45 : XLine(s_time, d, src, re, "SVSHOLD")
47 this->nickname = nick;
50 bool Matches(User* u) CXX11_OVERRIDE
52 if (u->nick == nickname)
57 bool Matches(const std::string& s) CXX11_OVERRIDE
59 return InspIRCd::Match(s, nickname);
62 void DisplayExpiry() CXX11_OVERRIDE
66 ServerInstance->SNO->WriteToSnoMask('x', "Removing expired SVSHOLD %s (set by %s %s ago): %s",
67 nickname.c_str(), source.c_str(), InspIRCd::DurationString(ServerInstance->Time() - set_time).c_str(), reason.c_str());
71 const std::string& Displayable() CXX11_OVERRIDE
77 /** An XLineFactory specialized to generate SVSHOLD pointers
79 class SVSHoldFactory : public XLineFactory
82 SVSHoldFactory() : XLineFactory("SVSHOLD") { }
84 /** Generate an SVSHOLD
86 XLine* Generate(time_t set_time, unsigned long duration, const std::string& source, const std::string& reason, const std::string& xline_specific_mask) CXX11_OVERRIDE
88 return new SVSHold(set_time, duration, source, reason, xline_specific_mask);
91 bool AutoApplyToUserList(XLine* x) CXX11_OVERRIDE
99 class CommandSvshold : public Command
102 CommandSvshold(Module* Creator) : Command(Creator, "SVSHOLD", 1)
104 flags_needed = 'o'; this->syntax = "<nick> [<duration> :<reason>]";
107 CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE
109 /* syntax: svshold nickname time :reason goes here */
110 /* 'time' is a human-readable timestring, like 2d3h2s. */
112 if (!user->server->IsULine())
114 /* don't allow SVSHOLD from non-ulined clients */
118 if (parameters.size() == 1)
122 if (ServerInstance->XLines->DelLine(parameters[0].c_str(), "SVSHOLD", reason, user))
125 ServerInstance->SNO->WriteToSnoMask('x', "%s removed SVSHOLD on %s: %s", user->nick.c_str(), parameters[0].c_str(), reason.c_str());
129 user->WriteNotice("*** SVSHOLD " + parameters[0] + " not found on the list.");
134 if (parameters.size() < 3)
137 unsigned long duration;
138 if (!InspIRCd::Duration(parameters[1], duration))
140 user->WriteNotice("*** Invalid duration for SVSHOLD.");
143 SVSHold* r = new SVSHold(ServerInstance->Time(), duration, user->nick.c_str(), parameters[2].c_str(), parameters[0].c_str());
145 if (ServerInstance->XLines->AddLine(r, user))
152 ServerInstance->SNO->WriteGlobalSno('x', "%s added permanent SVSHOLD for %s: %s", user->nick.c_str(), parameters[0].c_str(), parameters[2].c_str());
156 ServerInstance->SNO->WriteGlobalSno('x', "%s added timed SVSHOLD for %s, expires in %s (on %s): %s",
157 user->nick.c_str(), parameters[0].c_str(), InspIRCd::DurationString(duration).c_str(),
158 InspIRCd::TimeString(ServerInstance->Time() + duration).c_str(), parameters[2].c_str());
171 RouteDescriptor GetRouting(User* user, const Params& parameters) CXX11_OVERRIDE
173 return ROUTE_BROADCAST;
177 class ModuleSVSHold : public Module, public Stats::EventListener
185 : Stats::EventListener(this)
190 void init() CXX11_OVERRIDE
192 ServerInstance->XLines->RegisterFactory(&s);
195 void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
197 ConfigTag* tag = ServerInstance->Config->ConfValue("svshold");
198 silent = tag->getBool("silent", true);
201 ModResult OnStats(Stats::Context& stats) CXX11_OVERRIDE
203 if (stats.GetSymbol() != 'S')
204 return MOD_RES_PASSTHRU;
206 ServerInstance->XLines->InvokeStats("SVSHOLD", stats);
210 ModResult OnUserPreNick(LocalUser* user, const std::string& newnick) CXX11_OVERRIDE
212 XLine *rl = ServerInstance->XLines->MatchesLine("SVSHOLD", newnick);
216 user->WriteNumeric(ERR_ERRONEUSNICKNAME, newnick, InspIRCd::Format("Services reserved nickname: %s", rl->reason.c_str()));
220 return MOD_RES_PASSTHRU;
225 ServerInstance->XLines->DelAll("SVSHOLD");
226 ServerInstance->XLines->UnregisterFactory(&s);
229 Version GetVersion() CXX11_OVERRIDE
231 return Version("Adds the /SVSHOLD command which allows services to reserve nicknames.", VF_COMMON | VF_VENDOR);
235 MODULE_INIT(ModuleSVSHold)