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: 10024
Committed: Sat Jan 1 10:20:46 2022 UTC (2 years, 2 months ago) by michael
Content type: text/x-csrc
File size: 11524 byte(s)
Log Message:
- Bump copyright years

File Contents

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

Properties

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