ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/modules/m_resv.c
Revision: 139
Committed: Sun Oct 16 06:01:13 2005 UTC (20 years, 10 months ago) by db
Content type: text/x-csrc
File size: 12468 byte(s)
Log Message:
- get rid of map_conf_item and unmap_conf_item
- Use an union in struct ConfItem, but only allocate memory needed


File Contents

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

Properties

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