/[svn]/ircd-hybrid-7.2/modules/m_set.c
ViewVC logotype

Diff of /ircd-hybrid-7.2/modules/m_set.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1012 by michael, Mon Jul 20 23:18:04 2009 UTC revision 1013 by michael, Sun Oct 18 14:26:49 2009 UTC
# Line 73  struct SetStruct Line 73  struct SetStruct
73  {  {
74    const char *name;    const char *name;
75    void (*handler)();    void (*handler)();
76    int wants_char; /* 1 if it expects (char *, [int]) */    const int wants_char; /* 1 if it expects (char *, [int]) */
77    int wants_int;  /* 1 if it expects ([char *], int) */    const int wants_int;  /* 1 if it expects ([char *], int) */
78    /* eg:  0, 1 == only an int arg    /* eg:  0, 1 == only an int arg
79     * eg:  1, 1 == char and int args */     * eg:  1, 1 == char and int args */
80  };  };
# Line 105  static void quote_rejecttime(struct Clie Line 105  static void quote_rejecttime(struct Clie
105   * -davidt   * -davidt
106   */   */
107    
108  static struct SetStruct set_cmd_table[] =  static const struct SetStruct set_cmd_table[] =
109  {  {
110    /* name               function        string arg  int arg */    /* name               function        string arg  int arg */
111    /* -------------------------------------------------------- */    /* -------------------------------------------------------- */
# Line 136  static struct SetStruct set_cmd_table[] Line 136  static struct SetStruct set_cmd_table[]
136  static void  static void
137  list_quote_commands(struct Client *source_p)  list_quote_commands(struct Client *source_p)
138  {  {
   int i;  
139    int j = 0;    int j = 0;
140      const struct SetStruct *tab = set_cmd_table;
141    const char *names[4] = { "", "", "", "" };    const char *names[4] = { "", "", "", "" };
142    
143    sendto_one(source_p, ":%s NOTICE %s :Available QUOTE SET commands:",    sendto_one(source_p, ":%s NOTICE %s :Available QUOTE SET commands:",
144               me.name, source_p->name);               me.name, source_p->name);
145    
146    for (i = 0; set_cmd_table[i].handler; i++)    for (; tab->handler; ++tab)
147    {    {
148      names[j++] = set_cmd_table[i].name;      names[j++] = tab->name;
149    
150      if (j > 3)      if (j > 3)
151      {      {
# Line 291  quote_idletime(struct Client *source_p, Line 291  quote_idletime(struct Client *source_p,
291  static void  static void
292  quote_log(struct Client *source_p, int newval)  quote_log(struct Client *source_p, int newval)
293  {  {
   const char *log_level_as_string;  
   
294    if (newval >= 0)    if (newval >= 0)
295    {    {
296      if (newval < L_WARN)      if (newval < L_WARN)
# Line 303  quote_log(struct Client *source_p, int n Line 301  quote_log(struct Client *source_p, int n
301      }      }
302    
303      if (newval > L_DEBUG)      if (newval > L_DEBUG)
     {  
304        newval = L_DEBUG;        newval = L_DEBUG;
     }  
305    
306      set_log_level(newval);      set_log_level(newval);
     log_level_as_string = get_log_level_as_string(newval);  
307      sendto_realops_flags(UMODE_ALL, L_ALL,"%s has changed LOG level to %i (%s)",      sendto_realops_flags(UMODE_ALL, L_ALL,"%s has changed LOG level to %i (%s)",
308                           source_p->name, newval, log_level_as_string);                           source_p->name, get_log_level(),
309                             get_log_level_as_string(get_log_level()));
310    }    }
311    else    else
   {  
312      sendto_one(source_p, ":%s NOTICE %s :LOG level is currently %i (%s)",      sendto_one(source_p, ":%s NOTICE %s :LOG level is currently %i (%s)",
313                 me.name, source_p->name, get_log_level(),                 me.name, source_p->name, get_log_level(),
314                 get_log_level_as_string(get_log_level()));                 get_log_level_as_string(get_log_level()));
   }  
315  }  }
316    
317  /* SET MAX */  /* SET MAX */
# Line 387  quote_spamnum(struct Client *source_p, i Line 381  quote_spamnum(struct Client *source_p, i
381      }      }
382    
383      GlobalSetOptions.spam_num = IRCD_MAX(newval, MIN_SPAM_NUM);      GlobalSetOptions.spam_num = IRCD_MAX(newval, MIN_SPAM_NUM);
   
384      sendto_realops_flags(UMODE_ALL, L_ALL,"%s has changed SPAMNUM to %i",      sendto_realops_flags(UMODE_ALL, L_ALL,"%s has changed SPAMNUM to %i",
385                  source_p->name, GlobalSetOptions.spam_num);                           source_p->name, GlobalSetOptions.spam_num);
386    }    }
387    else    else
388      sendto_one(source_p, ":%s NOTICE %s :SPAMNUM is currently %i",      sendto_one(source_p, ":%s NOTICE %s :SPAMNUM is currently %i",
389                 me.name,                 me.name, source_p->name, GlobalSetOptions.spam_num);
                source_p->name, GlobalSetOptions.spam_num);  
390  }  }
391    
392  /* SET SPAMTIME */  /* SET SPAMTIME */
# Line 405  quote_spamtime(struct Client *source_p, Line 397  quote_spamtime(struct Client *source_p,
397    {    {
398      GlobalSetOptions.spam_time = IRCD_MAX(newval, MIN_SPAM_TIME);      GlobalSetOptions.spam_time = IRCD_MAX(newval, MIN_SPAM_TIME);
399      sendto_realops_flags(UMODE_ALL, L_ALL, "%s has changed SPAMTIME to %i",      sendto_realops_flags(UMODE_ALL, L_ALL, "%s has changed SPAMTIME to %i",
400                  source_p->name, GlobalSetOptions.spam_time);                           source_p->name, GlobalSetOptions.spam_time);
401    }    }
402    else    else
403      sendto_one(source_p, ":%s NOTICE %s :SPAMTIME is currently %i",      sendto_one(source_p, ":%s NOTICE %s :SPAMTIME is currently %i",
404                  me.name,                 me.name, source_p->name, GlobalSetOptions.spam_time);
                 source_p->name, GlobalSetOptions.spam_time);  
