ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_resv.c
Revision: 2820
Committed: Wed Jan 15 23:10:26 2014 UTC (11 years, 7 months ago) by michael
Content type: text/x-csrc
File size: 12887 byte(s)
Log Message:
- Clean up all files in modules/ (fixed indentation, removed whitespaces/tabs)
- Fixed copyright years
- Made module handlers int type for later use

File Contents

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

Properties

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