ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_set.c
Revision: 1997
Committed: Sat May 11 17:35:07 2013 UTC (12 years, 3 months ago) by michael
Content type: text/x-csrc
File size: 15933 byte(s)
Log Message:
- Mostly style cleanups & whitespace changes

File Contents

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

Properties

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