~ubuntu-branches/ubuntu/jaunty/openarena/jaunty

« back to all changes in this revision

Viewing changes to code/client/cl_main.c

  • Committer: Bazaar Package Importer
  • Author(s): Bruno "Fuddl" Kleinert, Bruno "Fuddl" Kleinert
  • Date: 2008-04-24 14:33:54 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20080424143354-0cuxsalv98ajw2js
Tags: 0.7.6-1
[ Bruno "Fuddl" Kleinert ]
* New upstream release
* Freshen 10_fix_build_and_binary_on_alpha.dpatch to apply to latest
  upstream sources
* Remove 10-fix_menudef.h_includes.dpatch which pulled in a missing header
  file. The header is now included in the upstream tarball.
* Remove debian/watch, because upstream places its new releases too often to
  different download locations
* Updated debian/copyright to reflect the download location
* Expand copyright years in debian/copyright

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
cvar_t  *cl_timeout;
37
37
cvar_t  *cl_maxpackets;
38
38
cvar_t  *cl_packetdup;
 
39
cvar_t  *cl_master;
39
40
cvar_t  *cl_timeNudge;
40
41
cvar_t  *cl_showTimeDelta;
41
42
cvar_t  *cl_freezeDemo;
43
44
cvar_t  *cl_shownet;
44
45
cvar_t  *cl_showSend;
45
46
cvar_t  *cl_timedemo;
 
47
cvar_t  *cl_timedemoLog;
46
48
cvar_t  *cl_autoRecordDemo;
47
49
cvar_t  *cl_aviFrameRate;
48
50
cvar_t  *cl_aviMotionJpeg;
393
395
 
394
396
/*
395
397
=================
 
398
CL_DemoFrameDurationSDev
 
399
=================
 
400
*/
 
401
static float CL_DemoFrameDurationSDev( void )
 
402
{
 
403
        int i;
 
404
        int numFrames;
 
405
        float mean = 0.0f;
 
406
        float variance = 0.0f;
 
407
 
 
408
        if( ( clc.timeDemoFrames - 1 ) > MAX_TIMEDEMO_DURATIONS )
 
409
                numFrames = MAX_TIMEDEMO_DURATIONS;
 
410
        else
 
411
                numFrames = clc.timeDemoFrames - 1;
 
412
 
 
413
        for( i = 0; i < numFrames; i++ )
 
414
                mean += clc.timeDemoDurations[ i ];
 
415
        mean /= numFrames;
 
416
 
 
417
        for( i = 0; i < numFrames; i++ )
 
418
        {
 
419
                float x = clc.timeDemoDurations[ i ];
 
420
 
 
421
                variance += ( ( x - mean ) * ( x - mean ) );
 
422
        }
 
423
        variance /= numFrames;
 
424
 
 
425
        return sqrt( variance );
 
426
}
 
427
 
 
428
/*
 
429
=================
396
430
CL_DemoCompleted
397
431
=================
398
432
*/
399
 
