2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2006-2008 Robin Burchell <robin+git@viroteck.net>
5 * Copyright (C) 2008 Pippijn van Steenhoven <pip88nl@gmail.com>
6 * Copyright (C) 2006-2008 Dennis Friis <peavey@inspircd.org>
7 * Copyright (C) 2006 Craig Edwards <craigedwards@brainbox.cc>
9 * This file is part of InspIRCd. InspIRCd is free software: you can
10 * redistribute it and/or modify it under the terms of the GNU General Public
11 * License as published by the Free Software Foundation, version 2.
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 #include "modules/stats.h"
32 /** Holds a SVSHold item
34 class SVSHold : public XLine
39 SVSHold(time_t s_time, unsigned long d, const std::string& src, const std::string& re, const std::string& nick)
40 : XLine(s_time, d, src, re, "SVSHOLD")
42 this->nickname = nick;
45 bool Matches(User* u) CXX11_OVERRIDE
47 if (u->nick == nickname)
52 bool Matches(const std::string& s) CXX11_OVERRIDE
54 return InspIRCd::Match(s, nickname);
57 void DisplayExpiry() CXX11_OVERRIDE
61 ServerInstance->SNO->WriteToSnoMask('x', "Removing expired SVSHOLD %s (set by %s %ld seconds ago): %s",
62 nickname.c_str(), source.c_str(), (long)(ServerInstance->Time() - set_time), reason.c_str());
66 const std::string& Displayable() CXX11_OVERRIDE
72 /** An XLineFactory specialized to generate SVSHOLD pointers
74 class SVSHoldFactory : public XLineFactory
77 SVSHoldFactory() : XLineFactory("SVSHOLD") { }
79 /** Generate an SVSHOLD
81 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
83 return new SVSHold(set_time, duration, source, reason, xline_specific_mask);
86 bool AutoApplyToUserList(XLine* x) CXX11_OVERRIDE
94 class CommandSvshold : public Command
97 CommandSvshold(Module* Creator) : Command(Creator, "SVSHOLD", 1)
99 flags_needed = 'o'; this->syntax = "<nickname> [<duration> :<reason>]";
102 CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE
104 /* syntax: svshold nickname time :reason goes here */
105 /* 'time' is a human-readable timestring, like 2d3h2s. */
107 if (!user->server->IsULine())
109 /* don't allow SVSHOLD from non-ulined clients */
113 if (parameters.size() == 1)
117 if (ServerInstance->XLines->DelLine(parameters[0].c_str(), "SVSHOLD", reason, user))
120 ServerInstance->SNO->WriteToSnoMask('x', "%s removed SVSHOLD on %s: %s", user->nick.c_str(), parameters[0].c_str(), reason.c_str());
124 user->WriteNotice("*** SVSHOLD " + parameters[0] + " not found in list, try /stats S.");
129 if (parameters.size() < 3)
132 unsigned long duration;
133 if (!InspIRCd::Duration(parameters[1], duration))
135 user->WriteNotice("*** Invalid duration for SVSHOLD.");
138 SVSHold* r = new SVSHold(ServerInstance->Time(), duration, user->nick.c_str(), parameters[2].c_str(), parameters[0].c_str());
140 if (ServerInstance->XLines->AddLine(r, user))
147 ServerInstance->SNO->WriteGlobalSno('x', "%s added permanent SVSHOLD for %s: %s", user->nick.c_str(), parameters[0].c_str(), parameters[2].c_str());
151 time_t c_requires_crap = duration + ServerInstance->Time();
152 std::string timestr = InspIRCd::TimeString(c_requires_crap);
153 ServerInstance->SNO->WriteGlobalSno('x', "%s added timed SVSHOLD for %s, expires on %s: %s", user->nick.c_str(), parameters[0].c_str(), timestr.c_str(), parameters[2].c_str());
166 RouteDescriptor GetRouting(User* user, const Params& parameters) CXX11_OVERRIDE
168 return ROUTE_BROADCAST;
172 class ModuleSVSHold : public Module, public Stats::EventListener
180 : Stats::EventListener(this)
185 void init() CXX11_OVERRIDE
187 ServerInstance->XLines->RegisterFactory(&s);
190 void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
192 ConfigTag* tag = ServerInstance->Config->ConfValue("svshold");
193 silent = tag->getBool("silent", true);
196 ModResult OnStats(Stats::Context& stats) CXX11_OVERRIDE
198 if (stats.GetSymbol() != 'S')
199 return MOD_RES_PASSTHRU;
201 ServerInstance->XLines->InvokeStats("SVSHOLD", 210, stats);
205 ModResult OnUserPreNick(LocalUser* user, const std::string& newnick) CXX11_OVERRIDE
207 XLine *rl = ServerInstance->XLines->MatchesLine("SVSHOLD", newnick);
211 user->WriteNumeric(ERR_ERRONEUSNICKNAME, newnick, InspIRCd::Format("Services reserved nickname: %s", rl->reason.c_str()));
215 return MOD_RES_PASSTHRU;
220 ServerInstance->XLines->DelAll("SVSHOLD");
221 ServerInstance->XLines->UnregisterFactory(&s);
224 Version GetVersion() CXX11_OVERRIDE
226 return Version("Implements SVSHOLD. Like Q-lines, but can only be added/removed by Services.", VF_COMMON | VF_VENDOR);
230 MODULE_INIT(ModuleSVSHold)