]> jfr.im git - irc/atheme/atheme.git/commitdiff
groupserv: Rewrite flags parser to use ga_flags
authorShockk <redacted>
Wed, 14 Jan 2015 18:04:26 +0000 (18:04 +0000)
committerShockk <redacted>
Wed, 14 Jan 2015 20:32:50 +0000 (20:32 +0000)
Currently the GroupServ flags parser is hardcoded for each flag. While this may
be faster than looping through ga_flags--debatable, as compilers can
probably optimize a loop over compile-time data--problems can arise from
adding a new GroupServ flag without also remembering to hardcode that
flag into the flags parser.

This patch replaces the hardcoded clauses in the flags parser switch
block with a loop across the elements of ga_flags to determine the
correct flag value for the specified flag character.

help/default/groupserv/flags
modules/groupserv/main/groupserv.c

index 46b2cae9206342759a9942a4ccb6b06863690fa6..4a28f40a548f04cec48f227d8312c2dc1dcac39d 100644 (file)
@@ -18,6 +18,7 @@ Syntax: FLAGS <!group> [nickname flag_changes]
 Permissions:
     +f - Enables modification of group access list.
     +F - Grants full founder access.
+    +A - Enables viewing of group access list.
     +m - Read memos sent to the group.
     +c - Have channel access in channels where the group has sufficient
          privileges.
index df61e63a6d813cc1d4caae365020f2df1a26cc1a..1bed1c33fa31db64186e1e460561bb477537fcca 100644 (file)
@@ -287,11 +287,14 @@ unsigned int gs_flags_parser(char *flagstring, bool allow_minus, unsigned int fl
 {
        char *c;
        unsigned int dir = 0;
+       unsigned int flag;
+       unsigned char n;
 
-       /* XXX: this sucks. :< */
        c = flagstring;
        while (*c)
        {
+               flag = 0;
+               n = 0;
                switch(*c)
                {
                case '+':
@@ -307,55 +310,20 @@ unsigned int gs_flags_parser(char *flagstring, bool allow_minus, unsigned int fl
                        else
                                flags = GA_ALL;
                        break;
-               case 'F':
-                       if (dir)
-                               flags &= ~GA_FOUNDER;
-                       else
-                               flags |= GA_FOUNDER;
-                       break;
-               case 'f':
-                       if (dir)
-                               flags &= ~GA_FLAGS;
-                       else
-                               flags |= GA_FLAGS;
-                       break;
-               case 's':
-                       if (dir)
-                               flags &= ~GA_SET;
-                       else
-                               flags |= GA_SET;
-                       break;
-               case 'v':
-                       if (dir)
-                               flags &= ~GA_VHOST;
-                       else
-                               flags |= GA_VHOST;
-                       break;
-               case 'c':
-                       if (dir)
-                               flags &= ~GA_CHANACS;
-                       else
-                               flags |= GA_CHANACS;
-                       break;
-               case 'm':
-                       if (dir)
-                               flags &= ~GA_MEMOS;
-                       else
-                               flags |= GA_MEMOS;
-                       break;
-               case 'b':
-                       if (dir)
-                               flags &= ~GA_BAN;
-                       else
-                               flags |= GA_BAN;
-                       break;
-               case 'i':
+               default:
+                       while (ga_flags[n].ch != 0 && flag == 0)
+                       {
+                               if (ga_flags[n].ch == *c)
+                                       flag = ga_flags[n].value;
+                               else
+                                       n++;
+                       }
+                       if (flag == 0)
+                               break;
                        if (dir)
-                               flags &= ~GA_INVITE;
+                               flags &= ~flag;
                        else
-                               flags |= GA_INVITE;
-                       break;
-               default:
+                               flags |= flag;
                        break;
                }