Ticket #7479: hook-noattr.patch.txt

File hook-noattr.patch.txt, 3.9 KB (added by Talvo, 15 months ago)
Line 
1*** src/command.c.orig  Fri Oct  5 23:36:32 2007
2--- src/command.c   Tue Oct 23 19:27:09 2007
3***************
4*** 54,59 ****
5--- 54,62 ----
6  int run_hook(dbref player, dbref cause, struct hook_data *hook,
7               char *saveregs[], int save);
8 
9+ int run_hook_override(COMMAND_INFO *cmd, dbref player, const char *commandraw);
10+
11+
12  /** The list of standard commands. Additional commands can be added
13   * at runtime with add_command().
14   */
15***************
16*** 1200,1208 ****
17      /* If we have a hook/ignore that returns false, we don't do the command */
18      if (run_hook(player, cause, &cmd->hooks.ignore, saveregs, 1)) {
19        /* If we have a hook/override, we use that instead */
20!       if (!has_hook(&cmd->hooks.override) ||
21!           !one_comm_match(cmd->hooks.override.obj, player,
22!                           cmd->hooks.override.attrname, commandraw)) {
23          /* Otherwise, we do hook/before, the command, and hook/after */
24          /* But first, let's see if we had an invalid switch */
25          if (*switch_err) {
26--- 1203,1209 ----
27      /* If we have a hook/ignore that returns false, we don't do the command */
28      if (run_hook(player, cause, &cmd->hooks.ignore, saveregs, 1)) {
29        /* If we have a hook/override, we use that instead */
30!       if (!run_hook_override(cmd, player, commandraw)) {
31          /* Otherwise, we do hook/before, the command, and hook/after */
32          /* But first, let's see if we had an invalid switch */
33          if (*switch_err) {
34***************
35*** 1801,1808 ****
36  static int
37  has_hook(struct hook_data *hook)
38  {
39!   if (!hook || !GoodObject(hook->obj) || IsGarbage(hook->obj)
40!       || !hook->attrname)
41      return 0;
42    return 1;
43  }
44--- 1802,1808 ----
45  static int
46  has_hook(struct hook_data *hook)
47  {
48!   if (!hook || !GoodObject(hook->obj) || IsGarbage(hook->obj))
49      return 0;
50    return 1;
51  }
52***************
53*** 1859,1864 ****
54--- 1859,1880 ----
55    return parse_boolean(buff);
56  }
57 
58+ int
59+ run_hook_override(COMMAND_INFO *cmd, dbref player, const char *commandraw)
60+ {
61+
62+   if (!has_hook(&cmd->hooks.override))
63+     return 0;
64+
65+   if (cmd->hooks.override.attrname) {
66+     return one_comm_match(cmd->hooks.override.obj, player,
67+                           cmd->hooks.override.attrname, commandraw);
68+   } else {
69+     return atr_comm_match(cmd->hooks.override.obj, player, '$', ':', commandraw,
70+                           0, NULL, NULL, NULL);
71+   }
72+ }
73+
74  /** Set up or remove a command hook.
75   * \verbatim
76   * This is the top-level function for @hook. If an object and attribute
77***************
78*** 1905,1912 ****
79      h->obj = NOTHING;
80      mush_free(h->attrname, "hook.attr");
81      h->attrname = NULL;
82!   } else if (!obj || !*obj || !attrname || !*attrname) {
83!     notify(player, T("You must give both an object and attribute."));
84    } else {
85      dbref objdb = match_thing(player, obj);
86      if (!GoodObject(objdb)) {
87--- 1921,1933 ----
88      h->obj = NOTHING;
89      mush_free(h->attrname, "hook.attr");
90      h->attrname = NULL;
91!   } else if (!obj || !*obj
92!              || (flag != HOOK_OVERRIDE && (!attrname || !*attrname))) {
93!     if (flag == HOOK_OVERRIDE) {
94!       notify(player, T("You must give an object."));
95!     } else {
96!       notify(player, T("You must give both an object and attribute."));
97!     }
98    } else {
99      dbref objdb = match_thing(player, obj);
100      if (!GoodObject(objdb)) {
101***************
102*** 1916,1922 ****
103      h->obj = objdb;
104      if (h->attrname)
105        mush_free(h->attrname, "hook.attr");
106!     h->attrname = mush_strdup(strupper(attrname), "hook.attr");
107      notify_format(player, T("Hook set for %s"), cmd->name);
108    }
109  }
110--- 1937,1947 ----
111      h->obj = objdb;
112      if (h->attrname)
113        mush_free(h->attrname, "hook.attr");
114!     if (!attrname || !*attrname) {
115!       h->attrname = NULL;
116!     } else {
117!       h->attrname = mush_strdup(strupper(attrname), "hook.attr");
118!     }
119      notify_format(player, T("Hook set for %s"), cmd->name);
120    }
121  }