ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid-8/modules/m_resv.c
Revision: 1247
Committed: Sat Oct 1 07:54:24 2011 UTC (12 years, 5 months ago) by michael
Content type: text/x-csrc
File size: 12284 byte(s)
Log Message:
- Rewrite and cleanup half-broken logging subsystem.
  Logfile rotating is not working yet

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 "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 "s_conf.h"
36 #include "s_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 (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 (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
236 if (tkline_time != 0)
237 {
238 sendto_one(source_p,
239 ":%s NOTICE %s :A %d minute %s RESV has been placed on channel: %s",
240 me.name, source_p->name,
241 tkline_time/60,
242 (MyClient(source_p) ? "local" : "remote"), name);
243 sendto_realops_flags(UMODE_ALL, L_ALL,
244 "%s has placed a %d minute %s RESV on channel: %s [%s]",
245 get_oper_name(source_p),
246 tkline_time/60,
247 (MyClient(source_p) ? "local" : "remote"),
248 resv_p->name, resv_p->reason);
249 ilog(LOG_TYPE_IRCD, "%s added temporary %d min. RESV for [%s] [%s]",
250 source_p->name, (int)tkline_time/60,
251 conf->name, resv_p->reason);
252 resv_p->hold = CurrentTime + tkline_time;
253 add_temp_line(conf);
254 }
255 else
256 {
257 sendto_one(source_p,
258 ":%s NOTICE %s :A %s RESV has been placed on channel %s",
259 me.name, source_p->name,
260 (MyClient(source_p) ? "local" : "remote"), name);
261 sendto_realops_flags(UMODE_ALL, L_ALL,
262 "%s has placed a %s RESV on channel %s : [%s]",
263 get_oper_name(source_p),
264 (MyClient(source_p) ? "local" : "remote"),
265 resv_p->name, resv_p->reason);
266 write_conf_line(source_p, conf, NULL /* not used */, 0 /* not used */);
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
297 if (tkline_time != 0)
298 {
299 sendto_one(source_p,
300 ":%s NOTICE %s :A %d minute %s RESV has been placed on nick %s : [%s]",
301 me.name, source_p->name,
302 tkline_time/60,
303 (MyClient(source_p) ? "local" : "remote"),
304 conf->name, resv_p->reason);
305 sendto_realops_flags(UMODE_ALL, L_ALL,
306 "%s has placed a %d minute %s RESV on nick %s : [%s]",
307 get_oper_name(source_p),
308 tkline_time/60,
309 (MyClient(source_p) ? "local" : "remote"),
310 conf->name, resv_p->reason);
311 ilog(LOG_TYPE_IRCD, "%s added temporary %d min. RESV for [%s] [%s]",
312 source_p->name, (int)tkline_time/60,
313 conf->name, resv_p->reason);
314 resv_p->hold = CurrentTime + tkline_time;
315 add_temp_line(conf);
316 }
317 else
318 {
319 sendto_one(source_p,
320 ":%s NOTICE %s :A %s RESV has been placed on nick %s : [%s]",
321 me.name, source_p->name,
322 (MyClient(source_p) ? "local" : "remote"),
323 conf->name, resv_p->reason);
324 sendto_realops_flags(UMODE_ALL, L_ALL,
325 "%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, resv_p->reason);
329 write_conf_line(source_p, conf, NULL /* not used */, 0 /* not used */);
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 (resv_p->conf)
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 remove_conf_line(CRESV_TYPE, source_p, name, NULL);
362
363 sendto_one(source_p,
364 ":%s NOTICE %s :The RESV has been removed on channel: %s",
365 me.name, source_p->name, name);
366 sendto_realops_flags(UMODE_ALL, L_ALL,
367 "%s has removed the RESV for channel: %s",
368 get_oper_name(source_p), name);
369 }
370 else
371 {
372 struct MatchItem *resv_p = NULL;
373
374 if ((conf = find_exact_name_conf(NRESV_TYPE, name, NULL, NULL)) == NULL)
375 {
376 sendto_one(source_p, ":%s NOTICE %s :A RESV does not exist for nick: %s",
377 me.name, source_p->name, name);
378 return;
379 }
380
381 resv_p = map_to_conf(conf);
382
383 if (resv_p->action)
384 {
385 sendto_one(source_p,
386 ":%s NOTICE %s :The RESV for nick: %s is in ircd.conf and must be removed by hand.",
387 me.name, source_p->name, name);
388 return;
389 }
390
391 delete_conf_item(conf);
392 remove_conf_line(NRESV_TYPE, source_p, name, NULL);
393
394 sendto_one(source_p, ":%s NOTICE %s :The RESV has been removed on nick: %s",
395 me.name, source_p->name, name);
396 sendto_realops_flags(UMODE_ALL, L_ALL,
397 "%s has removed the RESV for nick: %s",
398 get_oper_name(source_p), name);
399 }
400 }
401
402 static struct Message resv_msgtab = {
403 "RESV", 0, 0, 3, MAXPARA, MFLG_SLOW, 0,
404 { m_ignore, m_not_oper, ms_resv, me_resv, mo_resv, m_ignore }
405 };
406
407 static struct Message unresv_msgtab = {
408 "UNRESV", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
409 { m_ignore, m_not_oper, ms_unresv, m_ignore, mo_unresv, m_ignore }
410 };
411
412 static void
413 module_init(void)
414 {
415 mod_add_cmd(&resv_msgtab);
416 mod_add_cmd(&unresv_msgtab);
417 }
418
419 static void
420 module_exit(void)
421 {
422 mod_del_cmd(&resv_msgtab);
423 mod_del_cmd(&unresv_msgtab);
424 }
425
426 struct module module_entry = {
427 .node = { NULL, NULL, NULL },
428 .name = NULL,
429 .version = "$Revision$",
430 .handle = NULL,
431 .modinit = module_init,
432 .modexit = module_exit,
433 .flags = 0
434 };

Properties

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