From 31d2619028723addc26fb054aa7519a6a897d9ed Mon Sep 17 00:00:00 2001 From: Rick L Bird Date: Fri, 6 May 2011 17:12:52 -0400 Subject: [PATCH] PennMUSH 1.8.3p11 Enhancement Author: talvo@talvo.com Date: Sun Nov 29 22:16:35 2009 +0000 Issue 35, @hook/list without a command shows all cmds with hooks Author: talvo@talvo.com Date: Sun Nov 29 23:01:53 2009 +0000 Fix bug in @hook/list CobraMUSH Related Adjustments: * Added Hook power as a self-checking power. CanHook() HC Macro Fixes #130 --- hdrs/mushdb.h | 2 ++ src/command.c | 73 ++++++++++++++++++++++++++++++++++++-------------- src/division.c | 3 ++- 3 files changed, 57 insertions(+), 21 deletions(-) diff --git a/hdrs/mushdb.h b/hdrs/mushdb.h index fb92648..b8be352 100644 --- a/hdrs/mushdb.h +++ b/hdrs/mushdb.h @@ -18,6 +18,8 @@ #define Builder(x) OOREF(x,TC_Builder(x), TC_Builder(ooref)) #define TC_CanModify(x,y) (x == y || div_powover(x,y,"Modify")) #define CanModify(x,y) OOREF(x,TC_CanModify(x,y), TC_CanModify(ooref,y)) +#define TC_Hook(x) (div_powover(x,x,"Hook")) +#define CanHook(x) OOREF(x, TC_Hook(x), TC_Hook(x)) #define TC_Site(x) (God(x) || div_powover(x,x,"Site") || (Inherit_Powers(x) && div_powover(Owner(x),Owner(x),"Site"))) #define Site(x) OOREF(x, TC_Site(x), TC_Site(ooref)) #define Guest(x) (LEVEL(x) == LEVEL_GUEST) /* Guest needs no twincheck */ diff --git a/src/command.c b/src/command.c index 57b62a5..ddc8437 100644 --- a/src/command.c +++ b/src/command.c @@ -2120,7 +2120,6 @@ do_hook(dbref player, char *command, char *obj, char *attrname, } } - /** List command hooks. * \verbatim * This is the top-level function for @hook/list, @list/hooks, and @@ -2134,23 +2133,57 @@ 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, T("@hook/before: #%d/%s"), - cmd->hooks.before.obj, cmd->hooks.before.attrname); - if (GoodObject(cmd->hooks.after.obj)) - notify_format(player, T("@hook/after: #%d/%s"), cmd->hooks.after.obj, - cmd->hooks.after.attrname); - if (GoodObject(cmd->hooks.ignore.obj)) - notify_format(player, T("@hook/ignore: #%d/%s"), - cmd->hooks.ignore.obj, cmd->hooks.ignore.attrname); - if (GoodObject(cmd->hooks.override.obj)) - notify_format(player, T("@hook/override: #%d/%s"), - cmd->hooks.override.obj, cmd->hooks.override.attrname); - } + if (!command || !*command) { + /* Show all commands with hooks */ + char *ptrs[BUFFER_LEN / 2]; + static char buff[BUFFER_LEN]; + char *bp; + int i, count = 0; + + for (cmd = (COMMAND_INFO *) ptab_firstentry(&ptab_command); cmd; cmd = (COMMAND_INFO *) ptab_nextentry(&ptab_command)) { + if (has_hook(&cmd->hooks.ignore) || has_hook(&cmd->hooks.override) + || has_hook(&cmd->hooks.before) || has_hook(&cmd->hooks.after)) { + ptrs[count] = (char *) cmd->name; + count++; + } + } + if (count == 0) { + notify(player, T("There are no hooks currently set.")); + return; + } + do_gensort(0, ptrs, NULL, count, ALPHANUM_LIST); + bp = buff; + safe_str(T("The following commands have hooks: "), buff, &bp); + for (i = 0; i < count; i++) { + if (gencomp((dbref) 0, ptrs[i], ptrs[i - 1], ALPHANUM_LIST) <= 0) + continue; + if (i == (count - 1) && i) + safe_str(" and ", buff, &bp); + else if (i) + safe_str(", ", buff, &bp); + safe_str(ptrs[i], buff, &bp); + } + *bp = '\0'; + notify(player, buff); + } else { + cmd = command_find(command); + if (!cmd) { + notify(player, T("No such command.")); + return; + } + if (CanHook(player)) { + if (GoodObject(cmd->hooks.before.obj)) + notify_format(player, T("@hook/before: #%d/%s"), + cmd->hooks.before.obj, cmd->hooks.before.attrname); + if (GoodObject(cmd->hooks.after.obj)) + notify_format(player, T("@hook/after: #%d/%s"), cmd->hooks.after.obj, + cmd->hooks.after.attrname); + if (GoodObject(cmd->hooks.ignore.obj)) + notify_format(player, T("@hook/ignore: #%d/%s"), + cmd->hooks.ignore.obj, cmd->hooks.ignore.attrname); + if (GoodObject(cmd->hooks.override.obj)) + notify_format(player, T("@hook/override: #%d/%s"), + cmd->hooks.override.obj, cmd->hooks.override.attrname); + } + } } diff --git a/src/division.c b/src/division.c index 0bfbb70..7965dfc 100644 --- a/src/division.c +++ b/src/division.c @@ -137,7 +137,7 @@ static struct powergroup_text_t predefined_powergroups[] = { /* PowerGroup Name */ {"Director", /* Max Powers */ - "@SU:LTE Announce Attach BCreate Boot Builder Can_NsPemit Cemit Chat Chown Combat Cron DAnnounce Division EAnnounce Empire Empower GFuncs Halt Hide Idle Join Level Link Login MailAdmin Many_Attribs Modify Newpass:2 NoPay NoQuota Nuke:LTE Open:2 Pass_Locks PCreate PEmit Poll PowerGroup:LTE Privilege PrivWho Program ProgLock:lte Pueblo_Send Quota Queue RCACHE Remote RPChat RPEmit RPTel Search See_All See_Queue SetQuotas Site SQL_Ok Summon Tel_Thing Tel_Place", + "@SU:LTE Announce Attach BCreate Boot Builder Can_NsPemit Cemit Chat Chown Combat Cron DAnnounce Division EAnnounce Empire Empower GFuncs Halt Hide Hook Idle Join Level Link Login MailAdmin Many_Attribs Modify Newpass:2 NoPay NoQuota Nuke:LTE Open:2 Pass_Locks PCreate PEmit Poll PowerGroup:LTE Privilege PrivWho Program ProgLock:lte Pueblo_Send Quota Queue RCACHE Remote RPChat RPEmit RPTel Search See_All See_Queue SetQuotas Site SQL_Ok Summon Tel_Thing Tel_Place", /* Auto Powers */ "Announce Attach BCreate Boot:2 Builder Can_NsPemit Cemit Chat Chown:2 Combat Cron DAnnounce Division EAnnounce Economy Empire Empower:2 GFuncs Halt Hide Idle Join Level:1 Link Login MailAdmin:1 Many_Attribs Modify:2 Newpass:1 NoPay NoQuota Nuke:LT Open:2 Pass_Locks PCreate PEmit Poll PowerGroup:LTE Privilege PrivWho Program ProgLock:1 Pueblo_Send Quota Queue RCACHE Remote RPChat RPEmit RPTel Search:LTE See_All Search:lte See_Queue SetQuotas Site SQL_Ok Summon Tel_Thing Tel_Place"}, @@ -199,6 +199,7 @@ static struct new_division_power_entry_t new_power_list[] = { {"GFuncs", "self"}, {"Halt", "levchk"}, {"Hide", "self"}, + {"Hook", "self"}, {"Idle", "self"}, {"Join", "levchk"}, {"Level", "levset"}, -- 2.30.2