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
->name
= rb_strdup(name
);
221 aconf
->passwd
= rb_strdup(reason
);
222 add_to_resv_hash(aconf
->name
, 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
);
238 bandb_add(BANDB_RESV
, source_p
, aconf
->host
, NULL
, aconf
->passwd
, NULL
, 0);
240 else if(clean_resv_nick(name
))
242 if(strlen(name
) > NICKLEN
* 2)
244 sendto_one_notice(source_p
, ":Invalid RESV length: %s", name
);
248 if(strchr(reason
, '"'))
250 sendto_one_notice(source_p
, ":Invalid character '\"' in comment");
254 if(!valid_wild_card_simple(name
))
256 sendto_one_notice(source_p
,
257 ":Please include at least %d non-wildcard "
258 "characters with the resv",
259 ConfigFileEntry
.min_nonwildcard_simple
);
263 if(find_nick_resv_mask(name
))
265 sendto_one_notice(source_p
,
266 ":A RESV has already been placed on nick: %s", name
);
271 aconf
->status
= CONF_RESV_NICK
;
273 aconf
->name
= rb_strdup(name
);
274 aconf
->passwd
= rb_strdup(reason
);
275 rb_dlinkAddAlloc(aconf
, &resv_conf_list
);
279 aconf
->hold
= rb_current_time() + temp_time
;
281 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
282 "%s added temporary %d min. RESV for [%s] [%s]",
283 get_oper_name(source_p
), temp_time
/ 60,
285 ilog(L_KLINE
, "R %s %d %s %s",
286 get_oper_name(source_p
), temp_time
/ 60, name
, reason
);
287 sendto_one_notice(source_p
, ":Added temporary %d min. RESV [%s]",
288 temp_time
/ 60, name
);
291 bandb_add(BANDB_RESV
, source_p
, aconf
->host
, NULL
, aconf
->passwd
, NULL
, 0);
294 sendto_one_notice(source_p
, ":You have specified an invalid resv: [%s]", name
);
298 propagate_resv(struct Client
*source_p
, const char *target
,
299 int temp_time
, const char *name
, const char *reason
)
303 sendto_match_servs(source_p
, target
,
304 CAP_CLUSTER
, NOCAPS
, "RESV %s %s :%s", target
, name
, reason
);
305 sendto_match_servs(source_p
, target
,
306 CAP_ENCAP
, CAP_CLUSTER
,
307 "ENCAP %s RESV %d %s 0 :%s", target
, temp_time
, name
, reason
);
310 sendto_match_servs(source_p
, target
,
312 "ENCAP %s RESV %d %s 0 :%s", target
, temp_time
, name
, reason
);
316 cluster_resv(struct Client
*source_p
, int temp_time
, const char *name
, const char *reason
)
318 struct remote_conf
*shared_p
;
321 RB_DLINK_FOREACH(ptr
, cluster_conf_list
.head
)
323 shared_p
= ptr
->data
;
325 /* old protocol cant handle temps, and we dont really want
326 * to convert them to perm.. --fl
330 if(!(shared_p
->flags
& SHARED_PRESV
))
333 sendto_match_servs(source_p
, shared_p
->server
,
335 "RESV %s %s :%s", shared_p
->server
, name
, reason
);
336 sendto_match_servs(source_p
, shared_p
->server
,
337 CAP_ENCAP
, CAP_CLUSTER
,
338 "ENCAP %s RESV 0 %s 0 :%s",
339 shared_p
->server
, name
, reason
);
341 else if(shared_p
->flags
& SHARED_TRESV
)
342 sendto_match_servs(source_p
, shared_p
->server
,
344 "ENCAP %s RESV %d %s 0 :%s",
345 shared_p
->server
, temp_time
, name
, reason
);
352 * parv[0] = sender prefix
353 * parv[1] = channel/nick to unforbid
356 mo_unresv(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
358 if(!IsOperResv(source_p
))
360 sendto_one(source_p
, form_str(ERR_NOPRIVS
), me
.name
, source_p
->name
, "resv");
364 if((parc
== 4) && (irccmp(parv
[2], "ON") == 0))
366 if(!IsOperRemoteBan(source_p
))
368 sendto_one(source_p
, form_str(ERR_NOPRIVS
),
369 me
.name
, source_p
->name
, "remoteban");
373 propagate_generic(source_p
, "UNRESV", parv
[3], CAP_CLUSTER
, "%s", parv
[1]);
375 if(match(parv
[3], me
.name
) == 0)
378 else if(rb_dlink_list_length(&cluster_conf_list
) > 0)
379 cluster_generic(source_p
, "UNRESV", SHARED_UNRESV
, CAP_CLUSTER
, "%s", parv
[1]);
381 remove_resv(source_p
, parv
[1]);
386 * parv[0] = sender prefix
387 * parv[1] = target server
388 * parv[2] = resv to remove
391 ms_unresv(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
393 /* parv[0] parv[1] parv[2]
394 * oper target server resv to remove
396 propagate_generic(source_p
, "UNRESV", parv
[1], CAP_CLUSTER
, "%s", parv
[2]);
398 if(!match(parv
[1], me
.name
))
401 if(!IsPerson(source_p
))
404 handle_remote_unresv(source_p
, parv
[2]);
409 me_unresv(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
412 if(!IsPerson(source_p
))
415 handle_remote_unresv(source_p
, parv
[1]);
420 handle_remote_unresv(struct Client
*source_p
, const char *name
)
422 if(!find_shared_conf(source_p
->username
, source_p
->host
,
423 source_p
->servptr
->name
, SHARED_UNRESV
))
426 remove_resv(source_p
, name
);
432 remove_resv(struct Client
*source_p
, const char *name
)
434 struct ConfItem
*aconf
= NULL
;
436 if(IsChannelName(name
))
438 if((aconf
= hash_find_resv(name
)) == NULL
)
440 sendto_one_notice(source_p
, ":No RESV for %s", name
);
445 bandb_del(BANDB_RESV
, aconf
->host
, NULL
);
448 sendto_one_notice(source_p
, ":RESV for [%s] is removed", name
);
449 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
450 "%s has removed the RESV for: [%s]",
451 get_oper_name(source_p
), name
);
452 ilog(L_KLINE
, "UR %s %s", get_oper_name(source_p
), name
);
454 del_from_resv_hash(name
, aconf
);
460 RB_DLINK_FOREACH(ptr
, resv_conf_list
.head
)
464 if(irccmp(aconf
->name
, name
))
472 sendto_one_notice(source_p
, ":No RESV for %s", name
);
477 bandb_del(BANDB_RESV
, aconf
->host
, NULL
);
480 sendto_one_notice(source_p
, ":RESV for [%s] is removed", name
);
481 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
482 "%s has removed the RESV for: [%s]",
483 get_oper_name(source_p
), name
);
484 ilog(L_KLINE
, "UR %s %s", get_oper_name(source_p
), name
);
486 /* already have ptr from the loop above.. */
487 rb_dlinkDestroy(ptr
, &resv_conf_list
);