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 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347 6348 6349 6350 6351 6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385 6386 6387 6388 6389 6390 6391 6392 6393 6394 6395 6396 6397 6398 6399 6400 6401 6402 6403 6404 6405 6406 6407 6408 6409 6410 6411 6412 6413 6414 6415 6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 6431 6432 6433 6434 6435 6436 6437 6438 6439 6440 6441 6442 6443 6444 6445 6446 6447 6448 6449 6450 6451 6452 6453 6454 6455 6456 6457 6458 6459 6460 6461 6462 6463 6464 6465 6466 6467 6468 6469 6470 6471 6472 6473 6474 6475 6476 6477 6478 6479 6480 6481 6482 6483 6484 6485 6486 6487 6488 6489 6490 6491 6492 6493 6494 6495 6496 6497 6498 6499 6500 6501 6502 6503 6504 6505 6506 6507 6508 6509 6510 6511 6512 6513 6514 6515 6516 6517 6518 6519 6520 6521 6522 6523 6524 6525 6526 6527 6528 6529 6530 6531 6532 6533 6534 6535 6536 6537 6538 6539 6540 6541 6542 6543 6544 6545 6546 6547 6548 6549 6550 6551 6552 6553 6554 6555 6556 6557 6558 6559 6560 6561 6562 6563 6564 6565 6566 6567 6568 6569 6570 6571 6572 6573 6574 6575 6576 6577 6578 6579 6580 6581 6582 6583 6584 6585 6586 6587 6588 6589 6590 6591 6592 6593 6594 6595 6596 6597 6598 6599 6600 6601 6602 6603 6604 6605 6606 6607 6608 6609 6610 6611 6612 6613 6614 6615 6616 6617 6618 6619 6620 6621 6622 6623 6624 6625 6626 6627 6628 6629 6630 6631 6632 6633 6634 6635 6636 6637 6638 6639 6640 6641 6642 6643 6644 6645 6646 6647 6648 6649 6650 6651 6652 6653 6654 6655 6656 6657 6658 6659 6660 6661 6662 6663 6664 6665 6666 6667 6668 6669 6670 6671 6672 6673 6674 6675 6676 6677 6678 6679 6680 6681 6682 6683 6684 6685 6686 6687 6688 6689 6690 6691 6692 6693 6694 6695 6696 6697 6698 6699 6700 6701 6702 6703 6704 6705 6706 6707 6708 6709 6710 6711 6712 6713 6714 6715 6716 6717 6718 6719 6720 6721 6722 6723 6724 6725 6726 6727 6728 6729 6730 6731 6732 6733 6734 6735 6736 6737 6738 6739 6740 6741 6742 6743 6744 6745 6746 6747 6748 6749 6750 6751 6752 6753 6754 6755 6756 6757 6758 6759 6760 6761 6762 6763 6764 6765 6766 6767 6768 6769 6770 6771 6772 6773 6774 6775 6776 6777 6778 6779 6780 6781 6782 6783 6784 6785 6786 6787 6788 6789 6790 6791 6792 6793 6794 6795 6796 6797 6798 6799 6800 6801 6802 6803 6804 6805 6806 6807 6808 6809 6810 6811 6812 6813 6814 6815 6816 6817 6818 6819 6820 6821 6822 6823 6824 6825 6826 6827 6828 6829 6830 6831 6832 6833 6834 6835 6836 6837 6838 6839 6840 6841 6842 6843 6844 6845 6846 6847 6848 6849 6850 6851 6852 6853 6854 6855 6856 6857 6858 6859 6860 6861 6862 6863 6864 6865 6866 6867 6868 6869 6870 6871 6872 6873 6874 6875 6876 6877 6878 6879 6880 6881 6882 6883 6884 6885 6886 6887 6888 6889 6890 6891 6892 6893 6894 6895 6896 6897 6898 6899 6900 6901 6902 6903 6904 6905 6906 6907 6908 6909 6910 6911 6912 6913 6914 6915 6916 6917 6918 6919 6920 6921 6922 6923 6924 6925 6926 6927 6928 6929 6930 6931 6932 6933 6934 6935 6936 6937 6938 6939 6940 6941 6942 6943 6944 6945 6946 6947 6948 6949 6950 6951 6952 6953 6954 6955 6956 6957 6958 6959 6960 6961 6962 6963 6964 6965 6966 6967 6968 6969 6970 6971 6972 6973 6974 6975 6976 6977 6978 6979 6980 6981 6982 6983 6984 6985 6986 6987 6988 6989 6990 6991 6992 6993 6994 6995 6996 6997 6998 6999 7000 7001 7002 7003 7004 7005 7006 7007 7008 7009 7010 7011 7012 7013 7014 7015 7016 7017 7018 7019 7020 7021 7022 7023 7024 7025 7026 7027 7028 7029 7030 7031 7032 7033 7034 7035 7036 7037 7038 7039 7040 7041 7042 7043 7044 7045 7046 7047 7048 7049 7050 7051 7052 7053 7054 7055 7056 7057 7058 7059 7060 7061 7062 7063 7064 7065 7066 7067 7068 7069 7070 7071 7072 7073 7074 7075 7076 7077 7078 7079 7080 7081 7082 7083 7084 7085 7086 7087 7088 7089 7090 7091 7092 7093 7094 7095 7096 7097 7098 7099 7100 7101 7102 7103 7104 7105 7106 7107 7108 7109 7110 7111 7112 7113 7114 7115 7116 7117 7118 7119 7120 7121 7122 7123 7124 7125 7126 7127 7128 7129 7130 7131 7132 7133 7134 7135 7136 7137 7138 7139 7140 7141 7142 7143 7144 7145 7146 7147 7148 7149 7150 7151 7152 7153 7154 7155 7156 7157 7158 7159 7160 7161 7162 7163 7164 7165 7166 7167 7168 7169 7170 7171 7172 7173 7174 7175 7176 7177 7178 7179 7180 7181 7182 7183 7184 7185 7186 7187 7188 7189 7190 7191 7192 7193 7194 7195 7196 7197 7198 7199 7200 7201 7202 7203 7204 7205 7206 7207 7208 7209 7210 7211 7212 7213 7214 7215 7216 7217 7218 7219 7220 7221 7222 7223 7224 7225 7226 7227 7228 7229 7230 7231 7232 7233 7234 7235 7236 7237 7238 7239 7240 7241 7242 7243 7244 7245 7246 7247 7248 7249 7250 7251 7252 7253 7254 7255 7256 7257 7258 7259 7260 7261 7262 7263 7264 7265 7266 7267 7268 7269 7270 7271 7272 7273 7274 7275 7276 7277 7278 7279 7280 7281 7282 7283 7284 7285 7286 7287 7288 7289 7290 7291 7292 7293 7294 7295 7296 7297 7298 7299 7300 7301 7302 7303 7304 7305 7306 7307 7308 7309 7310 7311 7312 7313 7314 7315 7316 7317 7318 7319 7320 7321 7322 7323 7324 7325 7326 7327 7328 7329 7330 7331 7332 7333 7334 7335 7336 7337 7338 7339 7340 7341 7342 7343 7344 7345 7346 7347 7348 7349 7350 7351 7352 7353 7354 7355 7356 7357 7358 7359 7360 7361 7362 7363 7364 7365 7366 7367 7368 7369 7370 7371 7372 7373 7374 7375 7376 7377 7378 7379 7380 7381 7382 7383 7384 7385 7386 7387 7388 7389 7390 7391 7392 7393 7394 7395 7396 7397 7398 7399 7400 7401 7402 7403 7404 7405 7406 7407 7408 7409 7410 7411 7412 7413 7414 7415 7416 7417 7418 7419 7420 7421 7422 7423 7424 7425 7426 7427 7428 7429 7430 7431 7432 7433 7434 7435 7436 7437 7438 7439 7440 7441 7442 7443 7444 7445 7446 7447 7448 7449 7450 7451 7452 7453 7454 7455 7456 7457 7458 7459 7460 7461 7462 7463 7464 7465 7466 7467 7468 7469 7470 7471 7472 7473 7474 7475 7476 7477 7478 7479 7480 7481 7482 7483 7484 7485 7486 7487 7488 7489 7490 7491 7492 7493 7494 7495 7496 7497 7498 7499 7500 7501 7502 7503 7504 7505 7506 7507 7508 7509 7510 7511 7512 7513 7514 7515 7516 7517 7518 7519 7520 7521 7522 7523 7524 7525 7526 7527 7528 7529 7530 7531 7532 7533 7534 7535 7536 7537 7538 7539 7540 7541 7542 7543 7544 7545 7546 7547 7548 7549 7550 7551 7552 7553 7554 7555 7556 7557 7558 7559 7560 7561 7562 7563 7564 7565 7566 7567 7568 7569 7570 7571 7572 7573 7574 7575 7576 7577 7578 7579 7580 7581 7582 7583 7584 7585 7586 7587 7588 7589 7590 7591 7592 7593 7594 7595 7596 7597 7598 7599 7600 7601 7602 7603 7604 7605 7606 7607 7608 7609 7610 7611 7612 7613 7614 7615 7616 7617 7618 7619 7620 7621 7622 7623 7624 7625 7626 7627 7628 7629 7630 7631 7632 7633 7634 7635 7636 7637 7638 7639 7640 7641 7642 7643 7644 7645 7646 7647 7648 7649 7650 7651 7652 7653 7654 7655 7656 7657 7658 7659 7660 7661 7662 7663 7664 7665 7666 7667 7668 7669 7670 7671 7672 7673 7674 7675 7676 7677 7678 7679 7680 7681 7682 7683 7684 7685 7686 7687 7688 7689 7690 7691 7692 7693 7694 7695 7696 7697 7698 7699 7700 7701 7702 7703 7704 7705 7706 7707 7708 7709 7710 7711 7712 7713 7714 7715 7716 7717 7718 7719 7720 7721 7722 7723 7724 7725 7726 7727 7728 7729 7730 7731 7732 7733 7734 7735 7736 7737 7738 7739 7740 7741 7742 7743 7744 7745 7746 7747 7748 7749 7750 7751 7752 7753 7754 7755 7756 7757 7758 7759 7760 7761 7762 7763 7764 7765 7766 7767 7768 7769 7770 7771 7772 7773 7774 7775 7776 7777 7778 7779 7780 7781 7782 7783 7784 7785 7786 7787 7788 7789 7790 7791 7792 7793 7794 7795 7796 7797 7798 7799 7800 7801 7802 7803 7804 7805 7806 7807 7808 7809 7810 7811 7812 7813 7814 7815 7816 7817 7818 7819 7820 7821 7822 7823 7824 7825 7826 7827 7828 7829 7830 7831 7832 7833 7834 7835 7836 7837 7838 7839 7840 7841 7842 7843 7844 7845 7846 7847 7848 7849 7850 7851 7852 7853 7854 7855 7856 7857 7858 7859 7860 7861 7862 7863 7864 7865 7866 7867 7868 7869 7870 7871 7872 7873 7874 7875 7876 7877 7878 7879 7880 7881 7882 7883 7884 7885 7886 7887 7888 7889 7890 7891 7892 7893 7894 7895 7896 7897 7898 7899 7900 7901 7902 7903 7904 7905 7906 7907 7908 7909 7910 7911 7912 7913 7914 7915 7916 7917 7918 7919 7920 7921 7922 7923 7924 7925 7926 7927 7928 7929 7930 7931 7932 7933 7934 7935 7936 7937 7938 7939 7940 7941 7942 7943 7944 7945 7946 7947 7948 7949 7950 7951 7952 7953 7954 7955 7956 7957 7958 7959 7960 7961 7962 7963 7964 7965 7966 7967 7968 7969 7970 7971 7972 7973 7974 7975 7976 7977 7978 7979 7980 7981 7982 7983 7984 7985 7986 7987 7988 7989 7990 7991 7992 7993 7994 7995 7996 7997 7998 7999 8000 8001 8002 8003 8004 8005 8006 8007 8008 8009 8010 8011 8012 8013 8014 8015 8016 8017 8018 8019 8020 8021 8022 8023 8024 8025 8026 8027 8028 8029 8030 8031 8032 8033 8034 8035 8036 8037 8038 8039 8040 8041 8042 8043 8044 8045 8046 8047 8048 8049 8050 8051 8052 8053 8054 8055 8056 8057 8058 8059 8060 8061 8062 8063 8064 8065 8066 8067 8068 8069 8070 8071 8072 8073 8074 8075 8076 8077 8078 8079 8080 8081 8082 8083 8084 8085 8086 8087 8088 8089 8090 8091 8092 8093 8094 8095 8096 8097 8098 8099 8100 8101 8102 8103 8104 8105 8106 8107 8108 8109 8110 8111 8112 8113 8114 8115 8116 8117 8118 8119 8120 8121 8122 8123 8124 8125 8126 8127 8128 8129 8130 8131 8132 8133 8134 8135 8136 8137 8138 8139 8140 8141 8142 8143 8144 8145 8146 8147 8148 8149 8150 8151 8152 8153 8154 8155 8156 8157 8158 8159 8160 8161 8162 8163 8164 8165 8166 8167 8168 8169 8170 8171 8172 8173 8174 8175 8176 8177 8178 8179 8180 8181 8182 8183 8184 8185 8186 8187 8188 8189 8190 8191 8192 8193 8194 8195 8196 8197 8198 8199 8200 8201 8202 8203 8204 8205 8206 8207 8208 8209 8210 8211 8212 8213 8214 8215 8216 8217 8218 8219 8220 8221 8222 8223 8224 8225 8226 8227 8228 8229 8230 8231 8232 8233 8234 8235 8236 8237 8238 8239 8240 8241 8242 8243 8244 8245 8246 8247 8248 8249 8250 8251 8252 8253 8254 8255 8256 8257 8258 8259 8260 8261 8262 8263 8264 8265 8266 8267 8268 8269 8270 8271 8272 8273 8274 8275 8276 8277 8278 8279 8280 8281 8282 8283 8284 8285 8286 8287 8288 8289 8290 8291 8292 8293 8294 8295 8296 8297 8298 8299 8300 8301 8302 8303 8304 8305 8306 8307 8308 8309 8310 8311 8312 8313 8314 8315 8316 8317 8318 8319 8320 8321 8322 8323 8324 8325 8326 8327 8328 8329 8330 8331 8332 8333 8334 8335 8336 8337 8338 8339 8340 8341 8342 8343 8344 8345 8346 8347 8348 8349 8350 8351 8352 8353 8354 8355 8356 8357 8358 8359 8360 8361 8362 8363 8364 8365 8366 8367 8368 8369 8370 8371 8372 8373 8374 8375 8376 8377 8378 8379 8380 8381 8382 8383 8384 8385 8386 8387 8388 8389 8390 8391 8392 8393 8394 8395 8396 8397 8398 8399 8400 8401 8402 8403 8404 8405 8406 8407 8408 8409 8410 8411 8412 8413 8414 8415 8416 8417 8418 8419 8420 8421 8422 8423 8424 8425 8426 8427 8428 8429 8430 8431 8432 8433 8434 8435 8436 8437 8438 8439 8440 8441 8442 8443 8444 8445 8446 8447 8448 8449 8450 8451 8452 8453 8454 8455 8456 8457 8458 8459 8460 8461 8462 8463 8464 8465 8466 8467 8468 8469 8470 8471 8472 8473 8474 8475 8476 8477 8478 8479 8480 8481 8482 8483 8484 8485 8486 8487 8488 8489 8490 8491 8492 8493 8494 8495 8496 8497 8498 8499 8500 8501 8502 8503 8504 8505 8506 8507 8508 8509 8510 8511 8512 8513 8514 8515 8516 8517 8518 8519 8520 8521 8522 8523 8524 8525 8526 8527 8528 8529 8530 8531 8532 8533 8534 8535 8536 8537 8538 8539 8540 8541 8542 8543 8544 8545 8546 8547 8548 8549 8550 8551 8552 8553 8554 8555 8556 8557 8558 8559 8560 8561 8562 8563 8564 8565 8566 8567 8568 8569 8570 8571 8572 8573 8574 8575 8576 8577 8578 8579 8580 8581 8582 8583 8584 8585 8586 8587 8588 8589 8590 8591 8592 8593 8594 8595 8596 8597 8598 8599 8600 8601 8602 8603 8604 8605 8606 8607 8608 8609 8610 8611 8612 8613 8614 8615 8616 8617 8618 8619 8620 8621 8622 8623 8624 8625 8626 8627 8628 8629 8630 8631 8632 8633 8634 8635 8636 8637 8638 8639 8640 8641 8642 8643 8644 8645 8646 8647 8648 8649 8650 8651 8652 8653 8654 8655 8656 8657 8658 8659 8660 8661 8662 8663 8664 8665 8666 8667 8668 8669 8670 8671 8672 8673 8674 8675 8676 8677 8678 8679 8680 8681 8682 8683 8684 8685 8686 8687 8688 8689 8690 8691 8692 8693 8694 8695 8696 8697 8698 8699 8700 8701 8702 8703 8704 8705 8706 8707 8708 8709 8710 8711 8712 8713 8714 8715 8716 8717 8718 8719 8720 8721 8722 8723 8724 8725 8726 8727 8728 8729 8730
|
/*
* Copyright (C) Volition, Inc. 1999. All rights reserved.
*
* All source code herein is the property of Volition, Inc. You may not sell
* or otherwise commercially exploit the source or things you created based on the
* source.
*
*/
#include <limits.h>
#include "globalincs/pstypes.h"
#include "network/multimsgs.h"
#include "network/multiutil.h"
#include "network/multiui.h"
#include "network/multi.h"
#include "globalincs/linklist.h"
#include "gamesequence/gamesequence.h"
#include "hud/hudmessage.h"
#include "hud/hudsquadmsg.h"
#include "freespace2/freespace.h"
#include "io/timer.h"
#include "mission/missiongoals.h"
#include "mission/missionlog.h"
#include "mission/missionmessage.h"
#include "network/stand_gui.h"
#include "gamesnd/gamesnd.h"
#include "ship/shiphit.h"
#include "render/3d.h"
#include "playerman/player.h"
#include "debris/debris.h"
#include "missionui/missionweaponchoice.h"
#include "missionui/missionshipchoice.h"
#include "ship/shipfx.h"
#include "popup/popup.h"
#include "network/multi_ingame.h"
#include "network/multiteamselect.h"
#include "ai/aigoals.h"
#include "network/multi_campaign.h"
#include "network/multi_team.h"
#include "network/multi_respawn.h"
#include "network/multi_observer.h"
#include "asteroid/asteroid.h"
#include "network/multi_pmsg.h"
#include "object/object.h"
#include "ship/ship.h"
#include "weapon/weapon.h"
#include "hud/hudreticle.h"
#include "network/multi_pause.h"
#include "network/multi_endgame.h"
#include "missionui/missiondebrief.h"
#include "network/multi_log.h"
#include "weapon/emp.h"
#include "network/multi_kick.h"
#include "cmdline/cmdline.h"
#include "weapon/flak.h"
#include "weapon/beam.h"
#include "network/multi_rate.h"
#include "nebula/neblightning.h"
#include "hud/hud.h"
#include "missionui/missionscreencommon.h"
#include "mission/missionbriefcommon.h"
#include "network/multi_log.h"
#include "object/objectdock.h"
#include "cmeasure/cmeasure.h"
#include "parse/sexp.h"
#include "fs2netd/fs2netd_client.h"
#include "network/multi_sexp.h"
// #define _MULTI_SUPER_WACKY_COMPRESSION
#ifdef _MULTI_SUPER_WACKY_COMPRESSION
#define BITS 15
#define MAX_CODE ( ( 1 << BITS ) - 1 )
#define TABLE_SIZE 35023L
#define END_OF_STREAM 256
#define BUMP_CODE 257
#define FLUSH_CODE 258
#define FIRST_CODE 259
#define UNUSED -1
typedef struct {
int code_value;
int parent_code;
char character;
} DICTIONARY;
static DICTIONARY dict[TABLE_SIZE];
static char decode_stack[TABLE_SIZE];
static uint next_code;
static int current_code_bits;
static uint next_bump_code;
typedef struct BitBuf {
ubyte mask;
int rack;
ubyte *data;
} BitBuf;
void output_bits( BitBuf *bitbuf, uint code, int count )
{
uint mask;
mask = 1L << ( count - 1 );
while ( mask != 0) {
if ( mask & code )
bitbuf->rack |= bitbuf->mask;
bitbuf->mask >>= 1;
if ( bitbuf->mask == 0 ) {
*bitbuf->data++=(ubyte)bitbuf->rack;
bitbuf->rack = 0;
bitbuf->mask = 0x80;
}
mask >>= 1;
}
}
uint input_bits( BitBuf *bitbuf, int bit_count )
{
uint mask;
uint return_value;
mask = 1L << ( bit_count - 1 );
return_value = 0;
while ( mask != 0) {
if ( bitbuf->mask == 0x80 ) {
bitbuf->rack = *bitbuf->data++;
if ( bitbuf->rack == EOF )
return END_OF_STREAM;
}
if ( bitbuf->rack & bitbuf->mask )
return_value |= mask;
mask >>= 1;
bitbuf->mask >>= 1;
if ( bitbuf->mask == 0 )
bitbuf->mask = 0x80;
}
return( return_value );
}
static void InitializeDictionary()
{
uint i;
for ( i = 0 ; i < TABLE_SIZE ; i++ )
dict[i].code_value = UNUSED;
next_code = FIRST_CODE;
current_code_bits = 9;
next_bump_code = 511;
}
static uint find_child_node( int parent_code, int child_character )
{
uint index;
int offset;
index = ( child_character << ( BITS - 8 ) ) ^ parent_code;
if ( index == 0 )
offset = 1;
else
offset = TABLE_SIZE - index;
for ( ; ; ) {
if ( dict[ index ].code_value == UNUSED )
return( (uint) index );
if ( dict[ index ].parent_code == parent_code &&
dict[ index ].character == (char) child_character )
return( index );
if ( (int) index >= offset )
index -= offset;
else
index += TABLE_SIZE - offset;
}
}
static uint decode_string( uint count, uint code )
{
while ( code > 255 ) {
decode_stack[ count++ ] = dict[ code ].character;
code = dict[ code ].parent_code;
}
decode_stack[ count++ ] = (char) code;
return( count );
}
int lzw_compress( ubyte *outputbuf, ubyte *inputbuf, int input_size )
{
BitBuf output;
int character;
int string_code;
uint index;
int i;
// Init output bit buffer
output.rack = 0;
output.mask = 0x80;
output.data = outputbuf;
InitializeDictionary();
string_code = *inputbuf++;
for ( i=1 ; i<input_size ; i++ ) {
character = *inputbuf++;
index = find_child_node( string_code, character );
if ( dict[ index ].code_value != - 1 )
string_code = dict[ index ].code_value;
else {
dict[ index ].code_value = next_code++;
dict[ index ].parent_code = string_code;
dict[ index ].character = (char) character;
output_bits( &output, (unsigned long) string_code, current_code_bits );
string_code = character;
if ( next_code > MAX_CODE ) {
output_bits( &output, (unsigned long) FLUSH_CODE, current_code_bits );
InitializeDictionary();
} else if ( next_code > next_bump_code ) {
output_bits( &output, (unsigned long) BUMP_CODE, current_code_bits );
current_code_bits++;
next_bump_code <<= 1;
next_bump_code |= 1;
}
}
}
output_bits( &output, (unsigned long) string_code, current_code_bits );
output_bits( &output, (unsigned long) END_OF_STREAM, current_code_bits);
if ( output.mask != 0x80 )
*output.data++ = (ubyte)output.rack;
return output.data-outputbuf;
}
int lzw_expand( ubyte *outputbuf, ubyte *inputbuf )
{
BitBuf input;
uint new_code;
uint old_code;
int character;
uint count;
uint counter;
input.rack = 0;
input.mask = 0x80;
input.data = inputbuf;
counter = 0;
for ( ; ; ) {
InitializeDictionary();
old_code = (uint) input_bits( &input, current_code_bits );
if ( old_code == END_OF_STREAM )
return counter;
character = old_code;
outputbuf[counter++] = ( ubyte )old_code;
for ( ; ; ) {
new_code = (uint) input_bits( &input, current_code_bits );
if ( new_code == END_OF_STREAM )
return counter;
if ( new_code == FLUSH_CODE )
break;
if ( new_code == BUMP_CODE ) {
current_code_bits++;
continue;
}
if ( new_code >= next_code ) {
decode_stack[ 0 ] = (char) character;
count = decode_string( 1, old_code );
} else {
count = decode_string( 0, new_code );
}
character = decode_stack[ count - 1 ];
while ( count > 0 )
outputbuf[counter++] = ( ubyte )decode_stack[ --count ];
dict[ next_code ].parent_code = old_code;
dict[ next_code ].character = (char) character;
next_code++;
old_code = new_code;
}
}
}
#endif
// process a join request packet add
void add_join_request(ubyte *data, int *size, join_request *jr)
{
int packet_size = *size;
join_request jr_tmp;
memcpy(&jr_tmp, jr, sizeof(join_request));
jr_tmp.tracker_id = INTEL_INT(jr->tracker_id);
jr_tmp.player_options.flags = INTEL_INT(jr->player_options.flags);
jr_tmp.player_options.obj_update_level = INTEL_INT(jr->player_options.obj_update_level);
ADD_DATA(jr_tmp);
*size = packet_size;
}
// process a join request packet get
void get_join_request(ubyte *data, int *size, join_request *jr)
{
int offset = *size;
GET_DATA(*jr);
jr->tracker_id = INTEL_INT(jr->tracker_id); //-V570
jr->player_options.flags = INTEL_INT(jr->player_options.flags); //-V570
jr->player_options.obj_update_level = INTEL_INT(jr->player_options.obj_update_level); //-V570
*size = offset;
}
void add_net_addr(ubyte *data, int *size, net_addr *addr)
{
int packet_size = *size;
net_addr addr_tmp;
memcpy(&addr_tmp, addr, sizeof(net_addr));
addr_tmp.type = INTEL_INT(addr->type);
addr_tmp.port = INTEL_SHORT(addr->port);
ADD_DATA(addr_tmp);
*size = packet_size;
}
void get_net_addr(ubyte *data, int *size, net_addr *addr)
{
int offset = *size;
GET_DATA(*addr);
addr->type = INTEL_INT(addr->type); //-V570
addr->port = INTEL_SHORT(addr->port); //-V570
*size = offset;
}
/*
void add_vector_data(ubyte *data, int *size, vec3d vec)
{
int packet_size = *size;
ADD_FLOAT(vec.xyz.x);
ADD_FLOAT(vec.xyz.y);
ADD_FLOAT(vec.xyz.z);
*size = packet_size;
}
void get_vector_data(ubyte *data, int *size, vec3d vec)
{
int offset = *size;
GET_FLOAT(vec.xyz.x);
GET_FLOAT(vec.xyz.y);
GET_FLOAT(vec.xyz.z);
*size = offset;
}
*/
// send the specified data packet to all players
void multi_io_send(net_player *pl, ubyte *data, int len)
{
// invalid
if((pl == NULL) || (NET_PLAYER_NUM(pl) >= MAX_PLAYERS)){
return;
}
// don't do it for single player
if(!(Game_mode & GM_MULTIPLAYER)){
return;
}
// sanity checks
if(MULTIPLAYER_CLIENT){
// Assert(pl == Net_player);
if(pl != Net_player){
return;
}
} else {
// Assert(pl != Net_player);
if(pl == Net_player){
return;
}
}
// If this packet will push the buffer over MAX_PACKET_SIZE, send the current send_buffer
if ((pl->s_info.unreliable_buffer_size + len) > MAX_PACKET_SIZE) {
multi_io_send_force(pl);
pl->s_info.unreliable_buffer_size = 0;
}
Assert((pl->s_info.unreliable_buffer_size + len) <= MAX_PACKET_SIZE);
memcpy(pl->s_info.unreliable_buffer + pl->s_info.unreliable_buffer_size, data, len);
pl->s_info.unreliable_buffer_size += len;
}
void multi_io_send_to_all(ubyte *data, int length, net_player *ignore)
{
int i;
Assert(MULTIPLAYER_MASTER);
// need to check for i > 1, hmmm... and connected. I don't know.
for (i = 0; i < MAX_PLAYERS; i++ ) {
if ( !MULTI_CONNECTED(Net_players[i]) || (Net_player == &Net_players[i])){
continue;
}
// maybe ignore a player
if((ignore != NULL) && (&Net_players[i] == ignore)){
continue;
}
// ingame joiners not waiting to select a ship doesn't get any packets
if ( (Net_players[i].flags & NETINFO_FLAG_INGAME_JOIN) && !(Net_players[i].flags & INGAME_JOIN_FLAG_PICK_SHIP) ){
continue;
}
// send it
multi_io_send(&Net_players[i], data, length);
}
}
void multi_io_send_force(net_player *pl)
{
// invalid
if((pl == NULL) || (NET_PLAYER_NUM(pl) >= MAX_PLAYERS)){
return;
}
// don't do it for single player
if(!(Game_mode & GM_MULTIPLAYER)){
return;
}
// send everything in
if (MULTIPLAYER_MASTER) {
psnet_send(&pl->p_info.addr, pl->s_info.unreliable_buffer, pl->s_info.unreliable_buffer_size, NET_PLAYER_NUM(pl));
// add the bytes sent to this player
pl->sv_bytes_sent += pl->s_info.unreliable_buffer_size;
} else {
psnet_send(&Netgame.server_addr, pl->s_info.unreliable_buffer, pl->s_info.unreliable_buffer_size, NET_PLAYER_NUM(pl));
}
pl->s_info.unreliable_buffer_size = 0;
}
// send the data packet to all players via their reliable sockets
void multi_io_send_reliable(net_player *pl, ubyte *data, int len)
{
// invalid
if((pl == NULL) || (NET_PLAYER_NUM(pl) >= MAX_PLAYERS)){
return;
}
// don't do it for single player
if(!(Game_mode & GM_MULTIPLAYER)){
return;
}
// sanity checks
if(MULTIPLAYER_CLIENT){
// Assert(pl == Net_player);
if(pl != Net_player){
return;
}
} else {
// Assert(pl != Net_player);
if(pl == Net_player){
return;
}
}
// If this packet will push the buffer over MAX_PACKET_SIZE, send the current send_buffer
if ((pl->s_info.reliable_buffer_size + len) > MAX_PACKET_SIZE) {
multi_io_send_reliable_force(pl);
pl->s_info.reliable_buffer_size = 0;
}
Assert((pl->s_info.reliable_buffer_size + len) <= MAX_PACKET_SIZE);
memcpy(pl->s_info.reliable_buffer + pl->s_info.reliable_buffer_size, data, len);
pl->s_info.reliable_buffer_size += len;
}
void multi_io_send_to_all_reliable(ubyte* data, int length, net_player *ignore)
{
int i;
Assert(MULTIPLAYER_MASTER);
// need to check for i > 1, hmmm... and connected. I don't know.
for (i = 0; i < MAX_PLAYERS; i++ ) {
if ( !MULTI_CONNECTED(Net_players[i]) || (Net_player == &Net_players[i])){
continue;
}
// maybe ignore a player
if((ignore != NULL) && (&Net_players[i] == ignore)){
continue;
}
// ingame joiners not waiting to select a ship doesn't get any packets
if ( (Net_players[i].flags & NETINFO_FLAG_INGAME_JOIN) && !(Net_players[i].flags & INGAME_JOIN_FLAG_PICK_SHIP) ){
continue;
}
// send it
multi_io_send_reliable(&Net_players[i], data, length);
}
}
void multi_io_send_reliable_force(net_player *pl)
{
// invalid
if((pl == NULL) || (NET_PLAYER_NUM(pl) >= MAX_PLAYERS)){
return;
}
// don't do it for single player
if(!(Game_mode & GM_MULTIPLAYER)){
return;
}
// send everything in
if(MULTIPLAYER_MASTER) {
psnet_rel_send(pl->reliable_socket, pl->s_info.reliable_buffer, pl->s_info.reliable_buffer_size, NET_PLAYER_NUM(pl));
} else if(Net_player != NULL){
psnet_rel_send(Net_player->reliable_socket, pl->s_info.reliable_buffer, pl->s_info.reliable_buffer_size, NET_PLAYER_NUM(pl));
}
pl->s_info.reliable_buffer_size = 0;
}
// send all buffered packets
void multi_io_send_buffered_packets()
{
int idx;
// don't do it for single player
if(!(Game_mode & GM_MULTIPLAYER)){
return;
}
// server
if(MULTIPLAYER_MASTER){
for(idx=0; idx<MAX_PLAYERS; idx++){
if(MULTI_CONNECTED(Net_players[idx]) && (Net_player != &Net_players[idx])){
// force unreliable data
if(Net_players[idx].s_info.unreliable_buffer_size > 0){
multi_io_send_force(&Net_players[idx]);
Net_players[idx].s_info.unreliable_buffer_size = 0;
}
// force reliable data
if(Net_players[idx].s_info.reliable_buffer_size > 0){
multi_io_send_reliable_force(&Net_players[idx]);
Net_players[idx].s_info.reliable_buffer_size = 0;
}
}
}
}
// clients
else if(Net_player != NULL){
// force unreliable data
if(Net_player->s_info.unreliable_buffer_size > 0){
multi_io_send_force(Net_player);
Net_player->s_info.unreliable_buffer_size = 0;
}
// force reliable data
if(Net_player->s_info.reliable_buffer_size > 0){
multi_io_send_reliable_force(Net_player);
Net_player->s_info.reliable_buffer_size = 0;
}
}
}
//*********************************************************************************************************
// Game Chat Packet
//*********************************************************************************************************
/*
struct fs2_game_chat_packet
{
char packet_signature; //0xC3
short from_player_id;
int server_msg;
char mode;
// variable record
if (mode)
short to_player_id;
else
{
int i;
char expr[i];
}
int j;
char message[j];
}
*/
//+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// send a general game chat packet (if msg_mode == MULTI_MSG_TARGET, need to pass in "to", if == MULTI_MSG_EXPR, need to pass in expr)
void send_game_chat_packet(net_player *from, char *msg, int msg_mode, net_player *to, char *expr, int server_msg)
{
ubyte data[MAX_PACKET_SIZE],mode;
int packet_size,idx;
bool undeliverable = true;
BUILD_HEADER(GAME_CHAT);
// add the id
ADD_SHORT(from->player_id);
// add the message mode and if in MSG_TARGET mode, add who the target is
ADD_INT(server_msg);
mode = (ubyte)msg_mode;
ADD_DATA(mode);
switch(mode){
case MULTI_MSG_TARGET:
Assert(to != NULL);
ADD_SHORT(to->player_id);
break;
case MULTI_MSG_EXPR:
Assert(expr != NULL);
ADD_STRING(expr);
break;
}
// add the message itself
ADD_STRING( msg );
if(Net_player->flags & NETINFO_FLAG_AM_MASTER){
switch(mode){
// message all players
case MULTI_MSG_ALL:
for(idx=0;idx<MAX_PLAYERS;idx++){
if(MULTI_CONNECTED(Net_players[idx]) && !MULTI_STANDALONE(Net_players[idx]) && (&Net_players[idx] != from)){
multi_io_send_reliable(&Net_players[idx], data, packet_size);
}
}
break;
// message only friendly players
case MULTI_MSG_FRIENDLY:
for(idx=0;idx<MAX_PLAYERS;idx++){
if(MULTI_CONNECTED(Net_players[idx]) && !MULTI_STANDALONE(Net_players[idx]) && (&Net_players[idx] != from) && (Net_players[idx].p_info.team == from->p_info.team)){
multi_io_send_reliable(&Net_players[idx], data, packet_size);
}
}
break;
// message only hostile players
case MULTI_MSG_HOSTILE:
for(idx=0;idx<MAX_PLAYERS;idx++){
if(MULTI_CONNECTED(Net_players[idx]) && !MULTI_STANDALONE(Net_players[idx]) && (&Net_players[idx] != from) && (Net_players[idx].p_info.team != from->p_info.team)){
multi_io_send_reliable(&Net_players[idx], data, packet_size);
}
}
break;
// message the player's target
case MULTI_MSG_TARGET:
Assert(to != NULL);
if(MULTI_CONNECTED((*to)) && !MULTI_STANDALONE((*to))){
multi_io_send_reliable(to, data, packet_size);
}
break;
// message all players who match the expression string
case MULTI_MSG_EXPR:
Assert(expr != NULL);
for(idx=0;idx<MAX_PLAYERS;idx++){
if(MULTI_CONNECTED(Net_players[idx]) && !MULTI_STANDALONE(Net_players[idx]) && (&Net_players[idx] != from) && multi_msg_matches_expr(&Net_players[idx],expr) ){
multi_io_send_reliable(&Net_players[idx], data, packet_size);
undeliverable = false;
}
}
break;
}
// if the message can't be delivered, notify the player
if (undeliverable) {
switch(mode){
case MULTI_MSG_EXPR:
// if the message came from the server
if (from == Net_player) {
multi_display_chat_msg ("Unable to send message, player does not exist", 0, 0);
}
// otherwise send a message back to the player
else {
send_game_chat_packet(Net_player, "Unable to send message, player does not exist", MULTI_MSG_TARGET, from, NULL, 1);
}
break;
}
}
}
// send to the server, who will take care of routing it
else {
multi_io_send_reliable(Net_player, data, packet_size);
}
}
//+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// process a general game chat packet, if we're the standalone we should rebroadcast
void process_game_chat_packet( ubyte *data, header *hinfo )
{
int offset;
ubyte mode;
int color_index,player_index,to_player_index,should_display,server_msg;
char msg[MULTI_MSG_MAX_TEXT_LEN+CALLSIGN_LEN+2];
char expr[255];
short from, to;
offset = HEADER_LENGTH;
// get the id of the sender
GET_SHORT(from);
// determine if this is a server message
GET_INT(server_msg);
// get the mode
GET_DATA(mode);
// if targeting a specific player, get the address
to = -1;
switch(mode){
case MULTI_MSG_TARGET:
GET_SHORT(to);
break;
case MULTI_MSG_EXPR:
GET_STRING(expr);
break;
}
// get the message itself
GET_STRING(msg);
PACKET_SET_SIZE();
// get the index of the sending player
color_index = find_player_id(from);
player_index = color_index;
// if we couldn't find the player - bail
if(player_index == -1){
nprintf(("Network","Could not find player for processing game chat packet!\n"));
return;
}
should_display = 0;
// if we're the server, determine what to do with the packet here
if(Net_player->flags & NETINFO_FLAG_AM_MASTER){
// if he's targeting a specific player, find out who it is
if(mode == MULTI_MSG_TARGET){
to_player_index = find_player_id(to);
} else {
to_player_index = -1;
}
// if we couldn't find who sent the message or who should be getting the message, the bail
if(((to_player_index == -1) && (mode == MULTI_MSG_TARGET)) || (player_index == -1)){
return;
}
// determine if _I_ should be seeing the text
if(Game_mode & GM_STANDALONE_SERVER){
should_display = 1;
}
// check against myself for several specific cases
else {
if((mode == MULTI_MSG_ALL) ||
((mode == MULTI_MSG_FRIENDLY) && (Net_player->p_info.team == Net_players[player_index].p_info.team)) ||
((mode == MULTI_MSG_HOSTILE) && (Net_player->p_info.team != Net_players[player_index].p_info.team)) ||
((mode == MULTI_MSG_TARGET) && (MY_NET_PLAYER_NUM == to_player_index)) ||
((mode == MULTI_MSG_EXPR) && multi_msg_matches_expr(Net_player,expr)) ){
should_display = 1;
}
}
// if we're the server of a game, we need to rebroadcast to all other players
switch(mode){
// individual target mission
case MULTI_MSG_TARGET:
// if I was the inteneded target, or we couldn't find the intended target, don't rebroadcast
if(to_player_index != MY_NET_PLAYER_NUM){
send_game_chat_packet(&Net_players[player_index], msg, (int)mode, &Net_players[to_player_index], NULL, server_msg);
}
break;
// expression mode
case MULTI_MSG_EXPR:
send_game_chat_packet(&Net_players[player_index], msg, (int)mode, NULL, expr, server_msg);
break;
// all other modes
default :
send_game_chat_packet(&Net_players[player_index], msg, (int)mode, NULL, NULL, server_msg);
break;
}
}
// if a client receives this packet, its always ok for him to display it
else {
should_display = 1;
}
// if we're not on a standalone
if(should_display){
if(server_msg == 2){
HUD_printf(msg);
} else {
multi_display_chat_msg(msg, player_index, !server_msg);
}
}
}
//*********************************************************************************************************
// Hud Message packet
//*********************************************************************************************************
/*
struct fs2_game_chat_packet
{
char packet_signature; //0xC1 HUD_MSG
int msg_size;
char msg[msg_size];
}
*/
//+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// broadcast a hud message to all players
void send_hud_msg_to_all( char* msg )
{
ubyte data[MAX_PACKET_SIZE];
int packet_size;
// only the server should be sending this packet
BUILD_HEADER(HUD_MSG);
ADD_STRING(msg);
multi_io_send_to_all( data, packet_size );
}
//+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// process an incoming hud message packet
void process_hud_message(ubyte* data, header* hinfo)
{
int offset;
char msg_buffer[255];
offset = HEADER_LENGTH;
GET_STRING(msg_buffer);
PACKET_SET_SIZE();
// this is the only safe place to do this since only in the mission is the HUD guaranteed to be inited
if(Game_mode & GM_IN_MISSION){
HUD_printf(msg_buffer);
}
}
//*********************************************************************************************************
// Join Packet
//*********************************************************************************************************
/*
struct fs2_game_chat_packet
{
char packet_signature; //0xC1 HUD_MSG
int msg_size;
char msg[msg_size];
}
*/
//+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// send a join packet request to the specified address (should be a server)
void send_join_packet(net_addr* addr,join_request *jr)
{
ubyte data[MAX_PACKET_SIZE];
int packet_size;
// build the header and add the request
BUILD_HEADER(JOIN);
add_join_request(data, &packet_size, jr);
psnet_send(addr, data, packet_size);
}
//+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// process an incoming join request packet
void process_join_packet(ubyte* data, header* hinfo)
{
join_request jr;
int offset;
int ret_code;
int host_restr_mode;
int team0_avail,team1_avail;
char join_string[255];
net_addr addr;
// only the server of the game should ever receive this packet
if ( !(Net_player->flags & NETINFO_FLAG_AM_MASTER) )
return;
offset = HEADER_LENGTH;
// read in the request info
memset(&jr,0,sizeof(join_request));
get_join_request(data, &offset, &jr);
PACKET_SET_SIZE();
// fill in the address information of where this came from
fill_net_addr(&addr, hinfo->addr, hinfo->net_id, hinfo->port);
// determine if we should accept this guy, or return a reason we should reject him
// see the DENY_* codes in multi.h
ret_code = multi_eval_join_request(&jr,&addr);
// evaluate the return code
switch(ret_code)
{
// he should be accepted
case -1 :
break;
// we have to query the host because this is a restricted game
case JOIN_QUERY_RESTRICTED :
if(!(Game_mode & GM_STANDALONE_SERVER)){
// notify the host of the event
snd_play(&Snds[SND_CUE_VOICE]);
}
// set the query timestamp
Multi_restr_query_timestamp = timestamp(MULTI_QUERY_RESTR_STAMP);
Netgame.flags |= NG_FLAG_INGAME_JOINING;
// determine what mode we're in
host_restr_mode = -1;
memset(join_string,0,255);
if((Netgame.type_flags & NG_TYPE_TEAM) && Netgame.mode == NG_MODE_RESTRICTED){
multi_player_ships_available(&team0_avail,&team1_avail);
if(team0_avail && team1_avail){
host_restr_mode = MULTI_JOIN_RESTR_MODE_4;
sprintf(join_string,"Player %s has tried to join. Accept on team 1 or 2 ?",jr.callsign);
} else if(team0_avail && !team1_avail){
host_restr_mode = MULTI_JOIN_RESTR_MODE_2;
sprintf(join_string,"Player %s has tried to join team 0, accept y/n ? ?",jr.callsign);
} else if(!team0_avail && team1_avail){
host_restr_mode = MULTI_JOIN_RESTR_MODE_3;
sprintf(join_string,"Player %s has tried to join team 1, accept y/n ?",jr.callsign);
}
} else if(Netgame.mode == NG_MODE_RESTRICTED){
host_restr_mode = MULTI_JOIN_RESTR_MODE_1;
sprintf(join_string,XSTR("Player %s has tried to join, accept y/n ?",715),jr.callsign);
}
Assert(host_restr_mode != -1);
// store the request info
memcpy(&Multi_restr_join_request,&jr,sizeof(join_request));
memcpy(&Multi_restr_addr,&addr,sizeof(net_addr));
Multi_join_restr_mode = host_restr_mode;
// if i'm the standalone server, I need to send a query to the host
if(Game_mode & GM_STANDALONE_SERVER){
send_host_restr_packet(jr.callsign,0,Multi_join_restr_mode);
} else {
HUD_printf(join_string);
}
// NETLOG
ml_printf(NOX("Receive restricted join request from %s"), jr.callsign);
return;
// he'e being denied for some reason
default :
// send him the reason he is being denied
send_deny_packet(&addr,ret_code);
Netgame.flags &= ~(NG_FLAG_INGAME_JOINING);
return;
}
// process the rest of the request
multi_process_valid_join_request(&jr,&addr);
}
//*********************************************************************************************************
// New Player Packet
//*********************************************************************************************************
/*
struct fs2_new_player_packet
{
char packet_signature; // 0xB4 NOTIFY_NEW_PLAYER
int new_player_num;
net_addr player_addr;
short player_id;
int flags;
int i;
char callsign[i];
int j;
char plyr_image_filename[j];
int k;
char plyr_squad_filename[k];
int l;
char plyr_pxo_squad_name[l];
}
*/
//+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// send a notification that a new player has joined the game (if target != NULL, broadcast the packet)
void send_new_player_packet(int new_player_num,net_player *target)
{
ubyte data[MAX_PACKET_SIZE], val;
int packet_size = 0;
BUILD_HEADER( NOTIFY_NEW_PLAYER );
// add the new player's info
ADD_INT(new_player_num);
// ADD_DATA(Net_players[new_player_num].p_info.addr);
add_net_addr(data, &packet_size, &Net_players[new_player_num].p_info.addr);
ADD_SHORT(Net_players[new_player_num].player_id);
ADD_INT(Net_players[new_player_num].flags);
ADD_STRING(Net_players[new_player_num].m_player->callsign);
ADD_STRING(Net_players[new_player_num].m_player->image_filename);
ADD_STRING(Net_players[new_player_num].m_player->m_squad_filename);
ADD_STRING(Net_players[new_player_num].p_info.pxo_squad_name);
val = (ubyte)Net_players[new_player_num].p_info.team;
ADD_DATA(val);
// broadcast the data
if(target != NULL){
multi_io_send_reliable(target, data, packet_size);
} else {
multi_io_send_to_all_reliable(data, packet_size);
}
}
//+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// process a notification for a new player who has joined the game
void process_new_player_packet(ubyte* data, header* hinfo)
{
int already_in_game = 0;
int offset, new_player_num,player_num,new_flags;
net_addr new_addr;
char new_player_name[CALLSIGN_LEN+2] = "";
char new_player_image[MAX_FILENAME_LEN+1] = "";
char new_player_squad[MAX_FILENAME_LEN+1] = "";
char new_player_pxo_squad[LOGIN_LEN+1] = "";
char notify_string[256];
ubyte team;
short new_id;
offset = HEADER_LENGTH;
// get the new players information
GET_INT(new_player_num);
// GET_DATA(new_addr);
get_net_addr(data, &offset, &new_addr);
GET_SHORT(new_id);
GET_INT(new_flags);
GET_STRING(new_player_name);
GET_STRING(new_player_image);
GET_STRING(new_player_squad);
GET_STRING(new_player_pxo_squad);
GET_DATA(team);
PACKET_SET_SIZE();
player_num = multi_find_open_player_slot();
Assert(player_num != -1);
// note that this new code does not check for duplicate IPs. It merely checks to see if
// the slot referenced by new_player_num is already occupied by a connected player
if(MULTI_CONNECTED(Net_players[new_player_num])){
already_in_game=1;
}
// if he's not alreayd in the game for one reason or another
if ( !already_in_game ) {
if ( Game_mode & GM_IN_MISSION ){
HUD_sourced_printf(HUD_SOURCE_COMPUTER, XSTR("%s has entered the game\n",716), new_player_name);
}
// create the player
memcpy(new_addr.net_id, Psnet_my_addr.net_id, 4);
if(new_flags & NETINFO_FLAG_OBSERVER){
multi_obs_create_player(new_player_num,new_player_name,&new_addr,&Players[player_num]);
Net_players[new_player_num].flags |= new_flags;
} else {
multi_create_player( new_player_num, &Players[player_num],new_player_name, &new_addr, -1, new_id );
Net_players[new_player_num].flags |= new_flags;
}
// copy in the filename
if(new_player_image[0] != '\0'){
strcpy_s(Net_players[new_player_num].m_player->image_filename, new_player_image);
} else {
strcpy_s(Net_players[new_player_num].m_player->image_filename, "");
}
// copy his pilot squad filename
Net_players[new_player_num].m_player->insignia_texture = -1;
player_set_squad_bitmap(Net_players[new_player_num].m_player, new_player_squad, true);
// copy in his pxo squad name
strcpy_s(Net_players[new_player_num].p_info.pxo_squad_name, new_player_pxo_squad);
// since we just created the player, set the last_heard_time here.
Net_players[new_player_num].last_heard_time = timer_get_fixed_seconds();
Net_players[new_player_num].p_info.team = team;
Net_players[new_player_num].player_id = new_id;
// zero out this players ping
multi_ping_reset(&Net_players[new_player_num].s_info.ping);
// add a chat message
if(Net_players[new_player_num].m_player->callsign != NULL){
sprintf(notify_string,XSTR("<%s has joined>",717),Net_players[new_player_num].m_player->callsign);
multi_display_chat_msg(notify_string,0,0);
}
}
// NETLOG
ml_printf(NOX("Received notification of new player %s"), Net_players[new_player_num].m_player->callsign);
// let the current ui screen know someone joined
switch(gameseq_get_state()){
case GS_STATE_MULTI_HOST_SETUP :
multi_create_handle_join(&Net_players[new_player_num]);
break;
case GS_STATE_MULTI_CLIENT_SETUP :
multi_jw_handle_join(&Net_players[new_player_num]);
break;
}
}
//*********************************************************************************************************
// Accept Player Data Packet
//*********************************************************************************************************
/*
struct fs2_accept_player_data
{
char packet_signature; //ACCEPT_PLAYER_DATA
ubyte stop;
int player_num;
net_addr plyr_addr;
int player_id;
int i;
char callsign[i];
int j;
char plr_image_filename[j];
int k;
char plr_squad_filename[k]
int l
char plr_pxo_squadname[l];
int flags;
if (is_ingame)
int net_signature;
};
*/
//+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
#define PLAYER_DATA_SLOP 100
void send_accept_player_data( net_player *npp, int is_ingame )
{
int packet_size;
int i;
ubyte data[MAX_PACKET_SIZE], stop;
BUILD_HEADER(ACCEPT_PLAYER_DATA);
// add in the netplayer data for all players
stop = APD_NEXT;
for (i=0; i<MAX_PLAYERS; i++) {
// skip non connected players
if ( !MULTI_CONNECTED(Net_players[i]) ){
continue;
}
// skip this new player's entry
if ( npp->player_id == Net_players[i].player_id ){
continue;
}
// add the stop byte
ADD_DATA(stop);
// add the player's number
ADD_INT(i);
// add the player's address
// ADD_DATA(Net_players[i].p_info.addr);
add_net_addr(data, &packet_size, &Net_players[i].p_info.addr);
// add his id#
ADD_SHORT(Net_players[i].player_id);
// add his callsign
ADD_STRING(Net_players[i].m_player->callsign);
// add his image filename
ADD_STRING(Net_players[i].m_player->image_filename);
// add his squad filename
ADD_STRING(Net_players[i].m_player->m_squad_filename);
// add his PXO squad name
ADD_STRING(Net_players[i].p_info.pxo_squad_name);
// add his flags
ADD_INT(Net_players[i].flags);
// add his object's net sig
if ( is_ingame ) {
ADD_USHORT( Objects[Net_players[i].m_player->objnum].net_signature );
}
if ( (packet_size + PLAYER_DATA_SLOP) > MAX_PACKET_SIZE ) {
stop = APD_END_PACKET;
ADD_DATA(stop);
multi_io_send_reliable( npp, data, packet_size );
BUILD_HEADER(ACCEPT_PLAYER_DATA);
stop = APD_NEXT;
}
}
// add the stop byte
stop = APD_END_DATA;
ADD_DATA(stop);
multi_io_send_reliable(npp, data, packet_size);
}
//+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// process the player data from the server
void process_accept_player_data( ubyte *data, header *hinfo )
{
int offset, player_num, player_slot_num, new_flags;
char name[CALLSIGN_LEN + 1] = "";
char image_name[MAX_FILENAME_LEN + 1] = "";
char squad_name[MAX_FILENAME_LEN + 1] = "";
char pxo_squad_name[LOGIN_LEN+1] = "";
short player_id;
net_addr addr;
ubyte stop;
ushort ig_signature;
offset = HEADER_LENGTH;
GET_DATA(stop);
while ( stop == APD_NEXT ) {
player_slot_num = multi_find_open_player_slot();
Assert(player_slot_num != -1);
// get the player's number
GET_INT(player_num);
// add the player's address
// GET_DATA(addr);
get_net_addr(data, &offset, &addr);
// get the player's id#
GET_SHORT(player_id);
// get his callsign
GET_STRING(name);
// add his image filename
GET_STRING(image_name);
// get his squad logo filename
GET_STRING(squad_name);
// get his PXO squad name
GET_STRING(pxo_squad_name);
// get his flags
GET_INT(new_flags);
if (Net_players[player_num].flags & NETINFO_FLAG_OBSERVER) {
if (!multi_obs_create_player(player_num, name, &addr, &Players[player_slot_num])) {
Int3();
}
} else {
// the error handling here is less than stellar. We should probably put up a popup and go
// back to the main menu. But then again, this should never ever happen!
if ( !multi_create_player(player_num, &Players[player_slot_num],name, &addr, -1, player_id) ) {
Int3();
}
}
// copy his image filename
strcpy_s(Net_players[player_num].m_player->image_filename, image_name);
// copy his pilot squad filename
Net_players[player_num].m_player->insignia_texture = -1;
player_set_squad_bitmap(Net_players[player_num].m_player, squad_name, true);
// copy his pxo squad name
strcpy_s(Net_players[player_num].p_info.pxo_squad_name, pxo_squad_name);
// set his player id#
Net_players[player_num].player_id = player_id;
// mark him as being connected
Net_players[player_num].flags |= NETINFO_FLAG_CONNECTED;
Net_players[player_num].flags |= new_flags;
// set the server pointer
if ( Net_players[player_num].flags & NETINFO_FLAG_AM_MASTER ) {
Netgame.server = &Net_players[player_num];
Netgame.server->last_heard_time = timer_get_fixed_seconds();
// also - always set the server address to be where this data came from, NOT from
// the data in the packet
fill_net_addr(&Net_players[player_num].p_info.addr, hinfo->addr, hinfo->net_id, hinfo->port);
}
// set the host pointer
if ( Net_players[player_num].flags & NETINFO_FLAG_GAME_HOST ) {
Netgame.host = &Net_players[player_num];
}
// read in the player's object net signature and store as his objnum for now
if ( Net_player->flags & NETINFO_FLAG_ACCEPT_INGAME ) {
GET_USHORT( ig_signature );
Net_players[player_num].m_player->objnum = ig_signature;
}
// get the stop byte
GET_DATA(stop);
}
PACKET_SET_SIZE();
if ( stop == APD_END_DATA ) {
// if joining a game automatically, set the connect address to NULl so we don't try and
// do this next time we enter a game
if (Cmdline_connect_addr != NULL) {
Cmdline_connect_addr = NULL;
}
// send my stats to the server if I'm not in observer mode
if (!(Net_player->flags & NETINFO_FLAG_ACCEPT_OBSERVER)) {
send_player_stats_block_packet(Net_player, STATS_ALLTIME);
}
// if i'm being accepted as a host, then move into the host setup state
if ( Net_player->flags & NETINFO_FLAG_ACCEPT_HOST) {
// set my permission bits
Net_player->flags |= NETINFO_FLAG_GAME_HOST;
Net_player->state = NETPLAYER_STATE_STD_HOST_SETUP;
gameseq_post_event(GS_EVENT_MULTI_START_GAME);
}
if ( Net_player->flags & NETINFO_FLAG_ACCEPT_OBSERVER) {
Net_player->flags |= NETINFO_FLAG_OBSERVER;
// since observers can join 1 of 2 ways, only do this if we're not doing an ingame observer join
if ( !(Net_player->flags & NETINFO_FLAG_ACCEPT_INGAME) ) {
gameseq_post_event(GS_EVENT_MULTI_CLIENT_SETUP);
}
}
if ( Net_player->flags & NETINFO_FLAG_ACCEPT_CLIENT) {
gameseq_post_event(GS_EVENT_MULTI_CLIENT_SETUP);
}
if ( Net_player->flags & NETINFO_FLAG_ACCEPT_INGAME) {
// flag myself as being an ingame joiner
Net_player->flags |= NETINFO_FLAG_INGAME_JOIN;
// move myself into the ingame join mission sync state
Multi_sync_mode = MULTI_SYNC_INGAME;
gameseq_post_event(GS_EVENT_MULTI_MISSION_SYNC);
}
// update my options on the server
multi_options_update_local();
// if we're in PXO mode, mark it down in our player struct
if(MULTI_IS_TRACKER_GAME){
Player->flags |= PLAYER_FLAGS_HAS_PLAYED_PXO;
Player->save_flags |= PLAYER_FLAGS_HAS_PLAYED_PXO;
}
}
}
//*********************************************************************************************************
// Accept Player Packet
//*********************************************************************************************************
/*
struct fs2_accept_packet
{
char packet_signature;
int code;
if (code & ACCEPT_INGAME)
{
int gm_mis_fname_len;
char mission_filename[gm_mis_fname_len];
unsigned char ingame_joining_team;
if (ingame_joining_team == 1)
unsigned char ingame_join_team;
}
int skill_level;
int player_num;
short player_id;
int netgame_type_flags;
}
*/
// send an accept packet to a client in response to a request to join the game
void send_accept_packet(int new_player_num, int code, int ingame_join_team)
{
int packet_size, i;
ubyte data[MAX_PACKET_SIZE],val;
char notify_string[256];
// sanity
Assert(new_player_num >= 0);
// setup his "reliable" socket
Net_players[new_player_num].last_heard_time = timer_get_fixed_seconds();
// build the packet header
packet_size = 0;
BUILD_HEADER(ACCEPT);
// add the accept code
ADD_INT(code);
// add code specific accept data
if (code & ACCEPT_INGAME) {
// the game filename
ADD_STRING(Game_current_mission_filename);
// if he is joining on a specific team, mark it here
if(ingame_join_team != -1){
val = 1;
ADD_DATA(val);
val = (ubyte)ingame_join_team;
ADD_DATA(val);
} else {
val = 0;
ADD_DATA(val);
}
}
if (code & ACCEPT_OBSERVER) {
Assert(!(code & (ACCEPT_CLIENT | ACCEPT_HOST)));
}
if (code & ACCEPT_HOST) {
Assert(!(code & (ACCEPT_CLIENT | ACCEPT_OBSERVER | ACCEPT_INGAME)));
}
if (code & ACCEPT_CLIENT) {
Assert(!(code & (ACCEPT_HOST | ACCEPT_OBSERVER | ACCEPT_INGAME)));
}
// add the current skill level setting on the host
// sanity check - reset skill level to default before sending if out of range
if (Game_skill_level < 0 || Game_skill_level >= NUM_SKILL_LEVELS) {
Warning(LOCATION, "Trying to send packet containing invalid skill level %i! Valid range 0 to %i. Resetting to default.", Game_skill_level, NUM_SKILL_LEVELS);
Game_skill_level = game_get_default_skill_level();
}
ADD_INT(Game_skill_level);
// add this guys player num
ADD_INT(new_player_num);
// add his player id
ADD_SHORT(Net_players[new_player_num].player_id);
// add netgame type flags
ADD_INT(Netgame.type_flags);
//#ifndef NDEBUG
// char buffer[100];
// nprintf(("Network", "About to send accept packet to %s on port %d\n", get_text_address(buffer, addr->addr), addr->port ));
//#endif
// actually send the packet
psnet_send(&Net_players[new_player_num].p_info.addr, data, packet_size);
// if he's not an observer, inform all the other players in the game about him
// inform the other players in the game about this new player
for (i=0; i<MAX_PLAYERS; i++) {
// skip unconnected players as well as this new guy himself
if ( !MULTI_CONNECTED(Net_players[i]) || psnet_same(&Net_players[new_player_num].p_info.addr, &(Net_players[i].p_info.addr)) || (Net_player == &Net_players[i])) {
continue;
}
// send the new packet
send_new_player_packet(new_player_num,&Net_players[i]);
}
// add a chat message
if(Net_players[new_player_num].m_player->callsign != NULL){
sprintf(notify_string,XSTR("<%s has joined>",717), Net_players[new_player_num].m_player->callsign);
multi_display_chat_msg(notify_string, 0, 0);
}
// handle any team vs. team details
if (!(code & ACCEPT_OBSERVER)) {
multi_team_handle_join(&Net_players[new_player_num]);
}
// NETLOG
if(Net_players[new_player_num].tracker_player_id >= 0){
ml_printf(NOX("Server accepted %s (tracker id %d) as new client"), Net_players[new_player_num].m_player->callsign, Net_players[new_player_num].tracker_player_id);
} else {
ml_printf(NOX("Server accepted %s as new client"), Net_players[new_player_num].m_player->callsign);
}
}
// process an accept packet from the server
extern int Select_default_ship;
void process_accept_packet(ubyte* data, header* hinfo)
{
int code, my_player_num, offset;
ubyte val,team = 0;
short player_id;
// get the accept code
offset = HEADER_LENGTH;
GET_INT(code);
// read in the accept code specific data
val = 0;
if (code & ACCEPT_INGAME) {
// the game filename
GET_STRING(Game_current_mission_filename);
mprintf(("Got mission filename %s\n", Game_current_mission_filename));
Select_default_ship = 0;
// determine if I'm being placed on a team
GET_DATA(val);
if(val){
GET_DATA(team);
}
}
if (code & ACCEPT_OBSERVER) {
Assert(!(code & (ACCEPT_CLIENT | ACCEPT_HOST)));
}
if (code & ACCEPT_HOST) {
Assert(!(code & (ACCEPT_CLIENT | ACCEPT_OBSERVER | ACCEPT_INGAME)));
}
if (code & ACCEPT_CLIENT) {
Assert(!(code & (ACCEPT_HOST | ACCEPT_OBSERVER | ACCEPT_INGAME)));
}
// fill in the netgame server address
fill_net_addr( &Netgame.server_addr, hinfo->addr, hinfo->net_id, hinfo->port );
// get the skill level setting
GET_INT(Game_skill_level);
if (Game_skill_level < 0 || Game_skill_level >= NUM_SKILL_LEVELS) {
Warning(LOCATION, "Received packet containing invalid skill level %i! Valid range 0 to %i. Resetting to default.", Game_skill_level, NUM_SKILL_LEVELS);
Game_skill_level = game_get_default_skill_level();
}
// get my netplayer number
GET_INT(my_player_num);
// get my id #
GET_SHORT(player_id);
// get netgame type flags
GET_INT(Netgame.type_flags);
// setup the Net_players structure for myself first
Net_player = &Net_players[my_player_num];
Net_player->flags = 0;
Net_player->tracker_player_id = Multi_tracker_id;
Net_player->player_id = player_id;
Net_player->s_info.xfer_handle = -1;
// stuff_netplayer_info( Net_player, &Psnet_my_addr, Ships[Objects[Player->objnum].instance].ship_info_index, Player );
stuff_netplayer_info( Net_player, &Psnet_my_addr, 0, Player );
multi_options_local_load(&Net_player->p_info.options, Net_player);
Net_player->p_info.team = team;
// determine if I have a CD
if(Multi_has_cd){
Net_player->flags |= NETINFO_FLAG_HAS_CD;
}
// set accept code in netplayer for this guy
if ( code & ACCEPT_INGAME ){
Net_player->flags |= NETINFO_FLAG_ACCEPT_INGAME;
}
if ( code & ACCEPT_OBSERVER ){
Net_player->flags |= NETINFO_FLAG_ACCEPT_OBSERVER;
}
if ( code & ACCEPT_HOST ){
Net_player->flags |= NETINFO_FLAG_ACCEPT_HOST;
}
if ( code & ACCEPT_CLIENT ){
Net_player->flags |= NETINFO_FLAG_ACCEPT_CLIENT;
}
// if I have hacked data
if(game_hacked_data()){
Net_player->flags |= NETINFO_FLAG_HAXOR;
}
// if we're supposed to flush our local data cache, do so now
if(Net_player->p_info.options.flags & MLO_FLAG_FLUSH_CACHE){
multi_flush_multidata_cache();
}
Net_player->sv_bytes_sent = 0;
Net_player->sv_last_pl = -1;
Net_player->cl_bytes_recvd = 0;
Net_player->cl_last_pl = -1;
// intiialize endgame stuff
multi_endgame_init();
PACKET_SET_SIZE();
// make a call to psnet to initialize and try to connect with the server.
psnet_rel_connect_to_server( &Net_player->reliable_socket, &Netgame.server_addr );
if ( Net_player->reliable_socket == INVALID_SOCKET ) {
multi_quit_game(PROMPT_NONE, MULTI_END_NOTIFY_NONE, MULTI_END_ERROR_CONNECT_FAIL);
}
}
//*********************************************************************************************************
// Player Leave Packet
//*********************************************************************************************************
/*
struct fs2_leave_game_packet
{
char packet_signature;
char kicked_reason;
short player_id;
}
*/
// send a notice that the player at net_addr is leaving (if target is NULL, the broadcast the packet)
void send_leave_game_packet(short player_id, int kicked_reason, net_player *target)
{
ubyte data[MAX_PACKET_SIZE];
char val;
int packet_size = 0;
BUILD_HEADER(LEAVE_GAME);
// add a flag indicating whether he was kicked or not
val = (char)kicked_reason;
ADD_DATA(val);
if (player_id < 0) {
ADD_SHORT(Net_player->player_id);
// inform the host that we are leaving the game
if (Net_player->flags & NETINFO_FLAG_AM_MASTER) {
multi_io_send_to_all_reliable(data, packet_size);
} else {
multi_io_send_reliable(Net_player, data, packet_size);
}
}
// this is the case where to server is tossing a player (or indicating a respawned player has quit or become an observer)
// so he has to tell everyone that this guy left
else {
nprintf(("Network","Sending a leave game packet to all players (server)\n"));
// a couple of important checks
Assert(player_id != Net_player->player_id);
Assert(Net_player->flags & NETINFO_FLAG_AM_MASTER);
// add the id of the guy to be kicked
ADD_SHORT(player_id);
// broadcast to everyone
if (target == NULL) {
multi_io_send_to_all_reliable(data, packet_size);
} else {
multi_io_send_reliable(target, data, packet_size);
}
}
}
// process a notification that a player has left the game
void process_leave_game_packet(ubyte* data, header* hinfo)
{
int offset;
short deader_id;
int player_num;
char kicked_reason;
char str[512];
offset = HEADER_LENGTH;
// get whether he was kicked
GET_DATA(kicked_reason);
// get the address of the guy who is to leave
GET_SHORT(deader_id);
PACKET_SET_SIZE();
// determine who is dropping and printf out a notification
player_num = find_player_id(deader_id);
if (player_num == -1) {
nprintf(("Network", "Received leave game packet for unknown player, ignoring\n"));
return;
} else {
nprintf(("Network", "Received a leave game notice for %s\n", Net_players[player_num].m_player->callsign));
}
// a hook to display that a player was kicked
if (kicked_reason >= 0){
// if it was me that was kicked, leave the game
if((Net_player != NULL) && (Net_player->player_id == deader_id)){
int notify_code;
switch(kicked_reason){
case KICK_REASON_BAD_XFER:
notify_code = MULTI_END_NOTIFY_KICKED_BAD_XFER;
break;
case KICK_REASON_CANT_XFER:
notify_code = MULTI_END_NOTIFY_KICKED_CANT_XFER;
break;
case KICK_REASON_INGAME_ENDED:
notify_code = MULTI_END_NOTIFY_KICKED_INGAME_ENDED;
break;
default:
notify_code = MULTI_END_NOTIFY_KICKED;
break;
}
multi_quit_game(PROMPT_NONE, notify_code);
return;
// otherwise indicate someone was kicked
} else {
nprintf(("Network","%s was kicked\n",Net_players[player_num].m_player->callsign));
// display the result
memset(str, 0, 512);
multi_kick_get_text(&Net_players[player_num], kicked_reason, str);
multi_display_chat_msg(str, player_num, 0);
}
}
// first of all, if we're the master, we should be rebroadcasting this packet
if (Net_player->flags & NETINFO_FLAG_AM_MASTER) {
char msg[255];
sprintf(msg, XSTR("%s has left the game",719), Net_players[player_num].m_player->callsign );
if (!(Game_mode & GM_STANDALONE_SERVER)){
HUD_sourced_printf(HUD_SOURCE_HIDDEN, msg);
}
send_hud_msg_to_all(msg);
multi_io_send_to_all_reliable(data, offset);
}
// leave the game if the host and/or master has dropped
/*
if (((Net_players[player_num].flags & NETINFO_FLAG_AM_MASTER) || (Net_players[player_num].flags & NETINFO_FLAG_GAME_HOST)) ) {
nprintf(("Network","Host and/or server has left the game - aborting...\n"));
// NETLOG
ml_string(NOX("Host and/or server has left the game"));
// if the host leaves in the debriefing state, we should still wait until the player selects accept before we quit
if (gameseq_get_state() != GS_STATE_DEBRIEF) {
multi_quit_game(PROMPT_NONE, MULTI_END_NOTIFY_SERVER_LEFT);
}
delete_player(player_num);
} else {
*/
delete_player(player_num);
// OSAPI GUI stuff (if standalone)
if (Game_mode & GM_STANDALONE_SERVER) {
// returns true if we should reset the standalone
if (std_remove_player(&Net_players[player_num])) {
nprintf(("Network", "Should reset!!\n"));
return;
}
// update these gui vals
std_connect_set_host_connect_status();
std_connect_set_connect_count();
}
}
//*********************************************************************************************************
// Game active packet
//*********************************************************************************************************
/*
struct fs2_game_active_packet
{
char packet_signature;
ubyte server_version;
ubyte compat_version;
int len1;
char netgame_name[len1];
int len2;
char netgame_mission_name[len2];
int len3;
char netgame_title[len3];
ubyte num_players;
unsigned short flags;
}
*/
// send information about this currently active game to the specified address
void send_game_active_packet(net_addr* addr)
{
int packet_size;
ushort flags;
ubyte data[MAX_PACKET_SIZE],val;
// build the header and add the data
BUILD_HEADER(GAME_ACTIVE);
// add the server version and compatible version #
val = MULTI_FS_SERVER_VERSION;
ADD_DATA(val);
val = MULTI_FS_SERVER_COMPATIBLE_VERSION;
ADD_DATA(val);
ADD_STRING(Netgame.name);
ADD_STRING(Netgame.mission_name);
ADD_STRING(Netgame.title);
val = (ubyte)multi_num_players();
ADD_DATA(val);
// add the proper flags
flags = 0;
if ( (Netgame.mode == NG_MODE_PASSWORD) || ((Game_mode & GM_STANDALONE_SERVER) && (multi_num_players() == 0) && (std_is_host_passwd())) ) {
flags |= AG_FLAG_PASSWD;
}
// proper netgame type flags
if(Netgame.type_flags & NG_TYPE_TEAM){
flags |= AG_FLAG_TEAMS;
} else if(Netgame.type_flags & NG_TYPE_DOGFIGHT){
flags |= AG_FLAG_DOGFIGHT;
} else {
flags |= AG_FLAG_COOP;
}
// proper netgame state flags
switch(Netgame.game_state){
case NETGAME_STATE_FORMING:
flags |= AG_FLAG_FORMING;
break;
case NETGAME_STATE_BRIEFING:
case NETGAME_STATE_MISSION_SYNC:
case NETGAME_STATE_HOST_SETUP:
flags |= AG_FLAG_BRIEFING;
break;
case NETGAME_STATE_IN_MISSION:
flags |= AG_FLAG_IN_MISSION;
break;
case NETGAME_STATE_PAUSED:
flags |= AG_FLAG_PAUSE;
break;
case NETGAME_STATE_ENDGAME:
case NETGAME_STATE_DEBRIEF:
flags |= AG_FLAG_DEBRIEF;
break;
}
// if this is a standalone
if(Game_mode & GM_STANDALONE_SERVER){
flags |= AG_FLAG_STANDALONE;
}
// if we're in campaign mode
if(Netgame.campaign_mode == MP_CAMPAIGN){
flags |= AG_FLAG_CAMPAIGN;
}
// add the data about the connection speed of the host machine
Assert( (Multi_connection_speed >= 0) && (Multi_connection_speed <= 4) );
flags |= (Multi_connection_speed << AG_FLAG_CONNECTION_BIT);
ADD_USHORT(flags);
// send the data
psnet_send(addr, data, packet_size);
}
// process information about an active game
void process_game_active_packet(ubyte* data, header* hinfo)
{
int offset;
ubyte val;
active_game ag;
int modes_compatible = 1;
fill_net_addr(&ag.server_addr, hinfo->addr, hinfo->net_id, hinfo->port);
// read this game into a temporary structure
offset = HEADER_LENGTH;
// get the server version and compatible version
GET_DATA(ag.version);
GET_DATA(ag.comp_version);
GET_STRING(ag.name);
GET_STRING(ag.mission_name);
GET_STRING(ag.title);
GET_DATA(val);
ag.num_players = val;
GET_USHORT(ag.flags);
PACKET_SET_SIZE();
if ( (ag.flags & AG_FLAG_TRACKER) && !Multi_options_g.pxo )
modes_compatible = 0;
if ( !(ag.flags & AG_FLAG_TRACKER) && Multi_options_g.pxo )
modes_compatible = 0;
// if this is a compatible version, and our modes are compatible, register it
if ( (ag.version == MULTI_FS_SERVER_VERSION) && modes_compatible ) {
multi_update_active_games(&ag);
}
}
//*********************************************************************************************************
// Game Update Packet
//*********************************************************************************************************
/*
struct fs2_game_update
{
char packet_signature;
int len1;
char netgame_name[len1];
int len2;
char netgame_mission_name[len2];
int len3;
char netgame_title[len3];
int len4;
char netgame_campaign_name[len4];
int campaign_mode;
int max_players;
int security;
unsigned int respawn;
int flags;
int type_flags;
int version_info;
ubyte debug_flags;
// !!!!!! this isn't relying on information earlier in the packet!
// receiving seems to always assume it's there!
if(Net_player->flags & NETINFO_FLAG_AM_MASTER){
int game_state;
}
}
*/
// send_game_update_packet sends an updated Netgame structure to all players currently connected. The update
// is used to change the current mission, current state, etc.
void send_netgame_update_packet(net_player *pl)
{
int packet_size;
int idx;
ubyte data[MAX_PACKET_SIZE];
packet_size = 0;
BUILD_HEADER(GAME_UPDATE);
// with new mission description field, this becomes way to large
// so we must add every element piece by piece except the
ADD_STRING(Netgame.name);
ADD_STRING(Netgame.mission_name);
ADD_STRING(Netgame.title);
ADD_STRING(Netgame.campaign_name);
ADD_INT(Netgame.campaign_mode);
ADD_INT(Netgame.max_players);
ADD_INT(Netgame.security);
ADD_UINT(Netgame.respawn);
ADD_INT(Netgame.flags);
ADD_INT(Netgame.type_flags);
ADD_INT(Netgame.version_info);
ADD_DATA(Netgame.debug_flags);
// only the server should ever send the netgame state (standalone situation)
if(Net_player->flags & NETINFO_FLAG_AM_MASTER){
ADD_INT(Netgame.game_state);
}
// if we're the host on a standalone, send to the standalone and let him rebroadcast
if(Net_player->flags & NETINFO_FLAG_AM_MASTER){
if ( pl == NULL ) {
multi_io_send_to_all_reliable(data, packet_size);
for(idx=0; idx<MAX_PLAYERS; idx++){
if(MULTI_CONNECTED(Net_players[idx]) && (Net_player != &Net_players[idx])){
send_netgame_descript_packet(&Net_players[idx].p_info.addr, 1);
}
}
} else {
multi_io_send_reliable(pl, data, packet_size);
send_netgame_descript_packet( &pl->p_info.addr , 1 );
}
} else {
Assert( pl == NULL ); // I don't think that a host in a standalone game would get here.
multi_io_send_reliable(Net_player, data, packet_size);
}
// host should always send a netgame options update as well
if(Net_player->flags & NETINFO_FLAG_GAME_HOST){
multi_options_update_netgame();
}
}
// process information about the netgame sent from the server/host
void process_netgame_update_packet( ubyte *data, header *hinfo )
{
int offset;
int ng_state;
Assert(!(Game_mode & GM_STANDALONE_SERVER));
Assert(!(Net_player->flags & NETINFO_FLAG_AM_MASTER));
// read in the netgame information
offset = HEADER_LENGTH;
GET_STRING(Netgame.name);
GET_STRING(Netgame.mission_name);
GET_STRING(Netgame.title);
GET_STRING(Netgame.campaign_name);
GET_INT(Netgame.campaign_mode);
GET_INT(Netgame.max_players); // ignore on the standalone, who keeps track of this himself
GET_INT(Netgame.security);
GET_UINT(Netgame.respawn);
// be sure not to blast the quitting flag because of the "one frame extra" problem
GET_INT(Netgame.flags);
GET_INT(Netgame.type_flags);
GET_INT(Netgame.version_info);
GET_DATA(Netgame.debug_flags);
// netgame state
GET_INT(ng_state);
PACKET_SET_SIZE();
// now compare the passed in game state to our current known state. If it has changed, then maybe
// do something interesting.
// move from the forming or debriefing state to the mission sync state
if ( ng_state == NETGAME_STATE_MISSION_SYNC ){
// if coming from the forming state
if( (Netgame.game_state == NETGAME_STATE_FORMING) ||
((Netgame.game_state != NETGAME_STATE_FORMING) && ((gameseq_get_state() == GS_STATE_MULTI_HOST_SETUP) || (gameseq_get_state() == GS_STATE_MULTI_CLIENT_SETUP))) ){
// do any special processing for forced state transitions
multi_handle_state_special();
Multi_sync_mode = MULTI_SYNC_PRE_BRIEFING;
strncpy( Game_current_mission_filename, Netgame.mission_name, MAX_FILENAME_LEN );
gameseq_post_event(GS_EVENT_MULTI_MISSION_SYNC);
}
// if coming from the debriefing state
else if( (Netgame.game_state == NETGAME_STATE_DEBRIEF) ||
((Netgame.game_state != NETGAME_STATE_DEBRIEF) && ((gameseq_get_state() == GS_STATE_DEBRIEF) || (gameseq_get_state() == GS_STATE_MULTI_DOGFIGHT_DEBRIEF)) ) ){
// do any special processing for forced state transitions
multi_handle_state_special();
multi_flush_mission_stuff();
Multi_sync_mode = MULTI_SYNC_PRE_BRIEFING;
strncpy( Game_current_mission_filename, Netgame.mission_name, MAX_FILENAME_LEN );
gameseq_post_event(GS_EVENT_MULTI_MISSION_SYNC);
}
}
// move from mission sync to team select
else if ( ng_state == NETGAME_STATE_BRIEFING ){
if( (Netgame.game_state == NETGAME_STATE_MISSION_SYNC) ||
((Netgame.game_state != NETGAME_STATE_MISSION_SYNC) && (gameseq_get_state() == GS_STATE_MULTI_MISSION_SYNC) && (Multi_sync_mode != MULTI_SYNC_POST_BRIEFING)) ){
// do any special processing for forced state transitions
multi_handle_state_special();
strncpy( Game_current_mission_filename, Netgame.mission_name, MAX_FILENAME_LEN );
gameseq_post_event(GS_EVENT_START_BRIEFING);
}
}
// move from the debriefing to the create game screen
else if ( ng_state == NETGAME_STATE_FORMING ){
if( (Netgame.game_state == NETGAME_STATE_DEBRIEF) ||
((Netgame.game_state != NETGAME_STATE_DEBRIEF) && ((gameseq_get_state() == GS_STATE_DEBRIEF) || (gameseq_get_state() == GS_STATE_MULTI_DOGFIGHT_DEBRIEF)) ) ){
// do any special processing for forced state transitions
multi_handle_state_special();
multi_flush_mission_stuff();
// move to the proper screen
if(Net_player->flags & NETINFO_FLAG_GAME_HOST){
gameseq_post_event(GS_EVENT_MULTI_HOST_SETUP);
} else {
gameseq_post_event(GS_EVENT_MULTI_CLIENT_SETUP);
}
}
}
Netgame.game_state = ng_state;
}
//*********************************************************************************************************
// Game Update Packet
//*********************************************************************************************************
/*
*/
// send a request or a reply for mission description, if code == 0, request, if code == 1, reply
void send_netgame_descript_packet(net_addr *addr, int code)
{
ubyte data[MAX_PACKET_SIZE],val;
int desc_len;
int packet_size = 0;
// build the header
BUILD_HEADER(UPDATE_DESCRIPT);
val = (ubyte)code;
ADD_DATA(val);
if(code == 1){
// add as much of the description as we dare
desc_len = strlen(The_mission.mission_desc);
if(desc_len > MAX_PACKET_SIZE - 10){
desc_len = MAX_PACKET_SIZE - 10;
ADD_INT(desc_len);
memcpy(data+packet_size, The_mission.mission_desc, desc_len);
packet_size += desc_len;
} else {
ADD_STRING(The_mission.mission_desc);
}
}
Assert(addr != NULL);
if(addr != NULL){
psnet_send(addr, data, packet_size);
}
}
// process an incoming netgame description packet
void process_netgame_descript_packet( ubyte *data, header *hinfo )
{
int offset,state;
ubyte code;
char mission_desc[MISSION_DESC_LENGTH+2];
net_addr addr;
fill_net_addr(&addr, hinfo->addr, hinfo->net_id, hinfo->port);
// read this game into a temporary structure
offset = HEADER_LENGTH;
GET_DATA(code);
// if this is a request for mission description
if(code == 0){
if(!(Net_player->flags & NETINFO_FLAG_AM_MASTER)){
PACKET_SET_SIZE();
return;
}
// send an update to this guy
send_netgame_descript_packet(&addr, 1);
} else {
memset(mission_desc,0,MISSION_DESC_LENGTH+2);
GET_STRING(mission_desc);
// only display if we're in the proper state
state = gameseq_get_state();
switch(state){
case GS_STATE_MULTI_JOIN_GAME:
case GS_STATE_MULTI_CLIENT_SETUP:
case GS_STATE_MULTI_HOST_SETUP:
multi_common_set_text(mission_desc);
break;
}
}
PACKET_SET_SIZE();
}
// broadcast a query for active games. IPX will use net broadcast and TCP will either request from the MT or from the specified list
void broadcast_game_query()
{
int packet_size;
net_addr addr;
server_item *s_moveup;
ubyte data[MAX_PACKET_SIZE];
if ( MULTI_IS_TRACKER_GAME && (Multi_options_g.protocol == NET_TCP) ) {
fs2netd_send_game_request();
return;
}
BUILD_HEADER(GAME_QUERY);
// go through the server list and query each of those as well
s_moveup = Game_server_head;
if(s_moveup != NULL){
do {
send_server_query(&s_moveup->server_addr);
s_moveup = s_moveup->next;
} while(s_moveup != Game_server_head);
}
fill_net_addr(&addr, Psnet_my_addr.addr, Psnet_my_addr.net_id, DEFAULT_GAME_PORT);
// send out a broadcast if our options allow us
if(Net_player->p_info.options.flags & MLO_FLAG_LOCAL_BROADCAST){
psnet_broadcast( &addr, data, packet_size);
}
}
// send an individual query to an address to see if there is an active game
void send_server_query(net_addr *addr)
{
int packet_size;
ubyte data[MAX_PACKET_SIZE];
// build the header and send the data
BUILD_HEADER(GAME_QUERY);
psnet_send(addr, data, packet_size);
}
// process a query from a client looking for active freespace games
void process_game_query(ubyte* data, header* hinfo)
{
int offset;
net_addr addr;
offset = HEADER_LENGTH;
PACKET_SET_SIZE();
// check to be sure that we don't capture our own broadcast message
fill_net_addr(&addr, hinfo->addr, hinfo->net_id, hinfo->port);
if ( psnet_same( &addr, &Psnet_my_addr) ){
return;
}
// if I am not a server of a game, don't send a reply!!!
if ( !(Net_player->flags & NETINFO_FLAG_AM_MASTER) ){
return;
}
// if the game options are being selected, then ignore the request
// also, if Netgame.max_players == -1, the host has not chosen a mission yet and we should wait
if((Netgame.game_state == NETGAME_STATE_STD_HOST_SETUP) || (Netgame.game_state == NETGAME_STATE_HOST_SETUP) || (Netgame.game_state == 0) || (Netgame.max_players == -1)){
return;
}
// send information about this active game
send_game_active_packet(&addr);
}
// sends information about netplayers in the game. if called on the server, broadcasts information about _all_ players
void send_netplayer_update_packet( net_player *pl )
{
int packet_size,idx;
ubyte data[MAX_PACKET_SIZE],val;
BUILD_HEADER(NETPLAYER_UPDATE);
// if I'm the server of the game, I should send an update for _all_players in the game
if(Net_player->flags & NETINFO_FLAG_AM_MASTER){
for(idx=0;idx<MAX_PLAYERS;idx++){
// only send info for connected players
if(MULTI_CONNECTED(Net_players[idx])){
// add a stop byte
val = 0x0;
ADD_DATA(val);
// add the net player's information
ADD_SHORT(Net_players[idx].player_id);
ADD_INT(Net_players[idx].state);
ADD_INT(Net_players[idx].p_info.ship_class);
ADD_INT(Net_players[idx].tracker_player_id);
if(Net_players[idx].flags & NETINFO_FLAG_HAS_CD){
val = 1;
} else {
val = 0;
}
ADD_DATA(val);
}
}
// add the final stop byte
val = 0xff;
ADD_DATA(val);
// broadcast the packet
if(!(Game_mode & GM_IN_MISSION)){
if ( pl == NULL ) {
multi_io_send_to_all_reliable(data, packet_size);
} else {
multi_io_send_reliable(pl, data, packet_size);
}
} else {
if ( pl == NULL ) {
multi_io_send_to_all(data, packet_size);
} else {
multi_io_send(pl, data, packet_size);
}
}
} else {
// add a stop byte
val = 0x0;
ADD_DATA(val);
// add my current state in the netgame to this packet
ADD_SHORT(Net_player->player_id);
ADD_INT(Net_player->state);
ADD_INT(Net_player->p_info.ship_class);
ADD_INT(Multi_tracker_id);
// add if I have a CD or not
if(Multi_has_cd){
val = 1;
} else {
val = 0;
}
ADD_DATA(val);
// add a final stop byte
val = 0xff;
ADD_DATA(val);
// send the packet to the server
Assert( pl == NULL ); // shouldn't ever be the case that pl is non-null here.
if(!(Game_mode & GM_IN_MISSION)){
multi_io_send_reliable(Net_player, data, packet_size);
} else {
multi_io_send(Net_player, data, packet_size);
}
}
}
// process an incoming netplayer state update. if we're the server, we should rebroadcast
void process_netplayer_update_packet( ubyte *data, header *hinfo )
{
int offset, player_num;
net_player bogus;
ubyte stop, has_cd;
short player_id;
int new_state;
offset = HEADER_LENGTH;
// get the first stop byte
GET_DATA(stop);
player_num = -1;
while(stop != 0xff){
// look the player up
GET_SHORT(player_id);
player_num = find_player_id(player_id);
// if we couldn't find him, read in the bogus data
if((player_num == -1) || (Net_player == &Net_players[player_num])){
GET_INT(bogus.state);
GET_INT(bogus.p_info.ship_class);
GET_INT(bogus.tracker_player_id);
GET_DATA(has_cd);
}
// otherwise read in the data correctly
else {
GET_INT(new_state);
GET_INT(Net_players[player_num].p_info.ship_class);
GET_INT(Net_players[player_num].tracker_player_id);
GET_DATA(has_cd);
if(has_cd){
Net_players[player_num].flags |= NETINFO_FLAG_HAS_CD;
} else {
Net_players[player_num].flags &= ~(NETINFO_FLAG_HAS_CD);
}
// if he's changing state to joined, send a team update
if((Net_players[player_num].state == NETPLAYER_STATE_JOINING) && (new_state == NETPLAYER_STATE_JOINED) && (Netgame.type_flags & NG_TYPE_TEAM)){
multi_team_send_update();
}
// set state
Net_players[player_num].state = new_state;
}
// get the next stop byte
GET_DATA(stop);
}
PACKET_SET_SIZE();
// if I'm the host or the server of the game, update everyone else so things are synched up as tightly as possible
if(Net_player->flags & NETINFO_FLAG_AM_MASTER){
send_netplayer_update_packet(NULL);
}
// if i'm the standalone and this is an update from the host, maybe change some netgame settings
if((Game_mode & GM_STANDALONE_SERVER) && (player_num != -1) && (Net_players[player_num].flags & NETINFO_FLAG_GAME_HOST)){
switch(Net_players[player_num].state){
case NETPLAYER_STATE_STD_HOST_SETUP:
Netgame.game_state = NETGAME_STATE_STD_HOST_SETUP;
break;
case NETPLAYER_STATE_HOST_SETUP:
// check for race conditions
if(Netgame.game_state != NETGAME_STATE_MISSION_SYNC){
Netgame.game_state = NETGAME_STATE_FORMING;
}
break;
}
}
}
#define EXTRA_DEATH_VAPORIZED (1<<0)
#define EXTRA_DEATH_WASHED (1<<1)
// send a packet indicating a ship has been killed
void send_ship_kill_packet( object *objp, object *other_objp, float percent_killed, int self_destruct )
{
int packet_size, model;
ubyte data[MAX_PACKET_SIZE], was_player, extra_death_info, vaporized;
ushort debris_signature;
ubyte sd;
polymodel * pm;
// only sendable from the master
Assert ( Net_player->flags & NETINFO_FLAG_AM_MASTER );
// special deaths
vaporized = ( (Ships[objp->instance].flags & SF_VAPORIZE) > 0 );
extra_death_info = 0;
if ( vaporized ) {
extra_death_info |= EXTRA_DEATH_VAPORIZED;
}
if ( Ships[objp->instance].wash_killed ) {
extra_death_info |= EXTRA_DEATH_WASHED;
}
// find out the next network signature that will be used for the debris pieces.
model = Ship_info[Ships[objp->instance].ship_info_index].model_num;
pm = model_get(model);
debris_signature = 0;
if ( pm && !vaporized ) {
debris_signature = multi_get_next_network_signature( MULTI_SIG_DEBRIS );
multi_set_network_signature( (ushort)(debris_signature + pm->num_debris_objects), MULTI_SIG_DEBRIS );
Ships[objp->instance].debris_net_sig = debris_signature;
}
BUILD_HEADER(SHIP_KILL);
ADD_USHORT(objp->net_signature);
// ships which are initially killed get the rest of the data sent. self destructed ships and
if ( other_objp == NULL ) {
ushort temp;
temp = 0;
ADD_USHORT(temp);
nprintf(("Network","Don't know other_obj for ship kill packet, sending NULL\n"));
} else {
ADD_USHORT( other_objp->net_signature );
}
ADD_USHORT( debris_signature );
ADD_FLOAT( percent_killed );
sd = (ubyte)self_destruct;
ADD_DATA(sd);
ADD_DATA( extra_death_info );
// if the ship who died is a player, then send some extra info, like who killed him, etc.
was_player = 0;
if ( objp->flags & OF_PLAYER_SHIP ) {
int pnum;
char temp;
short temp2;
pnum = multi_find_player_by_object( objp );
if ( pnum != -1 ) {
was_player = 1;
ADD_DATA( was_player );
Assert(Net_players[pnum].m_player->killer_objtype < CHAR_MAX);
temp = (char)Net_players[pnum].m_player->killer_objtype;
ADD_DATA( temp );
Assert(Net_players[pnum].m_player->killer_species < CHAR_MAX);
temp = (char)Net_players[pnum].m_player->killer_species;
ADD_DATA( temp );
Assert(Net_players[pnum].m_player->killer_weapon_index < SHRT_MAX);
temp2 = (short)Net_players[pnum].m_player->killer_weapon_index;
ADD_SHORT( temp2 );
ADD_STRING( Net_players[pnum].m_player->killer_parent_name );
} else {
ADD_DATA( was_player );
}
} else {
ADD_DATA( was_player );
}
// send the packet reliably!!!
multi_io_send_to_all_reliable(data, packet_size);
}
// process a packet indicating that a ship has been killed
void process_ship_kill_packet( ubyte *data, header *hinfo )
{
int offset;
ushort ship_sig, other_sig, debris_sig;
object *sobjp, *oobjp;
float percent_killed;
ubyte was_player, extra_death_info, sd;
char killer_name[NAME_LENGTH], killer_objtype = OBJ_NONE, killer_species = 0;
short killer_weapon_index = -1;
offset = HEADER_LENGTH;
GET_USHORT(ship_sig);
GET_USHORT( other_sig );
GET_USHORT( debris_sig );
GET_FLOAT( percent_killed );
GET_DATA( sd );
GET_DATA( extra_death_info );
GET_DATA( was_player );
// pnum is >=0 when the dying ship is a pleyer ship. Get the info about how he died
if ( was_player != 0 ) {
GET_DATA( killer_objtype );
GET_DATA( killer_species );
GET_SHORT( killer_weapon_index );
GET_STRING( killer_name );
}
PACKET_SET_SIZE();
sobjp = multi_get_network_object( ship_sig );
// if I am unable to find the ship object which was killed, I have to bail and rely on getting
// another message from the server that this happened!
if ( sobjp == NULL ) {
nprintf(("Network", "Couldn't find net signature %d for kill packet\n", ship_sig));
return;
}
// set this ship's hull value to 0
sobjp->hull_strength = 0.0f;
// maybe set vaporized
if (extra_death_info & EXTRA_DEATH_VAPORIZED) {
Ships[sobjp->instance].flags |= SF_VAPORIZE;
}
// maybe set wash_killed
if (extra_death_info & EXTRA_DEATH_VAPORIZED) {
Ships[sobjp->instance].wash_killed = 1;
}
oobjp = multi_get_network_object( other_sig );
if ( was_player != 0 ) {
int pnum;
pnum = multi_find_player_by_object( sobjp );
if ( pnum != -1 ) {
Net_players[pnum].m_player->killer_objtype = killer_objtype;
Net_players[pnum].m_player->killer_species = killer_species;
Net_players[pnum].m_player->killer_weapon_index = killer_weapon_index;
strcpy_s( Net_players[pnum].m_player->killer_parent_name, killer_name );
}
}
// check to see if I need to respawn myself
multi_respawn_check(sobjp);
// store the debris signature in the arrival distance which will never get used for player ships
Ships[sobjp->instance].debris_net_sig = debris_sig;
// set this bit so that we don't accidentally start switching targets when we die
if(sobjp == Player_obj){
Game_mode |= GM_DEAD_DIED;
}
mprintf(("Network Killing off %s\n", Ships[sobjp->instance].ship_name));
// do the normal thing when not ingame joining. When ingame joining, simply kill off the ship.
if ( !(Net_player->flags & NETINFO_FLAG_INGAME_JOIN) ) {
ship_hit_kill( sobjp, oobjp, percent_killed, sd );
} else {
sobjp->flags |= OF_SHOULD_BE_DEAD;
ship_cleanup(sobjp->instance, SHIP_DESTROYED);
obj_delete( OBJ_INDEX(sobjp) );
}
}
// send a packet indicating a ship should be created
void send_ship_create_packet( object *objp, int is_support )
{
int packet_size;
ubyte data[MAX_PACKET_SIZE];
// We will pass the ship to create by name.
BUILD_HEADER(SHIP_CREATE);
ADD_USHORT(objp->net_signature);
ADD_INT( is_support );
if ( is_support ){
ADD_VECTOR( objp->pos );
}
// broadcast the packet
multi_io_send_to_all_reliable(data, packet_size);
}
// process a packet indicating a ship should be created
void process_ship_create_packet( ubyte *data, header *hinfo )
{
int offset, objnum, is_support;
ushort signature;
p_object *objp;
vec3d pos = ZERO_VECTOR;
Assert ( !(Net_player->flags & NETINFO_FLAG_AM_MASTER) );
offset = HEADER_LENGTH;
GET_USHORT(signature);
GET_INT( is_support );
if ( is_support ){
GET_VECTOR( pos );
}
PACKET_SET_SIZE();
// find the name of this ship on ship ship arrival list. if found, pass it to parse_object_create
if ( !is_support ) {
objp = mission_parse_get_arrival_ship( signature );
if ( objp != NULL ) {
objnum = parse_create_object(objp);
} else {
nprintf(("Network", "Ship with sig %d not found on ship arrival list -- not creating!!\n", signature));
}
} else {
Assert( Arriving_support_ship );
if(Arriving_support_ship == NULL){
return;
}
Arriving_support_ship->pos = pos;
Arriving_support_ship->net_signature = signature;
objnum = parse_create_object( Arriving_support_ship );
Assert( objnum != -1 );
if(objnum >= 0){
mission_parse_support_arrived( objnum );
}
}
}
// send a packet indicating a wing of ships should be created
void send_wing_create_packet( wing *wingp, int num_to_create, int pre_create_count )
{
int packet_size, index, ship_instance;
ubyte data[MAX_PACKET_SIZE];
ushort signature;
int val;
// for creating wing -- we just send the index into the wing array of this wing.
// all players load the same mission, and so their array's should all match. We also
// need to send the signature of the first ship that was created. We can find this by
// looking num_to_create places back in the ship_index field in the wing structure.
index = WING_INDEX(wingp);
ship_instance = wingp->ship_index[wingp->current_count - num_to_create];
signature = Objects[Ships[ship_instance].objnum].net_signature;
BUILD_HEADER( WING_CREATE );
ADD_INT(index);
ADD_INT(num_to_create);
ADD_USHORT(signature);
ADD_INT(pre_create_count);
val = wingp->current_wave - 1;
ADD_INT(val);
multi_io_send_to_all_reliable(data, packet_size);
}
// process a packet saying that a wing should be created
void process_wing_create_packet( ubyte *data, header *hinfo )
{
int offset, index, num_to_create;
ushort signature;
int total_arrived_count, current_wave;
offset = HEADER_LENGTH;
GET_INT(index);
GET_INT(num_to_create);
GET_USHORT(signature);
GET_INT(total_arrived_count);
GET_INT(current_wave);
PACKET_SET_SIZE();
// do a sanity check on the wing to be sure that we are actually working on a valid wing
if ( (index < 0) || (index >= Num_wings) || (Wings[index].num_waves == -1) ) {
nprintf(("Network", "invalid index %d for wing create packet\n"));
return;
}
if ( (num_to_create <= 0) || (num_to_create > Wings[index].wave_count) ) {
nprintf(("Network", "Invalid number of ships to create (%d) for wing %s\n", num_to_create, Wings[index].name));
return;
}
// bash some info
Wings[index].current_count = 0;
Wings[index].total_arrived_count = total_arrived_count;
Wings[index].current_wave = current_wave;
// set the network signature that was passed. The client should create ships in the same order
// as the server -- so all ships should get the same sigs as assigned by the server. We also
// need to set some timestamps and cues correctly to be sure that these things get created on
// the clients correctly
multi_set_network_signature( signature, MULTI_SIG_SHIP );
parse_wing_create_ships( &Wings[index], num_to_create, 1 );
}
// packet indicating a ship is departing
void send_ship_depart_packet( object *objp, int method )
{
ubyte data[MAX_PACKET_SIZE];
int packet_size;
ushort signature;
signature = objp->net_signature;
BUILD_HEADER(SHIP_DEPART);
ADD_USHORT( signature );
ADD_INT( method );
multi_io_send_to_all_reliable(data, packet_size);
}
// process a packet indicating a ship is departing
void process_ship_depart_packet( ubyte *data, header *hinfo )
{
int offset;
object *objp;
ushort signature;
int s_method;
offset = HEADER_LENGTH;
GET_USHORT( signature );
GET_INT(s_method);
PACKET_SET_SIZE();
// find the object which is departing
objp = multi_get_network_object( signature );
if ( objp == NULL ) {
nprintf(("network", "Couldn't find object with net signature %d to depart\n", signature ));
return;
}
switch (s_method) {
case SHIP_DEPARTED_BAY:
case SHIP_VANISHED:
if (objp->type == OBJ_SHIP) {
ship_actually_depart(objp->instance, s_method);
}
else {
nprintf(("network", "Can not process ship depart packed. Object with net signature %d is not a ship!\n", signature ));
return;
}
break;
// assume standard warp out
default:
// start warping him out
shipfx_warpout_start( objp );
}
}
// packet to tell clients cargo of a ship was revealed to all
void send_cargo_revealed_packet( ship *shipp )
{
ubyte data[MAX_PACKET_SIZE];
int packet_size;
// build the header and add the data
BUILD_HEADER(CARGO_REVEALED);
ADD_USHORT( Objects[shipp->objnum].net_signature );
// server sends to all players
if(MULTIPLAYER_MASTER){
multi_io_send_to_all_reliable(data, packet_size);
}
// clients just send to the server
else {
multi_io_send_reliable(Net_player, data, packet_size);
}
}
// process a cargo revealed packet
void process_cargo_revealed_packet( ubyte *data, header *hinfo )
{
int offset;
ushort signature;
object *objp;
offset = HEADER_LENGTH;
GET_USHORT(signature);
PACKET_SET_SIZE();
// get a ship pointer and call the ship function to reveal the cargo
objp = multi_get_network_object( signature );
if ( objp == NULL ) {
nprintf(("Network", "Could not find object with net signature %d for cargo revealed\n", signature ));
return;
}
// Assert( objp->type == OBJ_SHIP );
if((objp->type != OBJ_SHIP) || (objp->instance < 0) || (objp->instance >= MAX_SHIPS)){
return;
}
// this will take care of re-routing to all other clients
ship_do_cargo_revealed( &Ships[objp->instance], 1);
// server should rebroadcast
if(MULTIPLAYER_MASTER){
send_cargo_revealed_packet(&Ships[objp->instance]);
}
}
// packet to tell clients cargo of a ship was hidden to all
void send_cargo_hidden_packet( ship *shipp )
{
ubyte data[MAX_PACKET_SIZE];
int packet_size;
// build the header and add the data
BUILD_HEADER(CARGO_HIDDEN);
ADD_USHORT( Objects[shipp->objnum].net_signature );
// server sends to all players
if(MULTIPLAYER_MASTER){
multi_io_send_to_all_reliable(data, packet_size);
}
// clients just send to the server
else {
multi_io_send_reliable(Net_player, data, packet_size);
}
}
// process a cargo hidden packet
void process_cargo_hidden_packet( ubyte *data, header *hinfo )
{
int offset;
ushort signature;
object *objp;
offset = HEADER_LENGTH;
GET_USHORT(signature);
PACKET_SET_SIZE();
// get a ship pointer and call the ship function to hide the cargo
objp = multi_get_network_object( signature );
if ( objp == NULL ) {
nprintf(("Network", "Could not find object with net signature %d for cargo hidden\n", signature ));
return;
}
// Assert( objp->type == OBJ_SHIP );
if((objp->type != OBJ_SHIP) || (objp->instance < 0) || (objp->instance >= MAX_SHIPS)){
return;
}
// this will take care of re-routing to all other clients
ship_do_cargo_hidden( &Ships[objp->instance], 1);
// server should rebroadcast
if(MULTIPLAYER_MASTER){
send_cargo_hidden_packet(&Ships[objp->instance]);
}
}
// defines used for secondary fire packet
#define SFPF_ALLOW_SWARM (1<<7)
#define SFPF_DUAL_FIRE (1<<6)
#define SFPF_TARGET_LOCKED (1<<5)
// send a packet indicating a secondary weapon was fired
void send_secondary_fired_packet( ship *shipp, ushort starting_sig, int starting_count, int num_fired, int allow_swarm )
{
int packet_size, net_player_num;
ubyte data[MAX_PACKET_SIZE], sinfo, current_bank;
object *objp;
ushort target_signature;
char t_subsys;
ai_info *aip;
// Assert ( starting_count < UCHAR_MAX );
// get the object for this ship. If it is an AI object, send all the info to all player. Otherwise,
// we might send the info to the other player different than the one who fired
objp = &Objects[shipp->objnum];
if ( !(objp->flags & OF_PLAYER_SHIP) ) {
if ( num_fired == 0 ) {
return;
}
}
aip = &Ai_info[shipp->ai_index];
current_bank = (ubyte)shipp->weapons.current_secondary_bank;
Assert( (current_bank < MAX_SHIP_SECONDARY_BANKS) );
// build up the header portion
BUILD_HEADER( SECONDARY_FIRED_AI );
ADD_USHORT( Objects[shipp->objnum].net_signature );
ADD_USHORT( starting_sig );
// add a couple of bits for swarm missiles and dual fire secondary weapons
sinfo = current_bank;
if ( allow_swarm ){
sinfo |= SFPF_ALLOW_SWARM;
}
if ( shipp->flags & SF_SECONDARY_DUAL_FIRE ){
sinfo |= SFPF_DUAL_FIRE;
}
if ( aip->current_target_is_locked ){
sinfo |= SFPF_TARGET_LOCKED;
}
ADD_DATA( sinfo );
// add the ship's target and any targeted subsystem
target_signature = 0;
t_subsys = -1;
if ( aip->target_objnum != -1) {
target_signature = Objects[aip->target_objnum].net_signature;
if ( (Objects[aip->target_objnum].type == OBJ_SHIP) && (aip->targeted_subsys != NULL) ) {
int s_index;
s_index = ship_get_index_from_subsys( aip->targeted_subsys, aip->target_objnum );
Assert( s_index < CHAR_MAX ); // better be less than this!!!!
t_subsys = (char)s_index;
}
if ( Objects[aip->target_objnum].type == OBJ_WEAPON ) {
Assert(Weapon_info[Weapons[Objects[aip->target_objnum].instance].weapon_info_index].wi_flags & WIF_BOMB);
}
}
ADD_USHORT( target_signature );
ADD_DATA( t_subsys );
// just send this packet to everyone, then bail if an AI ship fired.
if ( !(objp->flags & OF_PLAYER_SHIP) ) {
multi_io_send_to_all(data, packet_size);
return;
}
net_player_num = multi_find_player_by_object( objp );
// getting here means a player fired. Send the current packet to all players except the player
// who fired. If nothing got fired, then don't send to the other players -- we will just send
// a packet to the player who will find out that he didn't fire anything
if ( num_fired > 0 ) {
multi_io_send_to_all_reliable(data, packet_size, &Net_players[net_player_num]);
}
// if I (the master) fired, then return
if ( Net_players[net_player_num].flags & NETINFO_FLAG_AM_MASTER ){
return;
}
// now build up the packet to send to the player who actually fired.
BUILD_HEADER( SECONDARY_FIRED_PLR );
ADD_USHORT(starting_sig);
ADD_DATA( sinfo );
// add the targeting information so that the player's weapons will always home on the correct
// ship
ADD_USHORT( target_signature );
ADD_DATA( t_subsys );
multi_io_send_reliable(&Net_players[net_player_num], data, packet_size);
}
/// process a packet indicating a secondary weapon was fired
void process_secondary_fired_packet(ubyte* data, header* hinfo, int from_player)
{
int offset, allow_swarm, target_objnum_save;
ushort net_signature, starting_sig, target_signature;
ubyte sinfo, current_bank;
object* objp, *target_objp;
ship *shipp;
char t_subsys;
ai_info *aip;
ship_subsys *targeted_subsys_save;
offset = HEADER_LENGTH; // size of the header
// if from_player is false, it means that the secondary weapon info in this packet was
// fired by an ai object (or another player). from_player == 1 means tha me (the person
// receiving this packet) fired the secondary weapon
if ( !from_player ) {
GET_USHORT( net_signature );
GET_USHORT( starting_sig );
GET_DATA( sinfo ); // are we firing swarm missiles
GET_USHORT( target_signature );
GET_DATA( t_subsys );
PACKET_SET_SIZE();
// find the object (based on network signatures) for the object that fired
objp = multi_get_network_object( net_signature );
if ( objp == NULL ) {
nprintf(("Network", "Could not find ship for fire secondary packet!"));
return;
}
// set up the ships current secondary bank and that bank's mode. Below, we will set the timeout
// of the next fire time of this bank to 0 so we can fire right away
shipp = &Ships[objp->instance];
} else {
GET_USHORT( starting_sig );
GET_DATA( sinfo );
GET_USHORT( target_signature );
GET_DATA( t_subsys );
PACKET_SET_SIZE();
// get the object and ship
objp = Player_obj;
shipp = Player_ship;
}
// check the allow swarm bit
allow_swarm = 0;
if ( sinfo & SFPF_ALLOW_SWARM ){
allow_swarm = 1;
}
// set the dual fire properties of the ship
if ( sinfo & SFPF_DUAL_FIRE ){
shipp->flags |= SF_SECONDARY_DUAL_FIRE;
} else {
shipp->flags &= ~SF_SECONDARY_DUAL_FIRE;
}
// determine whether current target is locked
Assert( shipp->ai_index != -1 );
aip = &Ai_info[shipp->ai_index];
if ( sinfo & SFPF_TARGET_LOCKED ) {
aip->current_target_is_locked = 1;
} else {
aip->current_target_is_locked = 0;
}
// find out the current bank
current_bank = (ubyte)(sinfo & 0x3);
Assert( (current_bank < MAX_SHIP_SECONDARY_BANKS) );
shipp->weapons.current_secondary_bank = current_bank;
// make it so we can fire this ship's secondary bank immediately!!!
shipp->weapons.next_secondary_fire_stamp[shipp->weapons.current_secondary_bank] = timestamp(0);
shipp->weapons.detonate_weapon_time = timestamp(5000); // be sure that we don't detonate a remote weapon before it is time.
// set this ship's target and subsystem information. We will save and restore target and
// targeted subsystem so that we do not accidentally change targets for this player or
// any AI ships on his system.
target_objnum_save = aip->target_objnum;
targeted_subsys_save = aip->targeted_subsys;
// reset these variables for accuracy. They will get reassigned at the end of this fuction
aip->target_objnum = -1;
aip->targeted_subsys = NULL;
target_objp = multi_get_network_object( target_signature );
if ( target_objp != NULL ) {
aip->target_objnum = OBJ_INDEX(target_objp);
if ( (t_subsys != -1) && (target_objp->type == OBJ_SHIP) ) {
aip->targeted_subsys = ship_get_indexed_subsys( &Ships[target_objp->instance], t_subsys);
}
}
if ( starting_sig != 0 ){
multi_set_network_signature( starting_sig, MULTI_SIG_NON_PERMANENT );
} else {
shipp->weapons.detonate_weapon_time = timestamp(0); // signature of -1 say detonate remote weapon
}
ship_fire_secondary( objp, allow_swarm );
// restore targeted object and targeted subsystem
aip->target_objnum = target_objnum_save;
aip->targeted_subsys = targeted_subsys_save;
}
// send a packet indicating a countermeasure was fired
void send_countermeasure_fired_packet( object *objp, int cmeasure_count, int rand_val )
{
ubyte data[MAX_PACKET_SIZE];
int packet_size;
Int3();
Assert ( cmeasure_count < UCHAR_MAX );
BUILD_HEADER(COUNTERMEASURE_FIRED);
ADD_USHORT( objp->net_signature );
ADD_INT( rand_val );
multi_io_send_to_all(data, packet_size);
}
// process a packet indicating a countermeasure was fired
void process_countermeasure_fired_packet( ubyte *data, header *hinfo )
{
int offset, rand_val;
ushort signature;
object *objp;
Int3();
offset = HEADER_LENGTH;
GET_USHORT( signature );
GET_INT( rand_val );
PACKET_SET_SIZE();
objp = multi_get_network_object( signature );
if ( objp == NULL ) {
nprintf(("network", "Could find object whose countermeasures are being launched!!!\n"));
return;
}
if(objp->type != OBJ_SHIP){
return;
}
// Assert ( objp->type == OBJ_SHIP );
// make it so ship can fire right away!
Ships[objp->instance].cmeasure_fire_stamp = timestamp(0);
if ( objp == Player_obj ){
nprintf(("network", "firing countermeasure from my ship\n"));
}
ship_launch_countermeasure( objp, rand_val );
}
// send a packet indicating that a turret has been fired
void send_turret_fired_packet( int ship_objnum, int subsys_index, int weapon_objnum )
{
int packet_size;
ushort pnet_signature;
ubyte data[MAX_PACKET_SIZE], cindex;
object *objp;
ubyte has_sig = 0;
ship_subsys *ssp;
short val;
// sanity
if((weapon_objnum < 0) || (Objects[weapon_objnum].type != OBJ_WEAPON) || (Objects[weapon_objnum].instance < 0) || (Weapons[Objects[weapon_objnum].instance].weapon_info_index < 0)){
return;
}
// local setup -- be sure we are actually passing a weapon!!!!
objp = &Objects[weapon_objnum];
Assert ( objp->type == OBJ_WEAPON );
if(Weapon_info[Weapons[objp->instance].weapon_info_index].subtype == WP_MISSILE){
has_sig = 1;
}
pnet_signature = Objects[ship_objnum].net_signature;
Assert( subsys_index < UCHAR_MAX );
cindex = (ubyte)subsys_index;
ssp = ship_get_indexed_subsys( &Ships[Objects[ship_objnum].instance], subsys_index, NULL );
if(ssp == NULL){
return;
}
// build the fire turret packet.
BUILD_HEADER(FIRE_TURRET_WEAPON);
packet_size += multi_pack_unpack_position(1, data + packet_size, &objp->orient.vec.fvec);
ADD_DATA( has_sig );
ADD_USHORT( pnet_signature );
if(has_sig){
ADD_USHORT( objp->net_signature );
}
ADD_DATA( cindex );
val = (short)ssp->submodel_info_1.angs.h;
ADD_SHORT( val );
val = (short)ssp->submodel_info_2.angs.p;
ADD_SHORT( val );
multi_io_send_to_all(data, packet_size);
multi_rate_add(1, "tur", packet_size);
}
// process a packet indicating a turret has been fired
void process_turret_fired_packet( ubyte *data, header *hinfo )
{
int offset, weapon_objnum, wid = -1;
ushort pnet_signature, wnet_signature;
vec3d pos, temp;
matrix orient;
vec3d o_fvec;
ubyte turret_index;
object *objp;
ship_subsys *ssp;
ubyte has_sig = 0;
ship *shipp;
short pitch, heading;
// get the data for the turret fired packet
offset = HEADER_LENGTH;
offset += multi_pack_unpack_position(0, data + offset, &o_fvec);
GET_DATA( has_sig );
GET_USHORT( pnet_signature );
if(has_sig){
GET_USHORT( wnet_signature );
} else {
wnet_signature = 0;
}
GET_DATA( turret_index );
GET_SHORT( heading );
GET_SHORT( pitch );
PACKET_SET_SIZE(); // move our counter forward the number of bytes we have read
// find the object
objp = multi_get_network_object( pnet_signature );
if ( objp == NULL ) {
nprintf(("network", "could find parent object with net signature %d for turret firing\n", pnet_signature));
return;
}
// if this isn't a ship, do nothing
if ( objp->type != OBJ_SHIP ){
return;
}
// make an orientation matrix from the o_fvec
vm_vector_2_matrix(&orient, &o_fvec, NULL, NULL);
// find this turret, and set the position of the turret that just fired to be where it fired. Quite a
// hack, but should be suitable.
shipp = &Ships[objp->instance];
ssp = ship_get_indexed_subsys( shipp, turret_index, NULL );
if(ssp == NULL){
return;
}
if (ssp->weapons.num_primary_banks > 0) {
wid = ssp->weapons.primary_bank_weapons[0];
} else if (ssp->weapons.num_secondary_banks > 0) {
wid = ssp->weapons.secondary_bank_weapons[0];
}
if (wid < 0)
return;
// bash the position and orientation of the turret
ssp->submodel_info_1.angs.h = (float)heading;
ssp->submodel_info_2.angs.p = (float)pitch;
// get the world position of the weapon
ship_get_global_turret_info(objp, ssp->system_info, &pos, &temp);
// create the weapon object
if(wnet_signature != 0){
multi_set_network_signature( wnet_signature, MULTI_SIG_NON_PERMANENT );
}
weapon_objnum = weapon_create( &pos, &orient, wid, OBJ_INDEX(objp), -1, 1, 0, 0.0f, ssp);
wid = Weapons[Objects[weapon_objnum].instance].weapon_info_index;
if (weapon_objnum != -1) {
if ( Weapon_info[wid].launch_snd != -1 ) {
snd_play_3d( &Snds[Weapon_info[wid].launch_snd], &pos, &View_position );
}
}
}
// send a mission log item packet
void send_mission_log_packet( int num )
{
int packet_size;
ubyte data[MAX_PACKET_SIZE];
ubyte type;
int sindex;
log_entry *entry;
Assert ( MULTIPLAYER_MASTER );
// get the data from the log
entry = &log_entries[num];
type = (ubyte)entry->type; // do the type casting thing to save on packet space
sindex = entry->index;
BUILD_HEADER(MISSION_LOG_ENTRY);
ADD_DATA(type);
ADD_INT(entry->flags);
ADD_INT(sindex);
ADD_INT(entry->timestamp); // NOTE: this is a long so careful with swapping in 64-bit platforms - taylor
ADD_STRING(entry->pname);
ADD_STRING(entry->sname);
// broadcast the packet to all players
multi_io_send_to_all_reliable(data, packet_size);
}
// process a mission log item packet
void process_mission_log_packet( ubyte *data, header *hinfo )
{
int offset, flags;
int sindex;
ubyte type;
char pname[NAME_LENGTH], sname[NAME_LENGTH];
fix timestamp;
Assert ( MULTIPLAYER_CLIENT );
offset = HEADER_LENGTH;
GET_DATA(type);
GET_INT(flags);
GET_INT(sindex);
GET_INT(timestamp); // NOTE: this is a long so careful with swapping in 64-bit platforms - taylor
GET_STRING(pname);
GET_STRING(sname);
PACKET_SET_SIZE();
mission_log_add_entry_multi( type, pname, sname, sindex, timestamp, flags );
}
// send a mission message packet
void send_mission_message_packet( int id, char *who_from, int priority, int timing, int source, int builtin_type, int multi_target, int multi_team_filter, int delay)
{
int packet_size;
ubyte data[MAX_PACKET_SIZE], up, us, utime;
Assert ( Net_player->flags & NETINFO_FLAG_AM_MASTER );
Assert ( (priority >= 0) && (priority < UCHAR_MAX) );
Assert ( (timing >= 0) && (timing < UCHAR_MAX) );
up = (ubyte) priority;
us = (ubyte) source;
utime = (ubyte)timing;
BUILD_HEADER(MISSION_MESSAGE);
ADD_INT(id);
ADD_STRING(who_from);
ADD_DATA(up);
ADD_DATA(utime);
ADD_DATA(us);
ADD_INT(builtin_type);
ADD_INT(multi_team_filter);
ADD_INT(delay);
if (multi_target == -1){
multi_io_send_to_all_reliable(data, packet_size);
} else {
multi_io_send_reliable(&Net_players[multi_target], data, packet_size);
}
}
// process a mission message packet
void process_mission_message_packet( ubyte *data, header *hinfo )
{
int offset, id, builtin_type, delay;
ubyte priority, source, utiming;
char who_from[NAME_LENGTH];
int multi_team_filter;
Assert( !(Net_player->flags & NETINFO_FLAG_AM_MASTER) );
offset = HEADER_LENGTH;
GET_INT(id);
GET_STRING(who_from);
GET_DATA(priority);
GET_DATA(utiming);
GET_DATA(source);
GET_INT(builtin_type);
GET_INT(multi_team_filter);
GET_INT(delay);
PACKET_SET_SIZE();
// filter out some builtin ones in TvT
if((builtin_type >= 0) && (Netgame.type_flags & NG_TYPE_TEAM) && (Net_player != NULL) && (Net_player->p_info.team != multi_team_filter)) {
mprintf(("Builtin message of type %d filtered out in process_mission_message_packet()\n", id));
return;
}
// maybe filter this out
if(!message_filter_multi(id)){
// send the message as if it came from an sexpression
message_queue_message( id, priority, utiming, who_from, source, 0, delay, builtin_type );
}
}
// just send them a pong back as fast as possible
void process_ping_packet(ubyte *data, header *hinfo)
{
net_addr addr;
int offset;
offset = HEADER_LENGTH;
PACKET_SET_SIZE();
// get the address to return the pong to
fill_net_addr(&addr, hinfo->addr, hinfo->net_id, hinfo->port);
// send the pong
send_pong(&addr);
}
// right now it just routes the pong through to the standalone gui, which is the only
// system which uses ping and pong right now.
void process_pong_packet(ubyte *data, header *hinfo)
{
net_player *p;
net_addr addr;
int offset,lookup;
offset = HEADER_LENGTH;
fill_net_addr(&addr, hinfo->addr, hinfo->net_id, hinfo->port);
PACKET_SET_SIZE();
// if we're connected , see who sent us this pong
if(Net_player->flags & NETINFO_FLAG_CONNECTED){
lookup = find_player_id(hinfo->id);
if(lookup == -1){
return;
}
p = &Net_players[lookup];
// evaluate the ping
multi_ping_eval_pong(&Net_players[lookup].s_info.ping);
// put in calls to any functions which may want to know about the ping times from
// this guy
if (Game_mode & GM_STANDALONE_SERVER) {
std_update_player_ping(p);
}
// mark his socket as still alive (extra precaution)
psnet_mark_received(Net_players[lookup].reliable_socket);
}
// otherwise, do any special processing
else {
// if we're in the join game state, see if this pong came from a server on our
// list
if(gameseq_get_state() == GS_STATE_MULTI_JOIN_GAME){
multi_join_eval_pong(&addr, timer_get_fixed_seconds());
}
}
}
// send a ping packet
void send_ping(net_addr *addr)
{
unsigned char data[8];
int packet_size;
// build the header and send the packet
BUILD_HEADER( PING );
psnet_send(addr, &data[0], packet_size);
}
// send a pong packet
void send_pong(net_addr *addr)
{
unsigned char data[8];
int packet_size;
// build the header and send the packet
BUILD_HEADER(PONG);
psnet_send(addr, &data[0], packet_size);
}
// sent from host to master. give me the list of missions you have.
// this will be used only in a standalone mode
void send_mission_list_request( int what )
{
ubyte data[MAX_PACKET_SIZE];
int packet_size;
// build the header and ask for a list of missions or campaigns (depending
// on the 'what' flag).
BUILD_HEADER(MISSION_REQUEST);
multi_io_send_reliable(Net_player, data, packet_size);
}
// maximum number of bytes that we can send in a mission items packet.
#define MAX_MISSION_ITEMS_BYTES (MAX_PACKET_SIZE - (sizeof(multi_create_info) + 1) )
// defines used to tell what type of packets are being sent
#define MISSION_LIST_ITEMS 1
#define CAMPAIGN_LIST_ITEMS 2
// send an individual mission file item
void send_mission_items( net_player *pl )
{
ubyte data[MAX_PACKET_SIZE];
int packet_size, i;
ubyte stop, type;
// build the header
BUILD_HEADER(MISSION_ITEM);
// send the list of missions and campaigns avilable on the server. Stop when
// reaching a certain maximum
type = MISSION_LIST_ITEMS;
ADD_DATA( type );
for (i = 0; i < (int)Multi_create_mission_list.size(); i++ ) {
stop = 0;
ADD_DATA( stop );
ADD_STRING( Multi_create_mission_list[i].filename );
ADD_STRING( Multi_create_mission_list[i].name );
ADD_INT( Multi_create_mission_list[i].flags );
ADD_DATA( Multi_create_mission_list[i].max_players );
ADD_INT( Multi_create_mission_list[i].respawn );
// STANDALONE_ONLY
ADD_DATA( Multi_create_mission_list[i].valid_status );
if ( packet_size > (int)MAX_MISSION_ITEMS_BYTES ) {
stop = 1;
ADD_DATA( stop );
multi_io_send_reliable(pl, data, packet_size);
BUILD_HEADER( MISSION_ITEM );
ADD_DATA( type );
}
}
stop = 1;
ADD_DATA(stop);
multi_io_send_reliable(pl, data, packet_size);
// send the campaign information
type = CAMPAIGN_LIST_ITEMS;
BUILD_HEADER(MISSION_ITEM);
ADD_DATA( type );
for (i = 0; i < (int)Multi_create_campaign_list.size(); i++ ) {
stop = 0;
ADD_DATA( stop );
ADD_STRING( Multi_create_campaign_list[i].filename );
ADD_STRING( Multi_create_campaign_list[i].name );
ADD_INT( Multi_create_campaign_list[i].flags );
ADD_DATA( Multi_create_campaign_list[i].max_players );
if ( packet_size > (int)MAX_MISSION_ITEMS_BYTES ) {
stop = 1;
ADD_DATA( stop );
multi_io_send_reliable(pl, data, packet_size);
BUILD_HEADER( MISSION_ITEM );
ADD_DATA( type );
}
}
stop = 1;
ADD_DATA(stop);
multi_io_send_reliable(pl, data, packet_size);
}
// process a request for a list of missions
void process_mission_request_packet(ubyte *data, header *hinfo)
{
int player_num,offset;
offset = HEADER_LENGTH;
PACKET_SET_SIZE();
// fill in the address information of where this came from
player_num = find_player_id(hinfo->id);
if(player_num == -1){
nprintf(("Network","Could not find player to send mission list items to!\n"));
return;
}
send_mission_items( &Net_players[player_num] );
}
// process an individual mission file item
void process_mission_item_packet(ubyte *data,header *hinfo)
{
int offset, flags;
char filename[MAX_FILENAME_LEN], name[NAME_LENGTH], valid_status;
ubyte stop, type,max_players;
uint respawn;
multi_create_info mcip;
Assert(gameseq_get_state() == GS_STATE_MULTI_HOST_SETUP);
offset = HEADER_LENGTH;
GET_DATA( type );
GET_DATA(stop);
while( !stop ) {
GET_STRING( filename );
GET_STRING( name );
GET_INT( flags );
GET_DATA( max_players );
// missions also have respawns and a crc32 associated with them
if(type == MISSION_LIST_ITEMS){
GET_UINT(respawn);
// STANDALONE_ONLY
GET_DATA(valid_status);
strcpy_s(mcip.filename, filename );
strcpy_s(mcip.name, name );
mcip.flags = flags;
mcip.respawn = respawn;
mcip.max_players = max_players;
// STANDALONE_ONLY
mcip.valid_status = valid_status;
Multi_create_mission_list.push_back( mcip );
} else if ( type == CAMPAIGN_LIST_ITEMS ) {
strcpy_s(mcip.filename, filename );
strcpy_s(mcip.name, name );
mcip.flags = flags;
mcip.respawn = 0;
mcip.max_players = max_players;
Multi_create_campaign_list.push_back( mcip );
}
GET_DATA( stop );
}
PACKET_SET_SIZE();
// this will cause whatever list to get resorted (although they should be appearing in order)
multi_create_setup_list_data(-1);
}
// send a request to the server to pause or unpause the game
void send_multi_pause_packet(int pause)
{
ubyte data[MAX_PACKET_SIZE];
ubyte val;
int packet_size = 0;
Assert(!(Net_player->flags & NETINFO_FLAG_AM_MASTER));
// build the header
BUILD_HEADER(MULTI_PAUSE_REQUEST);
val = (ubyte) pause;
// add the pause info
ADD_DATA(val);
// send the request to the server
multi_io_send_reliable(Net_player, data, packet_size);
}
// process a pause update packet (pause, unpause, etc)
void process_multi_pause_packet(ubyte *data, header *hinfo)
{
int offset;
ubyte val;
int player_index;
offset = HEADER_LENGTH;
// get the data
GET_DATA(val);
PACKET_SET_SIZE();
// get who sent the packet
player_index = find_player_id(hinfo->id);
// if we don't know who sent the packet, don't do anything
if(player_index == -1){
return;
}
// if we're the server, we should evaluate whether this guy is allowed to send the packet
multi_pause_server_eval_request(&Net_players[player_index],(int)val);
}
// send a game information update
void send_game_info_packet()
{
int packet_size;
ubyte data[MAX_PACKET_SIZE], paused;
// set the paused variable
paused = (ubyte)((Netgame.game_state == NETGAME_STATE_PAUSED)?1:0);
BUILD_HEADER(GAME_INFO);
ADD_INT( Missiontime ); // NOTE: this is a long so careful with swapping in 64-bit platforms - taylor
ADD_DATA( paused );
multi_io_send_to_all(data, packet_size);
}
// process a game information update
void process_game_info_packet( ubyte *data, header *hinfo )
{
int offset;
fix mission_time;
ubyte paused;
offset = HEADER_LENGTH;
// get the mission time -- we should examine our time and the time from the server. If off by some delta
// time, set our time to server time (should take ping time into account!!!)
GET_INT( mission_time ); // NOTE: this is a long so careful with swapping in 64-bit platforms - taylor
GET_DATA( paused );
PACKET_SET_SIZE();
}
// send an ingame nak packet
void send_ingame_nak(int state, net_player *p)
{
ubyte data[MAX_PACKET_SIZE];
int packet_size;
packet_size = 0;
BUILD_HEADER(INGAME_NAK);
ADD_INT(state);
multi_io_send_reliable(p, data, packet_size);
}
// process an ingame nak packet
void process_ingame_nak(ubyte *data, header *hinfo)
{
int offset,state,pid;
offset = HEADER_LENGTH;
GET_INT(state);
PACKET_SET_SIZE();
pid = find_player_id(hinfo->id);
if(pid < 0){
return;
}
switch(state){
case ACK_FILE_ACCEPTED :
Assert(Net_player->flags & NETINFO_FLAG_INGAME_JOIN);
nprintf(("Network","Mission file rejected by server, aborting...\n"));
multi_quit_game(PROMPT_NONE, MULTI_END_NOTIFY_FILE_REJECTED);
break;
}
}
// If the end_mission SEXP has been used tell clients to skip straight to the debrief screen
void send_force_end_mission_packet()
{
ubyte data[MAX_PACKET_SIZE];
int packet_size;
packet_size = 0;
BUILD_HEADER(FORCE_MISSION_END);
if (Net_player->flags & NETINFO_FLAG_AM_MASTER)
{
// tell everyone to leave the game
multi_io_send_to_all_reliable(data, packet_size);
}
}
// process a packet indicating that we should jump straight to the debrief screen
void process_force_end_mission_packet(ubyte *data, header *hinfo)
{
int offset;
offset = HEADER_LENGTH;
PACKET_SET_SIZE();
ml_string("Receiving force end mission packet");
// Since only the server sends out these packets it should never receive one
Assert (!(Net_player->flags & NETINFO_FLAG_AM_MASTER));
multi_handle_sudden_mission_end();
send_debrief_event();
}
// send a packet telling players to end the mission
void send_endgame_packet(net_player *pl)
{
ubyte data[MAX_PACKET_SIZE];
int packet_size;
packet_size = 0;
BUILD_HEADER(MISSION_END);
// sending to a specific player?
if(pl != NULL){
Assert(Net_player->flags & NETINFO_FLAG_AM_MASTER);
multi_io_send_reliable(pl, data, packet_size);
return;
}
if(Net_player->flags & NETINFO_FLAG_AM_MASTER){
// send all player stats here
multi_broadcast_stats(STATS_MISSION);
// if in dogfight mode, send all dogfight stats as well
ml_string("Before dogfight stats!");
if(Netgame.type_flags & NG_TYPE_DOGFIGHT){
ml_string("Sending dogfight stats!");
multi_broadcast_stats(STATS_DOGFIGHT_KILLS);
}
ml_string("After dogfight stats!");
// tell everyone to leave the game
multi_io_send_to_all_reliable(data, packet_size);
} else {
multi_io_send_reliable(Net_player, data, packet_size);
}
}
// process a packet indicating we should end the current mission
void process_endgame_packet(ubyte *data, header *hinfo)
{
int offset;
int player_num;
offset = HEADER_LENGTH;
PACKET_SET_SIZE();
ml_string("Receiving endgame packet");
// if I'm the server, I should evaluate whether the sender is authorized to end the game
if(Net_player->flags & NETINFO_FLAG_AM_MASTER){
// determine who this came from and make sure he is allowed to end the game
player_num = find_player_id(hinfo->id);
Assert(player_num != -1);
if(player_num < 0){
return;
}
// if the player is allowed to end the mission
if(!multi_can_end_mission(&Net_players[player_num])){
return;
}
// act as if we hit alt+j locally
multi_handle_end_mission_request();
}
// all clients process immediately
else {
// ingame joiners should quit when they receive an endgame packet since the game is over
if(Net_player->flags & NETINFO_FLAG_INGAME_JOIN){
multi_quit_game(PROMPT_NONE, MULTI_END_NOTIFY_EARLY_END);
return;
}
// do any special processing for being in a state other than the gameplay state
multi_handle_state_special();
// make sure we're not already in the debrief state
if((gameseq_get_state() != GS_STATE_DEBRIEF) && (gameseq_get_state() != GS_STATE_MULTI_DOGFIGHT_DEBRIEF)){
multi_warpout_all_players();
}
}
}
// send a position/orientation update for myself (if I'm an observer)
void send_observer_update_packet()
{
ubyte data[MAX_PACKET_SIZE];
int packet_size;
int ret;
ushort target_sig;
// its possible for the master to be an observer if has run out of respawns. In this case, he doesn't need
// to send any update packets to anyone.
if(Net_player->flags & NETINFO_FLAG_AM_MASTER){
return;
}
if((Player_obj == NULL) || (Player_obj->type != OBJ_OBSERVER) || (Net_player == NULL) || !(Net_player->flags & NETINFO_FLAG_OBSERVER)){
return;
}
packet_size = 0;
BUILD_HEADER(OBSERVER_UPDATE);
ret = multi_pack_unpack_position( 1, data + packet_size, &Player_obj->pos );
packet_size += ret;
ret = multi_pack_unpack_orient( 1, data + packet_size, &Player_obj->orient );
packet_size += ret;
// add targeting infomation
if((Player_ai != NULL) && (Player_ai->target_objnum >= 0)){
target_sig = Objects[Player_ai->target_objnum].net_signature;
} else {
target_sig = 0;
}
ADD_USHORT(target_sig);
multi_io_send(Net_player, data, packet_size);
}
// process a position/orientation update from an observer
void process_observer_update_packet(ubyte *data, header *hinfo)
{
int offset,ret;
int obs_num;
vec3d g_vec;
matrix g_mat;
physics_info bogus_pi;
ushort target_sig;
object *target_obj;
offset = HEADER_LENGTH;
obs_num = find_player_id(hinfo->id);
memset(&bogus_pi,0,sizeof(physics_info));
ret = multi_pack_unpack_position( 0, data + offset, &g_vec );
offset += ret;
ret = multi_pack_unpack_orient( 0, data + offset, &g_mat );
offset += ret;
// targeting information
GET_USHORT(target_sig);
PACKET_SET_SIZE();
if((obs_num < 0) || (Net_players[obs_num].m_player->objnum < 0)){
return;
}
// set targeting info
if(target_sig == 0){
Net_players[obs_num].s_info.target_objnum = -1;
} else {
target_obj = multi_get_network_object(target_sig);
Net_players[obs_num].s_info.target_objnum = (target_obj == NULL) ? -1 : OBJ_INDEX(target_obj);
}
Objects[Net_players[obs_num].m_player->objnum].pos = g_vec;
Objects[Net_players[obs_num].m_player->objnum].orient = g_mat;
Net_players[obs_num].s_info.eye_pos = g_vec;
Net_players[obs_num].s_info.eye_orient = g_mat;
}
void send_netplayer_slot_packet()
{
ubyte data[MAX_PACKET_SIZE];
int packet_size,idx;
ubyte stop;
packet_size = 0;
stop = 0xff;
BUILD_HEADER(NETPLAYER_SLOTS_P);
for(idx=0;idx<MAX_PLAYERS;idx++){
if( MULTI_CONNECTED(Net_players[idx]) && !MULTI_STANDALONE(Net_players[idx]) && !MULTI_OBSERVER(Net_players[idx])){
ADD_DATA(stop);
ADD_SHORT(Net_players[idx].player_id);
ADD_USHORT(Objects[Net_players[idx].m_player->objnum].net_signature);
ADD_INT(Net_players[idx].p_info.ship_class);
ADD_INT(Net_players[idx].p_info.ship_index);
}
}
stop = 0x0;
ADD_DATA(stop);
// standalone case or not
if(Net_player->flags & NETINFO_FLAG_AM_MASTER){
multi_io_send_to_all_reliable(data, packet_size);
} else {
multi_io_send_reliable(Net_player, data, packet_size);
}
}
void process_netplayer_slot_packet(ubyte *data, header *hinfo)
{
int offset;
int player_num,ship_class,ship_index;
ushort net_sig;
object *objp;
ubyte stop;
short player_id;
offset = HEADER_LENGTH;
// first untag all of the player ships and make them OF_COULD_BE_PLAYER
multi_untag_player_ships();
GET_DATA(stop);
while(stop != 0x0){
GET_SHORT(player_id);
GET_USHORT(net_sig);
GET_INT(ship_class);
GET_INT(ship_index);
player_num = find_player_id(player_id);
if(player_num < 0){
nprintf(("Network","Error looking up player for object/slot assignment!!\n"));
} else {
// call the function in multiutil.cpp to set up the player object stuff
// being careful not to muck with the standalone object
if(!((player_num == 0) && (Game_mode & GM_STANDALONE_SERVER))){
objp = multi_get_network_object(net_sig);
if (objp == NULL) {
Error(LOCATION, "Could not retrieve net object for signature %d!\n", net_sig);
}
multi_assign_player_ship( player_num, objp, ship_class );
Net_players[player_num].p_info.ship_index = ship_index;
objp->flags &= ~(OF_COULD_BE_PLAYER);
objp->flags |= OF_PLAYER_SHIP;
}
}
GET_DATA(stop);
}
PACKET_SET_SIZE();
// standalone should forward the packet and wait for a response
if(Game_mode & GM_STANDALONE_SERVER){
send_netplayer_slot_packet();
}
Net_player->state = NETPLAYER_STATE_SLOT_ACK;
send_netplayer_update_packet();
}
// two functions to deal with ships changing their primary/secondary weapon status. 'what' indicates
// if this change is a primary or secondary change. new_bank is the new current primary/secondary
// bank, link_status is whether primaries are linked or not, or secondaries are dual fire or not
void send_ship_weapon_change( ship *shipp, int what, int new_bank, int link_status )
{
ubyte data[MAX_PACKET_SIZE], utmp;
int packet_size;
BUILD_HEADER(SHIP_WSTATE_CHANGE);
ADD_USHORT( Objects[shipp->objnum].net_signature );
utmp = (ubyte)(what);
ADD_DATA( utmp );
utmp = (ubyte)(new_bank);
ADD_DATA( utmp );
utmp = (ubyte)(link_status);
ADD_DATA( utmp );
// Removed the above psnet_send() call - it didn't appear to do anything since it was called only from the server anyway - DB
multi_io_send_to_all_reliable(data, packet_size);
}
void process_ship_weapon_change( ubyte *data, header *hinfo )
{
int offset;
ushort signature;
ubyte what, new_bank, link_status;
object *objp;
ship *shipp;
offset = HEADER_LENGTH;
GET_USHORT( signature );
GET_DATA( what );
GET_DATA( new_bank );
GET_DATA( link_status );
PACKET_SET_SIZE();
objp = multi_get_network_object( signature );
if ( objp == NULL ) {
nprintf(("network", "Unable to locate ship with signature %d for weapon state change\n", signature));
return;
}
// Assert( objp->type == OBJ_SHIP );
if(objp->type != OBJ_SHIP){
return;
}
// if this is my data, do nothing since I already have my own data
if ( objp == Player_obj ){
return;
}
// now, get the ship and set the new bank and link modes based on the 'what' value
shipp = &Ships[objp->instance];
if ( what == MULTI_PRIMARY_CHANGED ) {
shipp->weapons.current_primary_bank = new_bank;
if ( link_status ){
shipp->flags |= SF_PRIMARY_LINKED;
} else {
shipp->flags &= ~SF_PRIMARY_LINKED;
}
} else {
shipp->weapons.current_secondary_bank = new_bank;
if ( link_status ){
shipp->flags |= SF_SECONDARY_DUAL_FIRE;
} else {
shipp->flags &= ~SF_SECONDARY_DUAL_FIRE;
}
}
}
// ship status change procedure
// 1.) <client> - Client runs through the normal button_function procedure. Any remaining control bits are implied as being
// server critical.
// 2.) <client> - Client puts this button_info item into his last_buttons array and sends a bunch of SHIP_STATUS packets
// for added redundancy.
// 3.) <server> - Receives the packet. Checks to see if the net_player on his side already has this one defined. If so, it
// ignores as a repeat packet. Otherwise it puts it in the last_buttons array for the net_player
// 4.) <server> - Server applies the command on his side (with multi_apply_ship_status(...) and sends the ack (also a SHIP_STATUS)
// back to the client. Also sends multiple times for redundancy
// 5.) <client> - Receives the packet back. Does a lookup into his last_buttons array. If he finds the match, apply the functions
// and remove the item from the list. If no match is found it means that either he has received an ack, has acted
// on it and removed it, or that it has been "timed out" and replaced by a newer button_info.
#define SHIP_STATUS_REPEAT 2
void send_ship_status_packet(net_player *pl, button_info *bi, int id)
{
int idx, temp;
ubyte data[MAX_PACKET_SIZE];
int packet_size = 0;
if(pl == NULL){
return;
}
BUILD_HEADER(SHIP_STATUS_CHANGE);
ADD_INT(id);
for(idx=0;idx<NUM_BUTTON_FIELDS;idx++){
temp = bi->status[idx];
ADD_INT(temp);
}
// server should send reliably (response packet)
if(MULTIPLAYER_MASTER){
multi_io_send_reliable(pl, data, packet_size);
} else {
multi_io_send(pl, data, packet_size);
}
}
void process_ship_status_packet(ubyte *data, header *hinfo)
{
int idx;
int offset;
int player_num,unique_id;
button_info bi;
int i_tmp;
offset = HEADER_LENGTH;
// zero out the button info structure for good measure
memset(&bi,0,sizeof(button_info));
// read the button-info
GET_INT(unique_id);
for(idx=0;idx<NUM_BUTTON_FIELDS;idx++){
GET_INT(i_tmp);
bi.status[idx] = i_tmp;
}
PACKET_SET_SIZE();
// this will be handled differently client and server side. Duh.
if(Net_player->flags & NETINFO_FLAG_AM_MASTER){ // SERVER SIDE
// find which net-player has sent us butotn information
player_num = find_player_id(hinfo->id);
Assert(player_num >= 0);
if(player_num < 0){
return;
}
// don't process critical button information for observers
// its a new button_info for this guy. apply and ack
if(!MULTI_OBSERVER(Net_players[player_num]) && !lookup_ship_status(&Net_players[player_num],unique_id)){
// mark that he's pressed this button
// add_net_button_info(&Net_players[player_num], &bi, unique_id);
// send a return packet
send_ship_status_packet(&Net_players[player_num], &bi,unique_id);
// apply the button presses to his ship as normal
multi_apply_ship_status(&Net_players[player_num], &bi, 0);
}
// else ignore it as a repeat from the same guy
} else { // CLIENT SIDE
// this is the return from the server, so we should now apply them locally
// if(lookup_ship_status(Net_player,unique_id,1)){
multi_apply_ship_status(Net_player, &bi, 1);
// }
}
}
// MWA 4/28/9 -- redid this function since message all fighers was really broken
// for clients. Left all details to this function instead of higher level messaging
// code
void send_player_order_packet(int type, int index, int cmd)
{
ubyte data[MAX_PACKET_SIZE];
ubyte val;
ushort target_signature;
char t_subsys;
int packet_size = 0;
BUILD_HEADER(PLAYER_ORDER_PACKET);
val = (ubyte)type;
ADD_DATA(val); // ship order or wing order, or message all fighters
// if we are not messaging all ships or wings, add the index, which is the shipnum or wingnum
if ( val != SQUAD_MSG_ALL ){
ADD_INT(index); // net signature of target ship
}
ADD_INT(cmd); // the command itself
// add target data.
target_signature = 0;
if ( Player_ai->target_objnum != -1 ){
target_signature = Objects[Player_ai->target_objnum].net_signature;
}
ADD_USHORT( target_signature );
t_subsys = -1;
if ( (Player_ai->target_objnum != -1) && (Player_ai->targeted_subsys != NULL) ) {
int s_index;
s_index = ship_get_index_from_subsys( Player_ai->targeted_subsys, Player_ai->target_objnum );
Assert( s_index < CHAR_MAX ); // better be less than this!!!!
t_subsys = (char)s_index;
}
ADD_DATA(t_subsys);
multi_io_send_reliable(Net_player, data, packet_size);
}
// brief explanation :
// in either case (wing or ship command), we need to send in a pseudo-ai object. Basically, both command handler
// functions "normally" (non multiplayer) use a couple of the Player_ai fields. So, we just fill in the ones necessary
// (which we can reconstruct from the packet data), and pass this as the default variable ai_info *local
// Its kind of a hack, but it eliminates the need to go in and screw around with quite a bit of code
void process_player_order_packet(ubyte *data, header *hinfo)
{
int offset, player_num, command, index = 0, tobjnum_save;
ushort target_signature;
char t_subsys, type;
object *objp, *target_objp;
ai_info *aip;
ship *shipp;
ship_subsys *tsubsys_save, *targeted_subsys;
Assert(MULTIPLAYER_MASTER);
// packet values - its easier to read all of these in first
offset = HEADER_LENGTH;
GET_DATA( type );
if ( type != SQUAD_MSG_ALL ){
GET_INT( index );
}
GET_INT( command );
GET_USHORT( target_signature );
GET_DATA( t_subsys );
PACKET_SET_SIZE();
player_num = find_player_id(hinfo->id);
if(player_num == -1){
nprintf(("Network","Received player order packet from unknown player\n"));
return;
}
objp = &Objects[Net_players[player_num].m_player->objnum];
if ( objp->type != OBJ_SHIP ) {
nprintf(("Network", "not doing player order because object requestting is not a ship\n"));
return;
}
// HACK HACK HACK HACK HACK HACK
// if the player has sent a rearm-repair me message, we should bail here after evaluating it, since most likely the rest of
// the data is BOGUS. All people should be able to to these things as well.
if(command == REARM_REPAIR_ME_ITEM){
hud_squadmsg_repair_rearm(0,&Objects[Net_players[player_num].m_player->objnum]);
return;
} else if(command == ABORT_REARM_REPAIR_ITEM){
hud_squadmsg_repair_rearm_abort(0,&Objects[Net_players[player_num].m_player->objnum]);
return;
}
// if this player is not allowed to do messaging, quit here
if( !multi_can_message(&Net_players[player_num]) ){
nprintf(("Network","Received player order packet from player not allowed to give orders!!\n"));
return;
}
// check to see if the type of order is a reinforcement call. If so, intercept it, and
// then call them in.
if ( type == SQUAD_MSG_REINFORCEMENT ) {
Assert( (index >= 0) && (index < Num_reinforcements) );
hud_squadmsg_call_reinforcement(index, player_num);
return;
}
// set the player's ai information here
shipp = &Ships[objp->instance];
aip = &Ai_info[shipp->ai_index];
// get the target objnum and targeted subsystem. Quick out if we don't have an object to act on.
target_objp = multi_get_network_object( target_signature );
if ( target_objp == NULL ) {
return;
}
targeted_subsys = NULL;
if ( t_subsys != -1 ) {
Assert( target_objp != NULL );
targeted_subsys = ship_get_indexed_subsys( &Ships[target_objp->instance], t_subsys);
}
// save and restore the target objnum and targeted subsystem so that we don't mess up other things
// here
tobjnum_save = aip->target_objnum;
tsubsys_save = aip->targeted_subsys;
if ( target_objp ) {
aip->target_objnum = OBJ_INDEX(target_objp);
} else {
aip->target_objnum = -1;
}
aip->targeted_subsys = targeted_subsys;
if ( type == SQUAD_MSG_SHIP ) {
hud_squadmsg_send_ship_command(index, command, 1, SQUADMSG_HISTORY_ADD_ENTRY, player_num);
} else if ( type == SQUAD_MSG_WING ) {
hud_squadmsg_send_wing_command(index, command, 1, SQUADMSG_HISTORY_ADD_ENTRY, player_num);
} else if ( type == SQUAD_MSG_ALL ) {
hud_squadmsg_send_to_all_fighters( command, player_num );
}
Assert(tobjnum_save != Ships[aip->shipnum].objnum); // make sure not targeting self
aip->target_objnum = tobjnum_save;
aip->targeted_subsys = tsubsys_save;
}
// FILE SIGNATURE stuff :
// there are 2 cases for file signature sending which are handled very differently
// 1.) Pregame. In this case, the host requires that all clients send a filesig packet (when process_file_sig() is called, it
// posts an ACK_FILE_ACCEPTED packet to ack_evaluate, so he thinks they have acked).
// 2.) Ingame join. In this case, the client sends his filesig packet automatically to the server and the _client_ waits for
// the ack, before continuing to join. It would be way too messy to have the server wait on the clients ack, since he
// would have to keep track of up to potentially 14 other ack handles (ouch).
void send_file_sig_packet(ushort sum_sig,int length_sig)
{
ubyte data[MAX_PACKET_SIZE];
int packet_size = 0;
BUILD_HEADER(FILE_SIG_INFO);
ADD_USHORT(sum_sig);
ADD_INT(length_sig);
multi_io_send_reliable(Net_player, data, packet_size);
}
void process_file_sig_packet(ubyte *data, header *hinfo)
{
int offset;
int length_sig;
ushort sum_sig;
offset = HEADER_LENGTH;
// should only be received on the server-side
Assert(Net_player->flags & NETINFO_FLAG_AM_MASTER);
GET_USHORT(sum_sig);
GET_INT(length_sig);
PACKET_SET_SIZE();
server_verify_filesig(hinfo->id, sum_sig, length_sig);
}
void send_file_sig_request(char *file_name)
{
ubyte data[MAX_PACKET_SIZE];
int packet_size = 0;
BUILD_HEADER(FILE_SIG_REQUEST);
ADD_STRING(file_name);
Assert(Net_player->flags & NETINFO_FLAG_AM_MASTER);
multi_io_send_to_all_reliable(data, packet_size);
}
void process_file_sig_request(ubyte *data, header *hinfo)
{
int offset = HEADER_LENGTH;
// get the mission name
GET_STRING(Netgame.mission_name);
PACKET_SET_SIZE();
// set the current mission filename
strcpy_s(Game_current_mission_filename,Netgame.mission_name);
// get the checksum
multi_get_mission_checksum(Game_current_mission_filename);
if(!multi_endgame_ending()){
// reply to the server
send_file_sig_packet(Multi_current_file_checksum,Multi_current_file_length);
}
}
// functions to deal with subsystems getting whacked
void send_subsystem_destroyed_packet( ship *shipp, int index, vec3d world_hitpos )
{
ubyte data[MAX_PACKET_SIZE];
int packet_size;
ubyte uindex;
vec3d tmp, local_hitpos;
object *objp;
Assert ( index < UCHAR_MAX );
uindex = (ubyte)(index);
objp = &Objects[shipp->objnum];
vm_vec_sub(&tmp, &world_hitpos, &objp->pos );
vm_vec_rotate( &local_hitpos, &tmp, &objp->orient );
BUILD_HEADER(SUBSYSTEM_DESTROYED);
ADD_USHORT( Objects[shipp->objnum].net_signature );
ADD_DATA( uindex );
ADD_VECTOR( local_hitpos );
multi_io_send_to_all_reliable(data, packet_size);
}
void process_subsystem_destroyed_packet( ubyte *data, header *hinfo )
{
int offset;
ushort signature;
ubyte uindex;
object *objp;
vec3d local_hit_pos, world_hit_pos;
offset = HEADER_LENGTH;
GET_USHORT( signature );
GET_DATA( uindex );
GET_VECTOR( local_hit_pos );
// get the network object. process it if we find it.
objp = multi_get_network_object( signature );
if ( objp != NULL ) {
ship *shipp;
ship_subsys *subsysp;
// be sure we have a ship!!!
// Assert ( objp->type == OBJ_SHIP );
if(objp->type != OBJ_SHIP){
PACKET_SET_SIZE();
return;
}
shipp = &Ships[objp->instance];
// call to get the pointer to the subsystem we should be working on
subsysp = ship_get_indexed_subsys( shipp, (int)uindex );
if (subsysp == NULL) {
nprintf(("Network", "Could not find subsys %d for ship %s to process as being destroyed\n", (int)uindex, shipp->ship_name ));
PACKET_SET_SIZE();
return;
}
vm_vec_unrotate( &world_hit_pos, &local_hit_pos, &objp->orient );
vm_vec_add2( &world_hit_pos, &objp->pos );
do_subobj_destroyed_stuff( shipp, subsysp, &world_hit_pos );
if ( objp == Player_obj ) {
hud_gauge_popup_start(HUD_DAMAGE_GAUGE, 5000);
}
}
PACKET_SET_SIZE();
}
// packet to tell clients cargo of a ship was revealed to all
void send_subsystem_cargo_revealed_packet( ship *shipp, int index )
{
ubyte data[MAX_PACKET_SIZE], uindex;
int packet_size;
Assert ( index < UCHAR_MAX );
uindex = (ubyte)(index);
// build the header and add the data
BUILD_HEADER(SUBSYS_CARGO_REVEALED);
ADD_USHORT( Objects[shipp->objnum].net_signature );
ADD_DATA( uindex );
// server sends to all players
if(MULTIPLAYER_MASTER){
multi_io_send_to_all_reliable(data, packet_size);
}
// clients just send to the server
else {
multi_io_send_reliable(Net_player, data, packet_size);
}
}
// process a subsystem cargo revealed packet
void process_subsystem_cargo_revealed_packet( ubyte *data, header *hinfo )
{
int offset;
ushort signature;
ubyte uindex;
object *objp;
ship *shipp;
ship_subsys *subsysp;
offset = HEADER_LENGTH;
GET_USHORT( signature );
GET_DATA( uindex );
PACKET_SET_SIZE();
// get a ship pointer and call the ship function to reveal the cargo
objp = multi_get_network_object( signature );
if ( objp == NULL ) {
nprintf(("Network", "Could not find object with net signature %d for cargo revealed\n", signature ));
return;
}
// Assert( objp->type == OBJ_SHIP );
if((objp->type != OBJ_SHIP) || (objp->instance < 0) || (objp->instance >= MAX_SHIPS)){
return;
}
shipp = &Ships[objp->instance];
// call to get the pointer to the subsystem we should be working on
subsysp = ship_get_indexed_subsys( shipp, (int)uindex );
if (subsysp == NULL) {
nprintf(("Network", "Could not find subsys for ship %s for cargo revealed\n", Ships[objp->instance].ship_name ));
return;
}
// this will take care of re-routing to all other clients
ship_do_cap_subsys_cargo_revealed( shipp, subsysp, 1 );
// server should rebroadcast
if(MULTIPLAYER_MASTER){
send_subsystem_cargo_revealed_packet(&Ships[objp->instance], (int)uindex);
}
}
// packet to tell clients cargo of a ship was hidden to all
void send_subsystem_cargo_hidden_packet( ship *shipp, int index )
{
ubyte data[MAX_PACKET_SIZE], uindex;
int packet_size;
Assert ( index < UCHAR_MAX );
uindex = (ubyte)(index);
// build the header and add the data
BUILD_HEADER(SUBSYS_CARGO_HIDDEN);
ADD_USHORT( Objects[shipp->objnum].net_signature );
ADD_DATA( uindex );
// server sends to all players
if(MULTIPLAYER_MASTER){
multi_io_send_to_all_reliable(data, packet_size);
}
// clients just send to the server
else {
multi_io_send_reliable(Net_player, data, packet_size);
}
}
// process a subsystem cargo hidden packet
void process_subsystem_cargo_hidden_packet( ubyte *data, header *hinfo )
{
int offset;
ushort signature;
ubyte uindex;
object *objp;
ship *shipp;
ship_subsys *subsysp;
offset = HEADER_LENGTH;
GET_USHORT( signature );
GET_DATA( uindex );
PACKET_SET_SIZE();
// get a ship pointer and call the ship function to reveal the cargo
objp = multi_get_network_object( signature );
if ( objp == NULL ) {
nprintf(("Network", "Could not find object with net signature %d for cargo hidden\n", signature ));
return;
}
// Assert( objp->type == OBJ_SHIP );
if((objp->type != OBJ_SHIP) || (objp->instance < 0) || (objp->instance >= MAX_SHIPS)){
return;
}
shipp = &Ships[objp->instance];
// call to get the pointer to the subsystem we should be working on
subsysp = ship_get_indexed_subsys( shipp, (int)uindex );
if (subsysp == NULL) {
nprintf(("Network", "Could not find subsys for ship %s for cargo hidden\n", Ships[objp->instance].ship_name ));
return;
}
// this will take care of re-routing to all other clients
ship_do_cap_subsys_cargo_hidden( shipp, subsysp, 1 );
// server should rebroadcast
if(MULTIPLAYER_MASTER){
send_subsystem_cargo_hidden_packet(&Ships[objp->instance], (int)uindex);
}
}
void send_netplayer_load_packet(net_player *pl)
{
ubyte data[MAX_PACKET_SIZE];
int packet_size = 0;
BUILD_HEADER(LOAD_MISSION_NOW);
ADD_STRING(Netgame.mission_name);
if(pl == NULL){
multi_io_send_to_all_reliable(data, packet_size);
} else {
multi_io_send_reliable(pl, data, packet_size);
}
}
void process_netplayer_load_packet(ubyte *data, header *hinfo)
{
char str[100];
int offset = HEADER_LENGTH;
GET_STRING(str);
PACKET_SET_SIZE();
strcpy_s(Netgame.mission_name,str);
strcpy_s(Game_current_mission_filename,str);
if(!Multi_mission_loaded){
// MWA 2/3/98 -- ingame join changes!!!
// everyone can go through the same mission loading path here!!!!
nprintf(("Network","Loading mission..."));
// notify everyone that I'm loading the mission
Net_player->state = NETPLAYER_STATE_MISSION_LOADING;
send_netplayer_update_packet();
// do the load itself
game_start_mission();
// ingame joiners need to "untag" all player ships as could_be_players. The ingame joining
// code will remark the correct player ships
if ( Net_player->flags & NETINFO_FLAG_INGAME_JOIN ) {
multi_untag_player_ships();
}
Net_player->flags |= NETINFO_FLAG_MISSION_OK;
Net_player->state = NETPLAYER_STATE_MISSION_LOADED;
send_netplayer_update_packet();
Multi_mission_loaded = 1;
nprintf(("Network","Finished loading mission\n"));
}
}
void send_jump_into_mission_packet(net_player *pl)
{
ubyte data[MAX_PACKET_SIZE];
int packet_size = 0;
Assert(Net_player->flags & NETINFO_FLAG_AM_MASTER);
BUILD_HEADER(JUMP_INTO_GAME);
// ingame joiners will get special data. We need to tell them about the state of the mission, like paused,
// and possible other things.
if ( pl != NULL ) {
if ( pl->flags & NETINFO_FLAG_INGAME_JOIN ) {
ADD_INT(Netgame.game_state);
}
}
// broadcast
if(pl == NULL){
multi_io_send_to_all_reliable(data, packet_size);
}
// send to a specific player
else {
multi_io_send_reliable(pl, data, packet_size);
}
}
void process_jump_into_mission_packet(ubyte *data, header *hinfo)
{
int offset = HEADER_LENGTH;
int state;
state = 0;
// if I am ingame joining, there should be extra data. For now, this data is the netgame state.
// the game could be paused, so ingame joiner needs to deal with it.
if ( Net_player->flags & NETINFO_FLAG_INGAME_JOIN ) {
GET_INT( state );
Netgame.game_state = state;
}
PACKET_SET_SIZE();
// handle any special processing for being in a weird substate
multi_handle_state_special();
// if I'm an ingame joiner, go to the ship select screen, or if I'm an observer, jump right in!
if(Net_player->flags & NETINFO_FLAG_INGAME_JOIN){
if(Net_player->flags & NETINFO_FLAG_OBSERVER){
multi_ingame_observer_finish();
} else {
gameseq_post_event(GS_EVENT_INGAME_PRE_JOIN);
Net_player->state = NETPLAYER_STATE_INGAME_SHIP_SELECT;
send_netplayer_update_packet();
}
} else {
// start the mission!!
if(!(Game_mode & GM_IN_MISSION) && !(Game_mode & GM_STANDALONE_SERVER)){
Netgame.game_state = NETGAME_STATE_IN_MISSION;
gameseq_post_event(GS_EVENT_ENTER_GAME);
Net_player->state = NETPLAYER_STATE_IN_MISSION;
send_netplayer_update_packet();
}
}
// recalc all object pairs now
extern void obj_reset_all_collisions();
obj_reset_all_collisions();
// display some cool text
multi_common_add_text(XSTR("Received mission start\n",720),1);
// NETLOG
ml_string(NOX("Client received mission start from server - entering mission"));
}
//XSTR:OFF
char *repair_text[] = {
"unknown",
"REPAIR_INFO_BEGIN",
"REPAIR_INFO_END",
"REPAIR_INFO_UPDATE",
"REPAIR_INFO_QUEUE",
"REPAIR_INFO_ABORT",
"REPAIR_INFO_BROKEN",
"REPAIR_INFO_WARP_ADD",
"REPAIR_INFO_WARP_REMOVE",
"REPAIR_INFO_ONWAY",
"REPAIR_INFO_KILLED",
"REPAIR_INFO_COMPLETE",
};
//XSTR:ON
// the following two routines deal with updating and sending information regarding players
// rearming and repairing during the game. The process function calls the routines to deal with
// setting flags and other interesting things.
void send_repair_info_packet(object *repaired_objp, object *repair_objp, int code )
{
int packet_size = 0;
ushort repaired_signature, repair_signature;
ubyte data[MAX_PACKET_SIZE];
ubyte cd;
// use the network signature of the destination object if there is one, -1 otherwise.
// client will piece it all together
repaired_signature = repaired_objp->net_signature;
// the repair ship may be NULL here since it might have been destroyed
repair_signature = 0;
if ( repair_objp ){
repair_signature = repair_objp->net_signature;
}
BUILD_HEADER(CLIENT_REPAIR_INFO);
cd = (ubyte)code;
ADD_DATA(cd);
ADD_USHORT( repaired_signature );
ADD_USHORT( repair_signature );
multi_io_send_to_all_reliable(data, packet_size);
nprintf(("Network", "Repair: %s sent to all players (%s/%s)\n", repair_text[cd], Ships[repaired_objp->instance].ship_name, (repair_objp==NULL)?"<none>":Ships[repair_objp->instance].ship_name));
}
void process_repair_info_packet(ubyte *data, header *hinfo)
{
int offset = HEADER_LENGTH;
ushort repaired_signature, repair_signature;
object *repaired_objp, *repair_objp;
ubyte code;
GET_DATA(code);
GET_USHORT( repaired_signature );
GET_USHORT( repair_signature );
PACKET_SET_SIZE();
repaired_objp = multi_get_network_object( repaired_signature );
repair_objp = multi_get_network_object( repair_signature );
nprintf(("Network", "Repair: %s received (%s/%s)\n", repair_text[code], (repaired_objp==NULL)?"<None>":Ships[repaired_objp->instance].ship_name, (repair_objp==NULL)?"<None>":Ships[repair_objp->instance].ship_name));
if ( Net_player->flags & NETINFO_FLAG_WARPING_OUT ){
return;
}
if ( repaired_objp == NULL ) {
Int3(); // Sandeep says this is bad bad bad. No ship to repair.
return;
}
// the hope is to simply call the routine in the ai code to set/unset flags
// based on the code value and everything else should happen..I hope....
if ( (code != REPAIR_INFO_WARP_ADD) && (code != REPAIR_INFO_WARP_REMOVE ) ) {
ai_do_objects_repairing_stuff( repaired_objp, repair_objp, (int)code );
// set the dock flags when repair begins. Prevents problem in lagging docking
// packet. Also set any other flags/modes which need to be set to prevent Asserts.
// bleah.
if ( (code == REPAIR_INFO_BEGIN) && (repair_objp != NULL) ) {
// Karajorma removed this in revision 4808 to fix bug 1088. Problem is, if
// this was originally intended to prevent docking problems, will they return?
/*
// find indexes from goal
ai_info *aip = &Ai_info[Ships[repair_objp->instance].ai_index];
Assert(aip->active_goal >= 0);
ai_goal *aigp = &aip->goals[aip->active_goal];
Assert(aigp->flags & AIGF_DOCK_INDEXES_VALID);
int docker_index = aigp->docker.index;
int dockee_index = aigp->dockee.index;
ai_do_objects_docked_stuff( repair_objp, docker_index, repaired_objp, dockee_index );
*/
Ai_info[Ships[repair_objp->instance].ai_index].mode = AIM_DOCK;
}
// if the repair is done (either by abort, or ending), mark the repair ship's goal
// as being done.
if ( ((code == REPAIR_INFO_ABORT) || (code == REPAIR_INFO_END)) && repair_objp ){
ai_mission_goal_complete( &Ai_info[Ships[repair_objp->instance].ai_index] );
}
} else {
if ( code == REPAIR_INFO_WARP_ADD ){
mission_bring_in_support_ship( repaired_objp );
} else {
mission_remove_scheduled_repair( repaired_objp );
}
}
}
// sends information updating clients on certain AI information that clients will
// need to know about to keep HUD information up to date. objp is the object that we
// are updating, and what is the type of stuff that we are updating.
void send_ai_info_update_packet( object *objp, char what, object * other_objp )
{
int packet_size;
ushort other_signature;
ubyte data[MAX_PACKET_SIZE];
ai_info *aip;
ai_goal *aigp = NULL;
ubyte docker_index, dockee_index;
// Assert( objp->type == OBJ_SHIP );
if(objp->type != OBJ_SHIP){
return;
}
aip = &Ai_info[Ships[objp->instance].ai_index];
// do an out here
if ( Ships[objp->instance].flags & (SF_DEPARTING | SF_DYING) )
return;
switch( what ) {
case AI_UPDATE_DOCK:
case AI_UPDATE_UNDOCK:
Assert (other_objp != NULL);
if (other_objp == NULL) {
return;
}
break;
default:
Assert (other_objp == NULL);
break;
}
BUILD_HEADER( AI_INFO_UPDATE );
ADD_USHORT( objp->net_signature );
ADD_DATA( what );
// depending on the "what" value, we will send different information
// to the clients
switch( what ) {
case AI_UPDATE_DOCK:
// for docking ships, add the signature of the ship that we are docked with.
Assert( other_objp != NULL );
other_signature = other_objp->net_signature;
// Goober5000 - this is sort of weird, but it's the best way to do it
docker_index = (ubyte) dock_find_dockpoint_used_by_object(objp, other_objp);
dockee_index = (ubyte) dock_find_dockpoint_used_by_object(other_objp, objp);
ADD_USHORT( other_signature );
ADD_DATA( docker_index );
ADD_DATA( dockee_index );
break;
case AI_UPDATE_UNDOCK:
// same for undocking ships
Assert( other_objp != NULL );
other_signature = other_objp->net_signature;
ADD_USHORT( other_signature );
break;
case AI_UPDATE_ORDERS: {
int shipnum;
// for orders, we only need to send a little bit of information here. Be sure that the
// first order for this ship is active
Assert( (aip->active_goal != AI_GOAL_NONE) && (aip->active_goal != AI_ACTIVE_GOAL_DYNAMIC) );
aigp = &aip->goals[aip->active_goal];
ADD_INT( aigp->ai_mode );
ADD_INT( aigp->ai_submode );
shipnum = -1;
if ( aigp->target_name != NULL )
shipnum = ship_name_lookup( aigp->target_name );
// the ship_name member of the goals structure may or may not contain a real shipname. If we don't
// have a valid shipnum, then don't sweat it since it may not really be a ship.
if ( shipnum != -1 ) {
Assert( Ships[shipnum].objnum != -1 );
other_signature = Objects[Ships[shipnum].objnum].net_signature;
} else
other_signature = 0;
ADD_USHORT( other_signature );
// for docking, add the dock and dockee index
if ( aigp->ai_mode & (AI_GOAL_DOCK|AI_GOAL_REARM_REPAIR) ) {
Assert(aigp->flags & AIGF_DOCK_INDEXES_VALID);
Assert( (aigp->docker.index >= 0) && (aigp->docker.index < UCHAR_MAX) );
Assert( (aigp->dockee.index >= 0) && (aigp->dockee.index < UCHAR_MAX) );
docker_index = (ubyte) aigp->docker.index;
dockee_index = (ubyte) aigp->dockee.index;
ADD_DATA( docker_index );
ADD_DATA( dockee_index );
}
break;
}
default:
Int3();
}
multi_rate_add(1, "aiu", packet_size);
multi_io_send_to_all_reliable(data, packet_size);
}
// process an ai_info update packet. Docking/undocking, ai orders, etc. are taken care of here. This
// information is mainly used to keep the clients HUD up to date with the appropriate information.
void process_ai_info_update_packet( ubyte *data, header *hinfo)
{
int offset = HEADER_LENGTH;
int mode, submode;
ushort net_signature, other_net_signature;
object *objp, *other_objp;
ai_info *aip;
ai_goal *aigp = NULL;
char code;
ubyte docker_index = 0, dockee_index = 0;
GET_USHORT( net_signature ); // signature of the object that we are dealing with.
GET_DATA( code ); // code of what we are doing.
objp = multi_get_network_object( net_signature );
if ( !objp )
nprintf(("Network", "Couldn't find object for ai update\n"));
switch( code ) {
case AI_UPDATE_DOCK:
GET_USHORT( other_net_signature );
GET_DATA( docker_index );
GET_DATA( dockee_index );
other_objp = multi_get_network_object( other_net_signature );
if ( !other_objp )
nprintf(("Network", "Couldn't find other object for ai update on dock\n"));
// if we don't have an object to work with, break out of loop
if ( !objp || !other_objp || (objp->type != OBJ_SHIP) || (other_objp->type != OBJ_SHIP)){
break;
}
// don't assign the dock indexes, because they're part of the docking ship's goal code... just dock them
// (and besides, we might be docking initially docked ships and we wouldn't have an active goal)
ai_do_objects_docked_stuff( objp, docker_index, other_objp, dockee_index );
break;
case AI_UPDATE_UNDOCK:
GET_USHORT( other_net_signature );
other_objp = multi_get_network_object( other_net_signature );
// if we don't have an object to work with, break out of loop
if ( !objp )
break;
ai_do_objects_undocked_stuff( objp, other_objp );
break;
case AI_UPDATE_ORDERS:
GET_INT( mode );
GET_INT( submode );
GET_USHORT( other_net_signature );
if ( mode & (AI_GOAL_DOCK|AI_GOAL_REARM_REPAIR) ) {
GET_DATA(docker_index);
GET_DATA(dockee_index);
}
// be sure that we have a ship object!!!
if ( !objp || (objp->type != OBJ_SHIP) )
break;
// set up the information in the first goal element of the object in question
aip = &Ai_info[Ships[objp->instance].ai_index];
aip->active_goal = 0;
aigp = &aip->goals[aip->active_goal];
aigp->ai_mode = mode;
aigp->ai_submode = submode;
// for docking, add the docker and dockee index to the active goal
if ( mode & (AI_GOAL_DOCK|AI_GOAL_REARM_REPAIR) ) {
aigp->docker.index = docker_index;
aigp->dockee.index = dockee_index;
aigp->flags |= AIGF_DOCK_INDEXES_VALID;
}
// get a shipname if we can.
other_objp = multi_get_network_object( other_net_signature );
if ( other_objp && (other_objp->type == OBJ_SHIP) ) {
// get a pointer to the shipname in question. Use the ship_name value in the
// ship. We are only using this for HUD display, so I think that using this
// method will be fine.
aigp->target_name = ai_get_goal_target_name(Ships[other_objp->instance].ship_name, &aigp->target_name_index);
// special case for destroy subsystem -- get the ai_info pointer to our target ship
// so that we can properly set up what subsystem this ship is attacking.
if ( (mode == AI_GOAL_DESTROY_SUBSYSTEM ) && (submode >= 0) )
aip->targeted_subsys = ship_get_indexed_subsys( &Ships[other_objp->instance], submode);
}
break;
default:
Int3(); // this Int3() should be temporary
nprintf(("Network", "Invalid code for ai update: %d\n", code));
break;
}
PACKET_SET_SIZE();
}
// tell the standalone to move into the MISSION_SYNC_STATE
void send_mission_sync_packet(int mode,int start_campaign)
{
ubyte data[MAX_PACKET_SIZE],is_campaign;
int packet_size = 0;
Assert((Net_player->flags & NETINFO_FLAG_GAME_HOST) && !(Net_player->flags & NETINFO_FLAG_AM_MASTER));
// build the header and add the sync mode (pre or post briefing)
BUILD_HEADER(MISSION_SYNC_DATA);
ADD_INT(mode);
// if this is a campaign game
if(mode == MULTI_SYNC_PRE_BRIEFING){
if(Game_mode & GM_CAMPAIGN_MODE){
// add a byte indicating campaign mode
is_campaign = 1;
ADD_DATA(is_campaign);
// add a byte indicating if we should be starting a campaign or continuing it
is_campaign = (ubyte)start_campaign;
ADD_DATA(is_campaign);
// add the campaign filename
ADD_STRING(Netgame.campaign_name);
}
// otherwise if this is a single mission
else {
// add a byte indicating single mission mode
is_campaign = 0;
ADD_DATA(is_campaign);
// add the mission filename
ADD_STRING(Game_current_mission_filename);
}
}
multi_io_send_reliable(Net_player, data, packet_size);
}
// move into the MISSION_SYNC state when this is received
// this packet is sent only from a game host to a standalone
void process_mission_sync_packet(ubyte *data, header *hinfo)
{
int mode;
ubyte campaign_flag;
int offset = HEADER_LENGTH;
Assert(Game_mode & GM_STANDALONE_SERVER);
// if this is a team vs team situation, lock the players send a final team update
if(Netgame.type_flags & NG_TYPE_TEAM){
multi_team_host_lock_all();
multi_team_send_update();
}
// get the sync mode (pre or post briefing)
GET_INT(mode);
if(mode == MULTI_SYNC_PRE_BRIEFING){
// get the flag indicating if this is a single mission or a campaign mode
GET_DATA(campaign_flag);
if(campaign_flag){
// get the flag indicating whether we should be starting a new campaign
GET_DATA(campaign_flag);
// get the campaign filename
GET_STRING(Netgame.campaign_name);
// either start a new campaign or continue on to the next mission in the current campaign
if(campaign_flag){
multi_campaign_start(Netgame.campaign_name);
} else {
multi_campaign_next_mission();
}
} else {
// make sure we remove the campaign mode flag
Game_mode &= ~(GM_CAMPAIGN_MODE);
// get the single mission filename
GET_STRING(Game_current_mission_filename);
strcpy_s(Netgame.mission_name,Game_current_mission_filename);
}
}
else if (mode == MULTI_SYNC_POST_BRIEFING) {
// process the initial orders now (moved from post_process_mission()in missionparse)
mission_parse_fixup_players();
ai_post_process_mission();
}
PACKET_SET_SIZE();
// set the correct mode and m ove into the state
Multi_sync_mode = mode;
gameseq_post_event(GS_EVENT_MULTI_MISSION_SYNC);
}
// tell a player to merge his mission stats into his alltime stats
void send_store_stats_packet(int accept)
{
ubyte data[10],val;
int packet_size = 0;
BUILD_HEADER(STORE_MISSION_STATS);
// add whether we're accepting or tossing
val = (ubyte)accept;
ADD_DATA(val);
// if I'm the server, send to everyone, else send to the standalone to be rebroadcasted
if(Net_player->flags & NETINFO_FLAG_AM_MASTER){
multi_io_send_to_all_reliable(data, packet_size);
} else {
multi_io_send_reliable(Net_player, data, packet_size);
}
}
void process_store_stats_packet(ubyte *data, header *hinfo)
{
int offset = HEADER_LENGTH;
ubyte accept;
GET_DATA(accept);
PACKET_SET_SIZE();
// if I'm the standalone, rebroadcast. Otherwise, if I'm a client, merge my mission stats with my alltime stats
if(Game_mode & GM_STANDALONE_SERVER){
// rebroadcast the packet to all others in the game
nprintf(("Network","Standalone received store stats packet - rebroadcasting..\n"));
multi_io_send_to_all_reliable(data, offset);
} else {
if(accept){
// all players should mark the stats as being accepted in the debriefing
multi_debrief_stats_accept();
} else {
// all players should mark the stats as being "tossed" in the debriefing
multi_debrief_stats_toss();
}
}
}
void send_debris_update_packet(object *objp,int code)
{
ubyte data[MAX_PACKET_SIZE];
ubyte val;
int packet_size = 0;
BUILD_HEADER(DEBRIS_UPDATE);
ADD_USHORT(objp->net_signature);
val = (ubyte) code;
ADD_DATA(val);
// add any extra relevant data
switch(code){
case DEBRIS_UPDATE_UPDATE:
ADD_VECTOR(objp->pos); // add position
ADD_ORIENT(objp->orient); // add orientation
ADD_VECTOR(objp->phys_info.vel); // add velocity
ADD_VECTOR(objp->phys_info.rotvel); // add rotational velocity
break;
}
multi_io_send_to_all(data, packet_size);
}
void process_debris_update_packet(ubyte *data, header *hinfo)
{
ushort net_sig;
ubyte code;
object bogus_object;
object *objp;
int offset = HEADER_LENGTH;
GET_USHORT(net_sig);
GET_DATA(code);
objp = NULL;
objp = multi_get_network_object(net_sig);
if(objp == NULL){
objp = &bogus_object;
}
switch((int)code){
// update the object
case DEBRIS_UPDATE_UPDATE:
GET_VECTOR(objp->pos);
GET_ORIENT(objp->orient);
GET_VECTOR(objp->phys_info.vel);
GET_VECTOR(objp->phys_info.rotvel);
break;
// simply remove it (no explosion)
case DEBRIS_UPDATE_REMOVE:
if(objp != &bogus_object){
Assert(objp->type == OBJ_DEBRIS);
obj_delete(OBJ_INDEX(objp));
}
break;
// blow it up
case DEBRIS_UPDATE_NUKE:
if(objp != &bogus_object)
debris_hit(objp,NULL,&objp->pos,1000000.0f);
break;
}
PACKET_SET_SIZE();
}
// ALAN begin
void send_wss_request_packet(short player_id, int from_slot, int from_index, int to_slot, int to_index, int wl_ship_slot, int ship_class, int mode, net_player *p)
{
ubyte data[MAX_PACKET_SIZE];
int packet_size = 0;
BUILD_HEADER(WSS_REQUEST_PACKET);
// add the request information
ADD_SHORT(player_id);
ADD_INT(from_slot);
ADD_INT(from_index);
ADD_INT(to_slot);
ADD_INT(to_index);
ADD_INT(wl_ship_slot); // only used in weapons loadout
ADD_INT(ship_class);
ADD_INT(mode);
// a standard request
if(p == NULL){
multi_io_send_reliable(Net_player, data, packet_size);
}
// being routed through the standalone to the host of the game
else {
Assert(Game_mode & GM_STANDALONE_SERVER);
multi_io_send_reliable(p, data, packet_size);
}
}
void process_wss_request_packet(ubyte *data, header *hinfo)
{
int offset = HEADER_LENGTH;
int from_slot,from_index;
int to_slot,to_index;
int mode;
int wl_ship_slot,ship_class;
short player_id;
int player_num;
// determine who this request is from
GET_SHORT(player_id);
player_num = find_player_id(player_id);
// read in the request data
GET_INT(from_slot);
GET_INT(from_index);
GET_INT(to_slot);
GET_INT(to_index);
GET_INT(wl_ship_slot); // only used in weapons loadout
GET_INT(ship_class); // only used in multi team select
GET_INT(mode);
PACKET_SET_SIZE();
Assert(player_num != -1);
if(player_num == -1){
return;
}
// if we're the standalone, we have to route this packet to the host of the game
if(Game_mode & GM_STANDALONE_SERVER){
send_wss_request_packet(player_id, from_slot, from_index, to_slot, to_index, wl_ship_slot, ship_class, mode, Netgame.host);
}
// otherwise we're the host and should process the request
else {
switch(mode){
case WSS_WEAPON_SELECT :
wl_drop(from_slot,from_index,to_slot,to_index,wl_ship_slot,player_num);
break;
case WSS_SHIP_SELECT :
multi_ts_drop(from_slot,from_index,to_slot,to_index,ship_class,player_num);
break;
default:
Int3();
}
}
}
void send_wss_update_packet(int team_num,ubyte *wss_data,int size)
{
ubyte data[MAX_PACKET_SIZE],team;
int packet_size = 0;
Assert(size <= (MAX_PACKET_SIZE - 10));
BUILD_HEADER(WSS_UPDATE_PACKET);
// add the team/pool # this is for
team = (ubyte)team_num;
ADD_DATA(team);
// add the data block size
ADD_INT(size);
// add the data itself
memcpy(data + packet_size,wss_data,size);
packet_size += size;
// if we're also the master of the game (not on a standalone)
if(Net_player->flags & NETINFO_FLAG_AM_MASTER){
multi_io_send_to_all_reliable(data, packet_size);
}
// if we're only the host on the standalone, then send the packet to the standalone to be routed
else {
multi_io_send_reliable(Net_player, data, packet_size);
}
}
void process_wss_update_packet(ubyte *data, header *hinfo)
{
ubyte team;
int size,player_index,idx;
int offset = HEADER_LENGTH;
// get the team/pool #
GET_DATA(team);
// get the data size
GET_INT(size);
// if we're the standalone, then we should be routing this data to all the other clients
if(Game_mode & GM_STANDALONE_SERVER){
// read in the data
offset += size;
PACKET_SET_SIZE();
// determine where this came from
player_index = find_player_id(hinfo->id);
Assert(player_index != -1);
if(player_index < 0){
return;
}
// route the packet (don't resend it to the host)
for(idx=0;idx<MAX_PLAYERS;idx++){
if(MULTI_CONNECTED(Net_players[idx]) && (&Net_players[idx] != Net_player) && (&Net_players[idx] != &Net_players[player_index]) ){
multi_io_send_reliable(&Net_players[idx], data, offset);
}
}
} else {
// set the proper pool pointers
common_set_team_pointers((int)team);
// read in the block of data, and apply it to the weapons/ship pools
offset += restore_wss_data(data + offset);
PACKET_SET_SIZE();
// set the pool pointers back to my own team
common_set_team_pointers(Net_player->p_info.team);
// sync the interface if this was for my own team
if((int)team == Net_player->p_info.team){
multi_ts_sync_interface();
}
}
}
// ALAN END
// function to send firing information from the client to the server once they reach
// the final sync screen.
void send_firing_info_packet()
{
ubyte data[MAX_PACKET_SIZE];
int packet_size;
ubyte plinked, sdual;
Assert( !(Net_player->flags & NETINFO_FLAG_AM_MASTER) );
BUILD_HEADER(FIRING_INFO);
plinked = (ubyte)((Player_ship->flags & SF_PRIMARY_LINKED)?1:0);
sdual = (ubyte)((Player_ship->flags & SF_SECONDARY_DUAL_FIRE)?1:0);
ADD_DATA( plinked );
ADD_DATA( sdual );
multi_io_send_reliable(Net_player, data, packet_size);
}
void process_firing_info_packet( ubyte *data, header *hinfo )
{
int offset, player_num;
ubyte plinked, sdual;
ship *shipp;
// only the master of the game should be dealing with these packets
Assert( Net_player->flags & NETINFO_FLAG_AM_MASTER );
offset = HEADER_LENGTH;
GET_DATA( plinked );
GET_DATA( sdual );
PACKET_SET_SIZE();
player_num = find_player_id(hinfo->id);
if(player_num < 0){
nprintf(("Network","Received firing info packet from unknown player, ignoring\n"));
return;
}
// get the ship pointer for this player and set the flags accordingly.
shipp = &(Ships[Objects[Net_players[player_num].m_player->objnum].instance]);
if ( plinked )
shipp->flags |= SF_PRIMARY_LINKED;
else
shipp->flags &= ~SF_PRIMARY_LINKED;
if ( sdual )
shipp->flags |= SF_SECONDARY_DUAL_FIRE;
else
shipp->flags &= ~SF_SECONDARY_DUAL_FIRE;
}
// packet to deal with changing status of mission goals. used to be sent every so often from server
// to clients, but with addition of reliable sockets, send when complete, invalid, etc.
// goal_num is the index into mission_goals. new_status means failed, success, etc. -1 if not used.
// valid means goal is changing to invalid(0) or valid(1). only applies if new_status == -1
void send_mission_goal_info_packet( int goal_num, int new_status, int valid )
{
ubyte data[MAX_PACKET_SIZE];
int packet_size;
BUILD_HEADER(MISSION_GOAL_INFO);
ADD_INT(goal_num);
ADD_INT(new_status);
ADD_INT(valid);
multi_io_send_to_all_reliable(data, packet_size);
}
void process_mission_goal_info_packet( ubyte *data, header *hinfo )
{
int offset, goal_num, new_status, valid;
offset = HEADER_LENGTH;
GET_INT(goal_num);
GET_INT(new_status);
GET_INT(valid);
PACKET_SET_SIZE();
// if new_status != -1, then this is a change in goal status (i.e. goal failed, or is successful)
if ( new_status != -1 ){
mission_goal_status_change( goal_num, new_status );
} else {
mission_goal_validation_change( goal_num, valid );
}
}
void send_player_settings_packet(net_player *p)
{
ubyte data[MAX_PACKET_SIZE];
ubyte stop;
int idx;
int packet_size = 0;
// build the header
BUILD_HEADER(PLAYER_SETTINGS);
// add all the data for all the players
stop = 0x0;
for(idx=0;idx<MAX_PLAYERS;idx++){
if(MULTI_CONNECTED(Net_players[idx])){
ADD_DATA(stop);
ADD_SHORT(Net_players[idx].player_id);
// break the p_info structure by member, so we don't overwrite any absolute pointers
// ADD_DATA(Net_players[idx].p_info);
ADD_INT(Net_players[idx].p_info.team);
ADD_INT(Net_players[idx].p_info.ship_index);
ADD_INT(Net_players[idx].p_info.ship_class);
}
}
// add the stop byte
stop = 0xff;
ADD_DATA(stop);
// either broadcast the data or send to a specific player
if(p == NULL){
multi_io_send_to_all_reliable(data, packet_size);
} else {
multi_io_send_reliable(p, data, packet_size);
}
}
void process_player_settings_packet(ubyte *data, header *hinfo)
{
int offset,player_num;
net_player_info bogus,*ptr;
short player_id;
ubyte stop;
offset = HEADER_LENGTH;
// read in the data for all the players
GET_DATA(stop);
while(stop != 0xff){
// lookup the player
GET_SHORT(player_id);
player_num = find_player_id(player_id);
// make sure this is a valid player
if(player_num == -1){
ptr = &bogus;
} else {
ptr = &Net_players[player_num].p_info;
}
GET_INT(ptr->team);
GET_INT(ptr->ship_index);
GET_INT(ptr->ship_class);
// next stop byte
GET_DATA(stop);
}
PACKET_SET_SIZE();
// update the server with my new state
// MWA -- 3/31/98 -- check for in mission instead of state.
//if ( Netgame.game_state == NETGAME_STATE_MISSION_SYNC) {
if( !(Game_mode & GM_IN_MISSION) ) {
Net_player->state = NETPLAYER_STATE_SETTINGS_ACK;
send_netplayer_update_packet();
}
// display some cool text
multi_common_add_text(XSTR("Received player settings packet\n",721),1);
}
void send_deny_packet(net_addr *addr, int code)
{
ubyte data[10];
int packet_size = 0;
// build the header and add the rejection code
BUILD_HEADER(DENY);
ADD_INT(code);
// send the packet
psnet_send(addr, data, packet_size);
}
void process_deny_packet(ubyte *data, header *hinfo)
{
int offset,code;
// get the denial code
offset = HEADER_LENGTH;
GET_INT(code);
PACKET_SET_SIZE();
// if there is already a dialog active, do nothing - who cares at this point.
if(popup_active()){
return;
}
// display the appropriate dialog
switch(code){
case JOIN_DENY_JR_STATE :
popup(PF_USE_AFFIRMATIVE_ICON,1,POPUP_OK,XSTR("You have been rejected because the game is not in an appropriate state to accept",722));
break;
case JOIN_DENY_JR_TRACKER_INVAL :
popup(PF_USE_AFFIRMATIVE_ICON,1,POPUP_OK,XSTR("You have been rejected because this is a Parallax Online game and you are not a registered Parallax Online pilot",723));
break;
case JOIN_DENY_JR_PASSWD :
popup(PF_USE_AFFIRMATIVE_ICON,1,POPUP_OK,XSTR("You have been rejected because this is a password protected game",724));
break;
case JOIN_DENY_JR_CLOSED :
popup(PF_USE_AFFIRMATIVE_ICON,1,POPUP_OK,XSTR("You have been rejected because this is a closed game and the mission is in progress",725));
break;
case JOIN_DENY_JR_TEMP_CLOSED :
popup(PF_USE_AFFIRMATIVE_ICON,1,POPUP_OK,XSTR("You have been rejected because the netgame is forming and the host has temporarily closed it",726));
break;
case JOIN_DENY_JR_RANK_HIGH :
popup(PF_USE_AFFIRMATIVE_ICON,1,POPUP_OK,XSTR("You have been rejected because this is a rank limited game and your rank is too high",727));
break;
case JOIN_DENY_JR_RANK_LOW :
popup(PF_USE_AFFIRMATIVE_ICON,1,POPUP_OK,XSTR("You have been rejected because this is a rank limited game and your rank is too low",728));
break;
case JOIN_DENY_JR_DUP :
popup(PF_USE_AFFIRMATIVE_ICON,1,POPUP_OK,XSTR("You have been rejected because there is an identical player already in the game",729));
break;
case JOIN_DENY_JR_FULL :
popup(PF_USE_AFFIRMATIVE_ICON,1,POPUP_OK,XSTR("You have been rejected because the game is full",730));
break;
case JOIN_DENY_JR_BANNED :
popup(PF_USE_AFFIRMATIVE_ICON,1,POPUP_OK,XSTR("You have been rejected because you are banned from this server",731));
break;
case JOIN_DENY_JR_NOOBS :
popup(PF_USE_AFFIRMATIVE_ICON,1,POPUP_OK,XSTR("You have been rejected because this game does not allow observers",732));
break;
case JOIN_DENY_JR_INGAME_JOIN :
popup(PF_USE_AFFIRMATIVE_ICON,1,POPUP_OK,XSTR("You cannot join at this time since someone else is currently joining. Try again shortly.",733));
break;
case JOIN_DENY_JR_BAD_VERSION :
popup(PF_USE_AFFIRMATIVE_ICON,1,POPUP_OK,XSTR("You cannot join this game because you are running an older version of FreeSpace than the server. Exit FreeSpace, and choose the 'Update FreeSpace' button in the FreeSpace launcher to download the latest version of FreeSpace.",734));
break;
case JOIN_DENY_JR_TYPE :
popup(PF_USE_AFFIRMATIVE_ICON,1,POPUP_OK,XSTR("You cannot join a game in progress unless it is a dogfight mission.",1433));
break;
}
// call this so that the join request timestamp automatically expires when we hear back from the server
multi_join_reset_join_stamp();
}
// this packet will consist of
// 1.) netplayer ship classes (85 bytes max)
// 2.) ship weapon state data (277 bytes max)
// 3.) player settings et. al. (133 bytes max)
// TOTAL 495 NOTE : keep this in mind when/if adding new data to this packet
void send_post_sync_data_packet(net_player *p, int std_request)
{
ubyte data[MAX_PACKET_SIZE], val;
char bval;
ship *shipp;
net_player *pl;
ship_obj *so;
ushort sval, ship_ets;
int idx, player_index;
int packet_size = 0;
int ship_count;
short val_short;
BUILD_HEADER(POST_SYNC_DATA);
// some header information for standalone packet routing purposes
val = (ubyte)std_request;
ADD_DATA(val);
// the standalone has two situations
// 1.) sending a request to the host to distribute this block of data
// 2.) having recevied this block of data from the host, it redistributes it
if((Game_mode & GM_STANDALONE_SERVER) && std_request && (Netgame.host != NULL)){
// case 1, send the request
multi_io_send_reliable(Netgame.host, data, packet_size);
return;
}
// case 2 for the standalone is below (as normal)
// otherwise build the data now
// add all deleted ships
val = (ubyte)Multi_ts_num_deleted;
ADD_DATA(val);
for(idx=0;idx<Multi_ts_num_deleted;idx++){
sval = (ushort)Objects[Multi_ts_deleted_objnums[idx]].net_signature;
ADD_USHORT(sval);
}
// ship count
ship_count = 0;
for ( so = GET_FIRST(&Ship_obj_list); so != END_OF_LIST(&Ship_obj_list); so = GET_NEXT(so) ) {
shipp = &Ships[Objects[so->objnum].instance];
// don't process non player wing ships
if ( !(shipp->flags & SF_FROM_PLAYER_WING ) )
continue;
ship_count++;
}
// # of ships - used multiple times in the packet
val = (ubyte)ship_count;
ADD_DATA(val);
// add ship class information (85 bytes max)
for ( so = GET_FIRST(&Ship_obj_list); so != END_OF_LIST(&Ship_obj_list); so = GET_NEXT(so) ) {
shipp = &Ships[Objects[so->objnum].instance];
// don't process non player wing ships
if ( !(shipp->flags & SF_FROM_PLAYER_WING ) )
continue;
// add the net signature of the object for look up
ADD_USHORT( Objects[so->objnum].net_signature );
// add the ship info index
val = (ubyte)(shipp->ship_info_index);
ADD_DATA(val);
// add the ships's team select index
val = (ubyte)shipp->ts_index;
ADD_DATA(val);
}
// add weapon state information for all starting ships (277 bytes max)
for ( so = GET_FIRST(&Ship_obj_list); so != END_OF_LIST(&Ship_obj_list); so = GET_NEXT(so) ) {
shipp = &Ships[Objects[so->objnum].instance];
// don't process non player wing ships
if ( !(shipp->flags & SF_FROM_PLAYER_WING ) )
continue;
// if this is a ship owned by a player, we should mark down his weapons bank/link settings now if we're the server
pl = NULL;
if(Net_player->flags & NETINFO_FLAG_AM_MASTER){
player_index = multi_find_player_by_net_signature(Objects[so->objnum].net_signature);
if(player_index == -1){
pl = NULL;
} else {
pl = &Net_players[player_index];
}
}
// add the net signature and other weapon information
ADD_USHORT( Objects[so->objnum].net_signature );
// add number of primary and secondary banks
bval = (char)(shipp->weapons.num_primary_banks);
ADD_DATA(bval);
bval = (char)(shipp->weapons.num_secondary_banks);
ADD_DATA(bval);
// add weapon bank status
bval = (char)(shipp->weapons.current_primary_bank);
if(pl != NULL){
pl->s_info.cur_primary_bank = bval;
}
// Assert(bval != -1);
ADD_DATA(bval);
bval = (char)(shipp->weapons.current_secondary_bank);
if(pl != NULL){
pl->s_info.cur_secondary_bank = bval;
}
// Assert(bval != -1);
ADD_DATA(bval);
// primary weapon info
val = (ubyte)(shipp->weapons.primary_bank_weapons[0]);
ADD_DATA(val);
val = (ubyte)(shipp->weapons.primary_bank_weapons[1]);
ADD_DATA(val);
// secondary weapon info
val_short = (short)(shipp->weapons.secondary_bank_weapons[0]);
ADD_SHORT(val_short);
val_short = (short)(shipp->weapons.secondary_bank_ammo[0]);
ADD_SHORT(val_short);
val_short = (short)(shipp->weapons.secondary_bank_weapons[1]);
ADD_SHORT(val_short);
val_short = (short)(shipp->weapons.secondary_bank_ammo[1]);
ADD_SHORT(val_short);
val_short = (short)(shipp->weapons.secondary_bank_weapons[2]);
ADD_SHORT(val_short);
val_short = (short)(shipp->weapons.secondary_bank_ammo[2]);
ADD_SHORT(val_short);
// send primary and secondary weapon link status
val = 0x0;
if(shipp->flags & SF_PRIMARY_LINKED){
if(pl != NULL){
pl->s_info.cur_link_status |= (1<<0);
}
val |= (1<<0);
}
if(shipp->flags & SF_SECONDARY_DUAL_FIRE){
if(pl != NULL){
pl->s_info.cur_link_status |= (1<<1);
}
val |= (1<<1);
}
// if this is a player ship add (1<<2)
if(Objects[shipp->objnum].flags & OF_PLAYER_SHIP){
val |= (1<<2);
}
ADD_DATA(val);
// add a ship ets value
ship_ets = 0x0000;
// shield ets
ship_ets |= ((ushort)shipp->shield_recharge_index << 8);
// weapon ets
ship_ets |= ((ushort)shipp->weapon_recharge_index << 4);
// engine ets
ship_ets |= ((ushort)shipp->engine_recharge_index);
ADD_USHORT(ship_ets);
}
// 2 cases, if I'm the host on a standalone, I should be sending this to the standalone only
// or if I'm the server as well as the host, I should be sending this to all players
if(Net_player->flags & NETINFO_FLAG_GAME_HOST){
if(Net_player->flags & NETINFO_FLAG_AM_MASTER){
// broadcast
if(p == NULL){
multi_io_send_to_all_reliable(data, packet_size);
}
// send to a specific player
else {
multi_io_send_reliable(p, data, packet_size);
}
} else {
multi_io_send_reliable(Net_player, data, packet_size);
}
}
// standalone mode
else {
// broadcast
if(p == NULL){
multi_io_send_to_all_reliable(data, packet_size);
}
// send to a specific player
else {
multi_io_send_reliable(p, data, packet_size);
}
}
}
void process_post_sync_data_packet(ubyte *data, header *hinfo)
{
ubyte val, sinfo_index, ts_index;
char b;
ushort net_sig, ship_ets, sval;
ship *shipp;
object *objp;
int idx;
int offset = HEADER_LENGTH;
int ship_count;
short val_short;
// packet routing information
GET_DATA(val);
// if I'm the host on a standalone, this is going to be a request to send the data to the standalone to be routed
if((Net_player->flags & NETINFO_FLAG_GAME_HOST) && !(Net_player->flags & NETINFO_FLAG_AM_MASTER) && val){
PACKET_SET_SIZE();
// at this point we want to delete all necessary ships, change all necessary ship classes, and set all weapons up
multi_ts_create_wings();
// send to the standalone through my socket
send_post_sync_data_packet(Net_player);
return;
}
// process player
// add all deleted ships
GET_DATA(val);
Multi_ts_num_deleted = (int)val;
for(idx=0;idx<Multi_ts_num_deleted;idx++){
// get the ship's objnum
GET_USHORT(sval);
objp = NULL;
objp = multi_get_network_object(sval);
if(objp != NULL){
// delete the ship appropriately
// mark the object as having been deleted
Multi_ts_deleted_objnums[idx] = OBJ_INDEX(objp);
// delete the ship
ship_add_exited_ship(&Ships[objp->instance], SEF_PLAYER_DELETED);
obj_delete(Multi_ts_deleted_objnums[idx]);
ship_wing_cleanup(objp->instance,&Wings[Ships[objp->instance].wingnum]);
} else {
Multi_ts_num_deleted--;
nprintf(("Network","Couldn't find object by net signature for ship delete in post sync data packet\n"));
}
}
// ship count
GET_DATA(val);
ship_count = val;
// process ship class information
for(idx=0; idx<ship_count; idx++){
// get the object's net signature
GET_USHORT(net_sig);
GET_DATA(sinfo_index);
GET_DATA(ts_index);
// attempt to get the object
objp = multi_get_network_object(net_sig);
// make sure we found a ship
Assert((objp != NULL) && (objp->type == OBJ_SHIP));
// set the ship to be the right class
change_ship_type(objp->instance,(int)sinfo_index);
// set the ship's team select index
Ships[objp->instance].ts_index = (int)ts_index;
}
// process ship weapon state info
for(idx=0; idx<ship_count; idx++){
// get the object's net signature
GET_USHORT(net_sig);
// attempt to get the object
objp = multi_get_network_object(net_sig);
// make sure we found a ship
Assert((objp != NULL) && (objp->type == OBJ_SHIP));
// get a pointer to the ship
shipp = &Ships[objp->instance];
// get number of primary and secondary banks;
GET_DATA(b);
Assert( b != -1 );
shipp->weapons.num_primary_banks = (int)b;
GET_DATA(b);
Assert( b != -1 );
shipp->weapons.num_secondary_banks = (int)b;
// get bank selection info
GET_DATA(b);
if ( b == -1 ){
b = 0;
}
shipp->weapons.current_primary_bank = (int)b;
GET_DATA(b);
if ( b == -1 ){
b = 0;
}
shipp->weapons.current_secondary_bank = (int)b;
// primary weapon info
GET_DATA(val);
shipp->weapons.primary_bank_weapons[0] = (int)val;
GET_DATA(val);
shipp->weapons.primary_bank_weapons[1] = (int)val;
// secondary weapon info
GET_SHORT(val_short);
shipp->weapons.secondary_bank_weapons[0] = (int)val_short;
GET_SHORT(val_short);
shipp->weapons.secondary_bank_ammo[0] = (int)val_short;
GET_SHORT(val_short);
shipp->weapons.secondary_bank_weapons[1] = (int)val_short;
GET_SHORT(val_short);
shipp->weapons.secondary_bank_ammo[1] = (int)val_short;
GET_SHORT(val_short);
shipp->weapons.secondary_bank_weapons[2] = (int)val_short;
GET_SHORT(val_short);
shipp->weapons.secondary_bank_ammo[2] = (int)val_short;
// other flags
val = 0x0;
GET_DATA(val);
if(val & (1<<0)){
shipp->flags |= SF_PRIMARY_LINKED;
}
if(val & (1<<1)){
shipp->flags |= SF_SECONDARY_DUAL_FIRE;
}
Objects[shipp->objnum].flags &= ~(OF_PLAYER_SHIP);
Objects[shipp->objnum].flags &= ~(OF_COULD_BE_PLAYER);
if(val & (1<<2)){
Objects[shipp->objnum].flags |= OF_PLAYER_SHIP;
} else {
obj_set_flags( &Objects[shipp->objnum], Objects[shipp->objnum].flags | OF_COULD_BE_PLAYER );
}
// get ship ets
GET_USHORT(ship_ets);
// shield ets
shipp->shield_recharge_index = ((ship_ets & 0x0f00) >> 8);
// weapon ets
shipp->weapon_recharge_index = ((ship_ets & 0x00f0) >> 4);
// engine ets
shipp->engine_recharge_index = (ship_ets & 0x000f);
}
PACKET_SET_SIZE();
// ack the server
Net_player->state = NETPLAYER_STATE_POST_DATA_ACK;
send_netplayer_update_packet();
// the standalone server will receive this packet from the host of the game, to be applied locally and
// also to be rebroadcast.
if(Game_mode & GM_STANDALONE_SERVER){
// update player ets settings
for(idx=0;idx<MAX_PLAYERS;idx++){
if(MULTI_CONNECTED(Net_players[idx]) && !MULTI_STANDALONE(Net_players[idx]) && !MULTI_PERM_OBSERVER(Net_players[idx]) && (Net_players[idx].m_player->objnum != -1)){
multi_server_update_player_weapons(&Net_players[idx],&Ships[Objects[Net_players[idx].m_player->objnum].instance]);
}
}
send_post_sync_data_packet(NULL,0);
}
}
void send_wss_slots_data_packet(int team_num,int final,net_player *p,int std_request)
{
ubyte data[MAX_PACKET_SIZE],val;
short val_short;
int idx,i;
int packet_size = 0;
// build the header
BUILD_HEADER(WSS_SLOTS_DATA);
// some header information for standalone packet routing purposes
val = (ubyte)std_request;
ADD_DATA(val);
// add the team #
val = (ubyte)team_num;
ADD_DATA(val);
// add whether this is the final packet or not
val = (ubyte)final;
ADD_DATA(val);
// the standalone has two situations
// 1.) sending a request to the host to distribute this block of data
// 2.) having recevied this block of data from the host, it redistributes it
if((Game_mode & GM_STANDALONE_SERVER) && std_request){
// case 1, send the request
multi_io_send_reliable(Netgame.host, data, packet_size);
return;
}
// case 2 for the standalone is below (as normal)
// add all the slots
for(idx=0;idx<MULTI_TS_NUM_SHIP_SLOTS;idx++){
// add the ship class
val = (ubyte)Wss_slots_teams[team_num][idx].ship_class;
ADD_DATA(val);
// add the weapons
for(i = 0;i<MAX_SHIP_WEAPONS;i++){
val_short = (short)Wss_slots_teams[team_num][idx].wep[i];
ADD_SHORT(val_short);
}
// add the weapon counts
for(i = 0;i<MAX_SHIP_WEAPONS;i++){
val_short = (short)Wss_slots_teams[team_num][idx].wep_count[i];
ADD_SHORT(val_short);
}
}
// 2 cases, if I'm the host on a standalone, I should be sending this to the standalone only
// or if I'm the server as well as the host, I should be sending this to all players
if(Net_player->flags & NETINFO_FLAG_GAME_HOST){
if(Net_player->flags & NETINFO_FLAG_AM_MASTER){
// broadcast
if(p == NULL){
multi_io_send_to_all_reliable(data, packet_size);
}
// send to a specific player
else {
multi_io_send_reliable(p, data, packet_size);
}
} else {
multi_io_send_reliable(Net_player, data, packet_size);
}
}
// standalone mode
else {
// broadcast
if(p == NULL){
multi_io_send_to_all_reliable(data, packet_size);
}
// send to a specific player
else {
multi_io_send_reliable(p, data, packet_size);
}
}
}
void process_wss_slots_data_packet(ubyte *data, header *hinfo)
{
ubyte val,team_num,final;
int idx,i;
int offset = HEADER_LENGTH;
short val_short;
// packet routing information
GET_DATA(val);
// get team data
GET_DATA(team_num);
// get whether this is the final packet or not
GET_DATA(final);
// if I'm the host on a standalone, this is going to be a request to send the data to the standalone to be routed
if((Net_player->flags & NETINFO_FLAG_GAME_HOST) && !(Net_player->flags & NETINFO_FLAG_AM_MASTER) && val){
PACKET_SET_SIZE();
// send to the standalone through my socket
send_wss_slots_data_packet((int)team_num,(int)final,Net_player);
return;
}
// read in all the slot data
for(idx=0;idx<MULTI_TS_NUM_SHIP_SLOTS;idx++){
memset(&Wss_slots_teams[team_num][idx],0,sizeof(wss_unit));
// get the ship class
GET_DATA(val);
Wss_slots_teams[team_num][idx].ship_class = (int)val;
// get the weapons
for(i = 0;i<MAX_SHIP_WEAPONS;i++){
GET_SHORT(val_short);
Wss_slots_teams[team_num][idx].wep[i] = (int)val_short;
}
// get the weapon counts
for(i = 0;i<MAX_SHIP_WEAPONS;i++){
GET_SHORT(val_short);
Wss_slots_teams[team_num][idx].wep_count[i] = (int)val_short;
}
}
PACKET_SET_SIZE();
// update my netplayer state if this is the final packet
if(final){
Net_player->state = NETPLAYER_STATE_WSS_ACK;
send_netplayer_update_packet();
}
// the standalone server will receive this packet from the host of the game, to be applied locally and
// also to be rebroadcast.
if(Game_mode & GM_STANDALONE_SERVER){
send_wss_slots_data_packet((int)team_num,(int)final,NULL,0);
} else {
// add some mission sync text
multi_common_add_text(XSTR("Weapon slots packet\n",735),1);
}
}
#define OBJ_VISIBILITY_DOT 0.6f
// send and receive packets for shield explosion information
void send_shield_explosion_packet( int objnum, int tri_num, vec3d hit_pos )
{
int packet_size, i;
ubyte data[MAX_PACKET_SIZE], utri_num;
Int3();
// Assert(!(Netgame.debug_flags & NETD_FLAG_CLIENT_NODAMAGE));
Assert( tri_num < UCHAR_MAX );
utri_num = (ubyte)tri_num;
// for each player, determine if this object is behind the player -- if so, don't
// send the packet.
for ( i = 0; i < MAX_PLAYERS; i++ ) {
if ( MULTI_CONNECTED(Net_players[i]) && (&Net_players[i] != Net_player) ) {
float dot;
vec3d eye_to_obj_vec, diff, eye_pos;
matrix eye_orient;
eye_pos = Net_players[i].s_info.eye_pos;
eye_orient = Net_players[i].s_info.eye_orient;
// check for same vectors
vm_vec_sub(&diff, &Objects[objnum].pos, &eye_pos);
if ( vm_vec_mag_quick(&diff) < 0.01 ){
continue;
}
vm_vec_normalized_dir(&eye_to_obj_vec, &Objects[objnum].pos, &eye_pos);
dot = vm_vec_dot(&eye_orient.vec.fvec, &eye_to_obj_vec);
if ( dot < OBJ_VISIBILITY_DOT ){
continue;
}
BUILD_HEADER(SHIELD_EXPLOSION);
ADD_USHORT( Objects[objnum].net_signature );
ADD_DATA(utri_num);
multi_io_send(&Net_players[i], data, packet_size);
}
}
}
void add_shield_point_multi(int objnum, int tri_num, vec3d *hit_pos);
void process_shield_explosion_packet( ubyte *data, header *hinfo)
{
int offset;
ushort signature;
ubyte utri_num;
object *objp;
// get the shield hit data
offset = HEADER_LENGTH;
GET_USHORT(signature);
GET_DATA(utri_num);
//GET_DATA(hit_pos);
PACKET_SET_SIZE();
// find the object with this signature. If found, then do a shield explosion
objp = multi_get_network_object( signature );
if ( objp ) {
polymodel *pm;
shield_info *shieldp;
shield_tri stri;
vec3d hit_pos;
int i;
// given the tri num, find the local position which is the average of the
// three vertices of the triangle affected. Use this average point as the hit
// point
// Assert( objp->type == OBJ_SHIP );
if(objp->type != OBJ_SHIP){
return;
}
pm = model_get(Ship_info[Ships[objp->instance].ship_info_index].model_num);
shieldp = &pm->shield;
Assert( utri_num < shieldp->ntris );
stri = shieldp->tris[utri_num];
vm_vec_zero(&hit_pos);
for ( i = 0; i < 3; i++ ) {
vm_vec_add2( &hit_pos, &(shieldp->verts[stri.verts[i]].pos) );
}
vm_vec_scale( &hit_pos, 1.0f/3.0f );
add_shield_point_multi( OBJ_INDEX(objp), utri_num, &hit_pos );
}
}
void send_player_stats_block_packet(net_player *pl, int stats_code, net_player *target, short offset)
{
scoring_struct *sc;
ubyte data[MAX_PACKET_SIZE], val;
int idx;
int packet_size = 0;
ushort u_tmp;
int i_tmp;
sc = &pl->m_player->stats;
// build the header
BUILD_HEADER(PLAYER_STATS);
// add the player id
ADD_SHORT(pl->player_id);
// add the byte indicating whether these stats are all-time or not
val = (ubyte)stats_code;
ADD_DATA(val);
// kill information - alltime
switch(stats_code){
case STATS_ALLTIME:
// alltime kills
idx = 0;
while(idx<MAX_SHIP_CLASSES)
{
send_player_stats_block_packet(pl, STATS_ALLTIME_KILLS, target, (short)idx);
idx += MAX_SHIPS_PER_PACKET;
}
// medal information
for(idx=0;idx<MAX_MEDALS;idx++){
i_tmp = sc->medals[idx];
ADD_INT(i_tmp);
}
ADD_INT(sc->score);
ADD_INT(sc->rank);
ADD_INT(sc->assists);
ADD_INT(sc->kill_count);
ADD_INT(sc->kill_count_ok);
ADD_UINT(sc->p_shots_fired);
ADD_UINT(sc->s_shots_fired);
ADD_UINT(sc->p_shots_hit);
ADD_UINT(sc->s_shots_hit);
ADD_UINT(sc->p_bonehead_hits);
ADD_UINT(sc->s_bonehead_hits);
ADD_INT(sc->bonehead_kills);
ADD_UINT(sc->missions_flown);
ADD_UINT(sc->flight_time);
ADD_INT(sc->last_flown); // should be 32-bit value - taylor
ADD_INT(sc->last_backup); // should be 32-bit value - taylor
break;
case STATS_MISSION:
// mission OKkills
idx = 0;
while(idx<MAX_SHIP_CLASSES)
{
send_player_stats_block_packet(pl, STATS_MISSION_CLASS_KILLS, target, (short)idx);
idx += MAX_SHIPS_PER_PACKET;
}
ADD_INT(sc->m_score);
ADD_INT(sc->m_assists);
ADD_INT(sc->m_kill_count);
ADD_INT(sc->m_kill_count_ok);
ADD_UINT(sc->mp_shots_fired);
ADD_UINT(sc->ms_shots_fired);
ADD_UINT(sc->mp_shots_hit);
ADD_UINT(sc->ms_shots_hit);
ADD_UINT(sc->mp_bonehead_hits);
ADD_UINT(sc->ms_bonehead_hits);
ADD_INT(sc->m_bonehead_kills);
ADD_INT(sc->m_player_deaths);
ADD_INT(sc->m_medal_earned);
break;
case STATS_MISSION_KILLS:
ADD_INT(sc->m_kill_count);
ADD_INT(sc->m_kill_count_ok);
ADD_INT(sc->m_assists);
break;
case STATS_DOGFIGHT_KILLS:
for(idx=0; idx<MAX_PLAYERS; idx++){
u_tmp = (ushort)sc->m_dogfight_kills[idx];
ADD_USHORT(u_tmp);
}
ADD_INT(sc->m_kill_count);
ADD_INT(sc->m_kill_count_ok);
ADD_INT(sc->m_assists);
break;
case STATS_MISSION_CLASS_KILLS:
ADD_SHORT(offset);
for (idx=offset; idx<MAX_SHIP_CLASSES && idx<offset+MAX_SHIPS_PER_PACKET; idx++)
{
ADD_INT(sc->m_okKills[idx]);
}
break;
case STATS_ALLTIME_KILLS:
ADD_SHORT(offset);
for (idx=offset; idx<MAX_SHIP_CLASSES && idx<offset+MAX_SHIPS_PER_PACKET; idx++)
{
ADD_INT(sc->kills[idx]);
}
break;
}
Assert(packet_size < MAX_PACKET_SIZE);
// if we're a client, always send the data to the server
if(!(Net_player->flags & NETINFO_FLAG_AM_MASTER)){
multi_io_send_reliable(Net_player, data, packet_size);
}
// otherwise do server specific stuff
else {
// send to a specific target
if(target != NULL){
multi_io_send_reliable(target, data, packet_size);
}
// otherwise, send to everyone
else {
multi_io_send_to_all_reliable(data, packet_size);
}
}
}
void process_player_stats_block_packet(ubyte *data, header *hinfo)
{
ubyte val;
int player_num,idx;
scoring_struct *sc,bogus;
short player_id;
int offset = HEADER_LENGTH;
ushort u_tmp;
int i_tmp;
// nprintf(("Network","----------++++++++++********RECEIVED STATS***********+++++++++----------\n"));
// get the player who these stats are for
GET_SHORT(player_id);
player_num = find_player_id(player_id);
if (player_num == -1) {
nprintf(("Network", "Couldn't find player for stats update!\n"));
ml_string("Couldn't find player for stats update!\n");
sc = &bogus;
Int3();
} else {
sc = &Net_players[player_num].m_player->stats;
}
// get the stats code
GET_DATA(val);
switch(val){
short si_offset;
case STATS_ALLTIME_KILLS:
GET_SHORT(si_offset);
for (idx = si_offset; idx<MAX_SHIP_CLASSES && idx<si_offset+MAX_SHIPS_PER_PACKET; idx++)
{
GET_INT(i_tmp);
sc->kills[idx] = i_tmp;
}
break;
case STATS_MISSION_CLASS_KILLS:
GET_SHORT(si_offset);
for (idx = si_offset; idx<MAX_SHIP_CLASSES && idx<si_offset+MAX_SHIPS_PER_PACKET; idx++)
{
GET_INT(i_tmp);
sc->m_okKills[idx] = i_tmp;
}
break;
case STATS_ALLTIME:
ml_string("Received STATS_ALLTIME\n");
// read in the stats
for (idx=0; idx<MAX_MEDALS; idx++) {
GET_INT(i_tmp);
sc->medals[idx] = i_tmp;
}
GET_INT(sc->score);
GET_INT(sc->rank);
GET_INT(sc->assists);
GET_INT(sc->kill_count);
GET_INT(sc->kill_count_ok);
GET_UINT(sc->p_shots_fired);
GET_UINT(sc->s_shots_fired);
GET_UINT(sc->p_shots_hit);
GET_UINT(sc->s_shots_hit);
GET_UINT(sc->p_bonehead_hits);
GET_UINT(sc->s_bonehead_hits);
GET_INT(sc->bonehead_kills);
GET_UINT(sc->missions_flown);
GET_UINT(sc->flight_time);
GET_INT(sc->last_flown); // should be 32-bit value - taylor
GET_INT(sc->last_backup); // should be 32-bit value - taylor
break;
case STATS_MISSION:
ml_string("Received STATS_MISSION\n");
GET_INT(sc->m_score);
GET_INT(sc->m_assists);
GET_INT(sc->m_kill_count);
GET_INT(sc->m_kill_count_ok);
GET_UINT(sc->mp_shots_fired);
GET_UINT(sc->ms_shots_fired);
GET_UINT(sc->mp_shots_hit);
GET_UINT(sc->ms_shots_hit);
GET_UINT(sc->mp_bonehead_hits);
GET_UINT(sc->ms_bonehead_hits);
GET_INT(sc->m_bonehead_kills);
GET_INT(sc->m_player_deaths);
GET_INT(sc->m_medal_earned);
break;
case STATS_MISSION_KILLS:
ml_string("Received STATS_MISSION_KILLS\n");
GET_INT(sc->m_kill_count);
GET_INT(sc->m_kill_count_ok);
GET_INT(sc->m_assists);
break;
case STATS_DOGFIGHT_KILLS:
ml_string("Received STATS_DOGFIGHT_KILLS\n");
if(player_num >= 0){
ml_printf("Dogfight stats for %s", Net_players[player_num].m_player->callsign);
}
for(idx=0; idx<MAX_PLAYERS; idx++){
GET_USHORT(u_tmp);
sc->m_dogfight_kills[idx] = u_tmp;
if(player_num >= 0){
ml_printf("%d", Net_players[player_num].m_player->stats.m_dogfight_kills[idx]);
}
}
GET_INT(sc->m_kill_count);
GET_INT(sc->m_kill_count_ok);
GET_INT(sc->m_assists);
break;
}
PACKET_SET_SIZE();
// if I'm the server of the game, I should always rebroadcast these stats
if ((Net_player->flags & NETINFO_FLAG_AM_MASTER) && (sc != &bogus)) {
// make sure these are alltime stats
Assert(val == STATS_ALLTIME || val == STATS_ALLTIME_KILLS);
multi_broadcast_stats(val);
}
}
// called to create asteroid stuff
void send_asteroid_create( object *new_objp, object *parent_objp, int asteroid_type, vec3d *relvec )
{
int packet_size;
ubyte data[MAX_PACKET_SIZE];
ubyte packet_type, atype;
vec3d vec;
vm_vec_zero(&vec);
if (relvec != NULL )
vec = *relvec;
BUILD_HEADER( ASTEROID_INFO );
packet_type = ASTEROID_CREATE;
Assert( asteroid_type < UCHAR_MAX );
atype = (ubyte)asteroid_type;
ADD_DATA( packet_type );
ADD_USHORT( parent_objp->net_signature );
ADD_USHORT( new_objp->net_signature );
ADD_DATA( atype );
ADD_VECTOR( vec );
multi_io_send_to_all(data, packet_size);
}
void send_asteroid_throw( object *objp )
{
int packet_size;
ubyte data[MAX_PACKET_SIZE], packet_type;
BUILD_HEADER( ASTEROID_INFO );
// this packet type is an asteroid throw
packet_type = ASTEROID_THROW;
ADD_DATA( packet_type );
ADD_USHORT( objp->net_signature );
ADD_VECTOR( objp->pos );
ADD_VECTOR( objp->phys_info.vel );
multi_io_send_to_all(data, packet_size);
}
void send_asteroid_hit( object *objp, object *other_objp, vec3d *hitpos, float damage )
{
int packet_size;
ubyte data[MAX_PACKET_SIZE], packet_type;
vec3d vec;
vm_vec_zero(&vec);
if ( hitpos != NULL )
vec = *hitpos;
// build up an asteroid hit packet
BUILD_HEADER( ASTEROID_INFO );
packet_type = ASTEROID_HIT;
ADD_DATA( packet_type );
ADD_USHORT( objp->net_signature );
if(other_objp == NULL){
ushort invalid_sig = 0xffff;
ADD_USHORT(invalid_sig);
} else {
ADD_USHORT( other_objp->net_signature );
}
ADD_VECTOR( vec );
ADD_FLOAT( damage );
multi_io_send_to_all(data, packet_size);
}
void process_asteroid_info( ubyte *data, header *hinfo )
{
int offset;
ubyte packet_type;
offset = HEADER_LENGTH;
GET_DATA( packet_type );
// based on the packet type, do something interesting with an asteroid!
switch( packet_type ) {
case ASTEROID_CREATE: {
ushort psignature, signature;
ubyte atype;
vec3d relvec;
object *parent_objp;
GET_USHORT( psignature );
GET_USHORT( signature );
GET_DATA( atype );
GET_VECTOR( relvec );
// after getting the values, set the next network signature, and call the create sub function
multi_set_network_signature( signature, MULTI_SIG_ASTEROID );
parent_objp = multi_get_network_object( psignature );
if ( parent_objp ) {
asteroid_sub_create( parent_objp, atype, &relvec );
} else {
nprintf(("Network", "Couldn't create asteroid because parent wasn't found!!!\n"));
}
break;
}
// asteroid throw packet -- asteroid has wrapped bounds
case ASTEROID_THROW: {
ushort signature;
vec3d pos, vel;
object *objp;
GET_USHORT( signature );
GET_VECTOR( pos );
GET_VECTOR( vel );
objp = multi_get_network_object( signature );
if ( !objp ) {
nprintf(("Network", "Couldn't throw asteroid because couldn't find it\n"));
break;
}
objp->pos = pos;
objp->phys_info.vel = vel;
objp->phys_info.desired_vel = vel;
break;
}
case ASTEROID_HIT: {
ushort signature, osignature;
object *objp, *other_objp;
vec3d hitpos;
float damage;
GET_USHORT( signature );
GET_USHORT( osignature );
GET_VECTOR( hitpos );
GET_FLOAT( damage );
objp = multi_get_network_object( signature );
if(osignature == 0xffff){
other_objp = NULL;
} else {
other_objp = multi_get_network_object( osignature );
}
if ( !objp ) {
nprintf(("Network", "Cannot hit asteroid because signature isn't found\n"));
break;
}
if ( IS_VEC_NULL(&hitpos) ){
asteroid_hit( objp, other_objp, NULL, damage );
} else {
asteroid_hit( objp, other_objp, &hitpos, damage );
}
// if we know the other object is a weapon, then do a weapon hit to kill the weapon
if ( other_objp && (other_objp->type == OBJ_WEAPON) ){
weapon_hit( other_objp, objp, &hitpos );
}
break;
}
default:
Int3();
break;
}
PACKET_SET_SIZE();
}
void send_host_restr_packet(char *callsign,int code,int mode)
{
ubyte data[MAX_PACKET_SIZE],val;
int packet_size = 0;
// build the header and add the opcode
BUILD_HEADER(HOST_RESTR_QUERY);
val = (ubyte)code;
ADD_DATA(val);
val = (ubyte)mode;
ADD_DATA(val);
// add the callsign
ADD_STRING(callsign);
// if I'm the standalone server, I should be sending this to the game host
if((Game_mode & GM_STANDALONE_SERVER) && (Netgame.host != NULL)){
multi_io_send_reliable(Netgame.host, data, packet_size);
}
// otherwise if I'm the host, I should be sending a reply back to the standalone server
else {
Assert(Net_player->flags & NETINFO_FLAG_GAME_HOST);
multi_io_send_reliable(Net_player, data, packet_size);
}
}
void process_host_restr_packet(ubyte *data, header *hinfo)
{
char callsign[255];
ubyte code,mode;
int offset = HEADER_LENGTH;
// get the opcode and the callsign
GET_DATA(code);
GET_DATA(mode);
GET_STRING(callsign);
PACKET_SET_SIZE();
// do code specific operations
switch(code)
{
// query to the host from standalone
case 0:
Assert((Net_player->flags & NETINFO_FLAG_GAME_HOST) && !(Net_player->flags & NETINFO_FLAG_AM_MASTER));
// set the join mode
Multi_join_restr_mode = mode;
// set the timestamp
Multi_restr_query_timestamp = timestamp(MULTI_QUERY_RESTR_STAMP);
// notify the host of the event
gamesnd_play_iface(SND_BRIEF_STAGE_CHG_FAIL);
HUD_printf(XSTR("Player %s has tried to join - allow (y/n) ?",736),callsign);
break;
// affirmative reply from the host to the standalone
case 1:
Assert(Game_mode & GM_STANDALONE_SERVER);
// let the player join if the timestamp has not already elapsed on the server
if(Multi_restr_query_timestamp != -1){
multi_process_valid_join_request(&Multi_restr_join_request,&Multi_restr_addr,(int)mode);
}
break;
// negative reply
case 2 :
Assert(Game_mode & GM_STANDALONE_SERVER);
Netgame.flags &= ~(NG_FLAG_INGAME_JOINING);
Multi_restr_query_timestamp = -1;
break;
}
}
void send_netgame_end_error_packet(int notify_code,int err_code)
{
ubyte data[10];
char code;
int packet_size = 0;
// only the server should ever be here - although this might change if for some reason the host wants to end the game
Assert(Net_player->flags & NETINFO_FLAG_AM_MASTER);
// build the header and add the notification and error codes
BUILD_HEADER(NETGAME_END_ERROR);
code = (char)notify_code;
ADD_DATA(code);
code = (char)err_code;
ADD_DATA(code);
// send the packet
multi_io_send_to_all_reliable(data, packet_size);
}
void process_netgame_end_error_packet(ubyte *data, header *hinfo)
{
int offset = HEADER_LENGTH;
char notify_code,error_code;
// get the error and notification codes
GET_DATA(notify_code);
GET_DATA(error_code);
PACKET_SET_SIZE();
// quit the game
multi_quit_game(PROMPT_NONE,notify_code,error_code);
}
// sends info that a countermeasure succeeded.
void send_countermeasure_success_packet( int objnum )
{
int pnum, packet_size;
ubyte data[MAX_PACKET_SIZE];
pnum = multi_find_player_by_object( &Objects[objnum] );
if ( pnum == -1 ) {
nprintf(("Network", "Coulnd't find player for countermeasure success packet\n"));
return;
}
BUILD_HEADER(COUNTERMEASURE_SUCCESS);
multi_io_send(&Net_players[pnum], data, packet_size);
}
// start the flashing of my hud gauge
void process_countermeasure_success_packet( ubyte *data, header *hinfo )
{
int offset;
offset = HEADER_LENGTH;
PACKET_SET_SIZE();
//Do this instead so there's less repeat code
//Player_obj is necessary...infinitely recursive function calls != FTW
cmeasure_maybe_alert_success(Player_obj);
/*hud_start_text_flash(XSTR("Evaded", 1430), 800);
snd_play(&Snds[SND_MISSILE_EVADED_POPUP]);*/
}
#define UPDATE_IS_PAUSED (1<<0)
#define UPDATE_HULL_INFO (1<<1)
void send_client_update_packet(net_player *pl)
{
ubyte data[MAX_PACKET_SIZE],val;
int packet_size = 0;
// build the header
BUILD_HEADER(CLIENT_UPDATE);
val = 0;
// add the pause status
if ( Multi_pause_status ) {
val |= UPDATE_IS_PAUSED;
} else if ( (Game_mode & GM_IN_MISSION) && !(pl->flags & NETINFO_FLAG_INGAME_JOIN) && !(NETPLAYER_IS_OBSERVER(pl)) && !(NETPLAYER_IS_DEAD(pl)) && (Objects[pl->m_player->objnum].type == OBJ_SHIP) ) {
val |= UPDATE_HULL_INFO;
Assert( Player_ship ); // I"d better have one of these!!!!
}
ADD_DATA(val);
// if paused, add the net address of the guy who paused
if(val & UPDATE_IS_PAUSED){
Assert(Multi_pause_pauser != NULL);
ADD_DATA(Multi_pause_pauser->player_id);
}
// when not paused, send hull/shield/subsystem updates to all clients (except for ingame joiners)
if ( val & UPDATE_HULL_INFO ) {
object *objp;
ubyte percent, ns, threats;
ship_info *sip;
ship *shipp;
ship_subsys *subsysp;
int i;
// get the object for the player
Assert( pl->m_player->objnum != -1 );
objp = &Objects[pl->m_player->objnum];
Assert ( objp->type == OBJ_SHIP );
shipp = &Ships[objp->instance];
sip = &Ship_info[shipp->ship_info_index];
// hull strength and shield mesh information are floats (as a percentage). Pass the integer
// percentage value since that should be close enough
percent = (ubyte) ((get_hull_pct(objp) * 100.0f) + 0.5f);
if ( (percent == 0) && (get_hull_pct(objp) > 0.0f) ) {
percent = 1;
}
ADD_DATA( percent );
for (i = 0; i < MAX_SHIELD_SECTIONS; i++ ) {
percent = (ubyte)(objp->shield_quadrant[i] / get_max_shield_quad(objp) * 100.0f);
ADD_DATA( percent );
}
// add the data for the subsystem hits. We can assume that the lists will be the same side of
// both machines. Added as percent since that number <= 100
// also write out the number of subsystems. We do this because the client might not know
// about the object he is getting data for. (i.e. he killed the object already).
ns = (ubyte)sip->n_subsystems;
ADD_DATA( ns );
// now the subsystems.
for ( subsysp = GET_FIRST(&shipp->subsys_list); subsysp != END_OF_LIST(&shipp->subsys_list); subsysp = GET_NEXT(subsysp) ) {
percent = (ubyte)(subsysp->current_hits / subsysp->max_hits * 100.0f);
ADD_DATA( percent );
}
// compute the threats for this player. Only compute the threats if this player is actually
// playing (i.e. he has a ship)
hud_update_reticle( pl->m_player );
threats = (ubyte)pl->m_player->threat_flags;
ADD_DATA( threats );
// add his energy level for guns
ADD_FLOAT(shipp->weapon_energy);
// add his secondary bank ammo
ADD_INT(shipp->weapons.num_secondary_banks);
for(i=0; i<shipp->weapons.num_secondary_banks; i++){
ADD_INT(shipp->weapons.secondary_bank_ammo[i]);
}
}
// add pl
ADD_INT(pl->sv_last_pl);
// send the packet reliably to the player
multi_io_send(pl, data, packet_size);
}
void process_client_update_packet(ubyte *data, header *hinfo)
{
ubyte val;
short pauser;
int player_index;
int is_paused, have_hull_info;
int ammo_count;
int ammo[10];
float weapon_energy;
int offset = HEADER_LENGTH;
// get the header byte containing useful information
GET_DATA(val);
is_paused = (val & UPDATE_IS_PAUSED)?1:0;
have_hull_info = (val & UPDATE_HULL_INFO)?1:0;
// if we are paused, get who paused
if(is_paused){
GET_SHORT(pauser);
player_index = find_player_id(pauser);
if(player_index != -1){
Multi_pause_pauser = &Net_players[player_index];
} else {
Multi_pause_pauser = NULL;
}
}
// if we have hull information, then read it in.
if ( have_hull_info ) {
float fl_val;
ship_info *sip;
ship *shipp;
ubyte hull_percent, shield_percent[MAX_SHIELD_SECTIONS], n_subsystems, subsystem_percent[MAX_MODEL_SUBSYSTEMS], threats;
ubyte ub_tmp;
ship_subsys *subsysp;
object *objp;
int i;
// hull strength and shield mesh information are floats (as a percentage). Pass the integer
// percentage value since that should be close enough
GET_DATA( hull_percent );
for (i = 0; i < MAX_SHIELD_SECTIONS; i++ ){
GET_DATA(ub_tmp);
shield_percent[i] = ub_tmp;
}
// get the data for the subsystems
GET_DATA( n_subsystems );
for ( i = 0; i < n_subsystems; i++ ){
GET_DATA(ub_tmp);
subsystem_percent[i] = ub_tmp;
}
GET_DATA( threats );
// add his energy level for guns
GET_FLOAT(weapon_energy);
// add his secondary bank ammo
GET_INT(ammo_count);
for(i=0; i<ammo_count; i++){
GET_INT(ammo[i]);
}
// assign the above information to my ship, assuming that I can find it! Ingame joiners might get this
// packet because of delay between reliable packet acknowledging my ingame ship and the start of these
// UDP client update packets. Only read this info if I have a ship.
if ( !(Net_player->flags & NETINFO_FLAG_INGAME_JOIN) && (Player_ship != NULL) && (Player_obj != NULL) && (Net_player != NULL)) {
shipp = Player_ship;
objp = Player_obj;
sip = &Ship_info[shipp->ship_info_index];
fl_val = hull_percent * shipp->ship_max_hull_strength / 100.0f;
objp->hull_strength = fl_val;
for ( i = 0; i < MAX_SHIELD_SECTIONS; i++ ) {
fl_val = (shield_percent[i] * get_max_shield_quad(objp) / 100.0f);
objp->shield_quadrant[i] = fl_val;
}
// for sanity, be sure that the number of susbystems that I read in matches the player. If not,
// then don't read these in.
if ( n_subsystems == sip->n_subsystems ) {
n_subsystems = 0; // reuse this variable
for ( subsysp = GET_FIRST(&shipp->subsys_list); subsysp != END_OF_LIST(&shipp->subsys_list); subsysp = GET_NEXT(subsysp) ) {
int subsys_type;
fl_val = subsystem_percent[n_subsystems] * subsysp->max_hits / 100.0f;
subsysp->current_hits = fl_val;
// add the value just generated (it was zero'ed above) into the array of generic system types
subsys_type = subsysp->system_info->type; // this is the generic type of subsystem
Assert ( subsys_type < SUBSYSTEM_MAX );
if (!(subsysp->flags & SSF_NO_AGGREGATE)) {
shipp->subsys_info[subsys_type].aggregate_current_hits += fl_val;
}
n_subsystems++;
}
}
ship_recalc_subsys_strength( shipp );
shipp->weapon_energy = weapon_energy;
for(i=0; i<ammo_count; i++){
shipp->weapons.secondary_bank_ammo[i] = ammo[i];
}
// update my threat flags.
// temporarily commented out until tested.
Net_player->m_player->threat_flags = threats;
}
}
// get pl
int pl;
GET_INT(pl);
if(Net_player != NULL){
Net_player->cl_last_pl = pl;
}
PACKET_SET_SIZE();
// note, if we're already paused or unpaused, calling these will have no effect, so it is safe to do so
if(!popup_active() && !(Net_player->flags & NETINFO_FLAG_RESPAWNING) && !(Net_player->flags & NETINFO_FLAG_LIMBO)){
if( is_paused ) {
multi_pause_pause();
} else {
multi_pause_unpause();
}
}
}
void send_countdown_packet(int time)
{
ubyte data[20];
char val;
int packet_size = 0;
// build the header and add the time
BUILD_HEADER(COUNTDOWN);
val = (char)time;
ADD_DATA(val);
// if we're the server, we should broadcast to everyone
if(Net_player->flags & NETINFO_FLAG_AM_MASTER){
multi_io_send_to_all_reliable(data, packet_size);
}
// otherwise we'de better be a host sending to the standalone
else {
Assert(Net_player->flags & NETINFO_FLAG_GAME_HOST);
multi_io_send_reliable(Net_player, data, packet_size);
}
}
void process_countdown_packet(ubyte *data, header *hinfo)
{
int offset = HEADER_LENGTH;
char time;
// get the time
GET_DATA(time);
PACKET_SET_SIZE();
// if we're not in the post sync data screen, ignore it
if(gameseq_get_state() != GS_STATE_MULTI_MISSION_SYNC){
return;
}
// if we're the standalone, this should be a -1 telling us to start the countdown
if(Game_mode & GM_STANDALONE_SERVER){
Assert((int)time == -1);
// start the countdown
multi_sync_start_countdown();
}
// otherwise if we're clients, just bash the countdown
else {
Multi_sync_countdown = (int)time;
}
}
// packets for debriefing information
void send_debrief_info( int stage_count[], int *stages[] )
{
ubyte data[MAX_PACKET_SIZE];
int packet_size, i, j;
int i_tmp;
BUILD_HEADER(DEBRIEF_INFO);
// add the data for the teams
for ( i = 0; i < Num_teams; i++ ) {
int count;
count = stage_count[i];
ADD_INT( count );
for ( j = 0; j < count; j++ ) {
i_tmp = stages[i][j];
ADD_INT( i_tmp );
}
}
multi_io_send_to_all_reliable(data, packet_size);
}
// process a debrief info packet from the server
void process_debrief_info( ubyte *data, header *hinfo )
{
int offset, i, j;
int stage_counts[MAX_TVT_TEAMS], active_stages[MAX_TVT_TEAMS][MAX_DEBRIEF_STAGES], *stages[MAX_TVT_TEAMS];
int i_tmp;
offset = HEADER_LENGTH;
for ( i = 0; i < Num_teams; i++ ) {
int count;
GET_INT( count );
stage_counts[i] = count;
stages[i] = active_stages[i];
for ( j = 0; j < count; j++ ) {
GET_INT(i_tmp);
active_stages[i][j] = i_tmp;
}
}
PACKET_SET_SIZE();
// now that we have the stage data for the debriefing stages, call debrief function with the
// data so that clients can now see the debriefing stuff. Do it only for my team.
Assert( (Net_player->p_info.team >= 0) && (Net_player->p_info.team < Num_teams) );
debrief_set_multi_clients( stage_counts[Net_player->p_info.team], stages[Net_player->p_info.team] );
}
// sends homing information to all clients. We only need signature and num_missiles (because of hornets).
// sends homing_object and homing_subsystem to all clients.
void send_homing_weapon_info( int weapon_num )
{
ubyte data[MAX_PACKET_SIZE];
char t_subsys;
int packet_size;
object *homing_object;
ushort homing_signature;
weapon *wp;
wp = &Weapons[weapon_num];
// be sure that this weapon object is a homing object.
if ( !(Weapon_info[wp->weapon_info_index].wi_flags & WIF_HOMING) )
return;
// default the subsystem
t_subsys = -1;
// get the homing signature. If this weapon isn't homing on anything, then sent 0 as the
// homing signature.
homing_signature = 0;
homing_object = wp->homing_object;
if ( homing_object != NULL ) {
homing_signature = homing_object->net_signature;
// get the subsystem index.
if ( (homing_object->type == OBJ_SHIP) && (wp->homing_subsys != NULL) ) {
int s_index;
s_index = ship_get_index_from_subsys( wp->homing_subsys, OBJ_INDEX(homing_object), 1 );
Assert( s_index < CHAR_MAX ); // better be less than this!!!!
t_subsys = (char)s_index;
}
}
BUILD_HEADER(HOMING_WEAPON_UPDATE);
ADD_USHORT( Objects[wp->objnum].net_signature );
ADD_USHORT( homing_signature );
ADD_DATA( t_subsys );
multi_io_send_to_all(data, packet_size);
}
// process a homing weapon info change packet. multiple_missiles parameter specifies is this
// packet contains information for multiple weapons (like hornets).
void process_homing_weapon_info( ubyte *data, header *hinfo )
{
int offset;
ushort weapon_signature, homing_signature;
char h_subsys;
object *homing_object, *weapon_objp;
weapon *wp;
offset = HEADER_LENGTH;
// get the data for the packet
GET_USHORT( weapon_signature );
GET_USHORT( homing_signature );
GET_DATA( h_subsys );
PACKET_SET_SIZE();
// deal with changing this weapons homing information
weapon_objp = multi_get_network_object( weapon_signature );
if ( weapon_objp == NULL ) {
nprintf(("Network", "Couldn't find weapon object for homing update -- skipping update\n"));
return;
}
Assert( weapon_objp->type == OBJ_WEAPON );
wp = &Weapons[weapon_objp->instance];
// be sure that we can find these weapons and
homing_object = multi_get_network_object( homing_signature );
if ( homing_object == NULL ) {
nprintf(("Network", "Couldn't find homing object for homing update\n"));
return;
}
if ( homing_object->type == OBJ_WEAPON ) {
int flags = Weapon_info[Weapons[homing_object->instance].weapon_info_index].wi_flags;
// Assert( (flags & WIF_BOMB) || (flags & WIF_CMEASURE) );
if ( !((flags & WIF_BOMB) || (flags & WIF_CMEASURE)) ) {
nprintf(("Network", "Homing object is invalid for homing update\n"));
return;
}
}
wp->homing_object = homing_object;
wp->homing_subsys = NULL;
wp->target_num = OBJ_INDEX(homing_object);
wp->target_sig = homing_object->signature;
if ( h_subsys != -1 ) {
Assert( homing_object->type == OBJ_SHIP );
wp->homing_subsys = ship_get_indexed_subsys( &Ships[homing_object->instance], h_subsys);
}
if ( homing_object->type == OBJ_SHIP ) {
nprintf(("Network", "Updating homing information for weapon -- homing on %s\n", Ships[homing_object->instance].ship_name));
}
}
void send_emp_effect(ushort net_sig, float intensity, float time)
{
ubyte data[25];
int packet_size;
Assert(MULTIPLAYER_MASTER);
// build the packet and add the opcode
BUILD_HEADER(EMP_EFFECT);
ADD_USHORT(net_sig);
ADD_FLOAT(intensity);
ADD_FLOAT(time);
// send it to the player
multi_io_send_to_all(data, packet_size);
}
void process_emp_effect(ubyte *data, header *hinfo)
{
float intensity, time;
ushort net_sig;
object *objp;
int offset = HEADER_LENGTH;
// read in the EMP effect data
GET_USHORT(net_sig);
GET_FLOAT(intensity);
GET_FLOAT(time);
PACKET_SET_SIZE();
// try and find the object
objp = multi_get_network_object(net_sig);
if((objp != NULL) && (objp->type == OBJ_SHIP)){
// if i'm not an observer and I have a valid ship, play the EMP effect
if(!(Net_player->flags & NETINFO_FLAG_OBSERVER) && (Player_obj != NULL) && (Player_obj->type == OBJ_SHIP) && (Player_obj == objp)){
emp_start_local(intensity, time);
}
// start the effect for the ship itself
emp_start_ship(objp, intensity, time);
}
}
// tells whether or not reinforcements are available
void send_reinforcement_avail( int rnum )
{
ubyte data[25];
int packet_size;
BUILD_HEADER(REINFORCEMENT_AVAIL);
ADD_INT( rnum );
multi_io_send_to_all_reliable(data, packet_size);
}
void process_reinforcement_avail( ubyte *data, header *hinfo )
{
int offset;
int rnum;
offset = HEADER_LENGTH;
GET_INT( rnum );
PACKET_SET_SIZE();
// sanity check for a valid reinforcement number
if ( (rnum >= 0) && (rnum < Num_reinforcements) ) {
Reinforcements[rnum].flags |= RF_IS_AVAILABLE;
}
}
void send_change_iff_packet(ushort net_signature, int new_team)
{
ubyte data[MAX_PACKET_SIZE];
int packet_size = 0;
if(Net_player == NULL){
return;
}
if(!(Net_player->flags & NETINFO_FLAG_AM_MASTER)){
return;
}
// build the packet and add the data
BUILD_HEADER(CHANGE_IFF);
ADD_USHORT(net_signature);
ADD_INT(new_team);
// send to all players
multi_io_send_to_all_reliable(data, packet_size);
}
void process_change_iff_packet( ubyte *data, header *hinfo)
{
int offset = HEADER_LENGTH;
ushort net_signature;
int new_team;
object *objp;
// get the data
GET_USHORT(net_signature);
GET_INT(new_team);
PACKET_SET_SIZE();
// lookup the object
objp = multi_get_network_object(net_signature);
if((objp != NULL) && (objp->type == OBJ_SHIP) && (objp->instance >=0)){
Ships[objp->instance].team = new_team;
}
}
void send_change_iff_color_packet(ushort net_signature, int observer_team, int observed_team, int alternate_iff_color)
{
ubyte data[MAX_PACKET_SIZE];
int packet_size = 0;
if(Net_player == NULL){
return;
}
if(!(Net_player->flags & NETINFO_FLAG_AM_MASTER)){
return;
}
// build the packet and add the data
BUILD_HEADER(CHANGE_IFF_COLOR);
ADD_USHORT(net_signature);
ADD_INT(observer_team);
ADD_INT(observed_team);
ADD_INT(alternate_iff_color);
// send to all players
multi_io_send_to_all_reliable(data, packet_size);
}
void process_change_iff_color_packet( ubyte *data, header *hinfo)
{
int offset = HEADER_LENGTH;
ushort net_signature;
int observer_team, observed_team, alternate_iff_color;
object *objp;
// get the data
GET_USHORT(net_signature);
GET_INT(observer_team);
GET_INT(observed_team);
GET_INT(alternate_iff_color);
PACKET_SET_SIZE();
// lookup the object
objp = multi_get_network_object(net_signature);
if((objp != NULL) && (objp->type == OBJ_SHIP) && (objp->instance >=0))
{
Ships[objp->instance].ship_iff_color[observer_team][observed_team] = alternate_iff_color;
}
}
void send_change_ai_class_packet(ushort net_signature, char *subsystem, int new_ai_class)
{
ubyte data[MAX_PACKET_SIZE];
int packet_size = 0;
if(Net_player == NULL){
return;
}
if(!(Net_player->flags & NETINFO_FLAG_AM_MASTER)){
return;
}
// build the packet and add the data
BUILD_HEADER(CHANGE_AI_CLASS);
ADD_USHORT(net_signature);
if (subsystem)
ADD_STRING(subsystem);
else
ADD_STRING(NO_SUBSYS_STRING);
ADD_INT(new_ai_class);
// send to all players
multi_io_send_to_all_reliable(data, packet_size);
}
void process_change_ai_class_packet(ubyte *data, header *hinfo)
{
int offset = HEADER_LENGTH;
ushort net_signature;
int new_ai_class;
char subsys_buf[255];
object *objp;
// get the data
GET_USHORT(net_signature);
GET_STRING(subsys_buf);
GET_INT(new_ai_class);
PACKET_SET_SIZE();
// lookup the object
objp = multi_get_network_object(net_signature);
if((objp != NULL) && (objp->type == OBJ_SHIP) && (objp->instance >=0))
{
// no subsystem?
if (!strcmp(subsys_buf, NO_SUBSYS_STRING))
{
ship_set_new_ai_class(objp->instance, new_ai_class);
}
// subsystem
else
{
ship_subsystem_set_new_ai_class(objp->instance, subsys_buf, new_ai_class);
}
}
}
void send_NEW_primary_fired_packet(ship *shipp, int banks_fired)
{
int packet_size, objnum;
ubyte data[MAX_PACKET_SIZE]; // ubanks_fired, current_bank;
object *objp;
int np_index;
net_player *ignore = NULL;
// get an object pointer for this ship.
objnum = shipp->objnum;
objp = &Objects[objnum];
// if i'm a multiplayer client, I should never send primary fired packets for anyone except me
if(MULTIPLAYER_CLIENT && (Player_obj != objp)){
return;
}
// just in case nothing got fired
if(banks_fired <= 0){
return;
}
// ubanks_fired = (ubyte)banks_fired;
// current_bank = (ubyte)shipp->weapons.current_primary_bank;
// Assert( current_bank <= 3 );
// insert the current primary bank into this byte
// ubanks_fired |= (current_bank << CURRENT_BANK_BIT);
// append the SF_PRIMARY_LINKED flag on the top nibble of the banks_fired
// if ( shipp->flags & SF_PRIMARY_LINKED ){
// ubanks_fired |= (1<<7);
// }
if(MULTIPLAYER_MASTER){
np_index = multi_find_player_by_net_signature(objp->net_signature);
if((np_index >= 0) && (np_index < MAX_PLAYERS)){
ignore = &Net_players[np_index];
}
}
// build up the standard weapon fired packet. This packet will get sent to all players if an AI
// ship fired the primary weapons. If a player fired the weapon, then this packet will get sent
// to every player but the guy who actullly fired the weapon. This method is used to help keep client
// and server in sync w.r.t. weapon energy for player ship
BUILD_HEADER( PRIMARY_FIRED_NEW );
ADD_USHORT(objp->net_signature);
// ADD_DATA(ubanks_fired);
// if I'm a server, broadcast to all players
if(MULTIPLAYER_MASTER){
multi_io_send_to_all(data, packet_size, ignore);
// TEST CODE
multi_rate_add(1, "wfi", packet_size);
}
// otherwise just send to the server
else {
multi_io_send(Net_player, data, packet_size);
}
}
void process_NEW_primary_fired_packet(ubyte *data, header *hinfo)
{
int offset; // linked;
// ubyte banks_fired, current_bank;
object* objp;
ship *shipp;
ushort shooter_sig;
// read all packet info
offset = HEADER_LENGTH;
GET_USHORT(shooter_sig);
// GET_DATA(banks_fired);
PACKET_SET_SIZE();
// find the object this fired packet is operating on
objp = multi_get_network_object( shooter_sig );
if ( objp == NULL ) {
nprintf(("Network", "Could not find ship for fire primary packet NEW!"));
return;
}
// if this object is not actually a valid ship, don't do anything
if(objp->type != OBJ_SHIP){
return;
}
// Juke - also check (objp->instance >= MAX_SHIPS)
if(objp->instance < 0 || objp->instance >= MAX_SHIPS){
return;
}
shipp = &Ships[objp->instance];
// get the link status of the primary banks
// linked = 0;
// if ( banks_fired & (1<<7) ) {
// linked = 1;
// banks_fired ^= (1<<7);
// }
// get the current primary bank
// current_bank = (ubyte)(banks_fired >> CURRENT_BANK_BIT);
// current_bank &= 0x3;
// Assert( (current_bank >= 0) && (current_bank < MAX_SHIP_PRIMARY_BANKS) );
// shipp->weapons.current_primary_bank = current_bank;
// strip off all remaining bits and just keep which banks were actually fired.
// banks_fired &= 0x3;
// set the link status of the ship if not the player. If it is the player, we will do sanity checking
// only (for now).
// if ( !linked ){
// shipp->flags &= ~SF_PRIMARY_LINKED;
// } else {
// shipp->flags |= SF_PRIMARY_LINKED;
// }
// if we're in client firing mode, ignore ones for myself
if((Player_obj != NULL) && (Player_obj == objp)){
return;
}
ship_fire_primary( objp, 0, 1 );
// Karajorma - It's still a hack but at least this way it only affects AI ships
if (!(objp->flags & OF_PLAYER_SHIP))
{
// Juke - this is the hackiest hack, but hopefully it will fix stream weapon
// notifications generated by AI ships.
uint flags = shipp->flags & SF_TRIGGER_DOWN;
shipp->flags |= SF_TRIGGER_DOWN;
ship_fire_primary( objp, 1, 1 );
shipp->flags &= flags | ~SF_TRIGGER_DOWN;
}
}
void send_NEW_countermeasure_fired_packet(object *objp, int cmeasure_count, int rand_val)
{
ubyte data[MAX_PACKET_SIZE];
int packet_size;
int np_index;
net_player *ignore = NULL;
// if i'm a multiplayer client, I should never send primary fired packets for anyone except me
if(MULTIPLAYER_CLIENT && (Player_obj != objp)){
return;
}
Assert ( cmeasure_count < UCHAR_MAX );
BUILD_HEADER(COUNTERMEASURE_NEW);
ADD_USHORT( objp->net_signature );
ADD_INT( rand_val );
nprintf(("Network","Sending NEW countermeasure packet!\n"));
// determine if its a player
if(MULTIPLAYER_MASTER){
np_index = multi_find_player_by_net_signature(objp->net_signature);
if((np_index >= 0) && (np_index < MAX_PLAYERS)){
ignore = &Net_players[np_index];
}
}
// if I'm the server, send to all players
if(MULTIPLAYER_MASTER){
multi_io_send_to_all(data, packet_size, ignore);
}
// otherwise send to the server
else {
multi_io_send(Net_player, data, packet_size);
}
}
void process_NEW_countermeasure_fired_packet(ubyte *data, header *hinfo)
{
int offset;
ushort signature;
int rand_val;
object *objp;
offset = HEADER_LENGTH;
GET_USHORT( signature );
GET_INT( rand_val );
PACKET_SET_SIZE();
objp = multi_get_network_object( signature );
if ( objp == NULL ) {
nprintf(("network", "Could find object whose countermeasures are being launched!!!\n"));
return;
}
if(objp->type != OBJ_SHIP){
return;
}
// if we're in client firing mode, ignore ones for myself
if((Player_obj != NULL) && (Player_obj == objp)){
return;
}
if ( (rand_val >= NPERM_SIG_MIN) && (rand_val <= NPERM_SIG_MAX) ) {
multi_set_network_signature((ushort)rand_val, MULTI_SIG_NON_PERMANENT);
}
// make it so ship can fire right away!
Ships[objp->instance].cmeasure_fire_stamp = timestamp(0);
if ( objp == Player_obj ){
nprintf(("network", "firing countermeasure from my ship\n"));
}
ship_launch_countermeasure( objp, rand_val );
}
void send_beam_fired_packet(object *shooter, ship_subsys *turret, object *target, int beam_info_index, beam_info *override, int bfi_flags, int bank_point)
{
ubyte data[MAX_PACKET_SIZE];
int packet_size = 0;
short u_beam_info;
char subsys_index;
beam_info b_info;
ushort target_sig;
// only the server should ever be doing this
Assert(MULTIPLAYER_MASTER);
// setup outgoing data
Assert(shooter != NULL);
Assert(turret != NULL);
Assert(override != NULL);
if((shooter == NULL) || (turret == NULL) || (override == NULL)){
return;
}
if (!(bfi_flags & BFIF_IS_FIGHTER_BEAM)) {
Assert(target != NULL);
if (target == NULL) {
return;
}
}
target_sig = (target) ? target->net_signature : 0;
u_beam_info = (short)beam_info_index;
if (bfi_flags & BFIF_IS_FIGHTER_BEAM) {
Assert( (bank_point >= 0) && (bank_point < UCHAR_MAX) );
subsys_index = (char)bank_point;
} else {
subsys_index = (char)ship_get_index_from_subsys(turret, OBJ_INDEX(shooter), 1);
}
Assert(subsys_index >= 0);
if (subsys_index < 0) {
return;
}
// swap the beam_info override info into little endian byte order
b_info.dir_a.xyz.x = INTEL_FLOAT(&override->dir_a.xyz.x);
b_info.dir_a.xyz.y = INTEL_FLOAT(&override->dir_a.xyz.y);
b_info.dir_a.xyz.z = INTEL_FLOAT(&override->dir_a.xyz.z);
b_info.dir_b.xyz.x = INTEL_FLOAT(&override->dir_b.xyz.x);
b_info.dir_b.xyz.y = INTEL_FLOAT(&override->dir_b.xyz.y);
b_info.dir_b.xyz.z = INTEL_FLOAT(&override->dir_b.xyz.z);
b_info.delta_ang = INTEL_FLOAT(&override->delta_ang);
b_info.shot_count = override->shot_count;
for (int i = 0; i < b_info.shot_count; i++) {
b_info.shot_aim[i] = INTEL_FLOAT(&override->shot_aim[i]);
}
// build the header
BUILD_HEADER(BEAM_FIRED);
ADD_USHORT(shooter->net_signature);
ADD_DATA(subsys_index);
ADD_USHORT(target_sig);
ADD_SHORT(u_beam_info);
ADD_DATA(b_info); // FIXME: This is still wrong, we shouldn't be sending an entire struct over the wire - taylor
// ADD_DATA(bfi_flags); // this breaks the protocol but is here in case we decided to do that in the future - taylor
// ADD_DATA(target_pos); // ditto - Goober5000
// send to all clients
multi_io_send_to_all_reliable(data, packet_size);
}
void process_beam_fired_packet(ubyte *data, header *hinfo)
{
int i, offset;
ushort shooter_sig, target_sig;
char subsys_index;
short u_beam_info;
beam_info b_info;
beam_fire_info fire_info;
// ubyte fighter_beam = 0;
// only clients should ever get this
Assert(MULTIPLAYER_CLIENT);
// read in packet data
offset = HEADER_LENGTH;
GET_USHORT(shooter_sig);
GET_DATA(subsys_index);
GET_USHORT(target_sig);
GET_SHORT(u_beam_info);
GET_DATA(b_info); // FIXME: This is still wrong, we shouldn't be sending an entire struct over the wire - taylor
// GET_DATA(fighter_beam); // this breaks the protocol but is here in case we decided to do that in the future - taylor
PACKET_SET_SIZE();
// swap the beam_info override info into native byte order
b_info.dir_a.xyz.x = INTEL_FLOAT(&b_info.dir_a.xyz.x);
b_info.dir_a.xyz.y = INTEL_FLOAT(&b_info.dir_a.xyz.y);
b_info.dir_a.xyz.z = INTEL_FLOAT(&b_info.dir_a.xyz.z);
b_info.dir_b.xyz.x = INTEL_FLOAT(&b_info.dir_b.xyz.x);
b_info.dir_b.xyz.y = INTEL_FLOAT(&b_info.dir_b.xyz.y);
b_info.dir_b.xyz.z = INTEL_FLOAT(&b_info.dir_b.xyz.z);
b_info.delta_ang = INTEL_FLOAT(&b_info.delta_ang);
for (i = 0; i < b_info.shot_count; i++) {
b_info.shot_aim[i] = INTEL_FLOAT(&b_info.shot_aim[i]);
}
memset(&fire_info, 0, sizeof(beam_fire_info));
// lookup all relevant data
fire_info.beam_info_index = (int)u_beam_info;
fire_info.shooter = NULL;
fire_info.target = NULL;
fire_info.turret = NULL;
fire_info.target_subsys = NULL;
fire_info.beam_info_override = NULL;
fire_info.shooter = multi_get_network_object(shooter_sig);
fire_info.target = multi_get_network_object(target_sig);
fire_info.beam_info_override = &b_info;
fire_info.accuracy = 1.0f;
if((fire_info.shooter == NULL) || (fire_info.shooter->type != OBJ_SHIP) || (fire_info.shooter->instance < 0) || (fire_info.shooter->instance > MAX_SHIPS)){
nprintf(("Network", "Couldn't get shooter info for BEAM weapon!\n"));
return;
}
ship *shipp = &Ships[fire_info.shooter->instance];
// this check is a little convoluted but should cover all bases until we decide to just break the protocol
if ( Ship_info[shipp->ship_info_index].flags & (SIF_FIGHTER | SIF_BOMBER) ) {
// make sure the beam is a primary weapon and not attached to a turret or something
for (i = 0; i < shipp->weapons.num_primary_banks; i++) {
if ( shipp->weapons.primary_bank_weapons[i] == fire_info.beam_info_index ) {
fire_info.bfi_flags |= BFIF_IS_FIGHTER_BEAM;
}
}
}
if ( !(fire_info.bfi_flags & BFIF_IS_FIGHTER_BEAM) && (fire_info.target == NULL) ) {
nprintf(("Network", "Couldn't get target info for BEAM weapon!\n"));
return;
}
if (fire_info.bfi_flags & BFIF_IS_FIGHTER_BEAM) {
polymodel *pm = model_get( Ship_info[shipp->ship_info_index].model_num );
float field_of_fire = Weapon_info[fire_info.beam_info_index].field_of_fire;
int bank = (ubyte)subsys_index % 10;
int point = (ubyte)subsys_index / 10;
fire_info.targeting_laser_offset = pm->gun_banks[bank].pnt[point];
shipp->beam_sys_info.turret_norm.xyz.x = 0.0f;
shipp->beam_sys_info.turret_norm.xyz.y = 0.0f;
shipp->beam_sys_info.turret_norm.xyz.z = 1.0f;
shipp->beam_sys_info.model_num = Ship_info[shipp->ship_info_index].model_num;
shipp->beam_sys_info.turret_gun_sobj = pm->detail[0];
shipp->beam_sys_info.turret_num_firing_points = 1;
shipp->beam_sys_info.turret_fov = (float)cos((field_of_fire != 0.0f) ? field_of_fire : 180);
shipp->beam_sys_info.pnt = fire_info.targeting_laser_offset;
shipp->beam_sys_info.turret_firing_point[0] = fire_info.targeting_laser_offset;
shipp->fighter_beam_turret_data.disruption_timestamp = timestamp(0);
shipp->fighter_beam_turret_data.turret_next_fire_pos = 0;
shipp->fighter_beam_turret_data.current_hits = 1.0;
shipp->fighter_beam_turret_data.system_info = &shipp->beam_sys_info;
fire_info.turret = &shipp->fighter_beam_turret_data;
fire_info.bank = bank;
} else {
fire_info.turret = ship_get_indexed_subsys(shipp, (int)subsys_index);
if (fire_info.turret == NULL) {
nprintf(("Network", "Couldn't get turret for BEAM weapon!\n"));
return;
}
}
// fire da beam
beam_fire(&fire_info);
}
void send_sw_query_packet(ubyte code, char *txt)
{
ubyte data[MAX_PACKET_SIZE];
int packet_size = 0;
// build the packet and add the code
BUILD_HEADER(SW_STD_QUERY);
ADD_DATA(code);
if((code == SW_STD_START) || (code == SW_STD_BAD)){
ADD_STRING(txt);
}
// if I'm the host, send to standalone
if(MULTIPLAYER_HOST){
Assert(!MULTIPLAYER_MASTER);
Assert(code == SW_STD_START);
multi_io_send_reliable(Net_player, data, packet_size);
}
// otherwise standalone sends back to host
else {
Assert(Game_mode & GM_STANDALONE_SERVER);
Assert(code != SW_STD_START);
Assert(Netgame.host != NULL);
if(Netgame.host != NULL){
multi_io_send_reliable(Netgame.host, data, packet_size);
}
}
}
void process_sw_query_packet(ubyte *data, header *hinfo)
{
}
void send_event_update_packet(int event)
{
ubyte data[MAX_PACKET_SIZE];
ushort u_event = (ushort)event;
int packet_size = 0;
// build the header and add the event
BUILD_HEADER(EVENT_UPDATE);
ADD_USHORT(u_event);
ADD_INT(Mission_events[event].flags);
ADD_INT(Mission_events[event].formula);
ADD_INT(Mission_events[event].result);
ADD_INT(Mission_events[event].count);
// send to all players
multi_io_send_to_all_reliable(data, packet_size);
}
void process_event_update_packet(ubyte *data, header *hinfo)
{
int offset = HEADER_LENGTH;
int store_flags;
ushort u_event;
// get the data
GET_USHORT(u_event);
store_flags = Mission_events[u_event].flags;
GET_INT(Mission_events[u_event].flags);
GET_INT(Mission_events[u_event].formula);
GET_INT(Mission_events[u_event].result);
GET_INT(Mission_events[u_event].count);
PACKET_SET_SIZE();
// went from non directive special to directive special
if(!(store_flags & MEF_DIRECTIVE_SPECIAL) && (Mission_events[u_event].flags & MEF_DIRECTIVE_SPECIAL)){
mission_event_set_directive_special(u_event);
}
// if we went directive special to non directive special
else if((store_flags & MEF_DIRECTIVE_SPECIAL) && !(Mission_events[u_event].flags & MEF_DIRECTIVE_SPECIAL)){
mission_event_unset_directive_special(u_event);
}
}
void send_weapon_or_ammo_changed_packet (int ship_index, int bank_type, int bank_number, int ammo_left, int rearm_limit, int new_weapon_index)
{
ubyte data[MAX_PACKET_SIZE];
int packet_size = 0;
if(Net_player == NULL){
return;
}
if(!(Net_player->flags & NETINFO_FLAG_AM_MASTER)){
return;
}
// build the packet and add the data
BUILD_HEADER(WEAPON_OR_AMMO_CHANGED);
ADD_INT(ship_index);
ADD_INT(bank_type);
ADD_INT(bank_number);
ADD_INT(ammo_left);
ADD_INT(rearm_limit);
ADD_INT(new_weapon_index);
//Send it to the player whose weapons have changes
multi_io_send_to_all_reliable(data, packet_size);
}
void process_weapon_or_ammo_changed_packet(ubyte *data, header *hinfo)
{
int offset = HEADER_LENGTH;
int ship_index, bank_type, bank_number, ammo_left, rearm_limit, new_weapon_index;
ship *shipp;
// get the data
GET_INT(ship_index);
GET_INT(bank_type);
GET_INT(bank_number);
GET_INT(ammo_left);
GET_INT(rearm_limit);
GET_INT(new_weapon_index);
PACKET_SET_SIZE();
// Now set the ships values up.
//Primary weapons
if (bank_type == 0)
{
// don't swap weapons
if (new_weapon_index < 0)
{
set_primary_ammo(ship_index, bank_number, ammo_left, rearm_limit);
}
else
{
Assert (new_weapon_index < MAX_WEAPON_TYPES);
shipp = &Ships[ship_index];
shipp->weapons.primary_bank_weapons[bank_number] = new_weapon_index;
set_primary_ammo(Player_obj->instance, bank_number, ammo_left, rearm_limit);
}
}
// Secondary weapons
else if (bank_type == 1)
{
// don't swap weapons
if (new_weapon_index < 0)
{
set_secondary_ammo(ship_index, bank_number, ammo_left, rearm_limit);
}
else
{
Assert (new_weapon_index < MAX_WEAPON_TYPES);
shipp = &Ships[ship_index];
shipp->weapons.secondary_bank_weapons[bank_number] = new_weapon_index;
set_secondary_ammo(Player_obj->instance, bank_number, ammo_left, rearm_limit);
}
}
else
{
nprintf(("network", "weapon_or_ammo_changed_packet recived for tertiary or other unsupported type\n"));
return;
}
}
// Karajorma - Sends a packet to all clients telling them that a SEXP variable has changed its value
void send_variable_update_packet(int variable_index, char *value)
{
ubyte data[MAX_PACKET_SIZE];
int packet_size = 0;
if(Net_player == NULL){
return;
}
if(!(Net_player->flags & NETINFO_FLAG_AM_MASTER)){
return;
}
// build the packet and add the data
BUILD_HEADER(VARIABLE_UPDATE);
ADD_INT(variable_index);
ADD_STRING(value);
if (MULTIPLAYER_MASTER) {
// send to all players
multi_io_send_to_all_reliable(data, packet_size);
}
else {
multi_io_send_reliable(Net_player, data, packet_size);
}
}
void process_variable_update_packet( ubyte *data, header *hinfo)
{
int offset = HEADER_LENGTH;
char value[TOKEN_LENGTH];
int variable_index;
// get the data
GET_INT(variable_index);
GET_STRING(value);
PACKET_SET_SIZE();
// set the sexp_variable
if ( (variable_index >= 0) && (variable_index < sexp_variable_count()) )
{
strcpy_s(Sexp_variables[variable_index].text, value);
}
// send the packet on to all clients.
if (MULTIPLAYER_MASTER) {
send_variable_update_packet(variable_index, Sexp_variables[variable_index].text);
}
}
// weapon detonate packet
void send_weapon_detonate_packet(object *objp)
{
ubyte data[MAX_PACKET_SIZE];
int packet_size = 0;
// sanity checks
Assert(MULTIPLAYER_MASTER);
if(!MULTIPLAYER_MASTER){
return;
}
Assert(objp != NULL);
if(objp == NULL){
return;
}
// build the header and add the data
BUILD_HEADER(WEAPON_DET);
ADD_USHORT(objp->net_signature);
// send to all players
multi_io_send_to_all(data, packet_size);
}
void process_weapon_detonate_packet(ubyte *data, header *hinfo)
{
ushort net_sig;
int offset = HEADER_LENGTH;
object *objp = NULL;
// get the weapon signature
GET_USHORT(net_sig);
PACKET_SET_SIZE();
// lookup the weapon
objp = multi_get_network_object(net_sig);
if((objp != NULL) && (objp->type == OBJ_WEAPON) && (objp->instance >= 0)){
weapon_detonate(objp);
}
}
// flak fired packet
void send_flak_fired_packet(int ship_objnum, int subsys_index, int weapon_objnum, float flak_range)
{
int packet_size;
ushort pnet_signature;
ubyte data[MAX_PACKET_SIZE], cindex;
object *objp;
ship_subsys *ssp;
short val;
// sanity
if((weapon_objnum < 0) || (Objects[weapon_objnum].type != OBJ_WEAPON) || (Objects[weapon_objnum].instance < 0) || (Weapons[Objects[weapon_objnum].instance].weapon_info_index < 0)){
return;
}
// local setup -- be sure we are actually passing a weapon!!!!
objp = &Objects[weapon_objnum];
Assert ( objp->type == OBJ_WEAPON );
pnet_signature = Objects[ship_objnum].net_signature;
Assert( subsys_index < UCHAR_MAX );
cindex = (ubyte)subsys_index;
ssp = ship_get_indexed_subsys( &Ships[Objects[ship_objnum].instance], subsys_index, NULL );
if(ssp == NULL){
return;
}
// build the fire turret packet.
BUILD_HEADER(FLAK_FIRED);
packet_size += multi_pack_unpack_position(1, data + packet_size, &objp->orient.vec.fvec);
ADD_USHORT( pnet_signature );
ADD_DATA( cindex );
val = (short)ssp->submodel_info_1.angs.h;
ADD_SHORT( val );
val = (short)ssp->submodel_info_2.angs.p;
ADD_SHORT( val );
ADD_FLOAT( flak_range );
multi_io_send_to_all(data, packet_size);
multi_rate_add(1, "flk", packet_size);
}
void process_flak_fired_packet(ubyte *data, header *hinfo)
{
int offset, weapon_objnum, wid = -1;
ushort pnet_signature;
vec3d pos, dir;
matrix orient;
vec3d o_fvec;
ubyte turret_index;
object *objp;
ship_subsys *ssp;
ship *shipp;
short pitch, heading;
float flak_range;
// get the data for the turret fired packet
offset = HEADER_LENGTH;
offset += multi_pack_unpack_position(0, data + offset, &o_fvec);
GET_USHORT( pnet_signature );
GET_DATA( turret_index );
GET_SHORT( heading );
GET_SHORT( pitch );
GET_FLOAT( flak_range );
PACKET_SET_SIZE(); // move our counter forward the number of bytes we have read
// find the object
objp = multi_get_network_object( pnet_signature );
if ( objp == NULL ) {
nprintf(("network", "could find parent object with net signature %d for flak firing\n", pnet_signature));
return;
}
// if this isn't a ship, do nothing
if ( objp->type != OBJ_SHIP ){
return;
}
// make an orientation matrix from the o_fvec
vm_vector_2_matrix(&orient, &o_fvec, NULL, NULL);
// find this turret, and set the position of the turret that just fired to be where it fired. Quite a
// hack, but should be suitable.
shipp = &Ships[objp->instance];
ssp = ship_get_indexed_subsys( shipp, turret_index, NULL );
if(ssp == NULL){
return;
}
if (ssp->weapons.num_primary_banks > 0) {
wid = ssp->weapons.primary_bank_weapons[0];
} else if (ssp->weapons.num_secondary_banks > 0) {
wid = ssp->weapons.secondary_bank_weapons[0];
}
if((wid < 0) || !(Weapon_info[wid].wi_flags & WIF_FLAK)){
return;
}
// bash the position and orientation of the turret
ssp->submodel_info_1.angs.h = (float)heading;
ssp->submodel_info_2.angs.p = (float)pitch;
// get the world position of the weapon
ship_get_global_turret_info(objp, ssp->system_info, &pos, &dir);
// create the weapon object
weapon_objnum = weapon_create( &pos, &orient, wid, OBJ_INDEX(objp), -1, 1, 0, 0.0f, ssp);
wid = Weapons[Objects[weapon_objnum].instance].weapon_info_index;
if (weapon_objnum != -1) {
if ( Weapon_info[wid].launch_snd != -1 ) {
snd_play_3d( &Snds[Weapon_info[wid].launch_snd], &pos, &View_position );
}
// create a muzzle flash from a flak gun based upon firing position and weapon type
flak_muzzle_flash(&pos, &dir, &objp->phys_info, wid);
// set its range explicitly - make it long enough so that it's guaranteed to still exist when the server tells us it blew up
flak_set_range(&Objects[weapon_objnum], (float)flak_range);
}
}
#define ADD_NORM_VEC(d) do { Assert((packet_size + 3) < MAX_PACKET_SIZE); char vnorm[3] = { (char)(d.x * 127.0f), (char)(d.y * 127.0f), (char)(d.z * 127.0f) }; memcpy(data + packet_size, vnorm, 3); packet_size += 3; } while(0);
#define GET_NORM_VEC(d) do { char vnorm[3]; memcpy(vnorm, data+offset, 3); d.x = (float)vnorm[0] / 127.0f; d.y = (float)vnorm[1] / 127.0f; d.z = (float)vnorm[2] / 127.0f; } while(0);
// player pain packet
void send_player_pain_packet(net_player *pl, int weapon_info_index, float damage, vec3d *force, vec3d *hitpos)
{
ubyte data[MAX_PACKET_SIZE];
short windex;
ushort udamage;
int packet_size = 0;
Assert(MULTIPLAYER_MASTER);
if(!MULTIPLAYER_MASTER){
return;
}
Assert(pl != NULL);
if(pl == NULL){
return;
}
// build the packet and add the code
BUILD_HEADER(NETPLAYER_PAIN);
windex = (short)weapon_info_index;
ADD_SHORT(windex);
udamage = (ushort)damage;
ADD_USHORT(udamage);
ADD_VECTOR((*force));
ADD_VECTOR((*hitpos));
// send to the player
multi_io_send(pl, data, packet_size);
multi_rate_add(1, "pai", packet_size);
}
void process_player_pain_packet(ubyte *data, header *hinfo)
{
int offset;
short windex = 0;
ushort udamage;
vec3d force;
vec3d local_hit_pos;
weapon_info *wip;
// get the data for the pain packet
offset = HEADER_LENGTH;
GET_SHORT(windex);
GET_USHORT(udamage);
GET_VECTOR(force);
GET_VECTOR(local_hit_pos);
PACKET_SET_SIZE();
// mprintf(("PAIN!\n"));
// get weapon info pointer
Assert((windex < Num_weapon_types) && (Weapon_info[windex].subtype == WP_LASER));
if(! ((windex < Num_weapon_types) && (Weapon_info[windex].subtype == WP_LASER)) ){
return;
}
wip = &Weapon_info[windex];
// play the weapon hit sound
Assert(Player_obj != NULL);
if(Player_obj == NULL){
return;
}
//Assume the weapon is armed -WMC
weapon_hit_do_sound(Player_obj, wip, &Player_obj->pos, true);
// we need to do 3 things here. player pain (game flash), weapon hit sound, ship_apply_whack()
ship_hit_pain((float)udamage);
// apply the whack
ship_apply_whack(&force, &local_hit_pos, Player_obj);
}
// lightning packet
void send_lightning_packet(int bolt_type, vec3d *start, vec3d *strike)
{
ubyte data[MAX_PACKET_SIZE];
char val;
int packet_size = 0;
// build the header and add the data
BUILD_HEADER(LIGHTNING_PACKET);
val = (char)bolt_type;
ADD_DATA(val);
ADD_VECTOR((*start));
ADD_VECTOR((*strike));
// send to everyone unreliable for now
multi_io_send_to_all(data, packet_size);
}
void process_lightning_packet(ubyte *data, header *hinfo)
{
int offset;
char bolt_type;
vec3d start, strike;
// read the data
offset = HEADER_LENGTH;
GET_DATA(bolt_type);
GET_VECTOR(start);
GET_VECTOR(strike);
PACKET_SET_SIZE();
// invalid bolt?
if(bolt_type < 0){
return;
}
// fire it up
nebl_bolt(bolt_type, &start, &strike);
}
void send_bytes_recvd_packet(net_player *pl)
{
// only clients should ever be doing this
if(pl == NULL){
return;
}
ubyte data[MAX_PACKET_SIZE];
int packet_size = 0;
BUILD_HEADER(BYTES_SENT);
ADD_INT(pl->cl_bytes_recvd);
// send to the server
multi_io_send_reliable(pl, data, packet_size);
}
void process_bytes_recvd_packet(ubyte *data, header *hinfo)
{
int bytes;
int pid;
net_player *pl = NULL;
int offset = HEADER_LENGTH;
GET_INT(bytes);
PACKET_SET_SIZE();
// not server?
if(Net_player == NULL){
return;
}
if(!MULTIPLAYER_MASTER){
return;
}
// make sure we know what player sent this
pid = find_player_id(hinfo->id);
if((pid < 0) || (pid >= MAX_PLAYERS)){
return;
}
pl = &Net_players[pid];
// compute his pl
pl->cl_bytes_recvd = bytes;
if(bytes < 0){
return;
}
pl->sv_last_pl = (int)(100.0f * (1.0f - ((float)pl->cl_bytes_recvd / (float)pl->sv_bytes_sent)));
// reset bytes sent
pl->sv_bytes_sent = 0;
}
// host transfer
void send_host_captain_change_packet(short player_id, int captain_change)
{
ubyte data[MAX_PACKET_SIZE];
int packet_size = 0;
// build the packet
BUILD_HEADER(TRANSFER_HOST);
ADD_SHORT(player_id);
ADD_INT(captain_change);
// send to all
multi_io_send_to_all_reliable(data, packet_size);
}
void process_host_captain_change_packet(ubyte *data, header *hinfo)
{
int offset = HEADER_LENGTH;
int idx, found_player, captain_change;
short player_id;
// get the player id
GET_SHORT(player_id);
GET_INT(captain_change);
PACKET_SET_SIZE();
// captain change
if(captain_change){
// flag the new guy
for(idx=0; idx<MAX_PLAYERS; idx++){
if(MULTI_CONNECTED(Net_players[idx]) && (Net_players[idx].player_id == player_id)){
HUD_printf("%s is the new captain of team %d", Net_players[idx].m_player->callsign, Net_players[idx].p_info.team + 1);
break;
}
}
} else {
// unflag all old players
for(idx=0; idx<MAX_PLAYERS; idx++){
Net_players[idx].flags &= ~NETINFO_FLAG_GAME_HOST;
}
// flag the new guy
found_player = 0;
for(idx=0; idx<MAX_PLAYERS; idx++){
if(MULTI_CONNECTED(Net_players[idx]) && (Net_players[idx].player_id == player_id)){
Net_players[idx].flags |= NETINFO_FLAG_GAME_HOST;
// spew to the HUD config
if(Net_players[idx].m_player != NULL){
HUD_printf("%s is the new game host", Net_players[idx].m_player->callsign);
}
found_player = 1;
break;
}
}
// doh
if(!found_player){
multi_quit_game(PROMPT_NONE, MULTI_END_NOTIFY_NONE, MULTI_END_ERROR_HOST_LEFT);
}
}
}
void send_self_destruct_packet()
{
ubyte data[MAX_PACKET_SIZE];
int packet_size = 0;
// bogus
if(Net_player == NULL){
return;
}
// if i'm the server, I shouldn't be here
Assert(!(Net_player->flags & NETINFO_FLAG_AM_MASTER));
if(Net_player->flags & NETINFO_FLAG_AM_MASTER){
return;
}
// only if this is valid
if(MULTI_OBSERVER(Net_players[MY_NET_PLAYER_NUM])){
return;
}
// bogus object?
if((Player_ship == NULL) || (Player_obj == NULL)){
return;
}
// self destruct
BUILD_HEADER(SELF_DESTRUCT);
ADD_USHORT(Player_obj->net_signature);
// send to the server
multi_io_send_reliable(Net_player, data, packet_size);
}
void process_self_destruct_packet(ubyte *data, header *hinfo)
{
int offset = HEADER_LENGTH;
ushort net_sig;
int np_index;
// get the net signature
GET_USHORT(net_sig);
PACKET_SET_SIZE();
// get the player
np_index = find_player_id(hinfo->id);
if(np_index < 0){
return;
}
if(MULTI_OBSERVER(Net_players[np_index])){
return;
}
if(Net_players[np_index].m_player == NULL){
return;
}
if((Net_players[np_index].m_player->objnum < 0) || (Net_players[np_index].m_player->objnum >= MAX_OBJECTS)){
return;
}
if(Objects[Net_players[np_index].m_player->objnum].net_signature != net_sig){
return;
}
if(Objects[Net_players[np_index].m_player->objnum].type != OBJ_SHIP){
return;
}
if((Objects[Net_players[np_index].m_player->objnum].instance < 0) || (Objects[Net_players[np_index].m_player->objnum].instance >= MAX_SHIPS)){
return;
}
// do eet
ship_self_destruct(&Objects[Net_players[np_index].m_player->objnum]);
}
void send_sexp_packet(ubyte *sexp_packet, int num_ubytes)
{
ubyte data[MAX_PACKET_SIZE];
int packet_size = 0;
int i;
ushort val;
Assert (MULTIPLAYER_MASTER);
// must have a bare minimum of OP, COUNT and TERMINATOR
if (num_ubytes < 9) {
Warning(LOCATION, "Invalid call to send_sexp_packet. Not enough data included!");
return;
}
BUILD_HEADER(SEXP);
val = (ushort)num_ubytes;
ADD_USHORT(val);
for (i =0; i < num_ubytes; i++) {
Assert (packet_size < MAX_PACKET_SIZE);
data[packet_size] = sexp_packet[i];
packet_size++;
}
// send to all
multi_io_send_to_all_reliable(data, packet_size);
}
void process_sexp_packet(ubyte *data, header *hinfo)
{
int offset = HEADER_LENGTH;
int i;
ushort num_ubytes;
ubyte received_packet[MAX_PACKET_SIZE];
// get the number of bytes of data in the packet
GET_USHORT(num_ubytes);
for (i=0; i < num_ubytes; i++) {
GET_DATA(received_packet[i]);
}
PACKET_SET_SIZE();
sexp_packet_received(received_packet, num_ubytes);
}
|