ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_resv.c
Revision: 1155
Committed: Tue Aug 9 20:27:45 2011 UTC (14 years ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid/modules/m_resv.c
File size: 12442 byte(s)
Log Message:
- recreate "trunk"

File Contents

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

Properties

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