permissions utilities (#42)

(an instance of Generic Utilities Package made by The_Mayor)




VERB SOURCE CODE:

controls:
"@perm_utils:controls(who, what)";
"Is WHO allowed to hack on WHAT?";
return (args[1] == args[2].owner) || args[1].wizard;
.


apply:
":apply(permstring,mods) => new permstring.";
"permstring is a permissions string, mods is a concatenation of strings of the form 
+, !, or -, where  is a string of letters as 
might appear in a permissions string (`+' adds the specified permissions, `-' or 
`!' removes them; `-' and `!' are entirely equivalent).";
perms = args[1];
mods = args[2];
if ((!mods) || (!index("!-+", mods[1])))
    return mods;
endif
i = 1;
while (i <= length(mods))
    if (mods[i] == "+")
        while (((i = i + 1) <= length(mods)) && (!index("!-+", mods[i])))
            if (!index(perms, mods[i]))
                perms = perms + mods[i];
            endif
        endwhile
    else
        "mods[i] must be ! or -";
        while (((i = i + 1) <= length(mods)) && (!index("!-+", mods[i])))
            perms = strsub(perms, mods[i], "");
        endwhile
    endif
endwhile
return perms;
.


caller:
stage = 1;
c = callers();
while (((stage = stage + 1) < length(c)) && (c[stage][1] == c[1][1]))
endwhile
return c[stage];
.


controls_prop controls_property:
"controls_prop(who, what, propname)";
"Is WHO allowed to hack on WHAT's PROPNAME?";
return (args[1] == property_info(args[2], args[3])[1]) || args[1].wizard;
.



PROPERTY DATA: