]>
jfr.im git - solanum.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
25 /* rewritten by jdc */
37 #include "s_newconf.h"
42 static int mo_set(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
44 struct Message set_msgtab
= {
46 {mg_unreg
, mg_not_oper
, mg_ignore
, mg_ignore
, mg_ignore
, {mo_set
, 0}}
49 mapi_clist_av1 set_clist
[] = { &set_msgtab
, NULL
};
50 DECLARE_MODULE_AV1(set
, NULL
, NULL
, set_clist
, NULL
, NULL
, "$Revision: 3406 $");
52 /* Structure used for the SET table itself */
56 void (*handler
)(struct Client
*source_p
, const char *chararg
, int intarg
);
57 int wants_char
; /* 1 if it expects (char *, [int]) */
58 int wants_int
; /* 1 if it expects ([char *], int) */
60 /* eg: 0, 1 == only an int arg
61 * eg: 1, 1 == char and int args */
65 static void quote_adminstring(struct Client
*, const char *, int);
66 static void quote_autoconn(struct Client
*, const char *, int);
67 static void quote_autoconnall(struct Client
*, const char *, int);
68 static void quote_floodcount(struct Client
*, const char *, int);
69 static void quote_identtimeout(struct Client
*, const char *, int);
70 static void quote_max(struct Client
*, const char *, int);
71 static void quote_operstring(struct Client
*, const char *, int);
72 static void quote_spamnum(struct Client
*, const char *, int);
73 static void quote_spamtime(struct Client
*, const char *, int);
74 static void quote_splitmode(struct Client
*, const char *, int);
75 static void quote_splitnum(struct Client
*, const char *, int);
76 static void quote_splitusers(struct Client
*, const char *, int);
78 static void list_quote_commands(struct Client
*);
82 * If this ever needs to be expanded to more than one arg of each
83 * type, want_char/want_int could be the count of the arguments,
84 * instead of just a boolean flag...
89 static struct SetStruct set_cmd_table
[] = {
90 /* name function string arg int arg */
91 /* -------------------------------------------------------- */
92 {"ADMINSTRING", quote_adminstring
, 1, 0 },
93 {"AUTOCONN", quote_autoconn
, 1, 1 },
94 {"AUTOCONNALL", quote_autoconnall
, 0, 1 },
95 {"FLOODCOUNT", quote_floodcount
, 0, 1 },
96 {"IDENTTIMEOUT", quote_identtimeout
, 0, 1 },
97 {"MAX", quote_max
, 0, 1 },
98 {"MAXCLIENTS", quote_max
, 0, 1 },
99 {"OPERSTRING", quote_operstring
, 1, 0 },
100 {"SPAMNUM", quote_spamnum
, 0, 1 },
101 {"SPAMTIME", quote_spamtime
, 0, 1 },
102 {"SPLITMODE", quote_splitmode
, 1, 0 },
103 {"SPLITNUM", quote_splitnum
, 0, 1 },
104 {"SPLITUSERS", quote_splitusers
, 0, 1 },
105 /* -------------------------------------------------------- */
106 {(char *) 0, (void (*)(struct Client
*, const char *, int)) 0, 0, 0}
111 * list_quote_commands() sends the client all the available commands.
112 * Four to a line for now.
115 list_quote_commands(struct Client
*source_p
)
119 const char *names
[4];
121 sendto_one_notice(source_p
, ":Available QUOTE SET commands:");
123 names
[0] = names
[1] = names
[2] = names
[3] = "";
125 for (i
= 0; set_cmd_table
[i
].handler
; i
++)
127 names
[j
++] = set_cmd_table
[i
].name
;
131 sendto_one_notice(source_p
, ":%s %s %s %s",
132 names
[0], names
[1], names
[2], names
[3]);
134 names
[0] = names
[1] = names
[2] = names
[3] = "";
139 sendto_one_notice(source_p
, ":%s %s %s %s",
140 names
[0], names
[1], names
[2], names
[3]);
145 quote_autoconn(struct Client
*source_p
, const char *arg
, int newval
)
147 set_server_conf_autoconn(source_p
, arg
, newval
);
150 /* SET AUTOCONNALL */
152 quote_autoconnall(struct Client
*source_p
, const char *arg
, int newval
)
156 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "%s has changed AUTOCONNALL to %i",
157 source_p
->name
, newval
);
159 GlobalSetOptions
.autoconn
= newval
;
163 sendto_one_notice(source_p
, ":AUTOCONNALL is currently %i",
164 GlobalSetOptions
.autoconn
);
171 quote_floodcount(struct Client
*source_p
, const char *arg
, int newval
)
175 GlobalSetOptions
.floodcount
= newval
;
176 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
177 "%s has changed FLOODCOUNT to %i", source_p
->name
,
178 GlobalSetOptions
.floodcount
);
182 sendto_one_notice(source_p
, ":FLOODCOUNT is currently %i",
183 GlobalSetOptions
.floodcount
);
187 /* SET IDENTTIMEOUT */
189 quote_identtimeout(struct Client
*source_p
, const char *arg
, int newval
)
191 if(!IsOperAdmin(source_p
))
193 sendto_one(source_p
, form_str(ERR_NOPRIVS
),
194 me
.name
, source_p
->name
, "admin");
200 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
201 "%s has changed IDENTTIMEOUT to %d",
202 get_oper_name(source_p
), newval
);
203 GlobalSetOptions
.ident_timeout
= newval
;
206 sendto_one_notice(source_p
, ":IDENTTIMEOUT is currently %d",
207 GlobalSetOptions
.ident_timeout
);
212 quote_max(struct Client
*source_p
, const char *arg
, int newval
)
216 if(newval
> maxconnections
- MAX_BUFFER
)
218 sendto_one_notice(source_p
,
219 ":You cannot set MAXCLIENTS to > %d",
220 maxconnections
- MAX_BUFFER
);
226 sendto_one_notice(source_p
, ":You cannot set MAXCLIENTS to < 32 (%d:%d)",
227 GlobalSetOptions
.maxclients
, rb_getmaxconnect());
231 GlobalSetOptions
.maxclients
= newval
;
233 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
234 "%s!%s@%s set new MAXCLIENTS to %d (%lu current)",
235 source_p
->name
, source_p
->username
, source_p
->host
,
236 GlobalSetOptions
.maxclients
,
237 rb_dlink_list_length(&lclient_list
));
243 sendto_one_notice(source_p
, ":Current Maxclients = %d (%lu)",
244 GlobalSetOptions
.maxclients
, rb_dlink_list_length(&lclient_list
));
250 quote_operstring(struct Client
*source_p
, const char *arg
, int newval
)
254 sendto_one_notice(source_p
, ":OPERSTRING is currently '%s'", GlobalSetOptions
.operstring
);
258 rb_strlcpy(GlobalSetOptions
.operstring
, arg
,
259 sizeof(GlobalSetOptions
.operstring
));
261 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
262 "%s has changed OPERSTRING to '%s'",
263 get_oper_name(source_p
), arg
);
267 /* SET ADMINSTRING */
269 quote_adminstring(struct Client
*source_p
, const char *arg
, int newval
)
273 sendto_one_notice(source_p
, ":ADMINSTRING is currently '%s'", GlobalSetOptions
.adminstring
);
277 rb_strlcpy(GlobalSetOptions
.adminstring
, arg
,
278 sizeof(GlobalSetOptions
.adminstring
));
280 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
281 "%s has changed ADMINSTRING to '%s'",
282 get_oper_name(source_p
), arg
);
288 quote_spamnum(struct Client
*source_p
, const char *arg
, int newval
)
294 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
295 "%s has disabled ANTI_SPAMBOT", source_p
->name
);
296 GlobalSetOptions
.spam_num
= newval
;
299 if(newval
< MIN_SPAM_NUM
)
301 GlobalSetOptions
.spam_num
= MIN_SPAM_NUM
;
303 else /* if (newval < MIN_SPAM_NUM) */
305 GlobalSetOptions
.spam_num
= newval
;
307 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "%s has changed SPAMNUM to %i",
308 source_p
->name
, GlobalSetOptions
.spam_num
);
312 sendto_one_notice(source_p
, ":SPAMNUM is currently %i", GlobalSetOptions
.spam_num
);
318 quote_spamtime(struct Client
*source_p
, const char *arg
, int newval
)
322 if(newval
< MIN_SPAM_TIME
)
324 GlobalSetOptions
.spam_time
= MIN_SPAM_TIME
;
326 else /* if (newval < MIN_SPAM_TIME) */
328 GlobalSetOptions
.spam_time
= newval
;
330 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "%s has changed SPAMTIME to %i",
331 source_p
->name
, GlobalSetOptions
.spam_time
);
335 sendto_one_notice(source_p
, ":SPAMTIME is currently %i", GlobalSetOptions
.spam_time
);
339 /* this table is what splitmode may be set to */
340 static const char *splitmode_values
[] = {
347 /* this table is what splitmode may be */
348 static const char *splitmode_status
[] = {
358 quote_splitmode(struct Client
*source_p
, const char *charval
, int intval
)
364 for (newval
= 0; splitmode_values
[newval
]; newval
++)
366 if(!irccmp(splitmode_values
[newval
], charval
))
373 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
374 "%s is disabling splitmode", get_oper_name(source_p
));
379 rb_event_delete(check_splitmode_ev
);
380 check_splitmode_ev
= NULL
;
385 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
386 "%s is enabling and activating splitmode",
387 get_oper_name(source_p
));
392 /* we might be deactivating an automatic splitmode, so pull the event */
393 rb_event_delete(check_splitmode_ev
);
394 check_splitmode_ev
= NULL
;
399 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
400 "%s is enabling automatic splitmode",
401 get_oper_name(source_p
));
404 check_splitmode(NULL
);
408 /* if we add splitchecking to splitmode*2 we get a unique table to
409 * pull values back out of, splitmode can be four states - but you can
410 * only set to three, which means we cant use the same table --fl_
412 sendto_one_notice(source_p
, ":SPLITMODE is currently %s",
413 splitmode_status
[(splitchecking
+ (splitmode
* 2))]);
418 quote_splitnum(struct Client
*source_p
, const char *arg
, int newval
)
422 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
423 "%s has changed SPLITNUM to %i", source_p
->name
, newval
);
424 split_servers
= newval
;
427 check_splitmode(NULL
);
430 sendto_one_notice(source_p
, ":SPLITNUM is currently %i", split_servers
);
435 quote_splitusers(struct Client
*source_p
, const char *arg
, int newval
)
439 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
440 "%s has changed SPLITUSERS to %i", source_p
->name
, newval
);
441 split_users
= newval
;
444 check_splitmode(NULL
);
447 sendto_one_notice(source_p
, ":SPLITUSERS is currently %i", split_users
);
451 * mo_set - SET command handler
452 * set options while running
455 mo_set(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
459 const char *arg
= NULL
;
460 const char *intarg
= NULL
;
465 * Go through all the commands in set_cmd_table, until one is
466 * matched. I realize strcmp() is more intensive than a numeric
467 * lookup, but at least it's better than a big-ass switch/case
470 for (i
= 0; set_cmd_table
[i
].handler
; i
++)
472 if(!irccmp(set_cmd_table
[i
].name
, parv
[1]))
475 * Command found; now execute the code
479 if(set_cmd_table
[i
].wants_char
)
484 if(set_cmd_table
[i
].wants_int
)
491 sendto_one_notice(source_p
,
492 ":SET %s expects (\"%s%s\") args",
493 set_cmd_table
[i
].name
,
495 wants_char
? "string, " : ""),
497 wants_char
? "int" : ""));
507 if(set_cmd_table
[i
].wants_int
&& (parc
> 2))
511 if(!irccmp(intarg
, "yes") || !irccmp(intarg
, "on"))
513 else if(!irccmp(intarg
, "no")
514 || !irccmp(intarg
, "off"))
517 newval
= atoi(intarg
);
526 sendto_one_notice(source_p
,
527 ":Value less than 0 illegal for %s",
528 set_cmd_table
[i
].name
);
536 set_cmd_table
[i
].handler(source_p
, arg
, newval
);
542 * Code here will be executed when a /QUOTE SET command is not
543 * found within set_cmd_table.
545 sendto_one_notice(source_p
, ":Variable not found.");
549 list_quote_commands(source_p
);