ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/modules/m_resv.c
Revision: 741
Committed: Sun Jul 23 13:49:20 2006 UTC (20 years ago) by adx
Content type: text/x-csrc
File size: 12409 byte(s)
Log Message:
+ removed s_conf.h and superseded parts of s_conf.c

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

Properties

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