405  }  }
406    
407  /* this table is what splitmode may be set to */  /* this table is what splitmode may be set to */
# Line 584  static void Line 575  static void
575  mo_set(struct Client *client_p, struct Client *source_p,  mo_set(struct Client *client_p, struct Client *source_p,
576         int parc, char *parv[])         int parc, char *parv[])
577  {  {
   int i;  
578    int n;    int n;
579    int newval;    int newval;
580    const char *arg    = NULL;    const char *arg    = NULL;
581    const char *intarg = NULL;    const char *intarg = NULL;
582      const struct SetStruct *tab = set_cmd_table;
583    
584    if (parc > 1)    if (parc > 1)
585    {    {
586      /* Go through all the commands in set_cmd_table, until one is      /*
587       * matched.  I realize strcmp() is more intensive than a numeric       * Go through all the commands in set_cmd_table, until one is
588       * lookup, but at least it's better than a big-ass switch/case       * matched.
      * statement.  
589       */       */
590      for (i = 0; set_cmd_table[i].handler; i++)      for (; tab->handler; ++tab)
591      {      {
592        if (irccmp(set_cmd_table[i].name, parv[1]) == 0)        if (!irccmp(tab->name, parv[1]))
593        {        {
594          /*          /*
595           * Command found; now execute the code           * Command found; now execute the code
596           */           */
597          n = 2;          n = 2;
598    
599          if (set_cmd_table[i].wants_char)          if (tab->wants_char)
         {  
600            arg = parv[n++];            arg = parv[n++];
         }  
601    
602          if (set_cmd_table[i].wants_int)          if (tab->wants_int)
         {  
603            intarg = parv[n++];            intarg = parv[n++];
         }  
604    
605          if ((n - 1) > parc)          if ((n - 1) > parc)
606          {          {
607            if (parc > 2)            if (parc > 2)
608              sendto_one(source_p,              sendto_one(source_p,
609                         ":%s NOTICE %s :SET %s expects (\"%s%s\") args",                         ":%s NOTICE %s :SET %s expects (\"%s%s\") args",
610                         me.name, source_p->name, set_cmd_table[i].name,                         me.name, source_p->name, tab->name,
611                         (set_cmd_table[i].wants_char ? "string, " : ""),                         (tab->wants_char ? "string, " : ""),
612                         (set_cmd_table[i].wants_char ? "int" : "")                         (tab->wants_char ? "int" : ""));
                       );  
613          }          }
614    
615          if (parc <= 2)          if (parc <= 2)
# Line 633  mo_set(struct Client *client_p, struct C Line 618  mo_set(struct Client *client_p, struct C
618            intarg = NULL;            intarg = NULL;
619          }          }
620    
621          if (!strcmp(set_cmd_table[i].name, "AUTOCONN") && (parc < 4))          if (!strcmp(tab->name, "AUTOCONN") && (parc < 4))
622          {          {
623            sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),            sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
624                       me.name, source_p->name, "SET");                       me.name, source_p->name, "SET");
625            return;            return;
626          }          }
627    
628          if (set_cmd_table[i].wants_int && (parc > 2))          if (tab->wants_int && (parc > 2))
629          {          {
630            if (intarg)            if (intarg)
631            {            {
# Line 661  mo_set(struct Client *client_p, struct C Line 646  mo_set(struct Client *client_p, struct C
646              sendto_one(source_p,              sendto_one(source_p,
647                         ":%s NOTICE %s :Value less than 0 illegal for %s",                         ":%s NOTICE %s :Value less than 0 illegal for %s",
648                         me.name, source_p->name,                         me.name, source_p->name,
649                         set_cmd_table[i].name);                         tab->name);
650    
651              return;              return;
652            }            }
# Line 669  mo_set(struct Client *client_p, struct C Line 654  mo_set(struct Client *client_p, struct C
654          else          else
655            newval = -1;            newval = -1;
656    
657          if (set_cmd_table[i].wants_char)          if (tab->wants_char)
658          {          {
659            if (set_cmd_table[i].wants_int)            if (tab->wants_int)
660              set_cmd_table[i].handler(source_p, arg, newval);              tab->handler(source_p, arg, newval);
661            else            else
662              set_cmd_table[i].handler(source_p, arg);              tab->handler(source_p, arg);
663            return;            return;
664          }          }
665          else          else
666          {          {
667            if (set_cmd_table[i].wants_int)            if (tab->wants_int)
668              set_cmd_table[i].handler(source_p, newval);              tab->handler(source_p, newval);
669            else            else
670              /* Just in case someone actually wants a              /* Just in case someone actually wants a
671               * set function that takes no args.. *shrug* */               * set function that takes no args.. *shrug* */
672              set_cmd_table[i].handler(source_p);              tab->handler(source_p);
673            return;            return;
674          }          }
675        }        }
# Line 701  mo_set(struct Client *client_p, struct C Line 686  mo_set(struct Client *client_p, struct C
686    
687    list_quote_commands(source_p);    list_quote_commands(source_p);
688  }  }
   

Legend:
Removed from v.1012  
changed lines
  Added in v.1013

svnadmin@ircd-hybrid.org
ViewVC Help
Powered by ViewVC 1.1.26