1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2009 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
17 /* $ModDesc: Implements SVSHOLD. Like Q:Lines, but can only be added/removed by Services. */
19 /** Holds a SVSHold item
21 class SVSHold : public XLine
26 SVSHold(InspIRCd* Instance, time_t s_time, long d, std::string src, std::string re, std::string nick)
27 : XLine(Instance, s_time, d, src, re, "SVSHOLD")
29 this->nickname = nick.c_str();
38 if (u->nick == nickname)
43 bool Matches(const std::string &s)
52 ServerInstance->SNO->WriteToSnoMask('x',"Removing expired SVSHOLD %s (set by %s %ld seconds ago)",
53 this->nickname.c_str(), this->source.c_str(), (long int)(ServerInstance->Time() - this->set_time));
56 const char* Displayable()
58 return nickname.c_str();
62 /** An XLineFactory specialized to generate SVSHOLD pointers
64 class SVSHoldFactory : public XLineFactory
67 SVSHoldFactory(InspIRCd* Instance) : XLineFactory(Instance, "SVSHOLD") { }
71 XLine* Generate(time_t set_time, long duration, std::string source, std::string reason, std::string xline_specific_mask)
73 return new SVSHold(ServerInstance, set_time, duration, source, reason, xline_specific_mask);
79 class CommandSvshold : public Command
82 CommandSvshold(Module* Creator) : Command(Creator, "SVSHOLD", 1)
84 flags_needed = 'o'; this->syntax = "<nickname> [<duration> :<reason>]";
85 TRANSLATE4(TR_NICK, TR_TEXT, TR_TEXT, TR_END);
88 CmdResult Handle(const std::vector<std::string> ¶meters, User *user)
90 /* syntax: svshold nickname time :reason goes here */
91 /* 'time' is a human-readable timestring, like 2d3h2s. */
93 if (!ServerInstance->ULine(user->server))
95 /* don't allow SVSHOLD from non-ulined clients */
99 if (parameters.size() == 1)
101 if (ServerInstance->XLines->DelLine(parameters[0].c_str(), "SVSHOLD", user))
103 ServerInstance->SNO->WriteToSnoMask('x',"%s removed SVSHOLD on %s",user->nick.c_str(),parameters[0].c_str());
107 user->WriteServ("NOTICE %s :*** SVSHOLD %s not found in list, try /stats S.",user->nick.c_str(),parameters[0].c_str());
112 else if (parameters.size() >= 2)
114 // Adding - XXX todo make this respect <insane> tag perhaps..
115 long duration = ServerInstance->Duration(parameters[1]);
120 r = new SVSHold(ServerInstance, 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 ServerInstance->SNO->WriteGlobalSno('x', "%s added timed SVSHOLD for %s, expires on %s: %s", user->nick.c_str(), parameters[0].c_str(), ServerInstance->TimeString(c_requires_crap).c_str(), parameters[2].c_str());
141 ServerInstance->XLines->ApplyLines();
153 RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
155 return ROUTE_BROADCAST;
159 class ModuleSVSHold : public Module
166 ModuleSVSHold(InspIRCd* Me) : Module(Me), cmd(this), s(Me)
168 ServerInstance->XLines->RegisterFactory(&s);
169 ServerInstance->AddCommand(&cmd);
170 Implementation eventlist[] = { I_OnUserPreNick, I_OnStats };
171 ServerInstance->Modules->Attach(eventlist, this, 2);
175 virtual ModResult OnStats(char symbol, User* user, string_list &out)
178 return MOD_RES_PASSTHRU;
180 ServerInstance->XLines->InvokeStats("SVSHOLD", 210, user, out);
184 virtual ModResult OnUserPreNick(User *user, const std::string &newnick)
186 XLine *rl = ServerInstance->XLines->MatchesLine("SVSHOLD", newnick);
190 user->WriteServ( "432 %s %s :Services reserved nickname: %s", user->nick.c_str(), newnick.c_str(), rl->reason.c_str());
194 return MOD_RES_PASSTHRU;
197 virtual ~ModuleSVSHold()
199 ServerInstance->XLines->DelAll("SVSHOLD");
200 ServerInstance->XLines->UnregisterFactory(&s);
203 virtual Version GetVersion()
205 return Version("$Id$", VF_COMMON | VF_VENDOR, API_VERSION);
209 MODULE_INIT(ModuleSVSHold)