forked from QW-Group/ezquake-source
-
Notifications
You must be signed in to change notification settings - Fork 1
/
cl_main.c
2962 lines (2446 loc) · 74.1 KB
/
cl_main.c
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
/*
Copyright (C) 1996-1997 Id Software, Inc.
This program 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 2
of the License, or (at your option) any later version.
This program 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 this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
// cl_main.c -- client main loop
#include "quakedef.h"
#include "cdaudio.h"
#include "cl_slist.h"
#include "movie.h"
#include "logging.h"
#include "ignore.h"
#include "fchecks.h"
#include "config_manager.h"
#include "mvd_utils.h"
#include "EX_browser.h"
#include "EX_qtvlist.h"
#include "qtv.h"
#include "keys.h"
#include "hud.h"
#include "hud_common.h"
#include "hud_editor.h"
#include "input.h"
#include "gl_model.h"
#include "tr_types.h"
#include "teamplay.h"
#include "tp_triggers.h"
#include "rulesets.h"
#include "version.h"
#include "stats_grid.h"
#include "fmod.h"
#include "sbar.h"
#include "utils.h"
#include "qsound.h"
#include "menu.h"
#include "image.h"
#ifndef _WIN32
#include <netdb.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#endif
#ifndef CLIENTONLY
#include "server.h"
#endif
#include "fs.h"
#include "help.h"
#include "irc.h"
#ifdef _DEBUG
#include "parser.h"
#endif
#include "pmove.h"
#include "vx_tracker.h"
#include "menu_demo.h"
#include "r_local.h"
#include "r_renderer.h"
#include "r_performance.h"
#include "r_program.h"
extern qbool ActiveApp, Minimized;
#ifndef CLIENTONLY
static void Dev_PhysicsNormalSet(void);
static void Dev_PhysicsNormalSave(void);
static void Dev_PhysicsNormalShow(void);
#endif
static void Cl_Reset_Min_fps_f(void);
void CL_QWURL_ProcessChallenge(const char *parameters);
// cl_input.c
void onchange_pext_serversideweapon(cvar_t* var, char* value, qbool* cancel);
void onchange_hud_performance_average(cvar_t* var, char* value, qbool* cancel);
#ifdef MVD_PEXT1_HIDDEN_MESSAGES
// cl_parse.c
void CL_ParseHiddenDataMessage(void);
#endif
static void AuthUsernameChanged(cvar_t* var, char* value, qbool* cancel);
cvar_t allow_scripts = {"allow_scripts", "2", 0, Rulesets_OnChange_allow_scripts};
cvar_t rcon_password = {"rcon_password", ""};
cvar_t rcon_address = {"rcon_address", ""};
cvar_t cl_crypt_rcon = {"cl_crypt_rcon", "1"};
cvar_t cl_timeout = {"cl_timeout", "60"};
cvar_t cl_delay_packet = {"cl_delay_packet", "0", 0, Rulesets_OnChange_cl_delay_packet};
cvar_t cl_delay_packet_target = { "cl_delay_packet_target", "0", 0, Rulesets_OnChange_cl_delay_packet };
cvar_t cl_delay_packet_dev = { "cl_delay_packet_deviation", "0", 0, Rulesets_OnChange_cl_delay_packet };
cvar_t cl_shownet = {"cl_shownet", "0"}; // can be 0, 1, or 2
#if defined(PROTOCOL_VERSION_FTE) || defined(PROTOCOL_VERSION_FTE2) || defined(PROTOCOL_VERSION_MVD1)
cvar_t cl_pext = {"cl_pext", "1"}; // allow/disallow protocol extensions at all.
// some extensions can be explicitly controlled.
cvar_t cl_pext_limits = { "cl_pext_limits", "1" }; // enhanced protocol limits
cvar_t cl_pext_other = {"cl_pext_other", "0"}; // extensions which does not have own variables should be controlled by this variable.
cvar_t cl_pext_warndemos = { "cl_pext_warndemos", "1" }; // if set, user will be warned when saving demos that are not backwards compatible
cvar_t cl_pext_lagteleport = { "cl_pext_lagteleport", "0" }; // server-side adjustment of yaw angle through teleports
#ifdef MVD_PEXT1_SERVERSIDEWEAPON
cvar_t cl_pext_serversideweapon = { "cl_pext_serversideweapon", "0", 0, onchange_pext_serversideweapon }; // server-side weapon selection
#endif
#endif
#ifdef FTE_PEXT_256PACKETENTITIES
cvar_t cl_pext_256packetentities = {"cl_pext_256packetentities", "1"};
#endif
#ifdef FTE_PEXT_CHUNKEDDOWNLOADS
cvar_t cl_pext_chunkeddownloads = {"cl_pext_chunkeddownloads", "1"};
cvar_t cl_chunksperframe = {"cl_chunksperframe", "5"};
#endif
#ifdef FTE_PEXT_FLOATCOORDS
cvar_t cl_pext_floatcoords = {"cl_pext_floatcoords", "1"};
#endif
#ifdef FTE_PEXT_TRANS
cvar_t cl_pext_alpha = {"cl_pext_alpha", "1"};
#endif
#ifdef CLIENTONLY
#define PROCESS_SERVERPACKETS_IMMEDIATELY (0)
#else
static cvar_t cl_sv_packetsync = { "cl_sv_packetsync", "1" };
#define PROCESS_SERVERPACKETS_IMMEDIATELY (cl_sv_packetsync.integer)
#endif
cvar_t cl_sbar = {"cl_sbar", "0"};
cvar_t cl_hudswap = {"cl_hudswap", "0"};
cvar_t cl_maxfps = {"cl_maxfps", "0"};
cvar_t cl_physfps = {"cl_physfps", "0"}; //#fps
cvar_t cl_physfps_spectator = {"cl_physfps_spectator", "30"};
cvar_t cl_independentPhysics = {"cl_independentPhysics", "1", 0, Rulesets_OnChange_indphys};
cvar_t cl_predict_players = {"cl_predict_players", "1"};
cvar_t cl_solid_players = {"cl_solid_players", "1"};
cvar_t cl_predict_half = {"cl_predict_half", "0"};
cvar_t hud_fps_min_reset_interval = {"hud_fps_min_reset_interval", "30"};
cvar_t hud_frametime_max_reset_interval = { "hud_frametime_max_reset_interval", "30" };
cvar_t hud_performance_average = { "hud_performance_average", "1", 0, onchange_hud_performance_average };
cvar_t localid = {"localid", ""};
static qbool allowremotecmd = true;
cvar_t cl_deadbodyfilter = {"cl_deadbodyFilter", "0"};
cvar_t cl_gibfilter = {"cl_gibFilter", "0"};
cvar_t cl_backpackfilter = {"cl_backpackfilter", "0"};
cvar_t cl_muzzleflash = {"cl_muzzleflash", "1"};
cvar_t cl_rocket2grenade = {"cl_r2g", "0"};
cvar_t cl_demospeed = {"cl_demospeed", "1"};
cvar_t cl_staticsounds = {"cl_staticSounds", "1"};
cvar_t cl_fakeshaft = {"cl_fakeshaft", "0", 0, Rulesets_OnChange_cl_fakeshaft};
cvar_t cl_fakeshaft_extra_updates = {"cl_fakeshaft_extra_updates", "1"};
cvar_t cl_parseWhiteText = {"cl_parseWhiteText", "1"};
cvar_t cl_filterdrawviewmodel = {"cl_filterdrawviewmodel", "0"};
cvar_t cl_demoPingInterval = {"cl_demoPingInterval", "5"};
cvar_t demo_getpings = {"demo_getpings", "1"};
cvar_t cl_chatsound = {"s_chat_custom", "1"};
cvar_t cl_confirmquit = {"cl_confirmquit", "0"}; // , CVAR_INIT
cvar_t cl_fakename = {"cl_fakename", ""};
cvar_t cl_fakename_suffix = {"cl_fakename_suffix", ": "};
cvar_t qizmo_dir = {"qizmo_dir", "qizmo"};
cvar_t qwdtools_dir = {"qwdtools_dir", "qwdtools"};
void OnChangeColorForcing (cvar_t *var, char *value, qbool *cancel);
void OnChangeDemoTeamplay (cvar_t *var, char *value, qbool *cancel);
cvar_t cl_demoteamplay = {"cl_demoteamplay", "0", 0, OnChangeDemoTeamplay}; // for NQ demos where we need to say it is teamplay rather than FFA
cvar_t cl_earlypackets = {"cl_earlypackets", "1"};
cvar_t cl_restrictions = {"cl_restrictions", "0"}; // 1 is FuhQuake and QW262 defaults
cvar_t cl_floodprot = {"cl_floodprot", "0"};
cvar_t cl_fp_messages = {"cl_fp_messages", "4"};
cvar_t cl_fp_persecond = {"cl_fp_persecond", "4"};
cvar_t cl_cmdline = {"cl_cmdline", "", CVAR_ROM};
cvar_t cl_useproxy = {"cl_useproxy", "0"};
cvar_t cl_proxyaddr = {"cl_proxyaddr", ""};
cvar_t cl_window_caption = {"cl_window_caption", "1"};
cvar_t cl_model_bobbing = {"cl_model_bobbing", "1"};
cvar_t cl_nolerp = {"cl_nolerp", "0"}; // 0 is good for indep-phys, 1 is good for old-phys
//this var has effect only if cl_nolerp is 1 and indep-phys enabled
//setting it to 0 removes jerking when standing on platforms
cvar_t cl_nolerp_on_entity = {"cl_nolerp_on_entity", "0"};
cvar_t cl_newlerp = {"cl_newlerp", "0"};
cvar_t cl_lerp_monsters = {"cl_lerp_monsters", "1"};
cvar_t cl_fix_mvd = {"cl_fix_mvd", "0"};
cvar_t r_rocketlight = {"r_rocketLight", "1"};
cvar_t r_rocketlightcolor = {"r_rocketLightColor", "0"};
cvar_t r_explosionlightcolor = {"r_explosionLightColor", "0"};
cvar_t r_explosionlight = {"r_explosionLight", "1"};
cvar_t r_flagcolor = {"r_flagColor", "0"};
cvar_t r_lightflicker = {"r_lightflicker", "1"};
cvar_t r_powerupglow = {"r_powerupGlow", "1"};
cvar_t cl_novweps = {"cl_novweps", "0"};
cvar_t r_drawvweps = {"r_drawvweps", "1"};
cvar_t r_rockettrail = {"r_rocketTrail", "1"}; // 9
cvar_t r_grenadetrail = {"r_grenadeTrail", "1"}; // 3
cvar_t r_railtrail = {"r_railTrail", "1"};
cvar_t r_instagibtrail = {"r_instagibTrail", "1"};
cvar_t r_explosiontype = {"r_explosionType", "1"}; // 7
cvar_t r_telesplash = {"r_telesplash", "1"}; // disconnect
cvar_t r_shaftalpha = {"r_shaftalpha", "1"};
cvar_t r_lightdecayrate = {"r_lightdecayrate", "2"}; // default 2, as CL_DecayLights() used to get called twice per frame
cvar_t r_lightmap_lateupload = {"r_lightmap_lateupload", "0"};
cvar_t r_lightmap_packbytexture = {"r_lightmap_packbytexture", "2"};
// info mirrors
cvar_t password = {"password", "", CVAR_USERINFO};
cvar_t spectator = {"spectator", "", CVAR_USERINFO_NO_CFG_RESET };
void CL_OnChange_name_validate(cvar_t *var, char *val, qbool *cancel);
cvar_t name = {"name", "player", CVAR_USERINFO, CL_OnChange_name_validate};
cvar_t team = {"team", "", CVAR_USERINFO_NO_CFG_RESET };
cvar_t topcolor = {"topcolor","", CVAR_USERINFO_NO_CFG_RESET };
cvar_t bottomcolor = {"bottomcolor","", CVAR_USERINFO_NO_CFG_RESET };
cvar_t skin = {"skin", "", CVAR_USERINFO_NO_CFG_RESET };
cvar_t rate = {"rate", "25000", CVAR_USERINFO};
void OnChange_AppliedAfterReconnect (cvar_t *var, char *value, qbool *cancel);
cvar_t mtu = {"mtu", "", CVAR_USERINFO, OnChange_AppliedAfterReconnect};
cvar_t msg = {"msg", "1", CVAR_USERINFO};
cvar_t noaim = {"noaim", "1", CVAR_USERINFO};
cvar_t w_switch = {"w_switch", "", CVAR_USERINFO};
cvar_t b_switch = {"b_switch", "", CVAR_USERINFO};
cvar_t railcolor = {"railcolor", "", CVAR_USERINFO};
cvar_t gender = {"gender", "", CVAR_USERINFO};
cvar_t cl_mediaroot = {"cl_mediaroot", "0"};
cvar_t msg_filter = {"msg_filter", "0"};
cvar_t cl_onload = {"cl_onload", "menu"};
#ifdef WIN32
cvar_t cl_verify_qwprotocol = {"cl_verify_qwprotocol", "1"};
#endif // WIN32
cvar_t demo_autotrack = {"demo_autotrack", "0"}; // use or not autotrack info from mvd demos
// Authentication
cvar_t cl_username = {"cl_username", "", CVAR_QUEUED_TRIGGER, AuthUsernameChanged};
static void CL_Authenticate_f(void);
// antilag debugging
cvar_t cl_debug_antilag_view = { "cl_debug_antilag_view", "0" };
cvar_t cl_debug_antilag_ghost = { "cl_debug_antilag_ghost", "0" };
cvar_t cl_debug_antilag_self = { "cl_debug_antilag_self", "0" };
cvar_t cl_debug_antilag_lines = { "cl_debug_antilag_lines", "0" };
cvar_t cl_debug_antilag_send = { "cl_debug_antilag_send", "0" };
// weapon-switching debugging
cvar_t cl_debug_weapon_view = { "cl_debug_weapon_view", "0" };
/// persistent client state
clientPersistent_t cls;
/// client state
clientState_t cl;
centity_t cl_entities[CL_MAX_EDICTS];
efrag_t cl_efrags[MAX_EFRAGS];
entity_t cl_static_entities[MAX_STATIC_ENTITIES];
lightstyle_t cl_lightstyle[MAX_LIGHTSTYLES];
dlight_t cl_dlights[MAX_DLIGHTS];
unsigned int cl_dlight_active[MAX_DLIGHTS/32];
// refresh list
visentlist_t cl_visents;
double connect_time = 0; // for connection retransmits
qbool connected_via_proxy = false;
qbool host_skipframe; // used in demo playback
byte *host_basepal = NULL;
byte *host_colormap = NULL;
qbool physframe;
double physframetime;
// emodel and pmodel are encrypted to prevent llamas from easily hacking them
char emodel_name[] = { 'e'^0xe5, 'm'^0xe5, 'o'^0xe5, 'd'^0xe5, 'e'^0xe5, 'l'^0xe5, 0 };
char pmodel_name[] = { 'p'^0xe5, 'm'^0xe5, 'o'^0xe5, 'd'^0xe5, 'e'^0xe5, 'l'^0xe5, 0 };
static void simple_crypt (char *buf, int len) {
while (len--)
*buf++ ^= 0xe5;
}
static void CL_FixupModelNames (void) {
simple_crypt (emodel_name, sizeof(emodel_name) - 1);
simple_crypt (pmodel_name, sizeof(pmodel_name) - 1);
}
void OnChange_AppliedAfterReconnect (cvar_t *var, char *value, qbool *cancel)
{
if (cls.state != ca_disconnected)
{
Com_Printf ("%s change will be applied after reconnect!\n", var->name);
}
}
char *CL_Macro_ConnectionType(void)
{
char *s;
static char macrobuf[16];
s = (cls.state < ca_connected) ? "disconnected" : cl.spectator ? "spectator" : "player";
strlcpy(macrobuf, s, sizeof(macrobuf));
return macrobuf;
}
char *CL_Macro_Demoplayback(void)
{
char *s;
static char macrobuf[16];
s = cls.mvdplayback ? "mvdplayback" : cls.demoplayback ? "qwdplayback" : "0";
strlcpy(macrobuf, s, sizeof(macrobuf));
return macrobuf;
}
char *CL_Macro_Demotime(void)
{
// Intended for scripted & timed camera movement
static char macrobuf[16];
snprintf(macrobuf, sizeof(macrobuf), "%f", (float) cls.demotime);
return macrobuf;
}
char *CL_Macro_Rand(void)
{
// Returns a number in range <0..1)
static char macrobuf[16];
snprintf(macrobuf, sizeof(macrobuf), "%f", (double) rand() / RAND_MAX);
return macrobuf;
}
char *CL_Macro_Serverstatus(void)
{
char *s;
static char macrobuf[16];
s = (cls.state < ca_connected) ? "disconnected" : cl.standby ? "standby" : "normal";
strlcpy(macrobuf, s, sizeof(macrobuf));
return macrobuf;
}
char *CL_Macro_ServerIp(void)
{
return NET_AdrToString(cls.server_adr);
}
char *CL_Macro_Conwidth(void)
{
static char macrobuf[16];
snprintf(macrobuf, sizeof(macrobuf), "%i", vid.conwidth);
return macrobuf;
}
char *CL_Macro_Conheight(void)
{
static char macrobuf[16];
snprintf(macrobuf, sizeof(macrobuf), "%i", vid.conheight);
return macrobuf;
}
int CL_ClientState (void)
{
return cls.state;
}
void CL_MakeActive(void)
{
#ifdef DEBUG_MEMORY_ALLOCATIONS
Sys_Printf("\nevent,active (map=%s)\n", host_mapname.string);
#endif
// last chance
CachePics_AtlasFrame();
// compile all programs
if (GL_Supported(R_SUPPORT_RENDERING_SHADERS)) {
R_ProgramCompileAll();
}
cls.state = ca_active;
if (cls.demoplayback)
{
host_skipframe = true;
demostarttime = cls.demotime;
}
if (key_dest == key_startupdemo_game) {
key_dest = key_game;
}
if (!cls.demoseeking) {
Con_ClearNotify ();
}
TP_ExecTrigger("f_spawn");
}
// Cvar system calls this when a CVAR_USERINFO cvar changes
void CL_UserinfoChanged (char *key, char *string)
{
char *s;
s = TP_ParseFunChars (string, false);
if (strcmp(s, Info_ValueForKey (cls.userinfo, key)))
{
Info_SetValueForKey (cls.userinfo, key, s, MAX_INFO_STRING);
if (cls.state >= ca_connected)
{
if (cls.mvdplayback == QTV_PLAYBACK)
{
QTV_Cmd_Printf(QTV_EZQUAKE_EXT_SETINFO, "setinfo \"%s\" \"%s\"", key, s);
}
else
{
MSG_WriteByte (&cls.netchan.message, clc_stringcmd);
SZ_Print (&cls.netchan.message, va("setinfo \"%s\" \"%s\"", key, s));
}
}
}
}
#ifdef PROTOCOL_VERSION_FTE
unsigned int CL_SupportedFTEExtensions (void)
{
unsigned int fteprotextsupported = 0;
if (!cl_pext.value)
return 0;
#ifdef FTE_PEXT_CHUNKEDDOWNLOADS
if (cl_pext_chunkeddownloads.value)
fteprotextsupported |= FTE_PEXT_CHUNKEDDOWNLOADS;
#endif
#ifdef FTE_PEXT_256PACKETENTITIES
if (cl_pext_256packetentities.value)
fteprotextsupported |= FTE_PEXT_256PACKETENTITIES;
#endif
#ifdef FTE_PEXT_FLOATCOORDS
if (cl_pext_floatcoords.value)
fteprotextsupported |= FTE_PEXT_FLOATCOORDS;
#endif
#ifdef FTE_PEXT_TRANS
if (cl_pext_alpha.value)
fteprotextsupported |= FTE_PEXT_TRANS;
#endif
if (cl_pext_limits.value) {
#ifdef FTE_PEXT_MODELDBL
fteprotextsupported |= FTE_PEXT_MODELDBL;
#endif
#ifdef FTE_PEXT_ENTITYDBL
fteprotextsupported |= FTE_PEXT_ENTITYDBL;
#endif
#ifdef FTE_PEXT_ENTITYDBL2
fteprotextsupported |= FTE_PEXT_ENTITYDBL2;
#endif
#ifdef FTE_PEXT_SPAWNSTATIC2
fteprotextsupported |= FTE_PEXT_SPAWNSTATIC2;
#endif
}
if (cl_pext_other.value)
{
#ifdef FTE_PEXT_ACCURATETIMINGS
fteprotextsupported |= FTE_PEXT_ACCURATETIMINGS;
#endif
#ifdef FTE_PEXT_HLBSP
fteprotextsupported |= FTE_PEXT_HLBSP;
#endif
}
return fteprotextsupported;
}
#endif // PROTOCOL_VERSION_FTE
#ifdef PROTOCOL_VERSION_FTE2
unsigned int CL_SupportedFTEExtensions2 (void)
{
unsigned int fteprotextsupported2 = 0
#ifdef FTE_PEXT2_VOICECHAT
| FTE_PEXT2_VOICECHAT
#endif
;
if (!cl_pext.value)
return 0;
return fteprotextsupported2;
}
#endif // PROTOCOL_VERSION_FTE2
#ifdef PROTOCOL_VERSION_MVD1
unsigned int CL_SupportedMVDExtensions1(void)
{
unsigned int extensions_supported = 0;
if (!cl_pext.value) {
return 0;
}
#ifdef MVD_PEXT1_FLOATCOORDS
if (cl_pext_floatcoords.value) {
extensions_supported |= MVD_PEXT1_FLOATCOORDS;
}
#endif
#ifdef MVD_PEXT1_HIGHLAGTELEPORT
if (cl_pext_lagteleport.integer & 1) {
extensions_supported |= MVD_PEXT1_HIGHLAGTELEPORT;
}
#endif
#ifdef MVD_PEXT1_SERVERSIDEWEAPON
if (cl_pext_serversideweapon.integer) {
extensions_supported |= MVD_PEXT1_SERVERSIDEWEAPON;
}
#endif
#ifdef MVD_PEXT1_DEBUG_ANTILAG
if (cl_debug_antilag_send.integer) {
extensions_supported |= MVD_PEXT1_DEBUG_ANTILAG;
}
#endif
return extensions_supported;
}
#endif
// Called by CL_Connect_f and CL_CheckResend
static void CL_SendConnectPacket(
#ifdef PROTOCOL_VERSION_FTE
unsigned int ftepext
#ifdef PROTOCOL_VERSION_FTE2
,
#endif // PROTOCOL_VERSION_FTE2
#endif // PROTOCOL_VERSION_FTE
#ifdef PROTOCOL_VERSION_FTE2
unsigned int ftepext2
#ifdef PROTOCOL_VERSION_MVD1
,
#endif
#endif // PROTOCOL_VERSION_FTE2
#ifdef PROTOCOL_VERSION_MVD1
unsigned int mvdpext1
#endif
)
{
char data[2048];
char biguserinfo[MAX_INFO_STRING + 32];
int extensions;
extern cvar_t cl_novweps;
if (cls.state != ca_disconnected)
return;
#ifdef PROTOCOL_VERSION_FTE
cls.fteprotocolextensions = (ftepext & CL_SupportedFTEExtensions());
#endif // PROTOCOL_VERSION_FTE
#ifdef PROTOCOL_VERSION_FTE2
cls.fteprotocolextensions2 = (ftepext2 & CL_SupportedFTEExtensions2());
#endif // PROTOCOL_VERSION_FTE
#ifdef PROTOCOL_VERSION_MVD1
cls.mvdprotocolextensions1 = (mvdpext1 & CL_SupportedMVDExtensions1());
#endif
connect_time = cls.realtime; // For retransmit requests
cls.qport = Cvar_Value("qport");
// Let the server know what extensions we support.
strlcpy (biguserinfo, cls.userinfo, sizeof (biguserinfo));
extensions = CLIENT_EXTENSIONS &~ (cl_novweps.value ? Z_EXT_VWEP : 0);
Info_SetValueForStarKey (biguserinfo, "*z_ext", va("%i", extensions), sizeof(biguserinfo));
snprintf(data, sizeof(data), "\xff\xff\xff\xff" "connect %i %i %i \"%s\"\n", PROTOCOL_VERSION, cls.qport, cls.challenge, biguserinfo);
#ifdef PROTOCOL_VERSION_FTE
if (cls.fteprotocolextensions)
{
char tmp[128];
snprintf(tmp, sizeof(tmp), "0x%x 0x%x\n", PROTOCOL_VERSION_FTE, cls.fteprotocolextensions);
Com_Printf_State(PRINT_DBG, "0x%x is fte protocol ver and 0x%x is fteprotocolextensions\n", PROTOCOL_VERSION_FTE, cls.fteprotocolextensions);
strlcat(data, tmp, sizeof(data));
}
#endif // PROTOCOL_VERSION_FTE
#ifdef PROTOCOL_VERSION_FTE2
if (cls.fteprotocolextensions2)
{
char tmp[128];
snprintf(tmp, sizeof(tmp), "0x%x 0x%x\n", PROTOCOL_VERSION_FTE2, cls.fteprotocolextensions2);
Com_Printf_State(PRINT_DBG, "0x%x is fte protocol ver and 0x%x is fteprotocolextensions2\n", PROTOCOL_VERSION_FTE2, cls.fteprotocolextensions2);
strlcat(data, tmp, sizeof(data));
}
#endif // PROTOCOL_VERSION_FTE2
#ifdef PROTOCOL_VERSION_MVD1
if (cls.mvdprotocolextensions1) {
char tmp[128];
snprintf(tmp, sizeof(tmp), "0x%x 0x%x\n", PROTOCOL_VERSION_MVD1, cls.mvdprotocolextensions1);
Com_Printf_State(PRINT_DBG, "0x%x is mvd protocol ver and 0x%x is mvdprotocolextensions1\n", PROTOCOL_VERSION_MVD1, cls.mvdprotocolextensions1);
strlcat(data, tmp, sizeof(data));
}
#endif
NET_SendPacket(NS_CLIENT, strlen(data), data, cls.server_adr);
}
// Resend a connect message if the last one has timed out
void CL_CheckForResend (void)
{
char data[2048];
double t1, t2;
#ifndef CLIENTONLY
if (cls.state == ca_disconnected && com_serveractive)
{
// if the local server is running and we are not, then connect
strlcpy (cls.servername, "local", sizeof(cls.servername));
NET_StringToAdr("local", &cls.server_adr);
// We don't need a challenge on the local server.
CL_SendConnectPacket(
#ifdef PROTOCOL_VERSION_FTE
svs.fteprotocolextensions
#ifdef PROTOCOL_VERSION_FTE2
,
#endif // PROTOCOL_VERSION_FTE2
#endif // PROTOCOL_VERSION_FTE
#ifdef PROTOCOL_VERSION_FTE2
svs.fteprotocolextensions2
#ifdef PROTOCOL_VERSION_MVD1
,
#endif
#endif // PROTOCOL_VERSION_FTE
#ifdef PROTOCOL_VERSION_MVD1
svs.mvdprotocolextension1
#endif
);
// FIXME: cls.state = ca_connecting so that we don't send the packet twice?
return;
}
#endif
if (cls.state != ca_disconnected || !connect_time)
return;
if (cls.realtime - connect_time < 5.0)
return;
t1 = Sys_DoubleTime();
if (!NET_StringToAdr(cls.servername, &cls.server_adr))
{
Com_Printf("Bad server address\n");
connect_time = 0;
return;
}
t2 = Sys_DoubleTime();
connect_time = cls.realtime + t2 - t1; // for retransmit requests
if (cls.server_adr.port == 0)
cls.server_adr.port = BigShort(PORT_SERVER);
Com_Printf("&cf11connect:&r %s...\n", cls.servername);
snprintf(data, sizeof(data), "\xff\xff\xff\xff" "getchallenge\n");
NET_SendPacket(NS_CLIENT, strlen(data), data, cls.server_adr);
}
void CL_BeginServerConnect(void)
{
connect_time = -999; // CL_CheckForResend() will fire immediately
CL_CheckForResend();
}
//
// Parses a QW-URL of the following format
// (this can be associated with ezquake in windows by setting some reg info):
// qw://server:port/command
//
// Supported commands:
// - join/connect
// - spectate/observe
// - qtv
//
void CL_QWURL_f (void)
{
char *connection_str = NULL;
char *command = NULL;
if (Cmd_Argc() != 2)
{
Com_Printf ("Usage: %s <qw-url>\n", Cmd_Argv(0));
return;
}
// Strip the leading qw:// first.
{
char qws_str[] = "qw://";
int qws_len = sizeof(qws_str) - 1;
connection_str = Cmd_Argv(1);
if (!strncasecmp(qws_str, connection_str, qws_len))
{
connection_str += qws_len;
}
else
{
Com_Printf("%s: The QW-URL must start with qw://\n", Cmd_Argv(0));
return;
}
}
// Find the first "/" and treat what's after it as the command.
if ((command = strchr(connection_str, '/')))
{
// Null terminate the server name string.
*command = 0;
command++;
}
else
{
// No command given.
command = "";
}
// Default to connecting.
if (!strcmp(command, "") || !strncasecmp(command, "join", 4) || !strncasecmp(command, "connect", 7))
{
Cbuf_AddText(va("join %s\n", connection_str));
}
else if (!strncmp(command, "challenge?", 10))
{
CL_QWURL_ProcessChallenge(command + 9);
Cbuf_AddText(va("connect %s\n", connection_str));
}
else if (!strncasecmp(command, "spectate", 8) || !strncasecmp(command, "observe", 7))
{
Cbuf_AddText(va("observe %s\n", connection_str));
}
else if (!strncasecmp(command, "qtv", 3))
{
char *password = command + 3;
if (*password == '/') {
*password = ' ';
}
else {
*password = '\0';
}
Cbuf_AddText(va("qtvplay %s%s\n", connection_str, password));
}
else
{
Com_Printf("%s: Illegal command %s\n", Cmd_Argv(0), command);
}
}
void CL_Connect_f (void)
{
qbool proxy;
char *connect_addr = NULL;
char *server_buf = NULL;
if (Cmd_Argc() != 2)
{
Com_Printf ("Usage: %s <server>\n", Cmd_Argv(0));
return;
}
// in this part proxy means QWFWD proxy
if (cl_proxyaddr.string[0]) {
char *secondproxy;
if ((secondproxy = strchr(cl_proxyaddr.string, '@'))) {
size_t prx_buf_len = strlen(cl_proxyaddr.string) + strlen(Cmd_Argv(1)) + 2;
char *prx_buf = (char *) Q_malloc(prx_buf_len);
server_buf = (char *) Q_malloc(strlen(cl_proxyaddr.string) + 1); // much more than needed
strlcpy(server_buf, cl_proxyaddr.string, secondproxy - cl_proxyaddr.string + 1);
connect_addr = server_buf;
strlcpy(prx_buf, secondproxy + 1, prx_buf_len);
strlcat(prx_buf, "@", prx_buf_len);
strlcat(prx_buf, Cmd_Argv(1), prx_buf_len);
Info_SetValueForKeyEx(cls.userinfo, "prx", prx_buf, MAX_INFO_STRING, false);
Q_free(prx_buf);
}
else {
Info_SetValueForKey (cls.userinfo, "prx", Cmd_Argv(1), MAX_INFO_STRING);
#if 0 // FIXME: qqshka: disabled untill one explain that it does and why.
if (cls.state >= ca_connected) {
Cmd_ForwardToServer ();
}
#endif
connect_addr = cl_proxyaddr.string;
}
connected_via_proxy = true;
}
else
{
connect_addr = Cmd_Argv(1);
connected_via_proxy = false;
}
// in this part proxy means Qizmo proxy
proxy = cl_useproxy.value && CL_ConnectedToProxy();
if (proxy)
{
Cbuf_AddText(va("say ,connect %s\n", connect_addr));
}
else
{
Host_EndGame();
strlcpy(cls.servername, connect_addr, sizeof(cls.servername));
CL_BeginServerConnect();
}
if (server_buf) Q_free(server_buf);
}
void CL_Connect_BestRoute_f(void)
{
if (Cmd_Argc() != 2) {
Com_Printf("Usage: %s <address>\nConnects to given server via fastest available path (ping-wise).\n", Cmd_Argv(0));
Com_Printf("Requires Server Browser refreshed with sb_findroutes 1\n");
return;
}
else {
netadr_t adr;
if (!NET_StringToAdr(Cmd_Argv(1), &adr)) {
Com_Printf("Invalid address\n");
return;
}
if (adr.port == 0)
adr.port = htons(27500);
SB_PingTree_DumpPath(&adr);
SB_PingTree_ConnectBestPath(&adr);
}
}
void CL_TCPConnect_f (void)
{
char buffer[6] = {'q', 'i', 'z', 'm', 'o', '\n'};
int newsocket;
int _true = true;
float giveuptime;
if (Cmd_Argc() != 2) {
Com_Printf ("Usage: %s <server>\n", Cmd_Argv(0));
return;
}
Host_EndGame (); // CL_Disconnect_f();
strlcpy(cls.servername, Cmd_Argv (1), sizeof(cls.servername));
NET_StringToAdr(cls.servername, &cls.sockettcpdest);
if (cls.sockettcp != INVALID_SOCKET)
closesocket(cls.sockettcp);
cls.sockettcp = INVALID_SOCKET;
cls.tcpinlen = 0;
newsocket = TCP_OpenStream(cls.sockettcpdest);
if (newsocket == INVALID_SOCKET)
{
// Failed
Com_Printf("Failed to connect, server is either down, firewalled, or on a different port\n");
return;
}
Com_Printf("Waiting for confirmation of server (10 secs)\n");
giveuptime = Sys_DoubleTime() + 10;
#if 1 // qqshka: qizmo sends "qizmo\n" then expects reply, unfortunatelly that does not work for mvdsv
// that how MVDSV expects, should work with qizmo too
send(newsocket, buffer, sizeof(buffer), 0);
memset(buffer, 0, sizeof(buffer));
#endif
while(giveuptime > Sys_DoubleTime())
{
recv(newsocket, buffer, sizeof(buffer), 0);
if (!strncmp(buffer, "qizmo\n", 6))
{
cls.sockettcp = newsocket;
break;
}
SCR_UpdateScreen();
}
if (cls.sockettcp == INVALID_SOCKET)
{
Com_Printf("Timeout - wrong server type\n");
closesocket(newsocket);
return;
}
Com_Printf("Confirmed\n");
#if 0 // qqshka: qizmo sends "qizmo\n" then expects reply, unfortunatelly that does not work for mvdsv
// that how qizmo expects, does not work with MVDSV
send(cls.sockettcp, buffer, sizeof(buffer), 0);
#endif
if (setsockopt(cls.sockettcp, IPPROTO_TCP, TCP_NODELAY, (char *)&_true, sizeof(_true)) == -1) {
Com_Printf ("CL_TCPConnect_f: setsockopt: (%i): %s\n", qerrno, strerror(qerrno));
}
CL_BeginServerConnect();
}
qbool CL_ConnectedToProxy(void)
{
cmd_alias_t *alias = NULL;
qbool found = true;
char **s;
char *qizmo_aliases[] = { "ezcomp", "ezcomp2", "ezcomp3",
"f_sens", "f_fps", "f_tj", "f_ta", NULL};
char *fteqtv_aliases[] = { "+proxleft", "+proxright", NULL }; // who would need more?
if (cls.state < ca_active)
return false;
for (s = qizmo_aliases; *s; s++)
{
if (!(alias = Cmd_FindAlias(*s)) || !(alias->flags & ALIAS_SERVER))
{
found = false;
break;
}
}
if (found)
return true;
found = true;
for (s = fteqtv_aliases; *s; s++)
{
if (!(alias = Cmd_FindAlias(*s)) || !(alias->flags & ALIAS_SERVER))
{
found = false; break;
}
}
return found;
}
void CL_Join_f (void)
{
qbool proxy;
proxy = cl_useproxy.value && CL_ConnectedToProxy();
if (Cmd_Argc() > 2)
{
Com_Printf ("Usage: %s [server]\n", Cmd_Argv(0));
return;
}
Cvar_Set(&spectator, "");
if (Cmd_Argc() == 2)