Qt character selection buglet

Testing for generic character name wasn't robust enough.  Looking
for whether "game" is a generic name would work when compared
with the list "game games" but falsely report 'no' for the list
"games game".  The first matching substring isn't followed by a
space and the routine wasn't checking for other matches in the
rest of the list.  Check again with a subset list starting after
the next space beyond the false hit; repeat as needed.
This commit is contained in:
PatR
2020-11-15 18:19:53 -08:00
parent ccb5bc4b55
commit 126d1f6bb6

View File

@@ -39,7 +39,7 @@ extern "C" {
static bool generic_plname()
{
if (*g.plname) {
const char *sptr;
const char *sptr, *p;
const char *genericusers = sysopt.genericusers;
int ln = (int) strlen(g.plname);
@@ -48,12 +48,18 @@ static bool generic_plname()
else if (!strcmp(genericusers, "*")) /* "*" => always ask for name */
return true;
if ((sptr = strstri(genericusers, g.plname)) != 0
while ((sptr = strstri(genericusers, g.plname)) != NULL) {
/* check for full word: start of list or following a space */
&& (sptr == genericusers || sptr[-1] == ' ')
/* and also preceding a space or at end of list */
&& (sptr[ln] == ' ' || sptr[ln] == '\0'))
return true;
if ((sptr == genericusers || sptr[-1] == ' ')
/* and also preceding a space or at end of list */
&& (sptr[ln] == ' ' || sptr[ln] == '\0'))
return true;
/* doesn't match full word, but maybe we got a false hit when
looking for "play" in list "player play" so keep going */
if ((p = strchr(sptr + 1, ' ')) == NULL)
break;
genericusers = p + 1;
}
}
return false;
}