From 8a63e785b85fb8ff726a6170c9793cdb45d781d5 Mon Sep 17 00:00:00 2001 From: Spoike Date: Thu, 23 Aug 2007 21:25:18 +0000 Subject: [PATCH] Added some anti-cheat measures, still needs lots of work. git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@2610 fc73d0e0-1445-4013-8a0c-d673dee63da5 --- engine/client/cl_input.c | 19 ++++++++++++++----- engine/client/cl_main.c | 22 +++++++++++++++++++++- engine/client/cl_tent.c | 5 +++-- engine/client/client.h | 8 ++++++++ engine/client/snd_dma.c | 8 +++++++- engine/client/zqtp.c | 25 +++++++++++++++++++++++++ engine/common/com_mesh.c | 26 ++++++++++++++++++++++++++ engine/common/cvar.c | 8 +++++++- engine/common/cvar.h | 29 +++++++++++++++-------------- 9 files changed, 126 insertions(+), 24 deletions(-) diff --git a/engine/client/cl_input.c b/engine/client/cl_input.c index 5f9287343..d6937fc6c 100644 --- a/engine/client/cl_input.c +++ b/engine/client/cl_input.c @@ -444,7 +444,12 @@ void CL_AdjustAngles (int pnum) float up, down; if (in_speed.state[pnum] & 1) - speed = host_frametime * cl_anglespeedkey.value; + { + if (ruleset_allow_frj.value) + speed = host_frametime * cl_anglespeedkey.value; + else + speed = host_frametime * bound(-2, cl_anglespeedkey.value, 2); + } else speed = host_frametime; @@ -454,13 +459,14 @@ void CL_AdjustAngles (int pnum) if (!cl_instantrotate.value) quant *= speed; in_rotate -= quant; - cl.viewangles[pnum][YAW] += quant; + if (ruleset_allow_frj.value) + cl.viewangles[pnum][YAW] += quant; } if (!(in_strafe.state[pnum] & 1)) { quant = cl_yawspeed.value; - if (cl.fpd & FPD_LIMIT_YAW) + if (cl.fpd & FPD_LIMIT_YAW || !ruleset_allow_frj.value) quant = bound(-900, quant, 900); cl.viewangles[pnum][YAW] -= speed*quant * CL_KeyState (&in_right, pnum); cl.viewangles[pnum][YAW] += speed*quant * CL_KeyState (&in_left, pnum); @@ -470,7 +476,7 @@ void CL_AdjustAngles (int pnum) { V_StopPitchDrift (pnum); quant = cl_pitchspeed.value; - if (cl.fpd & FPD_LIMIT_PITCH) + if (cl.fpd & FPD_LIMIT_PITCH || !ruleset_allow_frj.value) quant = bound(-700, quant, 700); cl.viewangles[pnum][PITCH] -= speed*quant * CL_KeyState (&in_forward, pnum); cl.viewangles[pnum][PITCH] += speed*quant * CL_KeyState (&in_back, pnum); @@ -478,7 +484,10 @@ void CL_AdjustAngles (int pnum) up = CL_KeyState (&in_lookup, pnum); down = CL_KeyState(&in_lookdown, pnum); - + + quant = cl_pitchspeed.value; + if (!ruleset_allow_frj.value) + quant = bound(-700, quant, 700); cl.viewangles[pnum][PITCH] -= speed*cl_pitchspeed.value * up; cl.viewangles[pnum][PITCH] += speed*cl_pitchspeed.value * down; diff --git a/engine/client/cl_main.c b/engine/client/cl_main.c index 7dee09164..ba0180b72 100644 --- a/engine/client/cl_main.c +++ b/engine/client/cl_main.c @@ -142,6 +142,14 @@ cvar_t cl_dlemptyterminate = SCVAR("cl_dlemptyterminate", "1"); cvar_t host_mapname = FCVAR("mapname", "host_mapname", "", 0); +cvar_t ruleset_allow_playercount = SCVAR("ruleset_allow_playercount", "1"); +cvar_t ruleset_allow_frj = SCVAR("ruleset_allow_frj", "1"); +cvar_t ruleset_allow_semicheats = SCVAR("ruleset_allow_semicheats", "1"); +cvar_t ruleset_allow_packet = SCVAR("ruleset_allow_packet", "1"); +cvar_t ruleset_allow_particle_lightning = SCVAR("ruleset_allow_particle_lightning", "1"); +cvar_t ruleset_allow_overlongsounds = SCVAR("ruleset_allow_overlong_sounds", "1"); +cvar_t ruleset_allow_larger_models = SCVAR("ruleset_allow_larger_models", "1"); + extern cvar_t cl_hightrack; char cl_screengroup[] = "Screen options"; @@ -1404,7 +1412,7 @@ void CL_CheckServerInfo(void) cls.allow_cheats = true; s = Info_ValueForKey(cl.serverinfo, "strict"); - if (!cls.demoplayback && *s && strcmp(s, "0")) + if ((!cls.demoplayback && *s && strcmp(s, "0")) || !ruleset_allow_semicheats.value) { cls.allow_semicheats = false; cls.allow_cheats = false; @@ -1723,6 +1731,11 @@ void CL_Packet_f (void) Con_DPrintf ("Sending realip packet\n"); } + else if (!ruleset_allow_packet.value) + { + Con_Printf("Sorry, the %s command is disallowed\n", Cmd_Argv(0)); + return; + } cls.lastarbiatarypackettime = Sys_DoubleTime(); //prevent the packet command from causing a reconnect on badly configured mvdsv servers. in = Cmd_Argv(2); @@ -2869,6 +2882,13 @@ void CL_Init (void) Cvar_Register (&cl_gunangley, cl_controlgroup); Cvar_Register (&cl_gunanglez, cl_controlgroup); + Cvar_Register (&ruleset_allow_playercount, cl_controlgroup); + Cvar_Register (&ruleset_allow_frj, cl_controlgroup); + Cvar_Register (&ruleset_allow_semicheats, cl_controlgroup); + Cvar_Register (&ruleset_allow_packet, cl_controlgroup); + Cvar_Register (&ruleset_allow_particle_lightning, cl_controlgroup); + Cvar_Register (&ruleset_allow_overlongsounds, cl_controlgroup); + Cvar_Register (&ruleset_allow_larger_models, cl_controlgroup); #ifdef WEBCLIENT Cmd_AddCommand ("ftp", CL_FTP_f); #endif diff --git a/engine/client/cl_tent.c b/engine/client/cl_tent.c index 87331f8b5..a8a8bbf0c 100644 --- a/engine/client/cl_tent.c +++ b/engine/client/cl_tent.c @@ -2586,8 +2586,9 @@ void CL_UpdateBeams (void) // if (part_type[rt_lightning1].loaded) // if (!P_ParticleTrail(b->start, b->end, rt_lightning1, NULL)) // continue; - if (b->particleeffect >= 0 && !P_ParticleTrail(b->start, b->end, b->particleeffect, &b->trailstate)) - continue; + if (ruleset_allow_particle_lightning.value) + if (b->particleeffect >= 0 && !P_ParticleTrail(b->start, b->end, b->particleeffect, &b->trailstate)) + continue; // add new entities for the lightning VectorCopy (b->start, org); diff --git a/engine/client/client.h b/engine/client/client.h index 62a9699aa..ffa9690d1 100644 --- a/engine/client/client.h +++ b/engine/client/client.h @@ -636,6 +636,14 @@ extern cvar_t _windowed_mouse; extern cvar_t name; +extern cvar_t ruleset_allow_playercount; +extern cvar_t ruleset_allow_frj; +extern cvar_t ruleset_allow_semicheats; +extern cvar_t ruleset_allow_packet; +extern cvar_t ruleset_allow_particle_lightning; +extern cvar_t ruleset_allow_overlongsounds; +extern cvar_t ruleset_allow_larger_models; + #define MAX_STATIC_ENTITIES 256 // torches, etc extern client_state_t cl; diff --git a/engine/client/snd_dma.c b/engine/client/snd_dma.c index b00c8895f..099670b1c 100644 --- a/engine/client/snd_dma.c +++ b/engine/client/snd_dma.c @@ -915,9 +915,15 @@ void S_StartSoundCard(soundcardinfo_t *sc, int entnum, int entchannel, sfx_t *sf target_chan->sfx = NULL; return; // couldn't load the sound's data } + + if (scache->length > snd_speed*20 && !ruleset_allow_overlongsounds.value) + { + Con_DPrintf("Shortening over-long sound effect\n"); + startpos = scache->length - snd_speed*20; + } target_chan->sfx = sfx; target_chan->pos = startpos; - target_chan->end = sc->paintedtime + scache->length; + target_chan->end = sc->paintedtime + scache->length - startpos; target_chan->looping = false; // if an identical sound has also been started this frame, offset the pos diff --git a/engine/client/zqtp.c b/engine/client/zqtp.c index 22b7a681e..ec9acd63d 100644 --- a/engine/client/zqtp.c +++ b/engine/client/zqtp.c @@ -309,6 +309,13 @@ static char *Macro_Latency (void) return macro_buf; } +static char *Macro_Gamedir (void) +{ + extern char gamedirfile[]; + Q_snprintfz(macro_buf, sizeof(macro_buf), "%s", gamedirfile); + return macro_buf; +} + static char *Macro_Health (void) { sprintf(macro_buf, "%i", cl.stats[SP][STAT_HEALTH]); @@ -929,6 +936,8 @@ static void CountNearbyPlayers(qboolean dead) static char *Macro_CountNearbyEnemyPlayers (void) { + if (!ruleset_allow_playercount.value) + return "banned by ruleset"; CountNearbyPlayers(false); sprintf(macro_buf, "\xffz%d\xff", vars.numenemies); suppress = true; @@ -938,6 +947,8 @@ static char *Macro_CountNearbyEnemyPlayers (void) static char *Macro_Count_Last_NearbyEnemyPlayers (void) { + if (!ruleset_allow_playercount.value) + return "banned by ruleset"; if (vars.deathtrigger_time && realtime - vars.deathtrigger_time <= 5) { sprintf(macro_buf, "\xffz%d\xff", vars.last_numenemies); @@ -954,6 +965,8 @@ static char *Macro_Count_Last_NearbyEnemyPlayers (void) static char *Macro_CountNearbyFriendlyPlayers (void) { + if (!ruleset_allow_playercount.value) + return "banned by ruleset"; CountNearbyPlayers(false); sprintf(macro_buf, "\xffz%d\xff", vars.numfriendlies); suppress = true; @@ -963,6 +976,8 @@ static char *Macro_CountNearbyFriendlyPlayers (void) static char *Macro_Count_Last_NearbyFriendlyPlayers (void) { + if (!ruleset_allow_playercount.value) + return "banned by ruleset"; if (vars.deathtrigger_time && realtime - vars.deathtrigger_time <= 5) { sprintf(macro_buf, "\xffz%d\xff", vars.last_numfriendlies); @@ -1163,6 +1178,16 @@ static void TP_InitMacros(void) //new, fte only (at least when first implemented) Cmd_AddMacro("chealth", Macro_CombinedHealth, true); + + //added for ezquake compatability +// Cmd_AddMacro("lastip", Macro_LastIP, false); + Cmd_AddMacro("ping", Macro_Latency, false); +// Cmd_AddMacro("colored_armor", Macro_Coloured_Armour, true); //*shudder* +// Cmd_AddMacro("colored_powerups", Macro_Coloured_Powerups, true); +// Cmd_AddMacro("colored_short_powerups", Macro_Coloured_Short_Powerups, true); + Cmd_AddMacro("gamedir", Macro_Gamedir, false); + Cmd_AddMacro("lastloc", Macro_Last_Location, true); + Cmd_AddMacro("lastpowerup", Macro_LastSeenPowerup, true); } #define MAX_MACRO_STRING 1024 diff --git a/engine/common/com_mesh.c b/engine/common/com_mesh.c index af6ca4bea..0e4ea7350 100644 --- a/engine/common/com_mesh.c +++ b/engine/common/com_mesh.c @@ -682,6 +682,18 @@ static void Mod_DoCRC(model_t *mod, char *buffer, int buffersize) #endif } + +static void Mod_ClampModelSize(model_t *mod) +{ +#ifndef SERVERONLY + if (ruleset_allow_larger_models.value) + return; + //otherwise clamp them + + Con_Printf("Loading %s, but size clamping isn't implemented yet\n", mod->name); +#endif +} + #ifdef RGLQUAKE static int R_FindTriangleWithEdge ( int *indexes, int numtris, int start, int end, int ignore) { @@ -1625,6 +1637,8 @@ qboolean Mod_LoadQ1Model (model_t *mod, void *buffer) VectorCopy (pq1inmodel->scale_origin, mod->mins); VectorMA (mod->mins, 255, pq1inmodel->scale, mod->maxs); + + Mod_ClampModelSize(mod); // // move the complete, relocatable alias model to the cache // @@ -1965,6 +1979,8 @@ qboolean Mod_LoadQ2Model (model_t *mod, void *buffer) VectorCopy (pq2inmodel->scale_origin, mod->mins); VectorMA (mod->mins, 255, pq2inmodel->scale, mod->maxs); */ + + Mod_ClampModelSize(mod); // // move the complete, relocatable alias model to the cache // @@ -2618,6 +2634,8 @@ qboolean Mod_LoadQ3Model(model_t *mod, void *buffer) if (!mod->flags) mod->flags = Mod_ReadFlagsFromMD1(mod->name, 0); + Mod_ClampModelSize(mod); + Hunk_Alloc(0); hunktotal = hunkend - hunkstart; @@ -2945,6 +2963,8 @@ qboolean Mod_LoadZymoticModel(model_t *mod, void *buffer) mod->flags = Mod_ReadFlagsFromMD1(mod->name, 0); //file replacement - inherit flags from any defunc mdl files. + Mod_ClampModelSize(mod); + Hunk_Alloc(0); hunktotal = hunkend - hunkstart; @@ -3304,6 +3324,8 @@ qboolean Mod_LoadDarkPlacesModel(model_t *mod, void *buffer) mod->flags = Mod_ReadFlagsFromMD1(mod->name, 0); //file replacement - inherit flags from any defunc mdl files. + Mod_ClampModelSize(mod); + Hunk_Alloc(0); hunktotal = hunkend - hunkstart; @@ -3768,6 +3790,8 @@ qboolean Mod_LoadMD5MeshModel(model_t *mod, void *buffer) mod->flags = Mod_ReadFlagsFromMD1(mod->name, 0); //file replacement - inherit flags from any defunc mdl files. + Mod_ClampModelSize(mod); + Hunk_Alloc(0); hunktotal = hunkend - hunkstart; @@ -4138,6 +4162,8 @@ qboolean Mod_LoadCompositeAnim(model_t *mod, void *buffer) mod->flags = Mod_ReadFlagsFromMD1(mod->name, 0); //file replacement - inherit flags from any defunc mdl files. + Mod_ClampModelSize(mod); + Hunk_Alloc(0); hunktotal = hunkend - hunkstart; diff --git a/engine/common/cvar.c b/engine/common/cvar.c index 5e9d954d8..912e7046a 100644 --- a/engine/common/cvar.c +++ b/engine/common/cvar.c @@ -624,6 +624,8 @@ cvar_t *Cvar_SetCore (cvar_t *var, const char *value, qboolean force) // latch = "variable %s is latched (type flush)\n"; else if (var->flags & CVAR_RENDERERLATCH && qrenderer) latch = "variable %s will be changed after a vid_restart\n"; + else if (var->flags & CVAR_RULESETLATCH) + latch = "variable %s is latched due to current ruleset\n"; #ifndef SERVERONLY else if (var->flags & CVAR_CHEAT && !cls.allow_cheats && cls.state) latch = "variable %s is a cheat variable - latched\n"; @@ -769,6 +771,7 @@ void Cvar_ApplyLatches(int latchflag) cvar_group_t *grp; cvar_t *var; int mask = ~0; + int of; if (latchflag == CVAR_SERVEROVERRIDE) //these ones are cleared mask = ~CVAR_SERVEROVERRIDE; @@ -780,7 +783,10 @@ void Cvar_ApplyLatches(int latchflag) { if (var->latched_string) { - Cvar_ForceSet(var, var->latched_string); + of = var->flags; + var->flags &= ~latchflag; + Cvar_Set(var, var->latched_string); + var->flags = of; } var->flags &= mask; } diff --git a/engine/common/cvar.h b/engine/common/cvar.h index 2f9424cf0..b7222ca2b 100644 --- a/engine/common/cvar.h +++ b/engine/common/cvar.h @@ -89,23 +89,24 @@ typedef struct cvar_group_s } cvar_group_t; //q2 constants -#define CVAR_ARCHIVE 1 // set to cause it to be saved to vars.rc -#define CVAR_USERINFO 2 // added to userinfo when changed -#define CVAR_SERVERINFO 4 // added to serverinfo when changed -#define CVAR_NOSET 8 // don't allow change from console at all, +#define CVAR_ARCHIVE (1<<0) // set to cause it to be saved to vars.rc +#define CVAR_USERINFO (1<<1) // added to userinfo when changed +#define CVAR_SERVERINFO (1<<2) // added to serverinfo when changed +#define CVAR_NOSET (1<<3) // don't allow change from console at all, // but can be set from the command line -#define CVAR_LATCH 16 // save changes until server restart +#define CVAR_LATCH (1<<4) // save changes until server restart //freestyle -#define CVAR_POINTER 32 // q2 style. May be converted to q1 if needed. These are often specified on the command line and then converted into q1 when registered properly. -#define CVAR_NOTFROMSERVER 64 // the console will ignore changes to cvars if set at from the server or any gamecode. This is to protect against security flaws - like qterm -#define CVAR_USERCREATED 128 //write a 'set' or 'seta' in front of the var name. -#define CVAR_CHEAT 256 //latch to the default, unless cheats are enabled. -#define CVAR_SEMICHEAT 512 //if strict ruleset, force to 0/blank. -#define CVAR_RENDERERLATCH 1024 //requires a vid_restart to reapply. -#define CVAR_SERVEROVERRIDE 2048 //the server has overridden out local value - should probably be called SERVERLATCH -#define CVAR_RENDERERCALLBACK 4096 //force callback for cvars on renderer change -#define CVAR_NOUNSAFEEXPAND 8192 // do not expand cvar value when command is from gamecode +#define CVAR_POINTER (1<<5) // q2 style. May be converted to q1 if needed. These are often specified on the command line and then converted into q1 when registered properly. +#define CVAR_NOTFROMSERVER (1<<6) // the console will ignore changes to cvars if set at from the server or any gamecode. This is to protect against security flaws - like qterm +#define CVAR_USERCREATED (1<<7) //write a 'set' or 'seta' in front of the var name. +#define CVAR_CHEAT (1<<8) //latch to the default, unless cheats are enabled. +#define CVAR_SEMICHEAT (1<<9) //if strict ruleset, force to 0/blank. +#define CVAR_RENDERERLATCH (1<<10) //requires a vid_restart to reapply. +#define CVAR_SERVEROVERRIDE (1<<11) //the server has overridden out local value - should probably be called SERVERLATCH +#define CVAR_RENDERERCALLBACK (1<<12) //force callback for cvars on renderer change +#define CVAR_NOUNSAFEEXPAND (1<<13) // do not expand cvar value when command is from gamecode +#define CVAR_RULESETLATCH (1<<14) //latched by the ruleset #define CVAR_LASTFLAG CVAR_NOUNSAFEEXPAND