ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_set.c
Revision: 3280
Committed: Mon Apr 7 18:21:22 2014 UTC (10 years ago) by michael
Content type: text/x-csrc
File size: 15125 byte(s)
Log Message:
- Fixed compile warnings

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) 1997-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     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19     * 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 "s_serv.h"
34     #include "send.h"
35     #include "channel.h"
36 michael 1309 #include "conf.h"
37 adx 30 #include "parse.h"
38     #include "modules.h"
39     #include "s_user.h"
40 michael 1243 #include "s_misc.h"
41 adx 30
42    
43     /* SET AUTOCONN */
44     static void
45     quote_autoconn(struct Client *source_p, const char *arg, int newval)
46     {
47 michael 896 if (arg != NULL)
48     {
49 michael 1632 struct MaskItem *conf = find_exact_name_conf(CONF_SERVER, NULL, arg, NULL, NULL);
50 michael 896
51     if (conf != NULL)
52     {
53     if (newval)
54 michael 1632 SetConfAllowAutoConn(conf);
55 michael 896 else
56 michael 1632 ClearConfAllowAutoConn(conf);
57 michael 896
58 michael 1618 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
59 michael 896 "%s has changed AUTOCONN for %s to %i",
60 michael 1141 get_oper_name(source_p), arg, newval);
61 michael 3110 sendto_one_notice(source_p, &me, ":AUTOCONN for %s is now set to %i",
62     arg, newval);
63 michael 896 }
64     else
65     {
66 michael 3110 sendto_one_notice(source_p, &me, ":Cannot find %s", arg);
67 michael 896 }
68     }
69     else
70     {
71 michael 3110 sendto_one_notice(source_p, &me, ":Please specify a server name!");
72 michael 896 }
73 adx 30 }
74    
75     /* SET AUTOCONNALL */
76     static void
77     quote_autoconnall(struct Client *source_p, int newval)
78     {
79     if (newval >= 0)
80     {
81 michael 1618 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
82     "%s has changed AUTOCONNALL to %i",
83 michael 1141 get_oper_name(source_p), newval);
84 adx 30
85     GlobalSetOptions.autoconn = newval;
86     }
87     else
88 michael 3110 sendto_one_notice(source_p, &me, ":AUTOCONNALL is currently %i",
89     GlobalSetOptions.autoconn);
90 adx 30 }
91    
92     /* SET FLOODCOUNT */
93     static void
94     quote_floodcount(struct Client *source_p, int newval)
95     {
96     if (newval >= 0)
97     {
98     GlobalSetOptions.floodcount = newval;
99 michael 1618 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
100 michael 1141 "%s has changed FLOODCOUNT to %i",
101     get_oper_name(source_p), GlobalSetOptions.floodcount);
102 adx 30 }
103     else
104 michael 3110 sendto_one_notice(source_p, &me, ":FLOODCOUNT is currently %i",
105     GlobalSetOptions.floodcount);
106 adx 30 }
107    
108     /* SET IDENTTIMEOUT */
109     static void
110     quote_identtimeout(struct Client *source_p, int newval)
111     {
112 michael 1219 if (!HasUMode(source_p, UMODE_ADMIN))
113 adx 30 {
114 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "set");
115 adx 30 return;
116     }
117    
118     if (newval > 0)
119     {
120 michael 1618 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
121 michael 1451 "%s has changed IDENTTIMEOUT to %d",
122     get_oper_name(source_p), newval);
123 adx 30 GlobalSetOptions.ident_timeout = newval;
124     }
125     else
126 michael 3110 sendto_one_notice(source_p, &me, ":IDENTTIMEOUT is currently %d",
127     GlobalSetOptions.ident_timeout);
128 adx 30 }
129    
130     /* SET MAX */
131     static void
132 michael 896 quote_max(struct Client *source_p, int newval)
133 adx 30 {
134     if (newval > 0)
135     {
136     if (newval > MAXCLIENTS_MAX)
137     {
138 michael 3110 sendto_one_notice(source_p, &me, ":You cannot set MAXCLIENTS to > %d, restoring to %d",
139     MAXCLIENTS_MAX, ServerInfo.max_clients);
140 adx 30 return;
141     }
142    
143     if (newval < MAXCLIENTS_MIN)
144     {
145 michael 3110 sendto_one_notice(source_p, &me, ":You cannot set MAXCLIENTS to < %d, restoring to %d",
146     MAXCLIENTS_MIN, ServerInfo.max_clients);
147 adx 30 return;
148     }
149    
150     ServerInfo.max_clients = newval;
151    
152 michael 1618 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
153 michael 1451 "%s set new MAXCLIENTS to %d (%d current)",
154     get_oper_name(source_p), ServerInfo.max_clients, Count.local);
155 adx 30 }
156     else
157 michael 3110 sendto_one_notice(source_p, &me, ":Current MAXCLIENTS = %d (%d)",
158     ServerInfo.max_clients, Count.local);
159 adx 30 }
160    
161     /* SET SPAMNUM */
162     static void
163 michael 896 quote_spamnum(struct Client *source_p, int newval)
164 adx 30 {
165 michael 646 if (newval >= 0)
166 adx 30 {
167     if (newval == 0)
168     {
169 michael 1618 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
170 adx 30 "%s has disabled ANTI_SPAMBOT", source_p->name);
171     GlobalSetOptions.spam_num = newval;
172     return;
173     }
174    
175     GlobalSetOptions.spam_num = IRCD_MAX(newval, MIN_SPAM_NUM);
176 michael 1618 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
177     "%s has changed SPAMNUM to %i",
178 michael 1141 get_oper_name(source_p), GlobalSetOptions.spam_num);
179 adx 30 }
180     else
181 michael 3110 sendto_one_notice(source_p, &me, ":SPAMNUM is currently %i",
182     GlobalSetOptions.spam_num);
183 adx 30 }
184    
185     /* SET SPAMTIME */
186     static void
187 michael 896 quote_spamtime(struct Client *source_p, int newval)
188 adx 30 {
189     if (newval > 0)
190     {
191     GlobalSetOptions.spam_time = IRCD_MAX(newval, MIN_SPAM_TIME);
192 michael 1618 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
193     "%s has changed SPAMTIME to %i",
194 michael 1141 get_oper_name(source_p), GlobalSetOptions.spam_time);
195 adx 30 }
196     else
197 michael 3110 sendto_one_notice(source_p, &me, ":SPAMTIME is currently %i",
198     GlobalSetOptions.spam_time);
199 adx 30 }
200    
201     /* this table is what splitmode may be set to */
202     static const char *splitmode_values[] =
203     {
204     "OFF",
205     "ON",
206     "AUTO",
207     NULL
208     };
209    
210     /* this table is what splitmode may be */
211     static const char *splitmode_status[] =
212     {
213     "OFF",
214     "AUTO (OFF)",
215     "ON",
216     "AUTO (ON)",
217     NULL
218     };
219    
220     /* SET SPLITMODE */
221     static void
222     quote_splitmode(struct Client *source_p, char *charval)
223     {
224     if (charval)
225     {
226     int newval;
227    
228 michael 896 for (newval = 0; splitmode_values[newval]; ++newval)
229 adx 30 if (irccmp(splitmode_values[newval], charval) == 0)
230     break;
231    
232     /* OFF */
233     if (newval == 0)
234     {
235 michael 1618 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
236 adx 30 "%s is disabling splitmode",
237     get_oper_name(source_p));
238    
239     splitmode = 0;
240     splitchecking = 0;
241    
242     eventDelete(check_splitmode, NULL);
243     }
244     /* ON */
245     else if (newval == 1)
246     {
247 michael 1618 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
248 adx 30 "%s is enabling and activating splitmode",
249 michael 1451 get_oper_name(source_p));
250    
251 adx 30 splitmode = 1;
252     splitchecking = 0;
253    
254     /* we might be deactivating an automatic splitmode, so pull the event */
255     eventDelete(check_splitmode, NULL);
256     }
257     /* AUTO */
258     else if (newval == 2)
259     {
260 michael 1618 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
261 adx 30 "%s is enabling automatic splitmode",
262 michael 1451 get_oper_name(source_p));
263 adx 30
264     splitchecking = 1;
265     check_splitmode(NULL);
266     }
267     }
268     else
269     /* if we add splitchecking to splitmode*2 we get a unique table to
270     * pull values back out of, splitmode can be four states - but you can
271     * only set to three, which means we cant use the same table --fl_
272     */
273 michael 3110 sendto_one_notice(source_p, &me, ":SPLITMODE is currently %s",
274     splitmode_status[(splitchecking + (splitmode * 2))]);
275 adx 30 }
276    
277     /* SET SPLITNUM */
278     static void
279     quote_splitnum(struct Client *source_p, int newval)
280     {
281     if (newval >= 0)
282     {
283 michael 1618 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
284 adx 30 "%s has changed SPLITNUM to %i",
285 michael 1451 get_oper_name(source_p), newval);
286 adx 30 split_servers = newval;
287    
288     if (splitchecking)
289     check_splitmode(NULL);
290     }
291     else
292 michael 3110 sendto_one_notice(source_p, &me, ":SPLITNUM is currently %i",
293     split_servers);
294 adx 30 }
295    
296     /* SET SPLITUSERS */
297     static void
298     quote_splitusers(struct Client *source_p, int newval)
299     {
300     if (newval >= 0)
301     {
302 michael 1618 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
303 adx 30 "%s has changed SPLITUSERS to %i",
304 michael 1451 get_oper_name(source_p), newval);
305 adx 30 split_users = newval;
306    
307     if (splitchecking)
308     check_splitmode(NULL);
309     }
310     else
311 michael 3110 sendto_one_notice(source_p, &me, ":SPLITUSERS is currently %i",
312     split_users);
313 adx 30 }
314    
315     /* SET JFLOODTIME */
316     static void
317     quote_jfloodtime(struct Client *source_p, int newval)
318     {
319     if (newval >= 0)
320     {
321 michael 1618 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
322 adx 30 "%s has changed JFLOODTIME to %i",
323 michael 1451 get_oper_name(source_p), newval);
324 adx 30 GlobalSetOptions.joinfloodtime = newval;
325     }
326     else
327 michael 3110 sendto_one_notice(source_p, &me, ":JFLOODTIME is currently %i",
328     GlobalSetOptions.joinfloodtime);
329 adx 30 }
330    
331     /* SET JFLOODCOUNT */
332     static void
333     quote_jfloodcount(struct Client *source_p, int newval)
334     {
335     if (newval >= 0)
336     {
337 michael 1618 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
338 adx 30 "%s has changed JFLOODCOUNT to %i",
339 michael 1451 get_oper_name(source_p), newval);
340 adx 30 GlobalSetOptions.joinfloodcount = newval;
341     }
342     else
343 michael 3110 sendto_one_notice(source_p, &me, ":JFLOODCOUNT is currently %i",
344     GlobalSetOptions.joinfloodcount);
345 adx 30 }
346    
347 michael 1997 /* Structure used for the SET table itself */
348     struct SetStruct
349     {
350     const char *name;
351     void (*handler)();
352     const int wants_char; /* 1 if it expects (char *, [int]) */
353     const int wants_int; /* 1 if it expects ([char *], int) */
354     /* eg: 0, 1 == only an int arg
355     * eg: 1, 1 == char and int args */
356     };
357    
358 adx 30 /*
359 michael 1997 * If this ever needs to be expanded to more than one arg of each
360     * type, want_char/want_int could be the count of the arguments,
361     * instead of just a boolean flag...
362     *
363     * -davidt
364     */
365     static const struct SetStruct set_cmd_table[] =
366     {
367     /* name function string arg int arg */
368     /* -------------------------------------------------------- */
369     { "AUTOCONN", quote_autoconn, 1, 1 },
370     { "AUTOCONNALL", quote_autoconnall, 0, 1 },
371     { "FLOODCOUNT", quote_floodcount, 0, 1 },
372     { "IDENTTIMEOUT", quote_identtimeout, 0, 1 },
373     { "MAX", quote_max, 0, 1 },
374     { "SPAMNUM", quote_spamnum, 0, 1 },
375     { "SPAMTIME", quote_spamtime, 0, 1 },
376     { "SPLITMODE", quote_splitmode, 1, 0 },
377     { "SPLITNUM", quote_splitnum, 0, 1 },
378     { "SPLITUSERS", quote_splitusers, 0, 1 },
379     { "JFLOODTIME", quote_jfloodtime, 0, 1 },
380     { "JFLOODCOUNT", quote_jfloodcount, 0, 1 },
381     /* -------------------------------------------------------- */
382     { NULL, NULL, 0, 0 }
383     };
384    
385     /*
386     * list_quote_commands() sends the client all the available commands.
387     * Four to a line for now.
388     */
389     static void
390     list_quote_commands(struct Client *source_p)
391     {
392     int j = 0;
393     const struct SetStruct *tab = set_cmd_table;
394     const char *names[4] = { "", "", "", "" };
395    
396 michael 3110 sendto_one_notice(source_p, &me, ":Available QUOTE SET commands:");
397 michael 1997
398     for (; tab->handler; ++tab)
399     {
400     names[j++] = tab->name;
401    
402     if (j > 3)
403     {
404 michael 3110 sendto_one_notice(source_p, &me, ":%s %s %s %s",
405     names[0], names[1],
406     names[2], names[3]);
407 michael 1997 j = 0;
408     names[0] = names[1] = names[2] = names[3] = "";
409     }
410    
411     }
412    
413     if (j)
414 michael 3110 sendto_one_notice(source_p, &me, ":%s %s %s %s",
415     names[0], names[1],
416     names[2], names[3]);
417 michael 1997 }
418    
419     /*
420 adx 30 * mo_set - SET command handler
421     * set options while running
422     */
423 michael 2820 static int
424 michael 3156 mo_set(struct Client *source_p, int parc, char *parv[])
425 adx 30 {
426     int n;
427     int newval;
428     const char *arg = NULL;
429     const char *intarg = NULL;
430 michael 1013 const struct SetStruct *tab = set_cmd_table;
431 adx 30
432 michael 1460 if (!HasOFlag(source_p, OPER_FLAG_SET))
433     {
434 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "set");
435 michael 2820 return 0;
436 michael 1460 }
437    
438 adx 30 if (parc > 1)
439     {
440 michael 1013 /*
441     * Go through all the commands in set_cmd_table, until one is
442     * matched.
443 adx 30 */
444 michael 1013 for (; tab->handler; ++tab)
445 adx 30 {
446 michael 1013 if (!irccmp(tab->name, parv[1]))
447 adx 30 {
448     /*
449     * Command found; now execute the code
450     */
451     n = 2;
452    
453 michael 1013 if (tab->wants_char)
454 adx 30 arg = parv[n++];
455    
456 michael 1013 if (tab->wants_int)
457 adx 30 intarg = parv[n++];
458    
459     if ((n - 1) > parc)
460     {
461     if (parc > 2)
462 michael 3280 sendto_one_notice(source_p, &me, ":SET %s expects (\"%s%s\") args", tab->name,
463 michael 3110 (tab->wants_char ? "string, " : ""),
464     (tab->wants_char ? "int" : ""));
465 adx 30 }
466    
467     if (parc <= 2)
468     {
469     arg = NULL;
470     intarg = NULL;
471     }
472    
473 michael 1013 if (!strcmp(tab->name, "AUTOCONN") && (parc < 4))
474 adx 30 {
475 michael 3109 sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, "SET");
476 michael 2820 return 0;
477 adx 30 }
478    
479 michael 1013 if (tab->wants_int && (parc > 2))
480 adx 30 {
481     if (intarg)
482     {
483     if (irccmp(intarg, "yes") == 0 || irccmp(intarg, "on") == 0)
484     newval = 1;
485     else if (irccmp(intarg, "no") == 0|| irccmp(intarg, "off") == 0)
486     newval = 0;
487     else
488     newval = atoi(intarg);
489     }
490     else
491     newval = -1;
492    
493     if (newval < 0)
494     {
495 michael 3110 sendto_one_notice(source_p, &me, ":Value less than 0 illegal for %s",
496     tab->name);
497 adx 30
498 michael 2820 return 0;
499 adx 30 }
500     }
501     else
502     newval = -1;
503    
504 michael 1013 if (tab->wants_char)
505 adx 30 {
506 michael 1013 if (tab->wants_int)
507     tab->handler(source_p, arg, newval);
508 adx 30 else
509 michael 1013 tab->handler(source_p, arg);
510 michael 2820 return 0;
511 adx 30 }
512     else
513     {
514 michael 1013 if (tab->wants_int)
515     tab->handler(source_p, newval);
516 adx 30 else
517     /* Just in case someone actually wants a
518     * set function that takes no args.. *shrug* */
519 michael 1013 tab->handler(source_p);
520 michael 2820 return 0;
521 adx 30 }
522     }
523     }
524    
525     /*
526     * Code here will be executed when a /QUOTE SET command is not
527     * found within set_cmd_table.
528     */
529 michael 3110 sendto_one_notice(source_p, &me, ":Variable not found.");
530 michael 2820 return 0;
531 adx 30 }
532    
533     list_quote_commands(source_p);
534 michael 2820 return 0;
535 adx 30 }
536 michael 1230
537 michael 2820 static struct Message set_msgtab =
538     {
539 michael 1230 "SET", 0, 0, 0, MAXPARA, MFLG_SLOW, 0,
540 michael 2820 { m_unregistered, m_not_oper, m_ignore, m_ignore, mo_set, m_ignore }
541 michael 1230 };
542    
543     static void
544     module_init(void)
545     {
546     mod_add_cmd(&set_msgtab);
547     }
548    
549     static void
550     module_exit(void)
551     {
552     mod_del_cmd(&set_msgtab);
553     }
554    
555 michael 2820 struct module module_entry =
556     {
557 michael 1230 .node = { NULL, NULL, NULL },
558     .name = NULL,
559     .version = "$Revision$",
560     .handle = NULL,
561     .modinit = module_init,
562     .modexit = module_exit,
563     .flags = 0
564     };

Properties

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