cvar cheat protection

This commit is contained in:
Scott Brooks 2001-09-16 04:04:31 +00:00
parent c0bef62b6e
commit cbd8ffcde8
12 changed files with 223 additions and 32 deletions

View file

@ -120,6 +120,15 @@ typedef enum {
IMPACTSOUND_FLESH
} impactSound_t;
//Blaze: anti cheat stuff
typedef struct {
char cvar[40];
float low;
float high;
} cheat_cvar;
//=================================================
// player entities need to track more information
@ -1341,6 +1350,8 @@ extern vmCvar_t cg_recordSPDemo;
extern vmCvar_t cg_recordSPDemoName;
extern vmCvar_t cg_obeliskRespawnDelay;
#endif
//Blaze: Cheat cvars
extern cheat_cvar cheats[30];
//
// cg_main.c

View file

@ -198,6 +198,8 @@ vmCvar_t cg_recordSPDemo;
vmCvar_t cg_recordSPDemoName;
vmCvar_t cg_obeliskRespawnDelay;
#endif
//Blaze: cheat struct
cheat_cvar cheats[30];
typedef struct {
vmCvar_t *vmCvar;

View file

@ -232,6 +232,8 @@ A respawn happened this snapshot
================
*/
void CG_Respawn( void ) {
int i=0;
float cvar_val;
// no error decay on player movement
cg.thisFrameTeleport = qtrue;
@ -245,6 +247,8 @@ void CG_Respawn( void ) {
CG_RQ3_Zoom1x();
cg.curSyncSound = 0;
}
extern char *eventnames[];

View file

@ -1056,6 +1056,45 @@ static void CG_ServerCommand( void ) {
cg.levelShot = qtrue;
return;
}
//Blaze: Dont think q3 can do
/*if ( !strcmp( cmd, "numCheatVars" ) )
{//set and clear the cheatvar structure
int numCheats;
numCheats = atoi(CG_Argv(1));
return;
}*/
if ( !strcmp( cmd, "delCheatVar" ) )
{//remove a cvar from the list of cheat variables
//not needed now, mabey later?
return;
}
if ( !strcmp( cmd, "addCheatVar" ) )
{//add a cvar from the list of cheat variables
char param[128];
int i;
float lowend, highend;
Q_strncpyz( param, CG_Argv(1), 128 );
lowend = atof(CG_Argv(2));
highend = atof(CG_Argv(3));
//CG_Printf("1) %s %f %f\n", param, lowend, highend);
for (i=0;i<30; i++)
{
if (!strcmp(cheats[i].cvar, NULL))
{
Q_strncpyz( cheats[i].cvar, param, 40 );
cheats[i].high = highend;
cheats[i].low = lowend;
//CG_Printf("2) %s %f %f\n", cheats[i].cvar, cheats[i].low, cheats[i].high);
return;
}
}
return;
}
if ( !strcmp( cmd, "selectpistol") ) {
//CG_Printf("Selecting pistol\n");

View file

@ -3,6 +3,13 @@
// cg_view.c -- setup all the parameters (position, angle, etc)
// for a 3D rendering
#include "cg_local.h"
//Blaze: Should come in handy for cheat detection
static float CG_Cvar_Get(const char *cvar) {
char buff[128];
memset(buff, 0, sizeof(buff));
trap_Cvar_VariableStringBuffer(cvar, buff, sizeof(buff));
return atof(buff);
}
/*
@ -943,6 +950,10 @@ Generates and draws a game scene and status information at the given time.
void CG_DrawActiveFrame( int serverTime, stereoFrame_t stereoView, qboolean demoPlayback ) {
int inwater;
//Blaze: for cheat detection
int i;
float cvar_val;
//end Blaze
cg.time = serverTime;
cg.demoPlayback = demoPlayback;
@ -1057,6 +1068,24 @@ void CG_DrawActiveFrame( int serverTime, stereoFrame_t stereoView, qboolean demo
CG_Printf( "cg.clientFrame:%i\n", cg.clientFrame );
}
if ((cg.time - cgs.levelStartTime) / 10000 == 1)
{
//Blaze: Check for invalid video settings.
for(i=0;i<30;i++)
{
if (strcmp(cheats[i].cvar, NULL)!=0)
{
cvar_val = CG_Cvar_Get(cheats[i].cvar);
//CG_Printf("%s is set to %f\n",cheats[i].cvar, cvar_val);
if ( cvar_val < cheats[i].low || cvar_val > cheats[i].high)
{
CG_Printf("This server restricts %s to be between %f and %f\n",cheats[i].cvar,cheats[i].low, cheats[i].high);
trap_SendConsoleCommand(va("disconnect\n"));
}
}
}
}
}

View file

@ -137,13 +137,14 @@ static qboolean CG_ParseWeaponSoundFile( const char *filename, weaponInfo_t *wea
CG_ParseWeaponAnimFile
==========================
*/
static qboolean CG_ParseWeaponAnimFile( const char *filename, weaponInfo_t *weapon ) {
static qboolean CG_ParseWeaponAnimFile( const char *filename, weaponInfo_t *weapon )
{
char *text_p;
int len;
int i;
int skip;
char *token;
float fps;
int skip;
char text[20000];
fileHandle_t f;
animation_t *animations;

View file

@ -6,14 +6,14 @@
--------------------Configuration: cgame - Win32 Debug--------------------
</h3>
<h3>Command Lines</h3>
Creating temporary file "C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\RSP2EA.tmp" with contents
Creating temporary file "C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\RSP2D3.tmp" with contents
[
/nologo /G5 /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /FR"Debug/" /Fp"Debug/cgame.pch" /YX /Fo"Debug/" /Fd"Debug/" /FD /c
"c:\reaction\cgame\cg_weapons.c"
"c:\reaction\ui\ui_shared.c"
"c:\reaction\cgame\cg_main.c"
"c:\reaction\cgame\cg_playerstate.c"
]
Creating command line "cl.exe @C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\RSP2EA.tmp"
Creating temporary file "C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\RSP2EB.tmp" with contents
Creating command line "cl.exe @C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\RSP2D3.tmp"
Creating temporary file "C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\RSP2D4.tmp" with contents
[
/nologo /base:"0x30000000" /subsystem:windows /dll /incremental:yes /pdb:"Debug/cgamex86.pdb" /map:"Debug/cgamex86.map" /debug /machine:I386 /def:".\cgame.def" /out:"../Debug/cgamex86.dll" /implib:"Debug/cgamex86.lib"
.\Debug\bg_misc.obj
@ -42,18 +42,19 @@ Creating temporary file "C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\RSP2EB.tmp" with con
.\Debug\q_shared.obj
.\Debug\ui_shared.obj
]
Creating command line "link.exe @C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\RSP2EB.tmp"
Creating command line "link.exe @C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\RSP2D4.tmp"
<h3>Output Window</h3>
Compiling...
cg_weapons.c
ui_shared.c
cg_main.c
cg_playerstate.c
c:\reaction\cgame\cg_playerstate.c(372) : warning C4101: 'sfx' : unreferenced local variable
Linking...
Creating library Debug/cgamex86.lib and object Debug/cgamex86.exp
<h3>Results</h3>
cgamex86.dll - 0 error(s), 0 warning(s)
cgamex86.dll - 0 error(s), 1 warning(s)
</pre>
</body>
</html>

View file

@ -304,7 +304,19 @@ static void PM_Accelerate( vec3_t wishdir, float wishspeed, float accel ) {
// q2 style
int i;
float addspeed, accelspeed, currentspeed;
//Blaze: New ramp move code
//vec3_t point;
//trace_t trace;
float normal;
float temp;
normal = pml.groundTrace.plane.normal[2];
if (normal > 0)
{
temp = wishspeed;
wishspeed *= (2 - normal);
}
//Blaze: end new ramp jump code
currentspeed = DotProduct (pm->ps->velocity, wishdir);
addspeed = wishspeed - currentspeed;
if (addspeed <= 0) {
@ -324,7 +336,26 @@ static void PM_Accelerate( vec3_t wishdir, float wishspeed, float accel ) {
vec3_t pushDir;
float pushLen;
float canPush;
//Blaze: New ramp move code
//vec3_t point;
//trace_t trace;
float normal;
float temp;
//point[0] = pm->ps->origin[0];
//point[1] = pm->ps->origin[1];
//point[2] = pm->ps->origin[2] - 0.25;
//pm->trace (&trace, pm->ps->origin, pm->mins, pm->maxs, point, pm->ps->clientNum, pm->tracemask);
normal = pml.groundTrace.plane.normal[2];
if (normal > 0)
{
Com_Printf("(%f)",wishspeed);
temp = wishspeed;
wishspeed *= (2 - normal);
Com_Printf(" (%f) (%f)\n", wishspeed-temp, normal);
}
//Blaze: end new ramp jump code
VectorScale( wishdir, wishspeed, wishVelocity );
VectorSubtract( wishVelocity, pm->ps->velocity, pushDir );
pushLen = VectorNormalize( pushDir );
@ -925,7 +956,7 @@ static void PM_WalkMove( void ) {
float accelerate;
float vel;
//Blaze: New ramp move code
vec3_t point;
/* vec3_t point;
trace_t trace;
point[0] = pm->ps->origin[0];
@ -933,6 +964,7 @@ static void PM_WalkMove( void ) {
point[2] = pm->ps->origin[2] - 0.25;
pm->trace (&trace, pm->ps->origin, pm->mins, pm->maxs, point, pm->ps->clientNum, pm->tracemask);
*/
//Com_Printf("(%f)",trace.plane.normal[2]);
//Blaze: end new ramp jump code
@ -995,7 +1027,8 @@ static void PM_WalkMove( void ) {
wishspeed *= scale;
//Blaze: Some ramp jump stuff here
wishspeed *= 2 - trace.plane.normal[2];
// if ( 2 - trace.plane.normal[2] > 1.00f) Com_Printf("(%f)\n",2 - trace.plane.normal[2]);
// wishspeed *= 2 - trace.plane.normal[2];
//End blaze ramp jumping stuff
@ -1038,7 +1071,7 @@ static void PM_WalkMove( void ) {
}
vel = VectorLength(pm->ps->velocity);
// Com_Printf("(%f)\n", vel);
// slide along the ground plane
//Blaze: ramp jump test
PM_ClipVelocity (pm->ps->velocity, pml.groundTrace.plane.normal,

View file

@ -861,7 +861,68 @@ void ClientUserinfoChanged( int clientNum ) {
G_LogPrintf( "ClientUserinfoChanged: %i %s\n", clientNum, s );
}
/*
===========
G_SendCheatVars(int)
Send which cvars are cheats, and the acceptable values
===========
*/
int G_SendCheatVars(int clientNum)
{
char *text_p;
int len;
int i;
int skip;
char *token;
char text[20000];
fileHandle_t f;
char *filename = "cvar.cfg";
char cheatVar[40], cl_cheatvar[128];
float lowval, highval;
// load the file
len = trap_FS_FOpenFile( filename, &f, FS_READ );
if ( len <= 0 ) {
return qfalse;
}
if ( len >= sizeof( text ) - 1 ) {
G_Printf( "File %s too long\n", filename );
return qfalse;
}
trap_FS_Read( text, len, f );
text[len] = 0;
trap_FS_FCloseFile( f );
// parse the text
text_p = text;
skip = 0; // quite the compiler warning
for ( i = 0 ; i < 30 ; i++ ) {
token = COM_Parse( &text_p );
if ( !token ) break;
if (strlen(token) >=40)
{
Com_Printf("Cheatvar %s is too long\n",token);
return qfalse;
}
Q_strncpyz( cheatVar, token, sizeof( cheatVar ) );
if ( !strcmp(token, NULL)) return qtrue;
token = COM_Parse( &text_p );
if ( !token ) break;
lowval = atof( token );
token = COM_Parse( &text_p );
if ( !token ) break;
highval = atof( token );
Com_sprintf(cl_cheatvar, sizeof(cl_cheatvar),"addCheatVar %s %f %f\n",cheatVar,lowval,highval);
//Com_Printf("%s", cl_cheatvar);
trap_SendServerCommand(clientNum, va("%s",cl_cheatvar));
}
return qtrue;
}
/*
===========
@ -1022,6 +1083,8 @@ void ClientBegin( int clientNum ) {
// count current clients and rank for scoreboard
CalculateRanks();
//Blaze: load in the cvar.cfg file and send off the values to the currently connecting client.
}
/*
@ -1319,6 +1382,13 @@ void ClientSpawn(gentity_t *ent) {
// run the presend to set anything else
ClientEndFrame( ent );
//Blaze: Send cheat cvars to client
if (!G_SendCheatVars(ent->s.clientNum))
{
Com_Printf("Error loading cvar cfg");
//return "Error_loading_cvar_cfg";
}
// clear entity state values
BG_PlayerStateToEntityState( &client->ps, &ent->s, qtrue );
}

View file

@ -2575,6 +2575,7 @@ void ClientCommand( int clientNum ) {
{
Cmd_PlayerStats_f( ent );
}
else
trap_SendServerCommand( clientNum, va("print \"unknown cmd %s\n\"", cmd ) );
}

View file

@ -760,6 +760,8 @@ void InitClientPersistant (gclient_t *client);
void InitClientResp (gclient_t *client);
void InitBodyQue (void);
void ClientSpawn( gentity_t *ent );
//Blaze: for the cheat vars stuff
int G_SendCheatVars(int);
void player_die (gentity_t *self, gentity_t *inflictor, gentity_t *attacker, int damage, int mod);
void AddScore( gentity_t *ent, vec3_t origin, int score );
void CalculateRanks( void );

View file

@ -6,7 +6,7 @@
--------------------Configuration: game - Win32 Debug--------------------
</h3>
<h3>Command Lines</h3>
Creating temporary file "C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\RSP20F.tmp" with contents
Creating temporary file "C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\RSP1A2.tmp" with contents
[
/nologo /G5 /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "BUILDING_REF_GL" /D "DEBUG" /FR"c:\reactionoutput/" /Fp"c:\reactionoutput/game.pch" /YX /Fo"c:\reactionoutput/" /Fd"c:\reactionoutput/" /FD /c
"c:\reaction\game\ai_chat.c"
@ -16,9 +16,6 @@ Creating temporary file "C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\RSP20F.tmp" with con
"c:\reaction\game\ai_main.c"
"c:\reaction\game\ai_team.c"
"c:\reaction\game\ai_vcmd.c"
"c:\reaction\game\bg_misc.c"
"c:\reaction\game\bg_pmove.c"
"c:\reaction\game\bg_slidemove.c"
"c:\reaction\game\g_active.c"
"c:\reaction\game\g_arenas.c"
"c:\reaction\game\g_bot.c"
@ -43,8 +40,8 @@ Creating temporary file "C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\RSP20F.tmp" with con
"c:\reaction\game\g_weapon.c"
"c:\reaction\game\rxn_game.c"
]
Creating command line "cl.exe @C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\RSP20F.tmp"
Creating temporary file "C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\RSP210.tmp" with contents
Creating command line "cl.exe @C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\RSP1A2.tmp"
Creating temporary file "C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\RSP1A3.tmp" with contents
[
kernel32.lib user32.lib winmm.lib /nologo /base:"0x20000000" /subsystem:windows /dll /incremental:yes /pdb:"c:\reactionoutput/qagamex86.pdb" /map:"c:\reactionoutput/qagamex86.map" /debug /machine:I386 /def:".\game.def" /out:"..\Debug/qagamex86.dll" /implib:"c:\reactionoutput/qagamex86.lib"
\reactionoutput\ai_chat.obj
@ -83,7 +80,7 @@ kernel32.lib user32.lib winmm.lib /nologo /base:"0x20000000" /subsystem:windows
\reactionoutput\q_shared.obj
\reactionoutput\rxn_game.obj
]
Creating command line "link.exe @C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\RSP210.tmp"
Creating command line "link.exe @C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\RSP1A3.tmp"
<h3>Output Window</h3>
Compiling...
ai_chat.c
@ -93,21 +90,17 @@ ai_dmq3.c
ai_main.c
ai_team.c
ai_vcmd.c
bg_misc.c
bg_pmove.c
bg_slidemove.c
g_active.c
g_arenas.c
g_bot.c
g_client.c
g_cmds.c
c:\reaction\game\g_cmds.c(1683) : error C2065: 'pm' : undeclared identifier
c:\reaction\game\g_cmds.c(1683) : error C2223: left of '->ps' must point to struct/union
c:\reaction\game\g_client.c(906) : warning C4700: local variable 'cheatVar' used without having been initialized
g_combat.c
g_fileio.c
g_items.c
c:\reaction\game\g_items.c(1572) : warning C4101: 'rq3_item' : unreferenced local variable
c:\reaction\game\g_items.c(1573) : warning C4101: 'rq3_temp' : unreferenced local variable
c:\reaction\game\g_items.c(1574) : warning C4101: 'rq3_item' : unreferenced local variable
c:\reaction\game\g_items.c(1575) : warning C4101: 'rq3_temp' : unreferenced local variable
g_main.c
g_mem.c
g_misc.c
@ -122,13 +115,18 @@ g_team.c
g_trigger.c
g_utils.c
g_weapon.c
c:\reaction\game\g_weapon.c(1386) : warning C4101: 'i' : unreferenced local variable
rxn_game.c
Error executing cl.exe.
Linking...
Creating library c:\reactionoutput/qagamex86.lib and object c:\reactionoutput/qagamex86.exp
g_client.obj : error LNK2001: unresolved external symbol _G_SendCheatVars
..\Debug/qagamex86.dll : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
<h3>Results</h3>
qagamex86.dll - 2 error(s), 2 warning(s)
qagamex86.dll - 2 error(s), 4 warning(s)
</pre>
</body>
</html>