Example #1
0
qbool FindBestNick (const char *nick, int flags, char *result, size_t result_len)
{
	int i, bestplayer = -1, best = 999999;
	char name[MAX_SCOREBOARDNAME], *match;

	result[0] = 0;

	for (i = 0; i < MAX_CLIENTS; i++)
	{
		if (flags & FBN_IGNORE_SPECS)
			if (cl.players[i].spectator)
				continue;
		if (flags & FBN_IGNORE_PLAYERS)
			if (!cl.players[i].spectator)
				continue;

		if (!cl.players[i].name[0])
			continue;

		strlcpy(name, cl.players[i].name, sizeof(name));
		RemoveColors (name, sizeof (name));
		for (match = name; match[0]; match++)
			match[0] = tolower(match[0]);

		if (!name[0])
			continue;

		if ((match = strstr(name, nick))  && match - name < best)
		{
			best = match - name;
			bestplayer = i;
		}
	}

	if (bestplayer != -1)
	{
		strlcpy(result, cl.players[bestplayer].name, result_len);
		return true;
	}

	if (flags & FBN_IGNORE_QTVSPECS)
		return false;

	return QTV_FindBestNick (nick, result, result_len);
}
Example #2
0
qbool QTV_FindBestNick (const char *nick, char *result, size_t result_len)
{
	int best = 999999;
	char name[128], *match;

	qtvuser_t *current = NULL, *bestplayer = NULL;

	result[0] = 0;

	for (current = qtvuserlist; current; current = current->next)
	{
		if (!current->name[0])
			continue;

		strlcpy(name, current->name, sizeof(name));
		RemoveColors(name, sizeof (name));
		for (match = name; match[0]; match++)
			match[0] = tolower(match[0]);

		if (!name[0])
			continue;

		if ((match = strstr(name, nick)) && match - name < best)
		{
			best = match - name;
			bestplayer = current;
		}
	}

	if (bestplayer)
	{
		strlcpy(result, bestplayer->name, result_len);
		return true;
	}

	return false;
}