ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_resv.c
Revision: 9857
Committed: Fri Jan 1 04:43:22 2021 UTC (4 years, 7 months ago) by michael
Content type: text/x-csrc
File size: 6194 byte(s)
Log Message:
- Bump copyright years

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 *
4 * Copyright (c) 2001-2021 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, const 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 = resv_find(aline->mask, irccmp);
68 if (resv)
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 = event_base->time.sec_real;
78 resv->in_database = true;
79
80 if (aline->duration)
81 {
82 resv->expire = event_base->time.sec_real + 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 void
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;
123 }
124
125 if (parse_aline("RESV", source_p, parc, parv, &aline) == false)
126 return;
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;
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 }
143
144 /*! \brief RESV command handler
145 *
146 * \param source_p Pointer to allocated Client struct from which the message
147 * originally comes from. This can be a local or remote client.
148 * \param parc Integer holding the number of supplied arguments.
149 * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
150 * pointers.
151 * \note Valid arguments for this command are:
152 * - parv[0] = command
153 * - parv[1] = target server mask
154 * - parv[2] = duration in seconds
155 * - parv[3] = name mask
156 * - parv[4] = reason
157 */
158 static void
159 ms_resv(struct Client *source_p, int parc, char *parv[])
160 {
161 struct aline_ctx aline =
162 {
163 .add = true,
164 .simple_mask = true,
165 .mask = parv[3],
166 .reason = parv[4],
167 .server = parv[1],
168 .duration = strtoumax(parv[2], NULL, 10)
169 };
170
171 sendto_match_servs(source_p, aline.server, CAPAB_CLUSTER, "RESV %s %ju %s :%s",
172 aline.server, aline.duration, aline.mask, aline.reason);
173
174 if (match(aline.server, me.name))
175 return;
176
177 if (HasFlag(source_p, FLAGS_SERVICE) ||
178 shared_find(SHARED_RESV, source_p->servptr->name,
179 source_p->username, source_p->host))
180 resv_handle(source_p, &aline);
181 }
182
183 static struct Message resv_msgtab =
184 {
185 .cmd = "RESV",
186 .handlers[UNREGISTERED_HANDLER] = { .handler = m_unregistered },
187 .handlers[CLIENT_HANDLER] = { .handler = m_not_oper },
188 .handlers[SERVER_HANDLER] = { .handler = ms_resv, .args_min = 5 },
189 .handlers[ENCAP_HANDLER] = { .handler = m_ignore },
190 .handlers[OPER_HANDLER] = { .handler = mo_resv, .args_min = 2 }
191 };
192
193 static void
194 module_init(void)
195 {
196 mod_add_cmd(&resv_msgtab);
197 }
198
199 static void
200 module_exit(void)
201 {
202 mod_del_cmd(&resv_msgtab);
203 }
204
205 struct module module_entry =
206 {
207 .version = "$Revision$",
208 .modinit = module_init,
209 .modexit = module_exit,
210 };

Properties

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