ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_resv.c
Revision: 8693
Committed: Sun Dec 2 14:31:43 2018 UTC (7 years, 7 months ago) by michael
Content type: text/x-csrc
File size: 6382 byte(s)
Log Message:
- m_resv.c:ms_resv(): add missing newline

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 *
4 * Copyright (c) 2001-2018 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_resv.c
23 * \brief Includes required functions for processing the RESV 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_capab.h"
33 #include "send.h"
34 #include "parse.h"
35 #include "modules.h"
36 #include "conf.h"
37 #include "conf_cluster.h"
38 #include "conf_resv.h"
39 #include "conf_shared.h"
40 #include "log.h"
41
42
43 /* parse_resv()
44 *
45 * inputs - source_p
46 * - thing to resv
47 * - !0 if temporary
48 * - reason
49 * outputs - none
50 * side effects - parse resv, create if valid
51 */
52 static void
53 resv_handle(struct Client *source_p, struct aline_ctx *aline)
54 {
55 if (!HasFlag(source_p, FLAGS_SERVICE))
56 {
57 if (!HasUMode(source_p, UMODE_ADMIN) && has_wildcards(aline->mask))
58 {
59 if (IsClient(source_p))
60 sendto_one_notice(source_p, &me, ":You must be an admin to perform a wildcard RESV");
61
62 return;
63 }
64
65 if (valid_wild_card_simple(aline->mask + !!IsChanPrefix(*aline->mask)) == false)
66 {
67 if (IsClient(source_p))
68 sendto_one_notice(source_p, &me, ":Please include at least %u non-wildcard characters with the RESV",
69 ConfigGeneral.min_nonwildcard_simple);
70
71 return;
72 }
73 }
74
75 struct ResvItem *resv;
76 if ((resv = resv_make(aline->mask, aline->reason, NULL)) == NULL)
77 {
78 if (IsClient(source_p))
79 sendto_one_notice(source_p, &me, ":A RESV has already been placed on: %s", aline->mask);
80
81 return;
82 }
83
84 resv->setat = CurrentTime;
85 resv->in_database = true;
86
87 if (aline->duration)
88 {
89 resv->expire = CurrentTime + aline->duration;
90
91 if (IsClient(source_p))
92 sendto_one_notice(source_p, &me, ":Added temporary %ju min. RESV [%s]",
93 aline->duration / 60, resv->mask);
94
95 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
96 "%s added temporary %ju min. RESV for [%s] [%s]",
97 get_oper_name(source_p), aline->duration / 60,
98 resv->mask, resv->reason);
99 ilog(LOG_TYPE_RESV, "%s added temporary %ju min. RESV for [%s] [%s]",
100 get_oper_name(source_p), aline->duration / 60, resv->mask, resv->reason);
101 }
102 else
103 {
104 if (IsClient(source_p))
105 sendto_one_notice(source_p, &me, ":Added RESV [%s] [%s]",
106 resv->mask, resv->reason);
107
108 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
109 "%s added RESV for [%s] [%s]",
110 get_oper_name(source_p), resv->mask,
111 resv->reason);
112 ilog(LOG_TYPE_RESV, "%s added RESV for [%s] [%s]",
113 get_oper_name(source_p), resv->mask, resv->reason);
114 }
115 }
116
117 /* mo_resv()
118 * parv[0] = command
119 * parv[1] = channel/nick to forbid
120 */
121 static int
122 mo_resv(struct Client *source_p, int parc, char *parv[])
123 {
124 struct aline_ctx aline = { .add = true, .simple_mask = true };
125
126 if (!HasOFlag(source_p, OPER_FLAG_RESV))
127 {
128 sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "resv");
129 return 0;
130 }
131
132 if (parse_aline("RESV", source_p, parc, parv, &aline) == false)
133 return 0;
134
135 if (aline.server)
136 {
137 sendto_match_servs(source_p, aline.server, CAPAB_CLUSTER, "RESV %s %ju %s :%s",
138 aline.server, aline.duration, aline.mask, aline.reason);
139
140 /* Allow ON to apply local resv as well if it matches */
141 if (match(aline.server, me.name))
142 return 0;
143 }
144 else
145 cluster_distribute(source_p, "RESV", CAPAB_KLN, CLUSTER_RESV, "%ju %s :%s",
146 aline.duration, aline.mask, aline.reason);
147
148 resv_handle(source_p, &aline);
149 return 0;
150 }
151
152 /*! \brief RESV command handler
153 *
154 * \param source_p Pointer to allocated Client struct from which the message
155 * originally comes from. This can be a local or remote client.
156 * \param parc Integer holding the number of supplied arguments.
157 * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
158 * pointers.
159 * \note Valid arguments for this command are:
160 * - parv[0] = command
161 * - parv[1] = target server mask
162 * - parv[2] = duration in seconds
163 * - parv[3] = name mask
164 * - parv[4] = reason
165 */
166 static int
167 ms_resv(struct Client *source_p, int parc, char *parv[])
168 {
169 struct aline_ctx aline =
170 {
171 .add = true,
172 .simple_mask = true,
173 .mask = parv[2],
174 .reason = parv[4],
175 .server = parv[1],
176 .duration = strtoumax(parv[2], NULL, 10)
177 };
178
179 if (parc != 5 || EmptyString(parv[parc - 1]))
180 return 0;
181
182 sendto_match_servs(source_p, aline.server, CAPAB_CLUSTER, "RESV %s %ju %s :%s",
183 aline.server, aline.duration, aline.mask, aline.reason);
184
185 if (match(aline.server, me.name))
186 return 0;
187
188 if (HasFlag(source_p, FLAGS_SERVICE) ||
189 shared_find(SHARED_RESV, source_p->servptr->name,
190 source_p->username, source_p->host))
191 resv_handle(source_p, &aline);
192 return 0;
193 }
194
195 static struct Message resv_msgtab =
196 {
197 .cmd = "RESV",
198 .args_min = 3,
199 .args_max = MAXPARA,
200 .handlers[UNREGISTERED_HANDLER] = m_unregistered,
201 .handlers[CLIENT_HANDLER] = m_not_oper,
202 .handlers[SERVER_HANDLER] = ms_resv,
203 .handlers[ENCAP_HANDLER] = m_ignore,
204 .handlers[OPER_HANDLER] = mo_resv
205 };
206
207 static void
208 module_init(void)
209 {
210 mod_add_cmd(&resv_msgtab);
211 }
212
213 static void
214 module_exit(void)
215 {
216 mod_del_cmd(&resv_msgtab);
217 }
218
219 struct module module_entry =
220 {
221 .version = "$Revision$",
222 .modinit = module_init,
223 .modexit = module_exit,
224 };

Properties

Name Value
svn:eol-style native
svn:keywords Id Revision