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"
42 static int mo_resv(struct Client
*, struct Client
*, int, const char **);
43 static int ms_resv(struct Client
*, struct Client
*, int, const char **);
44 static int me_resv(struct Client
*, struct Client
*, int, const char **);
45 static int mo_unresv(struct Client
*, struct Client
*, int, const char **);
46 static int ms_unresv(struct Client
*, struct Client
*, int, const char **);
47 static int me_unresv(struct Client
*, struct Client
*, int, const char **);
49 struct Message resv_msgtab
= {
50 "RESV", 0, 0, 0, MFLG_SLOW
| MFLG_UNREG
,
51 {mg_ignore
, mg_not_oper
, {ms_resv
, 4}, {ms_resv
, 4}, {me_resv
, 5}, {mo_resv
, 3}}
54 struct Message unresv_msgtab
= {
55 "UNRESV", 0, 0, 0, MFLG_SLOW
| MFLG_UNREG
,
56 {mg_ignore
, mg_not_oper
, {ms_unresv
, 3}, {ms_unresv
, 3}, {me_unresv
, 2}, {mo_unresv
, 2}}
59 mapi_clist_av1 resv_clist
[] = { &resv_msgtab
, &unresv_msgtab
, NULL
};
61 DECLARE_MODULE_AV1(resv
, NULL
, NULL
, resv_clist
, NULL
, NULL
, "$Revision$");
63 static void parse_resv(struct Client
*source_p
, const char *name
,
64 const char *reason
, int temp_time
);
65 static void propagate_resv(struct Client
*source_p
, const char *target
,
66 int temp_time
, const char *name
, const char *reason
);
67 static void cluster_resv(struct Client
*source_p
, int temp_time
,
68 const char *name
, const char *reason
);
70 static void handle_remote_unresv(struct Client
*source_p
, const char *name
);
71 static void remove_resv(struct Client
*source_p
, const char *name
);
72 static void resv_chan_forcepart(const char *name
, const char *reason
, int temp_time
);
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
;
89 if(!IsOperResv(source_p
))
91 sendto_one(source_p
, form_str(ERR_NOPRIVS
), me
.name
, source_p
->name
, "resv");
95 /* RESV [time] <name> [ON <server>] :<reason> */
97 if((temp_time
= valid_temp_time(parv
[loc
])) >= 0)
99 /* we just set temp_time to -1! */
106 if((parc
>= loc
+ 2) && (irccmp(parv
[loc
], "ON") == 0))
108 if(!IsOperRemoteBan(source_p
))
110 sendto_one(source_p
, form_str(ERR_NOPRIVS
),
111 me
.name
, source_p
->name
, "remoteban");
115 target_server
= parv
[loc
+ 1];
119 if(parc
<= loc
|| EmptyString(parv
[loc
]))
121 sendto_one(source_p
, form_str(ERR_NEEDMOREPARAMS
), me
.name
, source_p
->name
, "RESV");
130 propagate_resv(source_p
, target_server
, temp_time
, name
, reason
);
132 if(match(target_server
, me
.name
) == 0)
135 else if(rb_dlink_list_length(&cluster_conf_list
) > 0)
136 cluster_resv(source_p
, temp_time
, name
, reason
);
138 parse_resv(source_p
, name
, reason
, temp_time
);
144 * parv[0] = sender prefix
145 * parv[1] = target server
146 * parv[2] = channel/nick to forbid
150 ms_resv(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
152 /* parv[0] parv[1] parv[2] parv[3]
153 * oper target server resv reason
155 propagate_resv(source_p
, parv
[1], 0, parv
[2], parv
[3]);
157 if(!match(parv
[1], me
.name
))
160 if(!IsPerson(source_p
))
163 parse_resv(source_p
, parv
[2], parv
[3], 0);
168 me_resv(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
170 /* time name 0 :reason */
171 if(!IsPerson(source_p
))
174 parse_resv(source_p
, parv
[2], parv
[4], atoi(parv
[1]));
180 * inputs - source_p if error messages wanted
184 * side effects - will parse the resv and create it if valid
187 parse_resv(struct Client
*source_p
, const char *name
, const char *reason
, int temp_time
)
189 struct ConfItem
*aconf
;
191 if(!MyClient(source_p
) &&
192 !find_shared_conf(source_p
->username
, source_p
->host
,
193 source_p
->servptr
->name
,
194 (temp_time
> 0) ? SHARED_TRESV
: SHARED_PRESV
))
197 if(IsChannelName(name
))
199 if(hash_find_resv(name
))
201 sendto_one_notice(source_p
,
202 ":A RESV has already been placed on channel: %s", name
);
206 if(strlen(name
) > CHANNELLEN
)
208 sendto_one_notice(source_p
, ":Invalid RESV length: %s", name
);
212 if(strchr(reason
, '"'))
214 sendto_one_notice(source_p
, ":Invalid character '\"' in comment");
219 aconf
->status
= CONF_RESV_CHANNEL
;
221 aconf
->host
= rb_strdup(name
);
222 aconf
->passwd
= rb_strdup(reason
);
223 add_to_resv_hash(aconf
->host
, aconf
);
224 resv_chan_forcepart(aconf
->host
, aconf
->passwd
, temp_time
);
228 aconf
->hold
= rb_current_time() + temp_time
;
230 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
231 "%s added temporary %d min. RESV for [%s] [%s]",
232 get_oper_name(source_p
), temp_time
/ 60,
234 ilog(L_KLINE
, "R %s %d %s %s",
235 get_oper_name(source_p
), temp_time
/ 60, name
, reason
);
236 sendto_one_notice(source_p
, ":Added temporary %d min. RESV [%s]",
237 temp_time
/ 60, name
);
241 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
242 "%s added RESV for [%s] [%s]",
243 get_oper_name(source_p
), name
, reason
);
244 ilog(L_KLINE
, "R %s 0 %s %s",
245 get_oper_name(source_p
), name
, reason
);
246 sendto_one_notice(source_p
, ":Added RESV [%s]", name
);
248 bandb_add(BANDB_RESV
, source_p
, aconf
->host
, NULL
, aconf
->passwd
, NULL
, 0);
251 else if(clean_resv_nick(name
))
253 if(strlen(name
) > NICKLEN
* 2)
255 sendto_one_notice(source_p
, ":Invalid RESV length: %s", name
);
259 if(strchr(reason
, '"'))
261 sendto_one_notice(source_p
, ":Invalid character '\"' in comment");
265 if(!valid_wild_card_simple(name
))
267 sendto_one_notice(source_p
,
268 ":Please include at least %d non-wildcard "
269 "characters with the resv",
270 ConfigFileEntry
.min_nonwildcard_simple
);
274 if(find_nick_resv_mask(name
))
276 sendto_one_notice(source_p
,
277 ":A RESV has already been placed on nick: %s", name
);
282 aconf
->status
= CONF_RESV_NICK
;
284 aconf
->host
= rb_strdup(name
);
285 aconf
->passwd
= rb_strdup(reason
);
286 rb_dlinkAddAlloc(aconf
, &resv_conf_list
);
290 aconf
->hold
= rb_current_time() + temp_time
;
292 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
293 "%s added temporary %d min. RESV for [%s] [%s]",
294 get_oper_name(source_p
), temp_time
/ 60,
296 ilog(L_KLINE
, "R %s %d %s %s",
297 get_oper_name(source_p
), temp_time
/ 60, name
, reason
);
298 sendto_one_notice(source_p
, ":Added temporary %d min. RESV [%s]",
299 temp_time
/ 60, name
);
303 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
304 "%s added RESV for [%s] [%s]",
305 get_oper_name(source_p
), name
, reason
);
306 ilog(L_KLINE
, "R %s 0 %s %s",
307 get_oper_name(source_p
), name
, reason
);
308 sendto_one_notice(source_p
, ":Added RESV [%s]", name
);
310 bandb_add(BANDB_RESV
, source_p
, aconf
->host
, NULL
, aconf
->passwd
, NULL
, 0);
314 sendto_one_notice(source_p
, ":You have specified an invalid resv: [%s]", name
);
318 propagate_resv(struct Client
*source_p
, const char *target
,
319 int temp_time
, const char *name
, const char *reason
)
323 sendto_match_servs(source_p
, target
,
324 CAP_CLUSTER
, NOCAPS
, "RESV %s %s :%s", target
, name
, reason
);
325 sendto_match_servs(source_p
, target
,
326 CAP_ENCAP
, CAP_CLUSTER
,
327 "ENCAP %s RESV %d %s 0 :%s", target
, temp_time
, name
, reason
);
330 sendto_match_servs(source_p
, target
,
332 "ENCAP %s RESV %d %s 0 :%s", target
, temp_time
, name
, reason
);
336 cluster_resv(struct Client
*source_p
, int temp_time
, const char *name
, const char *reason
)
338 struct remote_conf
*shared_p
;
341 RB_DLINK_FOREACH(ptr
, cluster_conf_list
.head
)
343 shared_p
= ptr
->data
;
345 /* old protocol cant handle temps, and we dont really want
346 * to convert them to perm.. --fl
350 if(!(shared_p
->flags
& SHARED_PRESV
))
353 sendto_match_servs(source_p
, shared_p
->server
,
355 "RESV %s %s :%s", shared_p
->server
, name
, reason
);
356 sendto_match_servs(source_p
, shared_p
->server
,
357 CAP_ENCAP
, CAP_CLUSTER
,
358 "ENCAP %s RESV 0 %s 0 :%s",
359 shared_p
->server
, name
, reason
);
361 else if(shared_p
->flags
& SHARED_TRESV
)
362 sendto_match_servs(source_p
, shared_p
->server
,
364 "ENCAP %s RESV %d %s 0 :%s",
365 shared_p
->server
, temp_time
, name
, reason
);
372 * parv[0] = sender prefix
373 * parv[1] = channel/nick to unforbid
376 mo_unresv(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
378 if(!IsOperResv(source_p
))
380 sendto_one(source_p
, form_str(ERR_NOPRIVS
), me
.name
, source_p
->name
, "resv");
384 if((parc
== 4) && (irccmp(parv
[2], "ON") == 0))
386 if(!IsOperRemoteBan(source_p
))
388 sendto_one(source_p
, form_str(ERR_NOPRIVS
),
389 me
.name
, source_p
->name
, "remoteban");
393 propagate_generic(source_p
, "UNRESV", parv
[3], CAP_CLUSTER
, "%s", parv
[1]);
395 if(match(parv
[3], me
.name
) == 0)
398 else if(rb_dlink_list_length(&cluster_conf_list
) > 0)
399 cluster_generic(source_p
, "UNRESV", SHARED_UNRESV
, CAP_CLUSTER
, "%s", parv
[1]);
401 remove_resv(source_p
, parv
[1]);
406 * parv[0] = sender prefix
407 * parv[1] = target server
408 * parv[2] = resv to remove
411 ms_unresv(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
413 /* parv[0] parv[1] parv[2]
414 * oper target server resv to remove
416 propagate_generic(source_p
, "UNRESV", parv
[1], CAP_CLUSTER
, "%s", parv
[2]);
418 if(!match(parv
[1], me
.name
))
421 if(!IsPerson(source_p
))
424 handle_remote_unresv(source_p
, parv
[2]);
429 me_unresv(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
432 if(!IsPerson(source_p
))
435 handle_remote_unresv(source_p
, parv
[1]);
440 handle_remote_unresv(struct Client
*source_p
, const char *name
)
442 if(!find_shared_conf(source_p
->username
, source_p
->host
,
443 source_p
->servptr
->name
, SHARED_UNRESV
))
446 remove_resv(source_p
, name
);
452 remove_resv(struct Client
*source_p
, const char *name
)
454 struct ConfItem
*aconf
= NULL
;
456 if(IsChannelName(name
))
458 if((aconf
= hash_find_resv(name
)) == NULL
)
460 sendto_one_notice(source_p
, ":No RESV for %s", name
);
464 sendto_one_notice(source_p
, ":RESV for [%s] is removed", name
);
465 ilog(L_KLINE
, "UR %s %s", get_oper_name(source_p
), name
);
468 bandb_del(BANDB_RESV
, aconf
->host
, NULL
);
469 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
470 "%s has removed the RESV for: [%s]",
471 get_oper_name(source_p
), name
);
475 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
476 "%s has removed the temporary RESV for: [%s]",
477 get_oper_name(source_p
), name
);
479 del_from_resv_hash(name
, aconf
);
485 RB_DLINK_FOREACH(ptr
, resv_conf_list
.head
)
489 if(irccmp(aconf
->host
, name
))
497 sendto_one_notice(source_p
, ":No RESV for %s", name
);
502 bandb_del(BANDB_RESV
, aconf
->host
, NULL
);
505 sendto_one_notice(source_p
, ":RESV for [%s] is removed", name
);
506 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
507 "%s has removed the RESV for: [%s]",
508 get_oper_name(source_p
), name
);
509 ilog(L_KLINE
, "UR %s %s", get_oper_name(source_p
), name
);
511 /* already have ptr from the loop above.. */
512 rb_dlinkDestroy(ptr
, &resv_conf_list
);
520 resv_chan_forcepart(const char *name
, const char *reason
, int temp_time
)
523 rb_dlink_node
*next_ptr
;
524 struct Channel
*chptr
;
525 struct membership
*msptr
;
526 struct Client
*target_p
;
528 if(!ConfigChannel
.resv_forcepart
)
531 /* for each user on our server in the channel list
532 * send them a PART, and notify opers.
534 chptr
= find_channel(name
);
537 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->locmembers
.head
)
540 target_p
= msptr
->client_p
;
542 if(IsExemptResv(target_p
))
545 sendto_server(target_p
, chptr
, CAP_TS6
, NOCAPS
,
546 ":%s PART %s", target_p
->id
, chptr
->chname
);
548 sendto_channel_local(ALL_MEMBERS
, chptr
, ":%s!%s@%s PART %s :%s",
549 target_p
->name
, target_p
->username
,
550 target_p
->host
, chptr
->chname
, target_p
->name
);
552 remove_user_from_channel(msptr
);
554 /* notify opers & user they were removed from the channel */
555 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
556 "Forced PART for %s!%s@%s from %s (%s)",
557 target_p
->name
, target_p
->username
,
558 target_p
->host
, name
, reason
);
561 sendto_one_notice(target_p
, ":*** Channel %s is temporarily unavailable on this server.",
564 sendto_one_notice(target_p
, ":*** Channel %s is no longer available on this server.",