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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
|
/*
===========================================================================
Copyright (C) 1999-2005 Id Software, Inc.
Copyright (C) 2000-2009 Darklegion Development
This file is part of Tremulous.
Tremulous 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.
Tremulous 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 Tremulous; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
===========================================================================
*/
#include "client.h"
vm_t *uivm;
/*
====================
GetClientState
====================
*/
static void GetClientState( uiClientState_t *state ) {
state->connectPacketCount = clc.connectPacketCount;
state->connState = cls.state;
Q_strncpyz( state->servername, cls.servername, sizeof( state->servername ) );
Q_strncpyz( state->updateInfoString, cls.updateInfoString, sizeof( state->updateInfoString ) );
Q_strncpyz( state->messageString, clc.serverMessage, sizeof( state->messageString ) );
state->clientNum = cl.snap.ps.clientNum;
}
/*
====================
LAN_LoadCachedServers
====================
*/
void LAN_LoadCachedServers( void ) {
int size;
fileHandle_t fileIn;
cls.numglobalservers = cls.numfavoriteservers = 0;
cls.numGlobalServerAddresses = 0;
if (FS_SV_FOpenFileRead("servercache.dat", &fileIn)) {
FS_Read(&cls.numglobalservers, sizeof(int), fileIn);
FS_Read(&cls.numfavoriteservers, sizeof(int), fileIn);
FS_Read(&size, sizeof(int), fileIn);
if (size == sizeof(cls.globalServers) + sizeof(cls.favoriteServers)) {
FS_Read(&cls.globalServers, sizeof(cls.globalServers), fileIn);
FS_Read(&cls.favoriteServers, sizeof(cls.favoriteServers), fileIn);
} else {
cls.numglobalservers = cls.numfavoriteservers = 0;
cls.numGlobalServerAddresses = 0;
}
FS_FCloseFile(fileIn);
}
}
/*
====================
LAN_SaveServersToCache
====================
*/
void LAN_SaveServersToCache( void ) {
int size;
fileHandle_t fileOut = FS_SV_FOpenFileWrite("servercache.dat");
FS_Write(&cls.numglobalservers, sizeof(int), fileOut);
FS_Write(&cls.numfavoriteservers, sizeof(int), fileOut);
size = sizeof(cls.globalServers) + sizeof(cls.favoriteServers);
FS_Write(&size, sizeof(int), fileOut);
FS_Write(&cls.globalServers, sizeof(cls.globalServers), fileOut);
FS_Write(&cls.favoriteServers, sizeof(cls.favoriteServers), fileOut);
FS_FCloseFile(fileOut);
}
/*
====================
GetNews
====================
*/
qboolean GetNews( qboolean begin )
{
#ifdef USE_CURL
qboolean finished = qfalse;
fileHandle_t fileIn;
int readSize;
if( begin ) { // if not already using curl, start the download
if( !clc.downloadCURLM ) {
if(!CL_cURL_Init()) {
Cvar_Set( "cl_newsString", "^1Error: Could not load cURL library" );
return qtrue;
}
clc.activeCURLNotGameRelated = qtrue;
CL_cURL_BeginDownload("news.dat",
"http://tremulous.net/clientnews.txt");
return qfalse;
}
}
if ( !clc.downloadCURLM && FS_SV_FOpenFileRead("news.dat", &fileIn)) {
readSize = FS_Read(clc.newsString, sizeof( clc.newsString ), fileIn);
FS_FCloseFile(fileIn);
clc.newsString[ readSize ] = '\0';
if( readSize > 0 ) {
finished = qtrue;
clc.cURLUsed = qfalse;
CL_cURL_Shutdown();
clc.activeCURLNotGameRelated = qfalse;
}
}
if( !finished )
strcpy( clc.newsString, "Retrieving..." );
Cvar_Set( "cl_newsString", clc.newsString );
return finished;
#else
Cvar_Set( "cl_newsString",
"^1You must compile your client with CURL support to use this feature" );
return qtrue;
#endif
}
/*
====================
LAN_ResetPings
====================
*/
static void LAN_ResetPings(int source) {
int count,i;
serverInfo_t *servers = NULL;
count = 0;
switch (source) {
case AS_LOCAL :
servers = &cls.localServers[0];
count = MAX_OTHER_SERVERS;
break;
case AS_MPLAYER:
case AS_GLOBAL :
servers = &cls.globalServers[0];
count = MAX_GLOBAL_SERVERS;
break;
case AS_FAVORITES :
servers = &cls.favoriteServers[0];
count = MAX_OTHER_SERVERS;
break;
}
if (servers) {
for (i = 0; i < count; i++) {
servers[i].ping = -1;
}
}
}
/*
====================
LAN_AddServer
====================
*/
static int LAN_AddServer(int source, const char *name, const char *address) {
int max, *count, i;
netadr_t adr;
serverInfo_t *servers = NULL;
max = MAX_OTHER_SERVERS;
count = NULL;
switch (source) {
case AS_LOCAL :
count = &cls.numlocalservers;
servers = &cls.localServers[0];
break;
case AS_MPLAYER:
case AS_GLOBAL :
max = MAX_GLOBAL_SERVERS;
count = &cls.numglobalservers;
servers = &cls.globalServers[0];
break;
case AS_FAVORITES :
count = &cls.numfavoriteservers;
servers = &cls.favoriteServers[0];
break;
}
if (servers && *count < max) {
NET_StringToAdr( address, &adr, NA_IP );
for ( i = 0; i < *count; i++ ) {
if (NET_CompareAdr(servers[i].adr, adr)) {
break;
}
}
if (i >= *count) {
servers[*count].adr = adr;
Q_strncpyz(servers[*count].hostName, name, sizeof(servers[*count].hostName));
servers[*count].visible = qtrue;
(*count)++;
return 1;
}
return 0;
}
return -1;
}
/*
====================
LAN_RemoveServer
====================
*/
static void LAN_RemoveServer(int source, const char *addr) {
int *count, i;
serverInfo_t *servers = NULL;
count = NULL;
switch (source) {
case AS_LOCAL :
count = &cls.numlocalservers;
servers = &cls.localServers[0];
break;
case AS_MPLAYER:
case AS_GLOBAL :
count = &cls.numglobalservers;
servers = &cls.globalServers[0];
break;
case AS_FAVORITES :
count = &cls.numfavoriteservers;
servers = &cls.favoriteServers[0];
break;
}
if (servers) {
netadr_t comp;
NET_StringToAdr( addr, &comp, NA_IP );
for (i = 0; i < *count; i++) {
if (NET_CompareAdr( comp, servers[i].adr)) {
int j = i;
while (j < *count - 1) {
Com_Memcpy(&servers[j], &servers[j+1], sizeof(servers[j]));
j++;
}
(*count)--;
break;
}
}
}
}
/*
====================
LAN_GetServerCount
====================
*/
static int LAN_GetServerCount( int source ) {
switch (source) {
case AS_LOCAL :
return cls.numlocalservers;
break;
case AS_MPLAYER:
case AS_GLOBAL :
return cls.numglobalservers;
break;
case AS_FAVORITES :
return cls.numfavoriteservers;
break;
}
return 0;
}
/*
====================
LAN_GetLocalServerAddressString
====================
*/
static void LAN_GetServerAddressString( int source, int n, char *buf, int buflen ) {
switch (source) {
case AS_LOCAL :
if (n >= 0 && n < MAX_OTHER_SERVERS) {
Q_strncpyz(buf, NET_AdrToStringwPort( cls.localServers[n].adr) , buflen );
return;
}
break;
case AS_MPLAYER:
case AS_GLOBAL :
if (n >= 0 && n < MAX_GLOBAL_SERVERS) {
Q_strncpyz(buf, NET_AdrToStringwPort( cls.globalServers[n].adr) , buflen );
return;
}
break;
case AS_FAVORITES :
if (n >= 0 && n < MAX_OTHER_SERVERS) {
Q_strncpyz(buf, NET_AdrToStringwPort( cls.favoriteServers[n].adr) , buflen );
return;
}
break;
}
buf[0] = '\0';
}
/*
====================
LAN_GetServerInfo
====================
*/
static void LAN_GetServerInfo( int source, int n, char *buf, int buflen ) {
char info[MAX_STRING_CHARS];
serverInfo_t *server = NULL;
info[0] = '\0';
switch (source) {
case AS_LOCAL :
if (n >= 0 && n < MAX_OTHER_SERVERS) {
server = &cls.localServers[n];
}
break;
case AS_MPLAYER:
case AS_GLOBAL :
if (n >= 0 && n < MAX_GLOBAL_SERVERS) {
server = &cls.globalServers[n];
}
break;
case AS_FAVORITES :
if (n >= 0 && n < MAX_OTHER_SERVERS) {
server = &cls.favoriteServers[n];
}
break;
}
if (server && buf) {
buf[0] = '\0';
Info_SetValueForKey( info, "hostname", server->hostName);
Info_SetValueForKey( info, "mapname", server->mapName);
Info_SetValueForKey( info, "label", server->label);
Info_SetValueForKey( info, "clients", va("%i",server->clients));
Info_SetValueForKey( info, "sv_maxclients", va("%i",server->maxClients));
Info_SetValueForKey( info, "ping", va("%i",server->ping));
Info_SetValueForKey( info, "minping", va("%i",server->minPing));
Info_SetValueForKey( info, "maxping", va("%i",server->maxPing));
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_AdrToStringwPort(server->adr));
Q_strncpyz(buf, info, buflen);
} else {
if (buf) {
buf[0] = '\0';
}
}
}
/*
====================
LAN_GetServerPing
====================
*/
static int LAN_GetServerPing( int source, int n ) {
serverInfo_t *server = NULL;
switch (source) {
case AS_LOCAL :
if (n >= 0 && n < MAX_OTHER_SERVERS) {
server = &cls.localServers[n];
}
break;
case AS_MPLAYER:
case AS_GLOBAL :
if (n >= 0 && n < MAX_GLOBAL_SERVERS) {
server = &cls.globalServers[n];
}
break;
case AS_FAVORITES :
if (n >= 0 && n < MAX_OTHER_SERVERS) {
server = &cls.favoriteServers[n];
}
break;
}
if (server) {
return server->ping;
}
return -1;
}
/*
====================
LAN_GetServerPtr
====================
*/
static serverInfo_t *LAN_GetServerPtr( int source, int n ) {
switch (source) {
case AS_LOCAL :
if (n >= 0 && n < MAX_OTHER_SERVERS) {
return &cls.localServers[n];
}
break;
case AS_MPLAYER:
case AS_GLOBAL :
if (n >= 0 && n < MAX_GLOBAL_SERVERS) {
return &cls.globalServers[n];
}
break;
case AS_FAVORITES :
if (n >= 0 && n < MAX_OTHER_SERVERS) {
return &cls.favoriteServers[n];
}
break;
}
return NULL;
}
#define FEATURED_MAXPING 200
/*
====================
LAN_CompareServers
====================
*/
static int LAN_CompareServers( int source, int sortKey, int sortDir, int s1, int s2 ) {
int res;
serverInfo_t *server1, *server2;
server1 = LAN_GetServerPtr(source, s1);
server2 = LAN_GetServerPtr(source, s2);
if (!server1 || !server2) {
return 0;
}
// featured servers on top
if( ( server1->label[ 0 ] && server1->ping <= FEATURED_MAXPING ) ||
( server2->label[ 0 ] && server2->ping <= FEATURED_MAXPING ) ) {
res = Q_stricmpn( server1->label, server2->label, MAX_FEATLABEL_CHARS );
if( res )
return -res;
}
res = 0;
switch( sortKey ) {
case SORT_HOST:
{
char hostName1[ MAX_HOSTNAME_LENGTH ];
char hostName2[ MAX_HOSTNAME_LENGTH ];
char *p;
int i;
for( p = server1->hostName, i = 0; *p != '\0'; p++ )
{
if( Q_isalpha( *p ) )
hostName1[ i++ ] = *p;
}
hostName1[ i ] = '\0';
for( p = server2->hostName, i = 0; *p != '\0'; p++ )
{
if( Q_isalpha( *p ) )
hostName2[ i++ ] = *p;
}
hostName2[ i ] = '\0';
res = Q_stricmp( hostName1, hostName2 );
}
break;
case SORT_GAME:
res = Q_stricmp( server1->game, server2->game );
break;
case SORT_MAP:
res = Q_stricmp( server1->mapName, server2->mapName );
break;
case SORT_CLIENTS:
if (server1->clients < server2->clients) {
res = -1;
}
else if (server1->clients > server2->clients) {
res = 1;
}
else {
res = 0;
}
break;
case SORT_PING:
if (server1->ping < server2->ping) {
res = -1;
}
else if (server1->ping > server2->ping) {
res = 1;
}
else {
res = 0;
}
break;
}
if (sortDir) {
if (res < 0)
return 1;
if (res > 0)
return -1;
return 0;
}
return res;
}
/*
====================
LAN_GetPingQueueCount
====================
*/
static int LAN_GetPingQueueCount( void ) {
return (CL_GetPingQueueCount());
}
/*
====================
LAN_ClearPing
====================
*/
static void LAN_ClearPing( int n ) {
CL_ClearPing( n );
}
/*
====================
LAN_GetPing
====================
*/
static void LAN_GetPing( int n, char *buf, int buflen, int *pingtime ) {
CL_GetPing( n, buf, buflen, pingtime );
}
/*
====================
LAN_GetPingInfo
====================
*/
static void LAN_GetPingInfo( int n, char *buf, int buflen ) {
CL_GetPingInfo( n, buf, buflen );
}
/*
====================
LAN_MarkServerVisible
====================
*/
static void LAN_MarkServerVisible(int source, int n, qboolean visible ) {
if (n == -1) {
int count = MAX_OTHER_SERVERS;
serverInfo_t *server = NULL;
switch (source) {
case AS_LOCAL :
server = &cls.localServers[0];
break;
case AS_MPLAYER:
case AS_GLOBAL :
server = &cls.globalServers[0];
count = MAX_GLOBAL_SERVERS;
break;
case AS_FAVORITES :
server = &cls.favoriteServers[0];
break;
}
if (server) {
for (n = 0; n < count; n++) {
server[n].visible = visible;
}
}
} else {
switch (source) {
case AS_LOCAL :
if (n >= 0 && n < MAX_OTHER_SERVERS) {
cls.localServers[n].visible = visible;
}
break;
case AS_MPLAYER:
case AS_GLOBAL :
if (n >= 0 && n < MAX_GLOBAL_SERVERS) {
cls.globalServers[n].visible = visible;
}
break;
case AS_FAVORITES :
if (n >= 0 && n < MAX_OTHER_SERVERS) {
cls.favoriteServers[n].visible = visible;
}
break;
}
}
}
/*
=======================
LAN_ServerIsVisible
=======================
*/
static int LAN_ServerIsVisible(int source, int n ) {
switch (source) {
case AS_LOCAL :
if (n >= 0 && n < MAX_OTHER_SERVERS) {
return cls.localServers[n].visible;
}
break;
case AS_MPLAYER:
case AS_GLOBAL :
if (n >= 0 && n < MAX_GLOBAL_SERVERS) {
return cls.globalServers[n].visible;
}
break;
case AS_FAVORITES :
if (n >= 0 && n < MAX_OTHER_SERVERS) {
return cls.favoriteServers[n].visible;
}
break;
}
return qfalse;
}
/*
=======================
LAN_UpdateVisiblePings
=======================
*/
qboolean LAN_UpdateVisiblePings(int source ) {
return CL_UpdateVisiblePings_f(source);
}
/*
====================
LAN_GetServerStatus
====================
*/
int LAN_GetServerStatus( char *serverAddress, char *serverStatus, int maxLen ) {
return CL_ServerStatus( serverAddress, serverStatus, maxLen );
}
/*
====================
CL_GetGlConfig
====================
*/
static void CL_GetGlconfig( glconfig_t *config ) {
*config = cls.glconfig;
}
/*
====================
CL_GetClipboardData
====================
*/
static void CL_GetClipboardData( char *buf, int buflen ) {
char *cbd;
cbd = Sys_GetClipboardData();
if ( !cbd ) {
*buf = 0;
return;
}
Q_strncpyz( buf, cbd, buflen );
Z_Free( cbd );
}
/*
====================
GetConfigString
====================
*/
static int GetConfigString(int index, char *buf, int size)
{
int offset;
if (index < 0 || index >= MAX_CONFIGSTRINGS)
return qfalse;
offset = cl.gameState.stringOffsets[index];
if (!offset) {
if( size ) {
buf[0] = 0;
}
return qfalse;
}
Q_strncpyz( buf, cl.gameState.stringData+offset, size);
return qtrue;
}
/*
====================
FloatAsInt
====================
*/
static int FloatAsInt( float f ) {
floatint_t fi;
fi.f = f;
return fi.i;
}
/*
====================
CL_UISystemCalls
The ui module is making a system call
====================
*/
intptr_t CL_UISystemCalls( intptr_t *args ) {
switch( args[0] ) {
case UI_ERROR:
Com_Error( ERR_DROP, "%s", (const char*)VMA(1) );
return 0;
case UI_PRINT:
Com_Printf( "%s", (const char*)VMA(1) );
return 0;
case UI_MILLISECONDS:
return Sys_Milliseconds();
case UI_CVAR_REGISTER:
Cvar_Register( VMA(1), VMA(2), VMA(3), args[4] );
return 0;
case UI_CVAR_UPDATE:
Cvar_Update( VMA(1) );
return 0;
case UI_CVAR_SET:
Cvar_Set( VMA(1), VMA(2) );
return 0;
case UI_CVAR_VARIABLEVALUE:
return FloatAsInt( Cvar_VariableValue( VMA(1) ) );
case UI_CVAR_VARIABLESTRINGBUFFER:
Cvar_VariableStringBuffer( VMA(1), VMA(2), args[3] );
return 0;
case UI_CVAR_SETVALUE:
Cvar_SetValue( VMA(1), VMF(2) );
return 0;
case UI_CVAR_RESET:
Cvar_Reset( VMA(1) );
return 0;
case UI_CVAR_CREATE:
Cvar_Get( VMA(1), VMA(2), args[3] );
return 0;
case UI_CVAR_INFOSTRINGBUFFER:
Cvar_InfoStringBuffer( args[1], VMA(2), args[3] );
return 0;
case UI_ARGC:
return Cmd_Argc();
case UI_ARGV:
Cmd_ArgvBuffer( args[1], VMA(2), args[3] );
return 0;
case UI_CMD_EXECUTETEXT:
if(args[1] == 0
&& (!strncmp(VMA(2), "snd_restart", 11)
|| !strncmp(VMA(2), "vid_restart", 11)
|| !strncmp(VMA(2), "quit", 5)))
{
Com_Printf (S_COLOR_YELLOW "turning EXEC_NOW '%.11s' into EXEC_INSERT\n", (const char*)VMA(2));
args[1] = EXEC_INSERT;
}
Cbuf_ExecuteText( args[1], VMA(2) );
return 0;
case UI_FS_FOPENFILE:
return FS_FOpenFileByMode( VMA(1), VMA(2), args[3] );
case UI_FS_READ:
FS_Read2( VMA(1), args[2], args[3] );
return 0;
case UI_FS_WRITE:
FS_Write( VMA(1), args[2], args[3] );
return 0;
case UI_FS_FCLOSEFILE:
FS_FCloseFile( args[1] );
return 0;
case UI_FS_GETFILELIST:
return FS_GetFileList( VMA(1), VMA(2), VMA(3), args[4] );
case UI_FS_SEEK:
return FS_Seek( args[1], args[2], args[3] );
case UI_R_REGISTERMODEL:
return re.RegisterModel( VMA(1) );
case UI_R_REGISTERSKIN:
return re.RegisterSkin( VMA(1) );
case UI_R_REGISTERSHADERNOMIP:
return re.RegisterShaderNoMip( VMA(1) );
case UI_R_CLEARSCENE:
re.ClearScene();
return 0;
case UI_R_ADDREFENTITYTOSCENE:
re.AddRefEntityToScene( VMA(1) );
return 0;
case UI_R_ADDPOLYTOSCENE:
re.AddPolyToScene( args[1], args[2], VMA(3), 1 );
return 0;
case UI_R_ADDLIGHTTOSCENE:
re.AddLightToScene( VMA(1), VMF(2), VMF(3), VMF(4), VMF(5) );
return 0;
case UI_R_RENDERSCENE:
re.RenderScene( VMA(1) );
return 0;
case UI_R_SETCOLOR:
re.SetColor( VMA(1) );
return 0;
case UI_R_SETCLIPREGION:
re.SetClipRegion( VMA(1) );
return 0;
case UI_R_DRAWSTRETCHPIC:
re.DrawStretchPic( VMF(1), VMF(2), VMF(3), VMF(4), VMF(5), VMF(6), VMF(7), VMF(8), args[9] );
return 0;
case UI_R_MODELBOUNDS:
re.ModelBounds( args[1], VMA(2), VMA(3) );
return 0;
case UI_UPDATESCREEN:
SCR_UpdateScreen();
return 0;
case UI_CM_LERPTAG:
re.LerpTag( VMA(1), args[2], args[3], args[4], VMF(5), VMA(6) );
return 0;
case UI_S_REGISTERSOUND:
return S_RegisterSound( VMA(1), args[2] );
case UI_S_STARTLOCALSOUND:
S_StartLocalSound( args[1], args[2] );
return 0;
case UI_KEY_KEYNUMTOSTRINGBUF:
Key_KeynumToStringBuf( args[1], VMA(2), args[3] );
return 0;
case UI_KEY_GETBINDINGBUF:
Key_GetBindingBuf( args[1], VMA(2), args[3] );
return 0;
case UI_KEY_SETBINDING:
Key_SetBinding( args[1], VMA(2) );
return 0;
case UI_KEY_ISDOWN:
return Key_IsDown( args[1] );
case UI_KEY_GETOVERSTRIKEMODE:
return Key_GetOverstrikeMode();
case UI_KEY_SETOVERSTRIKEMODE:
Key_SetOverstrikeMode( args[1] );
return 0;
case UI_KEY_CLEARSTATES:
Key_ClearStates();
return 0;
case UI_KEY_GETCATCHER:
return Key_GetCatcher();
case UI_KEY_SETCATCHER:
// Don't allow the ui module to close the console
Key_SetCatcher( args[1] | ( Key_GetCatcher( ) & KEYCATCH_CONSOLE ) );
return 0;
case UI_GETCLIPBOARDDATA:
CL_GetClipboardData( VMA(1), args[2] );
return 0;
case UI_GETCLIENTSTATE:
GetClientState( VMA(1) );
return 0;
case UI_GETGLCONFIG:
CL_GetGlconfig( VMA(1) );
return 0;
case UI_GETCONFIGSTRING:
return GetConfigString( args[1], VMA(2), args[3] );
case UI_LAN_LOADCACHEDSERVERS:
LAN_LoadCachedServers();
return 0;
case UI_LAN_SAVECACHEDSERVERS:
LAN_SaveServersToCache();
return 0;
case UI_LAN_ADDSERVER:
return LAN_AddServer(args[1], VMA(2), VMA(3));
case UI_LAN_REMOVESERVER:
LAN_RemoveServer(args[1], VMA(2));
return 0;
case UI_LAN_GETPINGQUEUECOUNT:
return LAN_GetPingQueueCount();
case UI_LAN_CLEARPING:
LAN_ClearPing( args[1] );
return 0;
case UI_LAN_GETPING:
LAN_GetPing( args[1], VMA(2), args[3], VMA(4) );
return 0;
case UI_LAN_GETPINGINFO:
LAN_GetPingInfo( args[1], VMA(2), args[3] );
return 0;
case UI_LAN_GETSERVERCOUNT:
return LAN_GetServerCount(args[1]);
case UI_LAN_GETSERVERADDRESSSTRING:
LAN_GetServerAddressString( args[1], args[2], VMA(3), args[4] );
return 0;
case UI_LAN_GETSERVERINFO:
LAN_GetServerInfo( args[1], args[2], VMA(3), args[4] );
return 0;
case UI_LAN_GETSERVERPING:
return LAN_GetServerPing( args[1], args[2] );
case UI_LAN_MARKSERVERVISIBLE:
LAN_MarkServerVisible( args[1], args[2], args[3] );
return 0;
case UI_LAN_SERVERISVISIBLE:
return LAN_ServerIsVisible( args[1], args[2] );
case UI_LAN_UPDATEVISIBLEPINGS:
return LAN_UpdateVisiblePings( args[1] );
case UI_LAN_RESETPINGS:
LAN_ResetPings( args[1] );
return 0;
case UI_LAN_SERVERSTATUS:
return LAN_GetServerStatus( VMA(1), VMA(2), args[3] );
case UI_GETNEWS:
return GetNews( args[1] );
case UI_LAN_COMPARESERVERS:
return LAN_CompareServers( args[1], args[2], args[3], args[4], args[5] );
case UI_MEMORY_REMAINING:
return Hunk_MemoryRemaining();
case UI_SET_PBCLSTATUS:
return 0;
case UI_R_REGISTERFONT:
re.RegisterFont( VMA(1), args[2], VMA(3));
return 0;
case UI_MEMSET:
Com_Memset( VMA(1), args[2], args[3] );
return 0;
case UI_MEMCPY:
Com_Memcpy( VMA(1), VMA(2), args[3] );
return 0;
case UI_STRNCPY:
strncpy( VMA(1), VMA(2), args[3] );
return args[1];
case UI_SIN:
return FloatAsInt( sin( VMF(1) ) );
case UI_COS:
return FloatAsInt( cos( VMF(1) ) );
case UI_ATAN2:
return FloatAsInt( atan2( VMF(1), VMF(2) ) );
case UI_SQRT:
return FloatAsInt( sqrt( VMF(1) ) );
case UI_FLOOR:
return FloatAsInt( floor( VMF(1) ) );
case UI_CEIL:
return FloatAsInt( ceil( VMF(1) ) );
case UI_PARSE_ADD_GLOBAL_DEFINE:
return Parse_AddGlobalDefine( VMA(1) );
case UI_PARSE_LOAD_SOURCE:
return Parse_LoadSourceHandle( VMA(1) );
case UI_PARSE_FREE_SOURCE:
return Parse_FreeSourceHandle( args[1] );
case UI_PARSE_READ_TOKEN:
return Parse_ReadTokenHandle( args[1], VMA(2) );
case UI_PARSE_SOURCE_FILE_AND_LINE:
return Parse_SourceFileAndLine( args[1], VMA(2), VMA(3) );
case UI_S_STOPBACKGROUNDTRACK:
S_StopBackgroundTrack();
return 0;
case UI_S_STARTBACKGROUNDTRACK:
S_StartBackgroundTrack( VMA(1), VMA(2));
return 0;
case UI_REAL_TIME:
return Com_RealTime( VMA(1) );
case UI_CIN_PLAYCINEMATIC:
Com_DPrintf("UI_CIN_PlayCinematic\n");
return CIN_PlayCinematic(VMA(1), args[2], args[3], args[4], args[5], args[6]);
case UI_CIN_STOPCINEMATIC:
return CIN_StopCinematic(args[1]);
case UI_CIN_RUNCINEMATIC:
return CIN_RunCinematic(args[1]);
case UI_CIN_DRAWCINEMATIC:
CIN_DrawCinematic(args[1]);
return 0;
case UI_CIN_SETEXTENTS:
CIN_SetExtents(args[1], args[2], args[3], args[4], args[5]);
return 0;
case UI_R_REMAP_SHADER:
re.RemapShader( VMA(1), VMA(2), VMA(3) );
return 0;
default:
Com_Error( ERR_DROP, "Bad UI system trap: %ld", (long int) args[0] );
}
return 0;
}
/*
====================
CL_ShutdownUI
====================
*/
void CL_ShutdownUI( void ) {
Key_SetCatcher( Key_GetCatcher( ) & ~KEYCATCH_UI );
cls.uiStarted = qfalse;
if ( !uivm ) {
return;
}
VM_Call( uivm, UI_SHUTDOWN );
VM_Free( uivm );
uivm = NULL;
}
/*
====================
CL_InitUI
====================
*/
#define UI_OLD_API_VERSION 4
void CL_InitUI( void ) {
int v;
vmInterpret_t interpret;
// load the dll or bytecode
if ( cl_connectedToPureServer != 0 ) {
// if sv_pure is set we only allow qvms to be loaded
interpret = VMI_COMPILED;
}
else {
interpret = Cvar_VariableValue( "vm_ui" );
}
uivm = VM_Create( "ui", CL_UISystemCalls, interpret );
if ( !uivm ) {
Com_Printf( "Failed to find a valid UI vm. The following paths were searched:\n" );
Cmd_ExecuteString( "path /\n" );
Com_Error( ERR_FATAL, "VM_Create on UI failed" );
}
// sanity check
v = VM_Call( uivm, UI_GETAPIVERSION );
if (v == UI_OLD_API_VERSION) {
// init for this gamestate
VM_Call( uivm, UI_INIT, (cls.state >= CA_AUTHORIZING && cls.state < CA_ACTIVE));
}
else if (v != UI_API_VERSION) {
Com_Error( ERR_DROP, "User Interface is version %d, expected %d", v, UI_API_VERSION );
cls.uiStarted = qfalse;
}
else {
// init for this gamestate
VM_Call( uivm, UI_INIT, (cls.state >= CA_AUTHORIZING && cls.state < CA_ACTIVE) );
// show where the ui folder was loaded from
Cmd_ExecuteString( "which ui/\n" );
}
// reset any CVAR_CHEAT cvars registered by ui
if ( !clc.demoplaying && !cl_connectedToCheatServer )
Cvar_SetCheatState();
clc.newsString[ 0 ] = '\0';
}
/*
====================
UI_GameCommand
See if the current console command is claimed by the ui
====================
*/
qboolean UI_GameCommand( void ) {
if ( !uivm ) {
return qfalse;
}
return VM_Call( uivm, UI_CONSOLE_COMMAND, cls.realtime );
}
|