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, 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)",
62 nickname.c_str(), source.c_str(), (long)(ServerInstance->Time() - set_time));
66 const std::string& Displayable() CXX11_OVERRIDE
72 /** An XLineFactory specialized to generate SVSHOLD pointers
74 class SVSHoldFactory : public XLineFactory
77 SVSHoldFactory() : XLineFactory("SVSHOLD") { }
81 XLine* Generate(time_t set_time, long duration, std::string source, std::string reason, 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)
115 if (ServerInstance->XLines->DelLine(parameters[0].c_str(), "SVSHOLD", user))
118 ServerInstance->SNO->WriteToSnoMask('x',"%s removed SVSHOLD on %s",user->nick.c_str(),parameters[0].c_str());
122 user->WriteNotice("*** SVSHOLD " + parameters[0] + " not found in list, try /stats S.");
127 if (parameters.size() < 3)
130 unsigned long duration = InspIRCd::Duration(parameters[1]);
131 SVSHold* r = new SVSHold(ServerInstance->Time(), duration, user->nick.c_str(), parameters[2].c_str(), parameters[0].c_str());
133 if (ServerInstance->XLines->AddLine(r, user))
140 ServerInstance->SNO->WriteGlobalSno('x', "%s added permanent SVSHOLD for %s: %s", user->nick.c_str(), parameters[0].c_str(), parameters[2].c_str());
144 time_t c_requires_crap = duration + ServerInstance->Time();
145 std::string timestr = InspIRCd::TimeString(c_requires_crap);
146 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());
159 RouteDescriptor GetRouting(User* user, const Params& parameters) CXX11_OVERRIDE
161 return ROUTE_BROADCAST;
165 class ModuleSVSHold : public Module, public Stats::EventListener
173 : Stats::EventListener(this)
178 void init() CXX11_OVERRIDE
180 ServerInstance->XLines->RegisterFactory(&s);
183 void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
185 ConfigTag* tag = ServerInstance->Config->ConfValue("svshold");
186 silent = tag->getBool("silent", true);
189 ModResult OnStats(Stats::Context& stats) CXX11_OVERRIDE
191 if (stats.GetSymbol() != 'S')
192 return MOD_RES_PASSTHRU;
194 ServerInstance->XLines->InvokeStats("SVSHOLD", 210, stats);
198 ModResult OnUserPreNick(LocalUser* user, const std::string& newnick) CXX11_OVERRIDE
200 XLine *rl = ServerInstance->XLines->MatchesLine("SVSHOLD", newnick);
204 user->WriteNumeric(ERR_ERRONEUSNICKNAME, newnick, InspIRCd::Format("Services reserved nickname: %s", rl->reason.c_str()));
208 return MOD_RES_PASSTHRU;
213 ServerInstance->XLines->DelAll("SVSHOLD");
214 ServerInstance->XLines->UnregisterFactory(&s);
217 Version GetVersion() CXX11_OVERRIDE
219 return Version("Implements SVSHOLD. Like Q:Lines, but can only be added/removed by Services.", VF_COMMON | VF_VENDOR);
223 MODULE_INIT(ModuleSVSHold)