/[svn]/ircd-hybrid/trunk/modules/m_resv.c
ViewVC logotype

Contents of /ircd-hybrid/trunk/modules/m_resv.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1629 - (show annotations)
Thu Nov 1 21:28:58 2012 UTC (7 years, 8 months ago) by michael
File MIME type: text/x-chdr
File size: 12256 byte(s)
- Fixed previous commit to m_resv.c

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

Properties

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

svnadmin@ircd-hybrid.org
ViewVC Help
Powered by ViewVC 1.1.28