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 |
|
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 void |
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, |
64 |
AWILD, &resv, NULL, &tkline_time, &target_server, &reason) < 0) |
65 |
return; |
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; |
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 |
} |
97 |
|
98 |
/* me_resv() |
99 |
* |
100 |
* inputs - server |
101 |
* - client (oper) |
102 |
* - parc number of arguments |
103 |
* - parv list of arguments |
104 |
* via parv[] |
105 |
* parv[0] = client name applying resv |
106 |
* parv[1] = tkline_time |
107 |
* parv[2] = name |
108 |
* parv[3] = 0 |
109 |
* parv[4] = reason |
110 |
* parc should be 5 |
111 |
* |
112 |
* outputs - NONE |
113 |
* side effects - |
114 |
*/ |
115 |
static void |
116 |
me_resv(struct Client *client_p, struct Client *source_p, |
117 |
int parc, char *parv[]) |
118 |
{ |
119 |
if (parc != 5 || !IsClient(source_p)) |
120 |
return; |
121 |
|
122 |
parse_resv(source_p, parv[2], atoi(parv[1]), parv[4]); |
123 |
} |
124 |
|
125 |
/* ms_resv() |
126 |
* parv[0] = sender prefix |
127 |
* parv[1] = target server |
128 |
* parv[2] = channel/nick to resv |
129 |
* parv[3] = reason |
130 |
*/ |
131 |
static void |
132 |
ms_resv(struct Client *client_p, struct Client *source_p, |
133 |
int parc, char *parv[]) |
134 |
{ |
135 |
if ((parc != 4) || EmptyString(parv[3])) |
136 |
return; |
137 |
|
138 |
sendto_match_servs(source_p, parv[1], CAP_CLUSTER, |
139 |
"RESV %s %s :%s", |
140 |
parv[1], parv[2], parv[3]); |
141 |
|
142 |
if (!IsClient(source_p) || !match(parv[1], me.name)) |
143 |
return; |
144 |
|
145 |
if (find_matching_name_conf(ULINE_TYPE, source_p->servptr->name, |
146 |
source_p->username, source_p->host, |
147 |
SHARED_RESV)) |
148 |
parse_resv(source_p, parv[2], 0, parv[3]); |
149 |
} |
150 |
|
151 |
/* mo_unresv() |
152 |
* parv[0] = sender prefix |
153 |
* parv[1] = channel/nick to unforbid |
154 |
*/ |
155 |
static void |
156 |
mo_unresv(struct Client *client_p, struct Client *source_p, |
157 |
int parc, char *parv[]) |
158 |
{ |
159 |
char *resv = NULL; |
160 |
char *reason = NULL; |
161 |
char *target_server = NULL; |
162 |
|
163 |
/* UNRESV #channel ON irc.server.com */ |
164 |
/* UNRESV kiddie ON irc.server.com */ |
165 |
if (parse_aline("UNRESV", source_p, parc, parv, |
166 |
0, &resv, NULL, NULL, &target_server, &reason) < 0) |
167 |
return; |
168 |
|
169 |
if (target_server != NULL) |
170 |
{ |
171 |
sendto_match_servs(source_p, target_server, CAP_CLUSTER, |
172 |
"UNRESV %s %s", |
173 |
target_server, resv); |
174 |
|
175 |
/* Allow ON to apply local unresv as well if it matches */ |
176 |
if (!match(target_server, me.name)) |
177 |
return; |
178 |
} |
179 |
else |
180 |
cluster_a_line(source_p, "UNRESV", CAP_KLN, SHARED_UNRESV, resv); |
181 |
|
182 |
remove_resv(source_p, resv); |
183 |
} |
184 |
|
185 |
/* ms_unresv() |
186 |
* parv[0] = sender prefix |
187 |
* parv[1] = target server |
188 |
* parv[2] = resv to remove |
189 |
*/ |
190 |
static void |
191 |
ms_unresv(struct Client *client_p, struct Client *source_p, |
192 |
int parc, char *parv[]) |
193 |
{ |
194 |
if ((parc != 3) || EmptyString(parv[2])) |
195 |
return; |
196 |
|
197 |
sendto_match_servs(source_p, parv[1], CAP_CLUSTER, |
198 |
"UNRESV %s %s", |
199 |
parv[1], parv[2]); |
200 |
|
201 |
if (!IsClient(source_p) || !match(parv[1], me.name)) |
202 |
return; |
203 |
|
204 |
if (find_matching_name_conf(ULINE_TYPE, source_p->servptr->name, |
205 |
source_p->username, source_p->host, |
206 |
SHARED_UNRESV)) |
207 |
remove_resv(source_p, parv[2]); |
208 |
} |
209 |
|
210 |
/* parse_resv() |
211 |
* |
212 |
* inputs - source_p, NULL supported |
213 |
* - thing to resv |
214 |
* - time_t if tkline |
215 |
* - reason |
216 |
* outputs - none |
217 |
* side effects - parse resv, create if valid |
218 |
*/ |
219 |
static void |
220 |
parse_resv(struct Client *source_p, char *name, int tkline_time, char *reason) |
221 |
{ |
222 |
struct ConfItem *conf = NULL; |
223 |
|
224 |
if (IsChanPrefix(*name)) |
225 |
{ |
226 |
struct ResvChannel *resv_p; |
227 |
|
228 |
if ((conf = create_channel_resv(name, reason, 0)) == NULL) |
229 |
{ |
230 |
sendto_one(source_p, |
231 |
":%s NOTICE %s :A RESV has already been placed on channel: %s", |
232 |
me.name, source_p->name, name); |
233 |
return; |
234 |
} |
235 |
|
236 |
resv_p = map_to_conf(conf); |
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, |
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(L_TRACE, "%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 |
add_temp_line(conf); |
256 |
} |
257 |
else |
258 |
{ |
259 |
sendto_one(source_p, |
260 |
":%s NOTICE %s :A %s RESV has been placed on channel %s", |
261 |
me.name, source_p->name, |
262 |
(MyClient(source_p) ? "local" : "remote"), name); |
263 |
sendto_realops_flags(UMODE_ALL, L_ALL, |
264 |
"%s has placed a %s RESV on channel %s : [%s]", |
265 |
get_oper_name(source_p), |
266 |
(MyClient(source_p) ? "local" : "remote"), |
267 |
resv_p->name, resv_p->reason); |
268 |
write_conf_line(source_p, conf, NULL /* not used */, 0 /* not used */); |
269 |
} |
270 |
} |
271 |
else |
272 |
{ |
273 |
struct MatchItem *resv_p = NULL; |
274 |
|
275 |
if (!valid_wild_card_simple(name)) |
276 |
{ |
277 |
sendto_one(source_p, ":%s NOTICE %s :Please include at least %d non-wildcard characters with the resv", |
278 |
me.name, source_p->name, ConfigFileEntry.min_nonwildcard_simple); |
279 |
return; |
280 |
} |
281 |
|
282 |
if (!HasUMode(source_p, UMODE_ADMIN) && strpbrk(name, "*?#")) |
283 |
{ |
284 |
sendto_one(source_p, ":%s NOTICE %s :You must be an admin to perform a " |
285 |
"wildcard RESV", me.name, source_p->name); |
286 |
return; |
287 |
} |
288 |
|
289 |
if ((conf = create_nick_resv(name, reason, 0)) == NULL) |
290 |
{ |
291 |
sendto_one(source_p, |
292 |
":%s NOTICE %s :A RESV has already been placed on nick %s", |
293 |
me.name, source_p->name, name); |
294 |
return; |
295 |
} |
296 |
|
297 |
resv_p = map_to_conf(conf); |
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, |
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(L_TRACE, "%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 |
add_temp_line(conf); |
318 |
} |
319 |
else |
320 |
{ |
321 |
sendto_one(source_p, |
322 |
":%s NOTICE %s :A %s RESV has been placed on nick %s : [%s]", |
323 |
me.name, source_p->name, |
324 |
(MyClient(source_p) ? "local" : "remote"), |
325 |
conf->name, resv_p->reason); |
326 |
sendto_realops_flags(UMODE_ALL, L_ALL, |
327 |
"%s has placed a %s RESV on nick %s : [%s]", |
328 |
get_oper_name(source_p), |
329 |
(MyClient(source_p) ? "local" : "remote"), |
330 |
conf->name, resv_p->reason); |
331 |
write_conf_line(source_p, conf, NULL /* not used */, 0 /* not used */); |
332 |
} |
333 |
} |
334 |
} |
335 |
|
336 |
static void |
337 |
remove_resv(struct Client *source_p, const char *name) |
338 |
{ |
339 |
struct ConfItem *conf = NULL; |
340 |
|
341 |
if (IsChanPrefix(*name)) |
342 |
{ |
343 |
struct ResvChannel *resv_p; |
344 |
|
345 |
if (resv_channel_list.head == NULL || |
346 |
!(resv_p = hash_find_resv(name))) |
347 |
{ |
348 |
sendto_one(source_p, |
349 |
":%s NOTICE %s :A RESV does not exist for channel: %s", |
350 |
me.name, source_p->name, name); |
351 |
return; |
352 |
} |
353 |
|
354 |
if (resv_p->conf) |
355 |
{ |
356 |
sendto_one(source_p, |
357 |
":%s NOTICE %s :The RESV for channel: %s is in ircd.conf and must be removed by hand.", |
358 |
me.name, source_p->name, name); |
359 |
return; |
360 |
} |
361 |
|
362 |
delete_channel_resv(resv_p); |
363 |
remove_conf_line(CRESV_TYPE, source_p, name, NULL); |
364 |
|
365 |
sendto_one(source_p, |
366 |
":%s NOTICE %s :The RESV has been removed on channel: %s", |
367 |
me.name, source_p->name, name); |
368 |
sendto_realops_flags(UMODE_ALL, L_ALL, |
369 |
"%s has removed the RESV for channel: %s", |
370 |
get_oper_name(source_p), name); |
371 |
} |
372 |
else |
373 |
{ |
374 |
struct MatchItem *resv_p = NULL; |
375 |
|
376 |
if ((conf = find_exact_name_conf(NRESV_TYPE, name, NULL, NULL)) == NULL) |
377 |
{ |
378 |
sendto_one(source_p, ":%s NOTICE %s :A RESV does not exist for nick: %s", |
379 |
me.name, source_p->name, name); |
380 |
return; |
381 |
} |
382 |
|
383 |
resv_p = map_to_conf(conf); |
384 |
|
385 |
if (resv_p->action) |
386 |
{ |
387 |
sendto_one(source_p, |
388 |
":%s NOTICE %s :The RESV for nick: %s is in ircd.conf and must be removed by hand.", |
389 |
me.name, source_p->name, name); |
390 |
return; |
391 |
} |
392 |
|
393 |
delete_conf_item(conf); |
394 |
remove_conf_line(NRESV_TYPE, source_p, name, NULL); |
395 |
|
396 |
sendto_one(source_p, ":%s NOTICE %s :The RESV has been removed on nick: %s", |
397 |
me.name, source_p->name, name); |
398 |
sendto_realops_flags(UMODE_ALL, L_ALL, |
399 |
"%s has removed the RESV for nick: %s", |
400 |
get_oper_name(source_p), name); |
401 |
} |
402 |
} |
403 |
|
404 |
static struct Message resv_msgtab = { |
405 |
"RESV", 0, 0, 3, MAXPARA, MFLG_SLOW, 0, |
406 |
{ m_ignore, m_not_oper, ms_resv, me_resv, mo_resv, m_ignore } |
407 |
}; |
408 |
|
409 |
static struct Message unresv_msgtab = { |
410 |
"UNRESV", 0, 0, 2, MAXPARA, MFLG_SLOW, 0, |
411 |
{ m_ignore, m_not_oper, ms_unresv, m_ignore, mo_unresv, m_ignore } |
412 |
}; |
413 |
|
414 |
static void |
415 |
module_init(void) |
416 |
{ |
417 |
mod_add_cmd(&resv_msgtab); |
418 |
mod_add_cmd(&unresv_msgtab); |
419 |
} |
420 |
|
421 |
static void |
422 |
module_exit(void) |
423 |
{ |
424 |
mod_del_cmd(&resv_msgtab); |
425 |
mod_del_cmd(&unresv_msgtab); |
426 |
} |
427 |
|
428 |
struct module module_entry = { |
429 |
.node = { NULL, NULL, NULL }, |
430 |
.name = NULL, |
431 |
.version = "$Revision$", |
432 |
.handle = NULL, |
433 |
.modinit = module_init, |
434 |
.modexit = module_exit, |
435 |
.flags = 0 |
436 |
}; |