View Single Post
Old 09-03-2006, 10:43 AM   #107
=X=Master HeX
 
=X=Master HeX's Avatar
 
Join Date: Dec 2002
Location: Lake Villa, IL.
Posts: 117
Quote:
Originally Posted by ensiform
setting forcepowers to something illegal can cause a crash after forcechanged and respawn.
This is caused by a malformed forcepower string. To fix this we need to take any garbage the client sends us and turn it into a real forcepower string. A real forcepower string looks like #-#-##################. To do this we try to read anything the client gives us and then we fill in the blanks.

Add the following somewhere:
Code:
void FR_NormalizeForcePowers(char *powerOut, int powerLen)
{
	char powerBuf[128];
	char readBuf[2];
	int finalPowers[21] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
	int i, c;

	if (powerLen >= 128 || powerLen < 1)
	{ //This should not happen. If it does, this is obviously a bogus string.
		//They can have this string. Because I said so.
		strcpy(powerBuf, "7-1-032330000000001333");
	}
	else
	{
		Q_strncpyz(powerBuf, powerOut, sizeof(powerBuf)); //copy it as the original
	}

	c = 0;
	i = 0;
	while (i < powerLen && i < 128 && powerBuf[i] && powerBuf[i] != '\n' && powerBuf != '\0' && c < NUM_FORCE_POWERS+2)
	{
		if (powerBuf[i] != '-')
		{
			readBuf[0] = powerBuf[i];
			readBuf[1] = 0;
			finalPowers[c] = atoi(readBuf);
			c++;
		}
		i++;
	}

	strcpy(powerOut, va("%i-%i-%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i\0",
						finalPowers[0], finalPowers[1], finalPowers[2], 
						finalPowers[3], finalPowers[4], finalPowers[5], 
						finalPowers[6], finalPowers[7], finalPowers[8], 
						finalPowers[9], finalPowers[10], finalPowers[11], 
						finalPowers[12], finalPowers[13], finalPowers[14], 
						finalPowers[15], finalPowers[16], finalPowers[17], 
						finalPowers[18], finalPowers[19], finalPowers[20]));
}
In g_client.c, look for:
Code:
	Q_strncpyz( forcePowers, Info_ValueForKey (userinfo, "forcepowers"), sizeof( forcePowers ) );
replace with:
Code:
	if (!(ent->r.svFlags & SVF_BOT))
	{ // clients could have a bad forcepower string
		char *n;
		n = Info_ValueForKey (userinfo, "forcepowers");
		FR_NormalizeForcePowers(n, strlen(n));
		strcpy( forcePowers, n );
	}
	else
	{
		Q_strncpyz( forcePowers, Info_ValueForKey (userinfo, "forcepowers"), sizeof( forcePowers ) );
	}
in w_force.c, look for:
Code:
	Q_strncpyz( forcePowers, Info_ValueForKey (userinfo, "forcepowers"), sizeof( forcePowers ) );
replace with:
Code:
	if (!(ent->r.svFlags & SVF_BOT))
	{
		char *s;
		s = Info_ValueForKey (userinfo, "forcepowers");
		FR_NormalizeForcePowers(s, strlen(s));
		strcpy( forcePowers, s );
	}
	else
	{
		Q_strncpyz( forcePowers, Info_ValueForKey (userinfo, "forcepowers"), sizeof( forcePowers ) );
	}
**EDIT** Fixed to correct bot name issues.


Last edited by =X=Master HeX; 09-04-2006 at 05:33 PM.
=X=Master HeX is offline   you may: quote & reply,