From bdebde972ca1233f7a8b56eef7bc6e11ff5b9112 Mon Sep 17 00:00:00 2001 From: Ari Johnson Date: Wed, 21 Feb 2007 01:00:35 +0000 Subject: [PATCH] @hook/list --- game/txt/hlp/cobra_cmd.hlp | 3 +- hdrs/game.h | 1 + src/cmds.c | 5 +++- src/command.c | 56 ++++++++++++++++++++++++++------------ 4 files changed, 45 insertions(+), 20 deletions(-) diff --git a/game/txt/hlp/cobra_cmd.hlp b/game/txt/hlp/cobra_cmd.hlp index 884c36b..7c71fb6 100644 --- a/game/txt/hlp/cobra_cmd.hlp +++ b/game/txt/hlp/cobra_cmd.hlp @@ -1656,6 +1656,7 @@ See also: HAVEN, page, @lock, @away See also: enter, @enter, ENTER_OK, @describe, look, @idescformat & @hook @hook/ [=, ] + @hook/list @hook tells the command parser to evaluate given attributes at certain points in command evaluation. The possible points, indicated by the proper switch: @@ -1681,7 +1682,7 @@ See also: enter, @enter, ENTER_OK, @describe, look, @idescformat the hooks. Leaving out the object and attribute clears an existing hook. Directors can - see existing hooks with @command. + see existing hooks with @command or @hook/list. See HELP @HOOK2 for an example. & @hook2 diff --git a/hdrs/game.h b/hdrs/game.h index 1731c6d..6d7f4c4 100644 --- a/hdrs/game.h +++ b/hdrs/game.h @@ -47,6 +47,7 @@ extern int do_signal_qid(dbref signalby, int qid, enum qid_flags qid_flags, int enum hook_type { HOOK_BEFORE, HOOK_AFTER, HOOK_IGNORE, HOOK_OVERRIDE }; extern void do_hook(dbref player, char *command, char *obj, char *attrname, enum hook_type flag); +extern void do_hook_list(dbref player, char *command); /* From compress.c */ diff --git a/src/cmds.c b/src/cmds.c index f74131d..38024d8 100644 --- a/src/cmds.c +++ b/src/cmds.c @@ -472,7 +472,10 @@ COMMAND (cmd_hook) { flags = HOOK_IGNORE; else if (SW_ISSET(sw, SWITCH_OVERRIDE)) flags = HOOK_OVERRIDE; - else { + else if (SW_ISSET(sw, SWITCH_LIST)) { + do_hook_list(player, arg_left); + return; + } else { notify(player, T("You must give a switch for @hook")); return; } diff --git a/src/command.c b/src/command.c index 052534e..780472a 100644 --- a/src/command.c +++ b/src/command.c @@ -158,7 +158,8 @@ COMLIST commands[] = { CMD_T_ANY | CMD_T_EQSPLIT | CMD_T_RS_NOPARSE | CMD_T_NOGAGGED, NULL}, {"@HALT", "ALL", cmd_halt, CMD_T_ANY | CMD_T_EQSPLIT, NULL}, {"@HIDE", "NO OFF YES ON", cmd_hide, CMD_T_ANY, NULL}, - {"@HOOK", "AFTER BEFORE IGNORE OVERRIDE", cmd_hook, CMD_T_ANY | CMD_T_EQSPLIT | CMD_T_RS_ARGS, + {"@HOOK", "LIST AFTER BEFORE IGNORE OVERRIDE", cmd_hook, + CMD_T_ANY | CMD_T_EQSPLIT | CMD_T_RS_ARGS, "POWER^SITE"}, {"@KICK", NULL, cmd_kick, CMD_T_ANY, "POWER^SITE"}, @@ -1647,23 +1648,7 @@ COMMAND (cmd_command) { *bp = '\0'; notify_format(player, "Arguments : %s", buff); } - if (Site(player)) { - if (GoodObject(command->hooks.before.obj)) - notify_format(player, "@hook/before: #%d/%s", - command->hooks.before.obj, - command->hooks.before.attrname); - if (GoodObject(command->hooks.after.obj)) - notify_format(player, "@hook/after: #%d/%s", command->hooks.after.obj, - command->hooks.after.attrname); - if (GoodObject(command->hooks.ignore.obj)) - notify_format(player, "@hook/ignore: #%d/%s", - command->hooks.ignore.obj, - command->hooks.ignore.attrname); - if (GoodObject(command->hooks.override.obj)) - notify_format(player, "@hook/override: #%d/%s", - command->hooks.override.obj, - command->hooks.override.attrname); - } + do_hook_list(player, arg_left); } } @@ -1926,3 +1911,38 @@ do_hook(dbref player, char *command, char *obj, char *attrname, notify_format(player, T("Hook set for %s"), cmd->name); } } + + +/** List command hooks. + * \verbatim + * This is the top-level function for @hook/list, @list/hooks, and + * the hook-listing part of @command. + * \endverbatim + * \param player the enactor. + * \param command command to list hooks on. + */ +void +do_hook_list(dbref player, char *command) +{ + COMMAND_INFO *cmd; + + cmd = command_find(command); + if (!cmd) { + notify(player, T("No such command.")); + return; + } + if (Site(player)) { + if (GoodObject(cmd->hooks.before.obj)) + notify_format(player, "@hook/before: #%d/%s", + cmd->hooks.before.obj, cmd->hooks.before.attrname); + if (GoodObject(cmd->hooks.after.obj)) + notify_format(player, "@hook/after: #%d/%s", cmd->hooks.after.obj, + cmd->hooks.after.attrname); + if (GoodObject(cmd->hooks.ignore.obj)) + notify_format(player, "@hook/ignore: #%d/%s", + cmd->hooks.ignore.obj, cmd->hooks.ignore.attrname); + if (GoodObject(cmd->hooks.override.obj)) + notify_format(player, "@hook/override: #%d/%s", + cmd->hooks.override.obj, cmd->hooks.override.attrname); + } +} -- 2.30.2