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