1 |
/* |
2 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
3 |
* |
4 |
* Copyright (c) 2001-2015 ircd-hybrid development team |
5 |
* |
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 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 |
19 |
* USA |
20 |
*/ |
21 |
|
22 |
/*! \file m_unresv.c |
23 |
* \brief Includes required functions for processing the UNRESV command. |
24 |
* \version $Id$ |
25 |
*/ |
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 |
resv_remove(struct Client *source_p, const char *name) |
43 |
{ |
44 |
unsigned int type_int = CONF_CRESV; |
45 |
const char *type_str = "channel"; |
46 |
struct MaskItem *conf = NULL; |
47 |
|
48 |
if (!IsChanPrefix(*name)) |
49 |
{ |
50 |
type_int = CONF_NRESV; |
51 |
type_str = "nick"; |
52 |
} |
53 |
|
54 |
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 |
|
59 |
return; |
60 |
} |
61 |
|
62 |
if (!IsConfDatabase(conf)) |
63 |
{ |
64 |
if (IsClient(source_p)) |
65 |
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 |
} |
69 |
|
70 |
conf_free(conf); |
71 |
|
72 |
if (IsClient(source_p)) |
73 |
sendto_one_notice(source_p, &me, ":The RESV has been removed on %s: %s", type_str, name); |
74 |
|
75 |
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 |
} |
81 |
|
82 |
/*! \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 |
*/ |
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 |
if (!parse_aline("UNRESV", source_p, parc, parv, 0, &resv, NULL, |
105 |
NULL, &target_server, &reason)) |
106 |
return 0; |
107 |
|
108 |
if (target_server) |
109 |
{ |
110 |
sendto_match_servs(source_p, target_server, CAP_CLUSTER, "UNRESV %s %s", |
111 |
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 |
resv_remove(source_p, resv); |
121 |
return 0; |
122 |
} |
123 |
|
124 |
/*! \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 |
*/ |
136 |
static int |
137 |
ms_unresv(struct Client *source_p, int parc, char *parv[]) |
138 |
{ |
139 |
if (parc != 3 || EmptyString(parv[2])) |
140 |
return 0; |
141 |
|
142 |
sendto_match_servs(source_p, parv[1], CAP_CLUSTER, "UNRESV %s %s", |
143 |
parv[1], parv[2]); |
144 |
|
145 |
if (match(parv[1], me.name)) |
146 |
return 0; |
147 |
|
148 |
if (HasFlag(source_p, FLAGS_SERVICE) || |
149 |
find_matching_name_conf(CONF_ULINE, source_p->servptr->name, |
150 |
source_p->username, source_p->host, |
151 |
SHARED_UNRESV)) |
152 |
resv_remove(source_p, parv[2]); |
153 |
|
154 |
return 0; |
155 |
} |
156 |
|
157 |
static struct Message unresv_msgtab = |
158 |
{ |
159 |
.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 |
}; |
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 |
.version = "$Revision$", |
184 |
.modinit = module_init, |
185 |
.modexit = module_exit, |
186 |
}; |