From: Ari Johnson Date: Tue, 20 Feb 2007 23:24:24 +0000 (+0000) Subject: new function restriction 'localize' causes q-registers to be saved and restored aroun... X-Git-Tag: 0.73~161 X-Git-Url: https://git.theari.com/?a=commitdiff_plain;h=97407ca437e4dfd756f8efe762cc1f5213a879ac;p=cobramush.git new function restriction 'localize' causes q-registers to be saved and restored around the function as if localize() or ulocal() were used; aliased to 'ulocal' restriction --- diff --git a/game/txt/hlp/cobratop.hlp b/game/txt/hlp/cobratop.hlp index 4f095c1..82f767a 100644 --- a/game/txt/hlp/cobratop.hlp +++ b/game/txt/hlp/cobratop.hlp @@ -1925,6 +1925,8 @@ player who runs it instead of a generic, unhelpful error message. to @command or @function. noparse Function arguments are not evaluated. Only applies to @functions. + localize %q-registers are saved/restored when evaluating, as if + the @function were wrapped in localize(). Commands can also use the 'noplayer' restriction, which stops player objects from using the command, as well as any generic diff --git a/hdrs/function.h b/hdrs/function.h index 6e91f23..7dd56d3 100644 --- a/hdrs/function.h +++ b/hdrs/function.h @@ -33,8 +33,8 @@ #define FN_LOGNAME 0x1000 /* Log function name and args */ #define FN_LOGARGS 0x2000 -/* Run Function Ulocal Style */ -#define FN_ULOCAL 0x4000 +/* Localize function registers */ +#define FN_LOCALIZE 0x4000 #define FN_NORP 0x8000 #define FN_ONEARG 0x10000 diff --git a/src/function.c b/src/function.c index bb51ae0..8ed66b2 100644 --- a/src/function.c +++ b/src/function.c @@ -994,8 +994,10 @@ apply_restrictions(unsigned int result, const char *restriction) flag = FN_LOGNAME; } else if (!strcasecmp(restriction, "noparse")) { flag = FN_NOPARSE; - } else if(!strcasecmp(restriction, "ulocal")) { - flag = FN_ULOCAL; + } else if (!strcasecmp(restriction, "localize")) { + flag = FN_LOCALIZE; + } else if (!strcasecmp(restriction, "ulocal")) { + flag = FN_LOCALIZE; } if (clear) result &= ~flag; @@ -1021,6 +1023,7 @@ apply_restrictions(unsigned int result, const char *restriction) * god can only be used by god * noplayer can't be used by players, just objects/rooms/exits * nosidefx can't be used to do side-effect thingies + * localize localize q-registers * \endverbatim * \param name name of function to restrict. * \param restriction name of restriction to apply to function. @@ -1470,10 +1473,11 @@ do_function_report(dbref player, char *name) first = 0; } - if(fp->flags & FN_ULOCAL) { - safe_str("Ulocal", tbuf, &tp); - if(first) - first = 0; + if (fp->flags & FN_LOCALIZE) { + if (first == 0) + safe_strl(", ", 2, tbuf, &tp); + safe_str("Localize", tbuf, &tp); + first = 0; } if (fp->flags & FN_LITERAL) { diff --git a/src/parse.c b/src/parse.c index 30282fc..0fab687 100644 --- a/src/parse.c +++ b/src/parse.c @@ -467,7 +467,6 @@ process_expression(char *buff, char **bp, char const **str, int e_len; int retval = 0; const char *e_msg; - dbref local_ooref; if (!buff || !bp || !str || !*str) return 0; @@ -1271,24 +1270,18 @@ process_expression(char *buff, char **bp, char const **str, safe_str(userfn_tab[fp->where.offset].name, buff, bp); safe_chr(')', buff, bp); } else { - /* Open temporary ooref change exception */ - /* local ooref changing should be safe here. - * Cause we're going to the global func scope, any - * previous calling ooref shouldn't effect security here - */ + char *preserve[NUMQ]; + dbref local_ooref; + if (fp->flags & FN_LOCALIZE) + save_global_regs("@function.save", preserve); + /* Temporarily change ooref */ local_ooref = ooref; ooref = attrib->creator; - if(fp->flags & FN_ULOCAL) { - char *preserve[NUMQ]; - save_global_regs("globalufun.save", preserve); - do_userfn(buff, bp, thing, attrib, nfargs, fargs, - executor, caller, enactor, pe_info); - restore_global_regs("globalufun.save", preserve); - } else { - do_userfn(buff, bp, thing, attrib, nfargs, fargs, executor, caller, enactor, pe_info); - } - /* Go back to normal ooref status */ + do_userfn(buff, bp, thing, attrib, nfargs, fargs, + executor, caller, enactor, pe_info); ooref = local_ooref; + if (fp->flags & FN_LOCALIZE) + restore_global_regs("@function.save", preserve); } } pe_info->fun_depth--;