ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_set.c
Revision: 3117
Committed: Fri Mar 7 19:28:54 2014 UTC (12 years, 6 months ago) by michael
Content type: text/x-csrc
File size: 15146 byte(s)
Log Message:
- Removed unused header includes here and there

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

Properties

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