ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_set.c
Revision: 7896
Committed: Thu Nov 24 10:09:46 2016 UTC (7 years, 4 months ago) by michael
Content type: text/x-csrc
File size: 12262 byte(s)
Log Message:
- m_set.c: replace mixture of %d/%i conversion specifiers with proper ones

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 *
4 * Copyright (c) 1997-2016 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
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 = connect_find(arg, NULL, irccmp);
47
48 if (conf)
49 {
50 if (newval)
51 SetConfAllowAutoConn(conf);
52 else
53 ClearConfAllowAutoConn(conf);
54
55 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
56 "%s has changed AUTOCONN for %s to %i",
57 get_oper_name(source_p), conf->name, newval);
58 sendto_one_notice(source_p, &me, ":AUTOCONN for %s is now set to %i",
59 conf->name, 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 GlobalSetOptions.autoconn = newval;
75 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
76 "%s has changed AUTOCONNALL to %u",
77 get_oper_name(source_p), GlobalSetOptions.autoconn);
78 }
79 else
80 sendto_one_notice(source_p, &me, ":AUTOCONNALL is currently %u",
81 GlobalSetOptions.autoconn);
82 }
83
84 /* SET FLOODCOUNT */
85 static void
86 quote_floodcount(struct Client *source_p, const char *arg, int newval)
87 {
88 if (newval >= 0)
89 {
90 GlobalSetOptions.floodcount = newval;
91 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
92 "%s has changed FLOODCOUNT to %u",
93 get_oper_name(source_p), GlobalSetOptions.floodcount);
94 }
95 else
96 sendto_one_notice(source_p, &me, ":FLOODCOUNT is currently %u",
97 GlobalSetOptions.floodcount);
98 }
99
100 /* SET FLOODTIME */
101 static void
102 quote_floodtime(struct Client *source_p, const char *arg, int newval)
103 {
104 if (newval >= 0)
105 {
106 GlobalSetOptions.floodtime = newval;
107 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
108 "%s has changed FLOODTIME to %u",
109 get_oper_name(source_p), GlobalSetOptions.floodtime);
110 }
111 else
112 sendto_one_notice(source_p, &me, ":FLOODTIME is currently %u",
113 GlobalSetOptions.floodtime);
114 }
115
116 /* SET IDENTTIMEOUT */
117 static void
118 quote_identtimeout(struct Client *source_p, const char *arg, int newval)
119 {
120 if (!HasUMode(source_p, UMODE_ADMIN))
121 {
122 sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "set");
123 return;
124 }
125
126 if (newval > 0)
127 {
128 GlobalSetOptions.ident_timeout = newval;
129 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
130 "%s has changed IDENTTIMEOUT to %u",
131 get_oper_name(source_p), GlobalSetOptions.ident_timeout);
132 }
133 else
134 sendto_one_notice(source_p, &me, ":IDENTTIMEOUT is currently %u",
135 GlobalSetOptions.ident_timeout);
136 }
137
138 /* SET MAX */
139 static void
140 quote_max(struct Client *source_p, const char *arg, int newval)
141 {
142 if (newval > 0)
143 {
144 if (newval > MAXCLIENTS_MAX)
145 {
146 sendto_one_notice(source_p, &me, ":You cannot set MAXCLIENTS to > %d, restoring to %u",
147 MAXCLIENTS_MAX, GlobalSetOptions.maxclients);
148 return;
149 }
150
151 if (newval < MAXCLIENTS_MIN)
152 {
153 sendto_one_notice(source_p, &me, ":You cannot set MAXCLIENTS to < %d, restoring to %u",
154 MAXCLIENTS_MIN, GlobalSetOptions.maxclients);
155 return;
156 }
157
158 GlobalSetOptions.maxclients = newval;
159 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
160 "%s set new MAXCLIENTS to %u (%u current)",
161 get_oper_name(source_p), GlobalSetOptions.maxclients, Count.local);
162 }
163 else
164 sendto_one_notice(source_p, &me, ":Current MAXCLIENTS = %u (%u)",
165 GlobalSetOptions.maxclients, Count.local);
166 }
167
168 /* SET SPAMNUM */
169 static void
170 quote_spamnum(struct Client *source_p, const char *arg, int newval)
171 {
172 if (newval >= 0)
173 {
174 if (newval == 0)
175 {
176 GlobalSetOptions.spam_num = newval;
177 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
178 "%s has disabled ANTI_SPAMBOT", source_p->name);
179 return;
180 }
181
182 GlobalSetOptions.spam_num = IRCD_MAX(newval, MIN_SPAM_NUM);
183 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
184 "%s has changed SPAMNUM to %i",
185 get_oper_name(source_p), GlobalSetOptions.spam_num);
186 }
187 else
188 sendto_one_notice(source_p, &me, ":SPAMNUM is currently %i",
189 GlobalSetOptions.spam_num);
190 }
191
192 /* SET SPAMTIME */
193 static void
194 quote_spamtime(struct Client *source_p, const char *arg, int newval)
195 {
196 if (newval > 0)
197 {
198 GlobalSetOptions.spam_time = IRCD_MAX(newval, MIN_SPAM_TIME);
199 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
200 "%s has changed SPAMTIME to %u",
201 get_oper_name(source_p), GlobalSetOptions.spam_time);
202 }
203 else
204 sendto_one_notice(source_p, &me, ":SPAMTIME is currently %u",
205 GlobalSetOptions.spam_time);
206 }
207
208 /* SET JFLOODTIME */
209 static void
210 quote_jfloodtime(struct Client *source_p, const char *arg, int newval)
211 {
212 if (newval >= 0)
213 {
214 GlobalSetOptions.joinfloodtime = newval;
215 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
216 "%s has changed JFLOODTIME to %u",
217 get_oper_name(source_p), GlobalSetOptions.joinfloodtime);
218 }
219 else
220 sendto_one_notice(source_p, &me, ":JFLOODTIME is currently %u",
221 GlobalSetOptions.joinfloodtime);
222 }
223
224 /* SET JFLOODCOUNT */
225 static void
226 quote_jfloodcount(struct Client *source_p, const char *arg, int newval)
227 {
228 if (newval >= 0)
229 {
230 GlobalSetOptions.joinfloodcount = newval;
231 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
232 "%s has changed JFLOODCOUNT to %u",
233 get_oper_name(source_p), GlobalSetOptions.joinfloodcount);
234 }
235 else
236 sendto_one_notice(source_p, &me, ":JFLOODCOUNT is currently %u",
237 GlobalSetOptions.joinfloodcount);
238 }
239
240 /* Structure used for the SET table itself */
241 struct SetStruct
242 {
243 const char *const name;
244 void (*const handler)(struct Client *, const char *, int);
245 const unsigned int wants_char; /* 1 if it expects (char *, [int]) */
246 const unsigned int wants_int; /* 1 if it expects ([char *], int) */
247 /* eg: 0, 1 == only an int arg
248 * eg: 1, 1 == char and int args */
249 };
250
251 /*
252 * If this ever needs to be expanded to more than one arg of each
253 * type, want_char/want_int could be the count of the arguments,
254 * instead of just a boolean flag...
255 *
256 * -davidt
257 */
258 static const struct SetStruct set_cmd_table[] =
259 {
260 /* name function string arg int arg */
261 /* -------------------------------------------------------- */
262 { "AUTOCONN", quote_autoconn, 1, 1 },
263 { "AUTOCONNALL", quote_autoconnall, 0, 1 },
264 { "FLOODCOUNT", quote_floodcount, 0, 1 },
265 { "FLOODTIME", quote_floodtime, 0, 1 },
266 { "IDENTTIMEOUT", quote_identtimeout, 0, 1 },
267 { "MAX", quote_max, 0, 1 },
268 { "SPAMNUM", quote_spamnum, 0, 1 },
269 { "SPAMTIME", quote_spamtime, 0, 1 },
270 { "JFLOODTIME", quote_jfloodtime, 0, 1 },
271 { "JFLOODCOUNT", quote_jfloodcount, 0, 1 },
272 /* -------------------------------------------------------- */
273 { NULL, NULL, 0, 0 }
274 };
275
276 /*
277 * list_quote_commands() sends the client all the available commands.
278 * Four to a line for now.
279 */
280 static void
281 list_quote_commands(struct Client *source_p)
282 {
283 unsigned int j = 0;
284 const char *names[4] = { "", "", "", "" };
285
286 sendto_one_notice(source_p, &me, ":Available QUOTE SET commands:");
287
288 for (const struct SetStruct *tab = set_cmd_table; tab->handler; ++tab)
289 {
290 names[j++] = tab->name;
291
292 if (j > 3)
293 {
294 sendto_one_notice(source_p, &me, ":%s %s %s %s",
295 names[0], names[1],
296 names[2], names[3]);
297 j = 0;
298 names[0] = names[1] = names[2] = names[3] = "";
299 }
300 }
301
302 if (j)
303 sendto_one_notice(source_p, &me, ":%s %s %s %s",
304 names[0], names[1],
305 names[2], names[3]);
306 }
307
308 /*
309 * mo_set - SET command handler
310 * set options while running
311 */
312 static int
313 mo_set(struct Client *source_p, int parc, char *parv[])
314 {
315 int n;
316 int newval;
317 const char *strarg = NULL;
318 const char *intarg = NULL;
319
320 if (!HasOFlag(source_p, OPER_FLAG_SET))
321 {
322 sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "set");
323 return 0;
324 }
325
326 if (parc > 1)
327 {
328 /*
329 * Go through all the commands in set_cmd_table, until one is
330 * matched.
331 */
332 for (const struct SetStruct *tab = set_cmd_table; tab->handler; ++tab)
333 {
334 if (irccmp(tab->name, parv[1]))
335 continue;
336
337 /*
338 * Command found; now execute the code
339 */
340 n = 2;
341
342 if (tab->wants_char)
343 strarg = parv[n++];
344
345 if (tab->wants_int)
346 intarg = parv[n++];
347
348 if ((n - 1) > parc)
349 sendto_one_notice(source_p, &me, ":SET %s expects (\"%s%s\") args", tab->name,
350 (tab->wants_char ? "string, " : ""),
351 (tab->wants_int ? "int" : ""));
352
353 if (parc <= 2)
354 {
355 strarg = NULL;
356 intarg = NULL;
357 }
358
359 if (tab->wants_int && parc > 2)
360 {
361 if (intarg)
362 {
363 if (!irccmp(intarg, "yes") || !irccmp(intarg, "on"))
364 newval = 1;
365 else if (!irccmp(intarg, "no") || !irccmp(intarg, "off"))
366 newval = 0;
367 else
368 newval = atoi(intarg);
369 }
370 else
371 newval = -1;
372
373 if (newval < 0)
374 {
375 sendto_one_notice(source_p, &me, ":Value less than 0 illegal for %s",
376 tab->name);
377 return 0;
378 }
379 }
380 else
381 newval = -1;
382
383 tab->handler(source_p, strarg, newval);
384 return 0;
385 }
386
387 /*
388 * Code here will be executed when a /QUOTE SET command is not
389 * found within set_cmd_table.
390 */
391 sendto_one_notice(source_p, &me, ":Variable not found.");
392 return 0;
393 }
394
395 list_quote_commands(source_p);
396 return 0;
397 }
398
399 static struct Message set_msgtab =
400 {
401 .cmd = "SET",
402 .args_max = MAXPARA,
403 .handlers[UNREGISTERED_HANDLER] = m_unregistered,
404 .handlers[CLIENT_HANDLER] = m_not_oper,
405 .handlers[SERVER_HANDLER] = m_ignore,
406 .handlers[ENCAP_HANDLER] = m_ignore,
407 .handlers[OPER_HANDLER] = mo_set
408 };
409
410 static void
411 module_init(void)
412 {
413 mod_add_cmd(&set_msgtab);
414 }
415
416 static void
417 module_exit(void)
418 {
419 mod_del_cmd(&set_msgtab);
420 }
421
422 struct module module_entry =
423 {
424 .version = "$Revision$",
425 .modinit = module_init,
426 .modexit = module_exit,
427 };

Properties

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