From: Ari Johnson Date: Fri, 23 Feb 2007 02:45:04 +0000 (+0000) Subject: @attrib/access no longer treats unmatched flag names as a set of flag characters X-Git-Tag: 0.73~116 X-Git-Url: https://git.theari.com/?a=commitdiff_plain;h=cd5c223ff83d7ad035b827ebcbf3c9b743e0b5af;p=cobramush.git @attrib/access no longer treats unmatched flag names as a set of flag characters --- diff --git a/game/txt/hlp/cobra_cmd.hlp b/game/txt/hlp/cobra_cmd.hlp index e2ecb4f..85c2797 100644 --- a/game/txt/hlp/cobra_cmd.hlp +++ b/game/txt/hlp/cobra_cmd.hlp @@ -392,7 +392,7 @@ See also: @success, @osuccess, get, @lock, EXITS, ACTION LISTS Used without switches, @attribute shows info about a standard attrib. @attribute/access adds a new standard attribute into the table, - associating it with the given space-separated list of flags. + associating it with the given space-separated list of full flag names. See 'help @set' for possible flags. A flag list of "none" removes all flag associations. If the /retroactive switch is added, the flags are assigned to every copy diff --git a/hdrs/privtab.h b/hdrs/privtab.h index 6d0f9af..8532cf8 100644 --- a/hdrs/privtab.h +++ b/hdrs/privtab.h @@ -28,6 +28,7 @@ struct priv_info { #define PrivShowBits(x) ((x)->bits_to_show) extern int string_to_privs(PRIV *table, const char *str, long int origprivs); +extern int list_to_privs(PRIV *table, const char *str, long int origprivs); extern int string_to_privsets(PRIV *table, const char *str, int *setprivs, int *clrprivs); extern int letter_to_privs(PRIV *table, const char *str, long int origprivs); diff --git a/src/atr_tab.c b/src/atr_tab.c index 0a33fb4..75ff246 100644 --- a/src/atr_tab.c +++ b/src/atr_tab.c @@ -290,7 +290,7 @@ do_attribute_access(dbref player, char *name, char *perms, int retroactive) return; } if (strcasecmp(perms, "none")) { - flags = string_to_privs(attr_privs_set, perms, 0); + flags = list_to_privs(attr_privs_set, perms, 0); if (!flags) { notify(player, T("I don't understand those permissions.")); return; diff --git a/src/privtab.c b/src/privtab.c index c85af22..3e42ccf 100644 --- a/src/privtab.c +++ b/src/privtab.c @@ -22,7 +22,9 @@ /** Convert a string to a set of privilege bits, masked by an original set. * Given a privs table, a string, and an original set of privileges, * return a modified set of privileges by applying the privs in the - * string to the original set of privileges. + * string to the original set of privileges. IF A SINGLE WORD STRING + * IS GIVEN AND IT ISN'T THE NAME OF A PRIV, PARSE IT AS INDIVIDUAL + * PRIV CHARS. * \param table pointer to a privtab. * \param str a space-separated string of privilege names to apply. * \param origprivs the original privileges. @@ -83,6 +85,53 @@ string_to_privs(PRIV *table, const char *str, long int origprivs) return ((origprivs | yes) & ~no); } +/** Convert a list to a set of privilege bits, masked by an original set. + * Given a privs table, a list, and an original set of privileges, + * return a modified set of privileges by applying the privs in the + * string to the original set of privileges. No prefix-matching is + * permitted in this list. + * \param table pointer to a privtab. + * \param str a space-separated string of privilege names to apply. + * \param origprivs the original privileges. + * \return a privilege bitmask. + */ +int +list_to_privs(PRIV *table, const char *str, long int origprivs) +{ + PRIV *c; + long int yes = 0; + long int no = 0; + char *p, *r; + char tbuf1[BUFFER_LEN]; + int not; + int words = 0; + + if (!str || !*str) + return origprivs; + strcpy(tbuf1, str); + r = trim_space_sep(tbuf1, ' '); + while ((p = split_token(&r, ' '))) { + words++; + not = 0; + if (*p == '!') { + not = 1; + if (!*++p) + continue; + } + for (c = table; c->name; c++) { + if (!strcasecmp(c->name, p)) { + if (not) + no |= c->bits_to_set; + else + yes |= c->bits_to_set; + break; + } + } + } + return ((origprivs | yes) & ~no); +} + + /** Convert a string to 2 sets of privilege bits, privs to set and * privs to clear. * \param table pointer to a privtab.