-
Notifications
You must be signed in to change notification settings - Fork 71
Expand file tree
/
Copy pathcl_main.cpp
More file actions
2525 lines (2037 loc) · 57.7 KB
/
cl_main.cpp
File metadata and controls
2525 lines (2037 loc) · 57.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
===========================================================================
Daemon GPL Source Code
Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company.
This file is part of the Daemon GPL Source Code (Daemon Source Code).
Daemon Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Daemon Source Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Daemon Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Daemon Source Code is also subject to certain additional terms.
You should have received a copy of these additional terms immediately following the
terms and conditions of the GNU General Public License which accompanied the Daemon
Source Code. If not, please request a copy in writing from id Software at the address
below.
If you have questions concerning this license or the applicable additional terms, you
may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville,
Maryland 20850 USA.
===========================================================================
*/
// cl_main.c -- client main loop
#include "client.h"
#include "qcommon/q_unicode.h"
#include "qcommon/sys.h"
#include "common/Defs.h"
#include "framework/CommandSystem.h"
#include "framework/CvarSystem.h"
#if defined(USE_MUMBLE)
#include "mumblelink/libmumblelink.h"
#endif
#include "qcommon/crypto.h"
#include "framework/Rcon.h"
#include "framework/Crypto.h"
#include "framework/Network.h"
#ifndef _WIN32
#include <sys/stat.h>
#endif
#ifdef BUILD_GRAPHICAL_CLIENT
#include <SDL3/SDL.h>
#endif
#if defined(USE_MUMBLE)
cvar_t *cl_useMumble;
cvar_t *cl_mumbleScale;
#endif
cvar_t *cl_nodelta;
cvar_t *cl_noprint;
cvar_t *cl_timeout;
cvar_t *cl_maxpackets;
cvar_t *cl_packetdup;
cvar_t *cl_timeNudge;
cvar_t *cl_showTimeDelta;
cvar_t *cl_shownet = nullptr; // NERVE - SMF - This is referenced in msg.c and we need to make sure it is nullptr
cvar_t *cl_showSend;
Cvar::Cvar<bool> cvar_demo_status_isrecording(
"demo.status.isrecording",
"(Read-only) Whether there is a demo currently being recorded",
Cvar::ROM,
false
);
Cvar::Cvar<std::string> cvar_demo_status_filename(
"demo.status.filename",
"(Read-only) Name of the demo currently being recorded",
Cvar::ROM,
""
);
cvar_t *cl_aviFrameRate;
Cvar::Cvar<bool> cl_freelook("cl_freelook", "vertical mouse movement always controls pitch", Cvar::NONE, true);
cvar_t *cl_mouseAccelOffset;
cvar_t *cl_mouseAccel;
cvar_t *cl_mouseAccelStyle;
Cvar::Cvar<float> m_pitch("m_pitch", "mouse sensitivity modifier for looking up/down", Cvar::NONE, 0.022);
Cvar::Cvar<float> m_yaw("m_yaw", "mouse sensitivity modifier for looking left/right", Cvar::NONE, 0.022);
Cvar::Cvar<float> m_forward("m_forward", "mouse sensitivity modifier for (mlook off) walking", Cvar::NONE, 0.25);
Cvar::Cvar<float> m_side("m_side", "mouse sensitivity modifier for +strafe", Cvar::NONE, 0.25);
Cvar::Cvar<bool> m_filter("m_filter", "smooth mouse inputs over 2 frames", Cvar::NONE, false);
Cvar::Cvar<float> j_pitch("j_pitch", "joystick move scale for pitch axis", Cvar::NONE, 0.022);
Cvar::Cvar<float> j_yaw("j_yaw", "joystick move scale for yaw axis", Cvar::NONE, -0.022);
Cvar::Cvar<float> j_forward("j_forward", "joystick move scale for forward axis", Cvar::NONE, -0.25);
Cvar::Cvar<float> j_side("j_side", "joystick move scale for side (strafe) axis", Cvar::NONE, 0.25);
Cvar::Cvar<float> j_up("j_up", "joystick move scale for up axis", Cvar::NONE, 1.0);
Cvar::Range<Cvar::Cvar<int>> j_pitch_axis("j_pitch_axis", "joystick pitch axis number", Cvar::NONE, 3, 0, Util::ordinal(joystickAxis_t::MAX_JOYSTICK_AXIS) - 1);
Cvar::Range<Cvar::Cvar<int>> j_yaw_axis("j_yaw_axis", "joystick yaw axis number", Cvar::NONE, 4, 0, Util::ordinal(joystickAxis_t::MAX_JOYSTICK_AXIS) - 1);
Cvar::Range<Cvar::Cvar<int>> j_forward_axis("j_forward_axis", "joystick forward axis number", Cvar::NONE, 1, 0, Util::ordinal(joystickAxis_t::MAX_JOYSTICK_AXIS) - 1);
Cvar::Range<Cvar::Cvar<int>> j_side_axis("j_side_axis", "joystick side (strafe) axis number", Cvar::NONE, 0, 0, Util::ordinal(joystickAxis_t::MAX_JOYSTICK_AXIS) - 1);
Cvar::Range<Cvar::Cvar<int>> j_up_axis("j_up_axis", "joystick up axis number", Cvar::NONE, 2, 0, Util::ordinal(joystickAxis_t::MAX_JOYSTICK_AXIS) - 1);
cvar_t *cl_activeAction;
cvar_t *cl_autorecord;
cvar_t *cl_allowDownload;
cvar_t *cl_consoleFont;
cvar_t *cl_consoleFontSize;
cvar_t *cl_consoleFontScaling;
cvar_t *cl_consoleFontKerning;
cvar_t *cl_consoleCommand; //see also com_consoleCommand for terminal consoles
struct rsa_public_key public_key;
struct rsa_private_key private_key;
cvar_t *cl_altTab;
// XreaL BEGIN
cvar_t *cl_aviMotionJpeg;
// XreaL END
cvar_t *cl_rate;
clientActive_t cl;
clientConnection_t clc;
clientStatic_t cls;
CGameVM cgvm;
// Structure containing functions exported from refresh DLL
refexport_t re;
void CL_CheckForResend();
#if defined(USE_MUMBLE)
static void CL_UpdateMumble()
{
vec3_t pos, forward, up;
float scale = cl_mumbleScale->value;
float tmp;
if ( !cl_useMumble->integer )
{
return;
}
// !!! FIXME: not sure if this is even close to correct.
AngleVectors( cl.snap.ps.viewangles, forward, nullptr, up );
pos[ 0 ] = cl.snap.ps.origin[ 0 ] * scale;
pos[ 1 ] = cl.snap.ps.origin[ 2 ] * scale;
pos[ 2 ] = cl.snap.ps.origin[ 1 ] * scale;
tmp = forward[ 1 ];
forward[ 1 ] = forward[ 2 ];
forward[ 2 ] = tmp;
tmp = up[ 1 ];
up[ 1 ] = up[ 2 ];
up[ 2 ] = tmp;
if ( cl_useMumble->integer > 1 )
{
fprintf( stderr, "%f %f %f, %f %f %f, %f %f %f\n",
pos[ 0 ], pos[ 1 ], pos[ 2 ],
forward[ 0 ], forward[ 1 ], forward[ 2 ],
up[ 0 ], up[ 1 ], up[ 2 ] );
}
mumble_update_coordinates( pos, forward, up );
}
#endif
/*
=======================================================================
CLIENT RELIABLE COMMAND COMMUNICATION
=======================================================================
*/
/*
======================
CL_AddReliableCommand
The given command will be transmitted to the server, and is guaranteed to
not have future usercmd_t executed before it is executed
======================
*/
void CL_AddReliableCommand( const char *cmd )
{
int index;
// catch empty commands
while ( *cmd && *cmd <= ' ' )
{
++cmd;
}
if ( !*cmd )
{
return;
}
// if we would be losing an old command that hasn't been acknowledged,
// we must drop the connection
if ( clc.reliableSequence - clc.reliableAcknowledge > MAX_RELIABLE_COMMANDS )
{
Sys::Drop( "Client command overflow" );
}
clc.reliableSequence++;
index = clc.reliableSequence & ( MAX_RELIABLE_COMMANDS - 1 );
Q_strncpyz( clc.reliableCommands[ index ], cmd, sizeof( clc.reliableCommands[ index ] ) );
}
/*
=======================================================================
CLIENT SIDE DEMO RECORDING
=======================================================================
*/
/*
====================
CL_WriteDemoMessage
Dumps the current net message, prefixed by the length
====================
*/
void CL_WriteDemoMessage( msg_t *msg, int headerBytes )
{
int len, swlen;
// write the packet sequence
len = clc.serverMessageSequence;
swlen = LittleLong( len );
FS_Write( &swlen, 4, clc.demofile );
// skip the packet sequencing information
len = msg->cursize - headerBytes;
swlen = LittleLong( len );
FS_Write( &swlen, 4, clc.demofile );
FS_Write( msg->data + headerBytes, len, clc.demofile );
}
/**
* If a demo is being recorded, this stops it
*/
static void CL_StopRecord()
{
if ( !clc.demorecording )
return;
// finish up
int len = -1;
FS_Write( &len, 4, clc.demofile );
FS_Write( &len, 4, clc.demofile );
FS_FCloseFile( clc.demofile );
clc.demofile = 0;
clc.demorecording = false;
Cvar::SetValueForce(cvar_demo_status_isrecording.Name(), "0");
Cvar::SetValueForce(cvar_demo_status_filename.Name(), "");
Log::Notice("Stopped demo." );
}
class DemoRecordStopCmd: public Cmd::StaticCmd
{
public:
DemoRecordStopCmd()
: Cmd::StaticCmd("demo_record_stop", Cmd::CLIENT, "Stops recording a demo")
{}
void Run(const Cmd::Args&) const override
{
if ( !clc.demorecording )
{
Log::Notice("Not recording a demo." );
return;
}
CL_StopRecord();
}
};
static DemoRecordStopCmd DemoRecordStopCmdRegistration;
class DemoRecordCmd : public Cmd::StaticCmd
{
public:
DemoRecordCmd()
: Cmd::StaticCmd("demo_record", Cmd::CLIENT, "Begins recording a demo from the current position")
{}
void Run(const Cmd::Args& args) const override
{
if ( args.size() > 2 )
{
PrintUsage(args, "[demoname]", "Begins recording a demo from the current position");
return;
}
if ( clc.demorecording )
{
Log::Warn("Already recording.");
return;
}
if ( cls.state != connstate_t::CA_ACTIVE )
{
Log::Warn("You must be in a level to record.");
return;
}
// ATVI Wolfenstein Misc #479 - changing this to a warning
// sync 0 doesn't prevent recording, so not forcing it off .. everyone does g_sync 1 ; record ; g_sync 0 ..
if ( NET_IsLocalAddress(clc.serverAddress) && !Cvar_VariableValue("g_synchronousClients") )
{
Log::Warn("You should set '%s' for smoother demo recording" , "g_synchronousClients 1");
}
std::string demo_name;
if ( args.size() == 2 )
{
demo_name = args[1];
}
CL_Record(demo_name);
}
};
static DemoRecordCmd DemoRecordCmdRegistration;
/**
* Returns a demo name from the current map and time
*/
std::string GenerateDemoName()
{
qtime_t time;
Com_RealTime(&time);
std::string map_name = cl.mapname;
map_name.erase(map_name.rfind('.'));
auto last_slash = map_name.rfind('/');
if ( last_slash != std::string::npos )
map_name.erase(0, last_slash + 1);
return Str::Format(
"%04i-%02i-%02i_%02i%02i%02i_%s_%s",
1900 + time.tm_year, time.tm_mon + 1, time.tm_mday,
time.tm_hour, time.tm_min, time.tm_sec,
NET_AdrToString(clc.serverAddress),
map_name
);
}
void CL_Record(std::string demo_name)
{
if ( demo_name.empty() )
demo_name = GenerateDemoName();
std::string file_name = Str::Format("demos/%s.dm_%d", demo_name, PROTOCOL_VERSION);
clc.demofile = FS_FOpenFileWrite(file_name.c_str());
if ( !clc.demofile )
{
Log::Warn("couldn't open %s.", file_name);
return;
}
Log::Notice( "recording to %s.", file_name );
clc.demorecording = true;
Q_strncpyz(clc.demoName, demo_name.c_str(), std::min<std::size_t>(demo_name.size(), MAX_QPATH));
Cvar::SetValueForce(cvar_demo_status_isrecording.Name(), "1");
Cvar::SetValueForce(cvar_demo_status_filename.Name(), demo_name);
// don't start saving messages until a non-delta compressed message is received
clc.demowaiting = true;
msg_t buf;
byte bufData[ MAX_MSGLEN ];
// write out the gamestate message
MSG_Init( &buf, bufData, sizeof( bufData ) );
MSG_Bitstream( &buf );
// NOTE, MRE: all server->client messages now acknowledge
MSG_WriteLong( &buf, clc.reliableSequence );
MSG_WriteByte( &buf, svc_gamestate );
MSG_WriteLong( &buf, clc.serverCommandSequence );
// configstrings
for ( int i = 0; i < MAX_CONFIGSTRINGS; i++ )
{
if ( cl.gameState[i].empty() )
{
continue;
}
MSG_WriteByte( &buf, svc_configstring );
MSG_WriteShort( &buf, i );
MSG_WriteBigString( &buf, cl.gameState[i].c_str() );
if ( MAX_MSGLEN - buf.cursize < BIG_INFO_STRING ) {
// We have too much configstring data to put it all into one msg_t, so split it here
MSG_WriteByte( &buf, svc_partial );
int len = LittleLong( clc.serverMessageSequence - 1 );
FS_Write( &len, 4, clc.demofile );
len = LittleLong( buf.cursize );
FS_Write( &len, 4, clc.demofile );
FS_Write( buf.data, buf.cursize, clc.demofile );
MSG_Init( &buf, bufData, sizeof( bufData ) );
MSG_Bitstream( &buf );
MSG_WriteLong( &buf, clc.reliableSequence );
MSG_WriteByte( &buf, svc_gamestate );
MSG_WriteLong( &buf, clc.serverCommandSequence );
}
}
// baselines
entityState_t nullstate{};
for ( int i = 0; i < MAX_GENTITIES; i++ )
{
entityState_t *ent = &cl.entityBaselines[ i ];
if ( !ent->number )
{
continue;
}
MSG_WriteByte( &buf, svc_baseline );
MSG_WriteDeltaEntity( &buf, &nullstate, ent, true );
}
MSG_WriteByte( &buf, svc_EOF );
// finished writing the gamestate stuff
// write the client num
MSG_WriteLong( &buf, clc.clientNum );
// finished writing the client packet
MSG_WriteByte( &buf, svc_EOF );
// write it to the demo file
int len = LittleLong( clc.serverMessageSequence - 1 );
FS_Write( &len, 4, clc.demofile );
len = LittleLong( buf.cursize );
FS_Write( &len, 4, clc.demofile );
FS_Write( buf.data, buf.cursize, clc.demofile );
// the rest of the demo file will be copied from net messages
}
/*
=======================================================================
CLIENT SIDE DEMO PLAYBACK
=======================================================================
*/
/*
=================
CL_DemoCompleted
=================
*/
NORETURN static void CL_DemoCompleted()
{
if ( cvar_demo_timedemo.Get() )
{
int time;
time = Sys::Milliseconds() - clc.timeDemoStart;
if ( time > 0 )
{
Log::Notice( "%i frames, %3.1fs: %3.1f fps", clc.timeDemoFrames,
time / 1000.0, clc.timeDemoFrames * 1000.0 / time );
}
}
throw Sys::DropErr(false, "Demo completed");
}
/*
=================
CL_ReadDemoMessage
=================
*/
void CL_ReadDemoMessage()
{
int r;
msg_t buf;
byte bufData[ MAX_MSGLEN ];
int s;
if ( !clc.demofile )
{
CL_DemoCompleted();
}
// get the sequence number
r = FS_Read( &s, 4, clc.demofile );
if ( r != 4 )
{
CL_DemoCompleted();
}
clc.serverMessageSequence = LittleLong( s );
// init the message
MSG_Init( &buf, bufData, sizeof( bufData ) );
// get the length
r = FS_Read( &buf.cursize, 4, clc.demofile );
if ( r != 4 )
{
CL_DemoCompleted();
}
buf.cursize = LittleLong( buf.cursize );
if ( buf.cursize == -1 )
{
CL_DemoCompleted();
}
if ( buf.cursize > buf.maxsize )
{
Sys::Drop( "CL_ReadDemoMessage: demoMsglen > MAX_MSGLEN" );
}
r = FS_Read( buf.data, buf.cursize, clc.demofile );
if ( r != buf.cursize )
{
Log::Notice("Demo file was truncated.");
CL_DemoCompleted();
}
clc.lastPacketTime = cls.realtime;
buf.readcount = 0;
CL_ParseServerMessage( &buf );
}
class DemoPlayCmd: public Cmd::StaticCmd {
public:
DemoPlayCmd(): Cmd::StaticCmd("demo_play", Cmd::CLIENT, "Starts playing a demo file") {
}
void Run(const Cmd::Args& args) const override {
if (args.Argc() != 2) {
PrintUsage(args, "<demoname>", "starts playing a demo file");
return;
}
// make sure a local server is killed
Cvar_Set( "sv_killserver", "1" );
CL_Disconnect( true );
// open the demo file
const std::string& fileName = args.Argv(1);
const char* arg = fileName.c_str();
int prot_ver = PROTOCOL_VERSION - 1;
char extension[32];
char name[ MAX_OSPATH ];
while (prot_ver <= PROTOCOL_VERSION && !clc.demofile) {
Com_sprintf(extension, sizeof(extension), ".dm_%d", prot_ver );
if (!Q_stricmp(arg + strlen(arg) - strlen(extension), extension)) {
Com_sprintf(name, sizeof(name), "demos/%s", arg);
} else {
Com_sprintf(name, sizeof(name), "demos/%s.dm_%d", arg, prot_ver);
}
FS_FOpenFileRead(name, &clc.demofile);
prot_ver++;
}
if (!clc.demofile) {
Sys::Drop("couldn't open %s", name);
}
Q_strncpyz(clc.demoName, arg, sizeof(clc.demoName));
Con_Close();
cls.state = connstate_t::CA_CONNECTED;
clc.demoplaying = true;
// read demo messages until connected
while (cls.state >= connstate_t::CA_CONNECTED && cls.state < connstate_t::CA_PRIMED) {
CL_ReadDemoMessage();
}
// don't get the first snapshot this frame, to prevent the long
// time from the gamestate load from messing causing a time skip
clc.firstDemoFrameSkipped = false;
}
Cmd::CompletionResult Complete(int argNum, const Cmd::Args&, Str::StringRef prefix) const override {
if (argNum == 1) {
return FS::HomePath::CompleteFilename(prefix, "demos", ".dm_" XSTRING(PROTOCOL_VERSION), false, true);
}
return {};
}
};
static DemoPlayCmd DemoPlayCmdRegistration;
// stop demo recording and playback
static void StopDemos()
{
// stop demo recording
CL_StopRecord();
// stop demo playback
if ( clc.demofile )
{
FS_FCloseFile( clc.demofile );
clc.demofile = 0;
}
}
//======================================================================
// stop video recording
static void StopVideo()
{
// stop recording any video
if ( CL_VideoRecording() )
{
// finish rendering current frame
//SCR_UpdateScreen();
CL_CloseAVI();
}
}
/*
=====================
CL_ShutdownAll
=====================
*/
void CL_ShutdownAll()
{
// clear sounds
Audio::StopAllSounds();
// download subsystem
DL_Shutdown();
// shutdown CGame
CL_ShutdownCGame();
// Clear Faces
if ( cls.consoleFont )
{
re.UnregisterFont( cls.consoleFont );
cls.consoleFont = nullptr;
}
// shutdown the renderer
if ( re.Shutdown )
{
re.Shutdown( false ); // don't destroy window or context
}
cls.rendererStarted = false;
cls.soundRegistered = false;
StopVideo();
// Gordon: stop recording on map change etc, demos aren't valid over map changes anyway
CL_StopRecord();
if ( !com_sv_running.Get() )
{
void SV_ShutdownGameProgs();
SV_ShutdownGameProgs();
}
Hunk_Clear();
}
/*
=====================
CL_MapLoading
A local server is starting to load a map, so update the
screen to let the user know about it, then dump all client
memory on the hunk from cgame, ui, and renderer
=====================
*/
void CL_MapLoading()
{
if ( !com_cl_running->integer )
{
return;
}
Con_Close();
cls.keyCatchers = 0;
// if we are already connected to the local host, stay connected
if ( cls.state >= connstate_t::CA_CONNECTED && !Q_stricmp( cls.servername, "loopback" ) )
{
cls.state = connstate_t::CA_CONNECTED; // so the connect screen is drawn
memset( cls.updateInfoString, 0, sizeof( cls.updateInfoString ) );
memset( clc.serverMessage, 0, sizeof( clc.serverMessage ) );
cl.gameState.fill("");
clc.lastPacketSentTime = -9999;
SCR_UpdateScreen();
}
else
{
try {
CL_Disconnect( false );
} catch (Sys::DropErr& err) {
Sys::Error( "CL_Disconnect error during map load: %s", err.what() );
}
Q_strncpyz( cls.servername, "loopback", sizeof( cls.servername ) );
*cls.reconnectCmd = 0; // can't reconnect to this!
cls.state = connstate_t::CA_CHALLENGING; // so the connect screen is drawn
cls.keyCatchers = 0;
SCR_UpdateScreen();
clc.connectTime = -RETRANSMIT_TIMEOUT;
NET_StringToAdr( cls.servername, &clc.serverAddress, netadrtype_t::NA_UNSPEC );
// we don't need a challenge on the localhost
CL_CheckForResend();
}
}
/*
=====================
CL_ClearState
Called before parsing a gamestate
=====================
*/
void CL_ClearState()
{
ResetStruct( cl );
}
/*
=====================
CL_Disconnect
Called when a connection or demo is being terminated.
Goes from a connected state to either a menu state or a console state
Sends a disconnect message to the server
This is also called on Com_Error and Com_Quit, so it shouldn't cause any errors
=====================
*/
static void CL_SendDisconnect()
{
// send a disconnect message to the server
// send it a few times in case one is dropped
if ( com_cl_running && com_cl_running->integer && cls.state >= connstate_t::CA_CONNECTED )
{
CL_AddReliableCommand( "disconnect" );
CL_WritePacket();
CL_WritePacket();
CL_WritePacket();
}
}
void CL_Disconnect( bool showMainMenu )
{
if ( !com_cl_running || !com_cl_running->integer )
{
return;
}
CL_SendDisconnect();
#if defined(USE_MUMBLE)
if ( cl_useMumble->integer && mumble_islinked() )
{
Log::Notice("Mumble: Unlinking from Mumble application" );
mumble_unlink();
}
#endif
if ( clc.download )
{
FS_FCloseFile( clc.download );
clc.download = 0;
}
*cls.downloadTempName = *cls.downloadName = 0;
Cvar_Set( "cl_downloadName", "" );
StopVideo();
StopDemos();
// allow cheats locally again
if (showMainMenu) {
Cvar::SetValueForce("sv_cheats", "1");
}
CL_ClearState();
// wipe the client connection
ResetStruct( clc );
CL_ClearStaticDownload();
FS::PakPath::ClearPaks();
FS_LoadBasePak();
// show_bug.cgi?id=589
// don't try a restart if rocket is nullptr, as we might be in the middle of a restart already
if ( cgvm.IsActive() && cls.state > connstate_t::CA_DISCONNECTED )
{
// restart the UI
cls.state = connstate_t::CA_DISCONNECTED;
// shutdown the UI
CL_ShutdownCGame();
// init the UI
cgvm.Start();
cgvm.CGameRocketInit();
}
else
{
cls.state = connstate_t::CA_DISCONNECTED;
}
CL_OnTeamChanged( 0 );
}
/*
===================
CL_ForwardCommandToServer
adds the current command line as a clientCommand
things like godmode, noclip, etc, are commands directed to the server,
so when they are typed in at the console, they will need to be forwarded.
===================
*/
void CL_ForwardCommandToServer( const char *string )
{
const char *cmd = Cmd_Argv( 0 );
// ignore key up commands
if ( cmd[ 0 ] == '-' )
{
return;
}
if ( clc.demoplaying || cls.state < connstate_t::CA_CONNECTED || cmd[ 0 ] == '+' || cmd[ 0 ] == '\0' )
{
Log::Notice( "Unknown command \"%s\"", cmd );
return;
}
if ( Cmd_Argc() > 1 )
{
CL_AddReliableCommand( string );
}
else
{
CL_AddReliableCommand( cmd );
}
}
/*
======================================================================
CONSOLE COMMANDS
======================================================================
*/
/*
==================
CL_ForwardToServer_f
==================
*/
void CL_ForwardToServer_f()
{
if ( cls.state != connstate_t::CA_ACTIVE || clc.demoplaying )
{
Log::Notice("Not connected to a server." );
return;
}
// don't forward the first argument
if ( Cmd_Argc() > 1 )
{
CL_AddReliableCommand( Cmd_Args() );
}
}
/*
==================
CL_Disconnect_f
==================
*/
void CL_Disconnect_f()
{
throw Sys::DropErr(false, "Disconnecting.");
}
/*
================
CL_Reconnect_f
================
*/
void CL_Reconnect_f()
{
if ( !*cls.servername )
{
Log::Notice("Can't reconnect to nothing." );
}
else if ( !*cls.reconnectCmd )
{
Log::Notice("Can't reconnect to localhost." );
}
else
{
Cmd::BufferCommandTextAfter(cls.reconnectCmd, true);
}
}
/*
================
CL_Connect_f
================
*/
void CL_Connect_f()
{
char *server;
char password[ 64 ];
char *offset;
int argc = Cmd_Argc();
netadrtype_t family = netadrtype_t::NA_UNSPEC;
if ( argc != 2 && argc != 3 )
{
Cmd_PrintUsage("[-4|-6] <server>", nullptr);
return;
}
if ( argc == 2 )
{
server = (char *) Cmd_Argv( 1 );
}
else
{
if ( !strcmp( Cmd_Argv( 1 ), "-4" ) )
{
family = netadrtype_t::NA_IP;
}
else if ( !strcmp( Cmd_Argv( 1 ), "-6" ) )
{
family = netadrtype_t::NA_IP6;
}
else
{
Log::Warn("only -4 or -6 as address type understood." );
}
server = (char *) Cmd_Argv( 2 );