2 * ircd-ratbox: A slightly useful ircd.
3 * m_resv.c: Reserves(jupes) a nickname or channel.
5 * Copyright (C) 2001-2002 Hybrid Development Team
6 * Copyright (C) 2002-2005 ircd-ratbox development team
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
37 #include "s_newconf.h"
43 static int mo_resv(struct Client
*, struct Client
*, int, const char **);
44 static int ms_resv(struct Client
*, struct Client
*, int, const char **);
45 static int me_resv(struct Client
*, struct Client
*, int, const char **);
46 static int mo_unresv(struct Client
*, struct Client
*, int, const char **);
47 static int ms_unresv(struct Client
*, struct Client
*, int, const char **);
48 static int me_unresv(struct Client
*, struct Client
*, int, const char **);
50 struct Message resv_msgtab
= {
51 "RESV", 0, 0, 0, MFLG_SLOW
| MFLG_UNREG
,
52 {mg_ignore
, mg_not_oper
, {ms_resv
, 4}, {ms_resv
, 4}, {me_resv
, 5}, {mo_resv
, 3}}
55 struct Message unresv_msgtab
= {
56 "UNRESV", 0, 0, 0, MFLG_SLOW
| MFLG_UNREG
,
57 {mg_ignore
, mg_not_oper
, {ms_unresv
, 3}, {ms_unresv
, 3}, {me_unresv
, 2}, {mo_unresv
, 2}}
60 mapi_clist_av1 resv_clist
[] = { &resv_msgtab
, &unresv_msgtab
, NULL
};
62 DECLARE_MODULE_AV1(resv
, NULL
, NULL
, resv_clist
, NULL
, NULL
, "$Revision$");
64 static void parse_resv(struct Client
*source_p
, const char *name
,
65 const char *reason
, int temp_time
, int propagated
);
66 static void propagate_resv(struct Client
*source_p
, const char *target
,
67 int temp_time
, const char *name
, const char *reason
);
68 static void cluster_resv(struct Client
*source_p
, int temp_time
,
69 const char *name
, const char *reason
);
71 static void handle_remote_unresv(struct Client
*source_p
, const char *name
);
72 static void remove_resv(struct Client
*source_p
, const char *name
, int propagated
);
76 * parv[0] = sender prefix
77 * parv[1] = channel/nick to forbid
81 mo_resv(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
85 const char *target_server
= NULL
;
88 int propagated
= ConfigFileEntry
.use_propagated_bans
;
90 if(!IsOperResv(source_p
))
92 sendto_one(source_p
, form_str(ERR_NOPRIVS
), me
.name
, source_p
->name
, "resv");
96 /* RESV [time] <name> [ON <server>] :<reason> */
98 if((temp_time
= valid_temp_time(parv
[loc
])) >= 0)
100 /* we just set temp_time to -1! */
107 if((parc
>= loc
+ 2) && (irccmp(parv
[loc
], "ON") == 0))
109 if(!IsOperRemoteBan(source_p
))
111 sendto_one(source_p
, form_str(ERR_NOPRIVS
),
112 me
.name
, source_p
->name
, "remoteban");
116 target_server
= parv
[loc
+ 1];
119 /* Set as local-only. */
123 if(parc
<= loc
|| EmptyString(parv
[loc
]))
125 sendto_one(source_p
, form_str(ERR_NEEDMOREPARAMS
), me
.name
, source_p
->name
, "RESV");
134 propagate_resv(source_p
, target_server
, temp_time
, name
, reason
);
136 if(match(target_server
, me
.name
) == 0)
139 else if(!propagated
&& rb_dlink_list_length(&cluster_conf_list
) > 0)
140 cluster_resv(source_p
, temp_time
, name
, reason
);
142 if(propagated
&& temp_time
== 0)
144 sendto_one_notice(source_p
, ":Cannot set a permanent global ban");
148 parse_resv(source_p
, name
, reason
, temp_time
, propagated
);
154 * parv[0] = sender prefix
155 * parv[1] = target server
156 * parv[2] = channel/nick to forbid
160 ms_resv(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
162 /* parv[0] parv[1] parv[2] parv[3]
163 * oper target server resv reason
165 propagate_resv(source_p
, parv
[1], 0, parv
[2], parv
[3]);
167 if(!match(parv
[1], me
.name
))
170 if(!IsPerson(source_p
))
173 parse_resv(source_p
, parv
[2], parv
[3], 0, 0);
178 me_resv(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
180 /* time name 0 :reason */
181 if(!IsPerson(source_p
))
184 parse_resv(source_p
, parv
[2], parv
[4], atoi(parv
[1]), 0);
190 * inputs - source_p if error messages wanted
194 * side effects - will parse the resv and create it if valid
197 parse_resv(struct Client
*source_p
, const char *name
, const char *reason
, int temp_time
, int propagated
)
199 struct ConfItem
*aconf
;
201 if(!MyClient(source_p
) &&
202 !find_shared_conf(source_p
->username
, source_p
->host
,
203 source_p
->servptr
->name
,
204 (temp_time
> 0) ? SHARED_TRESV
: SHARED_PRESV
))
207 if(IsChannelName(name
))
209 if(hash_find_resv(name
))
211 sendto_one_notice(source_p
,
212 ":A RESV has already been placed on channel: %s", name
);
216 if(strlen(name
) > CHANNELLEN
)
218 sendto_one_notice(source_p
, ":Invalid RESV length: %s", name
);
222 if(strchr(reason
, '"'))
224 sendto_one_notice(source_p
, ":Invalid character '\"' in comment");
229 aconf
->status
= CONF_RESV_CHANNEL
;
231 aconf
->created
= rb_current_time();
232 aconf
->host
= rb_strdup(name
);
233 aconf
->passwd
= rb_strdup(reason
);
234 aconf
->info
.oper
= operhash_add(get_oper_name(source_p
));
238 aconf
->flags
|= CONF_FLAGS_MYOPER
| CONF_FLAGS_TEMPORARY
;
239 aconf
->hold
= rb_current_time() + temp_time
;
240 aconf
->lifetime
= aconf
->hold
;
241 replace_old_ban(aconf
);
242 rb_dlinkAddAlloc(aconf
, &prop_bans
);
244 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
245 "%s added global %d min. RESV for [%s] [%s]",
246 get_oper_name(source_p
), temp_time
/ 60,
248 ilog(L_KLINE
, "R %s %d %s %s",
249 get_oper_name(source_p
), temp_time
/ 60, name
, reason
);
250 sendto_one_notice(source_p
, ":Added global %d min. RESV [%s]",
251 temp_time
/ 60, name
);
252 sendto_server(NULL
, NULL
, CAP_BAN
|CAP_TS6
, NOCAPS
,
253 ":%s BAN R * %s %lu %d %d * :%s",
254 source_p
->id
, aconf
->host
,
255 (unsigned long)aconf
->created
,
256 (int)(aconf
->hold
- aconf
->created
),
257 (int)(aconf
->lifetime
- aconf
->created
),
260 else if(temp_time
> 0)
262 aconf
->hold
= rb_current_time() + temp_time
;
264 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
265 "%s added temporary %d min. RESV for [%s] [%s]",
266 get_oper_name(source_p
), temp_time
/ 60,
268 ilog(L_KLINE
, "R %s %d %s %s",
269 get_oper_name(source_p
), temp_time
/ 60, name
, reason
);
270 sendto_one_notice(source_p
, ":Added temporary %d min. RESV [%s]",
271 temp_time
/ 60, name
);
275 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
276 "%s added RESV for [%s] [%s]",
277 get_oper_name(source_p
), name
, reason
);
278 ilog(L_KLINE
, "R %s 0 %s %s",
279 get_oper_name(source_p
), name
, reason
);
280 sendto_one_notice(source_p
, ":Added RESV [%s]", name
);
282 bandb_add(BANDB_RESV
, source_p
, aconf
->host
, NULL
, aconf
->passwd
, NULL
, 0);
285 add_to_resv_hash(aconf
->host
, aconf
);
286 resv_chan_forcepart(aconf
->host
, aconf
->passwd
, temp_time
);
288 else if(clean_resv_nick(name
))
290 if(strlen(name
) > NICKLEN
* 2)
292 sendto_one_notice(source_p
, ":Invalid RESV length: %s", name
);
296 if(strchr(reason
, '"'))
298 sendto_one_notice(source_p
, ":Invalid character '\"' in comment");
302 if(!valid_wild_card_simple(name
))
304 sendto_one_notice(source_p
,
305 ":Please include at least %d non-wildcard "
306 "characters with the resv",
307 ConfigFileEntry
.min_nonwildcard_simple
);
311 if(find_nick_resv_mask(name
))
313 sendto_one_notice(source_p
,
314 ":A RESV has already been placed on nick: %s", name
);
319 aconf
->status
= CONF_RESV_NICK
;
321 aconf
->created
= rb_current_time();
322 aconf
->host
= rb_strdup(name
);
323 aconf
->passwd
= rb_strdup(reason
);
324 aconf
->info
.oper
= operhash_add(get_oper_name(source_p
));
328 aconf
->flags
|= CONF_FLAGS_MYOPER
| CONF_FLAGS_TEMPORARY
;
329 aconf
->hold
= rb_current_time() + temp_time
;
330 aconf
->lifetime
= aconf
->hold
;
331 replace_old_ban(aconf
);
332 rb_dlinkAddAlloc(aconf
, &prop_bans
);
334 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
335 "%s added global %d min. RESV for [%s] [%s]",
336 get_oper_name(source_p
), temp_time
/ 60,
338 ilog(L_KLINE
, "R %s %d %s %s",
339 get_oper_name(source_p
), temp_time
/ 60, name
, reason
);
340 sendto_one_notice(source_p
, ":Added global %d min. RESV [%s]",
341 temp_time
/ 60, name
);
342 sendto_server(NULL
, NULL
, CAP_BAN
|CAP_TS6
, NOCAPS
,
343 ":%s BAN R * %s %lu %d %d * :%s",
344 source_p
->id
, aconf
->host
,
345 (unsigned long)aconf
->created
,
346 (int)(aconf
->hold
- aconf
->created
),
347 (int)(aconf
->lifetime
- aconf
->created
),
350 else if(temp_time
> 0)
352 aconf
->hold
= rb_current_time() + temp_time
;
354 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
355 "%s added temporary %d min. RESV for [%s] [%s]",
356 get_oper_name(source_p
), temp_time
/ 60,
358 ilog(L_KLINE
, "R %s %d %s %s",
359 get_oper_name(source_p
), temp_time
/ 60, name
, reason
);
360 sendto_one_notice(source_p
, ":Added temporary %d min. RESV [%s]",
361 temp_time
/ 60, name
);
365 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
366 "%s added RESV for [%s] [%s]",
367 get_oper_name(source_p
), name
, reason
);
368 ilog(L_KLINE
, "R %s 0 %s %s",
369 get_oper_name(source_p
), name
, reason
);
370 sendto_one_notice(source_p
, ":Added RESV [%s]", name
);
372 bandb_add(BANDB_RESV
, source_p
, aconf
->host
, NULL
, aconf
->passwd
, NULL
, 0);
375 rb_dlinkAddAlloc(aconf
, &resv_conf_list
);
378 sendto_one_notice(source_p
, ":You have specified an invalid resv: [%s]", name
);
382 propagate_resv(struct Client
*source_p
, const char *target
,
383 int temp_time
, const char *name
, const char *reason
)
387 sendto_match_servs(source_p
, target
,
388 CAP_CLUSTER
, NOCAPS
, "RESV %s %s :%s", target
, name
, reason
);
389 sendto_match_servs(source_p
, target
,
390 CAP_ENCAP
, CAP_CLUSTER
,
391 "ENCAP %s RESV %d %s 0 :%s", target
, temp_time
, name
, reason
);
394 sendto_match_servs(source_p
, target
,
396 "ENCAP %s RESV %d %s 0 :%s", target
, temp_time
, name
, reason
);
400 cluster_resv(struct Client
*source_p
, int temp_time
, const char *name
, const char *reason
)
402 struct remote_conf
*shared_p
;
405 RB_DLINK_FOREACH(ptr
, cluster_conf_list
.head
)
407 shared_p
= ptr
->data
;
409 /* old protocol cant handle temps, and we dont really want
410 * to convert them to perm.. --fl
414 if(!(shared_p
->flags
& SHARED_PRESV
))
417 sendto_match_servs(source_p
, shared_p
->server
,
419 "RESV %s %s :%s", shared_p
->server
, name
, reason
);
420 sendto_match_servs(source_p
, shared_p
->server
,
421 CAP_ENCAP
, CAP_CLUSTER
,
422 "ENCAP %s RESV 0 %s 0 :%s",
423 shared_p
->server
, name
, reason
);
425 else if(shared_p
->flags
& SHARED_TRESV
)
426 sendto_match_servs(source_p
, shared_p
->server
,
428 "ENCAP %s RESV %d %s 0 :%s",
429 shared_p
->server
, temp_time
, name
, reason
);
436 * parv[0] = sender prefix
437 * parv[1] = channel/nick to unforbid
440 mo_unresv(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
444 if(!IsOperResv(source_p
))
446 sendto_one(source_p
, form_str(ERR_NOPRIVS
), me
.name
, source_p
->name
, "resv");
450 if((parc
== 4) && (irccmp(parv
[2], "ON") == 0))
452 if(!IsOperRemoteBan(source_p
))
454 sendto_one(source_p
, form_str(ERR_NOPRIVS
),
455 me
.name
, source_p
->name
, "remoteban");
459 propagate_generic(source_p
, "UNRESV", parv
[3], CAP_CLUSTER
, "%s", parv
[1]);
461 if(match(parv
[3], me
.name
) == 0)
467 else if(rb_dlink_list_length(&cluster_conf_list
) > 0)
468 cluster_generic(source_p
, "UNRESV", SHARED_UNRESV
, CAP_CLUSTER
, "%s", parv
[1]);
470 /* cluster{} moved to remove_resv */
472 remove_resv(source_p
, parv
[1], propagated
);
477 * parv[0] = sender prefix
478 * parv[1] = target server
479 * parv[2] = resv to remove
482 ms_unresv(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
484 /* parv[0] parv[1] parv[2]
485 * oper target server resv to remove
487 propagate_generic(source_p
, "UNRESV", parv
[1], CAP_CLUSTER
, "%s", parv
[2]);
489 if(!match(parv
[1], me
.name
))
492 if(!IsPerson(source_p
))
495 handle_remote_unresv(source_p
, parv
[2]);
500 me_unresv(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
503 if(!IsPerson(source_p
))
506 handle_remote_unresv(source_p
, parv
[1]);
511 handle_remote_unresv(struct Client
*source_p
, const char *name
)
513 if(!find_shared_conf(source_p
->username
, source_p
->host
,
514 source_p
->servptr
->name
, SHARED_UNRESV
))
517 remove_resv(source_p
, name
, 0);
523 remove_resv(struct Client
*source_p
, const char *name
, int propagated
)
525 struct ConfItem
*aconf
= NULL
;
528 if(IsChannelName(name
))
530 if((aconf
= hash_find_resv(name
)) == NULL
)
532 if(propagated
&& rb_dlink_list_length(&cluster_conf_list
))
533 cluster_generic(source_p
, "UNXLINE", SHARED_UNXLINE
, CAP_CLUSTER
, "%s", name
);
535 sendto_one_notice(source_p
, ":No RESV for %s", name
);
543 sendto_one_notice(source_p
, ":Cannot remove global RESV %s on specific servers", name
);
546 ptr
= rb_dlinkFind(aconf
, &prop_bans
);
549 sendto_one_notice(source_p
, ":RESV for [%s] is removed", name
);
550 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
551 "%s has removed the global RESV for: [%s]",
552 get_oper_name(source_p
), name
);
553 ilog(L_KLINE
, "UR %s %s", get_oper_name(source_p
), name
);
554 if(aconf
->created
< rb_current_time())
555 aconf
->created
= rb_current_time();
558 aconf
->hold
= aconf
->created
;
559 operhash_delete(aconf
->info
.oper
);
560 aconf
->info
.oper
= operhash_add(get_oper_name(source_p
));
561 aconf
->flags
|= CONF_FLAGS_MYOPER
| CONF_FLAGS_TEMPORARY
;
562 sendto_server(NULL
, NULL
, CAP_BAN
|CAP_TS6
, NOCAPS
,
563 ":%s BAN R * %s %lu %d %d * :*",
564 source_p
->id
, aconf
->host
,
565 (unsigned long)aconf
->created
,
567 (int)(aconf
->lifetime
- aconf
->created
));
568 deactivate_conf(aconf
, ptr
);
571 else if(propagated
&& rb_dlink_list_length(&cluster_conf_list
) > 0)
572 cluster_generic(source_p
, "UNRESV", SHARED_UNRESV
, CAP_CLUSTER
, "%s", name
);
574 sendto_one_notice(source_p
, ":RESV for [%s] is removed", name
);
575 ilog(L_KLINE
, "UR %s %s", get_oper_name(source_p
), name
);
578 bandb_del(BANDB_RESV
, aconf
->host
, NULL
);
579 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
580 "%s has removed the RESV for: [%s]",
581 get_oper_name(source_p
), name
);
585 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
586 "%s has removed the temporary RESV for: [%s]",
587 get_oper_name(source_p
), name
);
589 del_from_resv_hash(name
, aconf
);
593 RB_DLINK_FOREACH(ptr
, resv_conf_list
.head
)
597 if(irccmp(aconf
->host
, name
))
605 if(propagated
&& rb_dlink_list_length(&cluster_conf_list
))
606 cluster_generic(source_p
, "UNXLINE", SHARED_UNXLINE
, CAP_CLUSTER
, "%s", name
);
608 sendto_one_notice(source_p
, ":No RESV for %s", name
);
616 sendto_one_notice(source_p
, ":Cannot remove global RESV %s on specific servers", name
);
619 ptr
= rb_dlinkFind(aconf
, &prop_bans
);
622 sendto_one_notice(source_p
, ":RESV for [%s] is removed", name
);
623 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
624 "%s has removed the global RESV for: [%s]",
625 get_oper_name(source_p
), name
);
626 ilog(L_KLINE
, "UR %s %s", get_oper_name(source_p
), name
);
627 if(aconf
->created
< rb_current_time())
628 aconf
->created
= rb_current_time();
631 aconf
->hold
= aconf
->created
;
632 operhash_delete(aconf
->info
.oper
);
633 aconf
->info
.oper
= operhash_add(get_oper_name(source_p
));
634 aconf
->flags
|= CONF_FLAGS_MYOPER
| CONF_FLAGS_TEMPORARY
;
635 sendto_server(NULL
, NULL
, CAP_BAN
|CAP_TS6
, NOCAPS
,
636 ":%s BAN R * %s %lu %d %d * :*",
637 source_p
->id
, aconf
->host
,
638 (unsigned long)aconf
->created
,
640 (int)(aconf
->lifetime
- aconf
->created
));
641 deactivate_conf(aconf
, ptr
);
644 else if(propagated
&& rb_dlink_list_length(&cluster_conf_list
) > 0)
645 cluster_generic(source_p
, "UNRESV", SHARED_UNRESV
, CAP_CLUSTER
, "%s", name
);
647 sendto_one_notice(source_p
, ":RESV for [%s] is removed", name
);
648 ilog(L_KLINE
, "UR %s %s", get_oper_name(source_p
), name
);
651 bandb_del(BANDB_RESV
, aconf
->host
, NULL
);
652 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
653 "%s has removed the RESV for: [%s]",
654 get_oper_name(source_p
), name
);
658 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
659 "%s has removed the temporary RESV for: [%s]",
660 get_oper_name(source_p
), name
);
662 /* already have ptr from the loop above.. */
663 rb_dlinkDestroy(ptr
, &resv_conf_list
);