ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_set.c
(Generate patch)

Comparing:
ircd-hybrid-8/modules/m_set.c (file contents), Revision 1230 by michael, Thu Sep 22 19:41:19 2011 UTC vs.
ircd-hybrid/trunk/modules/m_set.c (file contents), Revision 2433 by michael, Fri Aug 2 18:43:00 2013 UTC

# Line 25 | Line 25
25   /* rewritten by jdc */
26  
27   #include "stdinc.h"
28 – #include "handlers.h"
28   #include "client.h"
29   #include "event.h"
30   #include "irc_string.h"
# Line 35 | Line 34
34   #include "s_bsd.h"
35   #include "s_serv.h"
36   #include "send.h"
38 – #include "common.h"   /* for NO */
37   #include "channel.h"
38 < #include "s_log.h"
41 < #include "s_conf.h"
42 < #include "msg.h"
38 > #include "conf.h"
39   #include "parse.h"
40   #include "modules.h"
41   #include "s_user.h"
42 + #include "s_misc.h"
43  
44  
48 – /* Structure used for the SET table itself */
49 – struct SetStruct
50 – {
51 –  const char *name;
52 –  void (*handler)();
53 –  const int wants_char; /* 1 if it expects (char *, [int]) */
54 –  const int wants_int;  /* 1 if it expects ([char *], int) */
55 –  /* eg:  0, 1 == only an int arg
56 –   * eg:  1, 1 == char and int args */
57 – };
58 –
59 – static void quote_autoconn(struct Client *, const char *, int);
60 – static void quote_autoconnall(struct Client *, int);
61 – static void quote_floodcount(struct Client *, int);
62 – static void quote_identtimeout(struct Client *, int);
63 – static void quote_log(struct Client *, int);
64 – static void quote_max(struct Client *, int);
65 – static void quote_msglocale(struct Client *, char *);
66 – static void quote_spamnum(struct Client *, int);
67 – static void quote_spamtime(struct Client *, int);
68 – static void quote_splitmode(struct Client *, char *);
69 – static void quote_splitnum(struct Client *, int);
70 – static void quote_splitusers(struct Client *, int);
71 – static void list_quote_commands(struct Client *);
72 – static void quote_jfloodtime(struct Client *, int);
73 – static void quote_jfloodcount(struct Client *, int);
74 – static void quote_rejecttime(struct Client *, int);
75 –
76 – /*
77 – * If this ever needs to be expanded to more than one arg of each
78 – * type, want_char/want_int could be the count of the arguments,
79 – * instead of just a boolean flag...
80 – *
81 – * -davidt
82 – */
83 –
84 – static const struct SetStruct set_cmd_table[] =
85 – {
86 –  /* name               function        string arg  int arg */
87 –  /* -------------------------------------------------------- */
88 –  { "AUTOCONN",         quote_autoconn,         1,      1 },
89 –  { "AUTOCONNALL",      quote_autoconnall,      0,      1 },
90 –  { "FLOODCOUNT",       quote_floodcount,       0,      1 },
91 –  { "IDENTTIMEOUT",     quote_identtimeout,     0,      1 },
92 –  { "LOG",              quote_log,              0,      1 },
93 –  { "MAX",              quote_max,              0,      1 },
94 –  { "MSGLOCALE",        quote_msglocale,        1,      0 },
95 –  { "SPAMNUM",          quote_spamnum,          0,      1 },
96 –  { "SPAMTIME",         quote_spamtime,         0,      1 },
97 –  { "SPLITMODE",        quote_splitmode,        1,      0 },
98 –  { "SPLITNUM",         quote_splitnum,         0,      1 },
99 –  { "SPLITUSERS",       quote_splitusers,       0,      1 },
100 –  { "JFLOODTIME",       quote_jfloodtime,       0,      1 },
101 –  { "JFLOODCOUNT",      quote_jfloodcount,      0,      1 },
102 –  { "REJECTTIME",       quote_rejecttime,       0,      1 },
103 –  /* -------------------------------------------------------- */
104 –  { NULL,               NULL,                   0,      0 }
105 – };
106 –
107 – /*
108 – * list_quote_commands() sends the client all the available commands.
109 – * Four to a line for now.
110 – */
111 – static void
112 – list_quote_commands(struct Client *source_p)
113 – {
114 –  int j = 0;
115 –  const struct SetStruct *tab = set_cmd_table;
116 –  const char *names[4] = { "", "", "", "" };
117 –
118 –  sendto_one(source_p, ":%s NOTICE %s :Available QUOTE SET commands:",
119 –             me.name, source_p->name);
120 –
121 –  for (; tab->handler; ++tab)
122 –  {
123 –    names[j++] = tab->name;
124 –
125 –    if (j > 3)
126 –    {
127 –      sendto_one(source_p, ":%s NOTICE %s :%s %s %s %s",
128 –                 me.name, source_p->name,
129 –                 names[0], names[1],
130 –                 names[2], names[3]);
131 –      j = 0;
132 –      names[0] = names[1] = names[2] = names[3] = "";
133 –    }
134 –
135 –  }
136 –
137 –  if (j)
138 –    sendto_one(source_p, ":%s NOTICE %s :%s %s %s %s",
139 –               me.name, source_p->name,
140 –               names[0], names[1],
141 –               names[2], names[3]);
142 – }
143 –
45   /* SET AUTOCONN */
46   static void
47   quote_autoconn(struct Client *source_p, const char *arg, int newval)
48   {
148 –  struct AccessItem *aconf;
149 –
49    if (arg != NULL)
50    {
51 <    struct ConfItem *conf = find_exact_name_conf(SERVER_TYPE, arg, NULL, NULL);
51 >    struct MaskItem *conf = find_exact_name_conf(CONF_SERVER, NULL, arg, NULL, NULL);
52  
53      if (conf != NULL)
54      {
156 –      aconf = map_to_conf(conf);
55        if (newval)
56 <        SetConfAllowAutoConn(aconf);
56 >        SetConfAllowAutoConn(conf);
57        else
58 <        ClearConfAllowAutoConn(aconf);
58 >        ClearConfAllowAutoConn(conf);
59  
60 <      sendto_realops_flags(UMODE_ALL, L_ALL,
60 >      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
61                             "%s has changed AUTOCONN for %s to %i",
62                             get_oper_name(source_p), arg, newval);
63        sendto_one(source_p,
# Line 185 | Line 83 | quote_autoconnall(struct Client *source_
83   {
84    if (newval >= 0)
85    {
86 <    sendto_realops_flags(UMODE_ALL, L_ALL, "%s has changed AUTOCONNALL to %i",
86 >    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
87 >                         "%s has changed AUTOCONNALL to %i",
88                           get_oper_name(source_p), newval);
89  
90      GlobalSetOptions.autoconn = newval;
# Line 202 | Line 101 | quote_floodcount(struct Client *source_p
101    if (newval >= 0)
102    {
103      GlobalSetOptions.floodcount = newval;
104 <    sendto_realops_flags(UMODE_ALL, L_ALL,
104 >    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
105                           "%s has changed FLOODCOUNT to %i",
106                           get_oper_name(source_p), GlobalSetOptions.floodcount);
107    }
# Line 224 | Line 123 | quote_identtimeout(struct Client *source
123  
124    if (newval > 0)
125    {
126 <    sendto_realops_flags(UMODE_ALL, L_ALL,
127 <                         "%s has changed IDENTTIMEOUT to %d",
128 <                         get_oper_name(source_p), newval);
126 >    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
127 >                         "%s has changed IDENTTIMEOUT to %d",
128 >                         get_oper_name(source_p), newval);
129      GlobalSetOptions.ident_timeout = newval;
130    }
131    else
132      sendto_one(source_p, ":%s NOTICE %s :IDENTTIMEOUT is currently %d",
133 <               me.name, source_p->name, GlobalSetOptions.ident_timeout);
235 < }
236 <
237 < /* SET LOG */
238 < static void
239 < quote_log(struct Client *source_p, int newval)
240 < {
241 <  if (newval >= 0)
242 <  {
243 <    if (newval < L_WARN)
244 <    {
245 <      sendto_one(source_p, ":%s NOTICE %s :LOG must be > %d (L_WARN)",
246 <                 me.name, source_p->name, L_WARN);
247 <      return;
248 <    }
249 <
250 <    if (newval > L_DEBUG)
251 <      newval = L_DEBUG;
252 <
253 <    set_log_level(newval);
254 <    sendto_realops_flags(UMODE_ALL, L_ALL, "%s has changed LOG level to %i (%s)",
255 <                         get_oper_name(source_p), get_log_level(),
256 <                         get_log_level_as_string(get_log_level()));
257 <  }
258 <  else
259 <    sendto_one(source_p, ":%s NOTICE %s :LOG level is currently %i (%s)",
260 <               me.name, source_p->name, get_log_level(),
261 <               get_log_level_as_string(get_log_level()));
133 >               me.name, source_p->name, GlobalSetOptions.ident_timeout);
134   }
135  
136   /* SET MAX */
# Line 267 | Line 139 | quote_max(struct Client *source_p, int n
139   {
140    if (newval > 0)
141    {
270 –    recalc_fdlimit(NULL);
271 –
142      if (newval > MAXCLIENTS_MAX)
143      {
144        sendto_one(source_p,
145          ":%s NOTICE %s :You cannot set MAXCLIENTS to > %d, restoring to %d",
146 <        me.name, source_p->name, MAXCLIENTS_MAX, ServerInfo.max_clients);
146 >        me.name, source_p->name, MAXCLIENTS_MAX, ServerInfo.max_clients);
147        return;
148      }
149  
150      if (newval < MAXCLIENTS_MIN)
151      {
152        sendto_one(source_p,
153 <        ":%s NOTICE %s :You cannot set MAXCLIENTS to < %d, restoring to %d",
154 <        me.name, source_p->name, MAXCLIENTS_MIN, ServerInfo.max_clients);
153 >        ":%s NOTICE %s :You cannot set MAXCLIENTS to < %d, restoring to %d",
154 >        me.name, source_p->name, MAXCLIENTS_MIN, ServerInfo.max_clients);
155        return;
156      }
157  
158      ServerInfo.max_clients = newval;
159  
160 <    sendto_realops_flags(UMODE_ALL, L_ALL,
161 <        "%s set new MAXCLIENTS to %d (%d current)",
162 <        get_oper_name(source_p), ServerInfo.max_clients, Count.local);
160 >    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
161 >        "%s set new MAXCLIENTS to %d (%d current)",
162 >        get_oper_name(source_p), ServerInfo.max_clients, Count.local);
163    }
164    else
165      sendto_one(source_p, ":%s NOTICE %s :Current MAXCLIENTS = %d (%d)",
166                 me.name, source_p->name, ServerInfo.max_clients, Count.local);
167   }
168  
299 – /* SET MSGLOCALE */
300 – static void
301 – quote_msglocale(struct Client *source_p, char *locale)
302 – {
303 –  if (locale != NULL)
304 –  {
305 –    set_locale(locale);
306 –    rebuild_isupport_message_line();
307 –    sendto_one(source_p, ":%s NOTICE %s :Set MSGLOCALE to '%s'",
308 –               me.name, source_p->name, get_locale());
309 –  }
310 –  else
311 –    sendto_one(source_p, ":%s NOTICE %s :MSGLOCALE is currently '%s'",
312 –               me.name, source_p->name, get_locale());
313 – }
314 –
169   /* SET SPAMNUM */
170   static void
171   quote_spamnum(struct Client *source_p, int newval)
# Line 320 | Line 174 | quote_spamnum(struct Client *source_p, i
174    {
175      if (newval == 0)
176      {
177 <      sendto_realops_flags(UMODE_ALL, L_ALL,
177 >      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
178                             "%s has disabled ANTI_SPAMBOT", source_p->name);
179        GlobalSetOptions.spam_num = newval;
180        return;
181      }
182  
183      GlobalSetOptions.spam_num = IRCD_MAX(newval, MIN_SPAM_NUM);
184 <    sendto_realops_flags(UMODE_ALL, L_ALL, "%s has changed SPAMNUM to %i",
184 >    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
185 >                         "%s has changed SPAMNUM to %i",
186                           get_oper_name(source_p), GlobalSetOptions.spam_num);
187    }
188    else
# Line 342 | Line 197 | quote_spamtime(struct Client *source_p,
197    if (newval > 0)
198    {
199      GlobalSetOptions.spam_time = IRCD_MAX(newval, MIN_SPAM_TIME);
200 <    sendto_realops_flags(UMODE_ALL, L_ALL, "%s has changed SPAMTIME to %i",
200 >    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
201 >                         "%s has changed SPAMTIME to %i",
202                           get_oper_name(source_p), GlobalSetOptions.spam_time);
203    }
204    else
# Line 384 | Line 240 | quote_splitmode(struct Client *source_p,
240      /* OFF */
241      if (newval == 0)
242      {
243 <      sendto_realops_flags(UMODE_ALL, L_ALL,
243 >      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
244                             "%s is disabling splitmode",
245                             get_oper_name(source_p));
246  
# Line 396 | Line 252 | quote_splitmode(struct Client *source_p,
252      /* ON */
253      else if (newval == 1)
254      {
255 <      sendto_realops_flags(UMODE_ALL, L_ALL,
255 >      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
256                             "%s is enabling and activating splitmode",
257 <                           get_oper_name(source_p));
258 <                
257 >                           get_oper_name(source_p));
258 >
259        splitmode = 1;
260        splitchecking = 0;
261  
# Line 409 | Line 265 | quote_splitmode(struct Client *source_p,
265      /* AUTO */
266      else if (newval == 2)
267      {
268 <      sendto_realops_flags(UMODE_ALL, L_ALL,
268 >      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
269                             "%s is enabling automatic splitmode",
270 <                           get_oper_name(source_p));
270 >                           get_oper_name(source_p));
271  
272        splitchecking = 1;
273        check_splitmode(NULL);
# Line 424 | Line 280 | quote_splitmode(struct Client *source_p,
280       */
281      sendto_one(source_p, ":%s NOTICE %s :SPLITMODE is currently %s",
282                 me.name, source_p->name,
283 <               splitmode_status[(splitchecking + (splitmode * 2))]);
283 >               splitmode_status[(splitchecking + (splitmode * 2))]);
284   }
285  
286   /* SET SPLITNUM */
# Line 433 | Line 289 | quote_splitnum(struct Client *source_p,
289   {
290    if (newval >= 0)
291    {
292 <    sendto_realops_flags(UMODE_ALL, L_ALL,
292 >    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
293                           "%s has changed SPLITNUM to %i",
294 <                         get_oper_name(source_p), newval);
294 >                         get_oper_name(source_p), newval);
295      split_servers = newval;
296  
297      if (splitchecking)
# Line 452 | Line 308 | quote_splitusers(struct Client *source_p
308   {
309    if (newval >= 0)
310    {
311 <    sendto_realops_flags(UMODE_ALL, L_ALL,
311 >    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
312                           "%s has changed SPLITUSERS to %i",
313 <                         get_oper_name(source_p), newval);
313 >                         get_oper_name(source_p), newval);
314      split_users = newval;
315  
316      if (splitchecking)
# Line 471 | Line 327 | quote_jfloodtime(struct Client *source_p
327   {
328    if (newval >= 0)
329    {
330 <    sendto_realops_flags(UMODE_ALL, L_ALL,
330 >    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
331                           "%s has changed JFLOODTIME to %i",
332 <                         get_oper_name(source_p), newval);
332 >                         get_oper_name(source_p), newval);
333      GlobalSetOptions.joinfloodtime = newval;
334    }
335    else
# Line 487 | Line 343 | quote_jfloodcount(struct Client *source_
343   {
344    if (newval >= 0)
345    {
346 <    sendto_realops_flags(UMODE_ALL, L_ALL,
346 >    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
347                           "%s has changed JFLOODCOUNT to %i",
348 <                         get_oper_name(source_p), newval);
348 >                         get_oper_name(source_p), newval);
349      GlobalSetOptions.joinfloodcount = newval;
350    }
351    else
# Line 497 | Line 353 | quote_jfloodcount(struct Client *source_
353                 me.name, source_p->name, GlobalSetOptions.joinfloodcount);
354   }
355  
356 < /* SET REJECTTIME */
356 > /* Structure used for the SET table itself */
357 > struct SetStruct
358 > {
359 >  const char *name;
360 >  void (*handler)();
361 >  const int wants_char; /* 1 if it expects (char *, [int]) */
362 >  const int wants_int;  /* 1 if it expects ([char *], int) */
363 >  /* eg:  0, 1 == only an int arg
364 >   * eg:  1, 1 == char and int args */
365 > };
366 >
367 > /*
368 > * If this ever needs to be expanded to more than one arg of each
369 > * type, want_char/want_int could be the count of the arguments,
370 > * instead of just a boolean flag...
371 > *
372 > * -davidt
373 > */
374 > static const struct SetStruct set_cmd_table[] =
375 > {
376 >  /* name               function        string arg  int arg */
377 >  /* -------------------------------------------------------- */
378 >  { "AUTOCONN",         quote_autoconn,         1,      1 },
379 >  { "AUTOCONNALL",      quote_autoconnall,      0,      1 },
380 >  { "FLOODCOUNT",       quote_floodcount,       0,      1 },
381 >  { "IDENTTIMEOUT",     quote_identtimeout,     0,      1 },
382 >  { "MAX",              quote_max,              0,      1 },
383 >  { "SPAMNUM",          quote_spamnum,          0,      1 },
384 >  { "SPAMTIME",         quote_spamtime,         0,      1 },
385 >  { "SPLITMODE",        quote_splitmode,        1,      0 },
386 >  { "SPLITNUM",         quote_splitnum,         0,      1 },
387 >  { "SPLITUSERS",       quote_splitusers,       0,      1 },
388 >  { "JFLOODTIME",       quote_jfloodtime,       0,      1 },
389 >  { "JFLOODCOUNT",      quote_jfloodcount,      0,      1 },
390 >  /* -------------------------------------------------------- */
391 >  { NULL,               NULL,                   0,      0 }
392 > };
393 >
394 > /*
395 > * list_quote_commands() sends the client all the available commands.
396 > * Four to a line for now.
397 > */
398   static void
399 < quote_rejecttime(struct Client *source_p, int newval)
399 > list_quote_commands(struct Client *source_p)
400   {
401 <  if (newval >= 0)
401 >  int j = 0;
402 >  const struct SetStruct *tab = set_cmd_table;
403 >  const char *names[4] = { "", "", "", "" };
404 >
405 >  sendto_one(source_p, ":%s NOTICE %s :Available QUOTE SET commands:",
406 >             me.name, source_p->name);
407 >
408 >  for (; tab->handler; ++tab)
409    {
410 <    sendto_realops_flags(UMODE_ALL, L_ALL,
411 <                         "%s has changed REJECTTIME to %i seconds",
412 <                         get_oper_name(source_p), newval);
413 <    GlobalSetOptions.rejecttime = newval;
410 >    names[j++] = tab->name;
411 >
412 >    if (j > 3)
413 >    {
414 >      sendto_one(source_p, ":%s NOTICE %s :%s %s %s %s",
415 >                 me.name, source_p->name,
416 >                 names[0], names[1],
417 >                 names[2], names[3]);
418 >      j = 0;
419 >      names[0] = names[1] = names[2] = names[3] = "";
420 >    }
421 >
422    }
423 <  else
424 <    sendto_one(source_p, ":%s NOTICE %s :REJECTTIME is currently %i seconds",
425 <               me.name, source_p->name, GlobalSetOptions.rejecttime);
423 >
424 >  if (j)
425 >    sendto_one(source_p, ":%s NOTICE %s :%s %s %s %s",
426 >               me.name, source_p->name,
427 >               names[0], names[1],
428 >               names[2], names[3]);
429   }
430  
431   /*
# Line 527 | Line 442 | mo_set(struct Client *client_p, struct C
442    const char *intarg = NULL;
443    const struct SetStruct *tab = set_cmd_table;
444  
445 +  if (!HasOFlag(source_p, OPER_FLAG_SET))
446 +  {
447 +    sendto_one(source_p, form_str(ERR_NOPRIVS),
448 +               me.name, source_p->name, "set");
449 +    return;
450 +  }
451 +
452    if (parc > 1)
453    {
454      /*
# Line 583 | Line 505 | mo_set(struct Client *client_p, struct C
505                newval = atoi(intarg);
506            }
507            else
586 –          {
508              newval = -1;
588 –          }
509  
510            if (newval < 0)
511            {
# Line 635 | Line 555 | mo_set(struct Client *client_p, struct C
555  
556   static struct Message set_msgtab = {
557    "SET", 0, 0, 0, MAXPARA, MFLG_SLOW, 0,
558 <  {m_unregistered, m_not_oper, rfc1459_command_send_error, m_ignore, mo_set, m_ignore}
558 >  {m_unregistered, m_not_oper, m_ignore, m_ignore, mo_set, m_ignore}
559   };
560  
561   static void

Diff Legend

– Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)