]>
jfr.im git - irc/rqf/shadowircd.git/blob - modules/m_set.c
2 * ircd-ratbox: A slightly useful ircd.
3 * m_set.c: Sets a server parameter.
5 * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
6 * Copyright (C) 1996-2002 Hybrid Development Team
7 * Copyright (C) 2002-2005 ircd-ratbox development team
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
24 * $Id: m_set.c 3161 2007-01-25 07:23:01Z nenolod $
27 /* rewritten by jdc */
32 #include "irc_string.h"
33 #include "sprintf_irc.h"
42 #include "s_newconf.h"
47 static int mo_set(struct Client
*, struct Client
*, int, const char **);
49 struct Message set_msgtab
= {
50 "SET", 0, 0, 0, MFLG_SLOW
,
51 {mg_unreg
, mg_not_oper
, mg_ignore
, mg_ignore
, mg_ignore
, {mo_set
, 0}}
54 mapi_clist_av1 set_clist
[] = { &set_msgtab
, NULL
};
55 DECLARE_MODULE_AV1(set
, NULL
, NULL
, set_clist
, NULL
, NULL
, "$Revision: 3161 $");
57 /* Structure used for the SET table itself */
62 int wants_char
; /* 1 if it expects (char *, [int]) */
63 int wants_int
; /* 1 if it expects ([char *], int) */
65 /* eg: 0, 1 == only an int arg
66 * eg: 1, 1 == char and int args */
70 static void quote_adminstring(struct Client
*, const char *);
71 static void quote_autoconn(struct Client
*, char *, int);
72 static void quote_autoconnall(struct Client
*, int);
73 static void quote_floodcount(struct Client
*, int);
74 static void quote_identtimeout(struct Client
*, int);
75 static void quote_idletime(struct Client
*, int);
76 static void quote_max(struct Client
*, int);
77 static void quote_operstring(struct Client
*, const char *);
78 static void quote_spamnum(struct Client
*, int);
79 static void quote_spamtime(struct Client
*, int);
80 static void quote_splitmode(struct Client
*, char *);
81 static void quote_splitnum(struct Client
*, int);
82 static void quote_splitusers(struct Client
*, int);
83 static void list_quote_commands(struct Client
*);
87 * If this ever needs to be expanded to more than one arg of each
88 * type, want_char/want_int could be the count of the arguments,
89 * instead of just a boolean flag...
94 static struct SetStruct set_cmd_table
[] = {
95 /* name function string arg int arg */
96 /* -------------------------------------------------------- */
97 {"ADMINSTRING", quote_adminstring
, 1, 0 },
98 {"AUTOCONN", quote_autoconn
, 1, 1 },
99 {"AUTOCONNALL", quote_autoconnall
, 0, 1 },
100 {"FLOODCOUNT", quote_floodcount
, 0, 1 },
101 {"IDENTTIMEOUT", quote_identtimeout
, 0, 1 },
102 {"IDLETIME", quote_idletime
, 0, 1 },
103 {"MAX", quote_max
, 0, 1 },
104 {"MAXCLIENTS", quote_max
, 0, 1 },
105 {"OPERSTRING", quote_operstring
, 1, 0 },
106 {"SPAMNUM", quote_spamnum
, 0, 1 },
107 {"SPAMTIME", quote_spamtime
, 0, 1 },
108 {"SPLITMODE", quote_splitmode
, 1, 0 },
109 {"SPLITNUM", quote_splitnum
, 0, 1 },
110 {"SPLITUSERS", quote_splitusers
, 0, 1 },
111 /* -------------------------------------------------------- */
112 {(char *) 0, (void (*)()) 0, 0, 0}
117 * list_quote_commands() sends the client all the available commands.
118 * Four to a line for now.
121 list_quote_commands(struct Client
*source_p
)
125 const char *names
[4];
127 sendto_one_notice(source_p
, ":Available QUOTE SET commands:");
129 names
[0] = names
[1] = names
[2] = names
[3] = "";
131 for (i
= 0; set_cmd_table
[i
].handler
; i
++)
133 names
[j
++] = set_cmd_table
[i
].name
;
137 sendto_one_notice(source_p
, ":%s %s %s %s",
138 names
[0], names
[1], names
[2], names
[3]);
140 names
[0] = names
[1] = names
[2] = names
[3] = "";
145 sendto_one_notice(source_p
, ":%s %s %s %s",
146 names
[0], names
[1], names
[2], names
[3]);
151 quote_autoconn(struct Client
*source_p
, char *arg
, int newval
)
153 set_server_conf_autoconn(source_p
, arg
, newval
);
156 /* SET AUTOCONNALL */
158 quote_autoconnall(struct Client
*source_p
, int newval
)
162 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "%s has changed AUTOCONNALL to %i",
163 source_p
->name
, newval
);
165 GlobalSetOptions
.autoconn
= newval
;
169 sendto_one_notice(source_p
, ":AUTOCONNALL is currently %i",
170 GlobalSetOptions
.autoconn
);
177 quote_floodcount(struct Client
*source_p
, int newval
)
181 GlobalSetOptions
.floodcount
= newval
;
182 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
183 "%s has changed FLOODCOUNT to %i", source_p
->name
,
184 GlobalSetOptions
.floodcount
);
188 sendto_one_notice(source_p
, ":FLOODCOUNT is currently %i",
189 GlobalSetOptions
.floodcount
);
193 /* SET IDENTTIMEOUT */
195 quote_identtimeout(struct Client
*source_p
, int newval
)
197 if(!IsOperAdmin(source_p
))
199 sendto_one(source_p
, form_str(ERR_NOPRIVS
),
200 me
.name
, source_p
->name
, "admin");
206 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
207 "%s has changed IDENTTIMEOUT to %d",
208 get_oper_name(source_p
), newval
);
209 GlobalSetOptions
.ident_timeout
= newval
;
212 sendto_one_notice(source_p
, ":IDENTTIMEOUT is currently %d",
213 GlobalSetOptions
.ident_timeout
);
218 quote_idletime(struct Client
*source_p
, int newval
)
224 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
225 "%s has disabled idletime checking", source_p
->name
);
226 GlobalSetOptions
.idletime
= 0;
230 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
231 "%s has changed IDLETIME to %i",
232 source_p
->name
, newval
);
233 GlobalSetOptions
.idletime
= (newval
* 60);
238 sendto_one_notice(source_p
, ":IDLETIME is currently %i",
239 GlobalSetOptions
.idletime
/ 60);
245 quote_max(struct Client
*source_p
, int newval
)
249 if(newval
> MASTER_MAX
)
251 sendto_one_notice(source_p
, ":You cannot set MAXCLIENTS to > MASTER_MAX (%d)",
258 sendto_one_notice(source_p
, ":You cannot set MAXCLIENTS to < 32 (%d:%d)",
259 GlobalSetOptions
.maxclients
, highest_fd
);
263 GlobalSetOptions
.maxclients
= newval
;
265 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
266 "%s!%s@%s set new MAXCLIENTS to %d (%lu current)",
267 source_p
->name
, source_p
->username
, source_p
->host
,
268 GlobalSetOptions
.maxclients
,
269 dlink_list_length(&lclient_list
));
275 sendto_one_notice(source_p
, ":Current Maxclients = %d (%lu)",
276 GlobalSetOptions
.maxclients
, dlink_list_length(&lclient_list
));
282 quote_operstring(struct Client
*source_p
, const char *arg
)
286 sendto_one_notice(source_p
, ":OPERSTRING is currently '%s'", GlobalSetOptions
.operstring
);
290 strlcpy(GlobalSetOptions
.operstring
, arg
,
291 sizeof(GlobalSetOptions
.operstring
));
293 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
294 "%s has changed OPERSTRING to '%s'",
295 get_oper_name(source_p
), arg
);
299 /* SET ADMINSTRING */
301 quote_adminstring(struct Client
*source_p
, const char *arg
)
305 sendto_one_notice(source_p
, ":ADMINSTRING is currently '%s'", GlobalSetOptions
.adminstring
);
309 strlcpy(GlobalSetOptions
.adminstring
, arg
,
310 sizeof(GlobalSetOptions
.adminstring
));
312 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
313 "%s has changed ADMINSTRING to '%s'",
314 get_oper_name(source_p
), arg
);
320 quote_spamnum(struct Client
*source_p
, int newval
)
326 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
327 "%s has disabled ANTI_SPAMBOT", source_p
->name
);
328 GlobalSetOptions
.spam_num
= newval
;
331 if(newval
< MIN_SPAM_NUM
)
333 GlobalSetOptions
.spam_num
= MIN_SPAM_NUM
;
335 else /* if (newval < MIN_SPAM_NUM) */
337 GlobalSetOptions
.spam_num
= newval
;
339 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "%s has changed SPAMNUM to %i",
340 source_p
->name
, GlobalSetOptions
.spam_num
);
344 sendto_one_notice(source_p
, ":SPAMNUM is currently %i", GlobalSetOptions
.spam_num
);
350 quote_spamtime(struct Client
*source_p
, int newval
)
354 if(newval
< MIN_SPAM_TIME
)
356 GlobalSetOptions
.spam_time
= MIN_SPAM_TIME
;
358 else /* if (newval < MIN_SPAM_TIME) */
360 GlobalSetOptions
.spam_time
= newval
;
362 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "%s has changed SPAMTIME to %i",
363 source_p
->name
, GlobalSetOptions
.spam_time
);
367 sendto_one_notice(source_p
, ":SPAMTIME is currently %i", GlobalSetOptions
.spam_time
);
371 /* this table is what splitmode may be set to */
372 static const char *splitmode_values
[] = {
379 /* this table is what splitmode may be */
380 static const char *splitmode_status
[] = {
390 quote_splitmode(struct Client
*source_p
, char *charval
)
396 for (newval
= 0; splitmode_values
[newval
]; newval
++)
398 if(!irccmp(splitmode_values
[newval
], charval
))
405 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
406 "%s is disabling splitmode", get_oper_name(source_p
));
411 eventDelete(check_splitmode
, NULL
);
416 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
417 "%s is enabling and activating splitmode",
418 get_oper_name(source_p
));
423 /* we might be deactivating an automatic splitmode, so pull the event */
424 eventDelete(check_splitmode
, NULL
);
429 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
430 "%s is enabling automatic splitmode",
431 get_oper_name(source_p
));
434 check_splitmode(NULL
);
438 /* if we add splitchecking to splitmode*2 we get a unique table to
439 * pull values back out of, splitmode can be four states - but you can
440 * only set to three, which means we cant use the same table --fl_
442 sendto_one_notice(source_p
, ":SPLITMODE is currently %s",
443 splitmode_status
[(splitchecking
+ (splitmode
* 2))]);
448 quote_splitnum(struct Client
*source_p
, int newval
)
452 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
453 "%s has changed SPLITNUM to %i", source_p
->name
, newval
);
454 split_servers
= newval
;
457 check_splitmode(NULL
);
460 sendto_one_notice(source_p
, ":SPLITNUM is currently %i", split_servers
);
465 quote_splitusers(struct Client
*source_p
, int newval
)
469 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
470 "%s has changed SPLITUSERS to %i", source_p
->name
, newval
);
471 split_users
= newval
;
474 check_splitmode(NULL
);
477 sendto_one_notice(source_p
, ":SPLITUSERS is currently %i", split_users
);
481 * mo_set - SET command handler
482 * set options while running
485 mo_set(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
489 const char *arg
= NULL
;
490 const char *intarg
= NULL
;
495 * Go through all the commands in set_cmd_table, until one is
496 * matched. I realize strcmp() is more intensive than a numeric
497 * lookup, but at least it's better than a big-ass switch/case
500 for (i
= 0; set_cmd_table
[i
].handler
; i
++)
502 if(!irccmp(set_cmd_table
[i
].name
, parv
[1]))
505 * Command found; now execute the code
509 if(set_cmd_table
[i
].wants_char
)
514 if(set_cmd_table
[i
].wants_int
)
521 sendto_one_notice(source_p
,
522 ":SET %s expects (\"%s%s\") args",
523 set_cmd_table
[i
].name
,
525 wants_char
? "string, " : ""),
527 wants_char
? "int" : ""));
537 if(set_cmd_table
[i
].wants_int
&& (parc
> 2))
541 if(!irccmp(intarg
, "yes") || !irccmp(intarg
, "on"))
543 else if(!irccmp(intarg
, "no")
544 || !irccmp(intarg
, "off"))
547 newval
= atoi(intarg
);
556 sendto_one_notice(source_p
,
557 ":Value less than 0 illegal for %s",
558 set_cmd_table
[i
].name
);
566 if(set_cmd_table
[i
].wants_char
)
568 if(set_cmd_table
[i
].wants_int
)
569 set_cmd_table
[i
].handler(source_p
, arg
, newval
);
571 set_cmd_table
[i
].handler(source_p
, arg
);
576 if(set_cmd_table
[i
].wants_int
)
577 set_cmd_table
[i
].handler(source_p
, newval
);
579 /* Just in case someone actually wants a
580 * set function that takes no args.. *shrug* */
581 set_cmd_table
[i
].handler(source_p
);
588 * Code here will be executed when a /QUOTE SET command is not
589 * found within set_cmd_table.
591 sendto_one_notice(source_p
, ":Variable not found.");
595 list_quote_commands(source_p
);