PennMUSH 1.8.3p11 Enhancement
authorRick L Bird <nveid@yahoo.com>
Fri, 6 May 2011 21:12:52 +0000 (17:12 -0400)
committerRick L Bird <nveid@yahoo.com>
Fri, 6 May 2011 21:16:52 +0000 (17:16 -0400)
Author: talvo@talvo.com <talvo@talvo.com@ba372814-4f39-11de-9ad6-1127a62b9fcd>
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 <talvo@talvo.com@ba372814-4f39-11de-9ad6-1127a62b9fcd>
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
src/command.c
src/division.c

index fb9264859b5eebbe8e9eb74c4b007fd6e52eece8..b8be3521e882d9bde1cb0233e2f5b2d1d1da4f55 100644 (file)
@@ -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 */
index 57b62a58b10abd74134775e95339d3cf3845b6a7..ddc8437984fb67c5b72bd260d4b88cbe0ac3ff60 100644 (file)
@@ -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);
+               }
+       }
 }
index 0bfbb70b7b5607876689e38e17eb82f286cb4cc5..7965dfc08b3f6116183f7cb9d9a50d12fd6ce824 100644 (file)
@@ -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"},