ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/branches/8.2.x/modules/m_resv.c
Revision: 8751
Committed: Tue Jan 1 11:06:50 2019 UTC (6 years, 7 months ago) by michael
Content type: text/x-csrc
File size: 6190 byte(s)
Log Message:
- Update copyright years

File Contents

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

Properties

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