engine: server: moved server cvars to static allocation

This commit is contained in:
Alibek Omarov 2023-05-21 02:04:20 +03:00
parent 8680757844
commit 9e0d389d9e
10 changed files with 65 additions and 66 deletions

View File

@ -157,7 +157,6 @@ extern convar_t gl_vsync;
extern convar_t scr_loading;
extern convar_t scr_download;
extern convar_t cmd_scripting;
extern convar_t *sv_maxclients;
extern convar_t cl_allow_levelshots;
extern convar_t host_developer;
extern convar_t host_limitlocal;

View File

@ -447,14 +447,14 @@ extern convar_t sv_cheats;
extern convar_t public_server;
extern convar_t sv_nat;
extern convar_t sv_speedhack_kick;
extern convar_t *sv_pausable; // allows pause in multiplayer
extern convar_t *sv_check_errors;
extern convar_t *sv_reconnect_limit;
extern convar_t *sv_lighting_modulate;
extern convar_t *sv_novis;
extern convar_t *sv_hostmap;
extern convar_t *sv_validate_changelevel;
extern convar_t sv_pausable; // allows pause in multiplayer
extern convar_t sv_check_errors;
extern convar_t sv_reconnect_limit;
extern convar_t sv_lighting_modulate;
extern convar_t sv_novis;
extern convar_t sv_hostmap;
extern convar_t sv_validate_changelevel;
extern convar_t sv_maxclients;
//===========================================================
//

View File

