ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/branches/8.2.x/modules/m_set.c
Revision: 3607
Committed: Tue May 20 17:44:33 2014 UTC (9 years, 10 months ago) by michael
Content type: text/x-csrc
File size: 14511 byte(s)
Log Message:
- m_set.c: whitespace changes

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

Properties

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