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: 4649
Committed: Sun Sep 21 18:47:52 2014 UTC (10 years, 11 months ago) by michael
Content type: text/x-csrc
File size: 8792 byte(s)
Log Message:
- m_resv.c, m_unresv.c: allow servers to add/remove RESVs

File Contents

# User Rev Content
1 adx 30 /*
2 michael 2820 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 adx 30 *
4 michael 2820 * Copyright (c) 2001-2014 ircd-hybrid development team
5 adx 30 *
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 4564 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19 adx 30 * USA
20     */
21    
22 michael 2820 /*! \file m_resv.c
23 michael 3354 * \brief Includes required functions for processing the RESV command.
24 michael 2820 * \version $Id$
25     */
26    
27 adx 30 #include "stdinc.h"
28     #include "client.h"
29     #include "ircd.h"
30     #include "irc_string.h"
31     #include "numeric.h"
32 michael 3347 #include "server.h"
33 adx 30 #include "send.h"
34     #include "parse.h"
35     #include "modules.h"
36 michael 1309 #include "conf.h"
37     #include "log.h"
38 adx 30 #include "resv.h"
39     #include "hash.h"
40    
41    
42 michael 3560 /* parse_resv()
43     *
44     * inputs - source_p, NULL supported
45     * - thing to resv
46     * - time_t if tkline
47     * - reason
48     * outputs - none
49     * side effects - parse resv, create if valid
50     */
51     static void
52     parse_resv(struct Client *source_p, char *name, int tkline_time, char *reason)
53     {
54     if (IsChanPrefix(*name))
55     {
56     struct MaskItem *conf = NULL;
57 adx 30
58 michael 3560 if ((conf = create_resv(name, reason, NULL)) == NULL)
59     {
60 michael 4649 if (IsClient(source_p))
61     sendto_one_notice(source_p, &me, ":A RESV has already been placed on channel: %s", name);
62 michael 3560 return;
63     }
64 adx 30
65 michael 3560 conf->setat = CurrentTime;
66     SetConfDatabase(conf);
67    
68     if (tkline_time)
69     {
70 michael 4649 if (IsClient(source_p))
71     sendto_one_notice(source_p, &me, ":A %d minute %s RESV has been placed on channel: %s",
72     tkline_time/60, (MyClient(source_p) ? "local" : "remote"), name);
73 michael 3560 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
74     "%s has placed a %d minute %s RESV on channel: %s [%s]",
75     get_oper_name(source_p),
76     tkline_time/60,
77     (MyClient(source_p) ? "local" : "remote"),
78     conf->name, conf->reason);
79     ilog(LOG_TYPE_RESV, "%s added temporary %d min. RESV for [%s] [%s]",
80 michael 4630 get_oper_name(source_p), (int)tkline_time/60,
81 michael 3560 conf->name, conf->reason);
82     conf->until = CurrentTime + tkline_time;
83     }
84     else
85     {
86 michael 4649 if (IsClient(source_p))
87     sendto_one_notice(source_p, &me, ":A %s RESV has been placed on channel %s",
88     (MyClient(source_p) ? "local" : "remote"), name);
89 michael 3560 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
90     "%s has placed a %s RESV on channel %s : [%s]",
91     get_oper_name(source_p),
92     (MyClient(source_p) ? "local" : "remote"),
93     conf->name, conf->reason);
94 michael 4632 ilog(LOG_TYPE_RESV, "%s added RESV for [%s] [%s]",
95     get_oper_name(source_p), conf->name, conf->reason);
96 michael 3560 }
97     }
98     else
99     {
100     struct MaskItem *conf = NULL;
101    
102     if (!valid_wild_card_simple(name))
103     {
104 michael 4649 if (IsClient(source_p))
105     sendto_one_notice(source_p, &me, ":Please include at least %u non-wildcard characters with the resv",
106     ConfigGeneral.min_nonwildcard_simple);
107 michael 3560 return;
108     }
109    
110     if (!HasUMode(source_p, UMODE_ADMIN) && has_wildcards(name))
111     {
112 michael 4649 if (IsClient(source_p))
113     sendto_one_notice(source_p, &me, ":You must be an admin to perform a wildcard RESV");
114 michael 3560 return;
115     }
116    
117     if ((conf = create_resv(name, reason, NULL)) == NULL)
118     {
119 michael 4649 if (IsClient(source_p))
120     sendto_one_notice(source_p, &me, ":A RESV has already been placed on nick %s", name);
121 michael 3560 return;
122     }
123    
124     conf->setat = CurrentTime;
125     SetConfDatabase(conf);
126    
127     if (tkline_time)
128     {
129 michael 4649 if (IsClient(source_p))
130     sendto_one_notice(source_p, &me, ":A %d minute %s RESV has been placed on nick %s : [%s]",
131     tkline_time/60, (MyClient(source_p) ? "local" : "remote"),
132     conf->name, conf->reason);
133 michael 3560 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
134     "%s has placed a %d minute %s RESV on nick %s : [%s]",
135     get_oper_name(source_p), tkline_time/60,
136     (MyClient(source_p) ? "local" : "remote"),
137     conf->name, conf->reason);
138     ilog(LOG_TYPE_RESV, "%s added temporary %d min. RESV for [%s] [%s]",
139 michael 4630 get_oper_name(source_p), (int)tkline_time/60, conf->name, conf->reason);
140 michael 3560 conf->until = CurrentTime + tkline_time;
141     }
142     else
143     {
144 michael 4649 if (IsClient(source_p))
145     sendto_one_notice(source_p, &me, ":A %s RESV has been placed on nick %s : [%s]",
146     (MyClient(source_p) ? "local" : "remote"), conf->name, conf->reason);
147 michael 3560 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
148     "%s has placed a %s RESV on nick %s : [%s]",
149     get_oper_name(source_p),
150     (MyClient(source_p) ? "local" : "remote"),
151     conf->name, conf->reason);
152 michael 4632 ilog(LOG_TYPE_RESV, "%s added RESV for [%s] [%s]",
153     get_oper_name(source_p), conf->name, conf->reason);
154 michael 3560 }
155     }
156     }
157    
158 adx 30 /* mo_resv()
159 michael 3096 * parv[0] = command
160 adx 30 * parv[1] = channel/nick to forbid
161     */
162 michael 2820 static int
163 michael 3156 mo_resv(struct Client *source_p, int parc, char *parv[])
164 adx 30 {
165     char *resv = NULL;
166     char *reason = NULL;
167     char *target_server = NULL;
168     time_t tkline_time = 0;
169    
170     /* RESV #channel ON irc.server.com :abuse
171     * RESV kiddie ON irc.server.com :abuse
172     */
173 michael 4275 if (parse_aline("RESV", source_p, parc, parv, 0, &resv, NULL,
174 michael 2820 &tkline_time, &target_server, &reason) < 0)
175     return 0;
176 adx 30
177 michael 3368 if (target_server)
178 adx 30 {
179     /* if a given expire time is given, ENCAP it */
180 michael 3368 if (tkline_time)
181 adx 30 sendto_match_servs(source_p, target_server, CAP_ENCAP,
182 michael 2820 "ENCAP %s RESV %d %s 0 :%s",
183     target_server, (int)tkline_time, resv, reason);
184 adx 30 else
185     sendto_match_servs(source_p, target_server, CAP_CLUSTER,
186 michael 2820 "RESV %s %s :%s",
187     target_server, resv, reason);
188 adx 30 /* Allow ON to apply local resv as well if it matches */
189 michael 1652 if (match(target_server, me.name))
190 michael 2820 return 0;
191 adx 30 }
192     else
193     {
194     /* RESV #channel :abuse
195     * RESV kiddie :abuse
196     */
197 michael 3368 if (tkline_time)
198 adx 30 cluster_a_line(source_p, "ENCAP", CAP_ENCAP, SHARED_RESV,
199 michael 4614 "RESV %d %s 0 :%s", (int)tkline_time, resv, reason);
200 adx 30 else
201     cluster_a_line(source_p, "RESV", CAP_KLN, SHARED_RESV,
202 michael 4614 "%s :%s", resv, reason);
203 adx 30 }
204    
205     parse_resv(source_p, resv, (int)tkline_time, reason);
206 michael 2820 return 0;
207 adx 30 }
208    
209     /* me_resv()
210     *
211     * inputs - server
212     * - client (oper)
213     * - parc number of arguments
214     * - parv list of arguments
215     * via parv[]
216 michael 3096 * parv[0] = command
217 adx 30 * parv[1] = tkline_time
218     * parv[2] = name
219     * parv[3] = 0
220     * parv[4] = reason
221     * parc should be 5
222     *
223     * outputs - NONE
224     * side effects -
225     */
226 michael 2820 static int
227 michael 3156 me_resv(struct Client *source_p, int parc, char *parv[])
228 adx 30 {
229 michael 4649 if (parc != 5 || EmptyString(parv[4]))
230 michael 2820 return 0;
231 adx 30
232     parse_resv(source_p, parv[2], atoi(parv[1]), parv[4]);
233 michael 2820 return 0;
234 adx 30 }
235    
236     /* ms_resv()
237 michael 3096 * parv[0] = command
238 adx 30 * parv[1] = target server
239     * parv[2] = channel/nick to resv
240     * parv[3] = reason
241     */
242 michael 2820 static int
243 michael 3156 ms_resv(struct Client *source_p, int parc, char *parv[])
244 adx 30 {
245 michael 3368 if (parc != 4 || EmptyString(parv[3]))
246 michael 2820 return 0;
247 adx 30
248 michael 4649 sendto_match_servs(source_p, parv[1], CAP_CLUSTER, "RESV %s %s :%s",
249 adx 30 parv[1], parv[2], parv[3]);
250    
251 michael 4649 if (match(parv[1], me.name))
252 michael 2820 return 0;
253 adx 30
254 michael 4649 if (HasFlag(source_p, FLAGS_SERVICE) ||
255     find_matching_name_conf(CONF_ULINE, source_p->servptr->name,
256 adx 30 source_p->username, source_p->host,
257     SHARED_RESV))
258     parse_resv(source_p, parv[2], 0, parv[3]);
259 michael 2820 return 0;
260 adx 30 }
261    
262 michael 2820 static struct Message resv_msgtab =
263     {
264 michael 4546 "RESV", NULL, 0, 0, 3, MAXPARA, MFLG_SLOW, 0,
265 michael 1230 { m_ignore, m_not_oper, ms_resv, me_resv, mo_resv, m_ignore }
266     };
267    
268     static void
269     module_init(void)
270     {
271     mod_add_cmd(&resv_msgtab);
272     }
273    
274     static void
275     module_exit(void)
276     {
277     mod_del_cmd(&resv_msgtab);
278     }
279    
280 michael 2820 struct module module_entry =
281     {
282 michael 1230 .node = { NULL, NULL, NULL },
283     .name = NULL,
284     .version = "$Revision$",
285     .handle = NULL,
286     .modinit = module_init,
287     .modexit = module_exit,
288     .flags = 0
289     };

Properties

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