| 1 |
michael |
3354 |
/* |
| 2 |
|
|
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
| 3 |
|
|
* |
| 4 |
michael |
5347 |
* Copyright (c) 2001-2015 ircd-hybrid development team |
| 5 |
michael |
3354 |
* |
| 6 |
|
|
* This program is free software; you can redistribute it and/or modify |
| 7 |
|
|
* it under the terms of the GNU General Public License as published by |
| 8 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
| 9 |
|
|
* (at your option) any later version. |
| 10 |
|
|
* |
| 11 |
|
|
* This program is distributed in the hope that it will be useful, |
| 12 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
|
|
* GNU General Public License for more details. |
| 15 |
|
|
* |
| 16 |
|
|
* You should have received a copy of the GNU General Public License |
| 17 |
|
|
* along with this program; if not, write to the Free Software |
| 18 |
michael |
4565 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 |
| 19 |
michael |
3354 |
* USA |
| 20 |
|
|
*/ |
| 21 |
|
|
|
| 22 |
|
|
/*! \file m_unresv.c |
| 23 |
|
|
* \brief Includes required functions for processing the UNRESV command. |
| 24 |
michael |
3355 |
* \version $Id$ |
| 25 |
michael |
3354 |
*/ |
| 26 |
|
|
|
| 27 |
|
|
#include "stdinc.h" |
| 28 |
|
|
#include "client.h" |
| 29 |
|
|
#include "ircd.h" |
| 30 |
|
|
#include "irc_string.h" |
| 31 |
|
|
#include "numeric.h" |
| 32 |
|
|
#include "server.h" |
| 33 |
|
|
#include "send.h" |
| 34 |
|
|
#include "parse.h" |
| 35 |
|
|
#include "modules.h" |
| 36 |
|
|
#include "conf.h" |
| 37 |
|
|
#include "log.h" |
| 38 |
|
|
#include "resv.h" |
| 39 |
|
|
|
| 40 |
|
|
|
| 41 |
|
|
static void |
| 42 |
michael |
5837 |
resv_remove(struct Client *source_p, const char *name) |
| 43 |
michael |
3354 |
{ |
| 44 |
michael |
5837 |
unsigned int type_int = CONF_CRESV; |
| 45 |
|
|
const char *type_str = "channel"; |
| 46 |
michael |
3354 |
struct MaskItem *conf = NULL; |
| 47 |
|
|
|
| 48 |
michael |
5837 |
if (!IsChanPrefix(*name)) |
| 49 |
michael |
3354 |
{ |
| 50 |
michael |
5837 |
type_int = CONF_NRESV; |
| 51 |
|
|
type_str = "nick"; |
| 52 |
|
|
} |
| 53 |
michael |
4890 |
|
| 54 |
michael |
5837 |
if ((conf = find_exact_name_conf(type_int, NULL, name, NULL, NULL)) == NULL) |
| 55 |
|
|
{ |
| 56 |
|
|
if (IsClient(source_p)) |
| 57 |
|
|
sendto_one_notice(source_p, &me, ":A RESV does not exist for %s: %s", type_str, name); |
| 58 |
michael |
3354 |
|
| 59 |
michael |
5837 |
return; |
| 60 |
|
|
} |
| 61 |
michael |
4890 |
|
| 62 |
michael |
5837 |
if (!IsConfDatabase(conf)) |
| 63 |
|
|
{ |
| 64 |
michael |
4650 |
if (IsClient(source_p)) |
| 65 |
michael |
5837 |
sendto_one_notice(source_p, &me, ":The RESV for %s: %s is in ircd.conf and must be removed by hand.", |
| 66 |
|
|
type_str, name); |
| 67 |
|
|
return; |
| 68 |
michael |
3354 |
} |
| 69 |
michael |
4890 |
|
| 70 |
michael |
5837 |
conf_free(conf); |
| 71 |
michael |
3354 |
|
| 72 |
michael |
5837 |
if (IsClient(source_p)) |
| 73 |
|
|
sendto_one_notice(source_p, &me, ":The RESV has been removed on %s: %s", type_str, name); |
| 74 |
michael |
4890 |
|
| 75 |
michael |
5837 |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
| 76 |
|
|
"%s has removed the RESV for %s: %s", |
| 77 |
|
|
get_oper_name(source_p), type_str, name); |
| 78 |
|
|
ilog(LOG_TYPE_RESV, "%s removed RESV for [%s]", |
| 79 |
|
|
get_oper_name(source_p), name); |
| 80 |
michael |
3354 |
} |
| 81 |
|
|
|
| 82 |
michael |
3365 |
/*! \brief UNRESV command handler |
| 83 |
|
|
* |
| 84 |
|
|
* \param source_p Pointer to allocated Client struct from which the message |
| 85 |
|
|
* originally comes from. This can be a local or remote client. |
| 86 |
|
|
* \param parc Integer holding the number of supplied arguments. |
| 87 |
|
|
* \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL |
| 88 |
|
|
* pointers. |
| 89 |
|
|
* \note Valid arguments for this command are: |
| 90 |
|
|
* - parv[0] = command |
| 91 |
|
|
* - parv[1] = channel/nick |
| 92 |
|
|
* - parv[2] = "ON" |
| 93 |
|
|
* - parv[3] = target server |
| 94 |
michael |
3354 |
*/ |
| 95 |
|
|
static int |
| 96 |
|
|
mo_unresv(struct Client *source_p, int parc, char *parv[]) |
| 97 |
|
|
{ |
| 98 |
|
|
char *resv = NULL; |
| 99 |
|
|
char *reason = NULL; |
| 100 |
|
|
char *target_server = NULL; |
| 101 |
|
|
|
| 102 |
|
|
/* UNRESV #channel ON irc.server.com */ |
| 103 |
|
|
/* UNRESV kiddie ON irc.server.com */ |
| 104 |
michael |
5776 |
if (!parse_aline("UNRESV", source_p, parc, parv, 0, &resv, NULL, |
| 105 |
|
|
NULL, &target_server, &reason)) |
| 106 |
michael |
3354 |
return 0; |
| 107 |
|
|
|
| 108 |
michael |
3368 |
if (target_server) |
| 109 |
michael |
3354 |
{ |
| 110 |
michael |
4650 |
sendto_match_servs(source_p, target_server, CAP_CLUSTER, "UNRESV %s %s", |
| 111 |
michael |
3354 |
target_server, resv); |
| 112 |
|
|
|
| 113 |
|
|
/* Allow ON to apply local unresv as well if it matches */ |
| 114 |
|
|
if (match(target_server, me.name)) |
| 115 |
|
|
return 0; |
| 116 |
|
|
} |
| 117 |
|
|
else |
| 118 |
|
|
cluster_a_line(source_p, "UNRESV", CAP_KLN, SHARED_UNRESV, resv); |
| 119 |
|
|
|
| 120 |
michael |
5837 |
resv_remove(source_p, resv); |
| 121 |
michael |
3354 |
return 0; |
| 122 |
|
|
} |
| 123 |
|
|
|
| 124 |
michael |
3365 |
/*! \brief UNRESV command handler |
| 125 |
|
|
* |
| 126 |
|
|
* \param source_p Pointer to allocated Client struct from which the message |
| 127 |
|
|
* originally comes from. This can be a local or remote client. |
| 128 |
|
|
* \param parc Integer holding the number of supplied arguments. |
| 129 |
|
|
* \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL |
| 130 |
|
|
* pointers. |
| 131 |
|
|
* \note Valid arguments for this command are: |
| 132 |
|
|
* - parv[0] = command |
| 133 |
|
|
* - parv[1] = target server |
| 134 |
|
|
* - parv[2] = channel/nick |
| 135 |
michael |
3354 |
*/ |
| 136 |
|
|
static int |
| 137 |
|
|
ms_unresv(struct Client *source_p, int parc, char *parv[]) |
| 138 |
|
|
{ |
| 139 |
michael |
3368 |
if (parc != 3 || EmptyString(parv[2])) |
| 140 |
michael |
3354 |
return 0; |
| 141 |
|
|
|
| 142 |
michael |
4650 |
sendto_match_servs(source_p, parv[1], CAP_CLUSTER, "UNRESV %s %s", |
| 143 |
michael |
3354 |
parv[1], parv[2]); |
| 144 |
|
|
|
| 145 |
michael |
4650 |
if (match(parv[1], me.name)) |
| 146 |
michael |
3354 |
return 0; |
| 147 |
|
|
|
| 148 |
michael |
3368 |
if (HasFlag(source_p, FLAGS_SERVICE) || |
| 149 |
|
|
find_matching_name_conf(CONF_ULINE, source_p->servptr->name, |
| 150 |
michael |
3354 |
source_p->username, source_p->host, |
| 151 |
|
|
SHARED_UNRESV)) |
| 152 |
michael |
5837 |
resv_remove(source_p, parv[2]); |
| 153 |
|
|
|
| 154 |
michael |
3354 |
return 0; |
| 155 |
|
|
} |
| 156 |
|
|
|
| 157 |
|
|
static struct Message unresv_msgtab = |
| 158 |
|
|
{ |
| 159 |
michael |
5881 |
.cmd = "UNRESV", |
| 160 |
|
|
.args_min = 2, |
| 161 |
|
|
.args_max = MAXPARA, |
| 162 |
|
|
.handlers[UNREGISTERED_HANDLER] = m_unregistered, |
| 163 |
|
|
.handlers[CLIENT_HANDLER] = m_not_oper, |
| 164 |
|
|
.handlers[SERVER_HANDLER] = ms_unresv, |
| 165 |
|
|
.handlers[ENCAP_HANDLER] = m_ignore, |
| 166 |
|
|
.handlers[OPER_HANDLER] = mo_unresv |
| 167 |
michael |
3354 |
}; |
| 168 |
|
|
|
| 169 |
|
|
static void |
| 170 |
|
|
module_init(void) |
| 171 |
|
|
{ |
| 172 |
|
|
mod_add_cmd(&unresv_msgtab); |
| 173 |
|
|
} |
| 174 |
|
|
|
| 175 |
|
|
static void |
| 176 |
|
|
module_exit(void) |
| 177 |
|
|
{ |
| 178 |
|
|
mod_del_cmd(&unresv_msgtab); |
| 179 |
|
|
} |
| 180 |
|
|
|
| 181 |
|
|
struct module module_entry = |
| 182 |
|
|
{ |
| 183 |
michael |
3355 |
.version = "$Revision$", |
| 184 |
michael |
3354 |
.modinit = module_init, |
| 185 |
|
|
.modexit = module_exit, |
| 186 |
|
|
}; |