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
|
/*
* Copyright (C) Volition, Inc. 2005. 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.
*
*/
#ifndef _WIN32
#include <netinet/in.h>
#endif
#include "freespace.h"
#include "io/timer.h"
#include "gamesequence/gamesequence.h"
#include "popup/popup.h"
#include "network/psnet2.h"
#include "network/valid.h" // tracker API
#include "network/gtrack.h" // tracker API
#include "network/ptrack.h" // tracker API
#include "network/multi.h"
#include "network/multi_fstracker.h"
#include "network/multiutil.h"
#include "network/multiui.h"
#include "network/multimsgs.h"
#include "network/multi_log.h"
#include "network/stand_gui.h"
#include "network/multi_pmsg.h"
#include "playerman/player.h"
#include "pilotfile/pilotfile.h"
#include "stats/medals.h"
// -----------------------------------------------------------------------------------
// FREESPACE MASTER TRACKER DEFINES/VARS
//
// if the fs tracker module has been successfully initialized
static int Multi_fs_tracker_inited = 0;
// if we're currently performing some operation with the tracker
static int Multi_fs_tracker_busy = 0;
// channel to associate when creating a server
char Multi_fs_tracker_channel[MAX_PATH] = "";
// channel to use when polling the tracker for games
char Multi_fs_tracker_filter[MAX_PATH] = "";
// used for mod detection
short Multi_fs_tracker_game_id = -1;
SCP_string Multi_fs_tracker_game_name;
SCP_string Multi_fs_tracker_game_tag;
enum PROBE_FLAGS {
PENDING = (1<<0),
SUCCESS = (1<<1),
FAILURE = (1<<2)
};
// -----------------------------------------------------------------------------------
// FREESPACE MASTER TRACKER FORWARD DECLARATIONS
//
// used with popup_till_condition() for validating freespace pilots
#define MT_VALIDATE_NOT_DONE 0 // still in the process of validation
#define MT_VALIDATE_SUCCEED 1 // successfully validated the pilot
#define MT_VALIDATE_FAIL 2 // failed in validating the pilot
#define MT_VALIDATE_TIMEOUT 3 // timedout on contacting the tracker
#define MT_VALIDATE_CANCEL 4 // if the action was cancelled
#define MT_PILOT_VAL_TIMEOUT 5000 // timeout for validating a pilot
static int Multi_validate_mode; // 0 == getting player id, 1 == getting player stats
int multi_fs_validate_process();
// used with popup_till_condition() for logging in freespace games
#define MT_LOGIN_NOT_DONE 0 // still in the process of logging in
#define MT_LOGIN_SUCCEED 1 // successfully logged the game in
#define MT_LOGIN_TIMEOUT 2 // timedout on contacting the tracker
// used with popup_till_condition() for storing player stats at the end of a freespace game
#define MT_STATS_NOT_DONE 0 // still in the process of storing stats
#define MT_STATS_SUCCEED 1 // successfully logged all player stats
// used with popup_till_condition() for validating missions
#define MT_MVALID_NOT_DONE 0 // still in the process of validating
#define MT_MVALID_VALID 1 // mission is valid
#define MT_MVALID_INVALID 2 // mission is invalid
#define MT_MVALID_ERROR 3 // error while performing operation. assume invalid
// store stats mode defined
#define MT_STORE_STATS_VALIDATE 0
#define MT_STORE_STATS_GET_STATS 1
#define MT_STORE_STATS_ACCEPT 2
#define MT_STORE_STATS_SEND_STATS 3
static int Multi_store_stats_mode; // 0 == initial request for player stats, 1 == waiting for player stats, 2 == tallying stats locally, 3 == sending stats to tracker
static int Multi_store_stats_player_index; // player we're currently working with
static int Multi_store_stats_player_flag; // if we're finished with the current guy
static vmt_stats_struct Multi_store_stats_stats; //
int multi_fs_store_stats_do(); // manage all master tracker stats storing
int multi_fs_store_stats_get_next_player(int cur_player);
static int Multi_tracker_player_is_valid = 0;
static int Multi_tracker_got_response = 0;
// copy a freespace stats struct to a tracker-freespace stats struct
void multi_stats_fs_to_tracker(scoring_struct *fs, vmt_stats_struct *vmt, player *pl, int tracker_id);
// copy a tracker-freespace stats struct to a freespace stats struct
void multi_stats_tracker_to_fs(vmt_stats_struct *vmt, scoring_struct *fs);
// process an incoming active game item
void multi_fs_tracker_process_game_item(game_list *gl);
// verify that there are no duplicate tracker id's to this one
void multi_fs_tracker_check_dup(int tracker_id,int player_index);
// verify that there are no duplicate pilot callsigns
void multi_fs_tracker_check_dup_callsign(net_player *player,int player_index);
// report on the results of the stats store procedure
void multi_fs_tracker_report_stats_results();
// tracker specific data structures
static pxo_net_game_data Multi_tracker_game_data;
static vmt_stats_struct Multi_tracker_fs_pilot;
static squad_war_response Multi_tracker_sw_response;
#define PXO_DEFAULT_TRACKER "tracker.pxo.nottheeye.com"
#define PXO_WEBSITE_URL "http://pxo.nottheeye.com" // NOTE: *must* be http: for compatiblity
// -----------------------------------------------------------------------------------
// FREESPACE MASTER TRACKER DEFINITIONS
//
// give some processor time to the tracker API
void multi_fs_tracker_process()
{
game_list *gl;
PSNET_TOP_LAYER_PROCESS();
if(Multi_fs_tracker_inited){
// pilot validation system
ValidIdle();
// pilot tracing system
PollPTrackNet();
// game tracking system
IdleGameTracker();
// set if we've got any pending game list items
gl = GetGameList();
if(gl != nullptr){
multi_fs_tracker_process_game_item(gl);
gl = nullptr;
}
}
}
// initialize the master tracker API for Freespace
void multi_fs_tracker_init()
{
// don't do anything if we're already initialized
if(Multi_fs_tracker_inited){
return;
}
// initialize the low-level validation stuff
if(!InitValidateClient()){
ml_printf("Error initializing tracker api (validateclient)");
return;
}
// initialize the low-level pilot tracking stuff
if(!InitPilotTrackerClient()){
ml_printf("Error initializing tracker api (pilotclient)");
return;
}
// intialize the low-level game tracking stuff
if(!InitGameTrackerClient(GT_FS2OPEN)){
ml_printf("Error initializing tracker api (gameclient)");
return;
}
nprintf(("Network","Successfully initialized tracker api\n"));
// we've successfully initialized the tracker stuff
Multi_fs_tracker_inited = 1;
}
// validate the current player with the master tracker (will create the pilot on the MT if necessary)
int multi_fs_tracker_validate(int show_error)
{
validate_id_request vir;
if(!Multi_fs_tracker_inited){
popup(PF_USE_AFFIRMATIVE_ICON,1,POPUP_OK,XSTR("Warning, Parallax Online startup failed. Will not be able to play tracker games!",666));
return 0;
}
// set this to false for now
Multi_tracker_player_is_valid = 0;
Multi_tracker_got_response = 0;
// mark the module as busy
Multi_fs_tracker_busy = 1;
while (true) {
// validate our pilot on the master tracker if possible
memset(&vir,0,sizeof(vir));
SDL_zero(Multi_tracker_id_string);
SDL_strlcpy(vir.login, Multi_tracker_login, SDL_arraysize(vir.login));
SDL_strlcpy(vir.password, Multi_tracker_passwd, SDL_arraysize(vir.password));
ValidateUser(&vir,Multi_tracker_id_string);
// set validation mode
Multi_validate_mode = 0;
int rval = popup_till_condition(multi_fs_validate_process,XSTR("&Cancel",667),XSTR("Attempting to validate pilot ...",668));
switch(rval){
// if we failed for one reason or another
case MT_VALIDATE_FAIL :
// if we're supposed to show error codes
if(show_error){
popup(PF_USE_AFFIRMATIVE_ICON | PF_BODY_BIG,1,XSTR("&Ok",669),XSTR("Pilot rejected by Parallax Online!",670));
}
Multi_validate_mode = -1;
Multi_fs_tracker_busy = 0;
return 0;
case MT_VALIDATE_SUCCEED :
// notify the user
if(Multi_tracker_fs_pilot.virgin_pilot){
multi_common_add_notify(XSTR("Successfully created and validated new pilot!",671));
} else {
multi_common_add_notify(XSTR("Parallax Online pilot validation succeeded!",672));
}
// copy my statistics into my pilot file
multi_stats_tracker_to_fs(&Multi_tracker_fs_pilot,&Player->stats);
Pilot.set_multi_stats(&Player->stats);
Multi_validate_mode = -1;
Multi_fs_tracker_busy = 0;
return 1;
case MT_VALIDATE_TIMEOUT :
rval = popup(PF_USE_AFFIRMATIVE_ICON | PF_USE_NEGATIVE_ICON | PF_BODY_BIG,2,XSTR("&Abort",673),XSTR("&Retry",674),XSTR("Validation timed out",675));
// if the user clicked abort, then leave. otherwise try again
if(rval == 0){
Multi_validate_mode = -1;
Multi_fs_tracker_busy = 0;
return 0;
}
break;
default :
Multi_validate_mode = -1;
Multi_fs_tracker_busy = 0;
// essentially, cancel
return -1;
}
}
}
// attempt to log the current game server in with the master tracker
void multi_fs_tracker_login_freespace()
{
if(!Multi_fs_tracker_inited){
if ( !(Game_mode & GM_STANDALONE_SERVER) ) {
popup(PF_USE_AFFIRMATIVE_ICON,1,POPUP_OK,XSTR("Warning, Parallax Online startup failed. Will not be able to play tracker games!",666));
}
return;
}
// if we're already logged into a game, don't do anything
if ( !(Net_player->flags & NETINFO_FLAG_AM_MASTER) || (Net_player->flags & NETINFO_FLAG_MT_CONNECTED) ) {
return;
}
// pretty much all we do is make 1 call
memset(&Multi_tracker_game_data, 0, sizeof(Multi_tracker_game_data));
SDL_strlcpy(Multi_tracker_game_data.game_name, Netgame.name, SDL_arraysize(Multi_tracker_game_data.game_name));
Multi_tracker_game_data.type = Netgame.type_flags;
Multi_tracker_game_data.state = Netgame.game_state;
Multi_tracker_game_data.max_players = MAX_PLAYERS;
Multi_tracker_game_data.current_num_players = 0;
// repurpose difficulty field to be netgame mode (both otherwise unused)
if (Netgame.mode == NG_MODE_RANK_BELOW) {
Multi_tracker_game_data.difficulty = -(100 + Netgame.rank_base);
} else if (Netgame.mode == NG_MODE_RANK_ABOVE) {
Multi_tracker_game_data.difficulty = (100 + Netgame.rank_base);
} else {
Multi_tracker_game_data.difficulty = Netgame.mode;
}
// if we have a valid channel string, use it
if(strlen(Multi_fs_tracker_channel)){
SDL_strlcpy(Multi_tracker_game_data.channel, Multi_fs_tracker_channel, SDL_arraysize(Multi_tracker_game_data.channel));
}
StartTrackerGame(&Multi_tracker_game_data);
Net_player->flags |= NETINFO_FLAG_MT_CONNECTED;
// NETLOG
ml_string(NOX("Server connected to Game Tracker"));
}
// attempt to update all player statistics and scores on the tracker
int multi_fs_tracker_store_stats()
{
int idx;
// NETLOG
ml_string(NOX("Server storing stats on User Tracker"));
// retrieve stats from tracker
Multi_store_stats_mode = MT_STORE_STATS_VALIDATE;
// multi_fs_store_stats_do() will handle all details of negotiating stats transfer with the tracker
Multi_store_stats_player_index = -1;
Multi_store_stats_player_flag = 1;
// mark the module as busy
Multi_fs_tracker_busy = 1;
// unmark everyone's GET_FAILED flag
for(idx=0;idx<MAX_PLAYERS;idx++){
Net_players[idx].flags &= ~(NETINFO_FLAG_MT_GET_FAILED);
Net_players[idx].flags &= ~(NETINFO_FLAG_MT_SEND_FAILED);
Net_players[idx].flags &= ~(NETINFO_FLAG_MT_DONE);
}
// if playing with any tables that are hacked/invalid
if ( game_hacked_data() ) {
send_game_chat_packet(Net_player, XSTR("<Server detected a hacked ships.tbl. Stats will not be saved>", 1044), MULTI_MSG_ALL, nullptr, nullptr, 1);
multi_display_chat_msg(XSTR("<Server detected a hacked ships.tbl. Stats will not be saved>", 1044), 0, 0);
popup(PF_USE_AFFIRMATIVE_ICON, 1, POPUP_OK, XSTR("You are playing with a hacked ships.tbl, your stats will not be saved", 1045) );
multi_fs_tracker_report_stats_results();
Multi_fs_tracker_busy = 0;
return 0;
}
// if there is only 1 player, don't store the stats
if((multi_num_players() <= 1) && (Multi_num_players_at_start <= 1)){
send_game_chat_packet(Net_player, XSTR("<Not enough players were present at game start or end, stats will not be saved>", 1048), MULTI_MSG_ALL, nullptr, nullptr, 1);
multi_display_chat_msg(XSTR("<Not enough players were present at game start or end, stats will not be saved>", 1048), 0, 0);
multi_fs_tracker_report_stats_results();
Multi_fs_tracker_busy = 0;
return 0;
}
// if any players have hacked info
for(idx=0; idx<MAX_PLAYERS; idx++){
if(MULTI_CONNECTED(Net_players[idx]) && !MULTI_STANDALONE(Net_players[idx]) && (Net_players[idx].flags & NETINFO_FLAG_HAXOR)){
return 0;
}
}
// check to see if the mission is valid
if(multi_fs_tracker_validate_mission(Game_current_mission_filename) != MVALID_STATUS_VALID){
send_game_chat_packet(Net_player, XSTR("<Server detected a non PXO validated mission. Stats will not be saved>", 1049), MULTI_MSG_ALL, nullptr, nullptr, 1);
multi_display_chat_msg(XSTR("<Server detected a non PXO validated mission. Stats will not be saved>", 1049), 0, 0);
popup(PF_USE_AFFIRMATIVE_ICON,1,POPUP_OK, XSTR("This is not a PXO validated mission, your stats will not be saved", 1050));
Multi_fs_tracker_busy = 0;
return 0;
}
popup_till_condition(multi_fs_store_stats_do,XSTR("&Cancel",667), XSTR("Sending player stats requests ...",676));
// send appropriate chat messages indicating stats store failure
multi_fs_tracker_report_stats_results();
// mark the module as not busy anymore
Multi_fs_tracker_busy = 0;
return 1;
}
// attempt to update all player statistics (standalone mode)
int multi_fs_std_tracker_store_stats()
{
int ret_val;
int idx;
// don't do anything if this is a tracker game
if(!(MULTI_IS_TRACKER_GAME)){
return 0;
}
if(!Multi_fs_tracker_inited){
return 0;
}
// NETLOG
ml_string(NOX("Standalone server storing stats on User Tracker"));
// retrieve stats from tracker
Multi_store_stats_mode = MT_STORE_STATS_VALIDATE;
// multi_fs_store_stats_do() will handle all details of negotiating stats transfer with the tracker
Multi_store_stats_player_index = -1;
Multi_store_stats_player_flag = 1;
// mark the module as busy
Multi_fs_tracker_busy = 1;
// unmark everyone's GET_FAILED flag
for(idx=0;idx<MAX_PLAYERS;idx++){
Net_players[idx].flags &= ~(NETINFO_FLAG_MT_GET_FAILED);
Net_players[idx].flags &= ~(NETINFO_FLAG_MT_SEND_FAILED);
Net_players[idx].flags &= ~(NETINFO_FLAG_MT_DONE);
}
// if playing with an invalid ships.tbl
if(!Game_ships_tbl_valid){
send_game_chat_packet(Net_player, XSTR("<Server detected a hacked ships.tbl. Stats will not be saved>", 1044), MULTI_MSG_ALL, nullptr, nullptr, 1);
multi_display_chat_msg(XSTR("<Server detected a hacked ships.tbl. Stats will not be saved>", 1044), 0, 0);
multi_fs_tracker_report_stats_results();
Multi_fs_tracker_busy = 0;
return 0;
}
// if playing with an invalid weapons.tbl
if(!Game_weapons_tbl_valid){
send_game_chat_packet(Net_player, XSTR("<Server detected a hacked weapons.tbl. Stats will not be saved>", 1046), MULTI_MSG_ALL, nullptr, nullptr, 1);
multi_display_chat_msg(XSTR("<Server detected a hacked weapons.tbl. Stats will not be saved>", 1046), 0, 0);
multi_fs_tracker_report_stats_results();
Multi_fs_tracker_busy = 0;
return 0;
}
// if any players have hacked info
for(idx=0; idx<MAX_PLAYERS; idx++){
if(MULTI_CONNECTED(Net_players[idx]) && !MULTI_STANDALONE(Net_players[idx]) && (Net_players[idx].flags & NETINFO_FLAG_HAXOR)){
return 0;
}
}
// if there is only 1 player, don't store the stats
if((multi_num_players() <= 1) && (Multi_num_players_at_start <= 1)){
send_game_chat_packet(Net_player, XSTR("<Not enough players were present at game start or end, stats will not be saved>", 1048), MULTI_MSG_ALL, nullptr, nullptr, 1);
multi_display_chat_msg(XSTR("<Not enough players were present at game start or end, stats will not be saved>", 1048), 0, 0);
multi_fs_tracker_report_stats_results();
Multi_fs_tracker_busy = 0;
return 0;
}
// check to see if the mission is valid
if(multi_fs_tracker_validate_mission(Game_current_mission_filename) != MVALID_STATUS_VALID){
send_game_chat_packet(Net_player, XSTR("<Server detected a non PXO validated mission. Stats will not be saved>", 1049), MULTI_MSG_ALL, nullptr, nullptr, 1);
multi_display_chat_msg(XSTR("<Server detected a non PXO validated mission. Stats will not be saved>", 1049), 0, 0);
Multi_fs_tracker_busy = 0;
return 0;
}
// multi_fs_store_stats_do() will handle all details of negotiating stats transfer with the tracker
do {
ret_val = multi_fs_store_stats_do();
game_set_frametime(GS_STATE_STANDALONE_POSTGAME);
multi_do_frame();
} while(ret_val == MT_STATS_NOT_DONE);
// report on the results
multi_fs_tracker_report_stats_results();
// mark the module as no longer busy
Multi_fs_tracker_busy = 0;
return 1;
}
// log freespace out of the tracker
void multi_fs_tracker_logout()
{
if(!Multi_fs_tracker_inited){
return;
}
// make sure we're connected
if(!(Net_player->flags & NETINFO_FLAG_AM_MASTER) || !(Net_player->flags & NETINFO_FLAG_MT_CONNECTED)){
return;
}
// otherwise, log us out
SendGameOver();
// clear our data
memset(&Multi_tracker_game_data, 0, sizeof(Multi_tracker_game_data));
Net_player->flags &= ~(NETINFO_FLAG_MT_CONNECTED);
// NETLOG
ml_string(NOX("Server disconnecting from Game Tracker"));
}
// send a request for a list of games
void multi_fs_tracker_send_game_request()
{
filter_game_list_struct filter;
size_t len;
// if we're not initialized, don't do anything
if(!Multi_fs_tracker_inited){
return;
}
// if we have a valid filter, use that instead
len = strlen(Multi_fs_tracker_filter);
if((len > 0) && (len < CHANNEL_LEN) ){
memset(&filter,0,sizeof(filter_game_list_struct));
SDL_strlcpy(filter.channel, Multi_fs_tracker_filter, SDL_arraysize(filter.channel));
RequestGameListWithFilter(&filter);
} else {
// simple API call
RequestGameList();
}
}
// if the API has successfully been initialized and is running
int multi_fs_tracker_inited()
{
return (Multi_fs_tracker_inited && (Multi_options_g.pxo));
}
// update our settings on the tracker regarding the current netgame stuff
void multi_fs_tracker_update_game(netgame_info *ng)
{
if(!Multi_fs_tracker_inited){
return;
}
// copy in the relevant data
SDL_strlcpy(Multi_tracker_game_data.game_name, ng->name, SDL_arraysize(Multi_tracker_game_data.game_name));
Multi_tracker_game_data.type = ng->type_flags;
Multi_tracker_game_data.state = ng->game_state;
Multi_tracker_game_data.max_players = ng->max_players;
Multi_tracker_game_data.current_num_players = multi_num_players();
// repurpose difficulty field to be netgame mode (both otherwise unused)
if (ng->mode == NG_MODE_RANK_BELOW) {
Multi_tracker_game_data.difficulty = -(100 + ng->rank_base);
} else if (ng->mode == NG_MODE_RANK_ABOVE) {
Multi_tracker_game_data.difficulty = (100 + ng->rank_base);
} else {
Multi_tracker_game_data.difficulty = ng->mode;
}
SDL_strlcpy(Multi_tracker_game_data.mission_name, ng->mission_name, SDL_arraysize(Multi_tracker_game_data.mission_name));
// NETLOG
ml_string(NOX("Server updating netgame info for Game Tracker"));
UpdateGameData(&Multi_tracker_game_data);
}
// if we're currently busy performing some tracker operation (ie, you should wait or not)
int multi_fs_tracker_busy()
{
return Multi_fs_tracker_busy;
}
// -----------------------------------------------------------------------------------
// FREESPACE MASTER TRACKER FORWARD DEFINITIONS
//
// used with popup_till_condition() for validating freespace pilots
int multi_fs_validate_process()
{
// should never be here if this is not true
Assert(Multi_fs_tracker_inited);
PSNET_TOP_LAYER_PROCESS();
// if we're still in player validation mode
if(Multi_validate_mode == 0){
switch(ValidateUser(nullptr,nullptr)){
// timeout on waiting for response
case -2 :
return MT_VALIDATE_TIMEOUT;
// user invalid
case -1:
// set tracker id to -1
SDL_strlcpy(Multi_tracker_id_string, "-1", SDL_arraysize(Multi_tracker_id_string));
Multi_tracker_id = -1;
return MT_VALIDATE_FAIL;
// still waiting
case 0:
return MT_VALIDATE_NOT_DONE;
// user valid
case 1:
// now we need to try and receive stats
// mark me as being valid
Multi_tracker_player_is_valid = 1;
// change the popup text
popup_change_text(XSTR("Attempting to get pilot stats ...",679));
// get my tracker id#
Multi_tracker_id = atoi(Multi_tracker_id_string);
Assert(Multi_tracker_id != -1);
GetFSPilotData(reinterpret_cast<vmt_stats_struct *>(static_cast<uintptr_t>(0xffffffff)),nullptr,nullptr,0);
GetFSPilotData(&Multi_tracker_fs_pilot,Player->callsign,Multi_tracker_id_string,1);
// set to mode 1
Multi_validate_mode = 1;
return MT_VALIDATE_NOT_DONE;
default :
Int3();
}
} else {
switch(GetFSPilotData(nullptr,nullptr,nullptr,0)){
// timedout
case -1:
return MT_VALIDATE_TIMEOUT;
// still waiting
case 0:
return MT_VALIDATE_NOT_DONE;
// got data
case 1:
return MT_VALIDATE_SUCCEED;
// failure
case 3:
return MT_VALIDATE_FAIL;
}
}
// we're not done yet - probably should never get here
return MT_VALIDATE_NOT_DONE;
}
// used with popup_till_condition() for storing player stats at the end of a freespace game
int multi_fs_store_stats_do()
{
char tracker_id_string[512];
char popup_text[100];
Assert(Multi_fs_tracker_inited);
PSNET_TOP_LAYER_PROCESS();
switch(Multi_store_stats_mode){
// get stats for all players
case MT_STORE_STATS_VALIDATE :
Multi_store_stats_mode = MT_STORE_STATS_GET_STATS;
break;
case MT_STORE_STATS_GET_STATS:
// if we need to get the next player
if(Multi_store_stats_player_flag){
Multi_store_stats_player_index = multi_fs_store_stats_get_next_player(Multi_store_stats_player_index);
// if it returns < 0 we're done with all players and should move onto the next stage (applying mission stats)
if(Multi_store_stats_player_index < 0){
Multi_store_stats_mode = MT_STORE_STATS_ACCEPT;
return MT_STATS_NOT_DONE;
}
// unset this flag so we process the request
Multi_store_stats_player_flag = 0;
// fill out the information request
memset(tracker_id_string,0,512);
Assert(Net_players[Multi_store_stats_player_index].tracker_player_id > 0);
// verify that there are no duplicate tracker id's to this one
multi_fs_tracker_check_dup(Net_players[Multi_store_stats_player_index].tracker_player_id,Multi_store_stats_player_index);
multi_fs_tracker_check_dup_callsign(&Net_players[Multi_store_stats_player_index],Multi_store_stats_player_index);
SDL_snprintf(tracker_id_string, SDL_arraysize(tracker_id_string), "%d", Net_players[Multi_store_stats_player_index].tracker_player_id);
Net_players[Multi_store_stats_player_index].s_info.tracker_security_last = -1;
Net_players[Multi_store_stats_player_index].s_info.tracker_checksum = 0;
// send the request itself
GetFSPilotData(reinterpret_cast<vmt_stats_struct *>(static_cast<uintptr_t>(0xffffffff)), nullptr, nullptr,0);
memset(&Multi_store_stats_stats, 0, sizeof(Multi_store_stats_stats));
if(GetFSPilotData(&Multi_store_stats_stats, Net_players[Multi_store_stats_player_index].m_player->callsign,tracker_id_string,1) != 0){
Int3();
// move onto the next player
Multi_store_stats_player_flag = 1;
return MT_STATS_NOT_DONE;
}
// set the popup text
if(!(Game_mode & GM_STANDALONE_SERVER)){
SDL_snprintf(popup_text, SDL_arraysize(popup_text), XSTR("Getting player stats for %s...\n", 680), Net_players[Multi_store_stats_player_index].m_player->callsign);
popup_change_text(popup_text);
}
return MT_STATS_NOT_DONE;
}
// process the request
switch(GetFSPilotData(nullptr,nullptr,nullptr,0)){
// got data
case 1:
// copy his stats, then flag him as done so we move onto the next guys
multi_stats_tracker_to_fs(&Multi_store_stats_stats,&Net_players[Multi_store_stats_player_index].m_player->stats);
// make sure we apply his mission stats now
scoring_do_accept(&Net_players[Multi_store_stats_player_index].m_player->stats);
#ifndef NDEBUG
{
// debug code to check for bogus stats
scoring_struct *ssp = &(Net_players[Multi_store_stats_player_index].m_player->stats);
vmt_stats_struct *vmt = &Multi_store_stats_stats;
if ( (ssp->missions_flown < vmt->missions_flown) || (ssp->flight_time < vmt->flight_time) || (ssp->kill_count < vmt->kill_count) ) {
Int3();
}
}
#endif
// flag him as being completed
Multi_store_stats_player_flag = 1;
// also store this last security value so we can properly update him
Net_players[Multi_store_stats_player_index].s_info.tracker_security_last = Multi_store_stats_stats.security;
Net_players[Multi_store_stats_player_index].s_info.tracker_checksum = Multi_store_stats_stats.checksum;
break;
// in progress
case 0:
break;
// failure
case 3: case -2: case 2: case -3: case -1:
// this shouldn't be happening under most conditions. For debugging....
Int3();
// flag him as done so we move onto the next guy
Multi_store_stats_player_flag = 1;
Net_players[Multi_store_stats_player_index].s_info.tracker_security_last = -1;
Net_players[Multi_store_stats_player_index].s_info.tracker_checksum = 0;
// mark down that the stats get for him failed
Net_players[Multi_store_stats_player_index].flags |= NETINFO_FLAG_MT_GET_FAILED;
Net_players[Multi_store_stats_player_index].flags |= NETINFO_FLAG_MT_DONE;
break;
}
break;
// update all stats for all players locally and on client machines
case MT_STORE_STATS_ACCEPT :
// tell everyone to save their stats
send_store_stats_packet(1);
// reset status flags and indices
Multi_store_stats_player_index = -1;
Multi_store_stats_player_flag = 1;
Multi_store_stats_mode = MT_STORE_STATS_SEND_STATS;
break;
// send stats to the tracker
case MT_STORE_STATS_SEND_STATS:
// if we need to get the next player
if(Multi_store_stats_player_flag){
Multi_store_stats_player_index = multi_fs_store_stats_get_next_player(Multi_store_stats_player_index);
// if it returns < 0 we need to move onto the next player
if(Multi_store_stats_player_index < 0){
return MT_STATS_SUCCEED;
}
Multi_store_stats_player_flag = 0;
// fill in the information
memset(&Multi_store_stats_stats,0,sizeof(Multi_store_stats_stats));
Assert(Net_players[Multi_store_stats_player_index].tracker_player_id > 0);
// verify that there are no duplicate tracker id's to this one
multi_fs_tracker_check_dup(Net_players[Multi_store_stats_player_index].tracker_player_id,Multi_store_stats_player_index);
multi_fs_tracker_check_dup_callsign(&Net_players[Multi_store_stats_player_index],Multi_store_stats_player_index);
multi_stats_fs_to_tracker(&Net_players[Multi_store_stats_player_index].m_player->stats,&Multi_store_stats_stats,Net_players[Multi_store_stats_player_index].m_player,Net_players[Multi_store_stats_player_index].tracker_player_id);
Multi_store_stats_stats.security = Net_players[Multi_store_stats_player_index].s_info.tracker_security_last;
// Assert(Net_players[Multi_store_stats_player_index].s_info.tracker_checksum != 0);
Multi_store_stats_stats.checksum = Net_players[Multi_store_stats_player_index].s_info.tracker_checksum;
// send the request
SendFSPilotData(reinterpret_cast<vmt_stats_struct *>(static_cast<uintptr_t>(0xffffffff)));
if(SendFSPilotData(&Multi_store_stats_stats) != 0){
Int3();
// failed to send, try another player the next time around
Multi_store_stats_player_flag = 1;
return MT_STATS_NOT_DONE;
}
// set the popup text
if(!(Game_mode & GM_STANDALONE_SERVER)){
SDL_snprintf(popup_text, SDL_arraysize(popup_text), XSTR("Updating player stats for %s...\n", 681), Net_players[Multi_store_stats_player_index].m_player->callsign);
popup_change_text(popup_text);
}
return MT_STATS_NOT_DONE;
}
// otherwise check on his status
switch(SendFSPilotData(nullptr)){
// error
case -1: case -2: case -3: case 2: case 3:
// flag him as done so we move onto the next guy
Multi_store_stats_player_flag = 1;
Net_players[Multi_store_stats_player_index].flags |= NETINFO_FLAG_MT_SEND_FAILED;
Net_players[Multi_store_stats_player_index].flags |= NETINFO_FLAG_MT_DONE;
break;
// got data
case 1:
// flag him as done so we move onto the next guys
Multi_store_stats_player_flag = 1;
Net_players[Multi_store_stats_player_index].flags |= NETINFO_FLAG_MT_DONE;
break;
}
break;
}
// return not done yet
return MT_STATS_NOT_DONE;
}
// copy a freespace stats struct to a tracker-freespace stats struct
void multi_stats_fs_to_tracker(scoring_struct *fs, vmt_stats_struct *vmt, player *pl, int tracker_id)
{
// tracker id
vmt->tracker_id = tracker_id;
// pilot callsign
SDL_strlcpy(vmt->pilot_name, pl->callsign, SDL_arraysize(vmt->pilot_name));
// score and rank
vmt->score = fs->score;
vmt->rank = fs->rank;
// kills and assists
vmt->assists = fs->assists;
vmt->kill_count = fs->kill_count;
vmt->kill_count_ok = fs->kill_count_ok;
// shot statistics
vmt->p_shots_fired = fs->p_shots_fired;
vmt->s_shots_fired = fs->s_shots_fired;
vmt->p_shots_hit = fs->p_shots_hit;
vmt->s_shots_hit = fs->s_shots_hit;
vmt->p_bonehead_hits = fs->p_bonehead_hits;
vmt->s_bonehead_hits = fs->s_bonehead_hits;
vmt->bonehead_kills = fs->bonehead_kills;
// missions flown information
vmt->missions_flown = fs->missions_flown;
vmt->flight_time = fs->flight_time;
vmt->last_flown = static_cast<unsigned int>(fs->last_flown);
// medals and ship kills are stored in a single array, medals first
Assert(fs->medal_counts.size() >= Medals.size());
vmt->num_medals = static_cast<unsigned char>(Medals.size());
if (vmt->num_medals > MAX_FS2OPEN_COUNTS) {
vmt->num_medals = MAX_FS2OPEN_COUNTS;
}
// find only up to last in array with at least 1 kill
vmt->num_ships = MAX_FS2OPEN_COUNTS - vmt->num_medals;
for (int idx = vmt->num_ships-1; idx >= 0; --idx) {
if (fs->kills[idx] > 0) {
break;
}
--vmt->num_ships;
}
// medals should always fit here, ships might get cut off on large mods
const size_t count = vmt->num_medals + vmt->num_ships;
for (size_t idx = 0, idx2 = 0; idx < count; ++idx) {
if (idx < vmt->num_medals) {
vmt->counts[idx] = static_cast<unsigned short>(fs->medal_counts[idx]);
} else {
vmt->counts[idx] = static_cast<unsigned short>(fs->kills[idx2++]);
}
}
}
// copy a tracker-freespace stats struct to a freespace stats struct
void multi_stats_tracker_to_fs(vmt_stats_struct *vmt,scoring_struct *fs)
{
// score and rank
fs->score = vmt->score;
fs->rank = vmt->rank;
// kills and assists
fs->assists = vmt->assists;
fs->kill_count = vmt->kill_count;
fs->kill_count_ok = vmt->kill_count_ok;
// shot statistics
fs->p_shots_fired = vmt->p_shots_fired;
fs->s_shots_fired = vmt->s_shots_fired;
fs->p_shots_hit = vmt->p_shots_hit;
fs->s_shots_hit = vmt->s_shots_hit;
fs->p_bonehead_hits = vmt->p_bonehead_hits;
fs->s_bonehead_hits = vmt->s_bonehead_hits;
fs->bonehead_kills = vmt->bonehead_kills;
// missions flown information
fs->missions_flown = vmt->missions_flown;
fs->flight_time = vmt->flight_time;
fs->last_flown = static_cast<_fs_time_t>(vmt->last_flown);
if(fs->last_flown < 0){
fs->last_flown = 0;
}
fs->last_backup = fs->last_flown;
// medals and ship kills are stored in a single array, medals first
const size_t count = vmt->num_medals + vmt->num_ships;
Assert(count <= MAX_FS2OPEN_COUNTS);
const size_t max_medals = std::max(Medals.size(), static_cast<size_t>(vmt->num_medals));
fs->medal_counts.assign(max_medals, 0);
for (size_t idx = 0, idx2 = 0; idx < count; ++idx) {
if (idx < vmt->num_medals) {
if (idx < max_medals) {
fs->medal_counts[idx] = static_cast<int>(vmt->counts[idx]);
}
} else {
fs->kills[idx2++] = static_cast<int>(vmt->counts[idx]);
}
}
}
// process an incoming active game item
void multi_fs_tracker_process_game_item(game_list *gl)
{
active_game ag;
int idx;
for(idx=0;idx<MAX_GAME_LISTS_PER_PACKET;idx++){
// skip null server addresses
if (IN6_IS_ADDR_UNSPECIFIED(&gl->game_server[idx])) {
continue;
}
// package up the game information
ag.init();
SDL_strlcpy(ag.name, gl->game_name[idx], SDL_arraysize(ag.name));
memcpy(&ag.server_addr.addr, &gl->game_server[idx], sizeof(ag.server_addr.addr));
ag.server_addr.port = ntohs(gl->port[idx]); //DEFAULT_GAME_PORT;
// add to the active game list
// multi_update_active_games(&ag);
// query this server
send_server_query(&ag.server_addr);
}
}
int multi_fs_store_stats_get_next_player(int cur_player)
{
int idx;
// if we're at the end of the list
if(cur_player == (MAX_PLAYERS - 1)){
return -2;
}
// find the next player
for(idx=cur_player+1;idx<MAX_PLAYERS;idx++){
// STANDALONE_ONLY
if(MULTI_CONNECTED(Net_players[idx]) && !MULTI_STANDALONE(Net_players[idx]) && !MULTI_PERM_OBSERVER(Net_players[idx]) && (Net_players[idx].tracker_player_id != -1) && !(Net_players[idx].flags & NETINFO_FLAG_MT_GET_FAILED) ){
return idx;
}
}
// couldn't find one
return -2;
}
// verify that there are no duplicate tracker id's to this one
void multi_fs_tracker_check_dup(int tracker_id,int player_index)
{
int idx;
// compare against all players except the passed player_index
for(idx=0;idx<MAX_PLAYERS;idx++){
if(idx == player_index){
continue;
}
if(MULTI_CONNECTED(Net_players[idx]) && !MULTI_STANDALONE(Net_players[idx]) && !MULTI_PERM_OBSERVER(Net_players[idx]) && (Net_players[idx].tracker_player_id != -1)){
Assert(Net_players[idx].tracker_player_id != tracker_id);
}
}
}
// verify that there are no duplicate pilot callsigns
void multi_fs_tracker_check_dup_callsign(net_player *player,int player_index)
{
int idx;
// compare against all players except the passed player_index
for(idx=0;idx<MAX_PLAYERS;idx++){
if(idx == player_index){
continue;
}
if(MULTI_CONNECTED(Net_players[idx]) && !MULTI_STANDALONE(Net_players[idx]) && !MULTI_PERM_OBSERVER(Net_players[idx]) && (Net_players[idx].tracker_player_id != -1)){
Assert(strcmp(player->m_player->callsign,Net_players[idx].m_player->callsign));
}
}
}
// return an MVALID_STATUS_* constant
int multi_fs_tracker_validate_mission_std()
{
int ret_val;
// wait for a response from the tracker
do {
ret_val = ValidateMission(nullptr);
} while(ret_val == 0);
// report on the results
switch(ret_val){
// timeout
case -2:
// consider timeout to be fatal and cancel validation
return -2; //MVALID_STATUS_UNKNOWN;
// invalid
case -1:
return MVALID_STATUS_INVALID;
// valid, success
case 1:
return MVALID_STATUS_VALID;
}
Int3();
return 0;
}
// special return values :
// 1 for timeout
// 2 for invalid
// 3 for valid
int multi_fs_tracker_validate_mission_normal()
{
switch(ValidateMission(nullptr)){
// timeout
case -2:
return 1;
// invalid
case -1 :
return 2;
// valid
case 1:
return 3;
}
// not done yet
return 0;
}
// return an MVALID_STATUS_* (see multiui.h) value, or -2 if the user has "cancelled"
int multi_fs_tracker_validate_mission(char *filename)
{
vmt_validate_mission_req_struct mission;
char popup_string[512] = "";
if(!Multi_fs_tracker_inited){
return MVALID_STATUS_UNKNOWN;
}
mprintf(("Standalone: Validating '%s'\n", filename));
// get the checksum of the local file
memset(&mission, 0, sizeof(mission));
SDL_strlcpy(mission.file_name, filename, SDL_arraysize(mission.file_name));
if(!cf_chksum_long(mission.file_name, reinterpret_cast<uint *>(&mission.checksum))){
return MVALID_STATUS_UNKNOWN;
}
// try and validate the mission
if(ValidateMission(&mission) != 0){
return MVALID_STATUS_UNKNOWN;
}
// do frames for standalone and non-standalone
if(Game_mode & GM_STANDALONE_SERVER){
int ret_code;
// set the filename in the dialog
std_gen_set_text(filename, 2);
// validate the mission
ret_code = multi_fs_tracker_validate_mission_std();
// if the dialog is no longer active, cancel everything
//if(!std_gen_is_active()){
// return MVALID_STATUS_UNKNOWN;
//}
return ret_code;
} else {
SDL_snprintf(popup_string, SDL_arraysize(popup_string), XSTR("Validating mission %s", 1074), filename);
// run a popup
switch ( popup_conditional_do(multi_fs_tracker_validate_mission_normal, popup_string) ) {
// cancel
case 0:
// bash some API values here so that next time we try and verify, everything works
MissionValidState = VALID_STATE_IDLE;
return -2;
// timeout
case 1:
return MVALID_STATUS_UNKNOWN;
// invalid
case 2:
return MVALID_STATUS_INVALID;
// valid
case 3:
return MVALID_STATUS_VALID;
}
}
return MVALID_STATUS_UNKNOWN;
}
// return a MVALID_STATUS_* constant
int multi_fs_tracker_validate_data_std()
{
int ret_val;
// wait for a response from the tracker
do {
ret_val = ValidateData(nullptr);
} while (ret_val == 0);
// report on the results
switch (ret_val) {
// timeout
case -2:
// consider timeout to be fatal and cancel validation
return -2; //MVALID_STATUS_UNKNOWN;
// invalid
case -1:
return MVALID_STATUS_INVALID;
// valid, success
case 1:
return MVALID_STATUS_VALID;
}
Int3();
return 0;
}
// special return values :
// 1 for timeout
// 2 for invalid
// 3 for valid
int multi_fs_tracker_validate_data_normal()
{
switch ( ValidateData(nullptr) ) {
// timeout
case -2:
return 1;
// invalid
case -1 :
return 2;
// valid
case 1:
return 3;
}
// not done yet
return 0;
}
int multi_fs_tracker_validate_data(const vmt_valid_data_req_struct *vdr, const char *popup_text = nullptr)
{
if ( !Multi_fs_tracker_inited ) {
return MVALID_STATUS_UNKNOWN;
}
if (ValidateData(vdr) != 0) {
return MVALID_STATUS_UNKNOWN;
}
if (Game_mode & GM_STANDALONE_SERVER) {
std_gen_set_text(popup_text, 1);
// validate the data
int ret_code = multi_fs_tracker_validate_data_std();
return ret_code;
} else {
switch ( popup_conditional_do(multi_fs_tracker_validate_data_normal, popup_text) ) {
// cancel
case 0:
DataValidState = VALID_STATE_IDLE;
return -2;
// timeout
case 1:
DataValidState = VALID_STATE_IDLE;
return -3;
// invalid
case 2:
return MVALID_STATUS_INVALID;
// valid
case 3:
return MVALID_STATUS_VALID;
}
}
return MVALID_STATUS_UNKNOWN;
}
// batch validate missions and fill passed struct with results
// returns:
// true if process completed successfully
// false if process was terminated from timeout or by cancellation
bool multi_fs_tracker_validate_mission_list(SCP_vector<multi_create_info> &file_list)
{
vmt_valid_data_req_struct vdr;
char popup_string[512] = "";
int rval;
vdr.type = VDR_TYPE_MISSION;
vdr.flags = VDR_FLAG_STATUS;
vdr.num_files = 0;
size_t packet_size = 3; // type, flags, num_files
for (size_t idx = 0; idx < file_list.size(); ) {
auto &entry = file_list[idx];
const size_t len = sizeof(uint32_t) + strlen(entry.filename) + 1;
if (packet_size+len < MAX_UDP_DATA_LENGH) {
valid_data_item item;
cf_chksum_long(entry.filename, &item.crc);
item.name = entry.filename;
vdr.files.push_back(item);
vdr.num_files++;
packet_size += len;
++idx;
} else {
// so we don't start at 0%
if (idx != vdr.num_files) {
SDL_snprintf(popup_string, SDL_arraysize(popup_string), XSTR("Validating missions ... %d%%", -1), static_cast<int>(((idx - vdr.num_files) / static_cast<float>(file_list.size())) * 100));
}
// send packet
rval = multi_fs_tracker_validate_data(&vdr, popup_string);
// if it was cancelled then just bail out
if (rval == -2 || rval == -3) {
return false;
}
// set status for each file checked
auto istart = idx - vdr.num_files;
for (auto p = 0; p < vdr.num_files; ++p) {
file_list[istart+p].valid_status = IsDataIndexValid(p) ? MVALID_STATUS_VALID : MVALID_STATUS_INVALID;
}
// reset counts for next run
packet_size = 3; // type, flags, num_files
vdr.files.clear();
vdr.num_files = 0;
}
}
// final packet
if (vdr.num_files) {
// so we don't start at 0%
if (file_list.size() != vdr.num_files) {
SDL_snprintf(popup_string, SDL_arraysize(popup_string), XSTR("Validating missions ... %d%%", -1), static_cast<int>(((file_list.size() - vdr.num_files) / static_cast<float>(file_list.size())) * 100));
}
// send packet
rval = multi_fs_tracker_validate_data(&vdr, popup_string);
// if it was cancelled then just bail out
if (rval == -2) {
return false;
}
// set status for each file checked
auto istart = file_list.size() - vdr.num_files;
for (auto p = 0; p < vdr.num_files; ++p) {
file_list[istart+p].valid_status = IsDataIndexValid(p) ? MVALID_STATUS_VALID : MVALID_STATUS_INVALID;
}
}
// done!
return true;
}
static int validate_table_list(const SCP_vector<SCP_string> &table_list, int &game_data_status)
{
vmt_valid_data_req_struct vdr;
char popup_string[512] = "";
int rval;
strcpy_s(popup_string, XSTR("Validating tables ...", -1));
vdr.type = VDR_TYPE_TABLE;
vdr.flags = VDR_FLAG_IDENT;
vdr.num_files = 0;
size_t packet_size = 3; // type, flags, num_files
for (size_t idx = 0; idx < table_list.size(); ) {
const auto &tbl = table_list[idx];
const size_t len = sizeof(uint32_t) + tbl.length() + 1;
if (packet_size+len < MAX_UDP_DATA_LENGH) {
valid_data_item item;
cf_chksum_long(tbl.c_str(), &item.crc);
item.name = tbl;
vdr.files.push_back(item);
vdr.num_files++;
packet_size += len;
++idx;
} else {
// so we don't start at 0%
if (idx != vdr.num_files) {
SDL_snprintf(popup_string, SDL_arraysize(popup_string), XSTR("Validating tables ... %d%%", -1), static_cast<int>(((idx - vdr.num_files) / static_cast<float>(table_list.size())) * 100));
}
// send packet
rval = multi_fs_tracker_validate_data(&vdr, popup_string);
// reset counts for next run
packet_size = 3; // type, flags, num_files
vdr.files.clear();
vdr.num_files = 0;
// if anything is valid then update our default
if ( (rval == MVALID_STATUS_VALID) && (game_data_status == MVALID_STATUS_UNKNOWN) ) {
game_data_status = MVALID_STATUS_VALID;
}
// continue processing after invalid for mod ident to fully work
else if (rval == MVALID_STATUS_INVALID) {
game_data_status = MVALID_STATUS_INVALID;
}
// if the popup was canceled then force a recheck on next attempt
else if (rval == -2) {
game_data_status = MVALID_STATUS_UNKNOWN;
break;
}
// if we timed out then log it and return error
else if (rval == -3) {
game_data_status = MVALID_STATUS_UNKNOWN;
if ( !(Game_mode & GM_STANDALONE_SERVER) ) {
popup_conditional_close();
}
ml_printf("PXO Game Ident timed out! Unable to connect to server: %s", Multi_options_g.user_tracker_ip);
return -1;
}
}
}
// final packet
if (vdr.num_files) {
// so we don't start at 0%
if (table_list.size() != vdr.num_files) {
SDL_snprintf(popup_string, SDL_arraysize(popup_string), XSTR("Validating tables ... %d%%", -1), static_cast<int>(((table_list.size() - vdr.num_files) / static_cast<float>(table_list.size())) * 100));
}
rval = multi_fs_tracker_validate_data(&vdr, popup_string);
// if anything is valid then update our default
if ( (rval == MVALID_STATUS_VALID) && (game_data_status == MVALID_STATUS_UNKNOWN) ) {
game_data_status = MVALID_STATUS_VALID;
}
// continue processing after invalid for mod ident to fully work
else if (rval == MVALID_STATUS_INVALID) {
game_data_status = MVALID_STATUS_INVALID;
}
// if the popup was canceled then force a recheck on next attempt
else if (rval == -2) {
game_data_status = MVALID_STATUS_UNKNOWN;
}
// if we timed out then log it and return error
else if (rval == -3) {
game_data_status = MVALID_STATUS_UNKNOWN;
if ( !(Game_mode & GM_STANDALONE_SERVER) ) {
popup_conditional_close();
}
ml_printf("PXO Game Ident timed out! Unable to connect to server: %s", Multi_options_g.user_tracker_ip);
return -1;
}
}
return 0;
}
// check all tables with tracker
// this is hacked data check as well as mod ident (done server side)
// returns:
// 1 if hacked (or no ident) - stats won't save
// 0 if ident and not hacked - stats can save
// -1 if server connection failed
int multi_fs_tracker_validate_game_data()
{
// should only do this only once per game session
static int game_data_status = MVALID_STATUS_UNKNOWN;
char popup_string[512] = "";
multi_fs_tracker_init();
if ( !Multi_fs_tracker_inited ) {
return 1; // assume hacked
}
if (game_data_status != MVALID_STATUS_UNKNOWN) {
return (game_data_status != MVALID_STATUS_VALID);
}
SCP_vector<SCP_string> table_list;
size_t tbl_idx, tbm_idx;
int rval;
// grab all tbl and tbm files and send the checksum to tracker
// cf_get_file_list() strips ext so we have to do this in parts
// let the tracker figure out which files to validate against
// get all tbl files first
cf_get_file_list(table_list, CF_TYPE_TABLES, "*.tbl");
// add ext back on filenames
for (tbl_idx = 0; tbl_idx < table_list.size(); ++tbl_idx) {
table_list[tbl_idx].append(".tbl");
}
// next grab any tbm files
cf_get_file_list(table_list, CF_TYPE_TABLES, "*.tbm");
// and add ext
for (tbm_idx = tbl_idx; tbm_idx < table_list.size(); ++tbm_idx) {
table_list[tbm_idx].append(".tbm");
}
// now check with tracker
strcpy_s(popup_string, XSTR("Validating tables ...", -1));
if ( !(Game_mode & GM_STANDALONE_SERVER) ) {
popup_conditional_create(0, XSTR("&Cancel", 667), popup_string);
}
rval = validate_table_list(table_list, game_data_status);
// if the connection timed out then maybe try a fallback...
if ( (rval == -1) && (psnet_get_ip_mode() == PSNET_IP_MODE_DUAL) ) {
// the default preference is IPv6, so fall back to IPv4
// otherwise move to 4 or 6 depending on current preference
if ( !Cmdline_prefer_ipv4 && !Cmdline_prefer_ipv6 ) {
Cmdline_prefer_ipv4 = true;
} else if (Cmdline_prefer_ipv4) {
Cmdline_prefer_ipv4 = false;
Cmdline_prefer_ipv6 = true;
} else if (Cmdline_prefer_ipv6) {
Cmdline_prefer_ipv4 = true;
Cmdline_prefer_ipv6 = false;
}
// now we have to re-init the low-level tracker connections
InitValidateClient();
InitPilotTrackerClient();
InitGameTrackerClient(GT_FS2OPEN);
// and try to validate again
validate_table_list(table_list, game_data_status);
}
if ( !(Game_mode & GM_STANDALONE_SERVER) ) {
popup_conditional_close();
}
// we should hopefully have a mod id now, so log it
if (Multi_fs_tracker_game_id < 0) {
ml_printf("PXO Game Ident => FAILED!");
} else {
ml_printf("PXO Game Ident => %d: %s", Multi_fs_tracker_game_id, Multi_fs_tracker_game_name.c_str());
}
return (game_data_status != MVALID_STATUS_VALID);
}
// report on the results of the stats store procedure
void multi_fs_tracker_report_stats_results()
{
int idx;
char str[512] = "";
// tell everyone stats store is complete
SDL_strlcpy(str, XSTR("<PXO stats store process complete>", 1001), SDL_arraysize(str));
send_game_chat_packet(Net_player, str, MULTI_MSG_ALL, nullptr, nullptr, 1);
multi_display_chat_msg(str, 0, 0);
ml_string(str);
// for all players
for(idx=0; idx<MAX_PLAYERS; idx++){
// for all players who we care about
if(MULTI_CONNECTED(Net_players[idx]) && !MULTI_STANDALONE(Net_players[idx])){
// if the stats get or send failed for any player, report as such
if(((Net_players[idx].tracker_player_id <= 0) || (Net_players[idx].flags & NETINFO_FLAG_MT_GET_FAILED) || (Net_players[idx].flags & NETINFO_FLAG_MT_SEND_FAILED) || !(Net_players[idx].flags & NETINFO_FLAG_MT_DONE)) && (Net_players[idx].m_player != nullptr)){
SDL_snprintf(str, SDL_arraysize(str), XSTR("<PXO stats store failed for player %s>", 1002), Net_players[idx].m_player->callsign);
send_game_chat_packet(Net_player, str, MULTI_MSG_ALL, nullptr, nullptr, 1);
multi_display_chat_msg(str, 0, 0);
ml_string(str);
}
}
}
}
// report the status of PXO game probe (firewall check)
void multi_fs_tracker_report_probe_status(int flags, int next_try)
{
static int last_flags = 0;
SCP_string str;
// if the flags haven't changed since last time then just bail
// *except* if the probe failed since we always want that message
// (don't & the flag check here, needs to be exact)
if ( (flags == last_flags) && (flags != PROBE_FLAGS::FAILURE) ) {
return;
}
if (flags & PROBE_FLAGS::PENDING) {
// if we've been here before just bail (to avoid log spam)
if (last_flags) {
last_flags = flags;
return;
}
str = "<PXO firewall probe in progress...>";
} else if (flags & PROBE_FLAGS::FAILURE) {
char t_str[64];
str = "<PXO firewall probe failed! Next attempt in ";
if (next_try < 120) {
SDL_snprintf(t_str, SDL_arraysize(t_str), "%d seconds...>", next_try);
} else if (next_try < (60*60+1)) {
int minutes = next_try / 60;
SDL_snprintf(t_str, SDL_arraysize(t_str), "%d minutes...>", minutes);
} else {
int hours = next_try / (60*60);
SDL_snprintf(t_str, SDL_arraysize(t_str), "%d hours...>", hours);
}
str += t_str;
} else if (flags & PROBE_FLAGS::SUCCESS) {
str = "<PXO firewall probe was a success!>";
} else {
// getting here shouldn't happen, but it's not technically fatal
return;
}
last_flags = flags;
multi_display_chat_msg(str.c_str(), 0, 0);
ml_string(str.c_str());
}
// return an MSW_STATUS_* constant
int multi_fs_tracker_validate_sw_std()
{
int ret_val;
// wait for a response from the tracker
do {
ret_val = ValidateSquadWar(nullptr, &Multi_tracker_sw_response);
} while(ret_val == 0);
// report on the results
switch(ret_val){
// timeout
case -2:
return MVALID_STATUS_UNKNOWN;
// invalid
case -1:
return MVALID_STATUS_INVALID;
// valid, success
case 1:
return MVALID_STATUS_VALID;
}
return MVALID_STATUS_UNKNOWN;
}
// special return values :
// 1 for timeout
// 2 for invalid
// 3 for valid
int multi_fs_tracker_validate_sw_normal()
{
switch(ValidateSquadWar(nullptr, &Multi_tracker_sw_response)){
// timeout
case -2:
return 1;
// invalid
case -1 :
return 2;
// valid
case 1:
return 3;
}
// not done yet
return 0;
}
#define STUFF_SW_RESPONSE(_c, _len) do {\
SDL_strlcpy(_c, "", _len);\
int _idx;\
int _bogus = 1;\
for(_idx=0; _idx<MAX_SQUAD_RESPONSE_LEN; _idx++){\
if(Multi_tracker_sw_response.reason[_idx] == '\0'){\
_bogus = 0;\
break;\
}\
}\
if(!_bogus){\
SDL_strlcpy(_c, Multi_tracker_sw_response.reason, _len);\
}\
} while(false);
// return an MSW_STATUS_* value
int multi_fs_tracker_validate_sw(squad_war_request *sw_req, char *bad_reply, const size_t max_reply_len)
{
char popup_string[512] = "";
if(!Multi_fs_tracker_inited){
return MSW_STATUS_UNKNOWN;
}
// zero the response
memset(&Multi_tracker_sw_response, 0, sizeof(Multi_tracker_sw_response));
// try and validate the mission
if(ValidateSquadWar(sw_req, &Multi_tracker_sw_response) != 0){
SDL_strlcpy(bad_reply, "Error sending request for Squad War validation", max_reply_len);
return MSW_STATUS_UNKNOWN;
}
// do frames for standalone and non-standalone
if(Game_mode & GM_STANDALONE_SERVER){
int ret_code;
// validate the mission
ret_code = multi_fs_tracker_validate_sw_std();
// copy the return code
STUFF_SW_RESPONSE(bad_reply, max_reply_len);
return ret_code;
} else {
SDL_strlcpy(popup_string, XSTR("Validating squad war", 1075), SDL_arraysize(popup_string));
// run a popup
switch(popup_till_condition(multi_fs_tracker_validate_sw_normal, XSTR("&Cancel", 645), popup_string)){
// cancel
case -1:
case 0:
// bash some API values here so that next time we try and verify, everything works
SquadWarValidState = VALID_STATE_IDLE;
// copy the return code
STUFF_SW_RESPONSE(bad_reply, max_reply_len);
return -2;
// timeout
case 1:
// copy the return code
SDL_strlcpy(bad_reply, "Timeout", max_reply_len);
return MSW_STATUS_UNKNOWN;
// invalid
case 2:
// copy the return code
STUFF_SW_RESPONSE(bad_reply, max_reply_len);
return MSW_STATUS_INVALID;
// valid
case 3:
// copy the return code
STUFF_SW_RESPONSE(bad_reply, max_reply_len);
return MSW_STATUS_VALID;
}
}
SDL_strlcpy(bad_reply, "Unknown error", max_reply_len);
return MSW_STATUS_UNKNOWN;
}
// popup do function
// -3 Error -- Called with NULL, but no request is waiting
// -2 Error -- Already sending data (hasn't timed out yet)
// -1 Timeout trying to send pilot data
// 0 Sending
// 1 Data succesfully sent
// 2 Send Cancelled (data may still have been written already, we just haven't been ACK'd yet)
// 3 Pilot not written (for some reason)
int multi_fs_tracker_store_sw_do()
{
switch(SendSWData(nullptr, &Multi_tracker_sw_response)){
// failure
case -3:
case -2:
case -1:
case 2:
case 3:
return 1;
// success
case 1:
return 10;
}
// not done
return 0;
}
// store the results of a squad war mission on PXO, return 1 on success
int multi_fs_tracker_store_sw(squad_war_result *sw_res, char * /*bad_reply*/, const size_t /*max_reply_len*/)
{
char popup_string[512] = "";
// clear any old requests
SendSWData(reinterpret_cast<squad_war_result *>(static_cast<uintptr_t>(0xffffffff)), nullptr);
// send this new request
SendSWData(sw_res, &Multi_tracker_sw_response);
// standalone
if(Game_mode & GM_STANDALONE_SERVER){
int ret_code;
do {
ret_code = SendSWData(nullptr, &Multi_tracker_sw_response);
} while(ret_code == 0);
// success
if(ret_code == 1){
return 1;
}
}
// non-standalone
else {
SDL_strlcpy(popup_string, XSTR("Storing SquadWar results", 1078), SDL_arraysize(popup_string));
// wait for a response
if(popup_till_condition(multi_fs_tracker_store_sw_do, XSTR("&Cancel", 645), popup_string) == 10){
// success
return 1;
}
}
// failure
return 0;
}
// verify and possibly update Multi_options_g with sane PXO values
void multi_fs_tracker_verify_options()
{
bool override = false;
// if any tracker ip is missing, force update
if ( !strlen(Multi_options_g.user_tracker_ip) || !strlen(Multi_options_g.game_tracker_ip)
|| !strlen(Multi_options_g.pxo_ip) )
{
override = true;
}
// if user tracker ip is set to retail setting, force update
if ( !override && !strcmp(Multi_options_g.user_tracker_ip, "ut.pxo.net") ) {
override = true;
}
// if user tracker ip is set to FS2NetD, force update
if ( !override && !strcmp(Multi_options_g.user_tracker_ip, "fs2netd.game-warden.com") ) {
override = true;
}
if ( !override ) {
return;
}
//
// update required options
//
strcpy_s(Multi_options_g.user_tracker_ip, PXO_DEFAULT_TRACKER);
strcpy_s(Multi_options_g.game_tracker_ip, PXO_DEFAULT_TRACKER);
strcpy_s(Multi_options_g.pxo_ip, PXO_DEFAULT_TRACKER);
//
// update optional urls
//
strcpy_s(Multi_options_g.pxo_rank_url, PXO_WEBSITE_URL);
strcat_s(Multi_options_g.pxo_rank_url, "/rankings");
strcpy_s(Multi_options_g.pxo_create_url, PXO_WEBSITE_URL);
strcat_s(Multi_options_g.pxo_create_url, "/register");
strcpy_s(Multi_options_g.pxo_verify_url, PXO_WEBSITE_URL);
strcat_s(Multi_options_g.pxo_verify_url, "/account");
strcpy_s(Multi_options_g.pxo_banner_url, PXO_WEBSITE_URL);
strcat_s(Multi_options_g.pxo_banner_url, "/files/banners");
}
|