static int fs2netd_send_player() { int rc; do_full_packet = true; In_process = true; if (Is_standalone) { do { rc = fs2netd_send_player_do(); } while (!rc); } else { rc = popup_till_condition(fs2netd_send_player_do, XSTR("&Cancel", 779), XSTR("Sending player stats requests ...", 676)); } In_process = false; Local_timeout = -1; rc = rc - 3; if (rc < -1) { rc = -1; } return rc; }
bool fs2netd_check_mission(char *mission_name) { int rc = 0; char popup_string[256]; if ( !Logged_in ) { return 0; } strcpy_s(Chk_mission_name, mission_name); cf_chksum_long(Chk_mission_name, &Chk_mission_crc); do_full_packet = true; In_process = true; memset(popup_string, 0, sizeof(popup_string)); sprintf(popup_string, XSTR("Validating mission %s", 1074), mission_name); if (Is_standalone) { do { rc = fs2netd_check_mission_do(); } while (!rc); } else { rc = popup_till_condition(fs2netd_check_mission_do, XSTR("&Cancel", 779), popup_string); } In_process = false; Local_timeout = -1; switch (rc) { // operation canceled, or invalid case 0: return false; // successful, but invalid case 1: return false; // successful and valid case 2: return true; // failed to send request packet case 3: if ( !Is_standalone ) { popup(PF_USE_AFFIRMATIVE_ICON, 1, POPUP_OK, XSTR("Server request failed!",1580)); } return false; // it timed out case 4: if ( !Is_standalone ) { popup(PF_USE_AFFIRMATIVE_ICON, 1, POPUP_OK, XSTR("Server request timed out!", 1581)); } return false; } return false; }
void fs2netd_connect() { int rc = 0; // don't bother with this if we aren't on FS2NetD if ( !Om_tracker_flag ) { return; } if ( !(Game_mode & GM_MULTIPLAYER) ) { return; } if (Is_connected) { return; } Assert( strlen(Multi_options_g.game_tracker_ip) ); Assert( strlen(Multi_options_g.tracker_port) ); In_process = true; if (Is_standalone) { do { rc = fs2netd_connect_do(); } while (!rc); } else { popup_till_condition(fs2netd_connect_do, XSTR("&Cancel", 779), XSTR("Connecting into FS2NetD", 1575)); } In_process = false; Local_timeout = -1; }
// process all endgame related events void multi_endgame_process() { if ( Multi_endgame_processing ) return; Multi_endgame_processing = 1; // check to see if we need to be warping out (strange transition possibilities) multi_endgame_check_for_warpout(); // if we're the server of the game if(Net_player->flags & NETINFO_FLAG_AM_MASTER){ // if we're not waiting for clients to leave, do nothing if(!Multi_endgame_server_waiting){ Multi_endgame_processing = 0; return; } // if a popup is already active, do nothing if(popup_active()){ Multi_endgame_processing = 0; return; } // otherwise popup until things are hunky-dory if(!multi_endgame_server_ok_to_leave()){ if(Game_mode & GM_STANDALONE_SERVER){ while(!multi_endgame_server_ok_to_leave()){ // run networking, etc. game_set_frametime(-1); game_do_state_common(gameseq_get_state()); } } else { popup_till_condition( multi_endgame_server_ok_to_leave , XSTR("&Cancel",645), XSTR("Waiting for clients to disconnect",646)); } } // mark myself as not waiting and get out multi_endgame_cleanup(); } else { // if we're not waiting to leave the game, do nothing if(!Multi_endgame_client_waiting){ Multi_endgame_processing = 0; return; } // otherwise, check to see if there is a popup active if(popup_active()){ Multi_endgame_processing = 0; return; } // if not, then we are good to leave multi_endgame_cleanup(); } Multi_endgame_processing = 0; }
bool fs2netd_get_valid_missions() { int rc = 0; if ( !Logged_in ) { return false; } FS2NetD_file_list.clear(); do_full_packet = true; In_process = true; if (Is_standalone) { do { rc = fs2netd_get_valid_missions_do(); } while (!rc); } else { rc = popup_till_condition(fs2netd_get_valid_missions_do, XSTR("&Cancel", 779), XSTR("Starting mission validation", 1588)); } In_process = false; Local_timeout = -1; FS2NetD_file_list.clear(); //-V586 switch (rc) { // canceled by popup case 0: return false; // timed out case 1: if ( !Is_standalone ) { popup(PF_USE_AFFIRMATIVE_ICON, 1, POPUP_OK, XSTR("Mission validation timed out!", 1589)); } return false; // no missions case 2: if ( !Is_standalone ) { popup(PF_USE_AFFIRMATIVE_ICON, 1, POPUP_OK, XSTR("No missions are available from the server for validation!", 1590)); } return false; // out of memory case 3: if ( !Is_standalone ) { popup(PF_USE_AFFIRMATIVE_ICON, 1, POPUP_OK, XSTR("Memory error during mission validation!", 1591)); } return false; } return true; }
void fs2netd_connect() { int rc = 0; // don't bother with this if we aren't on FS2NetD if ( !Om_tracker_flag ) { return; } if ( !(Game_mode & GM_MULTIPLAYER) ) { return; } if (Is_connected) { return; } if ( !PXO_port ) { Assert( strlen(Multi_options_g.game_tracker_ip) ); Assert( strlen(Multi_options_g.tracker_port) ); if ( strlen(Multi_options_g.game_tracker_ip) ) { strncpy( PXO_Server, Multi_options_g.game_tracker_ip, sizeof(PXO_Server) - 1 ); } else { ml_printf("FS2NetD ERROR: No server specified in multi.cfg! Using default instead (%s)!", FS2NETD_DEFAULT_SERVER); strncpy( PXO_Server, FS2NETD_DEFAULT_SERVER, sizeof(PXO_Server) - 1 ); } if ( strlen(Multi_options_g.tracker_port) ) { long tmp = strtol(Multi_options_g.tracker_port, (char**)NULL, 10); if ( (tmp < 1024) || (tmp > USHRT_MAX) ) { ml_printf("FS2NetD ERROR: The port specified in multi.cfg, '%i', is outside of the required range, %i through %i!", tmp, 1024, USHRT_MAX); ml_printf("Fs2NetD ERROR: Setting port to default value (%s) ...", FS2NETD_DEFAULT_PORT); PXO_port = (ushort) strtol(FS2NETD_DEFAULT_PORT, (char**)NULL, 10); } else { PXO_port = (ushort)tmp; } } else { PXO_port = (ushort) strtol(FS2NETD_DEFAULT_PORT, (char**)NULL, 10); } } In_process = true; if (Is_standalone) { do { rc = fs2netd_connect_do(); } while (!rc); } else { popup_till_condition(fs2netd_connect_do, XSTR("&Cancel", 779), XSTR("Connecting into FS2NetD", -1)); } In_process = false; }
void fs2netd_update_ban_list() { int rc = 0; // don't bother with this if we aren't on FS2NetD if ( !Om_tracker_flag ) { return; } if ( !(Game_mode & GM_MULTIPLAYER) ) { return; } if (!Is_connected) { return; } // destroy the file prior to updating cf_delete( "banlist.cfg", CF_TYPE_DATA ); do_full_packet = 1; In_process = true; if (Is_standalone) { do { rc = fs2netd_update_ban_list_do(); } while (!rc); } else { rc = popup_till_condition(fs2netd_update_ban_list_do, XSTR("&Cancel", 779), XSTR("Requesting IP ban list", -1)); } In_process = false; if (FS2NetD_ban_list) { CFILE *banlist_cfg = cfopen("banlist.cfg", "wt", CFILE_NORMAL, CF_TYPE_DATA); if (banlist_cfg != NULL) { for (int i = 0; i < FS2NetD_ban_list_count; i++) { cfputs( FS2NetD_ban_list[i].ip_mask, banlist_cfg ); } cfclose(banlist_cfg); } delete[] FS2NetD_ban_list; } FS2NetD_ban_list = NULL; FS2NetD_ban_list_count = -1; }
void fs2netd_update_ban_list() { int rc = 0; if ( !Logged_in ) { return; } // destroy the file prior to updating cf_delete( "banlist.cfg", CF_TYPE_DATA ); do_full_packet = true; In_process = true; if (Is_standalone) { do { rc = fs2netd_update_ban_list_do(); } while (!rc); } else { rc = popup_till_condition(fs2netd_update_ban_list_do, XSTR("&Cancel", 779), XSTR("Requesting IP ban list", 1587)); } In_process = false; Local_timeout = -1; if ( !FS2NetD_ban_list.empty() ) { CFILE *banlist_cfg = cfopen("banlist.cfg", "wt", CFILE_NORMAL, CF_TYPE_DATA); if (banlist_cfg != NULL) { for (SCP_vector<SCP_string>::iterator bl = FS2NetD_ban_list.begin(); bl != FS2NetD_ban_list.end(); ++bl) { cfputs( const_cast<char*>(bl->c_str()), banlist_cfg ); } cfclose(banlist_cfg); } } FS2NetD_ban_list.clear(); }
bool fs2netd_login() { bool retval = true; int rc; // don't bother with this if we aren't on FS2NetD if ( !Om_tracker_flag ) { return false; } if ( !(Game_mode & GM_MULTIPLAYER) ) { return false; } if ( Logged_in && (Multi_tracker_id >= 0) ) { return true; } Logged_in = false; Multi_tracker_id = -1; memset( Multi_tracker_id_string, 0, sizeof(Multi_tracker_id_string) ); // verify that our connection settings are sane fs2netd_options_config_init(); // if we're a standalone, show a dialog saying "validating tables" if (Is_standalone) { std_create_gen_dialog("Logging into FS2NetD"); std_gen_set_text("Connecting...", 1); } fs2netd_connect(); if ( !Is_connected ) { if ( !Is_standalone ) { popup(PF_USE_AFFIRMATIVE_ICON, 1, POPUP_OK, XSTR("Failed to connect to FS2NetD server!", 1578)); } else { std_gen_set_text("Connect FAILED!", 1); Sleep(2000); std_destroy_gen_dialog(); } return false; } char error_str[256]; char std_error_str[64]; do_full_packet = true; In_process = true; if (Is_standalone) { do { rc = fs2netd_login_do(); } while (!rc); } else { rc = popup_till_condition(fs2netd_login_do, XSTR("&Cancel", 779), XSTR("Logging into FS2NetD", 1579)); } In_process = false; Local_timeout = -1; memset( error_str, 0, sizeof(error_str) ); memset( std_error_str, 0, sizeof(std_error_str) ); switch (rc) { // the action was cancelled case 0: ml_string("FS2NetD MSG: Login process canceled by user."); retval = false; break; // didn't get a session id case 1: { const char *user = Multi_tracker_login; const char *passwd = Multi_tracker_passwd; if (Is_standalone) { if ( strlen(Multi_options_g.std_pxo_login) ) { user = Multi_options_g.std_pxo_login; } if ( strlen(Multi_options_g.std_pxo_password) ) { passwd = Multi_options_g.std_pxo_password; } } ml_printf("FS2NetD ERROR: Login %s/%s is invalid!", user, passwd); if (strlen(user) == 0) { strcpy_s(error_str, "Login failed! No username supplied. Go to options -> multi options and add one"); strcpy_s(std_error_str, "Login failed! No username!"); } else if (strlen(passwd) == 0) { strcpy_s(error_str, "Login failed! No password supplied. Go to options -> multi options and add one"); strcpy_s(std_error_str, "Login failed! No password!"); } else { strcpy_s(error_str, "Login failed!"); strcpy_s(std_error_str, "Login failed!"); } retval = false; break; } // unknown failure fetching pilot data case 2: ml_string("FS2NetD ERROR: UNKNOWN ERROR when fetching pilot data"); strcpy_s(error_str, "An Unknown Error (probably a timeout) occured when trying to retrieve your pilot data."); strcpy_s(std_error_str, "Unknown Error (timeout?)"); retval = false; break; // success!! case 3: ml_string("FS2NetD MSG: Got Pilot data"); retval = true; break; // success!! pilot was created case 4: ml_string("FS2NetD MSG: Created New Pilot"); strcpy_s(error_str, "New Pilot has been created."); strcpy_s(std_error_str, "New Pilot has been created."); retval = true; break; // invalid pilot name case 5: ml_string("FS2NetD ERROR: Invalid Pilot!"); strcpy_s(error_str, "Invalid pilot name - A serious error has occured, Contact the FS2NetD Administrator!"); strcpy_s(std_error_str, "Invalid pilot name!"); retval = false; break; // the session id was invalid case 6: ml_string("FS2NetD ERROR: Invalid SID!"); strcpy_s(error_str, "Invalid SID - A serious error has occured, Contact the FS2NetD Administrator!"); strcpy_s(std_error_str, "Invalid SID"); retval = false; break; default: ml_string("FS2NetD ERROR: Unknown return case for GetPlayerData()"); strcpy_s(error_str, "Unknown return case from GetPlayerData(). Contact the FS2NetD Administrator!"); retval = false; break; } if ( !Is_standalone && strlen(error_str) ) { popup(PF_USE_AFFIRMATIVE_ICON, 1, POPUP_OK, error_str); } else if ( Is_standalone && std_gen_is_active() && strlen(std_error_str) ) { std_gen_set_text(std_error_str, 1); Sleep(2000); } if (retval) { Logged_in = true; sprintf(Multi_tracker_id_string, "%d", Multi_tracker_id); } else { // clear and reset connection, for the next time we try... fs2netd_disconnect(); } if (Is_standalone) { std_destroy_gen_dialog(); } return retval; }
int fs2netd_update_valid_tables() { int rc; int hacked = 0; if ( !Logged_in ) { return -1; } // if there are no tables to check with then bail if ( Table_valid_status.empty() ) { return -1; } // if we're a standalone, show a dialog saying "validating tables" if (Game_mode & GM_STANDALONE_SERVER) { std_create_gen_dialog("Validating tables"); std_gen_set_text("Querying FS2NetD:", 1); } do_full_packet = true; In_process = true; if (Is_standalone) { do { rc = fs2netd_update_valid_tables_do(); } while (!rc); } else { rc = popup_till_condition(fs2netd_update_valid_tables_do, XSTR("&Cancel", 779), XSTR("Starting table validation", 1592)); } In_process = false; Local_timeout = -1; switch (rc) { // canceled by popup case 0: return -1; // timed out case 1: { if ( !Is_standalone ) { popup(PF_USE_AFFIRMATIVE_ICON, 1, POPUP_OK, XSTR("Table validation timed out!", 1593)); } return -1; } // no tables case 2: { if ( !Is_standalone ) { popup(PF_USE_AFFIRMATIVE_ICON, 1, POPUP_OK, XSTR("No tables are available from the server for validation!", 1594)); } return -1; } } // output the status of table validity to multi.log for (SCP_vector<crc_valid_status>::iterator tvs = Table_valid_status.begin(); tvs != Table_valid_status.end(); ++tvs) { if (tvs->valid) { ml_printf("FS2NetD Table Check: '%s' -- Valid!", tvs->name); } else { ml_printf("FS2NetD Table Check: '%s' -- INVALID (0x%x)!", tvs->name, tvs->crc32); hacked = 1; } } // if we're a standalone, kill the validate dialog if (Game_mode & GM_STANDALONE_SERVER) { std_destroy_gen_dialog(); } return hacked; }
bool fs2netd_get_valid_missions() { int rc = 0; // don't bother with this if we aren't on FS2NetD if ( !Om_tracker_flag ) { return false; } if ( !(Game_mode & GM_MULTIPLAYER) ) { return false; } // maybe try to init first fs2netd_connect(); // if we didn't connect to FS2NetD then bail out now if ( !Is_connected ) { return false; } do_full_packet = 1; In_process = true; if (Is_standalone) { do { rc = fs2netd_get_valid_missions_do(); } while (!rc); } else { rc = popup_till_condition(fs2netd_get_valid_missions_do, XSTR("&Cancel", 779), XSTR("Starting mission validation", -1)); } In_process = false; if (FS2NetD_file_list != NULL) { delete[] FS2NetD_file_list; FS2NetD_file_list = NULL; } FS2NetD_file_list_count = -1; switch (rc) { // canceled by popup case 0: return false; // timed out case 1: if ( !Is_standalone ) { popup(PF_USE_AFFIRMATIVE_ICON, 1, POPUP_OK, XSTR("Mission validation timed out!", -1)); } return false; // no missions case 2: if ( !Is_standalone ) { popup(PF_USE_AFFIRMATIVE_ICON, 1, POPUP_OK, XSTR("No missions are available from the server for validation!", -1)); } return false; // out of memory case 3: if ( !Is_standalone ) { popup(PF_USE_AFFIRMATIVE_ICON, 1, POPUP_OK, XSTR("Memory error during mission validation!", -1)); } return false; } return true; }
int fs2netd_load_servers() { int rc = 0; // don't bother with this if we aren't on FS2NetD if ( !Om_tracker_flag ) { return 0; } if ( !(Game_mode & GM_MULTIPLAYER) ) { return 0; } if ( !Is_connected ) { return 0; } // free up any existing server list multi_free_server_list(); do_full_packet = 1; In_process = true; if (Is_standalone) { do { rc = fs2netd_load_servers_do(); } while (!rc); } else { rc = popup_till_condition(fs2netd_load_servers_do, XSTR("&Cancel", 779), XSTR("Requesting list of servers", -1)); } In_process = false; switch (rc) { // operation canceled case 0: return 0; // successful case 1: return 1; // failed to send request packet case 2: if ( !Is_standalone ) { popup(PF_USE_AFFIRMATIVE_ICON, 1, POPUP_OK, XSTR("Server request failed!", -1)); } return -1; // it timed out case 3: if ( !Is_standalone ) { popup(PF_USE_AFFIRMATIVE_ICON, 1, POPUP_OK, XSTR("Server request timed out!", -1)); } return -1; } return 0; }
bool fs2netd_login() { bool retval = true; int rc; // don't bother with this if we aren't on FS2NetD if ( !Om_tracker_flag ) { return false; } if ( !(Game_mode & GM_MULTIPLAYER) ) { return false; } if ( Logged_in ) { if ( (PXO_SID != -1) && !(FS2NetD_CheckValidSID(PXO_SID)) ) { PXO_SID = -1; } else { return true; } } fs2netd_connect(); if ( !Is_connected ) { if ( !Is_standalone ) { popup(PF_USE_AFFIRMATIVE_ICON, 1, POPUP_OK, XSTR("Failed to connect to FS2NetD server!", -1)); } return false; } char error_str[256]; do_full_packet = 1; In_process = true; if (Is_standalone) { do { rc = fs2netd_login_do(); } while (!rc); } else { rc = popup_till_condition(fs2netd_login_do, XSTR("&Cancel", 779), XSTR("Logging into FS2NetD", -1)); } In_process = false; memset( error_str, 0, sizeof(error_str) ); switch (rc) { // the action was cancelled case 0: retval = false; break; // didn't get a session id case 1: ml_printf("FS2NetD ERROR: Login %s/%s is invalid!", Multi_tracker_login, Multi_tracker_passwd); strcpy(error_str, "Login failed!"); retval = false; break; // unknown failure fetching pilot data case 2: ml_printf("FS2NetD ERROR: UNKNOWN ERROR when fetching pilot data"); strcpy(error_str, "An Unknown Error (probably a timeout) occured when trying to retrieve your pilot data."); retval = false; break; // success!! case 3: ml_printf("FS2NetD MSG: Got Pilot data"); retval = true; break; // success!! pilot was created case 4: ml_printf("FS2NetD MSG: Created New Pilot"); strcpy(error_str, "New Pilot has been created."); retval = true; break; // invalid pilot name case 5: ml_printf("FS2NetD ERROR: Invalid Pilot!"); strcpy(error_str, "Invalid Pilot name - A serious error has occured, Contact the FS2NetD Administrator!"); retval = false; break; // the session id was invalid case 6: ml_printf("FS2NetD ERROR: Invalid SID!"); strcpy(error_str, "Invalid SID - A serious error has occured, Contact the FS2NetD Administrator!"); retval = false; break; default: ml_printf("FS2NetD ERROR: Unknown return case for GetPlayerData()"); strcpy(error_str, "Unkown return case from GetPlayerData(). Contact the FS2NetD Administrator!"); retval = false; break; } if ( !Is_standalone && strlen(error_str) ) { popup(PF_USE_AFFIRMATIVE_ICON, 1, POPUP_OK, error_str); } if (retval) { Logged_in = true; } return retval; }
int fs2netd_update_valid_tables() { int rc; int hacked = 0; // if there are no tables to check with then bail if ( Table_valid_status.empty() ) { return -1; } // if we're not on FS2NetD then don't bother with this function if ( !Om_tracker_flag && (Game_mode & GM_MULTIPLAYER) ) { return -1; } // maybe try to init first fs2netd_connect(); // if we didn't connect to FS2NetD then bail out now if ( !Is_connected ) { return -1; } // if we're a standalone, show a dialog saying "validating tables" if (Game_mode & GM_STANDALONE_SERVER) { std_create_gen_dialog("Validating tables"); std_gen_set_text("Querying FS2NetD:", 1); } do_full_packet = 1; In_process = true; if (Is_standalone) { do { rc = fs2netd_update_valid_tables_do(); } while (!rc); } else { rc = popup_till_condition(fs2netd_update_valid_tables_do, XSTR("&Cancel", 779), XSTR("Starting table validation", -1)); } In_process = false; switch (rc) { // canceled by popup case 0: return -1; // timed out case 1: { if ( !Is_standalone ) { popup(PF_USE_AFFIRMATIVE_ICON, 1, POPUP_OK, XSTR("Table validation timed out!", -1)); } return -1; } // no tables case 2: { if ( !Is_standalone ) { popup(PF_USE_AFFIRMATIVE_ICON, 1, POPUP_OK, XSTR("No tables are available from the server for validation!", -1)); } return -1; } } // output the status of table validity to multi.log for (uint i = 0; i < Table_valid_status.size(); i++) { if (Table_valid_status[i].valid) { ml_printf("FS2NetD Table Check: '%s' -- Valid!", Table_valid_status[i].name); } else { ml_printf("FS2NetD Table Check: '%s' -- INVALID (0x%x)!", Table_valid_status[i].name, Table_valid_status[i].crc32); hacked = 1; } } // if we're a standalone, kill the validate dialog if (Game_mode & GM_STANDALONE_SERVER) { std_destroy_gen_dialog(); } return hacked; }