r737 - trunk/code/server

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Tue May 2 17:20:07 EDT 2006


Author: thilo
Date: 2006-05-02 17:20:07 -0400 (Tue, 02 May 2006)
New Revision: 737

Modified:
   trunk/code/server/sv_ccmds.c
Log:
- Replaced SV_GetPlayerByName with SV_GetPlayerByHandle that supports lookup of client_t structures by playernum, too.
  That means the ban and kick commands will now accept the playernum - as seen in the status command - as argument.


Modified: trunk/code/server/sv_ccmds.c
===================================================================
--- trunk/code/server/sv_ccmds.c	2006-05-02 17:53:26 UTC (rev 736)
+++ trunk/code/server/sv_ccmds.c	2006-05-02 21:20:07 UTC (rev 737)
@@ -34,12 +34,12 @@
 
 /*
 ==================
-SV_GetPlayerByName
+SV_GetPlayerByHandle
 
-Returns the player with name from Cmd_Argv(1)
+Returns the player with player id or name from Cmd_Argv(1)
 ==================
 */
-static client_t *SV_GetPlayerByName( void ) {
+static client_t *SV_GetPlayerByHandle( void ) {
 	client_t	*cl;
 	int			i;
 	char		*s;
@@ -57,6 +57,23 @@
 
 	s = Cmd_Argv(1);
 
+	// Check whether this is a numeric player handle
+	for(i = 0; s[i] >= '0' && s[i] <= '9'; i++);
+	
+	if(!s[i])
+	{
+		int plid = atoi(s);
+
+		// Check for numeric playerid match
+		if(plid >= 0 && plid < sv_maxclients->integer)
+		{
+			cl = &svs.clients[plid];
+			
+			if(cl->state)
+				return cl;
+		}
+	}
+
 	// check for a name match
 	for ( i=0, cl=svs.clients ; i < sv_maxclients->integer ; i++,cl++ ) {
 		if ( !cl->state ) {
@@ -343,7 +360,7 @@
 		return;
 	}
 
-	cl = SV_GetPlayerByName();
+	cl = SV_GetPlayerByHandle();
 	if ( !cl ) {
 		if ( !Q_stricmp(Cmd_Argv(1), "all") ) {
 			for ( i=0, cl=svs.clients ; i < sv_maxclients->integer ; i++,cl++ ) {
@@ -402,7 +419,7 @@
 		return;
 	}
 
-	cl = SV_GetPlayerByName();
+	cl = SV_GetPlayerByHandle();
 
 	if (!cl) {
 		return;
@@ -681,7 +698,7 @@
 		return;
 	}
 
-	cl = SV_GetPlayerByName();
+	cl = SV_GetPlayerByHandle();
 	if ( !cl ) {
 		return;
 	}




More information about the quake3-commits mailing list