From 0f4da37c294fb10a5a826ea376a036bd4e6924a1 Mon Sep 17 00:00:00 2001 From: Ari Johnson Date: Wed, 21 Feb 2007 14:15:24 +0000 Subject: [PATCH] @function/preserve adds localize restriction; @function/restrict added to help --- game/txt/hlp/cobra_cmd.hlp | 19 +++++++++++++++---- hdrs/function.h | 2 +- src/cmds.c | 4 ++-- src/command.c | 2 +- src/function.c | 9 ++++++++- 5 files changed, 27 insertions(+), 9 deletions(-) diff --git a/game/txt/hlp/cobra_cmd.hlp b/game/txt/hlp/cobra_cmd.hlp index 5fdd351..eef513c 100644 --- a/game/txt/hlp/cobra_cmd.hlp +++ b/game/txt/hlp/cobra_cmd.hlp @@ -1484,9 +1484,11 @@ See also: PUPPET, DBREF & @function @function [] - @function =,[,, [,]] + @function[/preserve] =,[,, + [,]] or @function =/ @function/ + @function/restrict = When used without any arguments, this command lists all global user-defined functions. For Directors and others with the Functions @@ -1501,22 +1503,28 @@ See also: PUPPET, DBREF /disable, to disable a built in function. /enable, to re-enable it. /delete, to remove a user-defined function. + /restrict, to change the restriction flags on an existing function. Otherwise, this command defines a global function with the name , which evaluates to on . +(continued in help @function2) +& @function2 can be anything that the player using the @function command controls. must be 30 characters or less. -(continued in help @function2) -& @function2 A function defined using @function works just like any of the normal MUSH functions, from the user's perspective. The functions are executed by the object, with its powers. Functions defined via @function should follow the format used by UFUN() - %0 is the first argument passed, %1 is the second argument - passed, and so forth. Option third and fourth arguments to @function + passed, and so forth. Optional third and fourth arguments to @function can be used to set a parser-enforced number of arguments for the function. + An optional fifth argument will set restriction flags. + + The /preserve switch, for MUX compatibility, does the same thing as the + 'localize' restriction - treats the attribute that's evaluated as if it + were called with ulocal() instead of u(). Example: @@ -1552,6 +1560,9 @@ See also: PUPPET, DBREF @function/restore will delete the @function and turn the built in version back on. + Using @function on an already-added function will delete the old one and + install a new function with none of the settings of the old one kept. + For example: @function/delete ansi &ansi_fun #1234=%0 diff --git a/hdrs/function.h b/hdrs/function.h index 7dd56d3..a16d026 100644 --- a/hdrs/function.h +++ b/hdrs/function.h @@ -103,7 +103,7 @@ extern void do_function_restrict(dbref player, const char *name, extern void do_function_restore(dbref player, const char *name); extern void do_list_functions(dbref player, int lc); extern char *list_functions(void); -extern void do_function(dbref player, char *name, char **argv); +extern void do_function(dbref player, char *name, char **argv, int preserve); extern void do_function_toggle(dbref player, char *name, int toggle); extern void do_function_report(dbref player, char *name); extern void do_function_delete(dbref player, char *name); diff --git a/src/cmds.c b/src/cmds.c index 38024d8..96ab42c 100644 --- a/src/cmds.c +++ b/src/cmds.c @@ -430,11 +430,11 @@ COMMAND (cmd_function) { *args_right[2]++ = '\0'; } if (args_right[1] && *args_right[1]) - do_function(player, arg_left, args_right); + do_function(player, arg_left, args_right, SW_ISSET(sw, SWITCH_PRESERVE)); else if (arg_left && *arg_left) do_function_report(player, arg_left); else - do_function(player, NULL, NULL); + do_function(player, NULL, NULL, 0); if (split) { if (args_right[2]) *--args_right[2] = '/'; diff --git a/src/command.c b/src/command.c index 780472a..5a57203 100644 --- a/src/command.c +++ b/src/command.c @@ -152,7 +152,7 @@ COMLIST commands[] = { {"@FORCE", "NOEVAL", cmd_force, CMD_T_ANY | CMD_T_EQSPLIT | CMD_T_NOGAGGED, NULL}, - {"@FUNCTION", "DELETE ENABLE DISABLE RESTORE RESTRICT", cmd_function, + {"@FUNCTION", "DELETE ENABLE DISABLE PRESERVE RESTORE RESTRICT", cmd_function, CMD_T_ANY | CMD_T_EQSPLIT | CMD_T_RS_ARGS | CMD_T_NOGAGGED, NULL}, {"@GREP", "LIST PRINT ILIST IPRINT", cmd_grep, CMD_T_ANY | CMD_T_EQSPLIT | CMD_T_RS_NOPARSE | CMD_T_NOGAGGED, NULL}, diff --git a/src/function.c b/src/function.c index 5814f28..e85bc47 100644 --- a/src/function.c +++ b/src/function.c @@ -1086,9 +1086,11 @@ do_function_restrict(dbref player, const char *name, const char *restriction) * \param player the enactor. * \param name name of function to add. * \param argv array of arguments. + * \param preserve Treat the function like it was called with ulocal() instead + * of u(). */ void -do_function(dbref player, char *name, char *argv[]) +do_function(dbref player, char *name, char *argv[], int preserve) { char tbuf1[BUFFER_LEN]; char *bp = tbuf1; @@ -1202,6 +1204,8 @@ do_function(dbref player, char *name, char *argv[]) fp->flags = apply_restrictions(0, argv[5]); else fp->flags = 0; + if (preserve) + fp->flags |= FN_LOCALIZE; hashadd(name, fp, &htab_user_function); /* now add it to the user function table */ @@ -1256,10 +1260,13 @@ do_function(dbref player, char *name, char *argv[]) } else fp->maxargs = 10; + /* Set new flags */ if (argv[5] && *argv[5]) fp->flags = apply_restrictions(0, argv[5]); else fp->flags = 0; + if (preserve) + fp->flags |= FN_LOCALIZE; notify(player, T("Function updated.")); } -- 2.30.2