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
);
75 * parv[0] = sender prefix
76 * parv[1] = channel/nick to forbid
80 mo_resv(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
84 const char *target_server
= NULL
;
88 if(!IsOperResv(source_p
))
90 sendto_one(source_p
, form_str(ERR_NOPRIVS
), me
.name
, source_p
->name
, "resv");
94 /* RESV [time] <name> [ON <server>] :<reason> */
96 if((temp_time
= valid_temp_time(parv
[loc
])) >= 0)
98 /* we just set temp_time to -1! */
105 if((parc
>= loc
+ 2) && (irccmp(parv
[loc
], "ON") == 0))
107 if(!IsOperRemoteBan(source_p
))
109 sendto_one(source_p
, form_str(ERR_NOPRIVS
),
110 me
.name
, source_p
->name
, "remoteban");
114 target_server
= parv
[loc
+ 1];
118 if(parc
<= loc
|| EmptyString(parv
[loc
]))
120 sendto_one(source_p
, form_str(ERR_NEEDMOREPARAMS
), me
.name
, source_p
->name
, "RESV");
129 propagate_resv(source_p
, target_server
, temp_time
, name
, reason
);
131 if(match(target_server
, me
.name
) == 0)
134 else if(rb_dlink_list_length(&cluster_conf_list
) > 0)
135 cluster_resv(source_p
, temp_time
, name
, reason
);
137 parse_resv(source_p
, name
, reason
, temp_time
);
143 * parv[0] = sender prefix
144 * parv[1] = target server
145 * parv[2] = channel/nick to forbid
149 ms_resv(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
151 /* parv[0] parv[1] parv[2] parv[3]
152 * oper target server resv reason
154 propagate_resv(source_p
, parv
[1], 0, parv
[2], parv
[3]);
156 if(!match(parv
[1], me
.name
))
159 if(!IsPerson(source_p
))
162 parse_resv(source_p
, parv
[2], parv
[3], 0);
167 me_resv(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
169 /* time name 0 :reason */
170 if(!IsPerson(source_p
))
173 parse_resv(source_p
, parv
[2], parv
[4], atoi(parv
[1]));
179 * inputs - source_p if error messages wanted
183 * side effects - will parse the resv and create it if valid
186 parse_resv(struct Client
*source_p
, const char *name
, const char *reason
, int temp_time
)
188 struct ConfItem
*aconf
;
190 if(!MyClient(source_p
) &&
191 !find_shared_conf(source_p
->username
, source_p
->host
,
192 source_p
->servptr
->name
,
193 (temp_time
> 0) ? SHARED_TRESV
: SHARED_PRESV
))
196 if(IsChannelName(name
))
198 if(hash_find_resv(name
))
200 sendto_one_notice(source_p
,
201 ":A RESV has already been placed on channel: %s", name
);
205 if(strlen(name
) > CHANNELLEN
)
207 sendto_one_notice(source_p
, ":Invalid RESV length: %s", name
);
211 if(strchr(reason
, '"'))
213 sendto_one_notice(source_p
, ":Invalid character '\"' in comment");
218 aconf
->status
= CONF_RESV_CHANNEL
;
220 aconf
->host
= rb_strdup(name
);
221 aconf
->passwd
= rb_strdup(reason
);
222 add_to_resv_hash(aconf
->host
, aconf
);
226 aconf
->hold
= rb_current_time() + temp_time
;
228 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
229 "%s added temporary %d min. RESV for [%s] [%s]",
230 get_oper_name(source_p
), temp_time
/ 60,
232 ilog(L_KLINE
, "R %s %d %s %s",
233 get_oper_name(source_p
), temp_time
/ 60, name
, reason
);
234 sendto_one_notice(source_p
, ":Added temporary %d min. RESV [%s]",
235 temp_time
/ 60, name
);
239 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
240 "%s added RESV for [%s] [%s]",
241 get_oper_name(source_p
), name
, reason
);
242 ilog(L_KLINE
, "R %s 0 %s %s",
243 get_oper_name(source_p
), name
, reason
);
244 sendto_one_notice(source_p
, ":Added RESV [%s]", name
);
246 bandb_add(BANDB_RESV
, source_p
, aconf
->host
, NULL
, aconf
->passwd
, NULL
, 0);
249 else if(clean_resv_nick(name
))
251 if(strlen(name
) > NICKLEN
* 2)
253 sendto_one_notice(source_p
, ":Invalid RESV length: %s", name
);
257 if(strchr(reason
, '"'))
259 sendto_one_notice(source_p
, ":Invalid character '\"' in comment");
263 if(!valid_wild_card_simple(name
))
265 sendto_one_notice(source_p
,
266 ":Please include at least %d non-wildcard "
267 "characters with the resv",
268 ConfigFileEntry
.min_nonwildcard_simple
);
272 if(find_nick_resv_mask(name
))
274 sendto_one_notice(source_p
,
275 ":A RESV has already been placed on nick: %s", name
);
280 aconf
->status
= CONF_RESV_NICK
;
282 aconf
->host
= rb_strdup(name
);
283 aconf
->passwd
= rb_strdup(reason
);
284 rb_dlinkAddAlloc(aconf
, &resv_conf_list
);
288 aconf
->hold
= rb_current_time() + temp_time
;
290 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
291 "%s added temporary %d min. RESV for [%s] [%s]",
292 get_oper_name(source_p
), temp_time
/ 60,
294 ilog(L_KLINE
, "R %s %d %s %s",
295 get_oper_name(source_p
), temp_time
/ 60, name
, reason
);
296 sendto_one_notice(source_p
, ":Added temporary %d min. RESV [%s]",
297 temp_time
/ 60, name
);
301 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
302 "%s added RESV for [%s] [%s]",
303 get_oper_name(source_p
), name
, reason
);
304 ilog(L_KLINE
, "R %s 0 %s %s",
305 get_oper_name(source_p
), name
, reason
);
306 sendto_one_notice(source_p
, ":Added RESV [%s]", name
);
308 bandb_add(BANDB_RESV
, source_p
, aconf
->host
, NULL
, aconf
->passwd
, NULL
, 0);
312 sendto_one_notice(source_p
, ":You have specified an invalid resv: [%s]", name
);
316 propagate_resv(struct Client
*source_p
, const char *target
,
317 int temp_time
, const char *name
, const char *reason
)
321 sendto_match_servs(source_p
, target
,
322 CAP_CLUSTER
, NOCAPS
, "RESV %s %s :%s", target
, name
, reason
);
323 sendto_match_servs(source_p
, target
,
324 CAP_ENCAP
, CAP_CLUSTER
,
325 "ENCAP %s RESV %d %s 0 :%s", target
, temp_time
, name
, reason
);
328 sendto_match_servs(source_p
, target
,
330 "ENCAP %s RESV %d %s 0 :%s", target
, temp_time
, name
, reason
);
334 cluster_resv(struct Client
*source_p
, int temp_time
, const char *name
, const char *reason
)
336 struct remote_conf
*shared_p
;
339 RB_DLINK_FOREACH(ptr
, cluster_conf_list
.head
)
341 shared_p
= ptr
->data
;
343 /* old protocol cant handle temps, and we dont really want
344 * to convert them to perm.. --fl
348 if(!(shared_p
->flags
& SHARED_PRESV
))
351 sendto_match_servs(source_p
, shared_p
->server
,
353 "RESV %s %s :%s", shared_p
->server
, name
, reason
);
354 sendto_match_servs(source_p
, shared_p
->server
,
355 CAP_ENCAP
, CAP_CLUSTER
,
356 "ENCAP %s RESV 0 %s 0 :%s",
357 shared_p
->server
, name
, reason
);
359 else if(shared_p
->flags
& SHARED_TRESV
)
360 sendto_match_servs(source_p
, shared_p
->server
,
362 "ENCAP %s RESV %d %s 0 :%s",
363 shared_p
->server
, temp_time
, name
, reason
);
370 * parv[0] = sender prefix
371 * parv[1] = channel/nick to unforbid
374 mo_unresv(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
376 if(!IsOperResv(source_p
))
378 sendto_one(source_p
, form_str(ERR_NOPRIVS
), me
.name
, source_p
->name
, "resv");
382 if((parc
== 4) && (irccmp(parv
[2], "ON") == 0))
384 if(!IsOperRemoteBan(source_p
))
386 sendto_one(source_p
, form_str(ERR_NOPRIVS
),
387 me
.name
, source_p
->name
, "remoteban");
391 propagate_generic(source_p
, "UNRESV", parv
[3], CAP_CLUSTER
, "%s", parv
[1]);
393 if(match(parv
[3], me
.name
) == 0)
396 else if(rb_dlink_list_length(&cluster_conf_list
) > 0)
397 cluster_generic(source_p
, "UNRESV", SHARED_UNRESV
, CAP_CLUSTER
, "%s", parv
[1]);
399 remove_resv(source_p
, parv
[1]);
404 * parv[0] = sender prefix
405 * parv[1] = target server
406 * parv[2] = resv to remove
409 ms_unresv(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
411 /* parv[0] parv[1] parv[2]
412 * oper target server resv to remove
414 propagate_generic(source_p
, "UNRESV", parv
[1], CAP_CLUSTER
, "%s", parv
[2]);
416 if(!match(parv
[1], me
.name
))
419 if(!IsPerson(source_p
))
422 handle_remote_unresv(source_p
, parv
[2]);
427 me_unresv(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
430 if(!IsPerson(source_p
))
433 handle_remote_unresv(source_p
, parv
[1]);
438 handle_remote_unresv(struct Client
*source_p
, const char *name
)
440 if(!find_shared_conf(source_p
->username
, source_p
->host
,
441 source_p
->servptr
->name
, SHARED_UNRESV
))
444 remove_resv(source_p
, name
);
450 remove_resv(struct Client
*source_p
, const char *name
)
452 struct ConfItem
*aconf
= NULL
;
454 if(IsChannelName(name
))
456 if((aconf
= hash_find_resv(name
)) == NULL
)
458 sendto_one_notice(source_p
, ":No RESV for %s", name
);
463 bandb_del(BANDB_RESV
, aconf
->host
, NULL
);
466 sendto_one_notice(source_p
, ":RESV for [%s] is removed", name
);
467 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
468 "%s has removed the RESV for: [%s]",
469 get_oper_name(source_p
), name
);
470 ilog(L_KLINE
, "UR %s %s", get_oper_name(source_p
), name
);
472 del_from_resv_hash(name
, aconf
);
478 RB_DLINK_FOREACH(ptr
, resv_conf_list
.head
)
482 if(irccmp(aconf
->host
, name
))
490 sendto_one_notice(source_p
, ":No RESV for %s", name
);
495 bandb_del(BANDB_RESV
, aconf
->host
, NULL
);
498 sendto_one_notice(source_p
, ":RESV for [%s] is removed", name
);
499 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
500 "%s has removed the RESV for: [%s]",
501 get_oper_name(source_p
), name
);
502 ilog(L_KLINE
, "UR %s %s", get_oper_name(source_p
), name
);
504 /* already have ptr from the loop above.. */
505 rb_dlinkDestroy(ptr
, &resv_conf_list
);