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 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128
|
/*
===========================================================================
Return to Castle Wolfenstein multiplayer GPL Source Code
Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company.
This file is part of the Return to Castle Wolfenstein multiplayer GPL Source Code (“RTCW MP Source Code”).
RTCW MP Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
RTCW MP Source Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with RTCW MP Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the RTCW MP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW MP Source Code. If not, please request a copy in writing from id Software at the address below.
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
// sv_client.c -- server code for dealing with clients
#include "server.h"
static void SV_CloseDownload( client_t *cl );
/*
=================
SV_GetChallenge
A "getchallenge" OOB command has been received
Returns a challenge number that can be used
in a subsequent connectResponse command.
We do this to prevent denial of service attacks that
flood the server with invalid connection IPs. With a
challenge, they must give a valid IP address.
If we are authorizing, a challenge request will cause a packet
to be sent to the authorize server.
When an authorizeip is returned, a challenge response will be
sent to that ip.
ioquake3: we added a possibility for clients to add a challenge
to their packets, to make it more difficult for malicious servers
to hi-jack client connections.
Also, the auth stuff is completely disabled for com_standalone games
as well as IPv6 connections, since there is no way to use the
v4-only auth server for these new types of connections.
=================
*/
void SV_GetChallenge( netadr_t from )
{
int i;
int oldest;
int oldestTime;
int oldestClientTime;
int clientChallenge;
challenge_t *challenge;
qboolean wasfound = qfalse;
char *gameName;
qboolean gameMismatch;
// ignore if we are in single player
if ( Cvar_VariableValue( "g_gametype" ) == GT_SINGLE_PLAYER || Cvar_VariableValue("ui_singlePlayerActive")) {
return;
}
// Prevent using getchallenge as an amplifier
if ( SVC_RateLimitAddress( from, 10, 1000 ) ) {
Com_DPrintf( "SV_GetChallenge: rate limit from %s exceeded, dropping request\n",
NET_AdrToString( from ) );
return;
}
// Allow getchallenge to be DoSed relatively easily, but prevent
// excess outbound bandwidth usage when being flooded inbound
if ( SVC_RateLimit( &outboundLeakyBucket, 10, 100 ) ) {
Com_DPrintf( "SV_GetChallenge: rate limit exceeded, dropping request\n" );
return;
}
gameName = Cmd_Argv(2);
#ifdef LEGACY_PROTOCOL
// gamename is optional for legacy protocol
if (com_legacyprotocol->integer && !*gameName)
gameMismatch = qfalse;
else
#endif
gameMismatch = !*gameName || strcmp(gameName, com_gamename->string) != 0;
// reject client if the gamename string sent by the client doesn't match ours
if (gameMismatch)
{
NET_OutOfBandPrint(NS_SERVER, from, "print\nGame mismatch: This is a %s server\n",
com_gamename->string);
return;
}
oldest = 0;
oldestClientTime = oldestTime = 0x7fffffff;
// see if we already have a challenge for this ip
challenge = &svs.challenges[0];
clientChallenge = atoi(Cmd_Argv(1));
for(i = 0 ; i < MAX_CHALLENGES ; i++, challenge++)
{
if(!challenge->connected && NET_CompareAdr(from, challenge->adr))
{
wasfound = qtrue;
if(challenge->time < oldestClientTime)
oldestClientTime = challenge->time;
}
if(wasfound && i >= MAX_CHALLENGES_MULTI)
{
i = MAX_CHALLENGES;
break;
}
if ( challenge->time < oldestTime ) {
oldestTime = challenge->time;
oldest = i;
}
}
if ( i == MAX_CHALLENGES ) {
// this is the first time this client has asked for a challenge
challenge = &svs.challenges[oldest];
challenge->clientChallenge = clientChallenge;
challenge->adr = from;
challenge->firstTime = svs.time;
challenge->firstPing = 0;
challenge->connected = qfalse;
}
// always generate a new challenge number, so the client cannot circumvent sv_maxping
challenge->challenge = ( ( (unsigned int)rand() << 16 ) ^ (unsigned int)rand() ) ^ svs.time;
challenge->wasrefused = qfalse;
challenge->time = svs.time;
#ifndef STANDALONE
#ifdef USE_AUTHORIZE_SERVER
// Drop the authorize stuff if this client is coming in via v6 as the auth server does not support ipv6.
// Drop also for addresses coming in on local LAN and for stand-alone games independent from id's assets.
if(challenge->adr.type == NA_IP && !com_standalone->integer && !Sys_IsLANAddress(from))
{
// look up the authorize server's IP
if (svs.authorizeAddress.type == NA_BAD)
{
Com_Printf( "Resolving %s\n", AUTHORIZE_SERVER_NAME );
if (NET_StringToAdr(AUTHORIZE_SERVER_NAME, &svs.authorizeAddress, NA_IP))
{
svs.authorizeAddress.port = BigShort( PORT_AUTHORIZE );
Com_Printf( "%s resolved to %i.%i.%i.%i:%i\n", AUTHORIZE_SERVER_NAME,
svs.authorizeAddress.ip[0], svs.authorizeAddress.ip[1],
svs.authorizeAddress.ip[2], svs.authorizeAddress.ip[3],
BigShort( svs.authorizeAddress.port ) );
}
}
// we couldn't contact the auth server, let them in.
if(svs.authorizeAddress.type == NA_BAD)
Com_Printf("Couldn't resolve auth server address\n");
// if they have been challenging for a long time and we
// haven't heard anything from the authorize server, go ahead and
// let them in, assuming the id server is down
else if(svs.time - oldestClientTime > AUTHORIZE_TIMEOUT)
Com_DPrintf( "authorize server timed out\n" );
else
{
// otherwise send their ip to the authorize server
cvar_t *fs;
const char *game;
Com_DPrintf( "sending getIpAuthorize for %s\n", NET_AdrToString( from ));
game = Cvar_VariableString( "fs_game" );
if (game[0] == 0) {
game = BASEGAME;
}
fs = Cvar_Get( "sv_allowAnonymous", "0", CVAR_SERVERINFO );
// NERVE - SMF - fixed parsing on sv_allowAnonymous
NET_OutOfBandPrint( NS_SERVER, svs.authorizeAddress,
"getIpAuthorize %i %i.%i.%i.%i %s %i", challenge->challenge,
from.ip[0], from.ip[1], from.ip[2], from.ip[3], game, fs->integer );
return;
}
}
#endif
#endif
challenge->pingTime = svs.time;
NET_OutOfBandPrint(NS_SERVER, challenge->adr, "challengeResponse %d %d %d %d",
challenge->challenge, sv_onlyVisibleClients->integer, clientChallenge, com_protocol->integer);
}
#ifndef STANDALONE
#ifdef USE_AUTHORIZE_SERVER
/*
====================
SV_AuthorizeIpPacket
A packet has been returned from the authorize server.
If we have a challenge adr for that ip, send the
challengeResponse to it
====================
*/
void SV_AuthorizeIpPacket( netadr_t from ) {
int challenge;
int i;
char *s;
char *r;
challenge_t *challengeptr;
if ( !NET_CompareBaseAdr( from, svs.authorizeAddress ) ) {
Com_Printf( "SV_AuthorizeIpPacket: not from authorize server\n" );
return;
}
challenge = atoi( Cmd_Argv( 1 ) );
for ( i = 0 ; i < MAX_CHALLENGES ; i++ ) {
if ( svs.challenges[i].challenge == challenge ) {
break;
}
}
if ( i == MAX_CHALLENGES ) {
Com_Printf( "SV_AuthorizeIpPacket: challenge not found\n" );
return;
}
challengeptr = &svs.challenges[i];
// send a packet back to the original client
challengeptr->pingTime = svs.time;
s = Cmd_Argv( 2 );
r = Cmd_Argv( 3 ); // reason
if ( !Q_stricmp( s, "demo" ) ) {
// they are a demo client trying to connect to a real server
NET_OutOfBandPrint( NS_SERVER, challengeptr->adr, "print\nServer is not a demo server\n" );
// clear the challenge record so it won't timeout and let them through
Com_Memset( challengeptr, 0, sizeof( *challengeptr ) );
return;
}
if ( !Q_stricmp( s, "accept" ) ) {
NET_OutOfBandPrint( NS_SERVER, challengeptr->adr,
"challengeResponse %d %d %d %d", challengeptr->challenge, sv_onlyVisibleClients->integer, challengeptr->clientChallenge, com_protocol->integer );
return;
}
if ( !Q_stricmp( s, "unknown" ) ) {
if ( !r ) {
NET_OutOfBandPrint( NS_SERVER, challengeptr->adr, "print\nAwaiting CD key authorization\n" );
} else {
NET_OutOfBandPrint( NS_SERVER, challengeptr->adr, "print\n%s\n", r);
}
// clear the challenge record so it won't timeout and let them through
Com_Memset( challengeptr, 0, sizeof( *challengeptr ) );
return;
}
// authorization failed
if ( !r ) {
NET_OutOfBandPrint( NS_SERVER, challengeptr->adr, "print\nSomeone is using this CD Key\n" );
} else {
NET_OutOfBandPrint( NS_SERVER, challengeptr->adr, "print\n%s\n", r );
}
// clear the challenge record so it won't timeout and let them through
Com_Memset( challengeptr, 0, sizeof(*challengeptr) );
}
#endif
#endif
/*
==================
SV_IsBanned
Check whether a certain address is banned
==================
*/
static qboolean SV_IsBanned(netadr_t *from, qboolean isexception)
{
int index;
serverBan_t *curban;
if(!isexception)
{
// If this is a query for a ban, first check whether the client is excepted
if(SV_IsBanned(from, qtrue))
return qfalse;
}
for(index = 0; index < serverBansCount; index++)
{
curban = &serverBans[index];
if(curban->isexception == isexception)
{
if(NET_CompareBaseAdrMask(curban->ip, *from, curban->subnet))
return qtrue;
}
}
return qfalse;
}
/*
==================
SV_DirectConnect
A "connect" OOB command has been received
==================
*/
void SV_DirectConnect( netadr_t from ) {
char userinfo[MAX_INFO_STRING];
int i;
client_t *cl, *newcl;
client_t temp;
sharedEntity_t *ent;
int clientNum;
#ifndef UPDATE_SERVER
int version;
#endif
int qport;
int challenge;
char *password;
int startIndex;
intptr_t denied;
int count;
char *ip;
char *guid;
#ifdef LEGACY_PROTOCOL
qboolean compat = qfalse;
#endif
Com_DPrintf( "SVC_DirectConnect ()\n" );
// Check whether this client is banned.
if(SV_IsBanned(&from, qfalse))
{
NET_OutOfBandPrint(NS_SERVER, from, "print\nYou are banned from this server.\n");
return;
}
Q_strncpyz( userinfo, Cmd_Argv( 1 ), sizeof( userinfo ) );
// Check for GUID
guid = Info_ValueForKey( userinfo, "cl_guid" );
if ( !sv_allowAnonymous->integer && !Sys_IsLANAddress( from ) ) {
if ( !Q_stricmp( guid, "NO_GUID" ) ) {
NET_OutOfBandPrint(NS_SERVER, from, "print\nEmpty CD-Key or GUID not permitted on server.\n");
return;
}
}
// DHM - Nerve :: Update Server allows any protocol to connect
#ifndef UPDATE_SERVER
version = atoi(Info_ValueForKey(userinfo, "protocol"));
#ifdef LEGACY_PROTOCOL
if(version > 0 && com_legacyprotocol->integer == version)
compat = qtrue;
else
#endif
{
if(version != com_protocol->integer)
{
NET_OutOfBandPrint(NS_SERVER, from, "print\nServer uses protocol version %i "
"(yours is %i).\n", com_protocol->integer, version);
Com_DPrintf(" rejected connect from version %i\n", version);
return;
}
}
#endif
challenge = atoi( Info_ValueForKey( userinfo, "challenge" ) );
qport = atoi( Info_ValueForKey( userinfo, "qport" ) );
// quick reject
for ( i = 0,cl = svs.clients ; i < sv_maxclients->integer ; i++,cl++ ) {
if ( NET_CompareBaseAdr( from, cl->netchan.remoteAddress )
&& ( cl->netchan.qport == qport
|| from.port == cl->netchan.remoteAddress.port ) ) {
if ( ( svs.time - cl->lastConnectTime )
< ( sv_reconnectlimit->integer * 1000 ) ) {
Com_DPrintf( "%s:reconnect rejected : too soon\n", NET_AdrToString( from ) );
return;
}
break;
}
}
// don't let "ip" overflow userinfo string
if ( NET_IsLocalAddress (from) )
ip = "localhost";
else
ip = (char *)NET_AdrToString( from );
if( ( strlen( ip ) + strlen( userinfo ) + 4 ) >= MAX_INFO_STRING ) {
NET_OutOfBandPrint( NS_SERVER, from,
"print\nUserinfo string length exceeded. "
"Try removing setu cvars from your config.\n" );
return;
}
Info_SetValueForKey( userinfo, "ip", ip );
// see if the challenge is valid (LAN clients don't need to challenge)
if (!NET_IsLocalAddress(from))
{
int ping;
challenge_t *challengeptr;
for (i=0; i<MAX_CHALLENGES; i++)
{
if (NET_CompareAdr(from, svs.challenges[i].adr))
{
if(challenge == svs.challenges[i].challenge)
break;
}
}
if (i == MAX_CHALLENGES)
{
NET_OutOfBandPrint( NS_SERVER, from, "print\nNo or bad challenge for your address.\n" );
return;
}
challengeptr = &svs.challenges[i];
if(challengeptr->wasrefused)
{
// Return silently, so that error messages written by the server keep being displayed.
return;
}
// force the IP key/value pair so the game can filter based on ip
Info_SetValueForKey( userinfo, "ip", NET_AdrToString( from ) );
if ( svs.challenges[i].firstPing == 0 ) {
ping = svs.time - challengeptr->pingTime;
svs.challenges[i].firstPing = ping;
} else {
ping = svs.challenges[i].firstPing;
}
// never reject a LAN client based on ping
if ( !Sys_IsLANAddress( from ) ) {
if ( sv_minPing->value && ping < sv_minPing->value ) {
NET_OutOfBandPrint( NS_SERVER, from, "print\nServer is for high pings only\n" );
Com_DPrintf( "Client %i rejected on a too low ping\n", i );
challengeptr->wasrefused = qtrue;
return;
}
if ( sv_maxPing->value && ping > sv_maxPing->value ) {
NET_OutOfBandPrint( NS_SERVER, from, "print\nServer is for low pings only\n" );
Com_DPrintf( "Client %i rejected on a too high ping: %i\n", i, ping );
challengeptr->wasrefused = qtrue;
return;
}
}
Com_Printf("Client %i connecting with %i challenge ping\n", i, ping);
challengeptr->connected = qtrue;
}
newcl = &temp;
memset( newcl, 0, sizeof( client_t ) );
// if there is already a slot for this ip, reuse it
for ( i = 0,cl = svs.clients ; i < sv_maxclients->integer ; i++,cl++ ) {
if ( cl->state == CS_FREE ) {
continue;
}
if ( NET_CompareBaseAdr( from, cl->netchan.remoteAddress )
&& ( cl->netchan.qport == qport
|| from.port == cl->netchan.remoteAddress.port ) ) {
Com_Printf( "%s:reconnect\n", NET_AdrToString( from ) );
newcl = cl;
goto gotnewcl;
}
}
// find a client slot
// if "sv_privateClients" is set > 0, then that number
// of client slots will be reserved for connections that
// have "password" set to the value of "sv_privatePassword"
// Info requests will report the maxclients as if the private
// slots didn't exist, to prevent people from trying to connect
// to a full server.
// This is to allow us to reserve a couple slots here on our
// servers so we can play without having to kick people.
// check for privateClient password
password = Info_ValueForKey( userinfo, "password" );
if ( *password && !strcmp( password, sv_privatePassword->string ) ) {
startIndex = 0;
} else {
// skip past the reserved slots
startIndex = sv_privateClients->integer;
}
newcl = NULL;
for ( i = startIndex; i < sv_maxclients->integer ; i++ ) {
cl = &svs.clients[i];
if ( cl->state == CS_FREE ) {
newcl = cl;
break;
}
}
if ( !newcl ) {
if ( NET_IsLocalAddress( from ) ) {
count = 0;
for ( i = startIndex; i < sv_maxclients->integer ; i++ ) {
cl = &svs.clients[i];
if ( cl->netchan.remoteAddress.type == NA_BOT ) {
count++;
}
}
// if they're all bots
if ( count >= sv_maxclients->integer - startIndex ) {
SV_DropClient( &svs.clients[sv_maxclients->integer - 1], "only bots on server" );
newcl = &svs.clients[sv_maxclients->integer - 1];
} else {
Com_Error( ERR_FATAL, "server is full on local connect" );
return;
}
} else {
NET_OutOfBandPrint( NS_SERVER, from, "print\nServer is full.\n" );
Com_DPrintf( "Rejected a connection.\n" );
return;
}
}
// we got a newcl, so reset the reliableSequence and reliableAcknowledge
cl->reliableAcknowledge = 0;
cl->reliableSequence = 0;
gotnewcl:
// build a new connection
// accept the new client
// this is the only place a client_t is ever initialized
*newcl = temp;
clientNum = newcl - svs.clients;
ent = SV_GentityNum( clientNum );
newcl->gentity = ent;
// save the challenge
newcl->challenge = challenge;
// save the address
#ifdef LEGACY_PROTOCOL
newcl->compat = compat;
Netchan_Setup(NS_SERVER, &newcl->netchan, from, qport, challenge, compat);
#else
Netchan_Setup(NS_SERVER, &newcl->netchan, from, qport, challenge, qfalse);
#endif
// init the netchan queue
newcl->netchan_end_queue = &newcl->netchan_start_queue;
// save the userinfo
Q_strncpyz( newcl->userinfo, userinfo, sizeof( newcl->userinfo ) );
// get the game a chance to reject this connection or modify the userinfo
denied = VM_Call( gvm, GAME_CLIENT_CONNECT, clientNum, qtrue, qfalse ); // firstTime = qtrue
if ( denied ) {
// we can't just use VM_ArgPtr, because that is only valid inside a VM_Call
char *str = VM_ExplicitArgPtr( gvm, denied );
NET_OutOfBandPrint( NS_SERVER, from, "print\n%s\n", str );
Com_DPrintf ("Game rejected a connection: %s.\n", str);
return;
}
SV_UserinfoChanged( newcl );
// DHM - Nerve :: Clear out firstPing now that client is connected
svs.challenges[i].firstPing = 0;
// send the connect packet to the client
NET_OutOfBandPrint(NS_SERVER, from, "connectResponse %d", challenge);
Com_DPrintf( "Going from CS_FREE to CS_CONNECTED for %s\n", newcl->name );
newcl->state = CS_CONNECTED;
newcl->lastSnapshotTime = 0;
newcl->lastPacketTime = svs.time;
newcl->lastConnectTime = svs.time;
// when we receive the first packet from the client, we will
// notice that it is from a different serverid and that the
// gamestate message was not just sent, forcing a retransmit
newcl->gamestateMessageNum = -1;
// if this was the first client on the server, or the last client
// the server can hold, send a heartbeat to the master.
count = 0;
for ( i = 0,cl = svs.clients ; i < sv_maxclients->integer ; i++,cl++ ) {
if ( svs.clients[i].state >= CS_CONNECTED ) {
count++;
}
}
if ( count == 1 || count == sv_maxclients->integer ) {
SV_Heartbeat_f();
}
}
/*
=====================
SV_FreeClient
Destructor for data allocated in a client structure
=====================
*/
void SV_FreeClient(client_t *client)
{
#ifdef USE_VOIP
int index;
for(index = client->queuedVoipIndex; index < client->queuedVoipPackets; index++)
{
index %= ARRAY_LEN(client->voipPacket);
Z_Free(client->voipPacket[index]);
}
client->queuedVoipPackets = 0;
#endif
SV_Netchan_FreeQueue(client);
SV_CloseDownload(client);
}
/*
=====================
SV_DropClient
Called when the player is totally leaving the server, either willingly
or unwillingly. This is NOT called if the entire server is quiting
or crashing -- SV_FinalMessage() will handle that
=====================
*/
void SV_DropClient( client_t *drop, const char *reason ) {
int i;
challenge_t *challenge;
const qboolean isBot = drop->netchan.remoteAddress.type == NA_BOT;
if ( drop->state == CS_ZOMBIE ) {
return; // already dropped
}
if ( !isBot ) {
// see if we already have a challenge for this ip
challenge = &svs.challenges[0];
for (i = 0 ; i < MAX_CHALLENGES ; i++, challenge++)
{
if(NET_CompareAdr(drop->netchan.remoteAddress, challenge->adr))
{
Com_Memset(challenge, 0, sizeof(*challenge));
break;
}
}
}
// Free all allocated data on the client structure
SV_FreeClient(drop);
// tell everyone why they got dropped
SV_SendServerCommand( NULL, "print \"[lof]%s" S_COLOR_WHITE " [lon]%s\n\"", drop->name, reason );
// call the prog function for removing a client
// this will remove the body, among other things
VM_Call( gvm, GAME_CLIENT_DISCONNECT, drop - svs.clients );
// add the disconnect command
SV_SendServerCommand( drop, "disconnect \"%s\"", reason );
if ( isBot ) {
SV_BotFreeClient( drop - svs.clients );
// bots shouldn't go zombie, as there's no real net connection.
drop->state = CS_FREE;
} else {
Com_DPrintf( "Going to CS_ZOMBIE for %s\n", drop->name );
drop->state = CS_ZOMBIE; // become free in a few seconds
}
// nuke user info
SV_SetUserinfo( drop - svs.clients, "" );
// if this was the last client on the server, send a heartbeat
// to the master so it is known the server is empty
// send a heartbeat now so the master will get up to date info
// if there is already a slot for this ip, reuse it
for ( i = 0 ; i < sv_maxclients->integer ; i++ ) {
if ( svs.clients[i].state >= CS_CONNECTED ) {
break;
}
}
if ( i == sv_maxclients->integer ) {
SV_Heartbeat_f();
}
}
/*
================
SV_SendClientGameState
Sends the first message from the server to a connected client.
This will be sent on the initial connection and upon each new map load.
It will be resent if the client acknowledges a later message but has
the wrong gamestate.
================
*/
static void SV_SendClientGameState( client_t *client ) {
int start;
entityState_t *base, nullstate;
msg_t msg;
byte msgBuffer[MAX_MSGLEN];
Com_DPrintf( "SV_SendClientGameState() for %s\n", client->name );
Com_DPrintf( "Going from CS_CONNECTED to CS_PRIMED for %s\n", client->name );
client->state = CS_PRIMED;
client->pureAuthentic = 0;
client->gotCP = qfalse;
// when we receive the first packet from the client, we will
// notice that it is from a different serverid and that the
// gamestate message was not just sent, forcing a retransmit
client->gamestateMessageNum = client->netchan.outgoingSequence;
MSG_Init( &msg, msgBuffer, sizeof( msgBuffer ) );
// NOTE, MRE: all server->client messages now acknowledge
// let the client know which reliable clientCommands we have received
MSG_WriteLong( &msg, client->lastClientCommand );
// send any server commands waiting to be sent first.
// we have to do this cause we send the client->reliableSequence
// with a gamestate and it sets the clc.serverCommandSequence at
// the client side
SV_UpdateServerCommandsToClient( client, &msg );
// send the gamestate
MSG_WriteByte( &msg, svc_gamestate );
MSG_WriteLong( &msg, client->reliableSequence );
// write the configstrings
for ( start = 0 ; start < MAX_CONFIGSTRINGS ; start++ ) {
if ( sv.configstrings[start][0] ) {
MSG_WriteByte( &msg, svc_configstring );
MSG_WriteShort( &msg, start );
MSG_WriteBigString( &msg, sv.configstrings[start] );
}
}
// write the baselines
memset( &nullstate, 0, sizeof( nullstate ) );
for ( start = 0 ; start < MAX_GENTITIES; start++ ) {
base = &sv.svEntities[start].baseline;
if ( !base->number ) {
continue;
}
MSG_WriteByte( &msg, svc_baseline );
MSG_WriteDeltaEntity( &msg, &nullstate, base, qtrue );
}
MSG_WriteByte( &msg, svc_EOF );
MSG_WriteLong( &msg, client - svs.clients );
// write the checksum feed
MSG_WriteLong( &msg, sv.checksumFeed );
// deliver this to the client
SV_SendMessageToClient( &msg, client );
}
/*
==================
SV_ClientEnterWorld
==================
*/
void SV_ClientEnterWorld( client_t *client, usercmd_t *cmd ) {
int clientNum;
sharedEntity_t *ent;
Com_DPrintf( "Going from CS_PRIMED to CS_ACTIVE for %s\n", client->name );
client->state = CS_ACTIVE;
// resend all configstrings using the cs commands since these are
// no longer sent when the client is CS_PRIMED
SV_UpdateConfigstrings( client );
// set up the entity for the client
clientNum = client - svs.clients;
ent = SV_GentityNum( clientNum );
ent->s.number = clientNum;
client->gentity = ent;
client->deltaMessage = -1;
client->lastSnapshotTime = 0; // generate a snapshot immediately
if(cmd)
memcpy(&client->lastUsercmd, cmd, sizeof(client->lastUsercmd));
else
memset(&client->lastUsercmd, '\0', sizeof(client->lastUsercmd));
// call the game begin function
VM_Call( gvm, GAME_CLIENT_BEGIN, client - svs.clients );
}
/*
============================================================
CLIENT COMMAND EXECUTION
============================================================
*/
/*
==================
SV_CloseDownload
clear/free any download vars
==================
*/
static void SV_CloseDownload( client_t *cl ) {
int i;
// EOF
if ( cl->download ) {
FS_FCloseFile( cl->download );
}
cl->download = 0;
*cl->downloadName = 0;
// Free the temporary buffer space
for ( i = 0; i < MAX_DOWNLOAD_WINDOW; i++ ) {
if ( cl->downloadBlocks[i] ) {
Z_Free( cl->downloadBlocks[i] );
cl->downloadBlocks[i] = NULL;
}
}
}
/*
==================
SV_StopDownload_f
Abort a download if in progress
==================
*/
static void SV_StopDownload_f( client_t *cl ) {
if ( *cl->downloadName ) {
Com_DPrintf( "clientDownload: %d : file \"%s\" aborted\n", (int) (cl - svs.clients), cl->downloadName );
}
SV_CloseDownload( cl );
}
/*
==================
SV_DoneDownload_f
Downloads are finished
==================
*/
static void SV_DoneDownload_f( client_t *cl ) {
if ( cl->state == CS_ACTIVE )
return;
Com_DPrintf( "clientDownload: %s Done\n", cl->name );
// resend the game state to update any clients that entered during the download
SV_SendClientGameState( cl );
}
/*
==================
SV_NextDownload_f
The argument will be the last acknowledged block from the client, it should be
the same as cl->downloadClientBlock
==================
*/
static void SV_NextDownload_f( client_t *cl ) {
int block = atoi( Cmd_Argv( 1 ) );
if ( block == cl->downloadClientBlock ) {
Com_DPrintf( "clientDownload: %d : client acknowledge of block %d\n", (int) (cl - svs.clients), block );
// Find out if we are done. A zero-length block indicates EOF
if ( cl->downloadBlockSize[cl->downloadClientBlock % MAX_DOWNLOAD_WINDOW] == 0 ) {
Com_Printf( "clientDownload: %d : file \"%s\" completed\n", (int) (cl - svs.clients), cl->downloadName );
SV_CloseDownload( cl );
return;
}
cl->downloadSendTime = svs.time;
cl->downloadClientBlock++;
return;
}
// We aren't getting an acknowledge for the correct block, drop the client
// FIXME: this is bad... the client will never parse the disconnect message
// because the cgame isn't loaded yet
SV_DropClient( cl, "broken download" );
}
/*
==================
SV_BeginDownload_f
==================
*/
static void SV_BeginDownload_f( client_t *cl ) {
// Kill any existing download
SV_CloseDownload( cl );
// cl->downloadName is non-zero now, SV_WriteDownloadToClient will see this and open
// the file itself
Q_strncpyz( cl->downloadName, Cmd_Argv( 1 ), sizeof( cl->downloadName ) );
}
/*
==================
SV_WriteDownloadToClient
Check to see if the client wants a file, open it if needed and start pumping the client
Fill up msg with data, return number of download blocks added
==================
*/
int SV_WriteDownloadToClient( client_t *cl, msg_t *msg ) {
int curindex;
int unreferenced = 1;
char errorMessage[1024];
char pakbuf[MAX_QPATH], *pakptr;
int numRefPaks;
#ifdef UPDATE_SERVER
int i;
char testname[MAX_QPATH];
#endif
if ( !*cl->downloadName ) {
return 0;
}
#ifndef UPDATE_SERVER
// CVE-2006-2082
// validate the download against the list of pak files
if ( !FS_VerifyPak( cl->downloadName ) ) {
// will drop the client and leave it hanging on the other side. good for him
SV_DropClient( cl, "illegal download request" );
return 0;
}
#endif
if(!cl->download)
{
qboolean idPack = qfalse;
// Chop off filename extension.
Com_sprintf(pakbuf, sizeof(pakbuf), "%s", cl->downloadName);
pakptr = strrchr(pakbuf, '.');
if(pakptr)
{
*pakptr = '\0';
// Check for pk3 filename extension
if(!Q_stricmp(pakptr + 1, "pk3"))
{
const char *referencedPaks = FS_ReferencedPakNames();
// Check whether the file appears in the list of referenced
// paks to prevent downloading of arbitrary files.
Cmd_TokenizeStringIgnoreQuotes(referencedPaks);
numRefPaks = Cmd_Argc();
for(curindex = 0; curindex < numRefPaks; curindex++)
{
if(!FS_FilenameCompare(Cmd_Argv(curindex), pakbuf))
{
unreferenced = 0;
// now that we know the file is referenced,
// check whether it's legal to download it.
idPack = idPack || FS_idPak(pakbuf, BASEGAME, NUM_ID_PAKS);
break;
}
}
}
}
// DHM - Nerve :: Update server only allows files that are in versionmap.cfg to download
#ifdef UPDATE_SERVER
for ( i = 0; i < numVersions; i++ ) {
strcpy( testname, "updates/" );
Q_strcat( testname, MAX_QPATH, versionMap[ i ].installer );
if ( !Q_stricmp( cl->downloadName, testname ) ) {
break;
}
}
if ( i == numVersions ) {
MSG_WriteByte( msg, svc_download );
MSG_WriteShort( msg, 0 ); // client is expecting block zero
MSG_WriteLong( msg, -1 ); // illegal file size
Com_sprintf( errorMessage, sizeof( errorMessage ), "Invalid download from update server" );
MSG_WriteString( msg, errorMessage );
*cl->downloadName = 0;
SV_DropClient( cl, "Invalid download from update server" );
return 0;
}
#endif
// DHM - Nerve
cl->download = 0;
// We open the file here
if ( !(sv_allowDownload->integer & DLF_ENABLE) ||
(sv_allowDownload->integer & DLF_NO_UDP) ||
idPack ||
#ifndef UPDATE_SERVER
unreferenced ||
#endif
( cl->downloadSize = FS_SV_FOpenFileRead( cl->downloadName, &cl->download ) ) < 0 ) {
// cannot auto-download file
if(unreferenced)
{
Com_Printf("clientDownload: %d : \"%s\" is not referenced and cannot be downloaded.\n", (int) (cl - svs.clients), cl->downloadName);
Com_sprintf(errorMessage, sizeof(errorMessage), "File \"%s\" is not referenced and cannot be downloaded.", cl->downloadName);
}
else if (idPack) {
Com_Printf("clientDownload: %d : \"%s\" cannot download id pk3 files\n", (int) (cl - svs.clients), cl->downloadName);
Com_sprintf( errorMessage, sizeof( errorMessage ), "Cannot autodownload id pk3 file \"%s\"", cl->downloadName );
} else if (( !sv_allowDownload->integer & DLF_ENABLE) || (sv_allowDownload->integer & DLF_NO_UDP)) {
Com_Printf( "clientDownload: %d : \"%s\" download disabled\n", (int) (cl - svs.clients), cl->downloadName );
if ( sv_pure->integer ) {
Com_sprintf( errorMessage, sizeof( errorMessage ), "Could not download \"%s\" because autodownloading is disabled on the server.\n\n"
"You will need to get this file elsewhere before you "
"can connect to this pure server.\n", cl->downloadName );
} else {
Com_sprintf( errorMessage, sizeof( errorMessage ), "Could not download \"%s\" because autodownloading is disabled on the server.\n\n"
"Set autodownload to No in your settings and you might be "
"able to connect even if you do have the file.\n", cl->downloadName );
}
} else {
Com_Printf( "clientDownload: %d : \"%s\" file not found on server\n", (int) (cl - svs.clients), cl->downloadName );
Com_sprintf( errorMessage, sizeof( errorMessage ), "File \"%s\" not found on server for autodownloading.\n", cl->downloadName );
}
MSG_WriteByte( msg, svc_download );
MSG_WriteShort( msg, 0 ); // client is expecting block zero
MSG_WriteLong( msg, -1 ); // illegal file size
MSG_WriteString( msg, errorMessage );
*cl->downloadName = 0;
if(cl->download)
FS_FCloseFile(cl->download);
return 1;
}
Com_Printf( "clientDownload: %d : beginning \"%s\"\n", (int) (cl - svs.clients), cl->downloadName );
// Init
cl->downloadCurrentBlock = cl->downloadClientBlock = cl->downloadXmitBlock = 0;
cl->downloadCount = 0;
cl->downloadEOF = qfalse;
}
// Perform any reads that we need to
while ( cl->downloadCurrentBlock - cl->downloadClientBlock < MAX_DOWNLOAD_WINDOW &&
cl->downloadSize != cl->downloadCount ) {
curindex = ( cl->downloadCurrentBlock % MAX_DOWNLOAD_WINDOW );
if ( !cl->downloadBlocks[curindex] ) {
cl->downloadBlocks[curindex] = Z_Malloc( MAX_DOWNLOAD_BLKSIZE );
}
cl->downloadBlockSize[curindex] = FS_Read( cl->downloadBlocks[curindex], MAX_DOWNLOAD_BLKSIZE, cl->download );
if ( cl->downloadBlockSize[curindex] < 0 ) {
// EOF right now
cl->downloadCount = cl->downloadSize;
break;
}
cl->downloadCount += cl->downloadBlockSize[curindex];
// Load in next block
cl->downloadCurrentBlock++;
}
// Check to see if we have eof condition and add the EOF block
if ( cl->downloadCount == cl->downloadSize &&
!cl->downloadEOF &&
cl->downloadCurrentBlock - cl->downloadClientBlock < MAX_DOWNLOAD_WINDOW ) {
cl->downloadBlockSize[cl->downloadCurrentBlock % MAX_DOWNLOAD_WINDOW] = 0;
cl->downloadCurrentBlock++;
cl->downloadEOF = qtrue; // We have added the EOF block
}
if (cl->downloadClientBlock == cl->downloadCurrentBlock)
return 0; // Nothing to transmit
// Write out the next section of the file, if we have already reached our window,
// automatically start retransmitting
if (cl->downloadXmitBlock == cl->downloadCurrentBlock)
{
// We have transmitted the complete window, should we start resending?
if (svs.time - cl->downloadSendTime > 1000)
cl->downloadXmitBlock = cl->downloadClientBlock;
else
return 0;
}
// Send current block
curindex = (cl->downloadXmitBlock % MAX_DOWNLOAD_WINDOW);
MSG_WriteByte( msg, svc_download );
MSG_WriteShort( msg, cl->downloadXmitBlock );
// block zero is special, contains file size
if ( cl->downloadXmitBlock == 0 )
MSG_WriteLong( msg, cl->downloadSize );
MSG_WriteShort( msg, cl->downloadBlockSize[curindex] );
// Write the block
if(cl->downloadBlockSize[curindex])
MSG_WriteData(msg, cl->downloadBlocks[curindex], cl->downloadBlockSize[curindex]);
Com_DPrintf( "clientDownload: %d : writing block %d\n", (int) (cl - svs.clients), cl->downloadXmitBlock );
// Move on to the next block
// It will get sent with next snap shot. The rate will keep us in line.
cl->downloadXmitBlock++;
cl->downloadSendTime = svs.time;
return 1;
}
/*
==================
SV_SendQueuedMessages
Send one round of fragments, or queued messages to all clients that have data pending.
Return the shortest time interval for sending next packet to client
==================
*/
int SV_SendQueuedMessages(void)
{
int i, retval = -1, nextFragT;
client_t *cl;
for(i=0; i < sv_maxclients->integer; i++)
{
cl = &svs.clients[i];
if(cl->state)
{
nextFragT = SV_RateMsec(cl);
if(!nextFragT)
nextFragT = SV_Netchan_TransmitNextFragment(cl);
if(nextFragT >= 0 && (retval == -1 || retval > nextFragT))
retval = nextFragT;
}
}
return retval;
}
/*
==================
SV_SendDownloadMessages
Send one round of download messages to all clients
==================
*/
int SV_SendDownloadMessages(void)
{
int i, numDLs = 0, retval;
client_t *cl;
msg_t msg;
byte msgBuffer[MAX_MSGLEN];
for(i=0; i < sv_maxclients->integer; i++)
{
cl = &svs.clients[i];
if(cl->state && *cl->downloadName)
{
MSG_Init(&msg, msgBuffer, sizeof(msgBuffer));
MSG_WriteLong(&msg, cl->lastClientCommand);
retval = SV_WriteDownloadToClient(cl, &msg);
if(retval)
{
MSG_WriteByte(&msg, svc_EOF);
SV_Netchan_Transmit(cl, &msg);
numDLs += retval;
}
}
}
return numDLs;
}
/*
=================
SV_Disconnect_f
The client is going to disconnect, so remove the connection immediately FIXME: move to game?
=================
*/
static void SV_Disconnect_f( client_t *cl ) {
SV_DropClient( cl, "disconnected" );
}
// Paths in pk3s to allowing using as cgame and ui VM.
// Must be in pk3 with same checksum on server and client.
char *sv_pureVMPaths[] = {
// QVM names
"vm/%s.mp.qvm",
// Files in original mp_bin.pk3
"%s_mp_x86.dll",
"%s.mp.i386.so",
// Other VM names used by the game which could be put in a pk3.
// They would be loaded by clients so it makes no sense to kick for using them.
"%s_mp_x86_64.dll",
"%s.mp.x86_64.so",
"%s.mp.i386.dylib",
"%s.mp.x86_64.dylib",
"%s.mp.ppc.dylib"
};
const int sv_numPureVMPaths = ARRAY_LEN( sv_pureVMPaths );
/*
=================
SV_VerifyPaks_f
If we are pure, disconnect the client if they do no meet the following conditions:
1. the first two checksums match our view of cgame and ui DLLs
Wolf specific: the checksum is the checksum of the pk3 we found the DLL in
2. there are no any additional checksums that we do not have
This routine would be a bit simpler with a goto but i abstained
=================
*/
static void SV_VerifyPaks_f( client_t *cl ) {
int nChkSum1, nClientPaks, nServerPaks, i, j, nCurArg;
int nClientChkSum[1024];
int nServerChkSum[1024];
const char *pPaks, *pArg;
qboolean bGood = qtrue;
// if we are pure, we "expect" the client to load certain things from
// certain pk3 files, namely we want the client to have loaded the
// ui and cgame that we think should be loaded based on the pure setting
if ( sv_pure->integer != 0 ) {
nClientPaks = Cmd_Argc();
// start at arg 2 ( skip serverId cl_paks )
nCurArg = 1;
pArg = Cmd_Argv( nCurArg++ );
if ( !pArg ) {
bGood = qfalse;
} else
{
// show_bug.cgi?id=475
// we may get incoming cp sequences from a previous checksumFeed, which we need to ignore
// since serverId is a frame count, it always goes up
if ( atoi( pArg ) < sv.checksumFeedServerId ) {
Com_DPrintf( "ignoring outdated cp command from client %s\n", cl->name );
return;
}
}
// we basically use this while loop to avoid using 'goto' :)
while ( bGood ) {
// must be at least 6: "cl_paks cgame ui @ firstref ... numChecksums"
// numChecksums is encoded
if ( nClientPaks < 6 ) {
bGood = qfalse;
break;
}
// verify first to be the cgame checksum
pArg = Cmd_Argv( nCurArg++ );
if ( !pArg || *pArg == '@' ) {
bGood = qfalse;
break;
}
// check valid cgame checksums
for ( i = 0; i < sv_numPureVMPaths; i++ ) {
if ( FS_FileIsInPAK( va( sv_pureVMPaths[i], "cgame" ), &nChkSum1 ) == 1 && atoi( pArg ) == nChkSum1 ) {
break;
}
}
if ( i == sv_numPureVMPaths ) {
bGood = qfalse;
break;
}
// verify the second to be the ui checksum
pArg = Cmd_Argv( nCurArg++ );
if ( !pArg || *pArg == '@' ) {
bGood = qfalse;
break;
}
// check valid ui checksums
for ( i = 0; i < sv_numPureVMPaths; i++ ) {
if ( FS_FileIsInPAK( va( sv_pureVMPaths[i], "ui" ), &nChkSum1 ) == 1 && atoi( pArg ) == nChkSum1 ) {
break;
}
}
if ( i == sv_numPureVMPaths ) {
bGood = qfalse;
break;
}
// should be sitting at the delimeter now
pArg = Cmd_Argv( nCurArg++ );
if ( *pArg != '@' ) {
bGood = qfalse;
break;
}
// store checksums since tokenization is not re-entrant
for ( i = 0; nCurArg < nClientPaks; i++ ) {
nClientChkSum[i] = atoi( Cmd_Argv( nCurArg++ ) );
}
// store number to compare against (minus one cause the last is the number of checksums)
nClientPaks = i - 1;
// make sure none of the client check sums are the same
// so the client can't send 5 the same checksums
for ( i = 0; i < nClientPaks; i++ ) {
for ( j = 0; j < nClientPaks; j++ ) {
if ( i == j ) {
continue;
}
if ( nClientChkSum[i] == nClientChkSum[j] ) {
bGood = qfalse;
break;
}
}
if ( bGood == qfalse ) {
break;
}
}
if ( bGood == qfalse ) {
break;
}
// get the pure checksums of the pk3 files loaded by the server
pPaks = FS_LoadedPakPureChecksums();
Cmd_TokenizeString( pPaks );
nServerPaks = Cmd_Argc();
if ( nServerPaks > 1024 ) {
nServerPaks = 1024;
}
for ( i = 0; i < nServerPaks; i++ ) {
nServerChkSum[i] = atoi( Cmd_Argv( i ) );
}
// check if the client has provided any pure checksums of pk3 files not loaded by the server
for ( i = 0; i < nClientPaks; i++ ) {
for ( j = 0; j < nServerPaks; j++ ) {
if ( nClientChkSum[i] == nServerChkSum[j] ) {
break;
}
}
if ( j >= nServerPaks ) {
bGood = qfalse;
break;
}
}
if ( bGood == qfalse ) {
break;
}
// check if the number of checksums was correct
nChkSum1 = sv.checksumFeed;
for ( i = 0; i < nClientPaks; i++ ) {
nChkSum1 ^= nClientChkSum[i];
}
nChkSum1 ^= nClientPaks;
if ( nChkSum1 != nClientChkSum[nClientPaks] ) {
bGood = qfalse;
break;
}
// break out
break;
}
cl->gotCP = qtrue;
if ( bGood ) {
cl->pureAuthentic = 1;
} else {
cl->pureAuthentic = 0;
cl->lastSnapshotTime = 0;
cl->state = CS_ACTIVE;
SV_SendClientSnapshot( cl );
SV_DropClient( cl, "Unpure client detected. Invalid .PK3 files referenced!" );
}
}
}
/*
=================
SV_ResetPureClient_f
=================
*/
static void SV_ResetPureClient_f( client_t *cl ) {
cl->pureAuthentic = 0;
cl->gotCP = qfalse;
}
/*
=================
SV_UserinfoChanged
Pull specific info from a newly changed userinfo string
into a more C friendly form.
=================
*/
void SV_UserinfoChanged( client_t *cl ) {
char *val;
char *ip;
char *guid;
char *name;
char gname[MAX_QPATH];
int i;
int len;
// name for C code
name = Info_ValueForKey( cl->userinfo, "name" );
guid = Info_ValueForKey( cl->userinfo, "cl_guid" );
if ( sv_forceNameUniq->integer == 1 ) {
if ( !Q_stricmp( name, "" ) || !Q_stricmp( name, "WolfPlayer" ) || !Q_stricmp( name, "UnnamedPlayer" ) ) {
Com_sprintf( gname, sizeof( gname ), "%s %s", name, guid + 24 );
Info_SetValueForKey( cl->userinfo, "name", gname );
}
} else if ( sv_forceNameUniq->integer == 2 ) {
Com_sprintf( gname, sizeof( gname ), "%s %s", name, guid + 24 );
Info_SetValueForKey( cl->userinfo, "name", gname );
}
Q_strncpyz( cl->name, name, sizeof( cl->name ) );
// rate command
// if the client is on the same subnet as the server and we aren't running an
// internet public server, assume they don't need a rate choke
if ( Sys_IsLANAddress( cl->netchan.remoteAddress ) && com_dedicated->integer != 2 && sv_lanForceRate->integer == 1 ) {
cl->rate = 99999; // lans should not rate limit
} else {
val = Info_ValueForKey( cl->userinfo, "rate" );
if ( strlen( val ) ) {
i = atoi( val );
cl->rate = i;
if ( cl->rate < 1000 ) {
cl->rate = 1000;
} else if ( cl->rate > 90000 ) {
cl->rate = 90000;
}
} else {
cl->rate = 5000;
}
}
val = Info_ValueForKey( cl->userinfo, "handicap" );
if ( strlen( val ) ) {
i = atoi( val );
if ( i <= 0 || i > 100 || strlen( val ) > 4 ) {
Info_SetValueForKey( cl->userinfo, "handicap", "100" );
}
}
// snaps command
val = Info_ValueForKey (cl->userinfo, "snaps");
if(strlen(val))
{
i = atoi(val);
if(i < 1)
i = 1;
else if(i > sv_fps->integer)
i = sv_fps->integer;
i = 1000 / i;
}
else
i = 50;
if(i != cl->snapshotMsec)
{
// Reset last sent snapshot so we avoid desync between server frame time and snapshot send time
cl->lastSnapshotTime = 0;
cl->snapshotMsec = i;
}
#ifdef USE_VOIP
#ifdef LEGACY_PROTOCOL
if(cl->compat)
cl->hasVoip = qfalse;
else
#endif
{
val = Info_ValueForKey(cl->userinfo, "cl_voipProtocol");
cl->hasVoip = !Q_stricmp( val, "opus" );
}
#endif
// TTimo
// maintain the IP information
// the banning code relies on this being consistently present
if( NET_IsLocalAddress(cl->netchan.remoteAddress) )
ip = "localhost";
else
ip = (char*)NET_AdrToString( cl->netchan.remoteAddress );
val = Info_ValueForKey( cl->userinfo, "ip" );
if( val[0] )
len = strlen( ip ) - strlen( val ) + strlen( cl->userinfo );
else
len = strlen( ip ) + 4 + strlen( cl->userinfo );
if( len >= MAX_INFO_STRING )
SV_DropClient( cl, "userinfo string length exceeded" );
else
Info_SetValueForKey( cl->userinfo, "ip", ip );
}
/*
==================
SV_UpdateUserinfo_f
==================
*/
static void SV_UpdateUserinfo_f( client_t *cl ) {
Q_strncpyz( cl->userinfo, Cmd_Argv( 1 ), sizeof( cl->userinfo ) );
SV_UserinfoChanged( cl );
// call prog code to allow overrides
VM_Call( gvm, GAME_CLIENT_USERINFO_CHANGED, cl - svs.clients );
}
#ifdef USE_VOIP
static
void SV_UpdateVoipIgnore(client_t *cl, const char *idstr, qboolean ignore)
{
if ((*idstr >= '0') && (*idstr <= '9')) {
const int id = atoi(idstr);
if ((id >= 0) && (id < MAX_CLIENTS)) {
cl->ignoreVoipFromClient[id] = ignore;
}
}
}
/*
==================
SV_Voip_f
==================
*/
static void SV_Voip_f( client_t *cl ) {
const char *cmd = Cmd_Argv(1);
if (strcmp(cmd, "ignore") == 0) {
SV_UpdateVoipIgnore(cl, Cmd_Argv(2), qtrue);
} else if (strcmp(cmd, "unignore") == 0) {
SV_UpdateVoipIgnore(cl, Cmd_Argv(2), qfalse);
} else if (strcmp(cmd, "muteall") == 0) {
cl->muteAllVoip = qtrue;
} else if (strcmp(cmd, "unmuteall") == 0) {
cl->muteAllVoip = qfalse;
}
}
#endif
typedef struct {
char *name;
void ( *func )( client_t *cl );
} ucmd_t;
static ucmd_t ucmds[] = {
{"userinfo", SV_UpdateUserinfo_f},
{"disconnect", SV_Disconnect_f},
{"cp", SV_VerifyPaks_f},
{"vdr", SV_ResetPureClient_f},
{"download", SV_BeginDownload_f},
{"nextdl", SV_NextDownload_f},
{"stopdl", SV_StopDownload_f},
{"donedl", SV_DoneDownload_f},
#ifdef USE_VOIP
{"voip", SV_Voip_f},
#endif
{NULL, NULL}
};
/*
==================
SV_ExecuteClientCommand
Also called by bot code
==================
*/
void SV_ExecuteClientCommand( client_t *cl, const char *s, qboolean clientOK ) {
ucmd_t *u;
qboolean bProcessed = qfalse;
Cmd_TokenizeString( s );
// see if it is a server level command
for ( u = ucmds ; u->name ; u++ ) {
if ( !strcmp( Cmd_Argv( 0 ), u->name ) ) {
u->func( cl );
bProcessed = qtrue;
break;
}
}
if ( clientOK ) {
// pass unknown strings to the game
if (!u->name && sv.state == SS_GAME && (cl->state == CS_ACTIVE || cl->state == CS_PRIMED)) {
Cmd_Args_Sanitize();
VM_Call( gvm, GAME_CLIENT_COMMAND, cl - svs.clients );
}
} else if ( !bProcessed ) {
Com_DPrintf( "client text ignored for %s: %s\n", cl->name, Cmd_Argv( 0 ) );
}
}
/*
===============
SV_ClientCommand
===============
*/
static qboolean SV_ClientCommand( client_t *cl, msg_t *msg ) {
int seq;
const char *s;
qboolean clientOk = qtrue;
qboolean floodprotect = qtrue;
seq = MSG_ReadLong( msg );
s = MSG_ReadString( msg );
// see if we have already executed it
if ( cl->lastClientCommand >= seq ) {
return qtrue;
}
Com_DPrintf( "clientCommand: %s : %i : %s\n", cl->name, seq, s );
// drop the connection if we have somehow lost commands
if ( seq > cl->lastClientCommand + 1 ) {
Com_Printf( "Client %s lost %i clientCommands\n", cl->name,
seq - cl->lastClientCommand + 1 );
SV_DropClient( cl, "Lost reliable commands" );
return qfalse;
}
// NERVE - SMF - some server game-only commands we cannot have flood protect
if ( !Q_strncmp( "team", s, 4 ) || !Q_strncmp( "setspawnpt", s, 10 ) || !Q_strncmp( "score", s, 5 ) ) {
// Com_DPrintf( "Skipping flood protection for: %s\n", s );
floodprotect = qfalse;
}
// malicious users may try using too many string commands
// to lag other players. If we decide that we want to stall
// the command, we will stop processing the rest of the packet,
// including the usercmd. This causes flooders to lag themselves
// but not other people
// We don't do this when the client hasn't been active yet since it's
// normal to spam a lot of commands when downloading
if ( !com_cl_running->integer &&
cl->state >= CS_ACTIVE && // (SA) this was commented out in Wolf. Did we do that?
sv_floodProtect->integer &&
svs.time < cl->nextReliableTime &&
floodprotect ) {
// ignore any other text messages from this client but let them keep playing
// TTimo - moved the ignored verbose to the actual processing in SV_ExecuteClientCommand, only printing if the core doesn't intercept
clientOk = qfalse;
}
// don't allow another command for one second
if ( floodprotect ) {
cl->nextReliableTime = svs.time + 800;
}
SV_ExecuteClientCommand( cl, s, clientOk );
cl->lastClientCommand = seq;
Com_sprintf( cl->lastClientCommandString, sizeof( cl->lastClientCommandString ), "%s", s );
return qtrue; // continue procesing
}
//==================================================================================
/*
==================
SV_ClientThink
Also called by bot code
==================
*/
void SV_ClientThink( client_t *cl, usercmd_t *cmd ) {
cl->lastUsercmd = *cmd;
if ( cl->state != CS_ACTIVE ) {
return; // may have been kicked during the last usercmd
}
VM_Call( gvm, GAME_CLIENT_THINK, cl - svs.clients );
}
/*
==================
SV_UserMove
The message usually contains all the movement commands
that were in the last three packets, so that the information
in dropped packets can be recovered.
On very fast clients, there may be multiple usercmd packed into
each of the backup packets.
==================
*/
static void SV_UserMove( client_t *cl, msg_t *msg, qboolean delta ) {
int i, key;
int cmdCount;
usercmd_t nullcmd;
usercmd_t cmds[MAX_PACKET_USERCMDS];
usercmd_t *cmd, *oldcmd;
if ( delta ) {
cl->deltaMessage = cl->messageAcknowledge;
} else {
cl->deltaMessage = -1;
}
cmdCount = MSG_ReadByte( msg );
if ( cmdCount < 1 ) {
Com_Printf( "cmdCount < 1\n" );
return;
}
if ( cmdCount > MAX_PACKET_USERCMDS ) {
Com_Printf( "cmdCount > MAX_PACKET_USERCMDS\n" );
return;
}
// use the checksum feed in the key
key = sv.checksumFeed;
// also use the message acknowledge
key ^= cl->messageAcknowledge;
// also use the last acknowledged server command in the key
key ^= MSG_HashKey(cl->reliableCommands[ cl->reliableAcknowledge & (MAX_RELIABLE_COMMANDS-1) ], 32);
memset( &nullcmd, 0, sizeof( nullcmd ) );
oldcmd = &nullcmd;
for ( i = 0 ; i < cmdCount ; i++ ) {
cmd = &cmds[i];
MSG_ReadDeltaUsercmdKey( msg, key, oldcmd, cmd );
// MSG_ReadDeltaUsercmd( msg, oldcmd, cmd );
oldcmd = cmd;
}
// save time for ping calculation
cl->frames[ cl->messageAcknowledge & PACKET_MASK ].messageAcked = svs.time;
// TTimo
// catch the no-cp-yet situation before SV_ClientEnterWorld
// if CS_ACTIVE, then it's time to trigger a new gamestate emission
// if not, then we are getting remaining parasite usermove commands, which we should ignore
if ( sv_pure->integer != 0 && cl->pureAuthentic == 0 && !cl->gotCP ) {
if ( cl->state == CS_ACTIVE ) {
// we didn't get a cp yet, don't assume anything and just send the gamestate all over again
Com_DPrintf( "%s: didn't get cp command, resending gamestate\n", cl->name );
SV_SendClientGameState( cl );
}
return;
}
// if this is the first usercmd we have received
// this gamestate, put the client into the world
if ( cl->state == CS_PRIMED ) {
SV_ClientEnterWorld( cl, &cmds[0] );
// the moves can be processed normaly
}
// a bad cp command was sent, drop the client
if ( sv_pure->integer != 0 && cl->pureAuthentic == 0 ) {
SV_DropClient( cl, "Cannot validate pure client!" );
return;
}
if ( cl->state != CS_ACTIVE ) {
cl->deltaMessage = -1;
return;
}
// usually, the first couple commands will be duplicates
// of ones we have previously received, but the servertimes
// in the commands will cause them to be immediately discarded
for ( i = 0 ; i < cmdCount ; i++ ) {
// if this is a cmd from before a map_restart ignore it
if ( cmds[i].serverTime > cmds[cmdCount - 1].serverTime ) {
continue;
}
// extremely lagged or cmd from before a map_restart
//if ( cmds[i].serverTime > svs.time + 3000 ) {
// continue;
//}
if ( sv_gametype->integer != GT_SINGLE_PLAYER ) { // RF, we need to allow this in single player, where loadgame's can cause the player to freeze after reloading if we do this check
// don't execute if this is an old cmd which is already executed
// these old cmds are included when cl_packetdup > 0
if ( cmds[i].serverTime <= cl->lastUsercmd.serverTime ) { // Q3_MISSIONPACK
// if ( cmds[i].serverTime > cmds[cmdCount-1].serverTime ) {
continue; // from just before a map_restart
}
}
SV_ClientThink( cl, &cmds[ i ] );
}
}
#ifdef USE_VOIP
/*
==================
SV_ShouldIgnoreVoipSender
Blocking of voip packets based on source client
==================
*/
static qboolean SV_ShouldIgnoreVoipSender(const client_t *cl)
{
if (!sv_voip->integer)
return qtrue; // VoIP disabled on this server.
else if (!cl->hasVoip) // client doesn't have VoIP support?!
return qtrue;
// !!! FIXME: implement player blacklist.
return qfalse; // don't ignore.
}
static
void SV_UserVoip(client_t *cl, msg_t *msg, qboolean ignoreData)
{
int sender, generation, sequence, frames, packetsize;
uint8_t recips[(MAX_CLIENTS + 7) / 8];
int flags;
byte encoded[sizeof(cl->voipPacket[0]->data)];
client_t *client = NULL;
voipServerPacket_t *packet = NULL;
int i;
sender = cl - svs.clients;
generation = MSG_ReadByte(msg);
sequence = MSG_ReadLong(msg);
frames = MSG_ReadByte(msg);
MSG_ReadData(msg, recips, sizeof(recips));
flags = MSG_ReadByte(msg);
packetsize = MSG_ReadShort(msg);
if (msg->readcount > msg->cursize)
return; // short/invalid packet, bail.
if (packetsize > sizeof (encoded)) { // overlarge packet?
int bytesleft = packetsize;
while (bytesleft) {
int br = bytesleft;
if (br > sizeof (encoded))
br = sizeof (encoded);
MSG_ReadData(msg, encoded, br);
bytesleft -= br;
}
return; // overlarge packet, bail.
}
MSG_ReadData(msg, encoded, packetsize);
if (ignoreData || SV_ShouldIgnoreVoipSender(cl))
return; // Blacklisted, disabled, etc.
// !!! FIXME: see if we read past end of msg...
// !!! FIXME: reject if not opus data.
// !!! FIXME: decide if this is bogus data?
// decide who needs this VoIP packet sent to them...
for (i = 0, client = svs.clients; i < sv_maxclients->integer ; i++, client++) {
if (client->state != CS_ACTIVE)
continue; // not in the game yet, don't send to this guy.
else if (i == sender)
continue; // don't send voice packet back to original author.
else if (!client->hasVoip)
continue; // no VoIP support, or unsupported protocol
else if (client->muteAllVoip)
continue; // client is ignoring everyone.
else if (client->ignoreVoipFromClient[sender])
continue; // client is ignoring this talker.
else if (*cl->downloadName) // !!! FIXME: possible to DoS?
continue; // no VoIP allowed if downloading, to save bandwidth.
if(Com_IsVoipTarget(recips, sizeof(recips), i))
flags |= VOIP_DIRECT;
else
flags &= ~VOIP_DIRECT;
if (!(flags & (VOIP_SPATIAL | VOIP_DIRECT)))
continue; // not addressed to this player.
// Transmit this packet to the client.
if (client->queuedVoipPackets >= ARRAY_LEN(client->voipPacket)) {
Com_Printf("Too many VoIP packets queued for client #%d\n", i);
continue; // no room for another packet right now.
}
packet = Z_Malloc(sizeof(*packet));
packet->sender = sender;
packet->frames = frames;
packet->len = packetsize;
packet->generation = generation;
packet->sequence = sequence;
packet->flags = flags;
memcpy(packet->data, encoded, packetsize);
client->voipPacket[(client->queuedVoipIndex + client->queuedVoipPackets) % ARRAY_LEN(client->voipPacket)] = packet;
client->queuedVoipPackets++;
}
}
#endif
/*
===========================================================================
USER CMD EXECUTION
===========================================================================
*/
/*
===================
SV_ExecuteClientMessage
Parse a client packet
===================
*/
void SV_ExecuteClientMessage( client_t *cl, msg_t *msg ) {
int c;
int serverId;
MSG_Bitstream( msg );
serverId = MSG_ReadLong( msg );
cl->messageAcknowledge = MSG_ReadLong( msg );
if ( cl->messageAcknowledge < 0 ) {
// usually only hackers create messages like this
// it is more annoying for them to let them hanging
#ifndef NDEBUG
SV_DropClient( cl, "DEBUG: illegible client message" );
#endif
return;
}
cl->reliableAcknowledge = MSG_ReadLong( msg );
// NOTE: when the client message is fux0red the acknowledgement numbers
// can be out of range, this could cause the server to send thousands of server
// commands which the server thinks are not yet acknowledged in SV_UpdateServerCommandsToClient
if ( cl->reliableAcknowledge < cl->reliableSequence - MAX_RELIABLE_COMMANDS ) {
// usually only hackers create messages like this
// it is more annoying for them to let them hanging
#ifndef NDEBUG
SV_DropClient( cl, "DEBUG: illegible client message" );
#endif
cl->reliableAcknowledge = cl->reliableSequence;
return;
}
// if this is a usercmd from a previous gamestate,
// ignore it or retransmit the current gamestate
//
// if the client was downloading, let it stay at whatever serverId and
// gamestate it was at. This allows it to keep downloading even when
// the gamestate changes. After the download is finished, we'll
// notice and send it a new game state
//
// show_bug.cgi?id=536
// don't drop as long as previous command was a nextdl, after a dl is done, downloadName is set back to ""
// but we still need to read the next message to move to next download or send gamestate
// I don't like this hack though, it must have been working fine at some point, suspecting the fix is somewhere else
if ( serverId != sv.serverId && !*cl->downloadName && !strstr( cl->lastClientCommandString, "nextdl" ) ) {
if ( serverId >= sv.restartedServerId && serverId < sv.serverId ) { // TTimo - use a comparison here to catch multiple map_restart
if ( strstr( cl->lastClientCommandString, "donedl" ) ) {
SV_DoneDownload_f( cl );
} else {
// they just haven't caught the map_restart yet
Com_DPrintf( "%s : ignoring pre map_restart / outdated client message\n", cl->name );
return;
}
}
// if we can tell that the client has dropped the last
// gamestate we sent them, resend it
if ( cl->state != CS_ACTIVE && cl->messageAcknowledge > cl->gamestateMessageNum ) {
Com_DPrintf( "%s : dropped gamestate, resending\n", cl->name );
SV_SendClientGameState( cl );
}
return;
}
// this client has acknowledged the new gamestate so it's
// safe to start sending it the real time again
if( cl->oldServerTime && serverId == sv.serverId ){
Com_DPrintf( "%s acknowledged gamestate\n", cl->name );
cl->oldServerTime = 0;
}
// read optional clientCommand strings
do {
c = MSG_ReadByte( msg );
if ( c == clc_EOF ) {
break;
}
if ( c != clc_clientCommand ) {
break;
}
if ( !SV_ClientCommand( cl, msg ) ) {
return; // we couldn't execute it because of the flood protection
}
if ( cl->state == CS_ZOMBIE ) {
return; // disconnect command
}
} while ( 1 );
// skip legacy speex voip data
if ( c == clc_voipSpeex ) {
#ifdef USE_VOIP
SV_UserVoip( cl, msg, qtrue );
c = MSG_ReadByte( msg );
#endif
}
// read optional voip data
if ( c == clc_voipOpus ) {
#ifdef USE_VOIP
SV_UserVoip( cl, msg, qfalse );
c = MSG_ReadByte( msg );
#endif
}
// read the usercmd_t
if ( c == clc_move ) {
SV_UserMove( cl, msg, qtrue );
} else if ( c == clc_moveNoDelta ) {
SV_UserMove( cl, msg, qfalse );
} else if ( c != clc_EOF ) {
Com_Printf( "WARNING: bad command byte for client %i\n", (int) (cl - svs.clients) );
}
// if ( msg->readcount != msg->cursize ) {
// Com_Printf( "WARNING: Junk at end of packet for client %i\n", cl - svs.clients );
// }
}
|