00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "stdinc.h"
00028 #include "handlers.h"
00029 #include "client.h"
00030 #include "event.h"
00031 #include "irc_string.h"
00032 #include "ircd.h"
00033 #include "numeric.h"
00034 #include "fdlist.h"
00035 #include "s_bsd.h"
00036 #include "s_serv.h"
00037 #include "send.h"
00038 #include "common.h"
00039 #include "channel.h"
00040 #include "s_log.h"
00041 #include "s_conf.h"
00042 #include "msg.h"
00043 #include "parse.h"
00044 #include "modules.h"
00045 #include "s_user.h"
00046
00047
00048 static void mo_set(struct Client *, struct Client *, int, char *[]);
00049
00050 struct Message set_msgtab = {
00051 "SET", 0, 0, 0, 0, MFLG_SLOW, 0,
00052 {m_unregistered, m_not_oper, m_error, m_ignore, mo_set, m_ignore}
00053 };
00054
00055 #ifndef STATIC_MODULES
00056 void
00057 _modinit(void)
00058 {
00059 mod_add_cmd(&set_msgtab);
00060 }
00061
00062 void
00063 _moddeinit(void)
00064 {
00065 mod_del_cmd(&set_msgtab);
00066 }
00067
00068 const char *_version = "$Revision: 646 $";
00069 #endif
00070
00071
00072 struct SetStruct
00073 {
00074 const char *name;
00075 void (*handler)();
00076 int wants_char;
00077 int wants_int;
00078
00079
00080 };
00081
00082 static void quote_autoconn(struct Client *, const char *, int);
00083 static void quote_autoconnall(struct Client *, int);
00084 static void quote_floodcount(struct Client *, int);
00085 static void quote_identtimeout(struct Client *, int);
00086 static void quote_idletime(struct Client *, int);
00087 static void quote_log(struct Client *, int);
00088 static void quote_max(struct Client *, int);
00089 static void quote_msglocale(struct Client *, char *);
00090 static void quote_spamnum(struct Client *, int);
00091 static void quote_spamtime(struct Client *, int);
00092 static void quote_splitmode(struct Client *, char *);
00093 static void quote_splitnum(struct Client *, int);
00094 static void quote_splitusers(struct Client *, int);
00095 static void list_quote_commands(struct Client *);
00096 static void quote_jfloodtime(struct Client *, int);
00097 static void quote_jfloodcount(struct Client *, int);
00098 static void quote_rejecttime(struct Client *, int);
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108 static struct SetStruct set_cmd_table[] =
00109 {
00110
00111
00112 { "AUTOCONN", quote_autoconn, 1, 1 },
00113 { "AUTOCONNALL", quote_autoconnall, 0, 1 },
00114 { "FLOODCOUNT", quote_floodcount, 0, 1 },
00115 { "IDENTTIMEOUT", quote_identtimeout, 0, 1 },
00116 { "IDLETIME", quote_idletime, 0, 1 },
00117 { "LOG", quote_log, 0, 1 },
00118 { "MAX", quote_max, 0, 1 },
00119 { "MSGLOCALE", quote_msglocale, 1, 0 },
00120 { "SPAMNUM", quote_spamnum, 0, 1 },
00121 { "SPAMTIME", quote_spamtime, 0, 1 },
00122 { "SPLITMODE", quote_splitmode, 1, 0 },
00123 { "SPLITNUM", quote_splitnum, 0, 1 },
00124 { "SPLITUSERS", quote_splitusers, 0, 1 },
00125 { "JFLOODTIME", quote_jfloodtime, 0, 1 },
00126 { "JFLOODCOUNT", quote_jfloodcount, 0, 1 },
00127 { "REJECTTIME", quote_rejecttime, 0, 1 },
00128
00129 { NULL, NULL, 0, 0 }
00130 };
00131
00132
00133
00134
00135
00136 static void
00137 list_quote_commands(struct Client *source_p)
00138 {
00139 int i;
00140 int j = 0;
00141 const char *names[4];
00142
00143 sendto_one(source_p, ":%s NOTICE %s :Available QUOTE SET commands:",
00144 me.name, source_p->name);
00145
00146 names[0] = names[1] = names[2] = names[3] = "";
00147
00148 for (i = 0; set_cmd_table[i].handler; i++)
00149 {
00150 names[j++] = set_cmd_table[i].name;
00151
00152 if (j > 3)
00153 {
00154 sendto_one(source_p, ":%s NOTICE %s :%s %s %s %s",
00155 me.name, source_p->name,
00156 names[0], names[1],
00157 names[2], names[3]);
00158 j = 0;
00159 names[0] = names[1] = names[2] = names[3] = "";
00160 }
00161
00162 }
00163 if (j)
00164 sendto_one(source_p, ":%s NOTICE %s :%s %s %s %s",
00165 me.name, source_p->name,
00166 names[0], names[1],
00167 names[2], names[3]);
00168 }
00169
00170
00171 static void
00172 quote_autoconn(struct Client *source_p, const char *arg, int newval)
00173 {
00174 set_autoconn(source_p, arg, newval);
00175 }
00176
00177
00178 static void
00179 quote_autoconnall(struct Client *source_p, int newval)
00180 {
00181 if (newval >= 0)
00182 {
00183 sendto_realops_flags(UMODE_ALL, L_ALL, "%s has changed AUTOCONNALL to %i",
00184 source_p->name, newval);
00185
00186 GlobalSetOptions.autoconn = newval;
00187 }
00188 else
00189 sendto_one(source_p, ":%s NOTICE %s :AUTOCONNALL is currently %i",
00190 me.name, source_p->name, GlobalSetOptions.autoconn);
00191 }
00192
00193
00194 static void
00195 quote_floodcount(struct Client *source_p, int newval)
00196 {
00197 if (newval >= 0)
00198 {
00199 GlobalSetOptions.floodcount = newval;
00200 sendto_realops_flags(UMODE_ALL, L_ALL,
00201 "%s has changed FLOODCOUNT to %i", source_p->name,
00202 GlobalSetOptions.floodcount);
00203 }
00204 else
00205 sendto_one(source_p, ":%s NOTICE %s :FLOODCOUNT is currently %i",
00206 me.name, source_p->name, GlobalSetOptions.floodcount);
00207 }
00208
00209
00210 static void
00211 quote_identtimeout(struct Client *source_p, int newval)
00212 {
00213 if (!IsAdmin(source_p))
00214 {
00215 sendto_one(source_p, form_str(ERR_NOPRIVS),
00216 me.name, source_p->name, "set");
00217 return;
00218 }
00219
00220 if (newval > 0)
00221 {
00222 sendto_realops_flags(UMODE_ALL, L_ALL,
00223 "%s has changed IDENTTIMEOUT to %d",
00224 get_oper_name(source_p), newval);
00225 GlobalSetOptions.ident_timeout = newval;
00226 }
00227 else
00228 sendto_one(source_p, ":%s NOTICE %s :IDENTTIMEOUT is currently %d",
00229 me.name, source_p->name, GlobalSetOptions.ident_timeout);
00230 }
00231
00232
00233 static void
00234 quote_idletime(struct Client *source_p, int newval)
00235 {
00236 if (newval >= 0)
00237 {
00238 if (newval == 0)
00239 {
00240 sendto_realops_flags(UMODE_ALL, L_ALL,
00241 "%s has disabled idletime checking",
00242 source_p->name);
00243 GlobalSetOptions.idletime = 0;
00244 }
00245 else
00246 {
00247 sendto_realops_flags(UMODE_ALL, L_ALL,
00248 "%s has changed IDLETIME to %i",
00249 source_p->name, newval);
00250 GlobalSetOptions.idletime = (newval*60);
00251 }
00252 }
00253 else
00254 {
00255 sendto_one(source_p, ":%s NOTICE %s :IDLETIME is currently %i",
00256 me.name, source_p->name, GlobalSetOptions.idletime/60);
00257 }
00258 }
00259
00260
00261 static void
00262 quote_log( struct Client *source_p, int newval )
00263 {
00264 const char *log_level_as_string;
00265
00266 if (newval >= 0)
00267 {
00268 if (newval < L_WARN)
00269 {
00270 sendto_one(source_p, ":%s NOTICE %s :LOG must be > %d (L_WARN)",
00271 me.name, source_p->name, L_WARN);
00272 return;
00273 }
00274
00275 if (newval > L_DEBUG)
00276 {
00277 newval = L_DEBUG;
00278 }
00279
00280 set_log_level(newval);
00281 log_level_as_string = get_log_level_as_string(newval);
00282 sendto_realops_flags(UMODE_ALL, L_ALL,"%s has changed LOG level to %i (%s)",
00283 source_p->name, newval, log_level_as_string);
00284 }
00285 else
00286 {
00287 sendto_one(source_p, ":%s NOTICE %s :LOG level is currently %i (%s)",
00288 me.name, source_p->name, get_log_level(),
00289 get_log_level_as_string(get_log_level()));
00290 }
00291 }
00292
00293
00294 static void
00295 quote_max (struct Client *source_p, int newval)
00296 {
00297 if (newval > 0)
00298 {
00299 recalc_fdlimit(NULL);
00300
00301 if (newval > MAXCLIENTS_MAX)
00302 {
00303 sendto_one(source_p,
00304 ":%s NOTICE %s :You cannot set MAXCLIENTS to > %d, restoring to %d",
00305 me.name, source_p->name, MAXCLIENTS_MAX);
00306 return;
00307 }
00308
00309 if (newval < MAXCLIENTS_MIN)
00310 {
00311 sendto_one(source_p,
00312 ":%s NOTICE %s :You cannot set MAXCLIENTS to < %d, restoring to %d",
00313 me.name, source_p->name, MAXCLIENTS_MIN, ServerInfo.max_clients);
00314 return;
00315 }
00316
00317 ServerInfo.max_clients = newval;
00318
00319 sendto_realops_flags(UMODE_ALL, L_ALL,
00320 "%s!%s@%s set new MAXCLIENTS to %d (%d current)",
00321 source_p->name, source_p->username, source_p->host,
00322 ServerInfo.max_clients, Count.local);
00323 }
00324 else
00325 sendto_one(source_p, ":%s NOTICE %s :Current MAXCLIENTS = %d (%d)",
00326 me.name, source_p->name, ServerInfo.max_clients, Count.local);
00327 }
00328
00329
00330 static void
00331 quote_msglocale( struct Client *source_p, char *locale )
00332 {
00333 if (locale != NULL)
00334 {
00335 set_locale(locale);
00336 rebuild_isupport_message_line();
00337 sendto_one(source_p, ":%s NOTICE %s :Set MSGLOCALE to '%s'",
00338 me.name, source_p->name, get_locale());
00339 }
00340 else
00341 sendto_one(source_p, ":%s NOTICE %s :MSGLOCALE is currently '%s'",
00342 me.name, source_p->name, get_locale());
00343 }
00344
00345
00346 static void
00347 quote_spamnum( struct Client *source_p, int newval )
00348 {
00349 if (newval >= 0)
00350 {
00351 if (newval == 0)
00352 {
00353 sendto_realops_flags(UMODE_ALL, L_ALL,
00354 "%s has disabled ANTI_SPAMBOT", source_p->name);
00355 GlobalSetOptions.spam_num = newval;
00356 return;
00357 }
00358
00359 GlobalSetOptions.spam_num = IRCD_MAX(newval, MIN_SPAM_NUM);
00360
00361 sendto_realops_flags(UMODE_ALL, L_ALL,"%s has changed SPAMNUM to %i",
00362 source_p->name, GlobalSetOptions.spam_num);
00363 }
00364 else
00365 sendto_one(source_p, ":%s NOTICE %s :SPAMNUM is currently %i",
00366 me.name,
00367 source_p->name, GlobalSetOptions.spam_num);
00368 }
00369
00370
00371 static void
00372 quote_spamtime( struct Client *source_p, int newval )
00373 {
00374 if (newval > 0)
00375 {
00376 GlobalSetOptions.spam_time = IRCD_MAX(newval, MIN_SPAM_TIME);
00377 sendto_realops_flags(UMODE_ALL, L_ALL, "%s has changed SPAMTIME to %i",
00378 source_p->name, GlobalSetOptions.spam_time);
00379 }
00380 else
00381 sendto_one(source_p, ":%s NOTICE %s :SPAMTIME is currently %i",
00382 me.name,
00383 source_p->name, GlobalSetOptions.spam_time);
00384 }
00385
00386
00387 static const char *splitmode_values[] =
00388 {
00389 "OFF",
00390 "ON",
00391 "AUTO",
00392 NULL
00393 };
00394
00395
00396 static const char *splitmode_status[] =
00397 {
00398 "OFF",
00399 "AUTO (OFF)",
00400 "ON",
00401 "AUTO (ON)",
00402 NULL
00403 };
00404
00405
00406 static void
00407 quote_splitmode(struct Client *source_p, char *charval)
00408 {
00409 if (charval)
00410 {
00411 int newval;
00412
00413 for (newval = 0; splitmode_values[newval]; newval++)
00414 {
00415 if (irccmp(splitmode_values[newval], charval) == 0)
00416 break;
00417 }
00418
00419
00420 if (newval == 0)
00421 {
00422 sendto_realops_flags(UMODE_ALL, L_ALL,
00423 "%s is disabling splitmode",
00424 get_oper_name(source_p));
00425
00426 splitmode = 0;
00427 splitchecking = 0;
00428
00429 eventDelete(check_splitmode, NULL);
00430 }
00431
00432 else if (newval == 1)
00433 {
00434 sendto_realops_flags(UMODE_ALL, L_ALL,
00435 "%s is enabling and activating splitmode",
00436 get_oper_name(source_p));
00437
00438 splitmode = 1;
00439 splitchecking = 0;
00440
00441
00442 eventDelete(check_splitmode, NULL);
00443 }
00444
00445 else if (newval == 2)
00446 {
00447 sendto_realops_flags(UMODE_ALL, L_ALL,
00448 "%s is enabling automatic splitmode",
00449 get_oper_name(source_p));
00450
00451 splitchecking = 1;
00452 check_splitmode(NULL);
00453 }
00454 }
00455 else
00456
00457
00458
00459
00460 sendto_one(source_p, ":%s NOTICE %s :SPLITMODE is currently %s",
00461 me.name, source_p->name,
00462 splitmode_status[(splitchecking + (splitmode*2))]);
00463 }
00464
00465
00466 static void
00467 quote_splitnum(struct Client *source_p, int newval)
00468 {
00469 if (newval >= 0)
00470 {
00471 sendto_realops_flags(UMODE_ALL, L_ALL,
00472 "%s has changed SPLITNUM to %i",
00473 source_p->name, newval);
00474 split_servers = newval;
00475
00476 if (splitchecking)
00477 check_splitmode(NULL);
00478 }
00479 else
00480 sendto_one(source_p, ":%s NOTICE %s :SPLITNUM is currently %i",
00481 me.name, source_p->name, split_servers);
00482 }
00483
00484
00485 static void
00486 quote_splitusers(struct Client *source_p, int newval)
00487 {
00488 if (newval >= 0)
00489 {
00490 sendto_realops_flags(UMODE_ALL, L_ALL,
00491 "%s has changed SPLITUSERS to %i",
00492 source_p->name, newval);
00493 split_users = newval;
00494
00495 if (splitchecking)
00496 check_splitmode(NULL);
00497 }
00498 else
00499 sendto_one(source_p, ":%s NOTICE %s :SPLITUSERS is currently %i",
00500 me.name, source_p->name, split_users);
00501 }
00502
00503
00504 static void
00505 quote_jfloodtime(struct Client *source_p, int newval)
00506 {
00507 if (newval >= 0)
00508 {
00509 sendto_realops_flags(UMODE_ALL, L_ALL,
00510 "%s has changed JFLOODTIME to %i",
00511 source_p->name, newval);
00512 GlobalSetOptions.joinfloodtime = newval;
00513 }
00514 else
00515 sendto_one(source_p, ":%s NOTICE %s :JFLOODTIME is currently %i",
00516 me.name, source_p->name, GlobalSetOptions.joinfloodtime);
00517 }
00518
00519
00520 static void
00521 quote_jfloodcount(struct Client *source_p, int newval)
00522 {
00523 if (newval >= 0)
00524 {
00525 sendto_realops_flags(UMODE_ALL, L_ALL,
00526 "%s has changed JFLOODCOUNT to %i",
00527 source_p->name, newval);
00528 GlobalSetOptions.joinfloodcount = newval;
00529 }
00530 else
00531 sendto_one(source_p, ":%s NOTICE %s :JFLOODCOUNT is currently %i",
00532 me.name, source_p->name, GlobalSetOptions.joinfloodcount);
00533 }
00534
00535
00536 static void
00537 quote_rejecttime(struct Client *source_p, int newval)
00538 {
00539 if (newval >= 0)
00540 {
00541 sendto_realops_flags(UMODE_ALL, L_ALL,
00542 "%s has changed REJECTTIME to %i seconds",
00543 source_p->name, newval);
00544 GlobalSetOptions.rejecttime = newval;
00545 }
00546 else
00547 sendto_one(source_p, ":%s NOTICE %s :REJECTTIME is currently %i seconds",
00548 me.name, source_p->name, GlobalSetOptions.rejecttime);
00549 }
00550
00551
00552
00553
00554
00555 static void
00556 mo_set(struct Client *client_p, struct Client *source_p,
00557 int parc, char *parv[])
00558 {
00559 int i;
00560 int n;
00561 int newval;
00562 const char *arg = NULL;
00563 const char *intarg = NULL;
00564
00565 if (parc > 1)
00566 {
00567
00568
00569
00570
00571
00572 for (i = 0; set_cmd_table[i].handler; i++)
00573 {
00574 if (irccmp(set_cmd_table[i].name, parv[1]) == 0)
00575 {
00576
00577
00578
00579 n = 2;
00580
00581 if (set_cmd_table[i].wants_char)
00582 {
00583 arg = parv[n++];
00584 }
00585
00586 if (set_cmd_table[i].wants_int)
00587 {
00588 intarg = parv[n++];
00589 }
00590
00591 if ((n - 1) > parc)
00592 {
00593 if (parc > 2)
00594 sendto_one(source_p,
00595 ":%s NOTICE %s :SET %s expects (\"%s%s\") args",
00596 me.name, source_p->name, set_cmd_table[i].name,
00597 (set_cmd_table[i].wants_char ? "string, " : ""),
00598 (set_cmd_table[i].wants_char ? "int" : "")
00599 );
00600 }
00601
00602 if (parc <= 2)
00603 {
00604 arg = NULL;
00605 intarg = NULL;
00606 }
00607
00608 if (!strcmp(set_cmd_table[i].name, "AUTOCONN") && (parc < 4))
00609 {
00610 sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
00611 me.name, source_p->name, "SET");
00612 return;
00613 }
00614
00615 if (set_cmd_table[i].wants_int && (parc > 2))
00616 {
00617 if (intarg)
00618 {
00619 if (irccmp(intarg, "yes") == 0 || irccmp(intarg, "on") == 0)
00620 newval = 1;
00621 else if (irccmp(intarg, "no") == 0|| irccmp(intarg, "off") == 0)
00622 newval = 0;
00623 else
00624 newval = atoi(intarg);
00625 }
00626 else
00627 {
00628 newval = -1;
00629 }
00630
00631 if (newval < 0)
00632 {
00633 sendto_one(source_p,
00634 ":%s NOTICE %s :Value less than 0 illegal for %s",
00635 me.name, source_p->name,
00636 set_cmd_table[i].name);
00637
00638 return;
00639 }
00640 }
00641 else
00642 newval = -1;
00643
00644 if (set_cmd_table[i].wants_char)
00645 {
00646 if (set_cmd_table[i].wants_int)
00647 set_cmd_table[i].handler(source_p, arg, newval);
00648 else
00649 set_cmd_table[i].handler(source_p, arg);
00650 return;
00651 }
00652 else
00653 {
00654 if (set_cmd_table[i].wants_int)
00655 set_cmd_table[i].handler(source_p, newval);
00656 else
00657
00658
00659 set_cmd_table[i].handler(source_p);
00660 return;
00661 }
00662 }
00663 }
00664
00665
00666
00667
00668
00669 sendto_one(source_p, ":%s NOTICE %s :Variable not found.",
00670 me.name, source_p->name);
00671 return;
00672 }
00673
00674 list_quote_commands(source_p);
00675 }
00676