void CL_DemoCompleted( void ) {
400
 
        if (cl_timedemo && cl_timedemo->integer) {
 
433
void CL_DemoCompleted( void )
 
434
{
 
435
        char buffer[ MAX_STRING_CHARS ];
 
436
 
 
437
        if( cl_timedemo && cl_timedemo->integer )
 
438
        {
401
439
                int     time;
402
440
                
403
441
                time = Sys_Milliseconds() - clc.timeDemoStart;
404
 
                if ( time > 0 ) {
405
 
                        Com_Printf ("%i frames, %3.1f seconds: %3.1f fps\n", clc.timeDemoFrames,
406
 
                        time/1000.0, clc.timeDemoFrames*1000.0 / time);
 
442
                if( time > 0 )
 
443
                {
 
444
                        // Millisecond times are frame durations:
 
445
                        // minimum/average/maximum/std deviation
 
446
                        Com_sprintf( buffer, sizeof( buffer ),
 
447
                                        "%i frames %3.1f seconds %3.1f fps %d.0/%.1f/%d.0/%.1f ms\n",
 
448
                                        clc.timeDemoFrames,
 
449
                                        time/1000.0,
 
450
                                        clc.timeDemoFrames*1000.0 / time,
 
451
                                        clc.timeDemoMinDuration,
 
452
                                        time / (float)clc.timeDemoFrames,
 
453
                                        clc.timeDemoMaxDuration,
 
454
                                        CL_DemoFrameDurationSDev( ) );
 
455
                        Com_Printf( "%s", buffer );
 
456
 
 
457
                        // Write a log of all the frame durations
 
458
                        if( cl_timedemoLog && strlen( cl_timedemoLog->string ) > 0 )
 
459
                        {
 
460
                                int i;
 
461
                                int numFrames;
 
462
                                fileHandle_t f;
 
463
 
 
464
                                if( ( clc.timeDemoFrames - 1 ) > MAX_TIMEDEMO_DURATIONS )
 
465
                                        numFrames = MAX_TIMEDEMO_DURATIONS;
 
466
                                else
 
467
                                        numFrames = clc.timeDemoFrames - 1;
 
468
 
 
469
                                f = FS_FOpenFileWrite( cl_timedemoLog->string );
 
470
                                if( f )
 
471
                                {
 
472
                                        FS_Printf( f, "# %s", buffer );
 
473
 
 
474
                                        for( i = 0; i < numFrames; i++ )
 
475
                                                FS_Printf( f, "%d\n", clc.timeDemoDurations[ i ] );
 
476
 
 
477
                                        FS_FCloseFile( f );
 
478
                                        Com_Printf( "%s written\n", cl_timedemoLog->string );
 
479
                                }
 
480
                                else
 
481
                                {
 
482
                                        Com_Printf( "Couldn't open %s for writing\n",
 
483
                                                        cl_timedemoLog->string );
 
484
                                }
 
485
                        }
407
486
                }
408
487
        }
409
488
 
574
653
void CL_StartDemoLoop( void ) {
575
654
        // start the demo loop again
576
655
        Cbuf_AddText ("d1\n");
577
 
        cls.keyCatchers = 0;
 
656
        Key_SetCatcher( 0 );
578
657
}
579
658
 
580
659
/*
611
690
*/
612
691
void CL_ShutdownAll(void) {
613
692
 
614
 
#if USE_CURL
 
693
#ifdef USE_CURL
615
694
        CL_cURL_Shutdown();
616
695
#endif
617
696
        // clear sounds
658
737
                Hunk_ClearToMark();
659
738
        }
660
739
 
661
 
        CL_StartHunkUsers();
 
740
        CL_StartHunkUsers( qfalse );
662
741
}
663
742
 
664
743
/*
671
750
=====================
672
751
*/
673
752
void CL_MapLoading( void ) {
 
753
        if ( com_dedicated->integer ) {
 
754
                cls.state = CA_DISCONNECTED;
 
755
                Key_SetCatcher( KEYCATCH_CONSOLE );
 
756
                return;
 
757
        }
 
758
 
674
759
        if ( !com_cl_running->integer ) {
675
760
                return;
676
761
        }
677
762
 
678
763
        Con_Close();
679
 
        cls.keyCatchers = 0;
 
764
        Key_SetCatcher( 0 );
680
765
 
681
766
        // if we are already connected to the local host, stay connected
682
767
        if ( cls.state >= CA_CONNECTED && !Q_stricmp( cls.servername, "localhost" ) ) {
692
777
                CL_Disconnect( qtrue );
693
778
                Q_strncpyz( cls.servername, "localhost", sizeof(cls.servername) );
694
779
                cls.state = CA_CHALLENGING;             // so the connect screen is drawn
695
 
                cls.keyCatchers = 0;
 
780
                Key_SetCatcher( 0 );
696
781
                SCR_UpdateScreen();
697
782
                clc.connectTime = -RETRANSMIT_TIMEOUT;
698
783
                NET_StringToAdr( cls.servername, &clc.serverAddress);
804
889
 
805
890
        // Stop recording any video
806
891
        if( CL_VideoRecording( ) ) {
 
892
                // Finish rendering current frame
 
893
                SCR_UpdateScreen( );
807
894
                CL_CloseAVI( );
808
895
        }
809
896
        CL_UpdateGUID( NULL, 0 );
830
917
        }
831
918
 
832
919
        if ( clc.demoplaying || cls.state < CA_CONNECTED || cmd[0] == '+' ) {
833
 
                Com_Printf ("Unknown command \"%s\"\n", cmd);
 
920
                Com_Printf ("Unknown command \"%s" S_COLOR_WHITE "\"\n", cmd);
834
921
                return;
835
922
        }
836
923
 
939
1026
                return;
940
1027
        }
941
1028
 
942
 
        if ( Cvar_VariableValue( "fs_restrict" ) ) {
943
 
                Q_strncpyz( nums, "demota", sizeof( nums ) );
944
 
        } else {
945
 
                // only grab the alphanumeric values from the cdkey, to avoid any dashes or spaces
946
 
                j = 0;
947
 
                l = strlen( cl_cdkey );
948
 
                if ( l > 32 ) {
949
 
                        l = 32;
950
 
                }
951
 
                for ( i = 0 ; i < l ; i++ ) {
952
 
                        if ( ( cl_cdkey[i] >= '0' && cl_cdkey[i] <= '9' )
 
1029
        // only grab the alphanumeric values from the cdkey, to avoid any dashes or spaces
 
1030
        j = 0;
 
1031
        l = strlen( cl_cdkey );
 
1032
        if ( l > 32 ) {
 
1033
                l = 32;
 
1034
        }
 
1035
        for ( i = 0 ; i < l ; i++ ) {
 
1036
                if ( ( cl_cdkey[i] >= '0' && cl_cdkey[i] <= '9' )
953
1037
                                || ( cl_cdkey[i] >= 'a' && cl_cdkey[i] <= 'z' )
954
1038
                                || ( cl_cdkey[i] >= 'A' && cl_cdkey[i] <= 'Z' )
955
 
                                ) {
956
 
                                nums[j] = cl_cdkey[i];
957
 
                                j++;
958
 
                        }
 
1039
                         ) {
 
1040
                        nums[j] = cl_cdkey[i];
 
1041
                        j++;
959
1042
                }
960
 
                nums[j] = 0;
961
1043
        }
 
1044
        nums[j] = 0;
962
1045
 
963
1046
        fs = Cvar_Get ("cl_anonymous", "0", CVAR_INIT|CVAR_SYSTEMINFO );
964
1047
 
965
 
        NET_OutOfBandPrint(NS_CLIENT, cls.authorizeServer, va("getKeyAuthorize %i %s", fs->integer, nums) );
 
1048
        NET_OutOfBandPrint(NS_CLIENT, cls.authorizeServer, "getKeyAuthorize %i %s", fs->integer, nums );
966
1049
}
967
1050
 
968
1051
/*
1125
1208
                cls.state = CA_CONNECTING;
1126
1209
        }
1127
1210
 
1128
 
        cls.keyCatchers = 0;
 
1211
        Key_SetCatcher( 0 );
1129
1212
        clc.connectTime = -99999;       // CL_CheckForResend() will fire immediately
1130
1213
        clc.connectPacketCount = 0;
1131
1214
 
1192
1275
=================
1193
1276
*/
1194
1277
void CL_SendPureChecksums( void ) {
1195
 
        const char *pChecksums;
1196
1278
        char cMsg[MAX_INFO_VALUE];
1197
 
        int i;
1198
1279
 
1199
1280
        // if we are pure we need to send back a command with our referenced pk3 checksums
1200
 
        pChecksums = FS_ReferencedPakPureChecksums();
 
1281
        Com_sprintf(cMsg, sizeof(cMsg), "cp %d %s", cl.serverId, FS_ReferencedPakPureChecksums());
1201
1282
 
1202
 
        // "cp"
1203
 
        // "Yf"
1204
 
        Com_sprintf(cMsg, sizeof(cMsg), "Yf ");
1205
 
        Q_strcat(cMsg, sizeof(cMsg), va("%d ", cl.serverId) );
1206
 
        Q_strcat(cMsg, sizeof(cMsg), pChecksums);
1207
 
        for (i = 0; i < 2; i++) {
1208
 
                cMsg[i] += 10;
1209
 
        }
1210
1283
        CL_AddReliableCommand( cMsg );
1211
1284
}
1212
1285
 
1276
1349
        CL_InitRef();
1277
1350
 
1278
1351
        // startup all the client stuff
1279
 
        CL_StartHunkUsers();
 
1352
        CL_StartHunkUsers( qfalse );
1280
1353
 
1281
1354
        // start the cgame if connected
1282
1355
        if ( cls.state > CA_CONNECTED && cls.state != CA_CINEMATIC ) {
1371
1444
*/
1372
1445
void CL_DownloadsComplete( void ) {
1373
1446
 
1374
 
#if USE_CURL
 
1447
#ifdef USE_CURL
1375
1448
        // if we downloaded with cURL
1376
1449
        if(clc.cURLUsed) { 
1377
1450
                clc.cURLUsed = qfalse;
1499
1572
                        *s++ = 0;
1500
1573
                else
1501
1574
                        s = localName + strlen(localName); // point at the nul byte
1502
 
#if USE_CURL
 
1575
#ifdef USE_CURL
1503
1576
                if(!(cl_allowDownload->integer & DLF_NO_REDIRECT)) {
1504
1577
                        if(clc.sv_allowDownload & DLF_NO_REDIRECT) {
1505
1578
                                Com_Printf("WARNING: server does not "
2125
2198
                return;
2126
2199
        }
2127
2200
 
2128
 
#if USE_CURL
 
2201
#ifdef USE_CURL
2129
2202
        if(clc.downloadCURLM) {
2130
2203
                CL_cURL_PerformDownload();
2131
2204
                // we can't process frames normally when in disconnected
2148
2221
                // bring up the cd error dialog if needed
2149
2222
                cls.cddialog = qfalse;
2150
2223
                VM_Call( uivm, UI_SET_ACTIVE_MENU, UIMENU_NEED_CD );
2151
 
        } else  if ( cls.state == CA_DISCONNECTED && !( cls.keyCatchers & KEYCATCH_UI )
 
2224
        } else  if ( cls.state == CA_DISCONNECTED && !( Key_GetCatcher( ) & KEYCATCH_UI )
2152
2225
                && !com_sv_running->integer ) {
2153
2226
                // if disconnected, bring up the menu
2154
2227
                S_StopAllSounds();
2316
2389
This is the only place that any of these functions are called from
2317
2390
============================
2318
2391
*/
2319
 
void CL_StartHunkUsers( void ) {
 
2392
void CL_StartHunkUsers( qboolean rendererOnly ) {
2320
2393
        if (!com_cl_running) {
2321
2394
                return;
2322
2395
        }
2330
2403
                CL_InitRenderer();
2331
2404
        }
2332
2405
 
 
2406
        if ( rendererOnly ) {
 
2407
                return;
 
2408
        }
 
2409
 
2333
2410
        if ( !cls.soundStarted ) {
2334
2411
                cls.soundStarted = qtrue;
2335
2412
                S_Init();
2581
2658
 
2582
2659
        cl_timeout = Cvar_Get ("cl_timeout", "200", 0);
2583
2660
 
 
2661
        cl_master = Cvar_Get ("cl_master", MASTER_SERVER_NAME, CVAR_ARCHIVE);
2584
2662
        cl_timeNudge = Cvar_Get ("cl_timeNudge", "0", CVAR_TEMP );
2585
2663
        cl_shownet = Cvar_Get ("cl_shownet", "0", CVAR_TEMP );
2586
2664
        cl_showSend = Cvar_Get ("cl_showSend", "0", CVAR_TEMP );
2590
2668
        cl_activeAction = Cvar_Get( "activeAction", "", CVAR_TEMP );
2591
2669
 
2592
2670
        cl_timedemo = Cvar_Get ("timedemo", "0", 0);
 
2671
        cl_timedemoLog = Cvar_Get ("cl_timedemoLog", "", CVAR_ARCHIVE);
2593
2672
        cl_autoRecordDemo = Cvar_Get ("cl_autoRecordDemo", "0", CVAR_ARCHIVE);
2594
2673
        cl_aviFrameRate = Cvar_Get ("cl_aviFrameRate", "25", CVAR_ARCHIVE);
2595
2674
        cl_aviMotionJpeg = Cvar_Get ("cl_aviMotionJpeg", "1", CVAR_ARCHIVE);
2613
2692
        cl_showMouseRate = Cvar_Get ("cl_showmouserate", "0", 0);
2614
2693
 
2615
2694
        cl_allowDownload = Cvar_Get ("cl_allowDownload", "0", CVAR_ARCHIVE);
2616
 
#if USE_CURL
 
2695
#ifdef USE_CURL
2617
2696
        cl_cURLLib = Cvar_Get("cl_cURLLib", DEFAULT_CURL_LIB, CVAR_ARCHIVE);
2618
2697
#endif
2619
2698
 
2772
2851
        recursive = qfalse;
2773
2852
 
2774
2853
        Com_Memset( &cls, 0, sizeof( cls ) );
 
2854
        Key_SetCatcher( 0 );
2775
2855
 
2776
2856
        Com_Printf( "-----------------------\n" );
2777
2857
 
2867
2947
                                        type = 1;
2868
2948
                                        break;
2869
2949
 
2870
 
                                case NA_IPX:
2871
 
                                case NA_BROADCAST_IPX:
2872
 
                                        str = "ipx";
2873
 
                                        type = 2;
2874
 
                                        break;
2875
 
 
2876
2950
                                default:
2877
2951
                                        str = "???";
2878
2952
                                        type = 0;
3160
3234
 
3161
3235
                        to.type = NA_BROADCAST;
3162
3236
                        NET_SendPacket( NS_CLIENT, strlen( message ), message, to );
3163
 
 
3164
 
                        to.type = NA_BROADCAST_IPX;
3165
 
                        NET_SendPacket( NS_CLIENT, strlen( message ), message, to );
3166
3237
                }
3167
3238
        }
3168
3239
}
3191
3262
        // reset the list, waiting for response
3192
3263
        // -1 is used to distinguish a "no response"
3193
3264
 
 
3265
        NET_StringToAdr( cl_master->string, &to );
 
3266
 
3194
3267
        if( cls.masterNum == 1 ) {
3195
 
                NET_StringToAdr( MASTER_SERVER_NAME, &to );
3196
3268
                cls.nummplayerservers = -1;
3197
3269
                cls.pingUpdateSource = AS_MPLAYER;
3198
3270
        }
3199
3271
        else {
3200
 
                NET_StringToAdr( MASTER_SERVER_NAME, &to );
3201
3272
                cls.numglobalservers = -1;
3202
3273
                cls.pingUpdateSource = AS_GLOBAL;
3203
3274
        }
3212
3283
        for (i=3; i<count; i++)
3213
3284
                buffptr += sprintf( buffptr, " %s", Cmd_Argv(i) );
3214
3285
 
3215
 
        // if we are a demo, automatically add a "demo" keyword
3216
 
        if ( Cvar_VariableValue( "fs_restrict" ) ) {
3217
 
                buffptr += sprintf( buffptr, " demo" );
3218
 
        }
3219
 
 
3220
 
        NET_OutOfBandPrint( NS_SERVER, to, command );
 
3286
        NET_OutOfBandPrint( NS_SERVER, to, "%s", command );
3221
3287
}
3222
3288
 
3223
3289
 
3582
3648
=================
3583
3649
*/
3584
3650
qboolean CL_CDKeyValidate( const char *key, const char *checksum ) {
3585
 
/*      char    ch;
3586
 
        byte    sum;
3587
 
        char    chs[3];
3588
 
        int i, len;
3589
 
 
3590
 
        len = strlen(key);
3591
 
        if( len != CDKEY_LEN ) {
3592
 
                return qfalse;
3593
 
        }
3594
 
 
3595
 
        if( checksum && strlen( checksum ) != CDCHKSUM_LEN ) {
3596
 
                return qfalse;
3597
 
        }
3598
 
 
3599
 
        sum = 0;
3600
 
        // for loop gets rid of conditional assignment warning
3601
 
        for (i = 0; i < len; i++) {
3602
 
                ch = *key++;
3603
 
                if (ch>='a' && ch<='z') {
3604
 
                        ch -= 32;
3605
 
                }
3606
 
                switch( ch ) {
3607
 
                case '2':
3608
 
                case '3':
3609
 
                case '7':
3610
 
                case 'A':
3611
 
                case 'B':
3612
 
                case 'C':
3613
 
                case 'D':
3614
 
                case 'G':
3615
 
                case 'H':
3616
 
                case 'J':
3617
 
                case 'L':
3618
 
                case 'P':
3619
 
                case 'R':
3620
 
                case 'S':
3621
 
                case 'T':
3622
 
                case 'W':
3623
 
                        sum += ch;
3624
 
                        continue;
3625
 
                default:
3626
 
                        return qfalse;
3627
 
                }
3628
 
        }
3629
 
 
3630
 
        sprintf(chs, "%02x", sum);
3631
 
        
3632
 
        if (checksum && !Q_stricmp(chs, checksum)) {
3633
 
                return qtrue;
3634
 
        }
3635
 
 
3636
 
        if (!checksum) {
3637
 
                return qtrue;
3638
 
        }
3639
 
*/
 
3651
 
3640
3652
        return qtrue;
3641
3653
}
3642
3654