g_cmds…
/*///////////////////////////////////////////////
ClientNumberFromNameMatch
This function does what the name says - it takes
a string representing a partial name, and returns the
client numbers of all the players whose names contain
that string. The client numbers are stored in 'matches'
and the number of matches is returned. This function does
all the string handling you should need, so it is safe to pass
unformatted names to it
*////////////////////////////////////////////////
int ClientNumberFromNameMatch(char *name, int *matches)
{
int i, textLen;
char nm[32];
char c;
int index = 0;
Q_strncpyz(nm, name, sizeof(nm)); //copy the name match
Q_CleanStr(nm); //get rid of any color codes etc
textLen = strlen(nm);
c = *nm; //the first letter of the name match
for (i = 0; i < level.maxclients; i++) //loop through all the possible clients
{
int j, len;
char playerName[32];
if ((!g_entities[i].client) || (g_entities[i].client->pers.connected != CON_CONNECTED)) //if this client isn't connected, skip them
continue;
Q_strncpyz(playerName, g_entities[i].client->pers.netname, sizeof(playerName)); //copy the player's name
Q_CleanStr(playerName); //remove any color codes etc
len = strlen(playerName);
for (j = 0; j < len; j++) //go through the player's name letter by letter
{
if (tolower© == tolower(playerName[j])) //compare the first letter of the name match to each letter in the player's name
{
//if they're the same, check to see if the whole name match can be found
if (!Q_stricmpn(nm, playerName+j, textLen))
{
matches[index] = i; //we have a match, so record the client number
index++; //increment the index counter
break; //break out of the 'j' FOR loop because we already matched this client
}
}
}
}
return index; //return the number of matched client names
}
and this:
/*////////////////////////////////////////////////////////
Cmd_Pmsg_f
This command allows one player to send a 'private' message (text only)
to another player or players. The message is sent to all players whose
names contain the match string provided by the sender. This command is
not subject to spam rules governing text-only messages, but cannot be
used by people who are ignored.
*/////////////////////////////////////////////////////////
void Cmd_Pmsg_f(gentity_t *ent)
{
char cmd[MAX_TOKEN_CHARS];
char name[MAX_STRING_CHARS];
char nameList[MAX_STRING_CHARS];
char *msg;
int matchList[MAX_CLIENTS];
int count, i;
if (trap_Argc() < 3)
{
trap_Argv(0, cmd, sizeof(cmd)); //just for consistency, display the command they entered
trap_SendServerCommand(ent-g_entities, va("print \"Usage: %s <match> <message>
\"", cmd));
return;
}
if (ent->ignored) //ignored people can't do ANY kind of talking
{
trap_SendServerCommand(ent-g_entities, va("print \"^3You are ignored. Chat cancelled
\""));
return;
}
trap_Argv(1, name, sizeof(name));
if (strlen(name) < g_minMsgChars.integer) //make sure they entered a long enough name match
{
trap_SendServerCommand(ent-g_entities, va("print \"You must match at least %i characters of the name
\"", g_minMsgChars.integer));
return;
}
count = ClientNumberFromNameMatch(name, matchList);
if (count == 0)
{
trap_SendServerCommand(ent-g_entities, va("print \"No matching clients found
\""));
return;
}
msg = ConcatArgs(2); //get the whole message
//loop through all the matching clients and display the message for them
for (i = 0; i < count; i++)
{
strcat(nameList, g_entities[matchList[i]].client->pers.netname); //add their name to a list
if (i != (count-1))
strcat(nameList, "^7, ");
//if the message is short enough to fit in the talk space of the window, display it there
if ((strlen(msg) + strlen(va("Message from %s^7: ^3", ent->client->pers.netname))) < MAX_SAY_TEXT)
trap_SendServerCommand(matchList[i], va("chat \"Message from %s^7: ^3%s\" 0", ent->client->pers.netname, msg));
else //otherwise, print it in the console, and notify the recipient(s) that they received a message there
{
trap_SendServerCommand(matchList[i], va("print \"Message from %s^7: ^3%s
\"", ent->client->pers.netname, msg));
trap_SendServerCommand(matchList[i], va("print \"Message from %s^7: ^3Check your console
\"", ent->client->pers.netname));
}
}
//let the sender know who his message went to
trap_SendServerCommand(ent-g_entities, va("print \"Message to %s: %s
\"", nameList, msg));
}