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/>.
26 /* $ModDesc: Implements SVSHOLD. Like Q:Lines, but can only be added/removed by Services. */
28 /** Holds a SVSHold item
30 class SVSHold : public XLine
35 SVSHold(time_t s_time, long d, std::string src, std::string re, std::string nick)
36 : XLine(s_time, d, src, re, "SVSHOLD")
38 this->nickname = nick.c_str();
43 if (u->nick == nickname)
48 bool Matches(const std::string &s)
57 ServerInstance->SNO->WriteToSnoMask('x',"Removing expired SVSHOLD %s (set by %s %ld seconds ago)",
58 this->nickname.c_str(), this->source.c_str(), (long int)(ServerInstance->Time() - this->set_time));
61 const char* Displayable()
63 return nickname.c_str();
67 /** An XLineFactory specialized to generate SVSHOLD pointers
69 class SVSHoldFactory : public XLineFactory
72 SVSHoldFactory() : XLineFactory("SVSHOLD") { }
76 XLine* Generate(time_t set_time, long duration, std::string source, std::string reason, std::string xline_specific_mask)
78 return new SVSHold(set_time, duration, source, reason, xline_specific_mask);
81 bool AutoApplyToUserList(XLine *x)
89 class CommandSvshold : public Command
92 CommandSvshold(Module* Creator) : Command(Creator, "SVSHOLD", 1)
94 flags_needed = 'o'; this->syntax = "<nickname> [<duration> :<reason>]";
95 TRANSLATE4(TR_TEXT, TR_TEXT, TR_TEXT, TR_END);
98 CmdResult Handle(const std::vector<std::string> ¶meters, User *user)
100 /* syntax: svshold nickname time :reason goes here */
101 /* 'time' is a human-readable timestring, like 2d3h2s. */
103 if (!ServerInstance->ULine(user->server))
105 /* don't allow SVSHOLD from non-ulined clients */
109 if (parameters.size() == 1)
111 if (ServerInstance->XLines->DelLine(parameters[0].c_str(), "SVSHOLD", user))
113 ServerInstance->SNO->WriteToSnoMask('x',"%s removed SVSHOLD on %s",user->nick.c_str(),parameters[0].c_str());
117 user->WriteServ("NOTICE %s :*** SVSHOLD %s not found in list, try /stats S.",user->nick.c_str(),parameters[0].c_str());
122 if (parameters.size() < 3)
125 // Adding - XXX todo make this respect <insane> tag perhaps..
126 long duration = ServerInstance->Duration(parameters[1]);
127 SVSHold* r = new SVSHold(ServerInstance->Time(), duration, user->nick.c_str(), parameters[2].c_str(), parameters[0].c_str());
129 if (ServerInstance->XLines->AddLine(r, user))
133 ServerInstance->SNO->WriteGlobalSno('x', "%s added permanent SVSHOLD for %s: %s", user->nick.c_str(), parameters[0].c_str(), parameters[2].c_str());
137 time_t c_requires_crap = duration + ServerInstance->Time();
138 std::string timestr = ServerInstance->TimeString(c_requires_crap);
139 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());
152 RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
154 return ROUTE_BROADCAST;
158 class ModuleSVSHold : public Module
165 ModuleSVSHold() : cmd(this)
171 ServerInstance->XLines->RegisterFactory(&s);
172 ServerInstance->Modules->AddService(cmd);
173 Implementation eventlist[] = { I_OnUserPreNick, I_OnStats };
174 ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
177 virtual ModResult OnStats(char symbol, User* user, string_list &out)
180 return MOD_RES_PASSTHRU;
182 ServerInstance->XLines->InvokeStats("SVSHOLD", 210, user, out);
186 virtual ModResult OnUserPreNick(User *user, const std::string &newnick)
188 XLine *rl = ServerInstance->XLines->MatchesLine("SVSHOLD", newnick);
192 user->WriteServ( "432 %s %s :Services reserved nickname: %s", user->nick.c_str(), newnick.c_str(), rl->reason.c_str());
196 return MOD_RES_PASSTHRU;
199 virtual ~ModuleSVSHold()
201 ServerInstance->XLines->DelAll("SVSHOLD");
202 ServerInstance->XLines->UnregisterFactory(&s);
205 virtual Version GetVersion()
207 return Version("Implements SVSHOLD. Like Q:Lines, but can only be added/removed by Services.", VF_COMMON | VF_VENDOR);
211 MODULE_INIT(ModuleSVSHold)