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
35 #include "s_newconf.h"
41 static const char resv_desc
[] =
42 "Provides management of reserved nicknames and channels using (UN)RESV";
44 static void mo_resv(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
45 static void ms_resv(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
46 static void me_resv(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
47 static void mo_unresv(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
48 static void ms_unresv(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
49 static void me_unresv(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
51 struct Message resv_msgtab
= {
53 {mg_ignore
, mg_not_oper
, {ms_resv
, 4}, {ms_resv
, 4}, {me_resv
, 5}, {mo_resv
, 3}}
56 struct Message unresv_msgtab
= {
58 {mg_ignore
, mg_not_oper
, {ms_unresv
, 3}, {ms_unresv
, 3}, {me_unresv
, 2}, {mo_unresv
, 2}}
61 mapi_clist_av1 resv_clist
[] = { &resv_msgtab
, &unresv_msgtab
, NULL
};
63 DECLARE_MODULE_AV2(resv
, NULL
, NULL
, resv_clist
, NULL
, NULL
, NULL
, NULL
, resv_desc
);
65 static void parse_resv(struct Client
*source_p
, const char *name
,
66 const char *reason
, int temp_time
, int propagated
);
67 static void propagate_resv(struct Client
*source_p
, const char *target
,
68 int temp_time
, const char *name
, const char *reason
);
69 static void cluster_resv(struct Client
*source_p
, int temp_time
,
70 const char *name
, const char *reason
);
72 static void handle_remote_unresv(struct Client
*source_p
, const char *name
);
73 static void remove_resv(struct Client
*source_p
, const char *name
, int propagated
);
77 * parv[1] = channel/nick to forbid
81 mo_resv(struct MsgBuf
*msgbuf_p
, 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
);
152 * parv[1] = target server
153 * parv[2] = channel/nick to forbid
157 ms_resv(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
159 /* parv[0] parv[1] parv[2] parv[3]
160 * oper target server resv reason
162 propagate_resv(source_p
, parv
[1], 0, parv
[2], parv
[3]);
164 if(!match(parv
[1], me
.name
))
167 if(!IsPerson(source_p
))
170 parse_resv(source_p
, parv
[2], parv
[3], 0, 0);
174 me_resv(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
176 /* time name 0 :reason */
177 if(!IsPerson(source_p
))
180 parse_resv(source_p
, parv
[2], parv
[4], atoi(parv
[1]), 0);
185 * inputs - source_p if error messages wanted
189 * side effects - will parse the resv and create it if valid
192 parse_resv(struct Client
*source_p
, const char *name
, const char *reason
, int temp_time
, int propagated
)
194 struct ConfItem
*aconf
;
196 if(!MyClient(source_p
) &&
197 !find_shared_conf(source_p
->username
, source_p
->host
,
198 source_p
->servptr
->name
,
199 (temp_time
> 0) ? SHARED_TRESV
: SHARED_PRESV
))
202 if(IsChannelName(name
))
204 if(hash_find_resv(name
))
206 sendto_one_notice(source_p
,
207 ":A RESV has already been placed on channel: %s", name
);
211 if(strlen(name
) > CHANNELLEN
)
213 sendto_one_notice(source_p
, ":Invalid RESV length: %s", name
);
218 aconf
->status
= CONF_RESV_CHANNEL
;
220 aconf
->created
= rb_current_time();
221 aconf
->host
= rb_strdup(name
);
222 aconf
->passwd
= rb_strdup(reason
);
223 aconf
->info
.oper
= operhash_add(get_oper_name(source_p
));
227 aconf
->flags
|= CONF_FLAGS_MYOPER
| CONF_FLAGS_TEMPORARY
;
228 aconf
->hold
= rb_current_time() + temp_time
;
229 aconf
->lifetime
= aconf
->hold
;
230 replace_old_ban(aconf
);
231 rb_dlinkAddAlloc(aconf
, &prop_bans
);
233 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
234 "%s added global %d min. RESV for [%s] [%s]",
235 get_oper_name(source_p
), temp_time
/ 60,
237 ilog(L_KLINE
, "R %s %d %s %s",
238 get_oper_name(source_p
), temp_time
/ 60, name
, reason
);
239 sendto_one_notice(source_p
, ":Added global %d min. RESV [%s]",
240 temp_time
/ 60, name
);
241 sendto_server(NULL
, NULL
, CAP_BAN
|CAP_TS6
, NOCAPS
,
242 ":%s BAN R * %s %lu %d %d * :%s",
243 source_p
->id
, aconf
->host
,
244 (unsigned long)aconf
->created
,
245 (int)(aconf
->hold
- aconf
->created
),
246 (int)(aconf
->lifetime
- aconf
->created
),
249 else if(temp_time
> 0)
251 aconf
->hold
= rb_current_time() + temp_time
;
253 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
254 "%s added temporary %d min. RESV for [%s] [%s]",
255 get_oper_name(source_p
), temp_time
/ 60,
257 ilog(L_KLINE
, "R %s %d %s %s",
258 get_oper_name(source_p
), temp_time
/ 60, name
, reason
);
259 sendto_one_notice(source_p
, ":Added temporary %d min. RESV [%s]",
260 temp_time
/ 60, name
);
264 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
265 "%s added RESV for [%s] [%s]",
266 get_oper_name(source_p
), name
, reason
);
267 ilog(L_KLINE
, "R %s 0 %s %s",
268 get_oper_name(source_p
), name
, reason
);
269 sendto_one_notice(source_p
, ":Added RESV [%s]", name
);
271 bandb_add(BANDB_RESV
, source_p
, aconf
->host
, NULL
, aconf
->passwd
, NULL
, 0);
274 add_to_resv_hash(aconf
->host
, aconf
);
275 resv_chan_forcepart(aconf
->host
, aconf
->passwd
, temp_time
);
277 else if(clean_resv_nick(name
))
279 if(strlen(name
) > NICKLEN
* 2)
281 sendto_one_notice(source_p
, ":Invalid RESV length: %s", name
);
285 if(!valid_wild_card_simple(name
))
287 sendto_one_notice(source_p
,
288 ":Please include at least %d non-wildcard "
289 "characters with the resv",
290 ConfigFileEntry
.min_nonwildcard_simple
);
294 if(find_nick_resv_mask(name
))
296 sendto_one_notice(source_p
,
297 ":A RESV has already been placed on nick: %s", name
);
302 aconf
->status
= CONF_RESV_NICK
;
304 aconf
->created
= rb_current_time();
305 aconf
->host
= rb_strdup(name
);
306 aconf
->passwd
= rb_strdup(reason
);
307 aconf
->info
.oper
= operhash_add(get_oper_name(source_p
));
311 aconf
->flags
|= CONF_FLAGS_MYOPER
| CONF_FLAGS_TEMPORARY
;
312 aconf
->hold
= rb_current_time() + temp_time
;
313 aconf
->lifetime
= aconf
->hold
;
314 replace_old_ban(aconf
);
315 rb_dlinkAddAlloc(aconf
, &prop_bans
);
317 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
318 "%s added global %d min. RESV for [%s] [%s]",
319 get_oper_name(source_p
), temp_time
/ 60,
321 ilog(L_KLINE
, "R %s %d %s %s",
322 get_oper_name(source_p
), temp_time
/ 60, name
, reason
);
323 sendto_one_notice(source_p
, ":Added global %d min. RESV [%s]",
324 temp_time
/ 60, name
);
325 sendto_server(NULL
, NULL
, CAP_BAN
|CAP_TS6
, NOCAPS
,
326 ":%s BAN R * %s %lu %d %d * :%s",
327 source_p
->id
, aconf
->host
,
328 (unsigned long)aconf
->created
,
329 (int)(aconf
->hold
- aconf
->created
),
330 (int)(aconf
->lifetime
- aconf
->created
),
333 else if(temp_time
> 0)
335 aconf
->hold
= rb_current_time() + temp_time
;
337 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
338 "%s added temporary %d min. RESV for [%s] [%s]",
339 get_oper_name(source_p
), temp_time
/ 60,
341 ilog(L_KLINE
, "R %s %d %s %s",
342 get_oper_name(source_p
), temp_time
/ 60, name
, reason
);
343 sendto_one_notice(source_p
, ":Added temporary %d min. RESV [%s]",
344 temp_time
/ 60, name
);
348 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
349 "%s added RESV for [%s] [%s]",
350 get_oper_name(source_p
), name
, reason
);
351 ilog(L_KLINE
, "R %s 0 %s %s",
352 get_oper_name(source_p
), name
, reason
);
353 sendto_one_notice(source_p
, ":Added RESV [%s]", name
);
355 bandb_add(BANDB_RESV
, source_p
, aconf
->host
, NULL
, aconf
->passwd
, NULL
, 0);
358 rb_dlinkAddAlloc(aconf
, &resv_conf_list
);
359 resv_nick_fnc(aconf
->host
, aconf
->passwd
, temp_time
);
362 sendto_one_notice(source_p
, ":You have specified an invalid resv: [%s]", name
);
366 propagate_resv(struct Client
*source_p
, const char *target
,
367 int temp_time
, const char *name
, const char *reason
)
371 sendto_match_servs(source_p
, target
,
372 CAP_CLUSTER
, NOCAPS
, "RESV %s %s :%s", target
, name
, reason
);
373 sendto_match_servs(source_p
, target
,
374 CAP_ENCAP
, CAP_CLUSTER
,
375 "ENCAP %s RESV %d %s 0 :%s", target
, temp_time
, name
, reason
);
378 sendto_match_servs(source_p
, target
,
380 "ENCAP %s RESV %d %s 0 :%s", target
, temp_time
, name
, reason
);
384 cluster_resv(struct Client
*source_p
, int temp_time
, const char *name
, const char *reason
)
386 struct remote_conf
*shared_p
;
389 RB_DLINK_FOREACH(ptr
, cluster_conf_list
.head
)
391 shared_p
= ptr
->data
;
393 /* old protocol cant handle temps, and we dont really want
394 * to convert them to perm.. --fl
398 if(!(shared_p
->flags
& SHARED_PRESV
))
401 sendto_match_servs(source_p
, shared_p
->server
,
403 "RESV %s %s :%s", shared_p
->server
, name
, reason
);
404 sendto_match_servs(source_p
, shared_p
->server
,
405 CAP_ENCAP
, CAP_CLUSTER
,
406 "ENCAP %s RESV 0 %s 0 :%s",
407 shared_p
->server
, name
, reason
);
409 else if(shared_p
->flags
& SHARED_TRESV
)
410 sendto_match_servs(source_p
, shared_p
->server
,
412 "ENCAP %s RESV %d %s 0 :%s",
413 shared_p
->server
, temp_time
, name
, reason
);
420 * parv[1] = channel/nick to unforbid
423 mo_unresv(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
427 if(!IsOperResv(source_p
))
429 sendto_one(source_p
, form_str(ERR_NOPRIVS
), me
.name
, source_p
->name
, "resv");
433 if((parc
== 4) && (irccmp(parv
[2], "ON") == 0))
435 if(!IsOperRemoteBan(source_p
))
437 sendto_one(source_p
, form_str(ERR_NOPRIVS
),
438 me
.name
, source_p
->name
, "remoteban");
442 propagate_generic(source_p
, "UNRESV", parv
[3], CAP_CLUSTER
, "%s", parv
[1]);
444 if(match(parv
[3], me
.name
) == 0)
450 else if(rb_dlink_list_length(&cluster_conf_list
) > 0)
451 cluster_generic(source_p
, "UNRESV", SHARED_UNRESV
, CAP_CLUSTER
, "%s", parv
[1]);
453 /* cluster{} moved to remove_resv */
455 remove_resv(source_p
, parv
[1], propagated
);
459 * parv[1] = target server
460 * parv[2] = resv to remove
463 ms_unresv(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
465 /* parv[0] parv[1] parv[2]
466 * oper target server resv to remove
468 propagate_generic(source_p
, "UNRESV", parv
[1], CAP_CLUSTER
, "%s", parv
[2]);
470 if(!match(parv
[1], me
.name
))
473 if(!IsPerson(source_p
))
476 handle_remote_unresv(source_p
, parv
[2]);
480 me_unresv(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
483 if(!IsPerson(source_p
))
486 handle_remote_unresv(source_p
, parv
[1]);
490 handle_remote_unresv(struct Client
*source_p
, const char *name
)
492 if(!find_shared_conf(source_p
->username
, source_p
->host
,
493 source_p
->servptr
->name
, SHARED_UNRESV
))
496 remove_resv(source_p
, name
, 0);
502 remove_resv(struct Client
*source_p
, const char *name
, int propagated
)
504 struct ConfItem
*aconf
= NULL
;
508 if(IsChannelName(name
))
510 if((aconf
= hash_find_resv(name
)) == NULL
)
512 if(propagated
&& rb_dlink_list_length(&cluster_conf_list
))
513 cluster_generic(source_p
, "UNRESV", SHARED_UNRESV
, CAP_CLUSTER
, "%s", name
);
515 sendto_one_notice(source_p
, ":No RESV for %s", name
);
523 sendto_one_notice(source_p
, ":Cannot remove global RESV %s on specific servers", name
);
526 ptr
= rb_dlinkFind(aconf
, &prop_bans
);
529 sendto_one_notice(source_p
, ":RESV for [%s] is removed", name
);
530 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
531 "%s has removed the global RESV for: [%s]",
532 get_oper_name(source_p
), name
);
533 ilog(L_KLINE
, "UR %s %s", get_oper_name(source_p
), name
);
534 now
= rb_current_time();
535 if(aconf
->created
< now
)
536 aconf
->created
= now
;
539 aconf
->hold
= aconf
->created
;
540 operhash_delete(aconf
->info
.oper
);
541 aconf
->info
.oper
= operhash_add(get_oper_name(source_p
));
542 aconf
->flags
|= CONF_FLAGS_MYOPER
| CONF_FLAGS_TEMPORARY
;
543 sendto_server(NULL
, NULL
, CAP_BAN
|CAP_TS6
, NOCAPS
,
544 ":%s BAN R * %s %lu %d %d * :*",
545 source_p
->id
, aconf
->host
,
546 (unsigned long)aconf
->created
,
548 (int)(aconf
->lifetime
- aconf
->created
));
549 deactivate_conf(aconf
, ptr
, now
);
552 else if(propagated
&& rb_dlink_list_length(&cluster_conf_list
) > 0)
553 cluster_generic(source_p
, "UNRESV", SHARED_UNRESV
, CAP_CLUSTER
, "%s", name
);
555 sendto_one_notice(source_p
, ":RESV for [%s] is removed", name
);
556 ilog(L_KLINE
, "UR %s %s", get_oper_name(source_p
), name
);
559 bandb_del(BANDB_RESV
, aconf
->host
, NULL
);
560 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
561 "%s has removed the RESV for: [%s]",
562 get_oper_name(source_p
), name
);
566 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
567 "%s has removed the temporary RESV for: [%s]",
568 get_oper_name(source_p
), name
);
570 del_from_resv_hash(name
, aconf
);
574 RB_DLINK_FOREACH(ptr
, resv_conf_list
.head
)
578 if(irccmp(aconf
->host
, name
))
586 if(propagated
&& rb_dlink_list_length(&cluster_conf_list
))
587 cluster_generic(source_p
, "UNRESV", SHARED_UNRESV
, CAP_CLUSTER
, "%s", name
);
589 sendto_one_notice(source_p
, ":No RESV for %s", name
);
597 sendto_one_notice(source_p
, ":Cannot remove global RESV %s on specific servers", name
);
600 ptr
= rb_dlinkFind(aconf
, &prop_bans
);
603 sendto_one_notice(source_p
, ":RESV for [%s] is removed", name
);
604 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
605 "%s has removed the global RESV for: [%s]",
606 get_oper_name(source_p
), name
);
607 ilog(L_KLINE
, "UR %s %s", get_oper_name(source_p
), name
);
608 now
= rb_current_time();
609 if(aconf
->created
< now
)
610 aconf
->created
= now
;
613 aconf
->hold
= aconf
->created
;
614 operhash_delete(aconf
->info
.oper
);
615 aconf
->info
.oper
= operhash_add(get_oper_name(source_p
));
616 aconf
->flags
|= CONF_FLAGS_MYOPER
| CONF_FLAGS_TEMPORARY
;
617 sendto_server(NULL
, NULL
, CAP_BAN
|CAP_TS6
, NOCAPS
,
618 ":%s BAN R * %s %lu %d %d * :*",
619 source_p
->id
, aconf
->host
,
620 (unsigned long)aconf
->created
,
622 (int)(aconf
->lifetime
- aconf
->created
));
623 deactivate_conf(aconf
, ptr
, now
);
626 else if(propagated
&& rb_dlink_list_length(&cluster_conf_list
) > 0)
627 cluster_generic(source_p
, "UNRESV", SHARED_UNRESV
, CAP_CLUSTER
, "%s", name
);
629 sendto_one_notice(source_p
, ":RESV for [%s] is removed", name
);
630 ilog(L_KLINE
, "UR %s %s", get_oper_name(source_p
), name
);
633 bandb_del(BANDB_RESV
, aconf
->host
, NULL
);
634 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
635 "%s has removed the RESV for: [%s]",
636 get_oper_name(source_p
), name
);
640 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
641 "%s has removed the temporary RESV for: [%s]",
642 get_oper_name(source_p
), name
);
644 /* already have ptr from the loop above.. */
645 rb_dlinkDestroy(ptr
, &resv_conf_list
);