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(CONF_ULINE, 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(CONF_ULINE, 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 |
if (IsChanPrefix(*name)) |
221 |
{ |
222 |
struct MaskItem *conf = NULL; |
223 |
|
224 |
if ((conf = create_resv(name, reason, NULL)) == NULL) |
225 |
{ |
226 |
sendto_one(source_p, |
227 |
":%s NOTICE %s :A RESV has already been placed on channel: %s", |
228 |
me.name, source_p->name, name); |
229 |
return; |
230 |
} |
231 |
|
232 |
conf->setat = CurrentTime; |
233 |
SetConfDatabase(conf); |
234 |
|
235 |
if (tkline_time != 0) |
236 |
{ |
237 |
sendto_one(source_p, |
238 |
":%s NOTICE %s :A %d minute %s RESV has been placed on channel: %s", |
239 |
me.name, source_p->name, |
240 |
tkline_time/60, |
241 |
(MyClient(source_p) ? "local" : "remote"), name); |
242 |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
243 |
"%s has placed a %d minute %s RESV on channel: %s [%s]", |
244 |
get_oper_name(source_p), |
245 |
tkline_time/60, |
246 |
(MyClient(source_p) ? "local" : "remote"), |
247 |
conf->name, conf->reason); |
248 |
ilog(LOG_TYPE_RESV, "%s added temporary %d min. RESV for [%s] [%s]", |
249 |
source_p->name, (int)tkline_time/60, |
250 |
conf->name, conf->reason); |
251 |
conf->until = CurrentTime + tkline_time; |
252 |
} |
253 |
else |
254 |
{ |
255 |
sendto_one(source_p, |
256 |
":%s NOTICE %s :A %s RESV has been placed on channel %s", |
257 |
me.name, source_p->name, |
258 |
(MyClient(source_p) ? "local" : "remote"), name); |
259 |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
260 |
"%s has placed a %s RESV on channel %s : [%s]", |
261 |
get_oper_name(source_p), |
262 |
(MyClient(source_p) ? "local" : "remote"), |
263 |
conf->name, conf->reason); |
264 |
} |
265 |
} |
266 |
else |
267 |
{ |
268 |
struct MaskItem *conf = NULL; |
269 |
|
270 |
if (!valid_wild_card_simple(name)) |
271 |
{ |
272 |
sendto_one(source_p, ":%s NOTICE %s :Please include at least %d non-wildcard characters with the resv", |
273 |
me.name, source_p->name, ConfigFileEntry.min_nonwildcard_simple); |
274 |
return; |
275 |
} |
276 |
|
277 |
if (!HasUMode(source_p, UMODE_ADMIN) && has_wildcards(name)) |
278 |
{ |
279 |
sendto_one(source_p, ":%s NOTICE %s :You must be an admin to perform a " |
280 |
"wildcard RESV", me.name, source_p->name); |
281 |
return; |
282 |
} |
283 |
|
284 |
if ((conf = create_resv(name, reason, NULL)) == NULL) |
285 |
{ |
286 |
sendto_one(source_p, |
287 |
":%s NOTICE %s :A RESV has already been placed on nick %s", |
288 |
me.name, source_p->name, name); |
289 |
return; |
290 |
} |
291 |
|
292 |
conf->setat = CurrentTime; |
293 |
SetConfDatabase(conf); |
294 |
|
295 |
if (tkline_time != 0) |
296 |
{ |
297 |
sendto_one(source_p, |
298 |
":%s NOTICE %s :A %d minute %s RESV has been placed on nick %s : [%s]", |
299 |
me.name, source_p->name, |
300 |
tkline_time/60, |
301 |
(MyClient(source_p) ? "local" : "remote"), |
302 |
conf->name, conf->reason); |
303 |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
304 |
"%s has placed a %d minute %s RESV on nick %s : [%s]", |
305 |
get_oper_name(source_p), |
306 |
tkline_time/60, |
307 |
(MyClient(source_p) ? "local" : "remote"), |
308 |
conf->name, conf->reason); |
309 |
ilog(LOG_TYPE_RESV, "%s added temporary %d min. RESV for [%s] [%s]", |
310 |
source_p->name, (int)tkline_time/60, |
311 |
conf->name, conf->reason); |
312 |
conf->until = CurrentTime + tkline_time; |
313 |
} |
314 |
else |
315 |
{ |
316 |
sendto_one(source_p, |
317 |
":%s NOTICE %s :A %s RESV has been placed on nick %s : [%s]", |
318 |
me.name, source_p->name, |
319 |
(MyClient(source_p) ? "local" : "remote"), |
320 |
conf->name, conf->reason); |
321 |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
322 |
"%s has placed a %s RESV on nick %s : [%s]", |
323 |
get_oper_name(source_p), |
324 |
(MyClient(source_p) ? "local" : "remote"), |
325 |
conf->name, conf->reason); |
326 |
} |
327 |
} |
328 |
} |
329 |
|
330 |
static void |
331 |
remove_resv(struct Client *source_p, const char *name) |
332 |
{ |
333 |
struct MaskItem *conf = NULL; |
334 |
|
335 |
if (IsChanPrefix(*name)) |
336 |
{ |
337 |
if ((conf = find_exact_name_conf(CONF_CRESV, NULL, name, NULL, NULL)) == NULL) |
338 |
{ |
339 |
sendto_one(source_p, |
340 |
":%s NOTICE %s :A RESV does not exist for channel: %s", |
341 |
me.name, source_p->name, name); |
342 |
return; |
343 |
} |
344 |
|
345 |
if (!IsConfDatabase(conf)) |
346 |
{ |
347 |
sendto_one(source_p, |
348 |
":%s NOTICE %s :The RESV for channel: %s is in ircd.conf and must be removed by hand.", |
349 |
me.name, source_p->name, name); |
350 |
return; |
351 |
} |
352 |
|
353 |
conf_free(conf); |
354 |
sendto_one(source_p, |
355 |
":%s NOTICE %s :The RESV has been removed on channel: %s", |
356 |
me.name, source_p->name, name); |
357 |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
358 |
"%s has removed the RESV for channel: %s", |
359 |
get_oper_name(source_p), name); |
360 |
} |
361 |
else |
362 |
{ |
363 |
if ((conf = find_exact_name_conf(CONF_NRESV, NULL, name, NULL, NULL)) == NULL) |
364 |
{ |
365 |
sendto_one(source_p, ":%s NOTICE %s :A RESV does not exist for nick: %s", |
366 |
me.name, source_p->name, name); |
367 |
return; |
368 |
} |
369 |
|
370 |
if (!IsConfDatabase(conf)) |
371 |
{ |
372 |
sendto_one(source_p, |
373 |
":%s NOTICE %s :The RESV for nick: %s is in ircd.conf and must be removed by hand.", |
374 |
me.name, source_p->name, name); |
375 |
return; |
376 |
} |
377 |
|
378 |
conf_free(conf); |
379 |
sendto_one(source_p, ":%s NOTICE %s :The RESV has been removed on nick: %s", |
380 |
me.name, source_p->name, name); |
381 |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
382 |
"%s has removed the RESV for nick: %s", |
383 |
get_oper_name(source_p), name); |
384 |
} |
385 |
} |
386 |
|
387 |
static struct Message resv_msgtab = { |
388 |
"RESV", 0, 0, 3, MAXPARA, MFLG_SLOW, 0, |
389 |
{ m_ignore, m_not_oper, ms_resv, me_resv, mo_resv, m_ignore } |
390 |
}; |
391 |
|
392 |
static struct Message unresv_msgtab = { |
393 |
"UNRESV", 0, 0, 2, MAXPARA, MFLG_SLOW, 0, |
394 |
{ m_ignore, m_not_oper, ms_unresv, m_ignore, mo_unresv, m_ignore } |
395 |
}; |
396 |
|
397 |
static void |
398 |
module_init(void) |
399 |
{ |
400 |
mod_add_cmd(&resv_msgtab); |
401 |
mod_add_cmd(&unresv_msgtab); |
402 |
} |
403 |
|
404 |
static void |
405 |
module_exit(void) |
406 |
{ |
407 |
mod_del_cmd(&resv_msgtab); |
408 |
mod_del_cmd(&unresv_msgtab); |
409 |
} |
410 |
|
411 |
struct module module_entry = { |
412 |
.node = { NULL, NULL, NULL }, |
413 |
.name = NULL, |
414 |
.version = "$Revision$", |
415 |
.handle = NULL, |
416 |
.modinit = module_init, |
417 |
.modexit = module_exit, |
418 |
.flags = 0 |
419 |
}; |