]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_svshold.cpp
Remove CMD_LOCALONLY, enforce use of GetRouting for routed commands
[user/henk/code/inspircd.git] / src / modules / m_svshold.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "inspircd.h"
15 #include "xline.h"
16
17 /* $ModDesc: Implements SVSHOLD. Like Q:Lines, but can only be added/removed by Services. */
18
19 /** Holds a SVSHold item
20  */
21 class SVSHold : public XLine
22 {
23 public:
24         irc::string nickname;
25
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")
28         {
29                 this->nickname = nick.c_str();
30         }
31
32         ~SVSHold()
33         {
34         }
35
36         bool Matches(User *u)
37         {
38                 if (u->nick == nickname)
39                         return true;
40                 return false;
41         }
42
43         bool Matches(const std::string &s)
44         {
45                 if (nickname == s)
46                         return true;
47                 return false;
48         }
49
50         void DisplayExpiry()
51         {
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));
54         }
55
56         const char* Displayable()
57         {
58                 return nickname.c_str();
59         }
60 };
61
62 /** An XLineFactory specialized to generate SVSHOLD pointers
63  */
64 class SVSHoldFactory : public XLineFactory
65 {
66  public:
67         SVSHoldFactory(InspIRCd* Instance) : XLineFactory(Instance, "SVSHOLD") { }
68
69         /** Generate a shun
70         */
71         XLine* Generate(time_t set_time, long duration, std::string source, std::string reason, std::string xline_specific_mask)
72         {
73                 return new SVSHold(ServerInstance, set_time, duration, source, reason, xline_specific_mask);
74         }
75 };
76
77 /** Handle /SVSHold
78  */
79 class CommandSvshold : public Command
80 {
81  public:
82         CommandSvshold(InspIRCd* Me, Module* Creator) : Command(Me, Creator, "SVSHOLD", "o", 1)
83         {
84                 this->syntax = "<nickname> [<duration> :<reason>]";
85                 TRANSLATE4(TR_NICK, TR_TEXT, TR_TEXT, TR_END);
86         }
87
88         CmdResult Handle(const std::vector<std::string> &parameters, User *user)
89         {
90                 /* syntax: svshold nickname time :reason goes here */
91                 /* 'time' is a human-readable timestring, like 2d3h2s. */
92
93                 if (!ServerInstance->ULine(user->server))
94                 {
95                         /* don't allow SVSHOLD from non-ulined clients */
96                         return CMD_FAILURE;
97                 }
98
99                 if (parameters.size() == 1)
100                 {
101                         if (ServerInstance->XLines->DelLine(parameters[0].c_str(), "SVSHOLD", user))
102                         {
103                                 ServerInstance->SNO->WriteToSnoMask('x',"%s Removed SVSHOLD on %s.",user->nick.c_str(),parameters[0].c_str());
104                         }
105                         else
106                         {
107                                 user->WriteServ("NOTICE %s :*** SVSHOLD %s not found in list, try /stats S.",user->nick.c_str(),parameters[0].c_str());
108                         }
109
110                         return CMD_SUCCESS;
111                 }
112                 else if (parameters.size() >= 2)
113                 {
114                         // Adding - XXX todo make this respect <insane> tag perhaps..
115                         long duration = ServerInstance->Duration(parameters[1]);
116                         SVSHold *r = NULL;
117
118                         try
119                         {
120                                 r = new SVSHold(ServerInstance, ServerInstance->Time(), duration, user->nick.c_str(), parameters[2].c_str(), parameters[0].c_str());
121                         }
122                         catch (...)
123                         {
124                                 ; // Do nothing.
125                         }
126
127                         if (r)
128                         {
129                                 if (ServerInstance->XLines->AddLine(r, user))
130                                 {
131                                         ServerInstance->XLines->ApplyLines();
132                                 }
133                                 else
134                                 {
135                                         delete r;
136                                 }
137                         }
138                 }
139
140                 return CMD_SUCCESS;
141         }
142
143         RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
144         {
145                 return ROUTE_BROADCAST;
146         }
147 };
148
149 class ModuleSVSHold : public Module
150 {
151         CommandSvshold cmd;
152         SVSHoldFactory s;
153
154
155  public:
156         ModuleSVSHold(InspIRCd* Me) : Module(Me), cmd(Me, this), s(Me)
157         {
158                 ServerInstance->XLines->RegisterFactory(&s);
159                 ServerInstance->AddCommand(&cmd);
160                 Implementation eventlist[] = { I_OnUserPreNick, I_OnStats };
161                 ServerInstance->Modules->Attach(eventlist, this, 2);
162         }
163
164
165         virtual ModResult OnStats(char symbol, User* user, string_list &out)
166         {
167                 if(symbol != 'S')
168                         return MOD_RES_PASSTHRU;
169
170                 ServerInstance->XLines->InvokeStats("SVSHOLD", 210, user, out);
171                 return MOD_RES_DENY;
172         }
173
174         virtual ModResult OnUserPreNick(User *user, const std::string &newnick)
175         {
176                 XLine *rl = ServerInstance->XLines->MatchesLine("SVSHOLD", newnick);
177
178                 if (rl)
179                 {
180                         user->WriteServ( "432 %s %s :Services reserved nickname: %s", user->nick.c_str(), newnick.c_str(), rl->reason.c_str());
181                         return MOD_RES_DENY;
182                 }
183
184                 return MOD_RES_PASSTHRU;
185         }
186
187         virtual ~ModuleSVSHold()
188         {
189                 ServerInstance->XLines->DelAll("SVSHOLD");
190                 ServerInstance->XLines->UnregisterFactory(&s);
191         }
192
193         virtual Version GetVersion()
194         {
195                 return Version("$Id$", VF_COMMON | VF_VENDOR, API_VERSION);
196         }
197 };
198
199 MODULE_INIT(ModuleSVSHold)