]> jfr.im git - irc/rqf/shadowircd.git/blame - modules/m_set.c
Some const stuff for m_set.
[irc/rqf/shadowircd.git] / modules / m_set.c
CommitLineData
212380e3 1/*
2 * ircd-ratbox: A slightly useful ircd.
3 * m_set.c: Sets a server parameter.
4 *
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
8 *
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.
13 *
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.
18 *
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
22 * USA
23 *
f4ed5745 24 * $Id: m_set.c 3406 2007-04-13 19:06:53Z jilles $
212380e3 25 */
26
27/* rewritten by jdc */
28
29#include "stdinc.h"
30#include "client.h"
13ae2f4b 31#include "match.h"
212380e3 32#include "ircd.h"
33#include "numeric.h"
212380e3 34#include "s_serv.h"
35#include "send.h"
36#include "common.h"
37#include "channel.h"
38#include "s_conf.h"
39#include "s_newconf.h"
40#include "msg.h"
41#include "parse.h"
42#include "modules.h"
43
44static int mo_set(struct Client *, struct Client *, int, const char **);
45
46struct Message set_msgtab = {
47 "SET", 0, 0, 0, MFLG_SLOW,
48 {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, mg_ignore, {mo_set, 0}}
49};
50
51mapi_clist_av1 set_clist[] = { &set_msgtab, NULL };
f4ed5745 52DECLARE_MODULE_AV1(set, NULL, NULL, set_clist, NULL, NULL, "$Revision: 3406 $");
212380e3 53
54/* Structure used for the SET table itself */
55struct SetStruct
56{
57 const char *name;
58 void (*handler) ();
59 int wants_char; /* 1 if it expects (char *, [int]) */
60 int wants_int; /* 1 if it expects ([char *], int) */
61
62 /* eg: 0, 1 == only an int arg
63 * eg: 1, 1 == char and int args */
64};
65
66
67static void quote_adminstring(struct Client *, const char *);
6d18bf1a 68static void quote_autoconn(struct Client *, const char *, int);
212380e3 69static void quote_autoconnall(struct Client *, int);
70static void quote_floodcount(struct Client *, int);
71static void quote_identtimeout(struct Client *, int);
212380e3 72static void quote_max(struct Client *, int);
73static void quote_operstring(struct Client *, const char *);
74static void quote_spamnum(struct Client *, int);
75static void quote_spamtime(struct Client *, int);
6d18bf1a 76static void quote_splitmode(struct Client *, const char *);
212380e3 77static void quote_splitnum(struct Client *, int);
78static void quote_splitusers(struct Client *, int);
79static void list_quote_commands(struct Client *);
80
81
82/*
83 * If this ever needs to be expanded to more than one arg of each
84 * type, want_char/want_int could be the count of the arguments,
85 * instead of just a boolean flag...
86 *
87 * -davidt
88 */
89
90static struct SetStruct set_cmd_table[] = {
91 /* name function string arg int arg */
92 /* -------------------------------------------------------- */
93 {"ADMINSTRING", quote_adminstring, 1, 0 },
94 {"AUTOCONN", quote_autoconn, 1, 1 },
95 {"AUTOCONNALL", quote_autoconnall, 0, 1 },
96 {"FLOODCOUNT", quote_floodcount, 0, 1 },
97 {"IDENTTIMEOUT", quote_identtimeout, 0, 1 },
212380e3 98 {"MAX", quote_max, 0, 1 },
99 {"MAXCLIENTS", quote_max, 0, 1 },
100 {"OPERSTRING", quote_operstring, 1, 0 },
101 {"SPAMNUM", quote_spamnum, 0, 1 },
102 {"SPAMTIME", quote_spamtime, 0, 1 },
103 {"SPLITMODE", quote_splitmode, 1, 0 },
104 {"SPLITNUM", quote_splitnum, 0, 1 },
105 {"SPLITUSERS", quote_splitusers, 0, 1 },
106 /* -------------------------------------------------------- */
107 {(char *) 0, (void (*)()) 0, 0, 0}
108};
109
110
111/*
112 * list_quote_commands() sends the client all the available commands.
113 * Four to a line for now.
114 */
115static void
116list_quote_commands(struct Client *source_p)
117{
118 int i;
119 int j = 0;
120 const char *names[4];
121
5366977b 122 sendto_one_notice(source_p, ":Available QUOTE SET commands:");
212380e3 123
124 names[0] = names[1] = names[2] = names[3] = "";
125
126 for (i = 0; set_cmd_table[i].handler; i++)
127 {
128 names[j++] = set_cmd_table[i].name;
129
130 if(j > 3)
131 {
5366977b 132 sendto_one_notice(source_p, ":%s %s %s %s",
133 names[0], names[1], names[2], names[3]);
212380e3 134 j = 0;
135 names[0] = names[1] = names[2] = names[3] = "";
136 }
137
138 }
139 if(j)
5366977b 140 sendto_one_notice(source_p, ":%s %s %s %s",
141 names[0], names[1], names[2], names[3]);
212380e3 142}
143
144/* SET AUTOCONN */
145static void
6d18bf1a 146quote_autoconn(struct Client *source_p, const char *arg, int newval)
212380e3 147{
148 set_server_conf_autoconn(source_p, arg, newval);
149}
150
151/* SET AUTOCONNALL */
152static void
153quote_autoconnall(struct Client *source_p, int newval)
154{
155 if(newval >= 0)
156 {
157 sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s has changed AUTOCONNALL to %i",
158 source_p->name, newval);
159
160 GlobalSetOptions.autoconn = newval;
161 }
162 else
163 {
5366977b 164 sendto_one_notice(source_p, ":AUTOCONNALL is currently %i",
165 GlobalSetOptions.autoconn);
212380e3 166 }
167}
168
169
170/* SET FLOODCOUNT */
171static void
172quote_floodcount(struct Client *source_p, int newval)
173{
174 if(newval >= 0)
175 {
176 GlobalSetOptions.floodcount = newval;
177 sendto_realops_snomask(SNO_GENERAL, L_ALL,
178 "%s has changed FLOODCOUNT to %i", source_p->name,
179 GlobalSetOptions.floodcount);
180 }
181 else
182 {
5366977b 183 sendto_one_notice(source_p, ":FLOODCOUNT is currently %i",
184 GlobalSetOptions.floodcount);
212380e3 185 }
186}
187
188/* SET IDENTTIMEOUT */
189static void
190quote_identtimeout(struct Client *source_p, int newval)
191{
192 if(!IsOperAdmin(source_p))
193 {
194 sendto_one(source_p, form_str(ERR_NOPRIVS),
195 me.name, source_p->name, "admin");
196 return;
197 }
198
199 if(newval > 0)
200 {
201 sendto_realops_snomask(SNO_GENERAL, L_ALL,
202 "%s has changed IDENTTIMEOUT to %d",
203 get_oper_name(source_p), newval);
204 GlobalSetOptions.ident_timeout = newval;
205 }
206 else
5366977b 207 sendto_one_notice(source_p, ":IDENTTIMEOUT is currently %d",
208 GlobalSetOptions.ident_timeout);
212380e3 209}
210
212380e3 211/* SET MAX */
212static void
213quote_max(struct Client *source_p, int newval)
214{
215 if(newval > 0)
216 {
b717a466
JT
217 if(newval > maxconnections - MAX_BUFFER)
218 {
219 sendto_one_notice(source_p,
220 ":You cannot set MAXCLIENTS to > %d",
221 maxconnections - MAX_BUFFER);
222 return;
6c70c576 223 }
224
212380e3 225 if(newval < 32)
226 {
3fe90825
VY
227 sendto_one_notice(source_p, ":You cannot set MAXCLIENTS to < 32 (%d:%d)",
228 GlobalSetOptions.maxclients, rb_getmaxconnect());
212380e3 229 return;
230 }
231
232 GlobalSetOptions.maxclients = newval;
233
234 sendto_realops_snomask(SNO_GENERAL, L_ALL,
235 "%s!%s@%s set new MAXCLIENTS to %d (%lu current)",
236 source_p->name, source_p->username, source_p->host,
237 GlobalSetOptions.maxclients,
08d11e34 238 rb_dlink_list_length(&lclient_list));
212380e3 239
240 return;
241 }
242 else
243 {
5366977b 244 sendto_one_notice(source_p, ":Current Maxclients = %d (%lu)",
08d11e34 245 GlobalSetOptions.maxclients, rb_dlink_list_length(&lclient_list));
212380e3 246 }
247}
248
249/* SET OPERSTRING */
250static void
251quote_operstring(struct Client *source_p, const char *arg)
252{
253 if(EmptyString(arg))
254 {
5366977b 255 sendto_one_notice(source_p, ":OPERSTRING is currently '%s'", GlobalSetOptions.operstring);
212380e3 256 }
257 else
258 {
907468c4 259 rb_strlcpy(GlobalSetOptions.operstring, arg,
212380e3 260 sizeof(GlobalSetOptions.operstring));
261
262 sendto_realops_snomask(SNO_GENERAL, L_ALL,
263 "%s has changed OPERSTRING to '%s'",
264 get_oper_name(source_p), arg);
265 }
266}
267
268/* SET ADMINSTRING */
269static void
270quote_adminstring(struct Client *source_p, const char *arg)
271{
272 if(EmptyString(arg))
273 {
5366977b 274 sendto_one_notice(source_p, ":ADMINSTRING is currently '%s'", GlobalSetOptions.adminstring);
212380e3 275 }
276 else
277 {
907468c4 278 rb_strlcpy(GlobalSetOptions.adminstring, arg,
212380e3 279 sizeof(GlobalSetOptions.adminstring));
280
281 sendto_realops_snomask(SNO_GENERAL, L_ALL,
282 "%s has changed ADMINSTRING to '%s'",
283 get_oper_name(source_p), arg);
284 }
285}
286
287/* SET SPAMNUM */
288static void
289quote_spamnum(struct Client *source_p, int newval)
290{
291 if(newval > 0)
292 {
293 if(newval == 0)
294 {
295 sendto_realops_snomask(SNO_GENERAL, L_ALL,
296 "%s has disabled ANTI_SPAMBOT", source_p->name);
297 GlobalSetOptions.spam_num = newval;
298 return;
299 }
300 if(newval < MIN_SPAM_NUM)
301 {
302 GlobalSetOptions.spam_num = MIN_SPAM_NUM;
303 }
304 else /* if (newval < MIN_SPAM_NUM) */
305 {
306 GlobalSetOptions.spam_num = newval;
307 }
308 sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s has changed SPAMNUM to %i",
309 source_p->name, GlobalSetOptions.spam_num);
310 }
311 else
312 {
5366977b 313 sendto_one_notice(source_p, ":SPAMNUM is currently %i", GlobalSetOptions.spam_num);
212380e3 314 }
315}
316
317/* SET SPAMTIME */
318static void
319quote_spamtime(struct Client *source_p, int newval)
320{
321 if(newval > 0)
322 {
323 if(newval < MIN_SPAM_TIME)
324 {
325 GlobalSetOptions.spam_time = MIN_SPAM_TIME;
326 }
327 else /* if (newval < MIN_SPAM_TIME) */
328 {
329 GlobalSetOptions.spam_time = newval;
330 }
331 sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s has changed SPAMTIME to %i",
332 source_p->name, GlobalSetOptions.spam_time);
333 }
334 else
335 {
5366977b 336 sendto_one_notice(source_p, ":SPAMTIME is currently %i", GlobalSetOptions.spam_time);
212380e3 337 }
338}
339
340/* this table is what splitmode may be set to */
341static const char *splitmode_values[] = {
342 "OFF",
343 "ON",
344 "AUTO",
345 NULL
346};
347
348/* this table is what splitmode may be */
349static const char *splitmode_status[] = {
350 "OFF",
351 "AUTO (OFF)",
352 "ON",
353 "AUTO (ON)",
354 NULL
355};
356
357/* SET SPLITMODE */
358static void
6d18bf1a 359quote_splitmode(struct Client *source_p, const char *charval)
212380e3 360{
361 if(charval)
362 {
363 int newval;
364
365 for (newval = 0; splitmode_values[newval]; newval++)
366 {
367 if(!irccmp(splitmode_values[newval], charval))
368 break;
369 }
370
371 /* OFF */
372 if(newval == 0)
373 {
374 sendto_realops_snomask(SNO_GENERAL, L_ALL,
375 "%s is disabling splitmode", get_oper_name(source_p));
376
377 splitmode = 0;
378 splitchecking = 0;
379
ccfe0e97 380 rb_event_delete(check_splitmode_ev);
f0fbdf6c 381 check_splitmode_ev = NULL;
212380e3 382 }
383 /* ON */
384 else if(newval == 1)
385 {
386 sendto_realops_snomask(SNO_GENERAL, L_ALL,
387 "%s is enabling and activating splitmode",
388 get_oper_name(source_p));
389
390 splitmode = 1;
391 splitchecking = 0;
392
393 /* we might be deactivating an automatic splitmode, so pull the event */
ccfe0e97 394 rb_event_delete(check_splitmode_ev);
f0fbdf6c 395 check_splitmode_ev = NULL;
212380e3 396 }
397 /* AUTO */
398 else if(newval == 2)
399 {
400 sendto_realops_snomask(SNO_GENERAL, L_ALL,
401 "%s is enabling automatic splitmode",
402 get_oper_name(source_p));
403
404 splitchecking = 1;
405 check_splitmode(NULL);
406 }
407 }
408 else
409 /* if we add splitchecking to splitmode*2 we get a unique table to
410 * pull values back out of, splitmode can be four states - but you can
411 * only set to three, which means we cant use the same table --fl_
412 */
5366977b 413 sendto_one_notice(source_p, ":SPLITMODE is currently %s",
212380e3 414 splitmode_status[(splitchecking + (splitmode * 2))]);
415}
416
417/* SET SPLITNUM */
418static void
419quote_splitnum(struct Client *source_p, int newval)
420{
421 if(newval >= 0)
422 {
423 sendto_realops_snomask(SNO_GENERAL, L_ALL,
424 "%s has changed SPLITNUM to %i", source_p->name, newval);
425 split_servers = newval;
426
427 if(splitchecking)
428 check_splitmode(NULL);
429 }
430 else
5366977b 431 sendto_one_notice(source_p, ":SPLITNUM is currently %i", split_servers);
212380e3 432}
433
434/* SET SPLITUSERS */
435static void
436quote_splitusers(struct Client *source_p, int newval)
437{
438 if(newval >= 0)
439 {
440 sendto_realops_snomask(SNO_GENERAL, L_ALL,
441 "%s has changed SPLITUSERS to %i", source_p->name, newval);
442 split_users = newval;
443
444 if(splitchecking)
445 check_splitmode(NULL);
446 }
447 else
5366977b 448 sendto_one_notice(source_p, ":SPLITUSERS is currently %i", split_users);
212380e3 449}
450
451/*
452 * mo_set - SET command handler
453 * set options while running
454 */
455static int
456mo_set(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
457{
458 int newval;
459 int i, n;
460 const char *arg = NULL;
461 const char *intarg = NULL;
462
463 if(parc > 1)
464 {
465 /*
466 * Go through all the commands in set_cmd_table, until one is
467 * matched. I realize strcmp() is more intensive than a numeric
468 * lookup, but at least it's better than a big-ass switch/case
469 * statement.
470 */
471 for (i = 0; set_cmd_table[i].handler; i++)
472 {
473 if(!irccmp(set_cmd_table[i].name, parv[1]))
474 {
475 /*
476 * Command found; now execute the code
477 */
478 n = 2;
479
480 if(set_cmd_table[i].wants_char)
481 {
482 arg = parv[n++];
483 }
484
485 if(set_cmd_table[i].wants_int)
486 {
487 intarg = parv[n++];
488 }
489
490 if((n - 1) > parc)
491 {
5366977b 492 sendto_one_notice(source_p,
493 ":SET %s expects (\"%s%s\") args",
212380e3 494 set_cmd_table[i].name,
495 (set_cmd_table[i].
496 wants_char ? "string, " : ""),
497 (set_cmd_table[i].
498 wants_char ? "int" : ""));
499 return 0;
500 }
501
502 if(parc <= 2)
503 {
504 arg = NULL;
505 intarg = NULL;
506 }
507
508 if(set_cmd_table[i].wants_int && (parc > 2))
509 {
510 if(intarg)
511 {
512 if(!irccmp(intarg, "yes") || !irccmp(intarg, "on"))
513 newval = 1;
514 else if(!irccmp(intarg, "no")
515 || !irccmp(intarg, "off"))
516 newval = 0;
517 else
518 newval = atoi(intarg);
519 }
520 else
521 {
522 newval = -1;
523 }
524
525 if(newval < 0)
526 {
5366977b 527 sendto_one_notice(source_p,
528 ":Value less than 0 illegal for %s",
212380e3 529 set_cmd_table[i].name);
530
531 return 0;
532 }
533 }
534 else
535 newval = -1;
536
537 if(set_cmd_table[i].wants_char)
538 {
539 if(set_cmd_table[i].wants_int)
540 set_cmd_table[i].handler(source_p, arg, newval);
541 else
542 set_cmd_table[i].handler(source_p, arg);
543 return 0;
544 }
545 else
546 {
547 if(set_cmd_table[i].wants_int)
548 set_cmd_table[i].handler(source_p, newval);
549 else
550 /* Just in case someone actually wants a
551 * set function that takes no args.. *shrug* */
552 set_cmd_table[i].handler(source_p);
553 return 0;
554 }
555 }
556 }
557
558 /*
559 * Code here will be executed when a /QUOTE SET command is not
560 * found within set_cmd_table.
561 */
5366977b 562 sendto_one_notice(source_p, ":Variable not found.");
212380e3 563 return 0;
564 }
565
566 list_quote_commands(source_p);
567
568 return 0;
569}