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
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $Workfile: $
// $NoKeywords: $
//===========================================================================//
#include "server_pch.h"
#include "tier0/valve_minmax_off.h"
#include <algorithm>
#include "tier0/valve_minmax_on.h"
#include "vengineserver_impl.h"
#include "vox.h"
#include "sound.h"
#include "gl_model_private.h"
#include "host_saverestore.h"
#include "world.h"
#include "l_studio.h"
#include "decal.h"
#include "sys_dll.h"
#include "sv_log.h"
#include "sv_main.h"
#include "tier1/strtools.h"
#include "collisionutils.h"
#include "staticpropmgr.h"
#include "string_t.h"
#include "vstdlib/random.h"
#include "EngineSoundInternal.h"
#include "dt_send_eng.h"
#include "PlayerState.h"
#include "irecipientfilter.h"
#include "sv_user.h"
#include "server_class.h"
#include "cdll_engine_int.h"
#include "enginesingleuserfilter.h"
#include "ispatialpartitioninternal.h"
#include "con_nprint.h"
#include "tmessage.h"
#include "iscratchpad3d.h"
#include "pr_edict.h"
#include "networkstringtableserver.h"
#include "networkstringtable.h"
#include "LocalNetworkBackdoor.h"
#include "host_phonehome.h"
#include "matchmaking.h"
#include "sv_plugin.h"
#include "sv_steamauth.h"
#include "replay_internal.h"
#include "replayserver.h"
#include "replay/iserverengine.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
#define MAX_MESSAGE_SIZE 2500
#define MAX_TOTAL_ENT_LEAFS 128
void SV_DetermineMulticastRecipients( bool usepas, const Vector& origin, CBitVec< ABSOLUTE_PLAYER_LIMIT >& playerbits );
int MapList_ListMaps( const char *pszSubString, bool listobsolete, bool verbose, int maxcount, int maxitemlength, char maplist[][ 64 ] );
extern CNetworkStringTableContainer *networkStringTableContainerServer;
CSharedEdictChangeInfo g_SharedEdictChangeInfo;
CSharedEdictChangeInfo *g_pSharedChangeInfo = &g_SharedEdictChangeInfo;
IAchievementMgr *g_pAchievementMgr = NULL;
CGamestatsData *g_pGamestatsData = NULL;
void InvalidateSharedEdictChangeInfos()
{
if ( g_SharedEdictChangeInfo.m_iSerialNumber == 0xFFFF )
{
// Reset all edicts to 0.
g_SharedEdictChangeInfo.m_iSerialNumber = 1;
for ( int i=0; i < sv.num_edicts; i++ )
sv.edicts[i].SetChangeInfoSerialNumber( 0 );
}
else
{
g_SharedEdictChangeInfo.m_iSerialNumber++;
}
g_SharedEdictChangeInfo.m_nChangeInfos = 0;
}
// ---------------------------------------------------------------------- //
// Globals.
// ---------------------------------------------------------------------- //
struct MsgData
{
MsgData()
{
Reset();
// link buffers to messages
entityMsg.m_DataOut.StartWriting( entitydata, sizeof(entitydata) );
entityMsg.m_DataOut.SetDebugName( "s_MsgData.entityMsg.m_DataOut" );
userMsg.m_DataOut.StartWriting( userdata, sizeof(userdata) );
userMsg.m_DataOut.SetDebugName( "s_MsgData.userMsg.m_DataOut" );
}
void Reset()
{
filter = NULL;
reliable = false;
subtype = 0;
started = false;
usermessagesize = -1;
usermessagename = NULL;
currentMsg = NULL;
}
byte userdata[ PAD_NUMBER( MAX_USER_MSG_DATA, 4 ) ]; // buffer for outgoing user messages
byte entitydata[ PAD_NUMBER( MAX_ENTITY_MSG_DATA, 4 ) ]; // buffer for outgoing entity messages
IRecipientFilter *filter; // clients who get this message
bool reliable;
INetMessage *currentMsg; // pointer to entityMsg or userMessage
int subtype; // usermessage index
bool started; // IS THERE A MESSAGE IN THE PROCESS OF BEING SENT?
int usermessagesize;
char const *usermessagename;
SVC_EntityMessage entityMsg;
SVC_UserMessage userMsg;
};
static MsgData s_MsgData;
void SeedRandomNumberGenerator( bool random_invariant )
{
if (!random_invariant)
{
long iSeed;
g_pVCR->Hook_Time( &iSeed );
float flAppTime = Plat_FloatTime();
ThreadId_t threadId = ThreadGetCurrentId();
iSeed ^= (*((int *)&flAppTime));
iSeed ^= threadId;
RandomSeed( iSeed );
}
else
{
// Make those random numbers the same every time!
RandomSeed( 0 );
}
}
// ---------------------------------------------------------------------- //
// Static helpers.
// ---------------------------------------------------------------------- //
static void PR_CheckEmptyString (const char *s)
{
if (s[0] <= ' ')
Host_Error ("Bad string: %s", s);
}
// Average a list a vertices to find an approximate "center"
static void CenterVerts( Vector verts[], int vertCount, Vector& center )
{
int i;
float scale;
if ( vertCount )
{
Vector edge0, edge1, normal;
VectorCopy( vec3_origin, center );
// sum up verts
for ( i = 0; i < vertCount; i++ )
{
VectorAdd( center, verts[i], center );
}
scale = 1.0f / (float)vertCount;
VectorScale( center, scale, center ); // divide by vertCount
// Compute 2 poly edges
VectorSubtract( verts[1], verts[0], edge0 );
VectorSubtract( verts[vertCount-1], verts[0], edge1 );
// cross for normal
CrossProduct( edge0, edge1, normal );
// Find the component of center that is outside of the plane
scale = DotProduct( center, normal ) - DotProduct( verts[0], normal );
// subtract it off
VectorMA( center, scale, normal, center );
// center is in the plane now
}
}
// Copy the list of verts from an msurface_t int a linear array
static void SurfaceToVerts( model_t *model, SurfaceHandle_t surfID, Vector verts[], int *vertCount )
{
if ( *vertCount > MSurf_VertCount( surfID ) )
*vertCount = MSurf_VertCount( surfID );
// Build the list of verts from 0 to n
for ( int i = 0; i < *vertCount; i++ )
{
int vertIndex = model->brush.pShared->vertindices[ MSurf_FirstVertIndex( surfID ) + i ];
Vector& vert = model->brush.pShared->vertexes[ vertIndex ].position;
VectorCopy( vert, verts[i] );
}
// vert[0] is the first and last vert, there is no copy
}
// Calculate the surface area of an arbitrary msurface_t polygon (convex with collinear verts)
static float SurfaceArea( model_t *model, SurfaceHandle_t surfID )
{
Vector center, verts[32];
int vertCount = 32;
float area;
int i;
// Compute a "center" point and fan
SurfaceToVerts( model, surfID, verts, &vertCount );
CenterVerts( verts, vertCount, center );
area = 0;
// For a triangle of the center and each edge
for ( i = 0; i < vertCount; i++ )
{
Vector edge0, edge1, out;
int next;
next = (i+1)%vertCount;
VectorSubtract( verts[i], center, edge0 ); // 0.5 * edge cross edge (0.5 is done once at the end)
VectorSubtract( verts[next], center, edge1 );
CrossProduct( edge0, edge1, out );
area += VectorLength( out );
}
return area * 0.5; // 0.5 here
}
// Average the list of vertices to find an approximate "center"
static void SurfaceCenter( model_t *model, SurfaceHandle_t surfID, Vector& center )
{
Vector verts[32]; // We limit faces to 32 verts elsewhere in the engine
int vertCount = 32;
SurfaceToVerts( model, surfID, verts, &vertCount );
CenterVerts( verts, vertCount, center );
}
static bool ValidCmd( const char *pCmd )
{
int len;
len = strlen(pCmd);
// Valid commands all have a ';' or newline '\n' as their last character
if ( len && (pCmd[len-1] == '\n' || pCmd[len-1] == ';') )
return true;
return false;
}
// ---------------------------------------------------------------------- //
// CVEngineServer
// ---------------------------------------------------------------------- //
class CVEngineServer : public IVEngineServer
{
public:
virtual void ChangeLevel( const char* s1, const char* s2)
{
if ( !s1 )
{
Sys_Error( "CVEngineServer::Changelevel with NULL s1\n" );
}
char cmd[ 256 ];
char s1Escaped[ sizeof( cmd ) ];
char s2Escaped[ sizeof( cmd ) ];
if ( !Cbuf_EscapeCommandArg( s1, s1Escaped, sizeof( s1Escaped ) ) ||
( s2 && !Cbuf_EscapeCommandArg( s2, s2Escaped, sizeof( s2Escaped ) )))
{
Warning( "Illegal map name in ChangeLevel\n" );
return;
}
int cmdLen = 0;
if ( !s2 ) // no indication of where they are coming from; so just do a standard old changelevel
{
cmdLen = Q_snprintf( cmd, sizeof( cmd ), "changelevel %s\n", s1Escaped );
}
else
{
cmdLen = Q_snprintf( cmd, sizeof( cmd ), "changelevel2 %s %s\n", s1Escaped, s2Escaped );
}
if ( !cmdLen || cmdLen >= sizeof( cmd ) )
{
Warning( "Paramter overflow in ChangeLevel\n" );
return;
}
Cbuf_AddText( cmd );
}
virtual int IsMapValid( const char *filename )
{
return modelloader->Map_IsValid( filename );
}
virtual bool IsDedicatedServer( void )
{
return sv.IsDedicated();
}
virtual int IsInEditMode( void )
{
#ifdef SWDS
return false;
#else
return g_bInEditMode;
#endif
}
virtual int IsInCommentaryMode( void )
{
#ifdef SWDS
return false;
#else
return g_bInCommentaryMode;
#endif
}
virtual void NotifyEdictFlagsChange( int iEdict )
{
if ( g_pLocalNetworkBackdoor )
g_pLocalNetworkBackdoor->NotifyEdictFlagsChange( iEdict );
}
virtual const CCheckTransmitInfo* GetPrevCheckTransmitInfo( edict_t *pPlayerEdict )
{
int entnum = NUM_FOR_EDICT( pPlayerEdict );
if ( entnum < 1 || entnum > sv.GetClientCount() )
{
Error( "Invalid client specified in GetPrevCheckTransmitInfo\n" );
return NULL;
}
CGameClient *client = sv.Client( entnum-1 );
return client->GetPrevPackInfo();
}
virtual int PrecacheDecal( const char *name, bool preload /*=false*/ )
{
PR_CheckEmptyString( name );
int i = SV_FindOrAddDecal( name, preload );
if ( i >= 0 )
{
return i;
}
Host_Error( "CVEngineServer::PrecacheDecal: '%s' overflow, too many decals", name );
return 0;
}
virtual int PrecacheModel( const char *s, bool preload /*= false*/ )
{
PR_CheckEmptyString (s);
int i = SV_FindOrAddModel( s, preload );
if ( i >= 0 )
{
return i;
}
Host_Error( "CVEngineServer::PrecacheModel: '%s' overflow, too many models", s );
return 0;
}
virtual int PrecacheGeneric(const char *s, bool preload /*= false*/ )
{
int i;
PR_CheckEmptyString (s);
i = SV_FindOrAddGeneric( s, preload );
if (i >= 0)
{
return i;
}
Host_Error ("CVEngineServer::PrecacheGeneric: '%s' overflow", s);
return 0;
}
virtual bool IsModelPrecached( char const *s ) const
{
int idx = SV_ModelIndex( s );
return idx != -1 ? true : false;
}
virtual bool IsDecalPrecached( char const *s ) const
{
int idx = SV_DecalIndex( s );
return idx != -1 ? true : false;
}
virtual bool IsGenericPrecached( char const *s ) const
{
int idx = SV_GenericIndex( s );
return idx != -1 ? true : false;
}
virtual void ForceExactFile( const char *s )
{
Warning( "ForceExactFile no longer supported. Use sv_pure instead. (%s)\n", s );
}
virtual void ForceModelBounds( const char *s, const Vector &mins, const Vector &maxs )
{
PR_CheckEmptyString( s );
SV_ForceModelBounds( s, mins, maxs );
}
virtual void ForceSimpleMaterial( const char *s )
{
PR_CheckEmptyString( s );
SV_ForceSimpleMaterial( s );
}
virtual bool IsInternalBuild( void )
{
return !phonehome->IsExternalBuild();
}
//-----------------------------------------------------------------------------
// Purpose: Precache a sentence file (parse on server, send to client)
// Input : *s - file name
//-----------------------------------------------------------------------------
virtual int PrecacheSentenceFile( const char *s, bool preload /*= false*/ )
{
// UNDONE: Set up preload flag
// UNDONE: Send this data to the client to support multiple sentence files
VOX_ReadSentenceFile( s );
return 0;
}
//-----------------------------------------------------------------------------
// Purpose: Retrieves the pvs for an origin into the specified array
// Input : *org - origin
// outputpvslength - size of outputpvs array in bytes
// *outputpvs - If null, then return value is the needed length
// Output : int - length of pvs array used ( in bytes )
//-----------------------------------------------------------------------------
virtual int GetClusterForOrigin( const Vector& org )
{
return CM_LeafCluster( CM_PointLeafnum( org ) );
}
virtual int GetPVSForCluster( int clusterIndex, int outputpvslength, unsigned char *outputpvs )
{
int length = (CM_NumClusters()+7)>>3;
if ( outputpvs )
{
if ( outputpvslength < length )
{
Sys_Error( "GetPVSForOrigin called with inusfficient sized pvs array, need %i bytes!", length );
return length;
}
CM_Vis( outputpvs, outputpvslength, clusterIndex, DVIS_PVS );
}
return length;
}
//-----------------------------------------------------------------------------
// Purpose: Test origin against pvs array retreived from GetPVSForOrigin
// Input : *org - origin to chec
// checkpvslength - length of pvs array
// *checkpvs -
// Output : bool - true if entity is visible
//-----------------------------------------------------------------------------
virtual bool CheckOriginInPVS( const Vector& org, const unsigned char *checkpvs, int checkpvssize )
{
int clusterIndex = CM_LeafCluster( CM_PointLeafnum( org ) );
if ( clusterIndex < 0 )
return false;
int offset = clusterIndex>>3;
if ( offset > checkpvssize )
{
Sys_Error( "CheckOriginInPVS: cluster would read past end of pvs data (%i:%i)\n",
offset, checkpvssize );
return false;
}
if ( !(checkpvs[offset] & (1<<(clusterIndex&7)) ) )
{
return false;
}
return true;
}
//-----------------------------------------------------------------------------
// Purpose: Test origin against pvs array retreived from GetPVSForOrigin
// Input : *org - origin to chec
// checkpvslength - length of pvs array
// *checkpvs -
// Output : bool - true if entity is visible
//-----------------------------------------------------------------------------
virtual bool CheckBoxInPVS( const Vector& mins, const Vector& maxs, const unsigned char *checkpvs, int checkpvssize )
{
if ( !CM_BoxVisible( mins, maxs, checkpvs, checkpvssize ) )
{
return false;
}
return true;
}
virtual int GetPlayerUserId( const edict_t *e )
{
if ( !sv.IsActive() || !e)
return -1;
for ( int i = 0; i < sv.GetClientCount(); i++ )
{
CGameClient *pClient = sv.Client(i);
if ( pClient->edict == e )
{
return pClient->m_UserID;
}
}
// Couldn't find it
return -1;
}
virtual const char *GetPlayerNetworkIDString( const edict_t *e )
{
if ( !sv.IsActive() || !e)
return NULL;
for ( int i = 0; i < sv.GetClientCount(); i++ )
{
CGameClient *pGameClient = sv.Client(i);
if ( pGameClient->edict == e )
{
return pGameClient->GetNetworkIDString();
}
}
// Couldn't find it
return NULL;
}
virtual bool IsPlayerNameLocked( const edict_t *pEdict )
{
if ( !sv.IsActive() || !pEdict )
return false;
for ( int i = 0; i < sv.GetClientCount(); i++ )
{
CGameClient *pClient = sv.Client( i );
if ( pClient->edict == pEdict )
{
return pClient->IsPlayerNameLocked();
}
}
return false;
}
virtual bool CanPlayerChangeName( const edict_t *pEdict )
{
if ( !sv.IsActive() || !pEdict )
return false;
for ( int i = 0; i < sv.GetClientCount(); i++ )
{
CGameClient *pClient = sv.Client( i );
if ( pClient->edict == pEdict )
{
return ( !pClient->IsPlayerNameLocked() && !pClient->IsNameChangeOnCooldown() );
}
}
return false;
}
// See header comment. This is the canonical map lookup spot, and a superset of the server gameDLL's
// CanProvideLevel/PrepareLevelResources
virtual eFindMapResult FindMap( /* in/out */ char *pMapName, int nMapNameMax )
{
char szOriginalName[256] = { 0 };
V_strncpy( szOriginalName, pMapName, sizeof( szOriginalName ) );
IServerGameDLL::eCanProvideLevelResult eCanGameDLLProvide = IServerGameDLL::eCanProvideLevel_CannotProvide;
if ( g_iServerGameDLLVersion >= 10 )
{
eCanGameDLLProvide = serverGameDLL->CanProvideLevel( pMapName, nMapNameMax );
}
if ( eCanGameDLLProvide == IServerGameDLL::eCanProvideLevel_Possibly )
{
return eFindMap_PossiblyAvailable;
}
else if ( eCanGameDLLProvide == IServerGameDLL::eCanProvideLevel_CanProvide )
{
// See if the game dll fixed up the map name
return ( V_strcmp( szOriginalName, pMapName ) == 0 ) ? eFindMap_Found : eFindMap_NonCanonical;
}
AssertMsg( eCanGameDLLProvide == IServerGameDLL::eCanProvideLevel_CannotProvide,
"Unhandled enum member" );
char szDiskName[MAX_PATH] = { 0 };
// Check if we can directly use this as a map
Host_DefaultMapFileName( pMapName, szDiskName, sizeof( szDiskName ) );
if ( *szDiskName && modelloader->Map_IsValid( szDiskName, true ) )
{
return eFindMap_Found;
}
// Fuzzy match in map list and check file
char match[1][64] = { {0} };
if ( MapList_ListMaps( pMapName, false, false, 1, sizeof( match[0] ), match ) && *(match[0]) )
{
Host_DefaultMapFileName( match[0], szDiskName, sizeof( szDiskName ) );
if ( modelloader->Map_IsValid( szDiskName, true ) )
{
V_strncpy( pMapName, match[0], nMapNameMax );
return eFindMap_FuzzyMatch;
}
}
return eFindMap_NotFound;
}
virtual int IndexOfEdict(const edict_t *pEdict)
{
if ( !pEdict )
{
return 0;
}
int index = (int) ( pEdict - sv.edicts );
if ( index < 0 || index > sv.max_edicts )
{
Sys_Error( "Bad entity in IndexOfEdict() index %i pEdict %p sv.edicts %p\n",
index, pEdict, sv.edicts );
}
return index;
}
// Returns a pointer to an entity from an index, but only if the entity
// is a valid DLL entity (ie. has an attached class)
virtual edict_t* PEntityOfEntIndex(int iEntIndex)
{
if ( iEntIndex >= 0 && iEntIndex < sv.max_edicts )
{
edict_t *pEdict = EDICT_NUM( iEntIndex );
if ( !pEdict->IsFree() )
{
return pEdict;
}
}
return NULL;
}
virtual int GetEntityCount( void )
{
return sv.num_edicts - sv.free_edicts;
}
virtual INetChannelInfo* GetPlayerNetInfo( int playerIndex )
{
if ( playerIndex < 1 || playerIndex > sv.GetClientCount() )
return NULL;
CGameClient *client = sv.Client( playerIndex - 1 );
return client->m_NetChannel;
}
virtual edict_t* CreateEdict( int iForceEdictIndex )
{
edict_t *pedict = ED_Alloc( iForceEdictIndex );
if ( g_pServerPluginHandler )
{
g_pServerPluginHandler->OnEdictAllocated( pedict );
}
return pedict;
}
virtual void RemoveEdict(edict_t* ed)
{
if ( g_pServerPluginHandler )
{
g_pServerPluginHandler->OnEdictFreed( ed );
}
ED_Free(ed);
}
//
// Request engine to allocate "cb" bytes on the entity's private data pointer.
//
virtual void *PvAllocEntPrivateData( long cb )
{
return calloc( 1, cb );
}
//
// Release the private data memory, if any.
//
virtual void FreeEntPrivateData( void *pEntity )
{
#if defined( _DEBUG ) && defined( WIN32 )
// set the memory to a known value
int size = _msize( pEntity );
memset( pEntity, 0xDD, size );
#endif
if ( pEntity )
{
free( pEntity );
}
}
virtual void *SaveAllocMemory( size_t num, size_t size )
{
#ifndef SWDS
return ::SaveAllocMemory(num, size);
#else
return NULL;
#endif
}
virtual void SaveFreeMemory( void *pSaveMem )
{
#ifndef SWDS
::SaveFreeMemory(pSaveMem);
#endif
}
/*
=================
EmitAmbientSound
=================
*/
virtual void EmitAmbientSound( int entindex, const Vector& pos, const char *samp, float vol,
soundlevel_t soundlevel, int fFlags, int pitch, float soundtime /*=0.0f*/ )
{
SoundInfo_t sound;
sound.SetDefault();
sound.nEntityIndex = entindex;
sound.fVolume = vol;
sound.Soundlevel = soundlevel;
sound.nFlags = fFlags;
sound.nPitch = pitch;
sound.nChannel = CHAN_STATIC;
sound.vOrigin = pos;
sound.bIsAmbient = true;
ASSERT_COORD( sound.vOrigin );
// set sound delay
if ( soundtime != 0.0f )
{
sound.fDelay = soundtime - sv.GetTime();
sound.nFlags |= SND_DELAY;
}
// if this is a sentence, get sentence number
if ( TestSoundChar(samp, CHAR_SENTENCE) )
{
sound.bIsSentence = true;
sound.nSoundNum = Q_atoi( PSkipSoundChars(samp) );
if ( sound.nSoundNum >= VOX_SentenceCount() )
{
ConMsg("EmitAmbientSound: invalid sentence number: %s", PSkipSoundChars(samp));
return;
}
}
else
{
// check to see if samp was properly precached
sound.bIsSentence = false;
sound.nSoundNum = SV_SoundIndex( samp );
if (sound.nSoundNum <= 0)
{
ConMsg ("EmitAmbientSound: sound not precached: %s\n", samp);
return;
}
}
if ( (fFlags & SND_SPAWNING) && sv.allowsignonwrites )
{
SVC_Sounds sndmsg;
char buffer[32];
sndmsg.m_DataOut.StartWriting(buffer, sizeof(buffer) );
sndmsg.m_nNumSounds = 1;
sndmsg.m_bReliableSound = true;
SoundInfo_t defaultSound; defaultSound.SetDefault();
sound.WriteDelta( &defaultSound, sndmsg.m_DataOut );
// write into signon buffer
if ( !sndmsg.WriteToBuffer( sv.m_Signon ) )
{
Sys_Error( "EmitAmbientSound: Init message would overflow signon buffer!\n" );
return;
}
}
else
{
if ( fFlags & SND_SPAWNING )
{
DevMsg("EmitAmbientSound: warning, broadcasting sound labled as SND_SPAWNING.\n" );
}
// send sound to all active players
CEngineRecipientFilter filter;
filter.AddAllPlayers();
filter.MakeReliable();
sv.BroadcastSound( sound, filter );
}
}
virtual void FadeClientVolume(const edict_t *clientent,
float fadePercent, float fadeOutSeconds, float holdTime, float fadeInSeconds)
{
int entnum = NUM_FOR_EDICT(clientent);
if (entnum < 1 || entnum > sv.GetClientCount() )
{
ConMsg ("tried to DLL_FadeClientVolume a non-client\n");
return;
}
IClient *client = sv.Client(entnum-1);
NET_StringCmd sndMsg( va("soundfade %.1f %.1f %.1f %.1f", fadePercent, holdTime, fadeOutSeconds, fadeInSeconds ) );
client->SendNetMsg( sndMsg );
}
//-----------------------------------------------------------------------------
//
// Sentence API
//
//-----------------------------------------------------------------------------
virtual int SentenceGroupPick( int groupIndex, char *name, int nameLen )
{
if ( !name )
{
Sys_Error( "SentenceGroupPick with NULL name\n" );
}
Assert( nameLen > 0 );
return VOX_GroupPick( groupIndex, name, nameLen );
}
virtual int SentenceGroupPickSequential( int groupIndex, char *name, int nameLen, int sentenceIndex, int reset )
{
if ( !name )
{
Sys_Error( "SentenceGroupPickSequential with NULL name\n" );
}
Assert( nameLen > 0 );
return VOX_GroupPickSequential( groupIndex, name, nameLen, sentenceIndex, reset );
}
virtual int SentenceIndexFromName( const char *pSentenceName )
{
if ( !pSentenceName )
{
Sys_Error( "SentenceIndexFromName with NULL pSentenceName\n" );
}
int sentenceIndex = -1;
VOX_LookupString( pSentenceName, &sentenceIndex );
return sentenceIndex;
}
virtual const char *SentenceNameFromIndex( int sentenceIndex )
{
return VOX_SentenceNameFromIndex( sentenceIndex );
}
virtual int SentenceGroupIndexFromName( const char *pGroupName )
{
if ( !pGroupName )
{
Sys_Error( "SentenceGroupIndexFromName with NULL pGroupName\n" );
}
return VOX_GroupIndexFromName( pGroupName );
}
virtual const char *SentenceGroupNameFromIndex( int groupIndex )
{
return VOX_GroupNameFromIndex( groupIndex );
}
virtual float SentenceLength( int sentenceIndex )
{
return VOX_SentenceLength( sentenceIndex );
}
//-----------------------------------------------------------------------------
virtual int CheckHeadnodeVisible( int nodenum, const byte *visbits, int vissize )
{
return CM_HeadnodeVisible(nodenum, visbits, vissize );
}
/*
=================
ServerCommand
Sends text to servers execution buffer
localcmd (string)
=================
*/
virtual void ServerCommand( const char *str )
{
if ( !str )
{
Sys_Error( "ServerCommand with NULL string\n" );
}
if ( ValidCmd( str ) )
{
Cbuf_AddText( str );
}
else
{
ConMsg( "Error, bad server command %s\n", str );
}
}
/*
=================
ServerExecute
Executes all commands in server buffer
localcmd (string)
=================
*/
virtual void ServerExecute( void )
{
Cbuf_Execute();
}
/*
=================
ClientCommand
Sends text over to the client's execution buffer
stuffcmd (clientent, value)
=================
*/
virtual void ClientCommand(edict_t* pEdict, const char* szFmt, ...)
{
va_list argptr;
static char szOut[1024];
va_start(argptr, szFmt);
Q_vsnprintf(szOut, sizeof( szOut ), szFmt, argptr);
va_end(argptr);
if ( szOut[0] == 0 )
{
Warning( "ClientCommand, 0 length string supplied.\n" );
return;
}
int entnum = NUM_FOR_EDICT( pEdict );
if ( ( entnum < 1 ) || ( entnum > sv.GetClientCount() ) )
{
ConMsg("\n!!!\n\nStuffCmd: Some entity tried to stuff '%s' to console buffer of entity %i when maxclients was set to %i, ignoring\n\n",
szOut, entnum, sv.GetMaxClients() );
return;
}
NET_StringCmd string( szOut );
sv.GetClient(entnum-1)->SendNetMsg( string );
}
// Send a client command keyvalues
// keyvalues are deleted inside the function
virtual void ClientCommandKeyValues( edict_t *pEdict, KeyValues *pCommand )
{
if ( !pCommand )
return;
int entnum = NUM_FOR_EDICT( pEdict );
if ( ( entnum < 1 ) || ( entnum > sv.GetClientCount() ) )
{
ConMsg("\n!!!\n\nClientCommandKeyValues: Some entity tried to stuff '%s' to console buffer of entity %i when maxclients was set to %i, ignoring\n\n",
pCommand->GetName(), entnum, sv.GetMaxClients() );
return;
}
SVC_CmdKeyValues cmd( pCommand );
sv.GetClient(entnum-1)->SendNetMsg( cmd );
}
/*
===============
LightStyle
void(float style, string value) lightstyle
===============
*/
virtual void LightStyle(int style, const char* val)
{
if ( !val )
{
Sys_Error( "LightStyle with NULL value!\n" );
}
// change the string in string table
INetworkStringTable *stringTable = sv.GetLightStyleTable();
stringTable->SetStringUserData( style, Q_strlen(val)+1, val );
}
virtual void StaticDecal( const Vector& origin, int decalIndex, int entityIndex, int modelIndex, bool lowpriority )
{
SVC_BSPDecal decal;
decal.m_Pos = origin;
decal.m_nDecalTextureIndex = decalIndex;
decal.m_nEntityIndex = entityIndex;
decal.m_nModelIndex = modelIndex;
decal.m_bLowPriority = lowpriority;
if ( sv.allowsignonwrites )
{
decal.WriteToBuffer( sv.m_Signon );
}
else
{
sv.BroadcastMessage( decal, false, true );
}
}
void Message_DetermineMulticastRecipients( bool usepas, const Vector& origin, CBitVec< ABSOLUTE_PLAYER_LIMIT >& playerbits )
{
SV_DetermineMulticastRecipients( usepas, origin, playerbits );
}
/*
===============================================================================
MESSAGE WRITING
===============================================================================
*/
virtual bf_write *EntityMessageBegin( int ent_index, ServerClass * ent_class, bool reliable )
{
if ( s_MsgData.started )
{
Sys_Error( "EntityMessageBegin: New message started before matching call to EndMessage.\n " );
return NULL;
}
s_MsgData.Reset();
Assert( ent_class );
s_MsgData.filter = NULL;
s_MsgData.reliable = reliable;
s_MsgData.started = true;
s_MsgData.currentMsg = &s_MsgData.entityMsg;
s_MsgData.entityMsg.m_nEntityIndex = ent_index;
s_MsgData.entityMsg.m_nClassID = ent_class->m_ClassID;
s_MsgData.entityMsg.m_DataOut.Reset();
return &s_MsgData.entityMsg.m_DataOut;
}
virtual bf_write *UserMessageBegin( IRecipientFilter *filter, int msg_index )
{
if ( s_MsgData.started )
{
Sys_Error( "UserMessageBegin: New message started before matching call to EndMessage.\n " );
return NULL;
}
s_MsgData.Reset();
Assert( filter );
s_MsgData.filter = filter;
s_MsgData.reliable = filter->IsReliable();
s_MsgData.started = true;
s_MsgData.currentMsg = &s_MsgData.userMsg;
s_MsgData.userMsg.m_nMsgType = msg_index;
s_MsgData.userMsg.m_DataOut.Reset();
return &s_MsgData.userMsg.m_DataOut;
}
// Validates user message type and checks to see if it's variable length
// returns true if variable length
int Message_CheckMessageLength()
{
if ( s_MsgData.currentMsg == &s_MsgData.userMsg )
{
char msgname[ 256 ];
int msgsize = -1;
int msgtype = s_MsgData.userMsg.m_nMsgType;
if ( !serverGameDLL->GetUserMessageInfo( msgtype, msgname, sizeof(msgname), msgsize ) )
{
Warning( "Unable to find user message for index %i\n", msgtype );
return -1;
}
int bytesWritten = s_MsgData.userMsg.m_DataOut.GetNumBytesWritten();
if ( msgsize == -1 )
{
if ( bytesWritten > MAX_USER_MSG_DATA )
{
Warning( "DLL_MessageEnd: Refusing to send user message %s of %i bytes to client, user message size limit is %i bytes\n",
msgname, bytesWritten, MAX_USER_MSG_DATA );
return -1;
}
}
else if ( msgsize != bytesWritten )
{
Warning( "User Msg '%s': %d bytes written, expected %d\n",
msgname, bytesWritten, msgsize );
return -1;
}
return bytesWritten; // all checks passed, estimated final length
}
if ( s_MsgData.currentMsg == &s_MsgData.entityMsg )
{
int bytesWritten = s_MsgData.entityMsg.m_DataOut.GetNumBytesWritten();
if ( bytesWritten > MAX_ENTITY_MSG_DATA ) // TODO use a define or so
{
Warning( "Entity Message to %i, %i bytes written (max is %d)\n",
s_MsgData.entityMsg.m_nEntityIndex, bytesWritten, MAX_ENTITY_MSG_DATA );
return -1;
}
return bytesWritten; // all checks passed, estimated final length
}
Warning( "MessageEnd unknown message type.\n" );
return -1;
}
virtual void MessageEnd( void )
{
if ( !s_MsgData.started )
{
Sys_Error( "MESSAGE_END called with no active message\n" );
return;
}
int length = Message_CheckMessageLength();
// check to see if it's a valid message
if ( length < 0 )
{
s_MsgData.Reset(); // clear message data
return;
}
if ( s_MsgData.filter )
{
// send entity/user messages only to full connected clients in filter
sv.BroadcastMessage( *s_MsgData.currentMsg, *s_MsgData.filter );
}
else
{
// send entity messages to all full connected clients
sv.BroadcastMessage( *s_MsgData.currentMsg, true, s_MsgData.reliable );
}
s_MsgData.Reset(); // clear message data
}
/* single print to a specific client */
virtual void ClientPrintf( edict_t *pEdict, const char *szMsg )
{
int entnum = NUM_FOR_EDICT( pEdict );
if (entnum < 1 || entnum > sv.GetClientCount() )
{
ConMsg ("tried to sprint to a non-client\n");
return;
}
sv.Client(entnum-1)->ClientPrintf( "%s", szMsg );
}
#ifdef SWDS
void Con_NPrintf( int pos, const char *fmt, ... )
{
}
void Con_NXPrintf( const struct con_nprint_s *info, const char *fmt, ... )
{
}
#else
void Con_NPrintf( int pos, const char *fmt, ... )
{
if ( IsDedicatedServer() )
return;
va_list argptr;
char text[4096];
va_start (argptr, fmt);
Q_vsnprintf(text, sizeof( text ), fmt, argptr);
va_end (argptr);
::Con_NPrintf( pos, "%s", text );
}
void Con_NXPrintf( const struct con_nprint_s *info, const char *fmt, ... )
{
if ( IsDedicatedServer() )
return;
va_list argptr;
char text[4096];
va_start (argptr, fmt);
Q_vsnprintf(text, sizeof( text ), fmt, argptr);
va_end (argptr);
::Con_NXPrintf( info, "%s", text );
}
#endif
virtual void SetView(const edict_t *clientent, const edict_t *viewent)
{
int clientnum = NUM_FOR_EDICT( clientent );
if (clientnum < 1 || clientnum > sv.GetClientCount() )
Host_Error ("DLL_SetView: not a client");
CGameClient *client = sv.Client(clientnum-1);
client->m_pViewEntity = viewent;
SVC_SetView view( NUM_FOR_EDICT(viewent) );
client->SendNetMsg( view );
}
virtual float Time(void)
{
return Sys_FloatTime();
}
virtual void CrosshairAngle(const edict_t *clientent, float pitch, float yaw)
{
int clientnum = NUM_FOR_EDICT( clientent );
if (clientnum < 1 || clientnum > sv.GetClientCount() )
Host_Error ("DLL_Crosshairangle: not a client");
IClient *client = sv.Client(clientnum-1);
if (pitch > 180)
pitch -= 360;
if (pitch < -180)
pitch += 360;
if (yaw > 180)
yaw -= 360;
if (yaw < -180)
yaw += 360;
SVC_CrosshairAngle crossHairMsg;
crossHairMsg.m_Angle.x = pitch;
crossHairMsg.m_Angle.y = yaw;
crossHairMsg.m_Angle.y = 0;
client->SendNetMsg( crossHairMsg );
}
virtual void GetGameDir( char *szGetGameDir, int maxlength )
{
COM_GetGameDir(szGetGameDir, maxlength );
}
virtual int CompareFileTime( const char *filename1, const char *filename2, int *iCompare)
{
return COM_CompareFileTime(filename1, filename2, iCompare);
}
virtual bool LockNetworkStringTables( bool lock )
{
return networkStringTableContainerServer->Lock( lock );
}
// For use with FAKE CLIENTS
virtual edict_t* CreateFakeClient( const char *netname )
{
CGameClient *fcl = static_cast<CGameClient*>( sv.CreateFakeClient( netname ) );
if ( !fcl )
{
// server is full
return NULL;
}
return fcl->edict;
}
// For use with FAKE CLIENTS
virtual edict_t* CreateFakeClientEx( const char *netname, bool bReportFakeClient /*= true*/ )
{
sv.SetReportNewFakeClients( bReportFakeClient );
edict_t *ret = CreateFakeClient( netname );
sv.SetReportNewFakeClients( true ); // Leave this set as true so other callers of sv.CreateFakeClient behave correctly.
return ret;
}
// Get a keyvalue for s specified client
virtual const char *GetClientConVarValue( int clientIndex, const char *name )
{
if ( clientIndex < 1 || clientIndex > sv.GetClientCount() )
{
DevMsg( 1, "GetClientConVarValue: player invalid index %i\n", clientIndex );
return "";
}
return sv.GetClient( clientIndex - 1 )->GetUserSetting( name );
}
virtual const char *ParseFile(const char *data, char *token, int maxlen)
{
return ::COM_ParseFile(data, token, maxlen );
}
virtual bool CopyFile( const char *source, const char *destination )
{
return ::COM_CopyFile( source, destination );
}
virtual void AddOriginToPVS( const Vector& origin )
{
::SV_AddOriginToPVS(origin);
}
virtual void ResetPVS( byte* pvs, int pvssize )
{
::SV_ResetPVS( pvs, pvssize );
}
virtual void SetAreaPortalState( int portalNumber, int isOpen )
{
CM_SetAreaPortalState(portalNumber, isOpen);
}
virtual void SetAreaPortalStates( const int *portalNumbers, const int *isOpen, int nPortals )
{
CM_SetAreaPortalStates( portalNumbers, isOpen, nPortals );
}
virtual void DrawMapToScratchPad( IScratchPad3D *pPad, unsigned long iFlags )
{
worldbrushdata_t *pData = host_state.worldmodel->brush.pShared;
if ( !pData )
return;
SurfaceHandle_t surfID = SurfaceHandleFromIndex( host_state.worldmodel->brush.firstmodelsurface, pData );
for (int i=0; i< host_state.worldmodel->brush.nummodelsurfaces; ++i, ++surfID)
{
// Don't bother with nodraw surfaces
if( MSurf_Flags( surfID ) & SURFDRAW_NODRAW )
continue;
CSPVertList vertList;
for ( int iVert=0; iVert < MSurf_VertCount( surfID ); iVert++ )
{
int iWorldVert = pData->vertindices[surfID->firstvertindex + iVert];
const Vector &vPos = pData->vertexes[iWorldVert].position;
vertList.m_Verts.AddToTail( CSPVert( vPos ) );
}
pPad->DrawPolygon( vertList );
}
}
const CBitVec<MAX_EDICTS>* GetEntityTransmitBitsForClient( int iClientIndex )
{
if ( iClientIndex < 0 || iClientIndex >= sv.GetClientCount() )
{
Assert( false );
return NULL;
}
CGameClient *pClient = sv.Client( iClientIndex );
CClientFrame *deltaFrame = pClient->GetClientFrame( pClient->m_nDeltaTick );
if ( !deltaFrame )
return NULL;
return &deltaFrame->transmit_entity;
}
virtual bool IsPaused()
{
return sv.IsPaused();
}
virtual void SetFakeClientConVarValue( edict_t *pEntity, const char *pCvarName, const char *value )
{
int clientnum = NUM_FOR_EDICT( pEntity );
if (clientnum < 1 || clientnum > sv.GetClientCount() )
Host_Error ("DLL_SetView: not a client");
CGameClient *client = sv.Client(clientnum-1);
if ( client->IsFakeClient() )
{
client->SetUserCVar( pCvarName, value );
client->m_bConVarsChanged = true;
}
}
virtual CSharedEdictChangeInfo* GetSharedEdictChangeInfo()
{
return &g_SharedEdictChangeInfo;
}
virtual IChangeInfoAccessor *GetChangeAccessor( const edict_t *pEdict )
{
return &sv.edictchangeinfo[ NUM_FOR_EDICT( pEdict ) ];
}
virtual QueryCvarCookie_t StartQueryCvarValue( edict_t *pPlayerEntity, const char *pCvarName )
{
int clientnum = NUM_FOR_EDICT( pPlayerEntity );
if (clientnum < 1 || clientnum > sv.GetClientCount() )
Host_Error( "StartQueryCvarValue: not a client" );
CGameClient *client = sv.Client( clientnum-1 );
return SendCvarValueQueryToClient( client, pCvarName, false );
}
// Name of most recently load .sav file
virtual char const *GetMostRecentlyLoadedFileName()
{
#if !defined( SWDS )
return saverestore->GetMostRecentlyLoadedFileName();
#else
return "";
#endif
}
virtual char const *GetSaveFileName()
{
#if !defined( SWDS )
return saverestore->GetSaveFileName();
#else
return "";
#endif
}
// Tells the engine we can immdiately re-use all edict indices
// even though we may not have waited enough time
virtual void AllowImmediateEdictReuse( )
{
ED_AllowImmediateReuse();
}
virtual void MultiplayerEndGame()
{
#if !defined( SWDS )
g_pMatchmaking->EndGame();
#endif
}
virtual void ChangeTeam( const char *pTeamName )
{
#if !defined( SWDS )
g_pMatchmaking->ChangeTeam( pTeamName );
#endif
}
virtual void SetAchievementMgr( IAchievementMgr *pAchievementMgr )
{
g_pAchievementMgr = pAchievementMgr;
}
virtual IAchievementMgr *GetAchievementMgr()
{
return g_pAchievementMgr;
}
virtual int GetAppID()
{
return GetSteamAppID();
}
virtual bool IsLowViolence();
/*
=================
InsertServerCommand
Sends text to servers execution buffer
localcmd (string)
=================
*/
virtual void InsertServerCommand( const char *str )
{
if ( !str )
{
Sys_Error( "InsertServerCommand with NULL string\n" );
}
if ( ValidCmd( str ) )
{
Cbuf_InsertText( str );
}
else
{
ConMsg( "Error, bad server command %s (InsertServerCommand)\n", str );
}
}
bool GetPlayerInfo( int ent_num, player_info_t *pinfo )
{
// Entity numbers are offset by 1 from the player numbers
return sv.GetPlayerInfo( (ent_num-1), pinfo );
}
bool IsClientFullyAuthenticated( edict_t *pEdict )
{
int entnum = NUM_FOR_EDICT( pEdict );
if (entnum < 1 || entnum > sv.GetClientCount() )
return false;
// Entity numbers are offset by 1 from the player numbers
CGameClient *client = sv.Client(entnum-1);
if ( client )
return client->IsFullyAuthenticated();
return false;
}
void SetDedicatedServerBenchmarkMode( bool bBenchmarkMode )
{
g_bDedicatedServerBenchmarkMode = bBenchmarkMode;
if ( bBenchmarkMode )
{
extern ConVar sv_stressbots;
sv_stressbots.SetValue( (int)1 );
}
}
// Returns the SteamID of the game server
const CSteamID *GetGameServerSteamID()
{
if ( !Steam3Server().GetGSSteamID().IsValid() )
return NULL;
return &Steam3Server().GetGSSteamID();
}
// Returns the SteamID of the specified player. It'll be NULL if the player hasn't authenticated yet.
const CSteamID *GetClientSteamID( edict_t *pPlayerEdict )
{
int entnum = NUM_FOR_EDICT( pPlayerEdict );
return GetClientSteamIDByPlayerIndex( entnum );
}
const CSteamID *GetClientSteamIDByPlayerIndex( int entnum )
{
if (entnum < 1 || entnum > sv.GetClientCount() )
return NULL;
// Entity numbers are offset by 1 from the player numbers
CGameClient *client = sv.Client(entnum-1);
if ( !client )
return NULL;
// Make sure they are connected and Steam ID is valid
if ( !client->IsConnected() || !client->m_SteamID.IsValid() )
return NULL;
return &client->m_SteamID;
}
void SetGamestatsData( CGamestatsData *pGamestatsData )
{
g_pGamestatsData = pGamestatsData;
}
CGamestatsData *GetGamestatsData()
{
return g_pGamestatsData;
}
virtual IReplaySystem *GetReplay()
{
return g_pReplay;
}
virtual int GetClusterCount()
{
CCollisionBSPData *pBSPData = GetCollisionBSPData();
if ( pBSPData && pBSPData->map_vis )
return pBSPData->map_vis->numclusters;
return 0;
}
virtual int GetAllClusterBounds( bbox_t *pBBoxList, int maxBBox )
{
CCollisionBSPData *pBSPData = GetCollisionBSPData();
if ( pBSPData && pBSPData->map_vis && host_state.worldbrush )
{
// clamp to max clusters in the map
if ( maxBBox > pBSPData->map_vis->numclusters )
{
maxBBox = pBSPData->map_vis->numclusters;
}
// reset all of the bboxes
for ( int i = 0; i < maxBBox; i++ )
{
ClearBounds( pBBoxList[i].mins, pBBoxList[i].maxs );
}
// add each leaf's bounds to the bounds for that cluster
for ( int i = 0; i < host_state.worldbrush->numleafs; i++ )
{
mleaf_t *pLeaf = &host_state.worldbrush->leafs[i];
// skip solid leaves and leaves with cluster < 0
if ( !(pLeaf->contents & CONTENTS_SOLID) && pLeaf->cluster >= 0 && pLeaf->cluster < maxBBox )
{
Vector mins, maxs;
mins = pLeaf->m_vecCenter - pLeaf->m_vecHalfDiagonal;
maxs = pLeaf->m_vecCenter + pLeaf->m_vecHalfDiagonal;
AddPointToBounds( mins, pBBoxList[pLeaf->cluster].mins, pBBoxList[pLeaf->cluster].maxs );
AddPointToBounds( maxs, pBBoxList[pLeaf->cluster].mins, pBBoxList[pLeaf->cluster].maxs );
}
}
return pBSPData->map_vis->numclusters;
}
return 0;
}
virtual int GetServerVersion() const OVERRIDE
{
return GetSteamInfIDVersionInfo().ServerVersion;
}
virtual float GetServerTime() const OVERRIDE
{
return sv.GetTime();
}
virtual IServer *GetIServer() OVERRIDE
{
return (IServer *)&sv;
}
virtual void SetPausedForced( bool bPaused, float flDuration /*= -1.f*/ ) OVERRIDE
{
sv.SetPausedForced( bPaused, flDuration );
}
private:
// Purpose: Sends a temp entity to the client ( follows the format of the original MESSAGE_BEGIN stuff from HL1
virtual void PlaybackTempEntity( IRecipientFilter& filter, float delay, const void *pSender, const SendTable *pST, int classID );
virtual int CheckAreasConnected( int area1, int area2 );
virtual int GetArea( const Vector& origin );
virtual void GetAreaBits( int area, unsigned char *bits, int buflen );
virtual bool GetAreaPortalPlane( Vector const &vViewOrigin, int portalKey, VPlane *pPlane );
virtual client_textmessage_t *TextMessageGet( const char *pName );
virtual void LogPrint(const char * msg);
virtual bool LoadGameState( char const *pMapName, bool createPlayers );
virtual void LoadAdjacentEnts( const char *pOldLevel, const char *pLandmarkName );
virtual void ClearSaveDir();
virtual void ClearSaveDirAfterClientLoad();
virtual const char* GetMapEntitiesString();
virtual void BuildEntityClusterList( edict_t *pEdict, PVSInfo_t *pPVSInfo );
virtual void CleanUpEntityClusterList( PVSInfo_t *pPVSInfo );
virtual void SolidMoved( edict_t *pSolidEnt, ICollideable *pSolidCollide, const Vector* pPrevAbsOrigin, bool accurateBboxTriggerChecks );
virtual void TriggerMoved( edict_t *pTriggerEnt, bool accurateBboxTriggerChecks );
virtual ISpatialPartition *CreateSpatialPartition( const Vector& worldmin, const Vector& worldmax ) { return ::CreateSpatialPartition( worldmin, worldmax ); }
virtual void DestroySpatialPartition( ISpatialPartition *pPartition ) { ::DestroySpatialPartition( pPartition ); }
};
// Backwards-compat shim that inherits newest then provides overrides for the legacy behavior
class CVEngineServer22 : public CVEngineServer
{
virtual int IsMapValid( const char *filename ) OVERRIDE
{
// For users of the older interface, preserve here the old modelloader behavior of wrapping maps/%.bsp around
// the filename. This went away in newer interfaces since maps can now live in other places.
char szWrappedName[MAX_PATH] = { 0 };
V_snprintf( szWrappedName, sizeof( szWrappedName ), "maps/%s.bsp", filename );
return modelloader->Map_IsValid( szWrappedName );
}
};
//-----------------------------------------------------------------------------
// Expose CVEngineServer to the game DLL.
//-----------------------------------------------------------------------------
static CVEngineServer g_VEngineServer;
static CVEngineServer22 g_VEngineServer22;
// INTERFACEVERSION_VENGINESERVER_VERSION_21 is compatible with 22 latest since we only added virtuals to the end, so expose that as well.
EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CVEngineServer, IVEngineServer021, INTERFACEVERSION_VENGINESERVER_VERSION_21, g_VEngineServer22 );
EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CVEngineServer, IVEngineServer022, INTERFACEVERSION_VENGINESERVER_VERSION_22, g_VEngineServer22 );
EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CVEngineServer, IVEngineServer, INTERFACEVERSION_VENGINESERVER, g_VEngineServer );
// When bumping the version to this interface, check that our assumption is still valid and expose the older version in the same way
COMPILE_TIME_ASSERT( INTERFACEVERSION_VENGINESERVER_INT == 23 );
//-----------------------------------------------------------------------------
// Expose CVEngineServer to the engine.
//-----------------------------------------------------------------------------
IVEngineServer *g_pVEngineServer = &g_VEngineServer;
//-----------------------------------------------------------------------------
// Used to allocate pvs infos
//-----------------------------------------------------------------------------
static CUtlMemoryPool s_PVSInfoAllocator( 128, 128 * 64, CUtlMemoryPool::GROW_SLOW, "pvsinfopool", 128 );
//-----------------------------------------------------------------------------
// Purpose: Sends a temp entity to the client ( follows the format of the original MESSAGE_BEGIN stuff from HL1
// Input : msg_dest -
// delay -
// *origin -
// *recipient -
// *pSender -
// *pST -
// classID -
//-----------------------------------------------------------------------------
void CVEngineServer::PlaybackTempEntity( IRecipientFilter& filter, float delay, const void *pSender, const SendTable *pST, int classID )
{
VPROF( "PlaybackTempEntity" );
// don't add more events to a snapshot than a client can receive
if ( sv.m_TempEntities.Count() >= ((1<<CEventInfo::EVENT_INDEX_BITS)-1) )
{
// remove oldest effect
delete sv.m_TempEntities[0];
sv.m_TempEntities.Remove( 0 );
}
// Make this start at 1
classID = classID + 1;
// Encode now!
ALIGN4 unsigned char data[ CEventInfo::MAX_EVENT_DATA ] ALIGN4_POST;
bf_write buffer( "PlaybackTempEntity", data, sizeof(data) );
// write all properties, if init or reliable message delta against zero values
if( !SendTable_Encode( pST, pSender, &buffer, classID, NULL, false ) )
{
Host_Error( "PlaybackTempEntity: SendTable_Encode returned false (ent %d), overflow? %i\n", classID, buffer.IsOverflowed() ? 1 : 0 );
return;
}
// create CEventInfo:
CEventInfo *newEvent = new CEventInfo;
//copy client filter
newEvent->filter.AddPlayersFromFilter( &filter );
newEvent->classID = classID;
newEvent->pSendTable= pST;
newEvent->fire_delay= delay;
newEvent->bits = buffer.GetNumBitsWritten();
int size = Bits2Bytes( buffer.GetNumBitsWritten() );
newEvent->pData = new byte[size];
Q_memcpy( newEvent->pData, data, size );
// add to list
sv.m_TempEntities[sv.m_TempEntities.AddToTail()] = newEvent;
}
int CVEngineServer::CheckAreasConnected( int area1, int area2 )
{
return CM_AreasConnected(area1, area2);
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : *origin -
// *bits -
// Output : void
//-----------------------------------------------------------------------------
int CVEngineServer::GetArea( const Vector& origin )
{
return CM_LeafArea( CM_PointLeafnum( origin ) );
}
void CVEngineServer::GetAreaBits( int area, unsigned char *bits, int buflen )
{
CM_WriteAreaBits( bits, buflen, area );
}
bool CVEngineServer::GetAreaPortalPlane( Vector const &vViewOrigin, int portalKey, VPlane *pPlane )
{
return CM_GetAreaPortalPlane( vViewOrigin, portalKey, pPlane );
}
client_textmessage_t *CVEngineServer::TextMessageGet( const char *pName )
{
return ::TextMessageGet( pName );
}
void CVEngineServer::LogPrint(const char * msg)
{
g_Log.Print( msg );
}
// HACKHACK: Save/restore wrapper - Move this to a different interface
bool CVEngineServer::LoadGameState( char const *pMapName, bool createPlayers )
{
#ifndef SWDS
return saverestore->LoadGameState( pMapName, createPlayers ) != 0;
#else
return 0;
#endif
}
void CVEngineServer::LoadAdjacentEnts( const char *pOldLevel, const char *pLandmarkName )
{
#ifndef SWDS
saverestore->LoadAdjacentEnts( pOldLevel, pLandmarkName );
#endif
}
void CVEngineServer::ClearSaveDir()
{
#ifndef SWDS
saverestore->ClearSaveDir();
#endif
}
void CVEngineServer::ClearSaveDirAfterClientLoad()
{
#ifndef SWDS
saverestore->RequestClearSaveDir();
#endif
}
const char* CVEngineServer::GetMapEntitiesString()
{
return CM_EntityString();
}
//-----------------------------------------------------------------------------
// Builds PVS information for an entity
//-----------------------------------------------------------------------------
inline bool SortClusterLessFunc( const int &left, const int &right )
{
return left < right;
}
void CVEngineServer::BuildEntityClusterList( edict_t *pEdict, PVSInfo_t *pPVSInfo )
{
int i, j;
int topnode;
int leafCount;
int leafs[MAX_TOTAL_ENT_LEAFS], clusters[MAX_TOTAL_ENT_LEAFS];
int area;
CleanUpEntityClusterList( pPVSInfo );
pPVSInfo->m_pClusters = 0;
pPVSInfo->m_nClusterCount = 0;
pPVSInfo->m_nAreaNum = 0;
pPVSInfo->m_nAreaNum2 = 0;
if ( !pEdict )
return;
ICollideable *pCollideable = pEdict->GetCollideable();
Assert( pCollideable );
if ( !pCollideable )
return;
topnode = -1;
//get all leafs, including solids
Vector vecWorldMins, vecWorldMaxs;
pCollideable->WorldSpaceSurroundingBounds( &vecWorldMins, &vecWorldMaxs );
leafCount = CM_BoxLeafnums( vecWorldMins, vecWorldMaxs, leafs, MAX_TOTAL_ENT_LEAFS, &topnode );
// set areas
for ( i = 0; i < leafCount; i++ )
{
clusters[i] = CM_LeafCluster( leafs[i] );
area = CM_LeafArea( leafs[i] );
if ( area == 0 )
continue;
// doors may legally straggle two areas,
// but nothing should ever need more than that
if ( pPVSInfo->m_nAreaNum && pPVSInfo->m_nAreaNum != area )
{
if ( pPVSInfo->m_nAreaNum2 && pPVSInfo->m_nAreaNum2 != area && sv.IsLoading() )
{
ConDMsg ("Object touching 3 areas at %f %f %f\n",
vecWorldMins[0], vecWorldMins[1], vecWorldMins[2]);
}
pPVSInfo->m_nAreaNum2 = area;
}
else
{
pPVSInfo->m_nAreaNum = area;
}
}
Vector center = (vecWorldMins+vecWorldMaxs) * 0.5f; // calc center
pPVSInfo->m_nHeadNode = topnode; // save headnode
// save origin
pPVSInfo->m_vCenter[0] = center[0];
pPVSInfo->m_vCenter[1] = center[1];
pPVSInfo->m_vCenter[2] = center[2];
if ( leafCount >= MAX_TOTAL_ENT_LEAFS )
{
// assume we missed some leafs, and mark by headnode
pPVSInfo->m_nClusterCount = -1;
return;
}
pPVSInfo->m_pClusters = pPVSInfo->m_pClustersInline;
if ( leafCount >= 16 )
{
std::make_heap( clusters, clusters + leafCount, SortClusterLessFunc );
std::sort_heap( clusters, clusters + leafCount, SortClusterLessFunc );
for ( i = 0; i < leafCount; i++ )
{
if ( clusters[i] == -1 )
continue; // not a visible leaf
if ( ( i > 0 ) && ( clusters[i] == clusters[i-1] ) )
continue;
if ( pPVSInfo->m_nClusterCount == MAX_FAST_ENT_CLUSTERS )
{
unsigned short *pClusters = (unsigned short *)s_PVSInfoAllocator.Alloc();
memcpy( pClusters, pPVSInfo->m_pClusters, MAX_FAST_ENT_CLUSTERS * sizeof(unsigned short) );
pPVSInfo->m_pClusters = pClusters;
}
else if ( pPVSInfo->m_nClusterCount == MAX_ENT_CLUSTERS )
{
// assume we missed some leafs, and mark by headnode
s_PVSInfoAllocator.Free( pPVSInfo->m_pClusters );
pPVSInfo->m_pClusters = 0;
pPVSInfo->m_nClusterCount = -1;
break;
}
pPVSInfo->m_pClusters[pPVSInfo->m_nClusterCount++] = (short)clusters[i];
}
return;
}
for ( i = 0; i < leafCount; i++ )
{
if ( clusters[i] == -1 )
continue; // not a visible leaf
for ( j = 0; j < i; j++ )
{
if ( clusters[j] == clusters[i] )
break;
}
if ( j != i )
continue;
if ( pPVSInfo->m_nClusterCount == MAX_FAST_ENT_CLUSTERS )
{
unsigned short *pClusters = (unsigned short*)s_PVSInfoAllocator.Alloc();
memcpy( pClusters, pPVSInfo->m_pClusters, MAX_FAST_ENT_CLUSTERS * sizeof(unsigned short) );
pPVSInfo->m_pClusters = pClusters;
}
else if ( pPVSInfo->m_nClusterCount == MAX_ENT_CLUSTERS )
{
// assume we missed some leafs, and mark by headnode
s_PVSInfoAllocator.Free( pPVSInfo->m_pClusters );
pPVSInfo->m_pClusters = 0;
pPVSInfo->m_nClusterCount = -1;
break;
}
pPVSInfo->m_pClusters[pPVSInfo->m_nClusterCount++] = (short)clusters[i];
}
}
//-----------------------------------------------------------------------------
// Cleans up the cluster list
//-----------------------------------------------------------------------------
void CVEngineServer::CleanUpEntityClusterList( PVSInfo_t *pPVSInfo )
{
if ( pPVSInfo->m_nClusterCount > MAX_FAST_ENT_CLUSTERS )
{
s_PVSInfoAllocator.Free( pPVSInfo->m_pClusters );
pPVSInfo->m_pClusters = 0;
pPVSInfo->m_nClusterCount = 0;
}
}
//-----------------------------------------------------------------------------
// Adds a handle to the list of entities to update when a partition query occurs
//-----------------------------------------------------------------------------
void CVEngineServer::SolidMoved( edict_t *pSolidEnt, ICollideable *pSolidCollide, const Vector* pPrevAbsOrigin, bool accurateBboxTriggerChecks )
{
SV_SolidMoved( pSolidEnt, pSolidCollide, pPrevAbsOrigin, accurateBboxTriggerChecks );
}
void CVEngineServer::TriggerMoved( edict_t *pTriggerEnt, bool accurateBboxTriggerChecks )
{
SV_TriggerMoved( pTriggerEnt, accurateBboxTriggerChecks );
}
//-----------------------------------------------------------------------------
// Called by the server to determine violence settings.
//-----------------------------------------------------------------------------
bool CVEngineServer::IsLowViolence()
{
return g_bLowViolence;
}
|