ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_set.c
Revision: 3347
Committed: Sun Apr 20 14:03:06 2014 UTC (9 years, 11 months ago) by michael
Content type: text/x-csrc
File size: 15063 byte(s)
Log Message:
- Moved files:
  s_user.c -> user.c
  s_misc.c -> misc.c
  s_serv.c -> server.c

File Contents

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

Properties

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