From: Rick L Bird Date: Sat, 7 May 2011 04:33:39 +0000 (-0400) Subject: Altered and streamlined the @attribute command's behavior. X-Git-Url: https://git.theari.com/?a=commitdiff_plain;h=5ddf0514fd6b1920ccf3638889e94db53d265d34;p=cobramush.git Altered and streamlined the @attribute command's behavior. 1) The undocumented DEFAULTS switch now works with Access switch. 2) @attribute without any switches defaults to INFO a) @attribute/info or @attribute itself without any arguments defaults to info on the DEFAULT attribute. 3) @attribute x=y, defaults to ACCESS switch --- diff --git a/hdrs/attrib.h b/hdrs/attrib.h index 6354ca2..f93adae 100644 --- a/hdrs/attrib.h +++ b/hdrs/attrib.h @@ -38,7 +38,7 @@ struct aget_oi { extern ATTR *aname_hash_lookup(const char *name); extern int alias_attribute(const char *atr, const char *alias); extern void do_attribute_access - (dbref player, char *name, char *perms, int retroactive); + (dbref player, char *name, char *perms, switch_mask sw); extern void do_attribute_delete(dbref player, char *name, char def); extern void do_attribute_rename(dbref player, char *old, char *newname); extern void do_attribute_info(dbref player, char *name); diff --git a/src/atr_tab.c b/src/atr_tab.c index d893f97..7e70510 100644 --- a/src/atr_tab.c +++ b/src/atr_tab.c @@ -204,9 +204,9 @@ void do_attribute_lock(dbref player, char *name, char *lock, switch_mask swi) { /* If a lock is already set on whatever we're doing.. clear it */ free_boolexp(SW_ISSET(swi, SWITCH_WRITE) ? AL_WLock(ap) : AL_RLock(ap)); - } else { + } else { /* Create fresh if the name is ok */ - if (!good_atr_name(name)) { + if (!SW_ISSET(swi, SWITCH_DEFAULTS) && !good_atr_name(name)) { notify(player, T("Invalid attribute name.")); return; } @@ -237,11 +237,9 @@ void do_attribute_lock(dbref player, char *name, char *lock, switch_mask swi) { /* Only insert when it's not already in the table */ if (insert) { - if(!SW_ISSET(swi, SWITCH_DEFAULTS)) { - ptab_start_inserts(&ptab_attrib); - ptab_insert(&ptab_attrib, name, ap); - ptab_end_inserts(&ptab_attrib); - } + if(!SW_ISSET(swi, SWITCH_DEFAULTS)) + ptab_insert_one(&ptab_attrib, name, ap); + /* And If its the catchall.. just point the catchall to ap */ else catchall = ap; } @@ -280,18 +278,20 @@ void do_attribute_lock(dbref player, char *name, char *lock, switch_mask swi) { * \param retroactive if true, apply the permissions retroactively. */ void -do_attribute_access(dbref player, char *name, char *perms, int retroactive) +do_attribute_access(dbref player, char *name, char *arg2, switch_mask sw) { ATTR *ap, *ap2; privbits flags = 0; + char *perms; int i; int insert = 0; /* Parse name and perms */ - if (!name || !*name) { + if ((!name || !*name) && !SW_ISSET(sw, SWITCH_DEFAULTS)) { notify(player, T("Which attribute do you mean?")); return; } + perms = SW_ISSET(sw, SWITCH_DEFAULTS) ? name : arg2; if(strcasecmp(perms, "none")) { flags = list_to_privs(attr_privs_set, perms, 0); if (!flags) { @@ -299,11 +299,14 @@ do_attribute_access(dbref player, char *name, char *perms, int retroactive) return; } } - upcasestr(name); - /* Is this attribute already in the table? */ - if(*name == '@') - name++; - ap = (ATTR *) ptab_find_exact(&ptab_attrib, name); + if(!SW_ISSET(sw, SWITCH_DEFAULTS)) { + upcasestr(name); + /* Is this attribute already in the table? */ + if(*name == '@') + name++; + ap = (ATTR *) ptab_find_exact(&ptab_attrib, name); + } ap = catchall; + if (ap) { if (AF_Internal(ap)) { /* Don't muck with internal attributes */ @@ -326,7 +329,10 @@ do_attribute_access(dbref player, char *name, char *perms, int retroactive) } AL_WLock(ap) = TRUE_BOOLEXP; AL_RLock(ap) = TRUE_BOOLEXP; - AL_NAME(ap) = mush_strdup(name, "GLOBAL.ATR.NAME"); + if(SW_ISSET(sw, SWITCH_DEFAULTS)) + AL_NAME(ap) = NULL; + else + AL_NAME(ap) = mush_strdup(name, "GLOBAL.ATR.NAME"); ap->data = NULL_CHUNK_REFERENCE; } @@ -336,14 +342,17 @@ do_attribute_access(dbref player, char *name, char *perms, int retroactive) /* Only insert when it's not already in the table */ if (insert) { - ptab_insert_one(&ptab_attrib, name, ap); + if(!SW_ISSET(sw, SWITCH_DEFAULTS)) + ptab_insert_one(&ptab_attrib, name, ap); + /* And If its the catchall.. just point the catchall to ap */ + else catchall = ap; } /* Ok, now we need to see if there are any attributes of this name * set on objects in the db. If so, and if we're retroactive, set * perms/creator */ - if (retroactive) { + if (SW_ISSET(sw, SWITCH_RETROACTIVE)) { for (i = 0; i < db_top; i++) { if ((ap2 = atr_get_noparent(i, name))) { AL_FLAGS(ap2) = flags; @@ -352,7 +361,7 @@ do_attribute_access(dbref player, char *name, char *perms, int retroactive) } } - notify_format(player, T("%s -- Attribute permissions now: %s"), name, + notify_format(player, T("%s -- Attribute permissions now: %s"), SW_ISSET(sw, SWITCH_DEFAULTS) ? "Default" : name, privs_to_string(attr_privs_view, flags)); } diff --git a/src/cmds.c b/src/cmds.c index e3969e1..50ac5d5 100644 --- a/src/cmds.c +++ b/src/cmds.c @@ -76,22 +76,22 @@ COMMAND (cmd_atrlock) { } COMMAND (cmd_attribute) { + if(SW_ISSET(sw, SWITCH_INFO) || !has_power(player, "GFUNCS")) { - do_attribute_info(player, arg_left); - } else if (SW_ISSET(sw, SWITCH_ACCESS)) - do_attribute_access(player, arg_left, arg_right, - SW_ISSET(sw, SWITCH_RETROACTIVE)); - else if(SW_ISSET(sw, SWITCH_LOCK)) { + attribute_info: + do_attribute_info(player, (SW_ISSET(sw, SWITCH_DEFAULTS) ? NULL : arg_left)); + } else if(SW_ISSET(sw, SWITCH_LOCK)) { if(SW_ISSET(sw, SWITCH_DEFAULTS)) do_attribute_lock(player, NULL, arg_left, sw); else do_attribute_lock(player, arg_left, arg_right, sw); - } + } else if (SW_ISSET(sw, SWITCH_ACCESS) || (*arg_right != '\0' && has_power(player, "GFUNCS"))) + do_attribute_access(player, arg_left, arg_right, sw); else if (SW_ISSET(sw, SWITCH_DELETE)) do_attribute_delete(player, arg_left, SW_ISSET(sw, SWITCH_DEFAULTS)); else if (SW_ISSET(sw, SWITCH_RENAME)) { do_attribute_rename(player, arg_left, arg_right); - } else notify(player, "You lost me..."); + } else goto attribute_info; /* go back to info if everything else fails.. Its always a safe bet */ } COMMAND(cmd_atrchown) diff --git a/src/command.c b/src/command.c index abef43a..74506f0 100644 --- a/src/command.c +++ b/src/command.c @@ -86,7 +86,7 @@ COMLIST commands[] = { {"@ASSERT", NULL, cmd_assert, CMD_T_ANY | CMD_T_EQSPLIT | CMD_T_RS_NOPARSE, NULL}, {"@ATRLOCK", "READ WRITE", cmd_atrlock, CMD_T_ANY | CMD_T_EQSPLIT, NULL}, {"@ATRCHOWN", NULL, cmd_atrchown, CMD_T_EQSPLIT, NULL}, - {"@ATTRIBUTE", "ACCESS DEFAULTS LOCK WRITE READ DELETE RENAME RETROACTIVE", cmd_attribute, + {"@ATTRIBUTE", "ACCESS DEFAULTS LOCK WRITE INFO READ DELETE RENAME RETROACTIVE", cmd_attribute, CMD_T_ANY | CMD_T_EQSPLIT, NULL}, {"@BOOT", "PORT ME", cmd_boot, CMD_T_ANY, NULL}, {"@BREAK", NULL, cmd_break, CMD_T_ANY | CMD_T_EQSPLIT | CMD_T_RS_NOPARSE, NULL}, diff --git a/src/funufun.c b/src/funufun.c index 20e69fd..8c905c0 100644 --- a/src/funufun.c +++ b/src/funufun.c @@ -7,8 +7,11 @@ */ #include "copyrite.h" - #include "config.h" + +#ifdef HAVE_STRING_H +#include +#endif #include "conf.h" #include "externs.h" #include "match.h"