// exiting screen without canceling, so load in the new pilot selected here
int barracks_pilot_accepted()
{
	// check if pilot active.  If not, don't allow accept.
	if (!Cur_pilot->callsign[0]){
		return -1;
	}

	// check that pilot language is OK
	if (!valid_pilot_lang(Cur_pilot->callsign)) {
		popup(PF_USE_AFFIRMATIVE_ICON,1,POPUP_OK,XSTR(
			"Selected pilot was created with a different language\n"
			"to the currently active language.\n\n"
			"Please select a different pilot or change the language", 1637));
		return -1;
	}

	// set pilot image
	if (Game_mode & GM_MULTIPLAYER) {
		player_set_squad_bitmap(Cur_pilot, Cur_pilot->m_squad_filename, true);
	} else {
		player_set_squad_bitmap(Cur_pilot, Cur_pilot->s_squad_filename, false);
	}

	// MWA -- I think that we should be writing Cur_pilot here.
	Pilot.save_player(Cur_pilot);

	os_config_write_string(NULL, "LastPlayer", Cur_pilot->callsign);

	return 0;
}
// exiting screen without canceling, so load in the new pilot selected here
int pilot_manage_pilot_accepted()
{
	char str[CALLSIGN_LEN + 1];

	// check if pilot active.  If not, don't allow accept.
	if (!Cur_pilot->callsign[0]){
		return -1;
	}

	// set his image 
	player_set_squad_bitmap(Cur_pilot, Cur_pilot->squad_filename);

//	Skill_level = get_default_skill_level();

	// MWA -- I think that we should be writing Cur_pilot here.
	//write_pilot_file(!is_pilot_multi(Cur_pilot));
	write_pilot_file( Cur_pilot );
	
	// when we store the LastPlayer key, we have to mark it as being single or multiplayer, so we know where to look for him
	// (since we could have a single and a multiplayer pilot with the same callsign)
	// we'll distinguish them by putting an M and the end of the multiplayer callsign and a P at the end of a single player
	strcpy(str, Cur_pilot->callsign);
	strcat(str, is_pilot_multi(Cur_pilot) ? NOX("M") : NOX("S"));
		
	os_config_write_string( NULL, "LastPlayer", str );
	return 0;
}
// If app_name is NULL or ommited, then TITLE is used
// for the app name, which is where registry keys are stored.
void os_init(const char * wclass, const char * title, const char *app_name, const char *version_string )
{
	// create default ini entries for the user
	if (os_config_read_string(NULL, NOX("VideocardFs2open"), NULL) == NULL)
		os_config_write_string(NULL, NOX("VideocardFs2open"), NOX("OGL -(640x480)x16 bit"));

	os_init_registry_stuff(Osreg_company_name, title, version_string);
	
	strcpy_s( szWinTitle, title );
	strcpy_s( szWinClass, wclass );	

	INITIALIZE_CRITICAL_SECTION( Os_lock );

	unix_process(0);

	// initialized
	Os_inited = 1;

	atexit(os_deinit);
}
// exiting screen without canceling, so load in the new pilot selected here
int barracks_pilot_accepted()
{
	// check if pilot active.  If not, don't allow accept.
	if (!Cur_pilot->callsign[0]){
		return -1;
	}

	// set pilot image
	if (Game_mode & GM_MULTIPLAYER) {
		player_set_squad_bitmap(Cur_pilot, Cur_pilot->m_squad_filename, true);
	} else {
		player_set_squad_bitmap(Cur_pilot, Cur_pilot->s_squad_filename, false);
	}

	// MWA -- I think that we should be writing Cur_pilot here.
	Pilot.save_player(Cur_pilot);

	os_config_write_string(NULL, "LastPlayer", Cur_pilot->callsign);

	return 0;
}
Exemple #5
0
bool pilotfile::load_player(const char *callsign, player *_p)
{
    // if we're a standalone server in multiplayer, just fill in some bogus values
    // since we don't have a pilot file
    if ( (Game_mode & GM_MULTIPLAYER) && (Game_mode & GM_STANDALONE_SERVER) ) {
        Player->insignia_texture = -1;
        strcpy_s(Player->callsign, NOX("Standalone"));
        strcpy_s(Player->short_callsign, NOX("Standalone"));

        return true;
    }

    // set player ptr first thing
    p = _p;

    if ( !p ) {
        Assert( (Player_num >= 0) && (Player_num < MAX_PLAYERS) );
        p = &Players[Player_num];
    }

    filename = callsign;
    filename += ".plr";

    if ( filename.size() == 4 ) {
        mprintf(("PLR => Invalid filename '%s'!\n", filename.c_str()));
        return false;
    }

    cfp = cfopen((char*)filename.c_str(), "rb", CFILE_NORMAL, CF_TYPE_PLAYERS);

    if ( !cfp ) {
        mprintf(("PLR => Unable to open '%s' for reading!\n", filename.c_str()));
        return false;
    }

    unsigned int plr_id = cfread_uint(cfp);

    if (plr_id != PLR_FILE_ID) {
        mprintf(("PLR => Invalid header id for '%s'!\n", filename.c_str()));
        plr_close();
        return false;
    }

    // version, should be able to just ignore it
    version = cfread_ubyte(cfp);

    mprintf(("PLR => Loading '%s' with version %d...\n", filename.c_str(), version));

    plr_reset_data();

    // the point of all this: read in the PLR contents
    while ( !cfeof(cfp) ) {
        ushort section_id = cfread_ushort(cfp);
        uint section_size = cfread_uint(cfp);

        size_t start_pos = cftell(cfp);

        // safety, to help protect against long reads
        cf_set_max_read_len(cfp, section_size);

        try {
            switch (section_id) {
            case Section::Flags:
                mprintf(("PLR => Parsing:  Flags...\n"));
                m_have_flags = true;
                plr_read_flags();
                break;

            case Section::Info:
                mprintf(("PLR => Parsing:  Info...\n"));
                m_have_info = true;
                plr_read_info();
                break;

            case Section::Variables:
                mprintf(("PLR => Parsing:  Variables...\n"));
                plr_read_variables();
                break;

            case Section::HUD:
                mprintf(("PLR => Parsing:  HUD...\n"));
                plr_read_hud();
                break;

            case Section::Scoring:
                mprintf(("PLR => Parsing:  Scoring...\n"));
                plr_read_stats();
                break;

            case Section::ScoringMulti:
                mprintf(("PLR => Parsing:  ScoringMulti...\n"));
                plr_read_stats_multi();
                break;

            case Section::Multiplayer:
                mprintf(("PLR => Parsing:  Multiplayer...\n"));
                plr_read_multiplayer();
                break;

            case Section::Controls:
                mprintf(("PLR => Parsing:  Controls...\n"));
                plr_read_controls();
                break;

            case Section::Settings:
                mprintf(("PLR => Parsing:  Settings...\n"));
                plr_read_settings();
                break;

            default:
                mprintf(("PLR => Skipping unknown section 0x%04x!\n", section_id));
                break;
            }
        } catch (cfile::max_read_length &msg) {
            // read to max section size, move to next section, discarding
            // extra/unknown data
            mprintf(("PLR => (0x%04x) %s\n", section_id, msg.what()));
        } catch (const char *err) {
            mprintf(("PLR => ERROR: %s\n", err));
            plr_close();
            return false;
        }

        // reset safety catch
        cf_set_max_read_len(cfp, 0);

        // skip to next section (if not already there)
        size_t offset_pos = (start_pos + section_size) - cftell(cfp);

        if (offset_pos) {
            cfseek(cfp, offset_pos, CF_SEEK_CUR);
        }
    }

    // restore the callsign into the Player structure
    strcpy_s(p->callsign, callsign);

    // restore the truncated callsign into Player structure
    pilot_set_short_callsign(p, SHORT_CALLSIGN_PIXEL_W);

    player_set_squad_bitmap(p, p->m_squad_filename, true);

    hud_squadmsg_save_keys();

    // set last pilot
    os_config_write_string(NULL, "LastPlayer", (char*)callsign);

    mprintf(("PLR => Loading complete!\n"));

    // cleanup and return
    plr_close();

    return true;
}