Updated Private message Code


(VTX-aussie) #1

Lol was right under my nose cause i did it wrong in the first place.

Ok so this is what my code has been placed as
In G_cmds.h i placed this in between the the setting of the commands and the code of the commands right at the bottom though*


/*/////////////////////////////////////////////// 
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 
}

/*//////////////////////////////////////////////////////// 
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)); 
}

Went to g_local.h and found this.


	// if working on a post release patch, new variables should ONLY be inserted after this point
	// DHM - Nerve :: the above warning does not really apply to MP, but I'll follow it for good measure


	int			voiceChatSquelch;			// DHM - Nerve
	int			voiceChatPreviousTime;		// DHM - Nerve
	int			lastBurnedFrameNumber;		// JPW - Nerve   : to fix FT instant-kill exploit

and below it added in


	qboolean	ignored;					//whether or not a player has been ignored (by  admin or by a vote)

this is for the ignored command that really isnt added in the script but it makes it happy.

Then Went to around Line 1089 and in the extern vmCvar_t i added

 
extern	vmCvar_t	g_minMsgChars;

Then went to g_main.h
and found the other vmCvar_t*s
and added the code for min char’s


extern	vmCvar_t	g_minMsgChars;

and then found the commented //JPW
and added in the default setting for the cvar. which was added in so.


	{ &g_minMsgChars, "g_minMsgChars", "1", CVAR_SERVERINFO | CVAR_LATCH | CVAR_ARCHIVE, 0, qfalse  },

And i dont know if it works as of yet but it compiles without errors ill let you guys know if it does
Hope this comes in handy.
Thanx Dutch for the resource.


(vtxaussie) #2

sorry forgot to add in the command calling function in g_cmds.h
add this into your bottom code stuff of the file

	else if ((Q_stricmp(cmd, "msg") == 0) || (Q_stricmp(cmd, "pm") == 0) || (Q_stricmp(cmd, "m") == 0))	//BOTS TW - private messaging between clients
		Cmd_Pmsg_f(ent);


(dutchmeat) #3

:slight_smile: most ppl know that


(vtxaussie) #4

My bad !