ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_set.c
Revision: 7924
Committed: Sat Dec 31 13:57:08 2016 UTC (7 years, 3 months ago) by michael
Content type: text/x-csrc
File size: 12262 byte(s)
Log Message:
- Update copyright years

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 7924 * Copyright (c) 1997-2017 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 4565 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19 adx 30 * USA
20     */
21    
22 michael 2820 /*! \file m_set.c
23     * \brief Includes required functions for processing the SET command.
24     * \version $Id$
25     */
26 adx 30
27     #include "stdinc.h"
28     #include "client.h"
29     #include "event.h"
30     #include "irc_string.h"
31     #include "ircd.h"
32     #include "numeric.h"
33     #include "send.h"
34 michael 1309 #include "conf.h"
35 adx 30 #include "parse.h"
36     #include "modules.h"
37 michael 3347 #include "misc.h"
38 adx 30
39    
40     /* SET AUTOCONN */
41     static void
42     quote_autoconn(struct Client *source_p, const char *arg, int newval)
43     {
44 michael 3382 if (!EmptyString(arg))
45 michael 896 {
46 michael 7401 struct MaskItem *conf = connect_find(arg, NULL, irccmp);
47 michael 896
48 michael 3372 if (conf)
49 michael 896 {
50     if (newval)
51 michael 1632 SetConfAllowAutoConn(conf);
52 michael 896 else
53 michael 1632 ClearConfAllowAutoConn(conf);
54 michael 896
55 michael 6318 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
56 michael 896 "%s has changed AUTOCONN for %s to %i",
57 michael 7407 get_oper_name(source_p), conf->name, newval);
58 michael 3110 sendto_one_notice(source_p, &me, ":AUTOCONN for %s is now set to %i",
59 michael 7407 conf->name, newval);
60 michael 896 }
61     else
62 michael 3110 sendto_one_notice(source_p, &me, ":Cannot find %s", arg);
63 michael 896 }
64     else
65 michael 3110 sendto_one_notice(source_p, &me, ":Please specify a server name!");
66 adx 30 }
67    
68     /* SET AUTOCONNALL */
69     static void
70 michael 3372 quote_autoconnall(struct Client *source_p, const char *arg, int newval)
71 adx 30 {
72     if (newval >= 0)
73     {
74 michael 7896 GlobalSetOptions.autoconn = newval;
75 michael 6318 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
76 michael 7896 "%s has changed AUTOCONNALL to %u",
77     get_oper_name(source_p), GlobalSetOptions.autoconn);
78 adx 30 }
79     else
80 michael 7896 sendto_one_notice(source_p, &me, ":AUTOCONNALL is currently %u",
81 michael 3110 GlobalSetOptions.autoconn);
82 adx 30 }
83    
84     /* SET FLOODCOUNT */
85     static void
86 michael 3372 quote_floodcount(struct Client *source_p, const char *arg, int newval)
87 adx 30 {
88     if (newval >= 0)
89     {
90     GlobalSetOptions.floodcount = newval;
91 michael 6318 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
92 michael 7896 "%s has changed FLOODCOUNT to %u",
93 michael 1141 get_oper_name(source_p), GlobalSetOptions.floodcount);
94 adx 30 }
95     else
96 michael 7896 sendto_one_notice(source_p, &me, ":FLOODCOUNT is currently %u",
97 michael 3110 GlobalSetOptions.floodcount);
98 adx 30 }
99    
100 michael 7858 /* SET FLOODTIME */
101     static void
102     quote_floodtime(struct Client *source_p, const char *arg, int newval)
103     {
104     if (newval >= 0)
105     {
106     GlobalSetOptions.floodtime = newval;
107     sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
108 michael 7896 "%s has changed FLOODTIME to %u",
109 michael 7858 get_oper_name(source_p), GlobalSetOptions.floodtime);
110     }
111     else
112 michael 7896 sendto_one_notice(source_p, &me, ":FLOODTIME is currently %u",
113 michael 7858 GlobalSetOptions.floodtime);
114     }
115    
116 adx 30 /* SET IDENTTIMEOUT */
117     static void
118 michael 3372 quote_identtimeout(struct Client *source_p, const char *arg, int newval)
119 adx 30 {
120 michael 1219 if (!HasUMode(source_p, UMODE_ADMIN))
121 adx 30 {
122 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "set");
123 adx 30 return;
124     }
125    
126     if (newval > 0)
127     {
128 michael 7896 GlobalSetOptions.ident_timeout = newval;
129 michael 6318 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
130 michael 7896 "%s has changed IDENTTIMEOUT to %u",
131     get_oper_name(source_p), GlobalSetOptions.ident_timeout);
132 adx 30 }
133     else
134 michael 7896 sendto_one_notice(source_p, &me, ":IDENTTIMEOUT is currently %u",
135 michael 3110 GlobalSetOptions.ident_timeout);
136 adx 30 }
137    
138     /* SET MAX */
139     static void
140 michael 3372 quote_max(struct Client *source_p, const char *arg, int newval)
141 adx 30 {
142     if (newval > 0)
143     {
144     if (newval > MAXCLIENTS_MAX)
145     {
146 michael 7896 sendto_one_notice(source_p, &me, ":You cannot set MAXCLIENTS to > %d, restoring to %u",
147 michael 5489 MAXCLIENTS_MAX, GlobalSetOptions.maxclients);
148 adx 30 return;
149     }
150    
151     if (newval < MAXCLIENTS_MIN)
152     {
153 michael 7896 sendto_one_notice(source_p, &me, ":You cannot set MAXCLIENTS to < %d, restoring to %u",
154 michael 5489 MAXCLIENTS_MIN, GlobalSetOptions.maxclients);
155 adx 30 return;
156     }
157    
158 michael 5489 GlobalSetOptions.maxclients = newval;
159 michael 6318 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
160 michael 7896 "%s set new MAXCLIENTS to %u (%u current)",
161     get_oper_name(source_p), GlobalSetOptions.maxclients, Count.local);
162 adx 30 }
163     else
164 michael 7896 sendto_one_notice(source_p, &me, ":Current MAXCLIENTS = %u (%u)",
165 michael 5489 GlobalSetOptions.maxclients, Count.local);
166 adx 30 }
167    
168     /* SET SPAMNUM */
169     static void
170 michael 3372 quote_spamnum(struct Client *source_p, const char *arg, int newval)
171 adx 30 {
172 michael 646 if (newval >= 0)
173 adx 30 {
174     if (newval == 0)
175     {
176 michael 7896 GlobalSetOptions.spam_num = newval;
177 michael 6318 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
178 adx 30 "%s has disabled ANTI_SPAMBOT", source_p->name);
179     return;
180     }
181    
182     GlobalSetOptions.spam_num = IRCD_MAX(newval, MIN_SPAM_NUM);
183 michael 6318 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
184 michael 1618 "%s has changed SPAMNUM to %i",
185 michael 1141 get_oper_name(source_p), GlobalSetOptions.spam_num);
186 adx 30 }
187     else
188 michael 3110 sendto_one_notice(source_p, &me, ":SPAMNUM is currently %i",
189     GlobalSetOptions.spam_num);
190 adx 30 }
191    
192     /* SET SPAMTIME */
193     static void
194 michael 3372 quote_spamtime(struct Client *source_p, const char *arg, int newval)
195 adx 30 {
196     if (newval > 0)
197     {
198     GlobalSetOptions.spam_time = IRCD_MAX(newval, MIN_SPAM_TIME);
199 michael 6318 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
200 michael 7896 "%s has changed SPAMTIME to %u",
201 michael 1141 get_oper_name(source_p), GlobalSetOptions.spam_time);
202 adx 30 }
203     else
204 michael 7896 sendto_one_notice(source_p, &me, ":SPAMTIME is currently %u",
205 michael 3110 GlobalSetOptions.spam_time);
206 adx 30 }
207    
208     /* SET JFLOODTIME */
209     static void
210 michael 3372 quote_jfloodtime(struct Client *source_p, const char *arg, int newval)
211 adx 30 {
212     if (newval >= 0)
213     {
214 michael 7896 GlobalSetOptions.joinfloodtime = newval;
215 michael 6318 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
216 michael 7896 "%s has changed JFLOODTIME to %u",
217     get_oper_name(source_p), GlobalSetOptions.joinfloodtime);
218 adx 30 }
219     else
220 michael 7896 sendto_one_notice(source_p, &me, ":JFLOODTIME is currently %u",
221 michael 3110 GlobalSetOptions.joinfloodtime);
222 adx 30 }
223    
224     /* SET JFLOODCOUNT */
225     static void
226 michael 3372 quote_jfloodcount(struct Client *source_p, const char *arg, int newval)
227 adx 30 {
228     if (newval >= 0)
229     {
230 michael 7896 GlobalSetOptions.joinfloodcount = newval;
231 michael 6318 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
232 michael 7896 "%s has changed JFLOODCOUNT to %u",
233     get_oper_name(source_p), GlobalSetOptions.joinfloodcount);
234 adx 30 }
235     else
236 michael 7896 sendto_one_notice(source_p, &me, ":JFLOODCOUNT is currently %u",
237 michael 3110 GlobalSetOptions.joinfloodcount);
238 adx 30 }
239    
240 michael 1997 /* Structure used for the SET table itself */
241     struct SetStruct
242     {
243 michael 7076 const char *const name;
244     void (*const handler)(struct Client *, const char *, int);
245 michael 3856 const unsigned int wants_char; /* 1 if it expects (char *, [int]) */
246     const unsigned int wants_int; /* 1 if it expects ([char *], int) */
247 michael 1997 /* eg: 0, 1 == only an int arg
248     * eg: 1, 1 == char and int args */
249     };
250    
251 adx 30 /*
252 michael 1997 * If this ever needs to be expanded to more than one arg of each
253     * type, want_char/want_int could be the count of the arguments,
254     * instead of just a boolean flag...
255     *
256     * -davidt
257     */
258     static const struct SetStruct set_cmd_table[] =
259     {
260     /* name function string arg int arg */
261     /* -------------------------------------------------------- */
262     { "AUTOCONN", quote_autoconn, 1, 1 },
263     { "AUTOCONNALL", quote_autoconnall, 0, 1 },
264     { "FLOODCOUNT", quote_floodcount, 0, 1 },
265 michael 7858 { "FLOODTIME", quote_floodtime, 0, 1 },
266 michael 1997 { "IDENTTIMEOUT", quote_identtimeout, 0, 1 },
267     { "MAX", quote_max, 0, 1 },
268     { "SPAMNUM", quote_spamnum, 0, 1 },
269     { "SPAMTIME", quote_spamtime, 0, 1 },
270     { "JFLOODTIME", quote_jfloodtime, 0, 1 },
271     { "JFLOODCOUNT", quote_jfloodcount, 0, 1 },
272     /* -------------------------------------------------------- */
273     { NULL, NULL, 0, 0 }
274     };
275    
276     /*
277     * list_quote_commands() sends the client all the available commands.
278     * Four to a line for now.
279     */
280     static void
281     list_quote_commands(struct Client *source_p)
282     {
283 michael 3283 unsigned int j = 0;
284 michael 1997 const char *names[4] = { "", "", "", "" };
285    
286 michael 3110 sendto_one_notice(source_p, &me, ":Available QUOTE SET commands:");
287 michael 1997
288 michael 3283 for (const struct SetStruct *tab = set_cmd_table; tab->handler; ++tab)
289 michael 1997 {
290     names[j++] = tab->name;
291    
292     if (j > 3)
293     {
294 michael 3110 sendto_one_notice(source_p, &me, ":%s %s %s %s",
295     names[0], names[1],
296     names[2], names[3]);
297 michael 1997 j = 0;
298     names[0] = names[1] = names[2] = names[3] = "";
299     }
300     }
301    
302     if (j)
303 michael 3110 sendto_one_notice(source_p, &me, ":%s %s %s %s",
304     names[0], names[1],
305     names[2], names[3]);
306 michael 1997 }
307    
308     /*
309 adx 30 * mo_set - SET command handler
310     * set options while running
311     */
312 michael 2820 static int
313 michael 3156 mo_set(struct Client *source_p, int parc, char *parv[])
314 adx 30 {
315     int n;
316     int newval;
317 michael 3372 const char *strarg = NULL;
318 adx 30 const char *intarg = NULL;
319    
320 michael 1460 if (!HasOFlag(source_p, OPER_FLAG_SET))
321     {
322 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "set");
323 michael 2820 return 0;
324 michael 1460 }
325    
326 adx 30 if (parc > 1)
327     {
328 michael 1013 /*
329     * Go through all the commands in set_cmd_table, until one is
330     * matched.
331 adx 30 */
332 michael 3283 for (const struct SetStruct *tab = set_cmd_table; tab->handler; ++tab)
333 adx 30 {
334 michael 3373 if (irccmp(tab->name, parv[1]))
335 michael 3372 continue;
336 adx 30
337 michael 3372 /*
338     * Command found; now execute the code
339     */
340     n = 2;
341 adx 30
342 michael 3372 if (tab->wants_char)
343     strarg = parv[n++];
344 adx 30
345 michael 3372 if (tab->wants_int)
346     intarg = parv[n++];
347 adx 30
348 michael 3372 if ((n - 1) > parc)
349 michael 3373 sendto_one_notice(source_p, &me, ":SET %s expects (\"%s%s\") args", tab->name,
350     (tab->wants_char ? "string, " : ""),
351     (tab->wants_int ? "int" : ""));
352 adx 30
353 michael 3372 if (parc <= 2)
354     {
355     strarg = NULL;
356     intarg = NULL;
357     }
358 adx 30
359 michael 3372 if (tab->wants_int && parc > 2)
360     {
361     if (intarg)
362 adx 30 {
363 michael 3372 if (!irccmp(intarg, "yes") || !irccmp(intarg, "on"))
364     newval = 1;
365 michael 3855 else if (!irccmp(intarg, "no") || !irccmp(intarg, "off"))
366 michael 3372 newval = 0;
367 adx 30 else
368 michael 3372 newval = atoi(intarg);
369 adx 30 }
370     else
371     newval = -1;
372    
373 michael 3372 if (newval < 0)
374 adx 30 {
375 michael 3372 sendto_one_notice(source_p, &me, ":Value less than 0 illegal for %s",
376     tab->name);
377 michael 2820 return 0;
378 adx 30 }
379     }
380 michael 3372 else
381     newval = -1;
382    
383     tab->handler(source_p, strarg, newval);
384     return 0;
385 adx 30 }
386    
387     /*
388     * Code here will be executed when a /QUOTE SET command is not
389     * found within set_cmd_table.
390     */
391 michael 3110 sendto_one_notice(source_p, &me, ":Variable not found.");
392 michael 2820 return 0;
393 adx 30 }
394    
395     list_quote_commands(source_p);
396 michael 2820 return 0;
397 adx 30 }
398 michael 1230
399 michael 2820 static struct Message set_msgtab =
400     {
401 michael 5881 .cmd = "SET",
402     .args_max = MAXPARA,
403     .handlers[UNREGISTERED_HANDLER] = m_unregistered,
404     .handlers[CLIENT_HANDLER] = m_not_oper,
405     .handlers[SERVER_HANDLER] = m_ignore,
406     .handlers[ENCAP_HANDLER] = m_ignore,
407     .handlers[OPER_HANDLER] = mo_set
408 michael 1230 };
409    
410     static void
411     module_init(void)
412     {
413     mod_add_cmd(&set_msgtab);
414     }
415    
416     static void
417     module_exit(void)
418     {
419     mod_del_cmd(&set_msgtab);
420     }
421    
422 michael 2820 struct module module_entry =
423     {
424 michael 1230 .version = "$Revision$",
425     .modinit = module_init,
426     .modexit = module_exit,
427     };

Properties

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