'generic username' checking
Don't require the list of generic usernames in sysconf to need to be ordered to guard against false substring matches. If the list was "nethacker nethack" and the tentative character name was "nethack", it wouldn't be recognized as generic. The old code forced the list to be "nethack nethacker" for the matching to work correctly because it only checked the first matching substring. Either order works now. It also failed to recognize a generic name if the player used |nethack -u nethack-samurai-human-male-lawful because it checked for generic names before stripping off the role aspects. Now that will at least recognize the name as generic and prompt with "who are you?", but the role/race/&c info gets discarded.
This commit is contained in:
@@ -41,6 +41,7 @@
|
||||
char * visctrl (char)
|
||||
char * strsubst (char *, const char *, const char *)
|
||||
int strNsubst (char *,const char *,const char *,int)
|
||||
const char * findword (const char *,const char *,int,boolean)
|
||||
const char * ordin (int)
|
||||
char * sitoa (int)
|
||||
int sgn (int)
|
||||
@@ -615,6 +616,30 @@ strNsubst(
|
||||
return rcount;
|
||||
}
|
||||
|
||||
/* search for a word in a space-separated list; returns non-Null if found */
|
||||
const char *
|
||||
findword(
|
||||
const char *list, /* string of space-separated words */
|
||||
const char *word, /* word to try to find */
|
||||
int wordlen, /* so that it isn't required to be \0 terminated */
|
||||
boolean ignorecase) /* T: case-blind, F: case-sensitive */
|
||||
{
|
||||
const char *p = list;
|
||||
|
||||
while (p) {
|
||||
while (*p == ' ')
|
||||
++p;
|
||||
if (!*p)
|
||||
break;
|
||||
if ((ignorecase ? !strncmpi(p, word, wordlen)
|
||||
: !strncmp(p, word, wordlen))
|
||||
&& (p[wordlen] == '\0' || p[wordlen] == ' '))
|
||||
return p;
|
||||
p = strchr(p + 1, ' ');
|
||||
}
|
||||
return (const char *) 0;
|
||||
}
|
||||
|
||||
/* return the ordinal suffix of a number */
|
||||
const char *
|
||||
ordin(int n) /* note: should be non-negative */
|
||||
|
||||
Reference in New Issue
Block a user