static void fs2netd_store_stats_results() { char str[512]; memset(str, 0, sizeof(str)); multi_display_chat_msg(XSTR("<PXO stats store process complete>", 1001), 0, 0); ml_string( XSTR("<PXO stats store process complete>", 1001) ); if (Multi_debrief_stats_accept_code != 1) { sprintf(str, XSTR("<PXO stats store failed for player %s>", 1002), Net_player->m_player->callsign); multi_display_chat_msg(str, 0, 0); ml_string(str); } }
void fs2netd_gameserver_update(bool force) { if ( !Logged_in ) { return; } // server hasn't started yet? if ( !(Net_player->flags & NETINFO_FLAG_MT_CONNECTED) ) { return; } // is it actually time for an update if ( !force && (timer_get_seconds() < Next_gameserver_update) ) { return; } strcpy_s(Multi_tracker_game_data.mission_name, Netgame.mission_name); strcpy_s(Multi_tracker_game_data.title, Netgame.title); strcpy_s(Multi_tracker_game_data.campaign_name, Netgame.campaign_name); Multi_tracker_game_data.campaign_mode = (ubyte)Netgame.campaign_mode; Multi_tracker_game_data.players = (short)multi_num_players(); Multi_tracker_game_data.game_state = (ubyte)Netgame.game_state; FS2NetD_SendServerUpdate(); // set timeout for every 2 minutes Next_gameserver_update = timer_get_seconds() + 120; ml_string("FS2NetD sent game server update"); }
// write the standard shutdown trailer void multi_log_write_trailer() { char str[1024]; time_t timer; // header message timer = time(NULL); strftime(str, 1024, "\n\n----\n----\n----\nFreespace Multi Log - Closing on %a, %b %d, %Y at %I:%M%p", localtime(&timer)); ml_string(str, 0); }
// write the standard header to the logfile void multi_log_write_header() { char str[1024]; time_t timer; // header message timer = time(NULL); strftime(str, 1024, "Freespace Multi Log - Opened %a, %b %d, %Y at %I:%M%p\n----\n----\n----\n\n", localtime(&timer)); ml_string(str, 0); }
void fs2netd_gameserver_disconnect() { if ( !Logged_in ) { return; } // server hasn't started yet? if ( !(Net_player->flags & NETINFO_FLAG_MT_CONNECTED) ) { return; } FS2NetD_SendServerDisconnect(); Net_player->flags &= ~NETINFO_FLAG_MT_CONNECTED; ml_string("FS2NetD sent game server disconnect"); }
/* arguments: unit -> string list * * To avoid consing up the list each time this is called, the list * is created once and cached. This is the reason for the declare_root * with no corresponding retract_root. */ static mlval arguments(mlval unit) { static mlval result= DEAD; int i; if(result == DEAD) { result = MLNIL; declare_root(&result, 0); for(i=module_argc-1; i >= 0; --i) { mlval temp= ml_string(module_argv[i]); /* Do NOT inline this */ result= mlw_cons(temp, result); } } return result; }
// printf function itself called by the ml_printf macro void ml_printf(const char *format, ...) { char tmp[MAX_LOGFILE_LINE_LEN*4]; va_list args; // if we don't have a valid logfile do nothing if(Multi_log_out == NULL){ return; } // format the text va_start(args, format); vsprintf(tmp, format, args); va_end(args); // log the string ml_string(tmp); }
static mlval word32_to_string(mlval argument) { word *item; char *str; mlval result; /* The maximum value of a Word32 is 2^32-1 = 4294967295. This is 10 characters. Add 1 for the trailing null, and 2 for the leading 0w. */ str = (char *) malloc (13); item = CWORD32(argument); sprintf(str, "0w%lu", (unsigned long) *item); result = ml_string (str); free (str); return(result); }
void fs2netd_gameserver_start() { if ( !Logged_in ) { return; } // already been here if (Net_player->flags & NETINFO_FLAG_MT_CONNECTED) { return; } memset(&Multi_tracker_game_data, 0, sizeof(tracker_game_data)); strcpy_s(Multi_tracker_game_data.name, Netgame.name); strcpy_s(Multi_tracker_game_data.mission_name, Netgame.mission_name); strcpy_s(Multi_tracker_game_data.title, Netgame.title); strcpy_s(Multi_tracker_game_data.campaign_name, Netgame.campaign_name); if ( strlen(Multi_fs_tracker_channel) ) { strcpy_s(Multi_tracker_game_data.chat_channel, Multi_fs_tracker_channel); } Multi_tracker_game_data.campaign_mode = (ubyte)Netgame.campaign_mode; Multi_tracker_game_data.flags = Netgame.flags; Multi_tracker_game_data.type_flags = Netgame.type_flags; Multi_tracker_game_data.players = (short)multi_num_players(); Multi_tracker_game_data.max_players = (short)Netgame.max_players; Multi_tracker_game_data.mode = (ubyte)Netgame.mode; Multi_tracker_game_data.rank_base = (ubyte)Netgame.rank_base; Multi_tracker_game_data.game_state = (ubyte)Netgame.game_state; Multi_tracker_game_data.speed = (ubyte)multi_get_connection_speed(); FS2NetD_SendServerStart(); Net_player->flags |= NETINFO_FLAG_MT_CONNECTED; // initial update should be about 2 seconds from now Next_gameserver_update = timer_get_seconds() + 2; ml_string("FS2NetD sent game server start"); }
extern MLvalue c2ml_string(char *obj) { return_MLvalue( ml_string( (const char *)obj ) ); }
static mlval name(mlval unit) { mlval string = ml_string(runtime); return string; }
extern mlval unix_rusage(mlval unit) { mlval utime, stime, result; /* on Solaris we can't do getrusage without the BSD-compatibility * library, which sucks, so we have to fake it : */ prusage_t usage; prpsinfo_t psinfo; if (pioc(PIOCPSINFO,&psinfo) == -1 || pioc(PIOCUSAGE,&usage) == -1) exn_raise_syserr(ml_string(strerror(errno)), errno); utime = ml_time(&usage.pr_utime); declare_root(&utime, 0); stime = ml_time(&usage.pr_stime); declare_root(&stime, 0); result = allocate_record(16); retract_root(&utime); retract_root(&stime); /* Lexical ordering for fields -- the result is a record with name fields. * * idrss integral resident set size * inblock block input operations * isrss currently 0 * ixrss currently 0 * majflt page faults requiring physical I/O * maxrss maximum resident set size Solaris : resident set size * minflt page faults not requiring physical I/O * msgrcv messages received * msgsnd messages sent * nivcsw involuntary context switches * nsignals signals received * nswap swaps voluntary * nvcsw context switches * oublock block output operations * stime system time used * utime user time used */ FIELD(result, 0) = MLINT(psinfo.pr_rssize); FIELD(result, 1) = MLINT(usage.pr_inblk); FIELD(result, 2) = MLINT(0); FIELD(result, 3) = MLINT(0); FIELD(result, 4) = MLINT(usage.pr_majf); FIELD(result, 5) = MLINT(psinfo.pr_rssize); FIELD(result, 6) = MLINT(usage.pr_minf); FIELD(result, 7) = MLINT(usage.pr_msnd); FIELD(result, 8) = MLINT(usage.pr_mrcv); FIELD(result, 9) = MLINT(usage.pr_ictx); FIELD(result, 10) = MLINT(usage.pr_sigs); FIELD(result, 11) = MLINT(usage.pr_nswap); FIELD(result, 12) = MLINT(usage.pr_vctx); FIELD(result, 13) = MLINT(usage.pr_oublk); FIELD(result, 14) = stime; FIELD(result, 15) = utime; return result; }
static void fs2netd_handle_ping() { static int CONN_check = -1; // if we didn't get a pong within 30 seconds of a ping then assume that the // server connection must of have dropped or is otherwise unresponsive if ( (Ping_timestamp != -1) && ((timer_get_seconds() - Ping_timestamp) > 30) ) { Ping_timestamp = -1; ml_string("FS2NetD WARNING: Lost connection to server!"); fs2netd_reset_connection(); // make sure that we are good to go if ( !Is_connected ) { if (!Is_standalone) { gamesnd_play_iface(SND_GENERAL_FAIL); popup(PF_USE_AFFIRMATIVE_ICON | PF_TITLE_BIG | PF_TITLE_RED, 1, POPUP_OK, "ERROR:\nLost connection to the FS2NetD server!"); } ml_string("FS2NetD ERROR: Lost connection to the FS2NetD server!"); fs2netd_disconnect(); ml_string("FS2NetD MSG: Will attempt an automatic reconnect to server in 5 minutes..."); Login_retry_time = timer_get_seconds() + 300; return; } else { ml_string("FS2NetD NOTICE: Connection to server has been reestablished!"); } } // send out a ping after 5 minutes of no other activity to make sure the server // is still responding (probably not though) if ( (Ping_timestamp == -1) && (timer_get_seconds() >= (Last_activity + 300)) ) { Ping_timestamp = timer_get_seconds(); FS2NetD_Ping(); ml_string("FS2NetD sent PING"); if (Last_activity < 0) { Last_activity = timer_get_seconds(); } } // check for a valid connection (SID, duplicate login, etc.) if ( (CONN_check == -1) || (timer_get_seconds() >= CONN_check) ) { // every 3 minutes CONN_check = timer_get_seconds() + 180; // session ID check if ( FS2NetD_CheckValidID() < 0 ) { ml_string("FS2NetD WARNING: Unable to validate login!"); fs2netd_reset_connection(); // make sure that we are good to go if ( !Is_connected ) { if (!Is_standalone) { gamesnd_play_iface(SND_GENERAL_FAIL); popup(PF_USE_AFFIRMATIVE_ICON | PF_TITLE_BIG | PF_TITLE_RED, 1, POPUP_OK, "ERROR:\nLost connection to the FS2NetD server!"); } ml_string("FS2NetD ERROR: Lost connection to the FS2NetD server!"); fs2netd_disconnect(); ml_string("FS2NetD MSG: Will attempt an automatic reconnect to server in 5 minutes..."); Login_retry_time = timer_get_seconds() + 300; return; } else { ml_string("FS2NetD NOTICE: Connection to server has been reestablished!"); } } // verify that we are only logged in once (for stats saving purposes) if ( (Netgame.game_state == NETGAME_STATE_BRIEFING) || (Netgame.game_state == NETGAME_STATE_MISSION_SYNC) ) { FS2NetD_CheckDuplicateLogin(); } ml_string("FS2NetD sent IDENT check"); } }
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_login_do() { if (Multi_tracker_id < 0) { if ( Is_standalone && std_gen_is_active() ) { std_gen_set_text("Verifying username and password", 1); } else { popup_change_text( XSTR("Verifying username and password", 1576) ); } memset(Multi_tracker_id_string, 0, sizeof(Multi_tracker_id_string)); if (Local_timeout == -1) { Local_timeout = timer_get_seconds() + 15; } // if timeout passes then bail on SID failure if ( timer_get_seconds() > Local_timeout ) { ml_string("FS2NetD MSG: Login failure due to timeout!"); Local_timeout = -1; return 2; } 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; } } Multi_tracker_id = FS2NetD_Login(user, passwd, do_full_packet); // if we have already been through once then only deal with the recieve packet next time do_full_packet = false; // invalid login if (Multi_tracker_id == -2) { Multi_tracker_id = -1; Local_timeout = -1; return 1; } if (Multi_tracker_id >= 0) { ml_printf("FS2NetD MSG: Login '%s' is valid, session ID is %d!", user, Multi_tracker_id); do_full_packet = true; Local_timeout = -1; } } else { if ( Is_standalone && std_gen_is_active() ) { std_gen_set_text("Getting pilot stats", 1); } else { popup_change_text( XSTR("Getting pilot stats", 1577) ); } if (Local_timeout == -1) { Local_timeout = timer_get_seconds() + 30; } // if timeout passes then bail on stats failure if ( timer_get_seconds() > Local_timeout ) { Local_timeout = -1; return 2; } if (do_full_packet) { ml_printf("FS2NetD MSG: Requesting login pilot stats for '%s' ...", Players[Player_num].callsign); } int rescode = FS2NetD_GetPlayerData(Players[Player_num].callsign, &Players[Player_num], true, do_full_packet); do_full_packet = false; if ( rescode != -1 ) { Local_timeout = -1; return (rescode + 3); } } return 0; }
void fs2netd_store_stats() { if ( !Logged_in ) { return; } ml_string("Sending stats to server"); // default to not saving the stats Multi_debrief_stats_accept_code = 0; if (Duplicate_login_detected) { Duplicate_login_detected = false; multi_display_chat_msg( XSTR("<Duplicate login detected - stats have been tossed>", 1582), 0, 0 ); ml_string( XSTR("<Duplicate login detected - stats have been tossed>", 1583) ); fs2netd_store_stats_results(); return; } if ( game_hacked_data() ) { multi_display_chat_msg( XSTR("<Hacked tables detected - stats have been tossed>", 1584), 0, 0 ); popup(PF_USE_AFFIRMATIVE_ICON, 1, POPUP_OK, XSTR("You are playing with a hacked tables, your stats will not be saved", 1585) ); fs2netd_store_stats_results(); return; } if ( (multi_num_players() <= 1) && (Multi_num_players_at_start <= 1) ) { multi_display_chat_msg(XSTR("<Not enough players were present at game start or end, stats will not be saved>", 1048), 0, 0); ml_string( XSTR("<Not enough players were present at game start or end, stats will not be saved>", 1048) ); fs2netd_store_stats_results(); return; } /* // if any players have hacked info for(int idx = 0; idx < MAX_PLAYERS; idx++) { if ( MULTI_CONNECTED(Net_players[idx]) && !MULTI_STANDALONE(Net_players[idx]) && (Net_players[idx].flags & NETINFO_FLAG_HAXOR) ) { multi_display_chat_msg( XSTR("<Connected player has hacked info - tossing invalid stats>", -1), 0, 0 ); return; } } */ if ( !fs2netd_check_mission(Netgame.mission_name) ) { 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)); fs2netd_store_stats_results(); return; } int spd_ret = fs2netd_send_player(); switch (spd_ret) { // 0 = pilot updated, 1 = invalid pilot, 2 = invalid (expired?) sid case -1: ml_string("<stats have been tossed - server error>"); break; case 0: ml_string( XSTR("<stats have been accepted>", 850) ); Multi_debrief_stats_accept_code = 1; break; case 1: ml_string("<stats have been tossed - pilot error>"); break; case 2: // we should never get here with the new code Int3(); ml_string("<stats have been tossed - invalid tracker id>"); break; default: multi_display_chat_msg( XSTR("Unknown Stats Store Request Reply", 1586), 0, 0 ); break; } fs2netd_store_stats_results(); }