@ -1762,7 +1762,7 @@ static qboolean SV_Pause_f( sv_client_t *cl )
if( UI_CreditsActive( ))
return true;
if( !sv_pausable->value )
if( !sv_pausable.value )
{
SV_ClientPrintf( cl, "Pause not allowed.\n" );
return true;

View File

@ -175,7 +175,7 @@ qboolean SV_ValidateMap( const char *pMapName, qboolean check_spawn )
int flags;
// determine spawn entity classname
if( !check_spawn || (int)sv_maxclients->value <= 1 )
if( !check_spawn || (int)sv_maxclients.value <= 1 )
spawn_entity = GI->sp_entity;
else spawn_entity = GI->mp_entity;
@ -227,7 +227,7 @@ void SV_Map_f( void )
if( !SV_ValidateMap( mapname, true ))
return;
Cvar_DirectSet( sv_hostmap, mapname );
Cvar_DirectSet( &sv_hostmap, mapname );
COM_LoadLevel( mapname, false );
}
@ -338,12 +338,12 @@ void SV_NextMap_f( void )
continue;
COM_FileBase( t->filenames[i], nextmap, sizeof( nextmap ));
if( Q_stricmp( sv_hostmap->string, nextmap ))
if( Q_stricmp( sv_hostmap.string, nextmap ))
continue;
next = ( i + 1 ) % t->numfilenames;
COM_FileBase( t->filenames[next], nextmap, sizeof( nextmap ));
Cvar_DirectSet( sv_hostmap, nextmap );
Cvar_DirectSet( &sv_hostmap, nextmap );
// found current point, check for valid
if( SV_ValidateMap( nextmap, true ))
@ -535,7 +535,7 @@ void SV_Reload_f( void )
return;
if( !SV_LoadGame( SV_GetLatestSave( )))
COM_LoadLevel( sv_hostmap->string, false );
COM_LoadLevel( sv_hostmap.string, false );
}
/*

View File

@ -138,7 +138,7 @@ static void SV_BanID_f( void )
len = Q_strlen( id );
for( i = 0; i < sv_maxclients->value; i++ )
for( i = 0; i < sv_maxclients.value; i++ )
{
if( FBitSet( svs.clients[i].flags, FCL_FAKECLIENT ))
continue;
@ -201,7 +201,7 @@ static void SV_RemoveID_f( void )
{
int num = Q_atoi( id + 1 );
if( num >= sv_maxclients->value || num < 0 )
if( num >= sv_maxclients.value || num < 0 )
return;
id = Info_ValueForKey( svs.clients[num].useragent, "uuid" );

View File

@ -792,7 +792,7 @@ void SV_QueueChangeLevel( const char *level, const char *landname )
if( smooth && !FBitSet( flags, MAP_HAS_LANDMARK ))
{
if( sv_validate_changelevel->value )
if( sv_validate_changelevel.value )
{
// NOTE: we find valid map but specified landmark it's doesn't exist
// run simple changelevel like in q1, throw warning
@ -812,7 +812,7 @@ void SV_QueueChangeLevel( const char *level, const char *landname )
if( !smooth && !FBitSet( flags, MAP_HAS_SPAWNPOINT ))
{
if( sv_validate_changelevel->value )
if( sv_validate_changelevel.value )
{
Con_Printf( S_ERROR "changelevel: %s doesn't have a valid spawnpoint. Ignored.\n", mapname );
return;
@ -822,7 +822,7 @@ void SV_QueueChangeLevel( const char *level, const char *landname )
// bad changelevel position invoke enables in one-way transition
if( sv.framecount < 15 )
{
if( sv_validate_changelevel->value )
if( sv_validate_changelevel.value )
{
Con_Printf( S_WARN "an infinite changelevel was detected and will be disabled until a next save\\restore\n" );
return; // lock with svs.spawncount here
@ -4138,7 +4138,7 @@ byte *pfnSetFatPVS( const float *org )
{
qboolean fullvis = false;
if( !sv.worldmodel->visdata || sv_novis->value || !org || CL_DisableVisibility( ))
if( !sv.worldmodel->visdata || sv_novis.value || !org || CL_DisableVisibility( ))
fullvis = true;
// portals can't change viewpoint!
@ -4188,7 +4188,7 @@ byte *pfnSetFatPAS( const float *org )
{
qboolean fullvis = false;
if( !sv.worldmodel->visdata || sv_novis->value || !org || CL_DisableVisibility( ))
if( !sv.worldmodel->visdata || sv_novis.value || !org || CL_DisableVisibility( ))
fullvis = true;
// portals can't change viewpoint!

View File

@ -765,7 +765,7 @@ void SV_SetupClients( void )
qboolean changed_maxclients = false;
// check if clients count was really changed
if( svs.maxclients != (int)sv_maxclients->value )
if( svs.maxclients != (int)sv_maxclients.value )
changed_maxclients = true;
if( !changed_maxclients ) return; // nothing to change
@ -774,7 +774,7 @@ void SV_SetupClients( void )
if( svs.maxclients ) Host_ShutdownServer();
// copy the actual value from cvar
svs.maxclients = (int)sv_maxclients->value;
svs.maxclients = (int)sv_maxclients.value;
// dedicated servers are can't be single player and are usually DM
if( Host_IsDedicated() )
@ -802,7 +802,7 @@ void SV_SetupClients( void )
// init network stuff
NET_Config(( svs.maxclients > 1 ), true );
svgame.numEntities = svs.maxclients + 1; // clients + world
ClearBits( sv_maxclients->flags, FCVAR_CHANGED );
ClearBits( sv_maxclients.flags, FCVAR_CHANGED );
}
static qboolean CRC32_MapFile( dword *crcvalue, const char *filename, qboolean multiplayer )

View File

@ -124,22 +124,21 @@ CVAR_DEFINE_AUTO( sv_enttools_maxfire, "5", FCVAR_ARCHIVE|FCVAR_PROTECTED, "limi
CVAR_DEFINE( public_server, "public", "0", 0, "change server type from private to public" );
convar_t *sv_novis; // disable server culling entities by vis
convar_t *sv_pausable;
convar_t *timeout; // seconds without any message
convar_t *sv_lighting_modulate;
convar_t *sv_maxclients;
convar_t *sv_check_errors;
convar_t *sv_reconnect_limit; // minimum seconds between connect messages
convar_t *sv_validate_changelevel;
convar_t *sv_sendvelocity;
convar_t *sv_hostmap;
CVAR_DEFINE_AUTO( sv_novis, "0", 0, "force to ignore server visibility" ); // disable server culling entities by vis
CVAR_DEFINE( sv_pausable, "pausable", "1", FCVAR_SERVER, "allow players to pause or not" );
static CVAR_DEFINE_AUTO( timeout, "125", FCVAR_SERVER, "connection timeout" ); // seconds without any message
CVAR_DEFINE( sv_lighting_modulate, "r_lighting_modulate", "0.6", FCVAR_ARCHIVE, "lightstyles modulate scale" );
CVAR_DEFINE( sv_maxclients, "maxplayers", "1", FCVAR_LATCH, "server max capacity" );
CVAR_DEFINE_AUTO( sv_check_errors, "0", FCVAR_ARCHIVE, "check edicts for errors" );
CVAR_DEFINE_AUTO( sv_reconnect_limit, "3", FCVAR_ARCHIVE, "max reconnect attempts" ); // minimum seconds between connect messages
CVAR_DEFINE_AUTO( sv_validate_changelevel, "0", 0, "test change level for level-designer errors" );
CVAR_DEFINE( sv_hostmap, "hostmap", "", 0, "keep name of last entered map" );
convar_t *sv_allow_noinputdevices;
convar_t *sv_allow_touch;
convar_t *sv_allow_mouse;
convar_t *sv_allow_joystick;
convar_t *sv_allow_vr;
static CVAR_DEFINE_AUTO( sv_allow_joystick, "1", FCVAR_ARCHIVE, "allow connect with joystick enabled" );
static CVAR_DEFINE_AUTO( sv_allow_mouse, "1", FCVAR_ARCHIVE, "allow connect with mouse" );
static CVAR_DEFINE_AUTO( sv_allow_touch, "1", FCVAR_ARCHIVE, "allow connect with touch controls" );
static CVAR_DEFINE_AUTO( sv_allow_vr, "1", FCVAR_ARCHIVE, "allow connect from vr version" );
static CVAR_DEFINE_AUTO( sv_allow_noinputdevices, "1", FCVAR_ARCHIVE, "allow connect from old versions without useragent" );
//============================================================================
/*
@ -472,7 +471,7 @@ void SV_ReadPackets( void )
==================
SV_CheckTimeouts
If a packet has not been received from a client for timeout->value
If a packet has not been received from a client for timeout.value
seconds, drop the conneciton. Server frames are used instead of
realtime to avoid dropping the local client while debugging.
@ -487,7 +486,7 @@ void SV_CheckTimeouts( void )
double droppoint;
int i, numclients = 0;
droppoint = host.realtime - timeout->value;
droppoint = host.realtime - timeout.value;
for( i = 0, cl = svs.clients; i < svs.maxclients; i++, cl++ )
{
@ -750,7 +749,7 @@ qboolean SV_ProcessUserAgent( netadr_t from, const char *useragent )
const char *input_devices_str = Info_ValueForKey( useragent, "d" );
const char *id = Info_ValueForKey( useragent, "uuid" );
if( !sv_allow_noinputdevices->value && ( !input_devices_str || !input_devices_str[0] ) )
if( !sv_allow_noinputdevices.value && ( !input_devices_str || !input_devices_str[0] ) )
{
SV_RejectConnection( from, "This server does not allow\nconnect without input devices list.\nPlease update your engine.\n" );
return false;
@ -760,22 +759,22 @@ qboolean SV_ProcessUserAgent( netadr_t from, const char *useragent )
{
int input_devices = Q_atoi( input_devices_str );
if( !sv_allow_touch->value && ( input_devices & INPUT_DEVICE_TOUCH ) )
if( !sv_allow_touch.value && ( input_devices & INPUT_DEVICE_TOUCH ) )
{
SV_RejectConnection( from, "This server does not allow touch\nDisable it (touch_enable 0)\nto play on this server\n" );
return false;
}
if( !sv_allow_mouse->value && ( input_devices & INPUT_DEVICE_MOUSE) )
if( !sv_allow_mouse.value && ( input_devices & INPUT_DEVICE_MOUSE) )
{
SV_RejectConnection( from, "This server does not allow mouse\nDisable it(m_ignore 1)\nto play on this server\n" );
return false;
}
if( !sv_allow_joystick->value && ( input_devices & INPUT_DEVICE_JOYSTICK) )
if( !sv_allow_joystick.value && ( input_devices & INPUT_DEVICE_JOYSTICK) )
{
SV_RejectConnection( from, "This server does not allow joystick\nDisable it(joy_enable 0)\nto play on this server\n" );
return false;
}
if( !sv_allow_vr->value && ( input_devices & INPUT_DEVICE_VR) )
if( !sv_allow_vr.value && ( input_devices & INPUT_DEVICE_VR) )
{
SV_RejectConnection( from, "This server does not allow VR\n" );
return false;
@ -852,9 +851,9 @@ void SV_Init( void )
Cvar_RegisterVariable( &sv_stepsize );
Cvar_RegisterVariable( &sv_newunit );
Cvar_RegisterVariable( &hostname );
timeout = Cvar_Get( "timeout", "125", FCVAR_SERVER, "connection timeout" );
sv_pausable = Cvar_Get( "pausable", "1", FCVAR_SERVER, "allow players to pause or not" );
sv_validate_changelevel = Cvar_Get( "sv_validate_changelevel", "0", 0, "test change level for level-designer errors" );
Cvar_RegisterVariable( &timeout );
Cvar_RegisterVariable( &sv_pausable );
Cvar_RegisterVariable( &sv_validate_changelevel );
Cvar_RegisterVariable( &sv_clienttrace );
Cvar_RegisterVariable( &sv_bounce );
Cvar_RegisterVariable( &sv_spectatormaxspeed );
@ -870,11 +869,11 @@ void SV_Init( void )
Cvar_RegisterVariable( &sv_friction );
Cvar_RegisterVariable( &sv_edgefriction );
Cvar_RegisterVariable( &sv_stopspeed );
sv_maxclients = Cvar_Get( "maxplayers", "1", FCVAR_LATCH, "server max capacity" );
sv_check_errors = Cvar_Get( "sv_check_errors", "0", FCVAR_ARCHIVE, "check edicts for errors" );
Cvar_RegisterVariable( &sv_maxclients );
Cvar_RegisterVariable( &sv_check_errors );
Cvar_RegisterVariable( &public_server );
sv_lighting_modulate = Cvar_Get( "r_lighting_modulate", "0.6", FCVAR_ARCHIVE, "lightstyles modulate scale" );
sv_reconnect_limit = Cvar_Get ("sv_reconnect_limit", "3", FCVAR_ARCHIVE, "max reconnect attempts" );
Cvar_RegisterVariable( &sv_lighting_modulate );
Cvar_RegisterVariable( &sv_reconnect_limit );
Cvar_RegisterVariable( &sv_failuretime );
Cvar_RegisterVariable( &sv_unlag );
Cvar_RegisterVariable( &sv_maxunlag );
@ -889,8 +888,9 @@ void SV_Init( void )
Cvar_RegisterVariable( &sv_instancedbaseline );
Cvar_RegisterVariable( &sv_consistency );
Cvar_RegisterVariable( &sv_downloadurl );
sv_novis = Cvar_Get( "sv_novis", "0", 0, "force to ignore server visibility" );
sv_hostmap = Cvar_Get( "hostmap", GI->startmap, 0, "keep name of last entered map" );
Cvar_RegisterVariable( &sv_novis );
Cvar_RegisterVariable( &sv_hostmap );
Cvar_DirectSet( &sv_hostmap, GI->startmap );
Cvar_RegisterVariable( &sv_password );
Cvar_RegisterVariable( &sv_lan );
Cvar_RegisterVariable( &sv_nat );
@ -922,11 +922,11 @@ void SV_Init( void )
Cvar_RegisterVariable( &sv_speedhack_kick );
sv_allow_joystick = Cvar_Get( "sv_allow_joystick", "1", FCVAR_ARCHIVE, "allow connect with joystick enabled" );
sv_allow_mouse = Cvar_Get( "sv_allow_mouse", "1", FCVAR_ARCHIVE, "allow connect with mouse" );
sv_allow_touch = Cvar_Get( "sv_allow_touch", "1", FCVAR_ARCHIVE, "allow connect with touch controls" );
sv_allow_vr = Cvar_Get( "sv_allow_vr", "1", FCVAR_ARCHIVE, "allow connect from vr version" );
sv_allow_noinputdevices = Cvar_Get( "sv_allow_noinputdevices", "1", FCVAR_ARCHIVE, "allow connect from old versions without useragent" );
Cvar_RegisterVariable( &sv_allow_joystick );
Cvar_RegisterVariable( &sv_allow_mouse );
Cvar_RegisterVariable( &sv_allow_touch );
Cvar_RegisterVariable( &sv_allow_vr );
Cvar_RegisterVariable( &sv_allow_noinputdevices );
// when we in developer-mode automatically turn cheats on
if( host_developer.value ) Cvar_SetValue( "sv_cheats", 1.0f );

View File

@ -71,7 +71,7 @@ void SV_CheckAllEnts( void )
edict_t *e;
int i;
if( !sv_check_errors->value || sv.state != ss_active )
if( !sv_check_errors.value || sv.state != ss_active )
return;
if(( nextcheck - Sys_DoubleTime()) > 0.0 )
@ -128,14 +128,14 @@ void SV_CheckVelocity( edict_t *ent )
{
if( IS_NAN( ent->v.velocity[i] ))
{
if( sv_check_errors->value )
if( sv_check_errors.value )
Con_Printf( "Got a NaN velocity on %s\n", STRING( ent->v.classname ));
ent->v.velocity[i] = 0.0f;
}
if( IS_NAN( ent->v.origin[i] ))
{
if( sv_check_errors->value )
if( sv_check_errors.value )
Con_Printf( "Got a NaN origin on %s\n", STRING( ent->v.classname ));
ent->v.origin[i] = 0.0f;
}
@ -147,7 +147,7 @@ void SV_CheckVelocity( edict_t *ent )
if( wishspd > maxspd )
{
wishspd = sqrt( wishspd );
if( sv_check_errors->value )
if( sv_check_errors.value )
Con_Printf( "Got a velocity too high on %s ( %.2f > %.2f )\n", STRING( ent->v.classname ), wishspd, sqrt( maxspd ));
wishspd = sv_maxvelocity.value / wishspd;
VectorScale( ent->v.velocity, wishspd, ent->v.velocity );

View File

@ -1604,7 +1604,7 @@ void SV_RunLightStyles( void )
lightstyle_t *ls;
float scale;
scale = sv_lighting_modulate->value;
scale = sv_lighting_modulate.value;
// run lightstyles animation
for( i = 0, ls = sv.lightstyles; i < MAX_LIGHTSTYLES; i++, ls++ )