From f3e708f2d35966760bae95dc380121dea134f78c Mon Sep 17 00:00:00 2001 From: Ari Johnson Date: Wed, 21 Feb 2007 01:18:10 +0000 Subject: [PATCH] @flag/alias flag=!alias deletes an alias --- game/txt/hlp/cobra_cmd.hlp | 2 +- src/flags.c | 49 ++++++++++++++++++++++++++++---------- 2 files changed, 37 insertions(+), 14 deletions(-) diff --git a/game/txt/hlp/cobra_cmd.hlp b/game/txt/hlp/cobra_cmd.hlp index 7c71fb6..ac673ae 100644 --- a/game/txt/hlp/cobra_cmd.hlp +++ b/game/txt/hlp/cobra_cmd.hlp @@ -1432,7 +1432,7 @@ See also: PUPPET, DBREF All other switches to this command are restricted to God: /disable disables a flag, making it invisible and unusable /enable re-enables a disabled flag - /alias adds a new alias for an existing flag + /alias adds a new alias for an existing flag; use ! to delete one. /letter changes or removes a single-letter alias for an existing flag. /restrict changes flag permissions (see help @flag2) /type changes flag type(s) (see help @flag2) diff --git a/src/flags.c b/src/flags.c index 31f1082..a4b28b3 100644 --- a/src/flags.c +++ b/src/flags.c @@ -2222,8 +2222,9 @@ do_flag_add(dbref player, const char *name, char *args_right[]) void do_flag_alias(dbref player, const char *name, const char *alias) { - FLAG *f; + FLAG *f, *af; FLAGSPACE *n; + int delete = 0; if (!Director(player)) { notify(player, T("You don't look like God.")); return; @@ -2232,7 +2233,11 @@ do_flag_alias(dbref player, const char *name, const char *alias) notify(player, T("You must provide a name for the alias.")); return; } - if (strlen(alias) == 1) { + if (*alias == '!') { + delete = 1; + alias++; + } + if (strlen(alias) <= 1) { notify(player, T("Flag aliases must be longer than one character.")); return; } @@ -2241,10 +2246,10 @@ do_flag_alias(dbref player, const char *name, const char *alias) return; } n = hashfind("FLAG", &htab_flagspaces); - f = match_flag_ns(n, alias); - if (f) { + af = match_flag_ns(n, alias); + if (!delete && af) { notify_format(player, T("That alias already matches the %s flag."), - f->name); + af->name); return; } f = match_flag_ns(n, name); @@ -2256,14 +2261,32 @@ do_flag_alias(dbref player, const char *name, const char *alias) notify(player, T("That flag is disabled.")); return; } - /* Insert the flag in the ptab by the given alias */ - ptab_start_inserts(n->tab); - ptab_insert(n->tab, alias, f); - ptab_end_inserts(n->tab); - if ((f = match_flag_ns(n, alias))) - do_flag_info("FLAG", player, alias); - else - notify(player, T("Unknown failure adding alias.")); + if (delete && !af) { + notify_format(player, T("That isn't an alias of the %s flag."), + f->name); + return; + } + if (delete) { + /* Delete the alias in the ptab if it's really an alias! */ + if (!strcasecmp(n->flags[f->bitpos]->name, alias)) { + notify(player, T("That's the flag's name, not an alias.")); + return; + } + ptab_delete(n->tab, alias); + if ((af = match_flag_ns(n, alias))) + notify(player, T("Unknown failure deleting alias.")); + else + do_flag_info("FLAG", player, f->name); + } else { + /* Insert the flag in the ptab by the given alias */ + ptab_start_inserts(n->tab); + ptab_insert(n->tab, alias, f); + ptab_end_inserts(n->tab); + if ((f = match_flag_ns(n, alias))) + do_flag_info("FLAG", player, alias); + else + notify(player, T("Unknown failure adding alias.")); + } } /** Change a flag's alias. -- 2.30.2