* Rename voip cvar to cl_voip

* s/#if USE_VOIP/#ifdef USE_VOIP/
* Add generalised runtime cvar range checking, currently on [sv|cl]_voip,
  dedicated and a bunch of r_ variables
This commit is contained in:
Tim Angus 2008-07-07 22:31:39 +00:00
parent 809c361744
commit 37d664d4b2
24 changed files with 239 additions and 110 deletions

View file

@ -917,7 +917,7 @@ void CL_FirstSnapshot( void ) {
} }
#endif #endif
#if USE_VOIP #ifdef USE_VOIP
if (!clc.speexInitialized) { if (!clc.speexInitialized) {
int i; int i;
speex_bits_init(&clc.speexEncoderBits); speex_bits_init(&clc.speexEncoderBits);

View file

@ -52,7 +52,7 @@ kbutton_t in_lookup, in_lookdown, in_moveleft, in_moveright;
kbutton_t in_strafe, in_speed; kbutton_t in_strafe, in_speed;
kbutton_t in_up, in_down; kbutton_t in_up, in_down;
#if USE_VOIP #ifdef USE_VOIP
kbutton_t in_voiprecord; kbutton_t in_voiprecord;
#endif #endif
@ -220,7 +220,7 @@ void IN_SpeedUp(void) {IN_KeyUp(&in_speed);}
void IN_StrafeDown(void) {IN_KeyDown(&in_strafe);} void IN_StrafeDown(void) {IN_KeyDown(&in_strafe);}
void IN_StrafeUp(void) {IN_KeyUp(&in_strafe);} void IN_StrafeUp(void) {IN_KeyUp(&in_strafe);}
#if USE_VOIP #ifdef USE_VOIP
void IN_VoipRecordDown(void) void IN_VoipRecordDown(void)
{ {
IN_KeyDown(&in_voiprecord); IN_KeyDown(&in_voiprecord);
@ -759,7 +759,7 @@ void CL_WritePacket( void ) {
Com_Printf("MAX_PACKET_USERCMDS\n"); Com_Printf("MAX_PACKET_USERCMDS\n");
} }
#if USE_VOIP #ifdef USE_VOIP
if (clc.voipOutgoingDataSize > 0) { // only send if data. if (clc.voipOutgoingDataSize > 0) { // only send if data.
// Move cl_voipSendTarget from a string to the bitmasks if needed. // Move cl_voipSendTarget from a string to the bitmasks if needed.
if (cl_voipSendTarget->modified) { if (cl_voipSendTarget->modified) {
@ -841,7 +841,7 @@ void CL_WritePacket( void ) {
clc.voipOutgoingDataSize = 0; clc.voipOutgoingDataSize = 0;
clc.voipOutgoingDataFrames = 0; clc.voipOutgoingDataFrames = 0;
} else } else
#endif #endif
if ( count >= 1 ) { if ( count >= 1 ) {
if ( cl_showSend->integer ) { if ( cl_showSend->integer ) {
@ -1000,7 +1000,7 @@ void CL_InitInput( void ) {
Cmd_AddCommand ("+mlook", IN_MLookDown); Cmd_AddCommand ("+mlook", IN_MLookDown);
Cmd_AddCommand ("-mlook", IN_MLookUp); Cmd_AddCommand ("-mlook", IN_MLookUp);
#if USE_VOIP #ifdef USE_VOIP
Cmd_AddCommand ("+voiprecord", IN_VoipRecordDown); Cmd_AddCommand ("+voiprecord", IN_VoipRecordDown);
Cmd_AddCommand ("-voiprecord", IN_VoipRecordUp); Cmd_AddCommand ("-voiprecord", IN_VoipRecordUp);
#endif #endif

View file

@ -33,7 +33,7 @@ cvar_t *cl_useMumble;
cvar_t *cl_mumbleScale; cvar_t *cl_mumbleScale;
#endif #endif
#if USE_VOIP #ifdef USE_VOIP
cvar_t *cl_voipUseVAD; cvar_t *cl_voipUseVAD;
cvar_t *cl_voipVADThreshold; cvar_t *cl_voipVADThreshold;
cvar_t *cl_voipSend; cvar_t *cl_voipSend;
@ -41,7 +41,7 @@ cvar_t *cl_voipSendTarget;
cvar_t *cl_voipGainDuringCapture; cvar_t *cl_voipGainDuringCapture;
cvar_t *cl_voipCaptureMult; cvar_t *cl_voipCaptureMult;
cvar_t *cl_voipShowMeter; cvar_t *cl_voipShowMeter;
cvar_t *voip; cvar_t *cl_voip;
#endif #endif
cvar_t *cl_nodelta; cvar_t *cl_nodelta;
@ -179,7 +179,7 @@ void CL_UpdateMumble(void)
#endif #endif
#if USE_VOIP #ifdef USE_VOIP
static static
void CL_UpdateVoipIgnore(const char *idstr, qboolean ignore) void CL_UpdateVoipIgnore(const char *idstr, qboolean ignore)
{ {
@ -304,7 +304,7 @@ void CL_CaptureVoip(void)
dontCapture = qtrue; // single player game. dontCapture = qtrue; // single player game.
else if (clc.demoplaying) else if (clc.demoplaying)
dontCapture = qtrue; // playing back a demo. dontCapture = qtrue; // playing back a demo.
else if ( voip->integer == 0 ) else if ( cl_voip->integer == 0 )
dontCapture = qtrue; // client has VoIP support disabled. dontCapture = qtrue; // client has VoIP support disabled.
else if ( audioMult == 0.0f ) else if ( audioMult == 0.0f )
dontCapture = qtrue; // basically silenced incoming audio. dontCapture = qtrue; // basically silenced incoming audio.
@ -1162,7 +1162,7 @@ void CL_Disconnect( qboolean showMainMenu ) {
} }
#endif #endif
#if USE_VOIP #ifdef USE_VOIP
if (cl_voipSend->integer) { if (cl_voipSend->integer) {
int tmp = cl_voipUseVAD->integer; int tmp = cl_voipUseVAD->integer;
cl_voipUseVAD->integer = 0; // disable this for a moment. cl_voipUseVAD->integer = 0; // disable this for a moment.
@ -1219,7 +1219,7 @@ void CL_Disconnect( qboolean showMainMenu ) {
// not connected to a pure server anymore // not connected to a pure server anymore
cl_connectedToPureServer = qfalse; cl_connectedToPureServer = qfalse;
#if USE_VOIP #ifdef USE_VOIP
// not connected to voip server anymore. // not connected to voip server anymore.
cl_connectedToVoipServer = qfalse; cl_connectedToVoipServer = qfalse;
#endif #endif
@ -2640,7 +2640,7 @@ void CL_Frame ( int msec ) {
// update audio // update audio
S_Update(); S_Update();
#if USE_VOIP #ifdef USE_VOIP
CL_CaptureVoip(); CL_CaptureVoip();
#endif #endif
@ -2812,6 +2812,7 @@ void CL_InitRef( void ) {
ri.FS_FileExists = FS_FileExists; ri.FS_FileExists = FS_FileExists;
ri.Cvar_Get = Cvar_Get; ri.Cvar_Get = Cvar_Get;
ri.Cvar_Set = Cvar_Set; ri.Cvar_Set = Cvar_Set;
ri.Cvar_CheckRange = Cvar_CheckRange;
// cinematic stuff // cinematic stuff
@ -2978,7 +2979,7 @@ CL_Init
void CL_Init( void ) { void CL_Init( void ) {
Com_Printf( "----- Client Initialization -----\n" ); Com_Printf( "----- Client Initialization -----\n" );
Con_Init (); Con_Init ();
CL_ClearState (); CL_ClearState ();
@ -3035,7 +3036,7 @@ void CL_Init( void ) {
cl_conXOffset = Cvar_Get ("cl_conXOffset", "0", 0); cl_conXOffset = Cvar_Get ("cl_conXOffset", "0", 0);
#ifdef MACOS_X #ifdef MACOS_X
// In game video is REALLY slow in Mac OS X right now due to driver slowness // In game video is REALLY slow in Mac OS X right now due to driver slowness
cl_inGameVideo = Cvar_Get ("r_inGameVideo", "0", CVAR_ARCHIVE); cl_inGameVideo = Cvar_Get ("r_inGameVideo", "0", CVAR_ARCHIVE);
#else #else
cl_inGameVideo = Cvar_Get ("r_inGameVideo", "1", CVAR_ARCHIVE); cl_inGameVideo = Cvar_Get ("r_inGameVideo", "1", CVAR_ARCHIVE);
@ -3052,7 +3053,7 @@ void CL_Init( void ) {
m_forward = Cvar_Get ("m_forward", "0.25", CVAR_ARCHIVE); m_forward = Cvar_Get ("m_forward", "0.25", CVAR_ARCHIVE);
m_side = Cvar_Get ("m_side", "0.25", CVAR_ARCHIVE); m_side = Cvar_Get ("m_side", "0.25", CVAR_ARCHIVE);
#ifdef MACOS_X #ifdef MACOS_X
// Input is jittery on OS X w/o this // Input is jittery on OS X w/o this
m_filter = Cvar_Get ("m_filter", "1", CVAR_ARCHIVE); m_filter = Cvar_Get ("m_filter", "1", CVAR_ARCHIVE);
#else #else
m_filter = Cvar_Get ("m_filter", "0", CVAR_ARCHIVE); m_filter = Cvar_Get ("m_filter", "0", CVAR_ARCHIVE);
@ -3091,7 +3092,7 @@ void CL_Init( void ) {
cl_mumbleScale = Cvar_Get ("cl_mumbleScale", "0.0254", CVAR_ARCHIVE); cl_mumbleScale = Cvar_Get ("cl_mumbleScale", "0.0254", CVAR_ARCHIVE);
#endif #endif
#if USE_VOIP #ifdef USE_VOIP
cl_voipSend = Cvar_Get ("cl_voipSend", "0", 0); cl_voipSend = Cvar_Get ("cl_voipSend", "0", 0);
cl_voipSendTarget = Cvar_Get ("cl_voipSendTarget", "all", 0); cl_voipSendTarget = Cvar_Get ("cl_voipSendTarget", "all", 0);
cl_voipGainDuringCapture = Cvar_Get ("cl_voipGainDuringCapture", "0.2", CVAR_ARCHIVE); cl_voipGainDuringCapture = Cvar_Get ("cl_voipGainDuringCapture", "0.2", CVAR_ARCHIVE);
@ -3099,24 +3100,21 @@ void CL_Init( void ) {
cl_voipUseVAD = Cvar_Get ("cl_voipUseVAD", "0", CVAR_ARCHIVE); cl_voipUseVAD = Cvar_Get ("cl_voipUseVAD", "0", CVAR_ARCHIVE);
cl_voipVADThreshold = Cvar_Get ("cl_voipVADThreshold", "0.25", CVAR_ARCHIVE); cl_voipVADThreshold = Cvar_Get ("cl_voipVADThreshold", "0.25", CVAR_ARCHIVE);
cl_voipShowMeter = Cvar_Get ("cl_voipShowMeter", "1", CVAR_ARCHIVE); cl_voipShowMeter = Cvar_Get ("cl_voipShowMeter", "1", CVAR_ARCHIVE);
voip = Cvar_Get ("voip", "1", CVAR_USERINFO | CVAR_ARCHIVE | CVAR_LATCH);
// This is a protocol version number. // This is a protocol version number.
if ( (voip->integer < 0) || (voip->integer > 1) ) { cl_voip = Cvar_Get ("cl_voip", "1", CVAR_USERINFO | CVAR_ARCHIVE | CVAR_LATCH);
Com_Printf("WARNING: voip cvar must be 0 or 1. Setting to 1."); Cvar_CheckRange( cl_voip, 0, 1, qtrue );
Cvar_Set ("voip", "1");
}
// If your data rate is too low, you'll get Connection Interrupted warnings // If your data rate is too low, you'll get Connection Interrupted warnings
// when VoIP packets arrive, even if you have a broadband connection. // when VoIP packets arrive, even if you have a broadband connection.
// This might work on rates lower than 25000, but for safety's sake, we'll // This might work on rates lower than 25000, but for safety's sake, we'll
// just demand it. Who doesn't have at least a DSL line now, anyhow? If // just demand it. Who doesn't have at least a DSL line now, anyhow? If
// you don't, you don't need VoIP. :) // you don't, you don't need VoIP. :)
if ((voip->integer) && (Cvar_VariableIntegerValue("rate") < 25000)) { if ((cl_voip->integer) && (Cvar_VariableIntegerValue("rate") < 25000)) {
Com_Printf("Your network rate is too slow for VoIP.\n"); Com_Printf("Your network rate is too slow for VoIP.\n");
Com_Printf("Set 'Data Rate' to 'LAN/Cable/xDSL' in 'Setup/System/Network' and restart.\n"); Com_Printf("Set 'Data Rate' to 'LAN/Cable/xDSL' in 'Setup/System/Network' and restart.\n");
Com_Printf("Until then, VoIP is disabled.\n"); Com_Printf("Until then, VoIP is disabled.\n");
Cvar_Set("voip", "0"); Cvar_Set("cl_voip", "0");
} }
#endif #endif
@ -3161,7 +3159,7 @@ void CL_Init( void ) {
Cvar_Set( "cl_running", "1" ); Cvar_Set( "cl_running", "1" );
CL_GenerateQKey(); CL_GenerateQKey();
Cvar_Get( "cl_guid", "", CVAR_USERINFO | CVAR_ROM ); Cvar_Get( "cl_guid", "", CVAR_USERINFO | CVAR_ROM );
CL_UpdateGUID( NULL, 0 ); CL_UpdateGUID( NULL, 0 );

View file

@ -330,7 +330,7 @@ void CL_ParseSnapshot( msg_t *msg ) {
int cl_connectedToPureServer; int cl_connectedToPureServer;
int cl_connectedToCheatServer; int cl_connectedToCheatServer;
#if USE_VOIP #ifdef USE_VOIP
int cl_connectedToVoipServer; int cl_connectedToVoipServer;
#endif #endif
@ -362,7 +362,7 @@ void CL_SystemInfoChanged( void ) {
return; return;
} }
#if USE_VOIP #ifdef USE_VOIP
// in the future, (val) will be a protocol version string, so only // in the future, (val) will be a protocol version string, so only
// accept explicitly 1, not generally non-zero. // accept explicitly 1, not generally non-zero.
s = Info_ValueForKey( systemInfo, "sv_voip" ); s = Info_ValueForKey( systemInfo, "sv_voip" );
@ -635,11 +635,11 @@ void CL_ParseDownload ( msg_t *msg ) {
} }
} }
#if USE_VOIP #ifdef USE_VOIP
static static
qboolean CL_ShouldIgnoreVoipSender(int sender) qboolean CL_ShouldIgnoreVoipSender(int sender)
{ {
if (!voip->integer) if (!cl_voip->integer)
return qtrue; // VoIP is disabled. return qtrue; // VoIP is disabled.
else if ((sender == clc.clientNum) && (!clc.demoplaying)) else if ((sender == clc.clientNum) && (!clc.demoplaying))
return qtrue; // ignore own voice (unless playing back a demo). return qtrue; // ignore own voice (unless playing back a demo).
@ -900,7 +900,7 @@ void CL_ParseServerMessage( msg_t *msg ) {
CL_ParseDownload( msg ); CL_ParseDownload( msg );
break; break;
case svc_voip: case svc_voip:
#if USE_VOIP #ifdef USE_VOIP
CL_ParseVoip( msg ); CL_ParseVoip( msg );
#endif #endif
break; break;

View file

@ -365,7 +365,7 @@ void SCR_DrawVoipMeter( void ) {
return; // single player game. return; // single player game.
else if (clc.demoplaying) else if (clc.demoplaying)
return; // playing back a demo. return; // playing back a demo.
else if (!voip->integer) else if (!cl_voip->integer)
return; // client has VoIP support disabled. return; // client has VoIP support disabled.
limit = (int) (clc.voipPower * 10.0f); limit = (int) (clc.voipPower * 10.0f);
@ -528,9 +528,9 @@ void SCR_DrawScreenField( stereoFrame_t stereoFrame ) {
// always supply STEREO_CENTER as vieworg offset is now done by the engine. // always supply STEREO_CENTER as vieworg offset is now done by the engine.
CL_CGameRendering(stereoFrame); CL_CGameRendering(stereoFrame);
SCR_DrawDemoRecording(); SCR_DrawDemoRecording();
#if USE_VOIP #ifdef USE_VOIP
SCR_DrawVoipMeter(); SCR_DrawVoipMeter();
#endif #endif
break; break;
} }
} }

View file

@ -34,7 +34,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include "cl_curl.h" #include "cl_curl.h"
#endif /* USE_CURL */ #endif /* USE_CURL */
#if USE_VOIP #ifdef USE_VOIP
#include "speex/speex.h" #include "speex/speex.h"
#include "speex/speex_preprocess.h" #include "speex/speex_preprocess.h"
#endif #endif
@ -230,7 +230,7 @@ typedef struct {
int timeDemoMaxDuration; // maximum frame duration int timeDemoMaxDuration; // maximum frame duration
unsigned char timeDemoDurations[ MAX_TIMEDEMO_DURATIONS ]; // log of frame durations unsigned char timeDemoDurations[ MAX_TIMEDEMO_DURATIONS ]; // log of frame durations
#if USE_VOIP #ifdef USE_VOIP
qboolean speexInitialized; qboolean speexInitialized;
int speexFrameSize; int speexFrameSize;
int speexSampleRate; int speexSampleRate;
@ -407,7 +407,7 @@ extern cvar_t *cl_useMumble;
extern cvar_t *cl_mumbleScale; extern cvar_t *cl_mumbleScale;
#endif #endif
#if USE_VOIP #ifdef USE_VOIP
// cl_voipSendTarget is a string: "all" to broadcast to everyone, "none" to // cl_voipSendTarget is a string: "all" to broadcast to everyone, "none" to
// send to no one, or a comma-separated list of client numbers: // send to no one, or a comma-separated list of client numbers:
// "0,7,2,23" ... an empty string is treated like "all". // "0,7,2,23" ... an empty string is treated like "all".
@ -418,7 +418,7 @@ extern cvar_t *cl_voipSendTarget;
extern cvar_t *cl_voipGainDuringCapture; extern cvar_t *cl_voipGainDuringCapture;
extern cvar_t *cl_voipCaptureMult; extern cvar_t *cl_voipCaptureMult;
extern cvar_t *cl_voipShowMeter; extern cvar_t *cl_voipShowMeter;
extern cvar_t *voip; extern cvar_t *cl_voip;
#endif #endif
//================================================= //=================================================
@ -475,7 +475,7 @@ extern kbutton_t in_mlook, in_klook;
extern kbutton_t in_strafe; extern kbutton_t in_strafe;
extern kbutton_t in_speed; extern kbutton_t in_speed;
#if USE_VOIP #ifdef USE_VOIP
extern kbutton_t in_voiprecord; extern kbutton_t in_voiprecord;
#endif #endif
@ -500,7 +500,7 @@ void Key_SetCatcher( int catcher );
extern int cl_connectedToPureServer; extern int cl_connectedToPureServer;
extern int cl_connectedToCheatServer; extern int cl_connectedToCheatServer;
#if USE_VOIP #ifdef USE_VOIP
extern int cl_connectedToVoipServer; extern int cl_connectedToVoipServer;
void CL_Voip_f( void ); void CL_Voip_f( void );
#endif #endif

View file

@ -121,7 +121,7 @@ void S_Base_SoundInfo(void) {
} }
#if USE_VOIP #ifdef USE_VOIP
static static
void S_Base_StartCapture( void ) void S_Base_StartCapture( void )
{ {
@ -1530,7 +1530,7 @@ qboolean S_Base_Init( soundInterface_t *si ) {
si->SoundInfo = S_Base_SoundInfo; si->SoundInfo = S_Base_SoundInfo;
si->SoundList = S_Base_SoundList; si->SoundList = S_Base_SoundList;
#if USE_VOIP #ifdef USE_VOIP
si->StartCapture = S_Base_StartCapture; si->StartCapture = S_Base_StartCapture;
si->AvailableCaptureSamples = S_Base_AvailableCaptureSamples; si->AvailableCaptureSamples = S_Base_AvailableCaptureSamples;
si->Capture = S_Base_Capture; si->Capture = S_Base_Capture;

View file

@ -140,7 +140,7 @@ typedef struct
void (*ClearSoundBuffer)( void ); void (*ClearSoundBuffer)( void );
void (*SoundInfo)( void ); void (*SoundInfo)( void );
void (*SoundList)( void ); void (*SoundList)( void );
#if USE_VOIP #ifdef USE_VOIP
void (*StartCapture)( void ); void (*StartCapture)( void );
int (*AvailableCaptureSamples)( void ); int (*AvailableCaptureSamples)( void );
void (*Capture)( int samples, byte *data ); void (*Capture)( int samples, byte *data );

View file

@ -62,7 +62,7 @@ static qboolean S_ValidSoundInterface( soundInterface_t *si )
if( !si->SoundInfo ) return qfalse; if( !si->SoundInfo ) return qfalse;
if( !si->SoundList ) return qfalse; if( !si->SoundList ) return qfalse;
#if USE_VOIP #ifdef USE_VOIP
if( !si->StartCapture ) return qfalse; if( !si->StartCapture ) return qfalse;
if( !si->AvailableCaptureSamples ) return qfalse; if( !si->AvailableCaptureSamples ) return qfalse;
if( !si->Capture ) return qfalse; if( !si->Capture ) return qfalse;
@ -313,7 +313,7 @@ void S_SoundList( void )
} }
#if USE_VOIP #ifdef USE_VOIP
/* /*
================= =================
S_StartCapture S_StartCapture

View file

@ -1696,7 +1696,7 @@ void S_AL_MusicUpdate( void )
static ALCdevice *alDevice; static ALCdevice *alDevice;
static ALCcontext *alContext; static ALCcontext *alContext;
#if USE_VOIP #ifdef USE_VOIP
static ALCdevice *alCaptureDevice; static ALCdevice *alCaptureDevice;
static cvar_t *s_alCapture; static cvar_t *s_alCapture;
#endif #endif
@ -1844,7 +1844,7 @@ void S_AL_SoundList( void )
{ {
} }
#if USE_VOIP #ifdef USE_VOIP
static static
void S_AL_StartCapture( void ) void S_AL_StartCapture( void )
{ {
@ -1925,7 +1925,7 @@ void S_AL_Shutdown( void )
qalcDestroyContext(alContext); qalcDestroyContext(alContext);
qalcCloseDevice(alDevice); qalcCloseDevice(alDevice);
#if USE_VOIP #ifdef USE_VOIP
if (alCaptureDevice != NULL) { if (alCaptureDevice != NULL) {
qalcCaptureStop(alCaptureDevice); qalcCaptureStop(alCaptureDevice);
qalcCaptureCloseDevice(alCaptureDevice); qalcCaptureCloseDevice(alCaptureDevice);
@ -2067,7 +2067,7 @@ qboolean S_AL_Init( soundInterface_t *si )
qalDopplerFactor( s_alDopplerFactor->value ); qalDopplerFactor( s_alDopplerFactor->value );
qalDopplerVelocity( s_alDopplerSpeed->value ); qalDopplerVelocity( s_alDopplerSpeed->value );
#if USE_VOIP #ifdef USE_VOIP
// !!! FIXME: some of these alcCaptureOpenDevice() values should be cvars. // !!! FIXME: some of these alcCaptureOpenDevice() values should be cvars.
// !!! FIXME: add support for capture device enumeration. // !!! FIXME: add support for capture device enumeration.
// !!! FIXME: add some better error reporting. // !!! FIXME: add some better error reporting.
@ -2122,7 +2122,7 @@ qboolean S_AL_Init( soundInterface_t *si )
si->SoundInfo = S_AL_SoundInfo; si->SoundInfo = S_AL_SoundInfo;
si->SoundList = S_AL_SoundList; si->SoundList = S_AL_SoundList;
#if USE_VOIP #ifdef USE_VOIP
si->StartCapture = S_AL_StartCapture; si->StartCapture = S_AL_StartCapture;
si->AvailableCaptureSamples = S_AL_AvailableCaptureSamples; si->AvailableCaptureSamples = S_AL_AvailableCaptureSamples;
si->Capture = S_AL_Capture; si->Capture = S_AL_Capture;

View file

@ -72,7 +72,7 @@ void SNDDMA_Activate( void );
void S_UpdateBackgroundTrack( void ); void S_UpdateBackgroundTrack( void );
#if USE_VOIP #ifdef USE_VOIP
void S_StartCapture( void ); void S_StartCapture( void );
int S_AvailableCaptureSamples( void ); int S_AvailableCaptureSamples( void );
void S_Capture( int samples, byte *data ); void S_Capture( int samples, byte *data );

View file

@ -473,10 +473,12 @@ qboolean Com_AddStartupCommands( void ) {
continue; continue;
} }
// set commands won't override menu startup // set commands already added with Com_StartupVariable
if ( Q_stricmpn( com_consoleLines[i], "set", 3 ) ) { if ( !Q_stricmpn( com_consoleLines[i], "set", 3 ) ) {
added = qtrue; continue;
} }
added = qtrue;
Cbuf_AddText( com_consoleLines[i] ); Cbuf_AddText( com_consoleLines[i] );
Cbuf_AddText( "\n" ); Cbuf_AddText( "\n" );
} }
@ -2562,8 +2564,10 @@ void Com_Init( char *commandLine ) {
// get dedicated here for proper hunk megs initialization // get dedicated here for proper hunk megs initialization
#ifdef DEDICATED #ifdef DEDICATED
com_dedicated = Cvar_Get ("dedicated", "1", CVAR_INIT); com_dedicated = Cvar_Get ("dedicated", "1", CVAR_INIT);
Cvar_CheckRange( com_dedicated, 1, 2, qtrue );
#else #else
com_dedicated = Cvar_Get ("dedicated", "0", CVAR_LATCH); com_dedicated = Cvar_Get ("dedicated", "0", CVAR_LATCH);
Cvar_CheckRange( com_dedicated, 0, 2, qtrue );
#endif #endif
// allocate the stack based hunk allocator // allocate the stack based hunk allocator
Com_InitHunkMemory(); Com_InitHunkMemory();

View file

@ -189,6 +189,109 @@ void Cvar_CommandCompletion( void(*callback)(const char *s) ) {
} }
} }
/*
============
Cvar_Validate
============
*/
static const char *Cvar_Validate( cvar_t *var,
const char *value, qboolean warn )
{
static char s[ MAX_CVAR_VALUE_STRING ];
float valuef;
qboolean changed = qfalse;
if( !var->validate )
return value;
if( !value )
return value;
if( Q_isanumber( value ) )
{
valuef = atof( value );
if( var->integral )
{
if( !Q_isintegral( valuef ) )
{
if( warn )
Com_Printf( "WARNING: cvar '%s' must be integral", var->name );
valuef = (int)valuef;
changed = qtrue;
}
}
}
else
{
if( warn )
Com_Printf( "WARNING: cvar '%s' must be numeric", var->name );
valuef = atof( var->resetString );
changed = qtrue;
}
if( valuef < var->min )
{
if( warn )
{
if( changed )
Com_Printf( " and is" );
else
Com_Printf( "WARNING: cvar '%s'", var->name );
if( Q_isintegral( var->min ) )
Com_Printf( " out of range (min %d)", (int)var->min );
else
Com_Printf( " out of range (min %f)", var->min );
}
valuef = var->min;
changed = qtrue;
}
else if( valuef > var->max )
{
if( warn )
{
if( changed )
Com_Printf( " and is" );
else
Com_Printf( "WARNING: cvar '%s'", var->name );
if( Q_isintegral( var->max ) )
Com_Printf( " out of range (max %d)", (int)var->max );
else
Com_Printf( " out of range (max %f)", var->max );
}
valuef = var->max;
changed = qtrue;
}
if( changed )
{
if( Q_isintegral( valuef ) )
{
Com_sprintf( s, sizeof( s ), "%d", (int)valuef );
if( warn )
Com_Printf( ", setting to %d\n", (int)valuef );
}
else
{
Com_sprintf( s, sizeof( s ), "%f", valuef );
if( warn )
Com_Printf( ", setting to %f\n", valuef );
}
return s;
}
else
return value;
}
/* /*
============ ============
@ -220,6 +323,8 @@ cvar_t *Cvar_Get( const char *var_name, const char *var_value, int flags ) {
var = Cvar_FindVar (var_name); var = Cvar_FindVar (var_name);
if ( var ) { if ( var ) {
var_value = Cvar_Validate( var, var_value, qfalse );
// if the C code is now specifying a variable that the user already // if the C code is now specifying a variable that the user already
// set a value for, take the new value as the reset value // set a value for, take the new value as the reset value
if ( ( var->flags & CVAR_USER_CREATED ) && !( flags & CVAR_USER_CREATED ) if ( ( var->flags & CVAR_USER_CREATED ) && !( flags & CVAR_USER_CREATED )
@ -282,6 +387,7 @@ cvar_t *Cvar_Get( const char *var_name, const char *var_value, int flags ) {
var->value = atof (var->string); var->value = atof (var->string);
var->integer = atoi(var->string); var->integer = atoi(var->string);
var->resetString = CopyString( var_value ); var->resetString = CopyString( var_value );
var->validate = qfalse;
// link the variable in // link the variable in
var->next = cvar_vars; var->next = cvar_vars;
@ -364,6 +470,8 @@ cvar_t *Cvar_Set2( const char *var_name, const char *value, qboolean force ) {
value = var->resetString; value = var->resetString;
} }
value = Cvar_Validate( var, value, qtrue );
if((var->flags & CVAR_LATCH) && var->latchedString) { if((var->flags & CVAR_LATCH) && var->latchedString) {
if(!strcmp(value,var->latchedString)) if(!strcmp(value,var->latchedString))
return var; return var;
@ -877,6 +985,22 @@ void Cvar_InfoStringBuffer( int bit, char* buff, int buffsize ) {
Q_strncpyz(buff,Cvar_InfoString(bit),buffsize); Q_strncpyz(buff,Cvar_InfoString(bit),buffsize);
} }
/*
=====================
Cvar_CheckRange
=====================
*/
void Cvar_CheckRange( cvar_t *var, float min, float max, qboolean integral )
{
var->validate = qtrue;
var->min = min;
var->max = max;
var->integral = integral;
// Force an initial range check
Cvar_Set( var->name, var->string );
}
/* /*
===================== =====================
Cvar_Register Cvar_Register
@ -899,7 +1023,7 @@ void Cvar_Register( vmCvar_t *vmCvar, const char *varName, const char *defaultVa
/* /*
===================== =====================
Cvar_Register Cvar_Update
updates an interpreted modules' version of a cvar updates an interpreted modules' version of a cvar
===================== =====================

View file

@ -726,6 +726,28 @@ char* Q_strrchr( const char* string, int c )
return sp; return sp;
} }
qboolean Q_isanumber( const char *s )
{
#ifdef Q3_VM
//FIXME: implement
return qfalse;
#else
char *p;
if( *s == '\0' )
return qfalse;
strtof( s, &p );
return *p == '\0';
#endif
}
qboolean Q_isintegral( float f )
{
return (int)f == f;
}
/* /*
============= =============
Q_strncpyz Q_strncpyz

View file

@ -678,6 +678,8 @@ int Q_isprint( int c );
int Q_islower( int c ); int Q_islower( int c );
int Q_isupper( int c ); int Q_isupper( int c );
int Q_isalpha( int c ); int Q_isalpha( int c );
qboolean Q_isanumber( const char *s );
qboolean Q_isintegral( float f );
// portable case insensitive compare // portable case insensitive compare
int Q_stricmp (const char *s1, const char *s2); int Q_stricmp (const char *s1, const char *s2);
@ -786,15 +788,19 @@ default values.
// nothing outside the Cvar_*() functions should modify these fields! // nothing outside the Cvar_*() functions should modify these fields!
typedef struct cvar_s { typedef struct cvar_s {
char *name; char *name;
char *string; char *string;
char *resetString; // cvar_restart will reset to this value char *resetString; // cvar_restart will reset to this value
char *latchedString; // for CVAR_LATCH vars char *latchedString; // for CVAR_LATCH vars
int flags; int flags;
qboolean modified; // set each time the cvar is changed qboolean modified; // set each time the cvar is changed
int modificationCount; // incremented each time the cvar is changed int modificationCount; // incremented each time the cvar is changed
float value; // atof( string ) float value; // atof( string )
int integer; // atoi( string ) int integer; // atoi( string )
qboolean validate;
qboolean integral;
float min;
float max;
struct cvar_s *next; struct cvar_s *next;
struct cvar_s *hashNext; struct cvar_s *hashNext;
} cvar_t; } cvar_t;

View file

@ -528,6 +528,7 @@ char *Cvar_InfoString_Big( int bit );
// returns an info string containing all the cvars that have the given bit set // returns an info string containing all the cvars that have the given bit set
// in their flags ( CVAR_USERINFO, CVAR_SERVERINFO, CVAR_SYSTEMINFO, etc ) // in their flags ( CVAR_USERINFO, CVAR_SERVERINFO, CVAR_SYSTEMINFO, etc )
void Cvar_InfoStringBuffer( int bit, char *buff, int buffsize ); void Cvar_InfoStringBuffer( int bit, char *buff, int buffsize );
void Cvar_CheckRange( cvar_t *cv, float minVal, float maxVal, qboolean shouldBeIntegral );
void Cvar_Restart_f( void ); void Cvar_Restart_f( void );

View file

@ -159,30 +159,6 @@ int max_polys;
cvar_t *r_maxpolyverts; cvar_t *r_maxpolyverts;
int max_polyverts; int max_polyverts;
static void AssertCvarRange( cvar_t *cv, float minVal, float maxVal, qboolean shouldBeIntegral )
{
if ( shouldBeIntegral )
{
if ( ( int ) cv->value != cv->integer )
{
ri.Printf( PRINT_WARNING, "WARNING: cvar '%s' must be integral (%f)\n", cv->name, cv->value );
ri.Cvar_Set( cv->name, va( "%d", cv->integer ) );
}
}
if ( cv->value < minVal )
{
ri.Printf( PRINT_WARNING, "WARNING: cvar '%s' out of range (%f < %f)\n", cv->name, cv->value, minVal );
ri.Cvar_Set( cv->name, va( "%f", minVal ) );
}
else if ( cv->value > maxVal )
{
ri.Printf( PRINT_WARNING, "WARNING: cvar '%s' out of range (%f > %f)\n", cv->name, cv->value, maxVal );
ri.Cvar_Set( cv->name, va( "%f", maxVal ) );
}
}
/* /*
** InitOpenGL ** InitOpenGL
** **
@ -918,7 +894,7 @@ void R_Register( void )
r_picmip = ri.Cvar_Get ("r_picmip", "1", CVAR_ARCHIVE | CVAR_LATCH ); r_picmip = ri.Cvar_Get ("r_picmip", "1", CVAR_ARCHIVE | CVAR_LATCH );
r_roundImagesDown = ri.Cvar_Get ("r_roundImagesDown", "1", CVAR_ARCHIVE | CVAR_LATCH ); r_roundImagesDown = ri.Cvar_Get ("r_roundImagesDown", "1", CVAR_ARCHIVE | CVAR_LATCH );
r_colorMipLevels = ri.Cvar_Get ("r_colorMipLevels", "0", CVAR_LATCH ); r_colorMipLevels = ri.Cvar_Get ("r_colorMipLevels", "0", CVAR_LATCH );
AssertCvarRange( r_picmip, 0, 16, qtrue ); ri.Cvar_CheckRange( r_picmip, 0, 16, qtrue );
r_detailTextures = ri.Cvar_Get( "r_detailtextures", "1", CVAR_ARCHIVE | CVAR_LATCH ); r_detailTextures = ri.Cvar_Get( "r_detailtextures", "1", CVAR_ARCHIVE | CVAR_LATCH );
r_texturebits = ri.Cvar_Get( "r_texturebits", "0", CVAR_ARCHIVE | CVAR_LATCH ); r_texturebits = ri.Cvar_Get( "r_texturebits", "0", CVAR_ARCHIVE | CVAR_LATCH );
r_colorbits = ri.Cvar_Get( "r_colorbits", "0", CVAR_ARCHIVE | CVAR_LATCH ); r_colorbits = ri.Cvar_Get( "r_colorbits", "0", CVAR_ARCHIVE | CVAR_LATCH );
@ -944,7 +920,7 @@ void R_Register( void )
// temporary latched variables that can only change over a restart // temporary latched variables that can only change over a restart
// //
r_displayRefresh = ri.Cvar_Get( "r_displayRefresh", "0", CVAR_LATCH ); r_displayRefresh = ri.Cvar_Get( "r_displayRefresh", "0", CVAR_LATCH );
AssertCvarRange( r_displayRefresh, 0, 200, qtrue ); ri.Cvar_CheckRange( r_displayRefresh, 0, 200, qtrue );
r_fullbright = ri.Cvar_Get ("r_fullbright", "0", CVAR_LATCH|CVAR_CHEAT ); r_fullbright = ri.Cvar_Get ("r_fullbright", "0", CVAR_LATCH|CVAR_CHEAT );
r_mapOverBrightBits = ri.Cvar_Get ("r_mapOverBrightBits", "2", CVAR_LATCH ); r_mapOverBrightBits = ri.Cvar_Get ("r_mapOverBrightBits", "2", CVAR_LATCH );
r_intensity = ri.Cvar_Get ("r_intensity", "1", CVAR_LATCH ); r_intensity = ri.Cvar_Get ("r_intensity", "1", CVAR_LATCH );
@ -957,7 +933,7 @@ void R_Register( void )
r_lodbias = ri.Cvar_Get( "r_lodbias", "0", CVAR_ARCHIVE ); r_lodbias = ri.Cvar_Get( "r_lodbias", "0", CVAR_ARCHIVE );
r_flares = ri.Cvar_Get ("r_flares", "0", CVAR_ARCHIVE ); r_flares = ri.Cvar_Get ("r_flares", "0", CVAR_ARCHIVE );
r_znear = ri.Cvar_Get( "r_znear", "4", CVAR_CHEAT ); r_znear = ri.Cvar_Get( "r_znear", "4", CVAR_CHEAT );
AssertCvarRange( r_znear, 0.001f, 200, qtrue ); ri.Cvar_CheckRange( r_znear, 0.001f, 200, qtrue );
r_zproj = ri.Cvar_Get( "r_zproj", "64", CVAR_ARCHIVE ); r_zproj = ri.Cvar_Get( "r_zproj", "64", CVAR_ARCHIVE );
r_stereoSeparation = ri.Cvar_Get( "r_stereoSeparation", "64", CVAR_ARCHIVE ); r_stereoSeparation = ri.Cvar_Get( "r_stereoSeparation", "64", CVAR_ARCHIVE );
r_ignoreGLErrors = ri.Cvar_Get( "r_ignoreGLErrors", "1", CVAR_ARCHIVE ); r_ignoreGLErrors = ri.Cvar_Get( "r_ignoreGLErrors", "1", CVAR_ARCHIVE );

View file

@ -131,6 +131,7 @@ typedef struct {
cvar_t *(*Cvar_Get)( const char *name, const char *value, int flags ); cvar_t *(*Cvar_Get)( const char *name, const char *value, int flags );
void (*Cvar_Set)( const char *name, const char *value ); void (*Cvar_Set)( const char *name, const char *value );
void (*Cvar_CheckRange)( cvar_t *cv, float minVal, float maxVal, qboolean shouldBeIntegral );
void (*Cmd_AddCommand)( const char *name, void(*cmd)(void) ); void (*Cmd_AddCommand)( const char *name, void(*cmd)(void) );
void (*Cmd_RemoveCommand)( const char *name ); void (*Cmd_RemoveCommand)( const char *name );

View file

@ -33,7 +33,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#define MAX_ENT_CLUSTERS 16 #define MAX_ENT_CLUSTERS 16
#if USE_VOIP #ifdef USE_VOIP
typedef struct voipServerPacket_s typedef struct voipServerPacket_s
{ {
int generation; int generation;
@ -179,7 +179,7 @@ typedef struct client_s {
netchan_buffer_t *netchan_start_queue; netchan_buffer_t *netchan_start_queue;
netchan_buffer_t **netchan_end_queue; netchan_buffer_t **netchan_end_queue;
#if USE_VOIP #ifdef USE_VOIP
qboolean hasVoip; qboolean hasVoip;
qboolean muteAllVoip; qboolean muteAllVoip;
qboolean ignoreVoipFromClient[MAX_CLIENTS]; qboolean ignoreVoipFromClient[MAX_CLIENTS];
@ -284,7 +284,7 @@ extern cvar_t *sv_strictAuth;
extern serverBan_t serverBans[SERVER_MAXBANS]; extern serverBan_t serverBans[SERVER_MAXBANS];
extern int serverBansCount; extern int serverBansCount;
#if USE_VOIP #ifdef USE_VOIP
extern cvar_t *sv_voip; extern cvar_t *sv_voip;
#endif #endif
@ -345,7 +345,7 @@ void SV_ClientThink (client_t *cl, usercmd_t *cmd);
void SV_WriteDownloadToClient( client_t *cl , msg_t *msg ); void SV_WriteDownloadToClient( client_t *cl , msg_t *msg );
#if USE_VOIP #ifdef USE_VOIP
void SV_WriteVoipToClient( client_t *cl, msg_t *msg ); void SV_WriteVoipToClient( client_t *cl, msg_t *msg );
#endif #endif

View file

@ -1083,7 +1083,7 @@ void SV_WriteDownloadToClient( client_t *cl , msg_t *msg )
} }
} }
#if USE_VOIP #ifdef USE_VOIP
/* /*
================== ==================
SV_WriteVoipToClient SV_WriteVoipToClient
@ -1378,10 +1378,10 @@ void SV_UserinfoChanged( client_t *cl ) {
cl->snapshotMsec = 50; cl->snapshotMsec = 50;
} }
#if USE_VOIP #ifdef USE_VOIP
// in the future, (val) will be a protocol version string, so only // in the future, (val) will be a protocol version string, so only
// accept explicitly 1, not generally non-zero. // accept explicitly 1, not generally non-zero.
val = Info_ValueForKey (cl->userinfo, "voip"); val = Info_ValueForKey (cl->userinfo, "cl_voip");
cl->hasVoip = (atoi(val) == 1) ? qtrue : qfalse; cl->hasVoip = (atoi(val) == 1) ? qtrue : qfalse;
#endif #endif
@ -1421,7 +1421,7 @@ static void SV_UpdateUserinfo_f( client_t *cl ) {
} }
#if USE_VOIP #ifdef USE_VOIP
static static
void SV_UpdateVoipIgnore(client_t *cl, const char *idstr, qboolean ignore) void SV_UpdateVoipIgnore(client_t *cl, const char *idstr, qboolean ignore)
{ {
@ -1468,7 +1468,7 @@ static ucmd_t ucmds[] = {
{"stopdl", SV_StopDownload_f}, {"stopdl", SV_StopDownload_f},
{"donedl", SV_DoneDownload_f}, {"donedl", SV_DoneDownload_f},
#if USE_VOIP #ifdef USE_VOIP
{"voip", SV_Voip_f}, {"voip", SV_Voip_f},
#endif #endif
@ -1692,7 +1692,7 @@ static void SV_UserMove( client_t *cl, msg_t *msg, qboolean delta ) {
} }
#if USE_VOIP #ifdef USE_VOIP
static static
qboolean SV_ShouldIgnoreVoipSender(const client_t *cl) qboolean SV_ShouldIgnoreVoipSender(const client_t *cl)
{ {
@ -1922,7 +1922,7 @@ void SV_ExecuteClientMessage( client_t *cl, msg_t *msg ) {
} else if ( c == clc_moveNoDelta ) { } else if ( c == clc_moveNoDelta ) {
SV_UserMove( cl, msg, qfalse ); SV_UserMove( cl, msg, qfalse );
} else if ( c == clc_voip ) { } else if ( c == clc_voip ) {
#if USE_VOIP #ifdef USE_VOIP
SV_UserVoip( cl, msg ); SV_UserVoip( cl, msg );
#endif #endif
} else if ( c != clc_EOF ) { } else if ( c != clc_EOF ) {

View file

@ -654,12 +654,9 @@ void SV_Init (void) {
Cvar_Get ("sv_cheats", "1", CVAR_SYSTEMINFO | CVAR_ROM ); Cvar_Get ("sv_cheats", "1", CVAR_SYSTEMINFO | CVAR_ROM );
sv_serverid = Cvar_Get ("sv_serverid", "0", CVAR_SYSTEMINFO | CVAR_ROM ); sv_serverid = Cvar_Get ("sv_serverid", "0", CVAR_SYSTEMINFO | CVAR_ROM );
sv_pure = Cvar_Get ("sv_pure", "1", CVAR_SYSTEMINFO ); sv_pure = Cvar_Get ("sv_pure", "1", CVAR_SYSTEMINFO );
#if USE_VOIP #ifdef USE_VOIP
sv_voip = Cvar_Get ("sv_voip", "1", CVAR_SYSTEMINFO | CVAR_LATCH); sv_voip = Cvar_Get ("sv_voip", "1", CVAR_SYSTEMINFO | CVAR_LATCH);
if ( (sv_voip->integer < 0) || (sv_voip->integer > 1) ) { Cvar_CheckRange( sv_voip, 0, 1, qtrue );
Com_Printf("WARNING: sv_voip must be 0 or 1. Setting to 1.");
Cvar_Set ("sv_voip", "1");
}
#endif #endif
Cvar_Get ("sv_paks", "", CVAR_SYSTEMINFO | CVAR_ROM ); Cvar_Get ("sv_paks", "", CVAR_SYSTEMINFO | CVAR_ROM );
Cvar_Get ("sv_pakNames", "", CVAR_SYSTEMINFO | CVAR_ROM ); Cvar_Get ("sv_pakNames", "", CVAR_SYSTEMINFO | CVAR_ROM );

View file

@ -22,7 +22,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include "server.h" #include "server.h"
#if USE_VOIP #ifdef USE_VOIP
cvar_t *sv_voip; cvar_t *sv_voip;
#endif #endif
@ -411,9 +411,9 @@ void SVC_Info( netadr_t from ) {
Info_SetValueForKey( infostring, "gametype", va("%i", sv_gametype->integer ) ); Info_SetValueForKey( infostring, "gametype", va("%i", sv_gametype->integer ) );
Info_SetValueForKey( infostring, "pure", va("%i", sv_pure->integer ) ); Info_SetValueForKey( infostring, "pure", va("%i", sv_pure->integer ) );
#if USE_VOIP #ifdef USE_VOIP
if (sv_voip->integer) { if (sv_voip->integer) {
Info_SetValueForKey( infostring, "voip", va("%i", sv_voip->integer ) ); Info_SetValueForKey( infostring, "cl_voip", va("%i", sv_voip->integer ) );
} }
#endif #endif

View file

@ -653,7 +653,7 @@ void SV_SendClientSnapshot( client_t *client ) {
// Add any download data if the client is downloading // Add any download data if the client is downloading
SV_WriteDownloadToClient( client, &msg ); SV_WriteDownloadToClient( client, &msg );
#if USE_VOIP #ifdef USE_VOIP
SV_WriteVoipToClient( client, &msg ); SV_WriteVoipToClient( client, &msg );
#endif #endif

View file

@ -37,7 +37,7 @@ sv_voip: set to "1" (the default) to enable server-side VoIP support. Set to
"0" to disable. Without this, all VoIP packets are refused by the "0" to disable. Without this, all VoIP packets are refused by the
server, which means no one gets to use in-game VoIP. server, which means no one gets to use in-game VoIP.
voip: set to "1" (the default) to enable client-side VoIP support. Set to "0" cl_voip: set to "1" (the default) to enable client-side VoIP support. Set to "0"
to disable. Without this, you will neither be able to transmit voice nor to disable. Without this, you will neither be able to transmit voice nor
hear other people. hear other people.