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, const char* src, const char* re, const char *nick) : XLine(Instance, s_time, d, src, re, "SVSHOLD")
28 this->nickname = nick;
37 if (u->nick == nickname)
42 bool Matches(const std::string &s)
51 ServerInstance->SNO->WriteToSnoMask('x',"Removing expired SVSHOLD %s (set by %s %ld seconds ago)", this->nickname.c_str(), this->source, (long int)(ServerInstance->Time() - this->set_time));
54 const char* Displayable()
56 return nickname.c_str();
60 /** An XLineFactory specialized to generate SVSHOLD pointers
62 class SVSHoldFactory : public XLineFactory
65 SVSHoldFactory(InspIRCd* Instance) : XLineFactory(Instance, "SVSHOLD") { }
69 XLine* Generate(time_t set_time, long duration, const char* source, const char* reason, const char* xline_specific_mask)
71 return new SVSHold(ServerInstance, set_time, duration, source, reason, xline_specific_mask);
77 class CommandSvshold : public Command
80 CommandSvshold(InspIRCd* Me) : Command(Me, "SVSHOLD", "o", 1)
82 this->source = "m_svshold.so";
83 this->syntax = "<nickname> [<duration> :<reason>]";
84 TRANSLATE4(TR_NICK, TR_TEXT, TR_TEXT, TR_END);
87 CmdResult Handle(const std::vector<std::string> ¶meters, User *user)
89 /* syntax: svshold nickname time :reason goes here */
90 /* 'time' is a human-readable timestring, like 2d3h2s. */
92 if (!ServerInstance->ULine(user->server))
94 /* don't allow SVSHOLD from non-ulined clients */
98 if (parameters.size() == 1)
100 if (ServerInstance->XLines->DelLine(parameters[0].c_str(), "SVSHOLD", user))
102 ServerInstance->SNO->WriteToSnoMask('x',"%s Removed SVSHOLD on %s.",user->nick.c_str(),parameters[0].c_str());
106 user->WriteServ("NOTICE %s :*** SVSHOLD %s not found in list, try /stats S.",user->nick.c_str(),parameters[0].c_str());
111 else if (parameters.size() >= 2)
113 // Adding - XXX todo make this respect <insane> tag perhaps..
114 long duration = ServerInstance->Duration(parameters[1]);
119 r = new SVSHold(ServerInstance, ServerInstance->Time(), duration, user->nick.c_str(), parameters[2].c_str(), parameters[0].c_str());
128 if (ServerInstance->XLines->AddLine(r, user))
130 ServerInstance->XLines->ApplyLines();
143 class ModuleSVSHold : public Module
145 CommandSvshold *mycommand;
150 ModuleSVSHold(InspIRCd* Me) : Module(Me)
152 s = new SVSHoldFactory(ServerInstance);
153 ServerInstance->XLines->RegisterFactory(s);
154 mycommand = new CommandSvshold(Me);
155 ServerInstance->AddCommand(mycommand);
156 Implementation eventlist[] = { I_OnUserPreNick, I_OnSyncOtherMetaData, I_OnDecodeMetaData, I_OnStats };
157 ServerInstance->Modules->Attach(eventlist, this, 4);
161 virtual int OnStats(char symbol, User* user, string_list &out)
166 ServerInstance->XLines->InvokeStats("SVSHOLD", 210, user, out);
170 virtual int OnUserPreNick(User *user, const std::string &newnick)
172 XLine *rl = ServerInstance->XLines->MatchesLine("SVSHOLD", newnick);
176 user->WriteServ( "432 %s %s :Services reserved nickname: %s", user->nick.c_str(), newnick.c_str(), rl->reason);
183 virtual ~ModuleSVSHold()
185 ServerInstance->XLines->DelAll("SVSHOLD");
186 ServerInstance->XLines->UnregisterFactory(s);
189 virtual Version GetVersion()
191 return Version("$Id$", VF_COMMON | VF_VENDOR, API_VERSION);
195 MODULE_INIT(ModuleSVSHold)