From: Ari Johnson Date: Sat, 3 Mar 2007 00:30:24 +0000 (+0000) Subject: Better attribute-related error messages X-Git-Url: https://git.theari.com/?a=commitdiff_plain;h=7bf043a6d6b40dceeeb2b46a132e39696fa27e1f;p=cobramush.git Better attribute-related error messages (cherry picked from commit 595a04a22ea1c511599314955f2140aa9744fd7b) --- diff --git a/hdrs/externs.h b/hdrs/externs.h index 50da19a..a53f6f0 100644 --- a/hdrs/externs.h +++ b/hdrs/externs.h @@ -233,6 +233,10 @@ extern void parse_que(dbref player, const char *command, dbref cause); extern void div_parse_que(dbref division, const char *command, dbref called_division, dbref player); extern int queue_attribute_base (dbref executor, const char *atrname, dbref enactor, int noparent); +extern ATTR *queue_attribute_getatr(dbref executor, const char *atrname, + int noparent); +extern int queue_attribute_useatr(dbref executor, ATTR *a, dbref enactor); + /** Queue the code in an attribute, including parent objects */ #define queue_attribute(a,b,c) queue_attribute_base(a,b,c,0) /** Queue the code in an attribute, excluding parent objects */ diff --git a/src/attrib.c b/src/attrib.c index e348a0c..317b009 100644 --- a/src/attrib.c +++ b/src/attrib.c @@ -31,6 +31,15 @@ #pragma warning( disable : 4761) /* disable warning re conversion */ #endif +/** Attribute error - too many attribs */ +#define AE_TOOMANY -4 +/** Attribute error - invalid name */ +#define AE_BADNAME -3 +/** Attribute error - attempt to overwrite a safe attribute */ +#define AE_SAFE -2 +/** Attribute error - general failure */ +#define AE_ERROR -1 + /* Catchall Attribute any non-standard attributes will conform to this */ ATTR *catchall; @@ -389,7 +398,7 @@ can_create_attr(dbref player, dbref obj, char const *atr_name, int flags) if (Cannot_Write_This_Attr(player, atr, obj, 1, ns_chk, lock_owner)) { free_atr_locks(atr); - return 0; + return AE_ERROR; } free_atr_locks(atr); @@ -414,7 +423,7 @@ can_create_attr(dbref player, dbref obj, char const *atr_name, int flags) if (Cannot_Write_This_Attr(player, atr, obj, 1, ns_chk, lock_owner)) { free_atr_locks(atr); missing_name[0] = '\0'; - return 0; + return AE_ERROR; } free_atr_locks(atr); *p = '`'; @@ -425,7 +434,7 @@ can_create_attr(dbref player, dbref obj, char const *atr_name, int flags) do_log(LT_ERR, player, obj, T("Attempt by %s(%d) to create too many attributes on %s(%d)"), Name(player), player, Name(obj), obj); - return 0; + return AE_TOOMANY; } return 1; @@ -529,13 +538,6 @@ atr_new_add(dbref thing, const char *RESTRICT atr, const char *RESTRICT s, } } -/** Attribute error - invalid name */ -#define AE_BADNAME -3 -/** Attribute error - attempt to overwrite a safe attribute */ -#define AE_SAFE -2 -/** Attribute error - general failure */ -#define AE_ERROR -1 - /** Add an attribute to an object, safely. * \verbatim * This is the function that should be called in hardcode to add @@ -590,9 +592,10 @@ atr_add(dbref thing, const char *RESTRICT atr, const char *RESTRICT s, /* make a new atr, if needed */ if (!ptr) { - if (!can_create_attr(player, thing, atr, flags)) { + int res = can_create_attr(player, thing, atr, flags); + if (res < 0) { ooref = tooref; - return AE_ERROR; + return res; } strcpy(missing_name, atr); @@ -1842,6 +1845,9 @@ do_set_atr(dbref thing, const char *RESTRICT atr, const char *RESTRICT s, } else notify(player, T("That attribute cannot be changed by you.")); return 0; + } else if (res == AE_TOOMANY) { + notify(player, T("Too many attributes on that object to add another.")); + return 0; } else if (!res) { notify(player, T("No such attribute to reset.")); return 0; diff --git a/src/cque.c b/src/cque.c index 300970e..6723fb4 100644 --- a/src/cque.c +++ b/src/cque.c @@ -416,14 +416,27 @@ queue_attribute_base(dbref executor, const char *atrname, dbref enactor, int noparent) { ATTR *a; - char *start, *command; - dbref powinherit = NOTHING; - dbref local_ooref; - a = (noparent ? atr_get_noparent(executor, strupper(atrname)) : - atr_get(executor, strupper(atrname))); + a = queue_attribute_getatr(executor, atrname, noparent); if (!a) return 0; + queue_attribute_useatr(executor, a, enactor); + return 1; +} + +ATTR * +queue_attribute_getatr(dbref executor, const char *atrname, int noparent) +{ + return (noparent ? atr_get_noparent(executor, strupper(atrname)) : + atr_get(executor, strupper(atrname))); +} + +int +queue_attribute_useatr(dbref executor, ATTR *a, dbref enactor) +{ + char *start, *command; + dbref powinherit = NOTHING; + dbref local_ooref; if(AL_FLAGS(a) & AF_POWINHERIT) powinherit = atr_on_obj; start = safe_atr_value(a); @@ -455,6 +468,7 @@ queue_attribute_base(dbref executor, const char *atrname, dbref enactor, return 1; } + /** Queue an entry on the wait or semaphore queues. * This function creates and adds a queue entry to the wait queue * or the semaphore queue. Wait queue entries are sorted by when