ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_resv.c
Revision: 2820
Committed: Wed Jan 15 23:10:26 2014 UTC (11 years, 7 months ago) by michael
Content type: text/x-csrc
File size: 12887 byte(s)
Log Message:
- Clean up all files in modules/ (fixed indentation, removed whitespaces/tabs)
- Fixed copyright years
- Made module handlers int type for later use

File Contents

# User Rev Content
1 adx 30 /*
2 michael 2820 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 adx 30 *
4 michael 2820 * Copyright (c) 2001-2014 ircd-hybrid development team
5 adx 30 *
6     * This program is free software; you can redistribute it and/or modify
7     * it under the terms of the GNU General Public License as published by
8     * the Free Software Foundation; either version 2 of the License, or
9     * (at your option) any later version.
10     *
11     * This program is distributed in the hope that it will be useful,
12     * but WITHOUT ANY WARRANTY; without even the implied warranty of
13     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     * GNU General Public License for more details.
15     *
16     * You should have received a copy of the GNU General Public License
17     * along with this program; if not, write to the Free Software
18     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19     * USA
20     */
21    
22 michael 2820 /*! \file m_resv.c
23     * \brief Includes required functions for processing the RESV/UNRESV command.
24     * \version $Id$
25     */
26    
27 adx 30 #include "stdinc.h"
28     #include "client.h"
29     #include "channel.h"
30     #include "ircd.h"
31     #include "irc_string.h"
32     #include "numeric.h"
33     #include "s_serv.h"
34     #include "send.h"
35     #include "parse.h"
36     #include "modules.h"
37 michael 1309 #include "conf.h"
38     #include "log.h"
39 adx 30 #include "resv.h"
40     #include "hash.h"
41    
42    
43     static void parse_resv(struct Client *, char *, int, char *);
44     static void remove_resv(struct Client *, const char *);
45    
46    
47     /* mo_resv()
48     * parv[0] = sender prefix
49     * parv[1] = channel/nick to forbid
50     */
51 michael 2820 static int
52 adx 30 mo_resv(struct Client *client_p, struct Client *source_p,
53     int parc, char *parv[])
54     {
55     char *resv = NULL;
56     char *reason = NULL;
57     char *target_server = NULL;
58     time_t tkline_time = 0;
59    
60     /* RESV #channel ON irc.server.com :abuse
61     * RESV kiddie ON irc.server.com :abuse
62     */
63 michael 2820 if (parse_aline("RESV", source_p, parc, parv, AWILD, &resv, NULL,
64     &tkline_time, &target_server, &reason) < 0)
65     return 0;
66 adx 30
67     if (target_server != NULL)
68     {
69     /* if a given expire time is given, ENCAP it */
70     if (tkline_time != 0)
71     sendto_match_servs(source_p, target_server, CAP_ENCAP,
72 michael 2820 "ENCAP %s RESV %d %s 0 :%s",
73     target_server, (int)tkline_time, resv, reason);
74 adx 30 else
75     sendto_match_servs(source_p, target_server, CAP_CLUSTER,
76 michael 2820 "RESV %s %s :%s",
77     target_server, resv, reason);
78 adx 30 /* Allow ON to apply local resv as well if it matches */
79 michael 1652 if (match(target_server, me.name))
80 michael 2820 return 0;
81 adx 30 }
82     else
83     {
84     /* RESV #channel :abuse
85     * RESV kiddie :abuse
86     */
87     if (tkline_time != 0)
88     cluster_a_line(source_p, "ENCAP", CAP_ENCAP, SHARED_RESV,
89 michael 2820 "RESV %d %s 0 : %s", (int)tkline_time, resv, reason);
90 adx 30 else
91     cluster_a_line(source_p, "RESV", CAP_KLN, SHARED_RESV,
92 michael 2820 "%s : %s", resv, reason);
93 adx 30 }
94    
95     parse_resv(source_p, resv, (int)tkline_time, reason);
96 michael 2820 return 0;
97 adx 30 }
98    
99     /* me_resv()
100     *
101     * inputs - server
102     * - client (oper)
103     * - parc number of arguments
104     * - parv list of arguments
105     * via parv[]
106     * parv[0] = client name applying resv
107     * parv[1] = tkline_time
108     * parv[2] = name
109     * parv[3] = 0
110     * parv[4] = reason
111     * parc should be 5
112     *
113     * outputs - NONE
114     * side effects -
115     */
116 michael 2820 static int
117 adx 30 me_resv(struct Client *client_p, struct Client *source_p,
118     int parc, char *parv[])
119     {
120     if (parc != 5 || !IsClient(source_p))
121 michael 2820 return 0;
122 adx 30
123     parse_resv(source_p, parv[2], atoi(parv[1]), parv[4]);
124 michael 2820 return 0;
125 adx 30 }
126    
127     /* ms_resv()
128     * parv[0] = sender prefix
129     * parv[1] = target server
130     * parv[2] = channel/nick to resv
131     * parv[3] = reason
132     */
133 michael 2820 static int
134 adx 30 ms_resv(struct Client *client_p, struct Client *source_p,
135     int parc, char *parv[])
136     {
137     if ((parc != 4) || EmptyString(parv[3]))
138 michael 2820 return 0;
139 adx 30
140     sendto_match_servs(source_p, parv[1], CAP_CLUSTER,
141     "RESV %s %s :%s",
142     parv[1], parv[2], parv[3]);
143    
144 michael 1652 if (!IsClient(source_p) || match(parv[1], me.name))
145 michael 2820 return 0;
146 adx 30
147 michael 1632 if (HasFlag(source_p, FLAGS_SERVICE) || find_matching_name_conf(CONF_ULINE, source_p->servptr->name,
148 adx 30 source_p->username, source_p->host,
149     SHARED_RESV))
150     parse_resv(source_p, parv[2], 0, parv[3]);
151 michael 2820 return 0;
152 adx 30 }
153    
154     /* mo_unresv()
155     * parv[0] = sender prefix
156     * parv[1] = channel/nick to unforbid
157     */
158 michael 2820 static int
159 adx 30 mo_unresv(struct Client *client_p, struct Client *source_p,
160     int parc, char *parv[])
161     {
162     char *resv = NULL;
163     char *reason = NULL;
164     char *target_server = NULL;
165    
166     /* UNRESV #channel ON irc.server.com */
167     /* UNRESV kiddie ON irc.server.com */
168 michael 2820 if (parse_aline("UNRESV", source_p, parc, parv, 0, &resv, NULL,
169     NULL, &target_server, &reason) < 0)
170     return 0;
171 adx 30
172     if (target_server != NULL)
173     {
174     sendto_match_servs(source_p, target_server, CAP_CLUSTER,
175     "UNRESV %s %s",
176     target_server, resv);
177    
178     /* Allow ON to apply local unresv as well if it matches */
179 michael 1652 if (match(target_server, me.name))
180 michael 2820 return 0;
181 adx 30 }
182 michael 2820 else
183 adx 30 cluster_a_line(source_p, "UNRESV", CAP_KLN, SHARED_UNRESV, resv);
184    
185     remove_resv(source_p, resv);
186 michael 2820 return 0;
187 adx 30 }
188    
189     /* ms_unresv()
190     * parv[0] = sender prefix
191     * parv[1] = target server
192     * parv[2] = resv to remove
193     */
194 michael 2820 static int
195 adx 30 ms_unresv(struct Client *client_p, struct Client *source_p,
196     int parc, char *parv[])
197     {
198     if ((parc != 3) || EmptyString(parv[2]))
199 michael 2820 return 0;
200 adx 30
201     sendto_match_servs(source_p, parv[1], CAP_CLUSTER,
202     "UNRESV %s %s",
203     parv[1], parv[2]);
204    
205 michael 1652 if (!IsClient(source_p) || match(parv[1], me.name))
206 michael 2820 return 0;
207 adx 30
208 michael 1632 if (HasFlag(source_p, FLAGS_SERVICE) || find_matching_name_conf(CONF_ULINE, source_p->servptr->name,
209 adx 30 source_p->username, source_p->host,
210     SHARED_UNRESV))
211     remove_resv(source_p, parv[2]);
212 michael 2820 return 0;
213 adx 30 }
214    
215     /* parse_resv()
216     *
217     * inputs - source_p, NULL supported
218     * - thing to resv
219     * - time_t if tkline
220     * - reason
221     * outputs - none
222     * side effects - parse resv, create if valid
223     */
224     static void
225     parse_resv(struct Client *source_p, char *name, int tkline_time, char *reason)
226     {
227     if (IsChanPrefix(*name))
228     {
229 michael 1632 struct MaskItem *conf = NULL;
230 adx 30
231 michael 1858 if ((conf = create_resv(name, reason, NULL)) == NULL)
232 adx 30 {
233     sendto_one(source_p,
234 michael 2820 ":%s NOTICE %s :A RESV has already been placed on channel: %s",
235     me.name, source_p->name, name);
236 adx 30 return;
237     }
238    
239 michael 1632 conf->setat = CurrentTime;
240     SetConfDatabase(conf);
241 adx 30
242     if (tkline_time != 0)
243     {
244     sendto_one(source_p,
245 michael 2820 ":%s NOTICE %s :A %d minute %s RESV has been placed on channel: %s",
246     me.name, source_p->name, tkline_time/60,
247 adx 30 (MyClient(source_p) ? "local" : "remote"), name);
248 michael 1618 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
249 michael 2820 "%s has placed a %d minute %s RESV on channel: %s [%s]",
250     get_oper_name(source_p),
251     tkline_time/60,
252     (MyClient(source_p) ? "local" : "remote"),
253     conf->name, conf->reason);
254 michael 2336 ilog(LOG_TYPE_RESV, "%s added temporary %d min. RESV for [%s] [%s]",
255 michael 2820 source_p->name, (int)tkline_time/60,
256     conf->name, conf->reason);
257 michael 1649 conf->until = CurrentTime + tkline_time;
258 adx 30 }
259     else
260     {
261     sendto_one(source_p,
262 michael 2820 ":%s NOTICE %s :A %s RESV has been placed on channel %s",
263 adx 30 me.name, source_p->name,
264 michael 2820 (MyClient(source_p) ? "local" : "remote"), name);
265 michael 1618 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
266 michael 2820 "%s has placed a %s RESV on channel %s : [%s]",
267     get_oper_name(source_p),
268     (MyClient(source_p) ? "local" : "remote"),
269     conf->name, conf->reason);
270 adx 30 }
271     }
272     else
273     {
274 michael 1632 struct MaskItem *conf = NULL;
275 adx 30
276     if (!valid_wild_card_simple(name))
277     {
278     sendto_one(source_p, ":%s NOTICE %s :Please include at least %d non-wildcard characters with the resv",
279     me.name, source_p->name, ConfigFileEntry.min_nonwildcard_simple);
280     return;
281     }
282    
283 michael 1886 if (!HasUMode(source_p, UMODE_ADMIN) && has_wildcards(name))
284 adx 30 {
285     sendto_one(source_p, ":%s NOTICE %s :You must be an admin to perform a "
286     "wildcard RESV", me.name, source_p->name);
287     return;
288     }
289    
290 michael 1858 if ((conf = create_resv(name, reason, NULL)) == NULL)
291 adx 30 {
292     sendto_one(source_p,
293     ":%s NOTICE %s :A RESV has already been placed on nick %s",
294     me.name, source_p->name, name);
295     return;
296     }
297    
298 michael 1632 conf->setat = CurrentTime;
299     SetConfDatabase(conf);
300 adx 30
301     if (tkline_time != 0)
302     {
303     sendto_one(source_p,
304 michael 2820 ":%s NOTICE %s :A %d minute %s RESV has been placed on nick %s : [%s]",
305     me.name, source_p->name, tkline_time/60,
306 adx 30 (MyClient(source_p) ? "local" : "remote"),
307 michael 1632 conf->name, conf->reason);
308 michael 1618 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
309 michael 2820 "%s has placed a %d minute %s RESV on nick %s : [%s]",
310     get_oper_name(source_p), tkline_time/60,
311     (MyClient(source_p) ? "local" : "remote"),
312     conf->name, conf->reason);
313 michael 2336 ilog(LOG_TYPE_RESV, "%s added temporary %d min. RESV for [%s] [%s]",
314 michael 2820 source_p->name, (int)tkline_time/60, conf->name, conf->reason);
315 michael 1649 conf->until = CurrentTime + tkline_time;
316 adx 30 }
317     else
318     {
319     sendto_one(source_p,
320 michael 2820 ":%s NOTICE %s :A %s RESV has been placed on nick %s : [%s]",
321 adx 30 me.name, source_p->name,
322     (MyClient(source_p) ? "local" : "remote"),
323 michael 1632 conf->name, conf->reason);
324 michael 1618 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
325 michael 2820 "%s has placed a %s RESV on nick %s : [%s]",
326     get_oper_name(source_p),
327     (MyClient(source_p) ? "local" : "remote"),
328     conf->name, conf->reason);
329 adx 30 }
330     }
331     }
332    
333     static void
334     remove_resv(struct Client *source_p, const char *name)
335     {
336 michael 1632 struct MaskItem *conf = NULL;
337 adx 30
338     if (IsChanPrefix(*name))
339     {
340 michael 1825 if ((conf = find_exact_name_conf(CONF_CRESV, NULL, name, NULL, NULL)) == NULL)
341 adx 30 {
342     sendto_one(source_p,
343     ":%s NOTICE %s :A RESV does not exist for channel: %s",
344     me.name, source_p->name, name);
345     return;
346     }
347    
348 michael 1632 if (!IsConfDatabase(conf))
349 adx 30 {
350     sendto_one(source_p,
351     ":%s NOTICE %s :The RESV for channel: %s is in ircd.conf and must be removed by hand.",
352     me.name, source_p->name, name);
353     return;
354     }
355    
356 michael 1825 conf_free(conf);
357 adx 30 sendto_one(source_p,
358     ":%s NOTICE %s :The RESV has been removed on channel: %s",
359     me.name, source_p->name, name);
360 michael 1618 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
361 adx 30 "%s has removed the RESV for channel: %s",
362     get_oper_name(source_p), name);
363 michael 2340 ilog(LOG_TYPE_RESV, "%s removed RESV for [%s]",
364     get_oper_name(source_p), name);
365 adx 30 }
366     else
367     {
368 michael 1632 if ((conf = find_exact_name_conf(CONF_NRESV, NULL, name, NULL, NULL)) == NULL)
369 adx 30 {
370     sendto_one(source_p, ":%s NOTICE %s :A RESV does not exist for nick: %s",
371     me.name, source_p->name, name);
372     return;
373     }
374    
375 michael 1632 if (!IsConfDatabase(conf))
376 adx 30 {
377     sendto_one(source_p,
378     ":%s NOTICE %s :The RESV for nick: %s is in ircd.conf and must be removed by hand.",
379     me.name, source_p->name, name);
380     return;
381     }
382    
383 michael 1632 conf_free(conf);
384 adx 30 sendto_one(source_p, ":%s NOTICE %s :The RESV has been removed on nick: %s",
385     me.name, source_p->name, name);
386 michael 1618 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
387 adx 30 "%s has removed the RESV for nick: %s",
388     get_oper_name(source_p), name);
389 michael 2340 ilog(LOG_TYPE_RESV, "%s removed RESV for [%s]",
390     get_oper_name(source_p), name);
391 adx 30 }
392     }
393 michael 1230
394 michael 2820 static struct Message resv_msgtab =
395     {
396 michael 1230 "RESV", 0, 0, 3, MAXPARA, MFLG_SLOW, 0,
397     { m_ignore, m_not_oper, ms_resv, me_resv, mo_resv, m_ignore }
398     };
399    
400 michael 2820 static struct Message unresv_msgtab =
401     {
402 michael 1230 "UNRESV", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
403     { m_ignore, m_not_oper, ms_unresv, m_ignore, mo_unresv, m_ignore }
404     };
405    
406     static void
407     module_init(void)
408     {
409     mod_add_cmd(&resv_msgtab);
410     mod_add_cmd(&unresv_msgtab);
411     }
412    
413     static void
414     module_exit(void)
415     {
416     mod_del_cmd(&resv_msgtab);
417     mod_del_cmd(&unresv_msgtab);
418     }
419    
420 michael 2820 struct module module_entry =
421     {
422 michael 1230 .node = { NULL, NULL, NULL },
423     .name = NULL,
424     .version = "$Revision$",
425     .handle = NULL,
426     .modinit = module_init,
427     .modexit = module_exit,
428     .flags = 0
429     };

Properties

Name Value
svn:eol-style native
svn:keywords Id Revision