From: Ari Johnson Date: Sat, 3 Mar 2007 00:23:29 +0000 (+0000) Subject: Better error messages from @alias X-Git-Url: https://git.theari.com/?a=commitdiff_plain;h=1f70e1b4c265162c29435ebdeaf65551c8643b73;p=cobramush.git Better error messages from @alias (cherry picked from commit c8558960236dec2524e6ac802117bae2f72c655c) --- diff --git a/hdrs/attrib.h b/hdrs/attrib.h index 2bb35e4..667718f 100644 --- a/hdrs/attrib.h +++ b/hdrs/attrib.h @@ -132,4 +132,10 @@ safe_atr_value(ATTR *atr) #define AL_WLock(alist) ((alist)->write_lock) #define AL_RLock(alist) ((alist)->read_lock) +/* Errors from ok_player_alias */ +#define OPAE_SUCCESS 1 +#define OPAE_INVALID -1 +#define OPAE_TOOMANY -2 +#define OPAE_NULL -3 + #endif /* __ATTRIB_H */ diff --git a/src/attrib.c b/src/attrib.c index d530acd..e348a0c 100644 --- a/src/attrib.c +++ b/src/attrib.c @@ -1743,16 +1743,43 @@ do_set_atr(dbref thing, const char *RESTRICT atr, const char *RESTRICT s, if (old) { /* Old alias - we're allowed to change to a different case */ strcpy(tbuf1, atr_value(old)); - if (s && (!*s || (strcasecmp(s, tbuf1) - && !ok_player_alias(s, player, thing)))) { - notify_format(player, T("'%s' is not a valid alias."), s); - return -1; + if (s && !*s) { + notify_format(player, T("'%s' is not a valid alias."), s); + return -1; + } + if (s && strcasecmp(s, tbuf1)) { + int opae_res = ok_player_alias(s, player, thing); + switch (opae_res) { + case OPAE_INVALID: + notify_format(player, T("'%s' is not a valid alias."), s); + break; + case OPAE_TOOMANY: + notify_format(player, T("'%s' contains too many aliases."), s); + break; + case OPAE_NULL: + notify_format(player, T("Null aliases are not valid.")); + break; + } + if (opae_res != OPAE_SUCCESS) + return -1; } } else { /* No old alias */ - if (s && *s && !ok_player_alias(s, player, thing)) { - notify_format(player, T("'%s' is not a valid alias."), s); - return -1; + if (s && *s) { + int opae_res = ok_player_alias(s, player, thing); + switch (opae_res) { + case OPAE_INVALID: + notify_format(player, T("'%s' is not a valid alias."), s); + break; + case OPAE_TOOMANY: + notify_format(player, T("'%s' contains too many aliases."), s); + break; + case OPAE_NULL: + notify_format(player, T("Null aliases are not valid.")); + break; + } + if (opae_res != OPAE_SUCCESS) + return -1; } } } else if (s && *s && (!strcmp(name, "FORWARDLIST") diff --git a/src/predicat.c b/src/predicat.c index 66dec55..be72f28 100644 --- a/src/predicat.c +++ b/src/predicat.c @@ -832,6 +832,7 @@ ok_player_name(const char *name, dbref player, dbref thing) * \param thing player who is being aliased. * \retval 1 alias is valid for players. * \retval 0 alias is not valid for players. + * \return One of the OPAE_* constants defined in hdrs/attrib.h */ int ok_player_alias(const char *alias, dbref player, dbref thing) @@ -840,7 +841,7 @@ ok_player_alias(const char *alias, dbref player, dbref thing) int cnt = 0; if (!alias || !*alias) - return 0; + return OPAE_NULL; strncpy(tbuf1, alias, BUFFER_LEN - 1); tbuf1[BUFFER_LEN - 1] = '\0'; @@ -850,12 +851,16 @@ ok_player_alias(const char *alias, dbref player, dbref thing) while (sp && *sp && *sp == ' ') sp++; if (!sp || !*sp) - return 0; /* No null aliases */ + return OPAE_NULL; /* No null aliases */ if (!ok_player_name(sp, player, thing)) - return 0; + return OPAE_INVALID; cnt++; } - return ((cnt <= MAX_ALIASES) || Director(player)); + if (Director(player)) + return OPAE_SUCCESS; + if (cnt > MAX_ALIASES) + return OPAE_TOOMANY; + return OPAE_SUCCESS; }