From ce73838f1b7a51da81aa731e7d8503011940852a Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Thu, 4 Jan 2024 05:09:36 +0300 Subject: [PATCH] engine: add a function that validates requested features bits --- engine/client/cl_parse.c | 6 +----- engine/common/common.h | 2 +- engine/common/host.c | 32 +++++++++++++++++++++++++++++++- engine/server/sv_phys.c | 6 +++--- 4 files changed, 36 insertions(+), 10 deletions(-) diff --git a/engine/client/cl_parse.c b/engine/client/cl_parse.c index 5d15caee..b23a7bf3 100644 --- a/engine/client/cl_parse.c +++ b/engine/client/cl_parse.c @@ -903,11 +903,7 @@ void CL_ParseServerData( sizebuf_t *msg, qboolean legacy ) Q_strncpy( clgame.maptitle, MSG_ReadString( msg ), sizeof( clgame.maptitle )); background = MSG_ReadOneBit( msg ); Q_strncpy( gamefolder, MSG_ReadString( msg ), sizeof( gamefolder )); - host.features = (uint)MSG_ReadLong( msg ); - host.features &= legacy ? ENGINE_LEGACY_FEATURES_MASK : ENGINE_FEATURES_MASK; - - if( !Host_IsLocalGame( )) - Host_PrintEngineFeatures( host.features ); + Host_ValidateEngineFeatures( MSG_ReadDword( msg )); if( !legacy ) { diff --git a/engine/common/common.h b/engine/common/common.h index 8f053788..f6a240e1 100644 --- a/engine/common/common.h +++ b/engine/common/common.h @@ -554,7 +554,7 @@ qboolean Host_IsLocalGame( void ); qboolean Host_IsLocalClient( void ); void Host_ShutdownServer( void ); void Host_Error( const char *error, ... ) _format( 1 ); -void Host_PrintEngineFeatures( int features ); +void Host_ValidateEngineFeatures( uint32_t features ); void Host_Frame( float time ); void Host_InitDecals( void ); void Host_Credits( void ); diff --git a/engine/common/host.c b/engine/common/host.c index e8050fe7..fa7c0410 100644 --- a/engine/common/host.c +++ b/engine/common/host.c @@ -190,7 +190,7 @@ void Host_ShutdownServer( void ) Host_PrintEngineFeatures ================ */ -void Host_PrintEngineFeatures( int features ) +static void Host_PrintEngineFeatures( int features ) { const char *features_str[] = { @@ -213,6 +213,36 @@ void Host_PrintEngineFeatures( int features ) } } +/* +============== +Host_ValidateEngineFeatures + +validate features bits and set host.features +============== +*/ +void Host_ValidateEngineFeatures( uint32_t features ) +{ + uint32_t mask = ENGINE_FEATURES_MASK; + +#if !HOST_DEDICATED + if( !Host_IsDedicated( ) && cls.legacymode ) + mask = ENGINE_LEGACY_FEATURES_MASK; +#endif + + // don't allow unsupported bits + features &= mask; + + // print requested first + Host_PrintEngineFeatures( features ); + + // now warn about incompatible bits + if( FBitSet( features, ENGINE_STEP_POSHISTORY_LERP|ENGINE_COMPUTE_STUDIO_LERP )) + Con_Printf( S_WARN "%s: incompatible ENGINE_STEP_POSHISTORY_LERP and ENGINE_COMPUTE_STUDIO_LERP are enabled!\n", __func__ ); + + // finally set global variable + host.features = features; +} + /* ============== Host_IsQuakeCompatible diff --git a/engine/server/sv_phys.c b/engine/server/sv_phys.c index 905d81b4..8e152cb4 100644 --- a/engine/server/sv_phys.c +++ b/engine/server/sv_phys.c @@ -2139,18 +2139,18 @@ qboolean SV_InitPhysicsAPI( void ) if( svgame.physFuncs.SV_CheckFeatures != NULL ) { // grab common engine features (it will be shared across the network) - host.features = svgame.physFuncs.SV_CheckFeatures() & ENGINE_FEATURES_MASK; - Host_PrintEngineFeatures( host.features ); + Host_ValidateEngineFeatures( svgame.physFuncs.SV_CheckFeatures( )); } return true; } // make sure what physic functions is cleared memset( &svgame.physFuncs, 0, sizeof( svgame.physFuncs )); - + Host_ValidateEngineFeatures( 0 ); return false; // just tell user about problems } // physic interface is missed + Host_ValidateEngineFeatures( 0 ); return true; }