PennMUSH Community

Changeset 1202

Show
Ignore:
Timestamp:
01/19/08 23:11:34 (9 months ago)
Author:
shawnw
Message:

#7479: @hook/override enhancment.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • 1.8.3/branches/devel/CHANGES.183

    r1199 r1202  
    2626   are changed and automatically reload them instead of waiting for a  
    2727   @readcache. 
     28 * '@hook/override cmd=#1234' will look at all attributes on the object 
     29   for a matching $command. By Talvo. 
    2830 
    2931Functions: 
  • 1.8.3/branches/devel/src/command.c

    r1177 r1202  
    6868int run_hook(dbref player, dbref cause, struct hook_data *hook, 
    6969             char *saveregs[], int save); 
     70 
     71int run_hook_override(COMMAND_INFO *cmd, dbref player, const char *commandraw); 
     72 
    7073 
    7174/** The list of standard commands. Additional commands can be added 
     
    13431346    if (run_hook(player, cause, &cmd->hooks.ignore, saveregs, 1)) { 
    13441347      /* If we have a hook/override, we use that instead */ 
    1345       if (!has_hook(&cmd->hooks.override) || 
    1346           !one_comm_match(cmd->hooks.override.obj, player, 
    1347                           cmd->hooks.override.attrname, commandraw)) { 
     1348      if (!run_hook_override(cmd, player, commandraw)) { 
    13481349        /* Otherwise, we do hook/before, the command, and hook/after */ 
    13491350        /* But first, let's see if we had an invalid switch */ 
     
    19481949has_hook(struct hook_data *hook) 
    19491950{ 
    1950   if (!hook || !GoodObject(hook->obj) || IsGarbage(hook->obj) 
    1951       || !hook->attrname) 
     1951  if (!hook || !GoodObject(hook->obj) || IsGarbage(hook->obj)) 
    19521952    return 0; 
    19531953  return 1; 
     
    20042004  mush_free(code, "hook.code"); 
    20052005  return parse_boolean(buff); 
     2006} 
     2007 
     2008int 
     2009run_hook_override(COMMAND_INFO *cmd, dbref player, const char *commandraw) 
     2010{ 
     2011 
     2012  if (!has_hook(&cmd->hooks.override)) 
     2013    return 0; 
     2014 
     2015  if (cmd->hooks.override.attrname) { 
     2016    return one_comm_match(cmd->hooks.override.obj, player, 
     2017                          cmd->hooks.override.attrname, commandraw); 
     2018  } else { 
     2019    return atr_comm_match(cmd->hooks.override.obj, player, '$', ':', commandraw, 
     2020                          0, NULL, NULL, NULL); 
     2021  } 
    20062022} 
    20072023 
     
    20522068    mush_free(h->attrname, "hook.attr"); 
    20532069    h->attrname = NULL; 
    2054   } else if (!obj || !*obj || !attrname || !*attrname) { 
    2055     notify(player, T("You must give both an object and attribute.")); 
     2070  } else if (!obj || !*obj 
     2071             || (flag != HOOK_OVERRIDE && (!attrname || !*attrname))) { 
     2072    if (flag == HOOK_OVERRIDE) { 
     2073      notify(player, T("You must give an object.")); 
     2074    } else { 
     2075      notify(player, T("You must give both an object and attribute.")); 
     2076    } 
    20562077  } else { 
    20572078    dbref objdb = match_thing(player, obj); 
     
    20632084    if (h->attrname) 
    20642085      mush_free(h->attrname, "hook.attr"); 
    2065     h->attrname = mush_strdup(strupper(attrname), "hook.attr"); 
     2086    if (!attrname || !*attrname) { 
     2087      h->attrname = NULL; 
     2088    } else { 
     2089      h->attrname = mush_strdup(strupper(attrname), "hook.attr"); 
     2090    } 
    20662091    notify_format(player, T("Hook set for %s"), cmd->name); 
    20672092  }