48 |
|
static void mo_set(struct Client *, struct Client *, int, char *[]); |
49 |
|
|
50 |
|
struct Message set_msgtab = { |
51 |
< |
"SET", 0, 0, 0, 0, MFLG_SLOW, 0, |
52 |
< |
{m_unregistered, m_not_oper, m_error, m_ignore, mo_set, m_ignore} |
51 |
> |
"SET", 0, 0, 0, MAXPARA, MFLG_SLOW, 0, |
52 |
> |
{m_unregistered, m_not_oper, rfc1459_command_send_error, m_ignore, mo_set, m_ignore} |
53 |
|
}; |
54 |
|
|
55 |
– |
#ifndef STATIC_MODULES |
55 |
|
void |
56 |
|
_modinit(void) |
57 |
|
{ |
65 |
|
} |
66 |
|
|
67 |
|
const char *_version = "$Revision$"; |
69 |
– |
#endif |
68 |
|
|
69 |
|
/* Structure used for the SET table itself */ |
70 |
|
struct SetStruct |
71 |
|
{ |
72 |
|
const char *name; |
73 |
|
void (*handler)(); |
74 |
< |
int wants_char; /* 1 if it expects (char *, [int]) */ |
75 |
< |
int wants_int; /* 1 if it expects ([char *], int) */ |
74 |
> |
const int wants_char; /* 1 if it expects (char *, [int]) */ |
75 |
> |
const int wants_int; /* 1 if it expects ([char *], int) */ |
76 |
|
/* eg: 0, 1 == only an int arg |
77 |
|
* eg: 1, 1 == char and int args */ |
78 |
|
}; |
81 |
|
static void quote_autoconnall(struct Client *, int); |
82 |
|
static void quote_floodcount(struct Client *, int); |
83 |
|
static void quote_identtimeout(struct Client *, int); |
86 |
– |
static void quote_idletime(struct Client *, int); |
84 |
|
static void quote_log(struct Client *, int); |
85 |
|
static void quote_max(struct Client *, int); |
86 |
|
static void quote_msglocale(struct Client *, char *); |
102 |
|
* -davidt |
103 |
|
*/ |
104 |
|
|
105 |
< |
static struct SetStruct set_cmd_table[] = |
105 |
> |
static const struct SetStruct set_cmd_table[] = |
106 |
|
{ |
107 |
|
/* name function string arg int arg */ |
108 |
|
/* -------------------------------------------------------- */ |
110 |
|
{ "AUTOCONNALL", quote_autoconnall, 0, 1 }, |
111 |
|
{ "FLOODCOUNT", quote_floodcount, 0, 1 }, |
112 |
|
{ "IDENTTIMEOUT", quote_identtimeout, 0, 1 }, |
116 |
– |
{ "IDLETIME", quote_idletime, 0, 1 }, |
113 |
|
{ "LOG", quote_log, 0, 1 }, |
114 |
|
{ "MAX", quote_max, 0, 1 }, |
115 |
|
{ "MSGLOCALE", quote_msglocale, 1, 0 }, |
122 |
|
{ "JFLOODCOUNT", quote_jfloodcount, 0, 1 }, |
123 |
|
{ "REJECTTIME", quote_rejecttime, 0, 1 }, |
124 |
|
/* -------------------------------------------------------- */ |
125 |
< |
{ NULL, NULL, 0, 0 } |
125 |
> |
{ NULL, NULL, 0, 0 } |
126 |
|
}; |
127 |
|
|
128 |
|
/* |
132 |
|
static void |
133 |
|
list_quote_commands(struct Client *source_p) |
134 |
|
{ |
139 |
– |
int i; |
135 |
|
int j = 0; |
136 |
< |
const char *names[4]; |
136 |
> |
const struct SetStruct *tab = set_cmd_table; |
137 |
> |
const char *names[4] = { "", "", "", "" }; |
138 |
|
|
139 |
|
sendto_one(source_p, ":%s NOTICE %s :Available QUOTE SET commands:", |
140 |
|
me.name, source_p->name); |
141 |
|
|
142 |
< |
names[0] = names[1] = names[2] = names[3] = ""; |
147 |
< |
|
148 |
< |
for (i = 0; set_cmd_table[i].handler; i++) |
142 |
> |
for (; tab->handler; ++tab) |
143 |
|
{ |
144 |
< |
names[j++] = set_cmd_table[i].name; |
144 |
> |
names[j++] = tab->name; |
145 |
|
|
146 |
|
if (j > 3) |
147 |
|
{ |
154 |
|
} |
155 |
|
|
156 |
|
} |
157 |
+ |
|
158 |
|
if (j) |
159 |
|
sendto_one(source_p, ":%s NOTICE %s :%s %s %s %s", |
160 |
|
me.name, source_p->name, |
166 |
|
static void |
167 |
|
quote_autoconn(struct Client *source_p, const char *arg, int newval) |
168 |
|
{ |
169 |
< |
set_autoconn(source_p, arg, newval); |
169 |
> |
struct AccessItem *aconf; |
170 |
> |
|
171 |
> |
if (arg != NULL) |
172 |
> |
{ |
173 |
> |
struct ConfItem *conf = find_exact_name_conf(SERVER_TYPE, arg, NULL, NULL); |
174 |
> |
|
175 |
> |
if (conf != NULL) |
176 |
> |
{ |
177 |
> |
aconf = map_to_conf(conf); |
178 |
> |
if (newval) |
179 |
> |
SetConfAllowAutoConn(aconf); |
180 |
> |
else |
181 |
> |
ClearConfAllowAutoConn(aconf); |
182 |
> |
|
183 |
> |
sendto_realops_flags(UMODE_ALL, L_ALL, |
184 |
> |
"%s has changed AUTOCONN for %s to %i", |
185 |
> |
get_oper_name(source_p), arg, newval); |
186 |
> |
sendto_one(source_p, |
187 |
> |
":%s NOTICE %s :AUTOCONN for %s is now set to %i", |
188 |
> |
me.name, source_p->name, arg, newval); |
189 |
> |
} |
190 |
> |
else |
191 |
> |
{ |
192 |
> |
sendto_one(source_p, ":%s NOTICE %s :Can't find %s", |
193 |
> |
me.name, source_p->name, arg); |
194 |
> |
} |
195 |
> |
} |
196 |
> |
else |
197 |
> |
{ |
198 |
> |
sendto_one(source_p, ":%s NOTICE %s :Please specify a server name!", |
199 |
> |
me.name, source_p->name); |
200 |
> |
} |
201 |
|
} |
202 |
|
|
203 |
|
/* SET AUTOCONNALL */ |
207 |
|
if (newval >= 0) |
208 |
|
{ |
209 |
|
sendto_realops_flags(UMODE_ALL, L_ALL, "%s has changed AUTOCONNALL to %i", |
210 |
< |
source_p->name, newval); |
210 |
> |
get_oper_name(source_p), newval); |
211 |
|
|
212 |
|
GlobalSetOptions.autoconn = newval; |
213 |
|
} |
224 |
|
{ |
225 |
|
GlobalSetOptions.floodcount = newval; |
226 |
|
sendto_realops_flags(UMODE_ALL, L_ALL, |
227 |
< |
"%s has changed FLOODCOUNT to %i", source_p->name, |
228 |
< |
GlobalSetOptions.floodcount); |
227 |
> |
"%s has changed FLOODCOUNT to %i", |
228 |
> |
get_oper_name(source_p), GlobalSetOptions.floodcount); |
229 |
|
} |
230 |
|
else |
231 |
|
sendto_one(source_p, ":%s NOTICE %s :FLOODCOUNT is currently %i", |
255 |
|
me.name, source_p->name, GlobalSetOptions.ident_timeout); |
256 |
|
} |
257 |
|
|
232 |
– |
/* SET IDLETIME */ |
233 |
– |
static void |
234 |
– |
quote_idletime(struct Client *source_p, int newval) |
235 |
– |
{ |
236 |
– |
if (newval >= 0) |
237 |
– |
{ |
238 |
– |
if (newval == 0) |
239 |
– |
{ |
240 |
– |
sendto_realops_flags(UMODE_ALL, L_ALL, |
241 |
– |
"%s has disabled idletime checking", |
242 |
– |
source_p->name); |
243 |
– |
GlobalSetOptions.idletime = 0; |
244 |
– |
} |
245 |
– |
else |
246 |
– |
{ |
247 |
– |
sendto_realops_flags(UMODE_ALL, L_ALL, |
248 |
– |
"%s has changed IDLETIME to %i", |
249 |
– |
source_p->name, newval); |
250 |
– |
GlobalSetOptions.idletime = (newval*60); |
251 |
– |
} |
252 |
– |
} |
253 |
– |
else |
254 |
– |
{ |
255 |
– |
sendto_one(source_p, ":%s NOTICE %s :IDLETIME is currently %i", |
256 |
– |
me.name, source_p->name, GlobalSetOptions.idletime/60); |
257 |
– |
} |
258 |
– |
} |
259 |
– |
|
258 |
|
/* SET LOG */ |
259 |
|
static void |
260 |
< |
quote_log( struct Client *source_p, int newval ) |
260 |
> |
quote_log(struct Client *source_p, int newval) |
261 |
|
{ |
264 |
– |
const char *log_level_as_string; |
265 |
– |
|
262 |
|
if (newval >= 0) |
263 |
|
{ |
264 |
|
if (newval < L_WARN) |
269 |
|
} |
270 |
|
|
271 |
|
if (newval > L_DEBUG) |
276 |
– |
{ |
272 |
|
newval = L_DEBUG; |
278 |
– |
} |
273 |
|
|
274 |
|
set_log_level(newval); |
275 |
< |
log_level_as_string = get_log_level_as_string(newval); |
276 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL,"%s has changed LOG level to %i (%s)", |
277 |
< |
source_p->name, newval, log_level_as_string); |
275 |
> |
sendto_realops_flags(UMODE_ALL, L_ALL, "%s has changed LOG level to %i (%s)", |
276 |
> |
get_oper_name(source_p), get_log_level(), |
277 |
> |
get_log_level_as_string(get_log_level())); |
278 |
|
} |
279 |
|
else |
286 |
– |
{ |
280 |
|
sendto_one(source_p, ":%s NOTICE %s :LOG level is currently %i (%s)", |
281 |
|
me.name, source_p->name, get_log_level(), |
282 |
|
get_log_level_as_string(get_log_level())); |
290 |
– |
} |
283 |
|
} |
284 |
|
|
285 |
|
/* SET MAX */ |
286 |
|
static void |
287 |
< |
quote_max (struct Client *source_p, int newval) |
287 |
> |
quote_max(struct Client *source_p, int newval) |
288 |
|
{ |
289 |
|
if (newval > 0) |
290 |
|
{ |
294 |
|
{ |
295 |
|
sendto_one(source_p, |
296 |
|
":%s NOTICE %s :You cannot set MAXCLIENTS to > %d, restoring to %d", |
297 |
< |
me.name, source_p->name, MAXCLIENTS_MAX); |
297 |
> |
me.name, source_p->name, MAXCLIENTS_MAX, ServerInfo.max_clients); |
298 |
|
return; |
299 |
|
} |
300 |
|
|
309 |
|
ServerInfo.max_clients = newval; |
310 |
|
|
311 |
|
sendto_realops_flags(UMODE_ALL, L_ALL, |
312 |
< |
"%s!%s@%s set new MAXCLIENTS to %d (%d current)", |
313 |
< |
source_p->name, source_p->username, source_p->host, |
322 |
< |
ServerInfo.max_clients, Count.local); |
312 |
> |
"%s set new MAXCLIENTS to %d (%d current)", |
313 |
> |
get_oper_name(source_p), ServerInfo.max_clients, Count.local); |
314 |
|
} |
315 |
|
else |
316 |
|
sendto_one(source_p, ":%s NOTICE %s :Current MAXCLIENTS = %d (%d)", |
319 |
|
|
320 |
|
/* SET MSGLOCALE */ |
321 |
|
static void |
322 |
< |
quote_msglocale( struct Client *source_p, char *locale ) |
322 |
> |
quote_msglocale(struct Client *source_p, char *locale) |
323 |
|
{ |
324 |
|
if (locale != NULL) |
325 |
|
{ |
335 |
|
|
336 |
|
/* SET SPAMNUM */ |
337 |
|
static void |
338 |
< |
quote_spamnum( struct Client *source_p, int newval ) |
338 |
> |
quote_spamnum(struct Client *source_p, int newval) |
339 |
|
{ |
340 |
|
if (newval >= 0) |
341 |
|
{ |
348 |
|
} |
349 |
|
|
350 |
|
GlobalSetOptions.spam_num = IRCD_MAX(newval, MIN_SPAM_NUM); |
351 |
< |
|
352 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL,"%s has changed SPAMNUM to %i", |
362 |
< |
source_p->name, GlobalSetOptions.spam_num); |
351 |
> |
sendto_realops_flags(UMODE_ALL, L_ALL, "%s has changed SPAMNUM to %i", |
352 |
> |
get_oper_name(source_p), GlobalSetOptions.spam_num); |
353 |
|
} |
354 |
|
else |
355 |
|
sendto_one(source_p, ":%s NOTICE %s :SPAMNUM is currently %i", |
356 |
< |
me.name, |
367 |
< |
source_p->name, GlobalSetOptions.spam_num); |
356 |
> |
me.name, source_p->name, GlobalSetOptions.spam_num); |
357 |
|
} |
358 |
|
|
359 |
|
/* SET SPAMTIME */ |
360 |
|
static void |
361 |
< |
quote_spamtime( struct Client *source_p, int newval ) |
361 |
> |
quote_spamtime(struct Client *source_p, int newval) |
362 |
|
{ |
363 |
|
if (newval > 0) |
364 |
|
{ |
365 |
|
GlobalSetOptions.spam_time = IRCD_MAX(newval, MIN_SPAM_TIME); |
366 |
|
sendto_realops_flags(UMODE_ALL, L_ALL, "%s has changed SPAMTIME to %i", |
367 |
< |
source_p->name, GlobalSetOptions.spam_time); |
367 |
> |
get_oper_name(source_p), GlobalSetOptions.spam_time); |
368 |
|
} |
369 |
|
else |
370 |
|
sendto_one(source_p, ":%s NOTICE %s :SPAMTIME is currently %i", |
371 |
< |
me.name, |
383 |
< |
source_p->name, GlobalSetOptions.spam_time); |
371 |
> |
me.name, source_p->name, GlobalSetOptions.spam_time); |
372 |
|
} |
373 |
|
|
374 |
|
/* this table is what splitmode may be set to */ |
398 |
|
{ |
399 |
|
int newval; |
400 |
|
|
401 |
< |
for (newval = 0; splitmode_values[newval]; newval++) |
414 |
< |
{ |
401 |
> |
for (newval = 0; splitmode_values[newval]; ++newval) |
402 |
|
if (irccmp(splitmode_values[newval], charval) == 0) |
403 |
|
break; |
417 |
– |
} |
404 |
|
|
405 |
|
/* OFF */ |
406 |
|
if (newval == 0) |
445 |
|
*/ |
446 |
|
sendto_one(source_p, ":%s NOTICE %s :SPLITMODE is currently %s", |
447 |
|
me.name, source_p->name, |
448 |
< |
splitmode_status[(splitchecking + (splitmode*2))]); |
448 |
> |
splitmode_status[(splitchecking + (splitmode * 2))]); |
449 |
|
} |
450 |
|
|
451 |
|
/* SET SPLITNUM */ |
456 |
|
{ |
457 |
|
sendto_realops_flags(UMODE_ALL, L_ALL, |
458 |
|
"%s has changed SPLITNUM to %i", |
459 |
< |
source_p->name, newval); |
459 |
> |
get_oper_name(source_p), newval); |
460 |
|
split_servers = newval; |
461 |
|
|
462 |
|
if (splitchecking) |
475 |
|
{ |
476 |
|
sendto_realops_flags(UMODE_ALL, L_ALL, |
477 |
|
"%s has changed SPLITUSERS to %i", |
478 |
< |
source_p->name, newval); |
478 |
> |
get_oper_name(source_p), newval); |
479 |
|
split_users = newval; |
480 |
|
|
481 |
|
if (splitchecking) |
494 |
|
{ |
495 |
|
sendto_realops_flags(UMODE_ALL, L_ALL, |
496 |
|
"%s has changed JFLOODTIME to %i", |
497 |
< |
source_p->name, newval); |
497 |
> |
get_oper_name(source_p), newval); |
498 |
|
GlobalSetOptions.joinfloodtime = newval; |
499 |
|
} |
500 |
|
else |
510 |
|
{ |
511 |
|
sendto_realops_flags(UMODE_ALL, L_ALL, |
512 |
|
"%s has changed JFLOODCOUNT to %i", |
513 |
< |
source_p->name, newval); |
513 |
> |
get_oper_name(source_p), newval); |
514 |
|
GlobalSetOptions.joinfloodcount = newval; |
515 |
|
} |
516 |
|
else |
526 |
|
{ |
527 |
|
sendto_realops_flags(UMODE_ALL, L_ALL, |
528 |
|
"%s has changed REJECTTIME to %i seconds", |
529 |
< |
source_p->name, newval); |
529 |
> |
get_oper_name(source_p), newval); |
530 |
|
GlobalSetOptions.rejecttime = newval; |
531 |
|
} |
532 |
|
else |
542 |
|
mo_set(struct Client *client_p, struct Client *source_p, |
543 |
|
int parc, char *parv[]) |
544 |
|
{ |
559 |
– |
int i; |
545 |
|
int n; |
546 |
|
int newval; |
547 |
|
const char *arg = NULL; |
548 |
|
const char *intarg = NULL; |
549 |
+ |
const struct SetStruct *tab = set_cmd_table; |
550 |
|
|
551 |
|
if (parc > 1) |
552 |
|
{ |
553 |
< |
/* Go through all the commands in set_cmd_table, until one is |
554 |
< |
* matched. I realize strcmp() is more intensive than a numeric |
555 |
< |
* lookup, but at least it's better than a big-ass switch/case |
570 |
< |
* statement. |
553 |
> |
/* |
554 |
> |
* Go through all the commands in set_cmd_table, until one is |
555 |
> |
* matched. |
556 |
|
*/ |
557 |
< |
for (i = 0; set_cmd_table[i].handler; i++) |
557 |
> |
for (; tab->handler; ++tab) |
558 |
|
{ |
559 |
< |
if (irccmp(set_cmd_table[i].name, parv[1]) == 0) |
559 |
> |
if (!irccmp(tab->name, parv[1])) |
560 |
|
{ |
561 |
|
/* |
562 |
|
* Command found; now execute the code |
563 |
|
*/ |
564 |
|
n = 2; |
565 |
|
|
566 |
< |
if (set_cmd_table[i].wants_char) |
582 |
< |
{ |
566 |
> |
if (tab->wants_char) |
567 |
|
arg = parv[n++]; |
584 |
– |
} |
568 |
|
|
569 |
< |
if (set_cmd_table[i].wants_int) |
587 |
< |
{ |
569 |
> |
if (tab->wants_int) |
570 |
|
intarg = parv[n++]; |
589 |
– |
} |
571 |
|
|
572 |
|
if ((n - 1) > parc) |
573 |
|
{ |
574 |
|
if (parc > 2) |
575 |
|
sendto_one(source_p, |
576 |
|
":%s NOTICE %s :SET %s expects (\"%s%s\") args", |
577 |
< |
me.name, source_p->name, set_cmd_table[i].name, |
578 |
< |
(set_cmd_table[i].wants_char ? "string, " : ""), |
579 |
< |
(set_cmd_table[i].wants_char ? "int" : "") |
599 |
< |
); |
577 |
> |
me.name, source_p->name, tab->name, |
578 |
> |
(tab->wants_char ? "string, " : ""), |
579 |
> |
(tab->wants_char ? "int" : "")); |
580 |
|
} |
581 |
|
|
582 |
|
if (parc <= 2) |
585 |
|
intarg = NULL; |
586 |
|
} |
587 |
|
|
588 |
< |
if (!strcmp(set_cmd_table[i].name, "AUTOCONN") && (parc < 4)) |
588 |
> |
if (!strcmp(tab->name, "AUTOCONN") && (parc < 4)) |
589 |
|
{ |
590 |
|
sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), |
591 |
|
me.name, source_p->name, "SET"); |
592 |
|
return; |
593 |
|
} |
594 |
|
|
595 |
< |
if (set_cmd_table[i].wants_int && (parc > 2)) |
595 |
> |
if (tab->wants_int && (parc > 2)) |
596 |
|
{ |
597 |
|
if (intarg) |
598 |
|
{ |
613 |
|
sendto_one(source_p, |
614 |
|
":%s NOTICE %s :Value less than 0 illegal for %s", |
615 |
|
me.name, source_p->name, |
616 |
< |
set_cmd_table[i].name); |
616 |
> |
tab->name); |
617 |
|
|
618 |
|
return; |
619 |
|
} |
621 |
|
else |
622 |
|
newval = -1; |
623 |
|
|
624 |
< |
if (set_cmd_table[i].wants_char) |
624 |
> |
if (tab->wants_char) |
625 |
|
{ |
626 |
< |
if (set_cmd_table[i].wants_int) |
627 |
< |
set_cmd_table[i].handler(source_p, arg, newval); |
626 |
> |
if (tab->wants_int) |
627 |
> |
tab->handler(source_p, arg, newval); |
628 |
|
else |
629 |
< |
set_cmd_table[i].handler(source_p, arg); |
629 |
> |
tab->handler(source_p, arg); |
630 |
|
return; |
631 |
|
} |
632 |
|
else |
633 |
|
{ |
634 |
< |
if (set_cmd_table[i].wants_int) |
635 |
< |
set_cmd_table[i].handler(source_p, newval); |
634 |
> |
if (tab->wants_int) |
635 |
> |
tab->handler(source_p, newval); |
636 |
|
else |
637 |
|
/* Just in case someone actually wants a |
638 |
|
* set function that takes no args.. *shrug* */ |
639 |
< |
set_cmd_table[i].handler(source_p); |
639 |
> |
tab->handler(source_p); |
640 |
|
return; |
641 |
|
} |
642 |
|
} |
653 |
|
|
654 |
|
list_quote_commands(source_p); |
655 |
|
} |
676 |
– |
|