diff options
author | Tim Angus <tim@ngus.net> | 2009-10-03 15:17:16 +0000 |
---|---|---|
committer | Tim Angus <tim@ngus.net> | 2013-01-03 00:16:38 +0000 |
commit | 6d2ffb4c637a49983bc6ce22b68ccec0ed09e0f4 (patch) | |
tree | ff15343e4a2ae5a2512c1c21e05a3821a46f10da /src/client | |
parent | e9e52d0b7ec9bae071534df7581126d69d3e9bf8 (diff) |
* Merge ioq3-r1637
Diffstat (limited to 'src/client')
-rw-r--r-- | src/client/cl_avi.c | 2 | ||||
-rw-r--r-- | src/client/cl_cgame.c | 2 | ||||
-rw-r--r-- | src/client/cl_main.c | 114 | ||||
-rw-r--r-- | src/client/cl_ui.c | 2 | ||||
-rw-r--r-- | src/client/snd_dma.c | 11 | ||||
-rw-r--r-- | src/client/snd_main.c | 5 | ||||
-rw-r--r-- | src/client/snd_openal.c | 53 |
7 files changed, 116 insertions, 73 deletions
diff --git a/src/client/cl_avi.c b/src/client/cl_avi.c index df7bc7b9..fee1340e 100644 --- a/src/client/cl_avi.c +++ b/src/client/cl_avi.c @@ -555,7 +555,7 @@ void CL_WriteAVIAudioFrame( const byte *pcmBuffer, int size ) afd.numAudioFrames++; afd.moviSize += ( chunkSize + paddingSize ); - afd.a.totalBytes =+ bytesInBuffer; + afd.a.totalBytes += bytesInBuffer; // Index bufIndex = 0; diff --git a/src/client/cl_cgame.c b/src/client/cl_cgame.c index 9a16d3bf..d30d4ac0 100644 --- a/src/client/cl_cgame.c +++ b/src/client/cl_cgame.c @@ -336,6 +336,8 @@ rescan: // clear notify lines and outgoing commands before passing // the restart to the cgame Con_ClearNotify(); + // reparse the string, because Con_ClearNotify() may have done another Cmd_TokenizeString() + Cmd_TokenizeString( s ); Com_Memset( cl.cmds, 0, sizeof( cl.cmds ) ); return qtrue; } diff --git a/src/client/cl_main.c b/src/client/cl_main.c index 47cf0196..16fbe56b 100644 --- a/src/client/cl_main.c +++ b/src/client/cl_main.c @@ -194,8 +194,10 @@ void CL_UpdateVoipIgnore(const char *idstr, qboolean ignore) ignore ? "ignore" : "unignore", id)); Com_Printf("VoIP: %s ignoring player #%d\n", ignore ? "Now" : "No longer", id); + return; } } + Com_Printf("VoIP: invalid player ID#\n"); } static @@ -234,7 +236,19 @@ void CL_Voip_f( void ) } else if (strcmp(cmd, "unignore") == 0) { CL_UpdateVoipIgnore(Cmd_Argv(2), qfalse); } else if (strcmp(cmd, "gain") == 0) { - CL_UpdateVoipGain(Cmd_Argv(2), atof(Cmd_Argv(3))); + if (Cmd_Argc() > 3) { + CL_UpdateVoipGain(Cmd_Argv(2), atof(Cmd_Argv(3))); + } else if (Q_isanumber(Cmd_Argv(2))) { + int id = atoi(Cmd_Argv(2)); + if (id >= 0 && id < MAX_CLIENTS) { + Com_Printf("VoIP: current gain for player #%d " + "is %f\n", id, clc.voipGain[id]); + } else { + Com_Printf("VoIP: invalid player ID#\n"); + } + } else { + Com_Printf("usage: voip gain <playerID#> [value]\n"); + } } else if (strcmp(cmd, "muteall") == 0) { Com_Printf("VoIP: muting incoming voice\n"); CL_AddReliableCommand("voip muteall"); @@ -243,6 +257,10 @@ void CL_Voip_f( void ) Com_Printf("VoIP: unmuting incoming voice\n"); CL_AddReliableCommand("voip unmuteall"); clc.voipMuteAll = qfalse; + } else { + Com_Printf("usage: voip [un]ignore <playerID#>\n" + " voip [un]muteall\n" + " voip gain <playerID#> [value]\n"); } } @@ -1354,11 +1372,7 @@ void CL_RequestMotd( void ) { NET_AdrToStringwPort( cls.updateServer ) ); info[0] = 0; - // NOTE TTimo xoring against Com_Milliseconds, otherwise we may not have a true randomization - // only srand I could catch before here is tr_noise.c l:26 srand(1001) - // https://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=382 - // NOTE: the Com_Milliseconds xoring only affects the lower 16-bit word, - // but I decided it was enough randomization + Com_sprintf( cls.updateChallenge, sizeof( cls.updateChallenge ), "%i", ((rand() << 16) ^ rand()) ^ Com_Milliseconds()); @@ -1531,10 +1545,14 @@ void CL_Connect_f( void ) { // if we aren't playing on a lan, we need to authenticate // with the cd key - if ( NET_IsLocalAddress( clc.serverAddress ) ) { + if(NET_IsLocalAddress(clc.serverAddress)) cls.state = CA_CHALLENGING; - } else { + else + { cls.state = CA_CONNECTING; + + // Set a client challenge number that ideally is mirrored back by the server. + clc.challenge = ((rand() << 16) ^ rand()) ^ Com_Milliseconds(); } Key_SetCatcher( 0 ); @@ -2129,7 +2147,11 @@ void CL_CheckForResend( void ) { switch ( cls.state ) { case CA_CONNECTING: // requesting a challenge - NET_OutOfBandPrint(NS_CLIENT, clc.serverAddress, "getchallenge"); + + // The challenge request shall be followed by a client challenge so no malicious server can hijack this connection. + Com_sprintf(data, sizeof(data), "getchallenge %d", clc.challenge); + + NET_OutOfBandPrint(NS_CLIENT, clc.serverAddress, "%s", data); break; case CA_CHALLENGING: @@ -2505,8 +2527,7 @@ Responses to broadcasts, etc */ void CL_ConnectionlessPacket( netadr_t from, msg_t *msg ) { char *s; - char c[ BIG_INFO_STRING ]; - char arg1[ BIG_INFO_STRING ]; + char *c; MSG_BeginReadingOOB( msg ); MSG_ReadLong( msg ); // skip the -1 @@ -2515,27 +2536,44 @@ void CL_ConnectionlessPacket( netadr_t from, msg_t *msg ) { Cmd_TokenizeString( s ); - Q_strncpyz( c, Cmd_Argv( 0 ), BIG_INFO_STRING ); - Q_strncpyz( arg1, Cmd_Argv( 1 ), BIG_INFO_STRING ); + c = Cmd_Argv(0); Com_DPrintf ("CL packet %s: %s\n", NET_AdrToStringwPort(from), c); // challenge from the server we are connecting to - if ( !Q_stricmp(c, "challengeResponse") ) { - if ( cls.state != CA_CONNECTING ) { - Com_DPrintf( "Unwanted challenge response received. Ignored.\n" ); - } else { - // start sending challenge repsonse instead of challenge request packets - clc.challenge = atoi(arg1); - cls.state = CA_CHALLENGING; - clc.connectPacketCount = 0; - clc.connectTime = -99999; - - // take this address as the new server address. This allows - // a server proxy to hand off connections to multiple servers - clc.serverAddress = from; - Com_DPrintf ("challengeResponse: %d\n", clc.challenge); + if (!Q_stricmp(c, "challengeResponse")) + { + if (cls.state != CA_CONNECTING) + { + Com_DPrintf("Unwanted challenge response received. Ignored.\n"); + return; + } + + if(!NET_CompareAdr(from, clc.serverAddress)) + { + // This challenge response is not coming from the expected address. + // Check whether we have a matching client challenge to prevent + // connection hi-jacking. + + c = Cmd_Argv(2); + + if(!*c || atoi(c) != clc.challenge) + { + Com_DPrintf("Challenge response received from unexpected source. Ignored.\n"); + return; + } } + + // start sending challenge response instead of challenge request packets + clc.challenge = atoi(Cmd_Argv(1)); + cls.state = CA_CHALLENGING; + clc.connectPacketCount = 0; + clc.connectTime = -99999; + + // take this address as the new server address. This allows + // a server proxy to hand off connections to multiple servers + clc.serverAddress = from; + Com_DPrintf ("challengeResponse: %d\n", clc.challenge); return; } @@ -2546,13 +2584,11 @@ void CL_ConnectionlessPacket( netadr_t from, msg_t *msg ) { return; } if ( cls.state != CA_CHALLENGING ) { - Com_Printf ("connectResponse packet while not connecting. Ignored.\n"); + Com_Printf ("connectResponse packet while not connecting. Ignored.\n"); return; } - if ( !NET_CompareBaseAdr( from, clc.serverAddress ) ) { - Com_Printf( "connectResponse from a different address. Ignored.\n" ); - Com_Printf( "%s should have been %s\n", NET_AdrToStringwPort( from ), - NET_AdrToStringwPort( clc.serverAddress ) ); + if ( !NET_CompareAdr( from, clc.serverAddress ) ) { + Com_Printf( "connectResponse from wrong address. Ignored.\n" ); return; } Netchan_Setup (NS_CLIENT, &clc.netchan, from, Cvar_VariableValue( "net_qport" ) ); @@ -2582,7 +2618,7 @@ void CL_ConnectionlessPacket( netadr_t from, msg_t *msg ) { // echo request from server if ( !Q_stricmp(c, "echo") ) { - NET_OutOfBandPrint( NS_CLIENT, from, "%s", arg1 ); + NET_OutOfBandPrint( NS_CLIENT, from, "%s", Cmd_Argv(1) ); return; } @@ -3544,7 +3580,7 @@ void CL_ServerInfoPacket( netadr_t from, msg_t *msg ) { if ( cl_pinglist[i].adr.port && !cl_pinglist[i].time && NET_CompareAdr( from, cl_pinglist[i].adr ) ) { // calc ping time - cl_pinglist[i].time = cls.realtime - cl_pinglist[i].start + 1; + cl_pinglist[i].time = Sys_Milliseconds() - cl_pinglist[i].start; Com_DPrintf( "ping time %dms from %s\n", cl_pinglist[i].time, NET_AdrToString( from ) ); // save of info @@ -3936,7 +3972,7 @@ void CL_GetPing( int n, char *buf, int buflen, int *pingtime ) if (!time) { // check for timeout - time = cls.realtime - cl_pinglist[n].start; + time = Sys_Milliseconds() - cl_pinglist[n].start; maxPing = Cvar_VariableIntegerValue( "cl_maxPing" ); if( maxPing < 100 ) { maxPing = 100; @@ -4043,7 +4079,7 @@ ping_t* CL_GetFreePing( void ) { if (!pingptr->time) { - if (cls.realtime - pingptr->start < 500) + if (Sys_Milliseconds() - pingptr->start < 500) { // still waiting for response continue; @@ -4068,7 +4104,7 @@ ping_t* CL_GetFreePing( void ) for (i=0; i<MAX_PINGREQUESTS; i++, pingptr++ ) { // scan for oldest - time = cls.realtime - pingptr->start; + time = Sys_Milliseconds() - pingptr->start; if (time > oldest) { oldest = time; @@ -4121,7 +4157,7 @@ void CL_Ping_f( void ) { pingptr = CL_GetFreePing(); memcpy( &pingptr->adr, &to, sizeof (netadr_t) ); - pingptr->start = cls.realtime; + pingptr->start = Sys_Milliseconds(); pingptr->time = 0; CL_SetServerInfoByAddress(pingptr->adr, NULL, 0); @@ -4193,7 +4229,7 @@ qboolean CL_UpdateVisiblePings_f(int source) { } } memcpy(&cl_pinglist[j].adr, &server[i].adr, sizeof(netadr_t)); - cl_pinglist[j].start = cls.realtime; + cl_pinglist[j].start = Sys_Milliseconds(); cl_pinglist[j].time = 0; NET_OutOfBandPrint( NS_CLIENT, cl_pinglist[j].adr, "getinfo xxx" ); slots++; diff --git a/src/client/cl_ui.c b/src/client/cl_ui.c index 34ae04ea..6c00a353 100644 --- a/src/client/cl_ui.c +++ b/src/client/cl_ui.c @@ -295,7 +295,7 @@ static void LAN_GetServerInfo( int source, int n, char *buf, int buflen ) { Info_SetValueForKey( info, "game", server->game); Info_SetValueForKey( info, "gametype", va("%i",server->gameType)); Info_SetValueForKey( info, "nettype", va("%i",server->netType)); - Info_SetValueForKey( info, "addr", NET_AdrToString(server->adr)); + Info_SetValueForKey( info, "addr", NET_AdrToStringwPort(server->adr)); Q_strncpyz(buf, info, buflen); } else { if (buf) { diff --git a/src/client/snd_dma.c b/src/client/snd_dma.c index a418733a..c8df2daf 100644 --- a/src/client/snd_dma.c +++ b/src/client/snd_dma.c @@ -1369,17 +1369,13 @@ void S_UpdateBackgroundTrack( void ) { byte raw[30000]; // just enough to fit in a mac stack frame int fileBytes; int r; - static float musicVolume = 0.5f; if(!s_backgroundStream) { return; } - // graeme see if this is OK - musicVolume = (musicVolume + (s_musicVolume->value * 2))/4.0f; - // don't bother playing anything if musicvolume is 0 - if ( musicVolume <= 0 ) { + if ( s_musicVolume->value <= 0 ) { return; } @@ -1394,6 +1390,9 @@ void S_UpdateBackgroundTrack( void ) { // decide how much data needs to be read from the file fileSamples = bufferSamples * s_backgroundStream->info.rate / dma.speed; + if (!fileSamples) + return; + // our max buffer size fileBytes = fileSamples * (s_backgroundStream->info.width * s_backgroundStream->info.channels); if ( fileBytes > sizeof(raw) ) { @@ -1413,7 +1412,7 @@ void S_UpdateBackgroundTrack( void ) { { // add to raw buffer S_Base_RawSamples( 0, fileSamples, s_backgroundStream->info.rate, - s_backgroundStream->info.width, s_backgroundStream->info.channels, raw, musicVolume ); + s_backgroundStream->info.width, s_backgroundStream->info.channels, raw, s_musicVolume->value ); } else { diff --git a/src/client/snd_main.c b/src/client/snd_main.c index d3391b23..c386cd75 100644 --- a/src/client/snd_main.c +++ b/src/client/snd_main.c @@ -32,6 +32,7 @@ cvar_t *s_musicVolume; cvar_t *s_doppler; cvar_t *s_backend; cvar_t *s_muteWhenMinimized; +cvar_t *s_muteWhenUnfocused; static soundInterface_t si; @@ -230,7 +231,8 @@ S_Update */ void S_Update( void ) { - if( s_muteWhenMinimized->integer && com_minimized->integer ) { + if( ( s_muteWhenMinimized->integer && com_minimized->integer ) || + ( s_muteWhenUnfocused->integer && com_unfocused->integer ) ) { S_StopAllSounds( ); return; } @@ -466,6 +468,7 @@ void S_Init( void ) s_doppler = Cvar_Get( "s_doppler", "1", CVAR_ARCHIVE ); s_backend = Cvar_Get( "s_backend", "", CVAR_ROM ); s_muteWhenMinimized = Cvar_Get( "s_muteWhenMinimized", "0", CVAR_ARCHIVE ); + s_muteWhenUnfocused = Cvar_Get( "s_muteWhenUnfocused", "0", CVAR_ARCHIVE ); cv = Cvar_Get( "s_initsound", "1", 0 ); if( !cv->integer ) { diff --git a/src/client/snd_openal.c b/src/client/snd_openal.c index 912006d8..1f91ae95 100644 --- a/src/client/snd_openal.c +++ b/src/client/snd_openal.c @@ -1419,6 +1419,8 @@ S_AL_StreamDie static void S_AL_StreamDie( int stream ) { + int numBuffers; + if ((stream < 0) || (stream >= MAX_RAW_STREAMS)) return; @@ -1427,6 +1429,16 @@ void S_AL_StreamDie( int stream ) streamPlaying[stream] = qfalse; qalSourceStop(streamSources[stream]); + + // Un-queue any buffers, and delete them + qalGetSourcei( streamSources[stream], AL_BUFFERS_PROCESSED, &numBuffers ); + while( numBuffers-- ) + { + ALuint buffer; + qalSourceUnqueueBuffers(streamSources[stream], 1, &buffer); + qalDeleteBuffers(1, &buffer); + } + S_AL_FreeStreamChannel(stream); } @@ -1726,7 +1738,6 @@ static cvar_t *s_alCapture; #ifdef _WIN32 #define ALDRIVER_DEFAULT "OpenAL32.dll" -#define ALDEVICE_DEFAULT "Generic Software" #elif defined(MACOS_X) #define ALDRIVER_DEFAULT "/System/Library/Frameworks/OpenAL.framework/OpenAL" #else @@ -1976,8 +1987,7 @@ S_AL_Init qboolean S_AL_Init( soundInterface_t *si ) { #ifdef USE_OPENAL - - qboolean enumsupport, founddev = qfalse; + const char* device = NULL; int i; if( !si ) { @@ -2001,7 +2011,9 @@ qboolean S_AL_Init( soundInterface_t *si ) s_alRolloff = Cvar_Get( "s_alRolloff", "2", CVAR_CHEAT); s_alGraceDistance = Cvar_Get("s_alGraceDistance", "512", CVAR_CHEAT); - s_alDriver = Cvar_Get( "s_alDriver", ALDRIVER_DEFAULT, CVAR_ARCHIVE ); + s_alDriver = Cvar_Get( "s_alDriver", ALDRIVER_DEFAULT, CVAR_ARCHIVE | CVAR_LATCH ); + + s_alDevice = Cvar_Get("s_alDevice", "", CVAR_ARCHIVE | CVAR_LATCH); // Load QAL if( !QAL_Init( s_alDriver->string ) ) @@ -2010,8 +2022,12 @@ qboolean S_AL_Init( soundInterface_t *si ) return qfalse; } + device = s_alDevice->string; + if(device && !*device) + device = NULL; + // Device enumeration support (extension is implemented reasonably only on Windows right now). - if((enumsupport = qalcIsExtensionPresent(NULL, "ALC_ENUMERATION_EXT"))) + if(qalcIsExtensionPresent(NULL, "ALC_ENUMERATION_EXT")) { char devicenames[1024] = ""; const char *devicelist; @@ -2027,11 +2043,9 @@ qboolean S_AL_Init( soundInterface_t *si ) // Generic Software as that one works more reliably with various sound systems. // If it's not, use OpenAL's default selection as we don't want to ignore // native hardware acceleration. - if(!strcmp(defaultdevice, "Generic Hardware")) - s_alDevice = Cvar_Get("s_alDevice", ALDEVICE_DEFAULT, CVAR_ARCHIVE | CVAR_LATCH); - else + if(!device && !strcmp(defaultdevice, "Generic Hardware")) + device = "Generic Software"; #endif - s_alDevice = Cvar_Get("s_alDevice", defaultdevice, CVAR_ARCHIVE | CVAR_LATCH); // dump a list of available devices to a cvar for the user to see. while((curlen = strlen(devicelist))) @@ -2039,26 +2053,18 @@ qboolean S_AL_Init( soundInterface_t *si ) Q_strcat(devicenames, sizeof(devicenames), devicelist); Q_strcat(devicenames, sizeof(devicenames), "\n"); - // check whether the device we want to load is available at all. - if(!strcmp(s_alDevice->string, devicelist)) - founddev = qtrue; - devicelist += curlen + 1; } s_alAvailableDevices = Cvar_Get("s_alAvailableDevices", devicenames, CVAR_ROM | CVAR_NORESTART); - - if(!founddev) - { - Cvar_ForceReset("s_alDevice"); - founddev = 1; - } } - if(founddev) - alDevice = qalcOpenDevice(s_alDevice->string); - else + alDevice = qalcOpenDevice(device); + if( !alDevice && device ) + { + Com_Printf( "Failed to open OpenAL device '%s', trying default.\n", device ); alDevice = qalcOpenDevice(NULL); + } if( !alDevice ) { @@ -2067,9 +2073,6 @@ qboolean S_AL_Init( soundInterface_t *si ) return qfalse; } - if(enumsupport) - Cvar_Set("s_alDevice", qalcGetString(alDevice, ALC_DEVICE_SPECIFIER)); - // Create OpenAL context alContext = qalcCreateContext( alDevice, NULL ); if( !alContext ) |