ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_set.c
Revision: 1219
Committed: Sun Sep 18 09:02:38 2011 UTC (12 years, 7 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid-8/modules/m_set.c
File size: 17755 byte(s)
Log Message:
- Start cleaning up macros in client.h. Replace several ClientHasSomeCoolFlag()
with simple HasFlag/HasUMode macros.

File Contents

# User Rev Content
1 adx 30 /*
2     * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3     * m_set.c: Sets a server parameter.
4     *
5     * Copyright (C) 2002 by the past and present ircd coders, and others.
6     *
7     * This program is free software; you can redistribute it and/or modify
8     * it under the terms of the GNU General Public License as published by
9     * the Free Software Foundation; either version 2 of the License, or
10     * (at your option) any later version.
11     *
12     * This program is distributed in the hope that it will be useful,
13     * but WITHOUT ANY WARRANTY; without even the implied warranty of
14     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15     * GNU General Public License for more details.
16     *
17     * You should have received a copy of the GNU General Public License
18     * along with this program; if not, write to the Free Software
19     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20     * USA
21     *
22 knight 31 * $Id$
23 adx 30 */
24    
25     /* rewritten by jdc */
26    
27     #include "stdinc.h"
28     #include "handlers.h"
29     #include "client.h"
30     #include "event.h"
31     #include "irc_string.h"
32     #include "ircd.h"
33     #include "numeric.h"
34     #include "fdlist.h"
35     #include "s_bsd.h"
36     #include "s_serv.h"
37     #include "send.h"
38     #include "common.h" /* for NO */
39     #include "channel.h"
40     #include "s_log.h"
41     #include "s_conf.h"
42     #include "msg.h"
43     #include "parse.h"
44     #include "modules.h"
45     #include "s_user.h"
46    
47    
48     static void mo_set(struct Client *, struct Client *, int, char *[]);
49    
50     struct Message set_msgtab = {
51 michael 1178 "SET", 0, 0, 0, MAXPARA, MFLG_SLOW, 0,
52 michael 946 {m_unregistered, m_not_oper, rfc1459_command_send_error, m_ignore, mo_set, m_ignore}
53 adx 30 };
54    
55     void
56     _modinit(void)
57     {
58     mod_add_cmd(&set_msgtab);
59     }
60    
61     void
62     _moddeinit(void)
63     {
64     mod_del_cmd(&set_msgtab);
65     }
66    
67 knight 31 const char *_version = "$Revision$";
68 adx 30
69     /* Structure used for the SET table itself */
70     struct SetStruct
71     {
72     const char *name;
73     void (*handler)();
74 michael 1013 const int wants_char; /* 1 if it expects (char *, [int]) */
75     const int wants_int; /* 1 if it expects ([char *], int) */
76 adx 30 /* eg: 0, 1 == only an int arg
77     * eg: 1, 1 == char and int args */
78     };
79    
80     static void quote_autoconn(struct Client *, const char *, int);
81     static void quote_autoconnall(struct Client *, int);
82     static void quote_floodcount(struct Client *, int);
83     static void quote_identtimeout(struct Client *, int);
84     static void quote_log(struct Client *, int);
85     static void quote_max(struct Client *, int);
86     static void quote_msglocale(struct Client *, char *);
87     static void quote_spamnum(struct Client *, int);
88     static void quote_spamtime(struct Client *, int);
89     static void quote_splitmode(struct Client *, char *);
90     static void quote_splitnum(struct Client *, int);
91     static void quote_splitusers(struct Client *, int);
92     static void list_quote_commands(struct Client *);
93     static void quote_jfloodtime(struct Client *, int);
94     static void quote_jfloodcount(struct Client *, int);
95     static void quote_rejecttime(struct Client *, int);
96    
97     /*
98     * If this ever needs to be expanded to more than one arg of each
99     * type, want_char/want_int could be the count of the arguments,
100     * instead of just a boolean flag...
101     *
102     * -davidt
103     */
104    
105 michael 1013 static const struct SetStruct set_cmd_table[] =
106 adx 30 {
107     /* name function string arg int arg */
108     /* -------------------------------------------------------- */
109     { "AUTOCONN", quote_autoconn, 1, 1 },
110     { "AUTOCONNALL", quote_autoconnall, 0, 1 },
111     { "FLOODCOUNT", quote_floodcount, 0, 1 },
112     { "IDENTTIMEOUT", quote_identtimeout, 0, 1 },
113     { "LOG", quote_log, 0, 1 },
114     { "MAX", quote_max, 0, 1 },
115     { "MSGLOCALE", quote_msglocale, 1, 0 },
116     { "SPAMNUM", quote_spamnum, 0, 1 },
117     { "SPAMTIME", quote_spamtime, 0, 1 },
118     { "SPLITMODE", quote_splitmode, 1, 0 },
119     { "SPLITNUM", quote_splitnum, 0, 1 },
120     { "SPLITUSERS", quote_splitusers, 0, 1 },
121     { "JFLOODTIME", quote_jfloodtime, 0, 1 },
122     { "JFLOODCOUNT", quote_jfloodcount, 0, 1 },
123     { "REJECTTIME", quote_rejecttime, 0, 1 },
124     /* -------------------------------------------------------- */
125 michael 946 { NULL, NULL, 0, 0 }
126 adx 30 };
127    
128     /*
129     * list_quote_commands() sends the client all the available commands.
130     * Four to a line for now.
131     */
132     static void
133     list_quote_commands(struct Client *source_p)
134     {
135     int j = 0;
136 michael 1013 const struct SetStruct *tab = set_cmd_table;
137 michael 896 const char *names[4] = { "", "", "", "" };
138 adx 30
139     sendto_one(source_p, ":%s NOTICE %s :Available QUOTE SET commands:",
140     me.name, source_p->name);
141    
142 michael 1013 for (; tab->handler; ++tab)
143 adx 30 {
144 michael 1013 names[j++] = tab->name;
145 adx 30
146     if (j > 3)
147     {
148     sendto_one(source_p, ":%s NOTICE %s :%s %s %s %s",
149     me.name, source_p->name,
150     names[0], names[1],
151     names[2], names[3]);
152     j = 0;
153     names[0] = names[1] = names[2] = names[3] = "";
154     }
155    
156     }
157 michael 896
158 adx 30 if (j)
159     sendto_one(source_p, ":%s NOTICE %s :%s %s %s %s",
160     me.name, source_p->name,
161     names[0], names[1],
162     names[2], names[3]);
163     }
164    
165     /* SET AUTOCONN */
166     static void
167     quote_autoconn(struct Client *source_p, const char *arg, int newval)
168     {
169 michael 896 struct AccessItem *aconf;
170    
171     if (arg != NULL)
172     {
173     struct ConfItem *conf = find_exact_name_conf(SERVER_TYPE, arg, NULL, NULL);
174    
175     if (conf != NULL)
176     {
177     aconf = map_to_conf(conf);
178     if (newval)
179     SetConfAllowAutoConn(aconf);
180     else
181     ClearConfAllowAutoConn(aconf);
182    
183     sendto_realops_flags(UMODE_ALL, L_ALL,
184     "%s has changed AUTOCONN for %s to %i",
185 michael 1141 get_oper_name(source_p), arg, newval);
186 michael 896 sendto_one(source_p,
187     ":%s NOTICE %s :AUTOCONN for %s is now set to %i",
188     me.name, source_p->name, arg, newval);
189     }
190     else
191     {
192     sendto_one(source_p, ":%s NOTICE %s :Can't find %s",
193     me.name, source_p->name, arg);
194     }
195     }
196     else
197     {
198     sendto_one(source_p, ":%s NOTICE %s :Please specify a server name!",
199     me.name, source_p->name);
200     }
201 adx 30 }
202    
203     /* SET AUTOCONNALL */
204     static void
205     quote_autoconnall(struct Client *source_p, int newval)
206     {
207     if (newval >= 0)
208     {
209     sendto_realops_flags(UMODE_ALL, L_ALL, "%s has changed AUTOCONNALL to %i",
210 michael 1141 get_oper_name(source_p), newval);
211 adx 30
212     GlobalSetOptions.autoconn = newval;
213     }
214     else
215     sendto_one(source_p, ":%s NOTICE %s :AUTOCONNALL is currently %i",
216     me.name, source_p->name, GlobalSetOptions.autoconn);
217     }
218    
219     /* SET FLOODCOUNT */
220     static void
221     quote_floodcount(struct Client *source_p, int newval)
222     {
223     if (newval >= 0)
224     {
225     GlobalSetOptions.floodcount = newval;
226     sendto_realops_flags(UMODE_ALL, L_ALL,
227 michael 1141 "%s has changed FLOODCOUNT to %i",
228     get_oper_name(source_p), GlobalSetOptions.floodcount);
229 adx 30 }
230     else
231     sendto_one(source_p, ":%s NOTICE %s :FLOODCOUNT is currently %i",
232     me.name, source_p->name, GlobalSetOptions.floodcount);
233     }
234    
235     /* SET IDENTTIMEOUT */
236     static void
237     quote_identtimeout(struct Client *source_p, int newval)
238     {
239 michael 1219 if (!HasUMode(source_p, UMODE_ADMIN))
240 adx 30 {
241     sendto_one(source_p, form_str(ERR_NOPRIVS),
242     me.name, source_p->name, "set");
243     return;
244     }
245    
246     if (newval > 0)
247     {
248     sendto_realops_flags(UMODE_ALL, L_ALL,
249     "%s has changed IDENTTIMEOUT to %d",
250     get_oper_name(source_p), newval);
251     GlobalSetOptions.ident_timeout = newval;
252     }
253     else
254     sendto_one(source_p, ":%s NOTICE %s :IDENTTIMEOUT is currently %d",
255     me.name, source_p->name, GlobalSetOptions.ident_timeout);
256     }
257    
258     /* SET LOG */
259     static void
260 michael 896 quote_log(struct Client *source_p, int newval)
261 adx 30 {
262     if (newval >= 0)
263     {
264     if (newval < L_WARN)
265     {
266     sendto_one(source_p, ":%s NOTICE %s :LOG must be > %d (L_WARN)",
267     me.name, source_p->name, L_WARN);
268     return;
269     }
270    
271     if (newval > L_DEBUG)
272     newval = L_DEBUG;
273    
274     set_log_level(newval);
275 michael 1141 sendto_realops_flags(UMODE_ALL, L_ALL, "%s has changed LOG level to %i (%s)",
276     get_oper_name(source_p), get_log_level(),
277 michael 1013 get_log_level_as_string(get_log_level()));
278 adx 30 }
279     else
280     sendto_one(source_p, ":%s NOTICE %s :LOG level is currently %i (%s)",
281     me.name, source_p->name, get_log_level(),
282     get_log_level_as_string(get_log_level()));
283     }
284    
285     /* SET MAX */
286     static void
287 michael 896 quote_max(struct Client *source_p, int newval)
288 adx 30 {
289     if (newval > 0)
290     {
291     recalc_fdlimit(NULL);
292    
293     if (newval > MAXCLIENTS_MAX)
294     {
295     sendto_one(source_p,
296     ":%s NOTICE %s :You cannot set MAXCLIENTS to > %d, restoring to %d",
297 michael 1140 me.name, source_p->name, MAXCLIENTS_MAX, ServerInfo.max_clients);
298 adx 30 return;
299     }
300    
301     if (newval < MAXCLIENTS_MIN)
302     {
303     sendto_one(source_p,
304     ":%s NOTICE %s :You cannot set MAXCLIENTS to < %d, restoring to %d",
305     me.name, source_p->name, MAXCLIENTS_MIN, ServerInfo.max_clients);
306     return;
307     }
308    
309     ServerInfo.max_clients = newval;
310    
311     sendto_realops_flags(UMODE_ALL, L_ALL,
312 michael 1141 "%s set new MAXCLIENTS to %d (%d current)",
313 michael 1142 get_oper_name(source_p), ServerInfo.max_clients, Count.local);
314 adx 30 }
315     else
316     sendto_one(source_p, ":%s NOTICE %s :Current MAXCLIENTS = %d (%d)",
317     me.name, source_p->name, ServerInfo.max_clients, Count.local);
318     }
319    
320     /* SET MSGLOCALE */
321     static void
322 michael 896 quote_msglocale(struct Client *source_p, char *locale)
323 adx 30 {
324     if (locale != NULL)
325     {
326     set_locale(locale);
327     rebuild_isupport_message_line();
328     sendto_one(source_p, ":%s NOTICE %s :Set MSGLOCALE to '%s'",
329     me.name, source_p->name, get_locale());
330     }
331     else
332     sendto_one(source_p, ":%s NOTICE %s :MSGLOCALE is currently '%s'",
333     me.name, source_p->name, get_locale());
334     }
335    
336     /* SET SPAMNUM */
337     static void
338 michael 896 quote_spamnum(struct Client *source_p, int newval)
339 adx 30 {
340 michael 646 if (newval >= 0)
341 adx 30 {
342     if (newval == 0)
343     {
344     sendto_realops_flags(UMODE_ALL, L_ALL,
345     "%s has disabled ANTI_SPAMBOT", source_p->name);
346     GlobalSetOptions.spam_num = newval;
347     return;
348     }
349    
350     GlobalSetOptions.spam_num = IRCD_MAX(newval, MIN_SPAM_NUM);
351 michael 1141 sendto_realops_flags(UMODE_ALL, L_ALL, "%s has changed SPAMNUM to %i",
352     get_oper_name(source_p), GlobalSetOptions.spam_num);
353 adx 30 }
354     else
355     sendto_one(source_p, ":%s NOTICE %s :SPAMNUM is currently %i",
356 michael 1013 me.name, source_p->name, GlobalSetOptions.spam_num);
357 adx 30 }
358    
359     /* SET SPAMTIME */
360     static void
361 michael 896 quote_spamtime(struct Client *source_p, int newval)
362 adx 30 {
363     if (newval > 0)
364     {
365     GlobalSetOptions.spam_time = IRCD_MAX(newval, MIN_SPAM_TIME);
366     sendto_realops_flags(UMODE_ALL, L_ALL, "%s has changed SPAMTIME to %i",
367 michael 1141 get_oper_name(source_p), GlobalSetOptions.spam_time);
368 adx 30 }
369     else
370     sendto_one(source_p, ":%s NOTICE %s :SPAMTIME is currently %i",
371 michael 1013 me.name, source_p->name, GlobalSetOptions.spam_time);
372 adx 30 }
373    
374     /* this table is what splitmode may be set to */
375     static const char *splitmode_values[] =
376     {
377     "OFF",
378     "ON",
379     "AUTO",
380     NULL
381     };
382    
383     /* this table is what splitmode may be */
384     static const char *splitmode_status[] =
385     {
386     "OFF",
387     "AUTO (OFF)",
388     "ON",
389     "AUTO (ON)",
390     NULL
391     };
392    
393     /* SET SPLITMODE */
394     static void
395     quote_splitmode(struct Client *source_p, char *charval)
396     {
397     if (charval)
398     {
399     int newval;
400    
401 michael 896 for (newval = 0; splitmode_values[newval]; ++newval)
402 adx 30 if (irccmp(splitmode_values[newval], charval) == 0)
403     break;
404    
405     /* OFF */
406     if (newval == 0)
407     {
408     sendto_realops_flags(UMODE_ALL, L_ALL,
409     "%s is disabling splitmode",
410     get_oper_name(source_p));
411    
412     splitmode = 0;
413     splitchecking = 0;
414    
415     eventDelete(check_splitmode, NULL);
416     }
417     /* ON */
418     else if (newval == 1)
419     {
420     sendto_realops_flags(UMODE_ALL, L_ALL,
421     "%s is enabling and activating splitmode",
422     get_oper_name(source_p));
423    
424     splitmode = 1;
425     splitchecking = 0;
426    
427     /* we might be deactivating an automatic splitmode, so pull the event */
428     eventDelete(check_splitmode, NULL);
429     }
430     /* AUTO */
431     else if (newval == 2)
432     {
433     sendto_realops_flags(UMODE_ALL, L_ALL,
434     "%s is enabling automatic splitmode",
435     get_oper_name(source_p));
436    
437     splitchecking = 1;
438     check_splitmode(NULL);
439     }
440     }
441     else
442     /* if we add splitchecking to splitmode*2 we get a unique table to
443     * pull values back out of, splitmode can be four states - but you can
444     * only set to three, which means we cant use the same table --fl_
445     */
446     sendto_one(source_p, ":%s NOTICE %s :SPLITMODE is currently %s",
447     me.name, source_p->name,
448 michael 1141 splitmode_status[(splitchecking + (splitmode * 2))]);
449 adx 30 }
450    
451     /* SET SPLITNUM */
452     static void
453     quote_splitnum(struct Client *source_p, int newval)
454     {
455     if (newval >= 0)
456     {
457     sendto_realops_flags(UMODE_ALL, L_ALL,
458     "%s has changed SPLITNUM to %i",
459 michael 1141 get_oper_name(source_p), newval);
460 adx 30 split_servers = newval;
461    
462     if (splitchecking)
463     check_splitmode(NULL);
464     }
465     else
466     sendto_one(source_p, ":%s NOTICE %s :SPLITNUM is currently %i",
467     me.name, source_p->name, split_servers);
468     }
469    
470     /* SET SPLITUSERS */
471     static void
472     quote_splitusers(struct Client *source_p, int newval)
473     {
474     if (newval >= 0)
475     {
476     sendto_realops_flags(UMODE_ALL, L_ALL,
477     "%s has changed SPLITUSERS to %i",
478 michael 1141 get_oper_name(source_p), newval);
479 adx 30 split_users = newval;
480    
481     if (splitchecking)
482     check_splitmode(NULL);
483     }
484     else
485     sendto_one(source_p, ":%s NOTICE %s :SPLITUSERS is currently %i",
486     me.name, source_p->name, split_users);
487     }
488    
489     /* SET JFLOODTIME */
490     static void
491     quote_jfloodtime(struct Client *source_p, int newval)
492     {
493     if (newval >= 0)
494     {
495     sendto_realops_flags(UMODE_ALL, L_ALL,
496     "%s has changed JFLOODTIME to %i",
497 michael 1141 get_oper_name(source_p), newval);
498 adx 30 GlobalSetOptions.joinfloodtime = newval;
499     }
500     else
501     sendto_one(source_p, ":%s NOTICE %s :JFLOODTIME is currently %i",
502     me.name, source_p->name, GlobalSetOptions.joinfloodtime);
503     }
504    
505     /* SET JFLOODCOUNT */
506     static void
507     quote_jfloodcount(struct Client *source_p, int newval)
508     {
509     if (newval >= 0)
510     {
511     sendto_realops_flags(UMODE_ALL, L_ALL,
512     "%s has changed JFLOODCOUNT to %i",
513 michael 1141 get_oper_name(source_p), newval);
514 adx 30 GlobalSetOptions.joinfloodcount = newval;
515     }
516     else
517     sendto_one(source_p, ":%s NOTICE %s :JFLOODCOUNT is currently %i",
518     me.name, source_p->name, GlobalSetOptions.joinfloodcount);
519     }
520    
521     /* SET REJECTTIME */
522     static void
523     quote_rejecttime(struct Client *source_p, int newval)
524     {
525     if (newval >= 0)
526     {
527     sendto_realops_flags(UMODE_ALL, L_ALL,
528     "%s has changed REJECTTIME to %i seconds",
529 michael 1141 get_oper_name(source_p), newval);
530 adx 30 GlobalSetOptions.rejecttime = newval;
531     }
532     else
533     sendto_one(source_p, ":%s NOTICE %s :REJECTTIME is currently %i seconds",
534     me.name, source_p->name, GlobalSetOptions.rejecttime);
535     }
536    
537     /*
538     * mo_set - SET command handler
539     * set options while running
540     */
541     static void
542     mo_set(struct Client *client_p, struct Client *source_p,
543     int parc, char *parv[])
544     {
545     int n;
546     int newval;
547     const char *arg = NULL;
548     const char *intarg = NULL;
549 michael 1013 const struct SetStruct *tab = set_cmd_table;
550 adx 30
551     if (parc > 1)
552     {
553 michael 1013 /*
554     * Go through all the commands in set_cmd_table, until one is
555     * matched.
556 adx 30 */
557 michael 1013 for (; tab->handler; ++tab)
558 adx 30 {
559 michael 1013 if (!irccmp(tab->name, parv[1]))
560 adx 30 {
561     /*
562     * Command found; now execute the code
563     */
564     n = 2;
565    
566 michael 1013 if (tab->wants_char)
567 adx 30 arg = parv[n++];
568    
569 michael 1013 if (tab->wants_int)
570 adx 30 intarg = parv[n++];
571    
572     if ((n - 1) > parc)
573     {
574     if (parc > 2)
575     sendto_one(source_p,
576     ":%s NOTICE %s :SET %s expects (\"%s%s\") args",
577 michael 1013 me.name, source_p->name, tab->name,
578     (tab->wants_char ? "string, " : ""),
579     (tab->wants_char ? "int" : ""));
580 adx 30 }
581    
582     if (parc <= 2)
583     {
584     arg = NULL;
585     intarg = NULL;
586     }
587    
588 michael 1013 if (!strcmp(tab->name, "AUTOCONN") && (parc < 4))
589 adx 30 {
590     sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
591     me.name, source_p->name, "SET");
592     return;
593     }
594    
595 michael 1013 if (tab->wants_int && (parc > 2))
596 adx 30 {
597     if (intarg)
598     {
599     if (irccmp(intarg, "yes") == 0 || irccmp(intarg, "on") == 0)
600     newval = 1;
601     else if (irccmp(intarg, "no") == 0|| irccmp(intarg, "off") == 0)
602     newval = 0;
603     else
604     newval = atoi(intarg);
605     }
606     else
607     {
608     newval = -1;
609     }
610    
611     if (newval < 0)
612     {
613     sendto_one(source_p,
614     ":%s NOTICE %s :Value less than 0 illegal for %s",
615     me.name, source_p->name,
616 michael 1013 tab->name);
617 adx 30
618     return;
619     }
620     }
621     else
622     newval = -1;
623    
624 michael 1013 if (tab->wants_char)
625 adx 30 {
626 michael 1013 if (tab->wants_int)
627     tab->handler(source_p, arg, newval);
628 adx 30 else
629 michael 1013 tab->handler(source_p, arg);
630 adx 30 return;
631     }
632     else
633     {
634 michael 1013 if (tab->wants_int)
635     tab->handler(source_p, newval);
636 adx 30 else
637     /* Just in case someone actually wants a
638     * set function that takes no args.. *shrug* */
639 michael 1013 tab->handler(source_p);
640 adx 30 return;
641     }
642     }
643     }
644    
645     /*
646     * Code here will be executed when a /QUOTE SET command is not
647     * found within set_cmd_table.
648     */
649     sendto_one(source_p, ":%s NOTICE %s :Variable not found.",
650     me.name, source_p->name);
651     return;
652     }
653    
654     list_quote_commands(source_p);
655     }

Properties

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