Exemplo n.º 1
0
/**
 *
 *  @author OLiver
 */
bool Savegame::Save(BinaryFile& file)
{
    // Versionszeug schreiben
    WriteVersion(file, 8, SAVE_SIGNATURE, SAVE_VERSION);

    // Timestamp der Aufzeichnung
    unser_time_t tmpTime = libendian::ConvertEndianess<false>::fromNative(save_time);
    file.WriteRawData(&tmpTime, 8);

    // Mapname
    file.WriteShortString(map_name);

    // Anzahl Spieler
    file.WriteUnsignedChar(GetPlayerCount());

    // Größe der Spielerdaten (später ausfüllen)
    unsigned players_size = 0;
    unsigned players_pos = file.Tell();
    file.WriteUnsignedInt(players_size);

    // Spielerdaten
    WritePlayerData(file);

    // Wieder zurückspringen und Größe des Spielerblocks eintragen
    unsigned new_pos = file.Tell();
    file.Seek(players_pos, SEEK_SET);
    file.WriteUnsignedInt(new_pos - players_pos - 4);
    file.Seek(new_pos, SEEK_SET);

    // GGS
    WriteGGS(file);

    // Start-GF
    file.WriteUnsignedInt(start_gf);

    // Serialisiertes Spielzeug reinschreiben
    sgd.WriteToFile(file);

    return true;
}
Exemplo n.º 2
0
bool DebugInfo::SendReplay()
{
    LOG.lprintf("Sending replay...\n");

    // Replay mode is on, no recording of replays active
    if (!GAMECLIENT.IsReplayModeOn())
    {
        Replay rpl = GAMECLIENT.GetReplay();

        if(!rpl.IsValid())
            return true;

        BinaryFile* f = rpl.GetFile();

        if(!f) // no replay to send
            return true;

        f->Flush();

        unsigned replay_len = f->Tell();

        LOG.lprintf("- Replay length: %u\n", replay_len);

        boost::interprocess::unique_ptr<char, Deleter<char[]> > replay(new char[replay_len]);

        f->Seek(0, SEEK_SET);

        f->ReadRawData(replay.get(), replay_len);

        unsigned int compressed_len = replay_len * 2 + 600;
        boost::interprocess::unique_ptr<char, Deleter<char[]> > compressed(new char[compressed_len]);

        // send size of replay via socket
        if (!SendString("Replay"))
        {
            return false;
        }

        LOG.lprintf("- Compressing...\n");
        if (BZ2_bzBuffToBuffCompress(compressed.get(), (unsigned int*) &compressed_len, replay.get(), replay_len, 9, 0, 250) == BZ_OK)
        {
            LOG.lprintf("- Sending...\n");

            if (SendString(compressed.get(), compressed_len))
            {
                LOG.lprintf("-> success\n");
                return true;
            }

            LOG.lprintf("-> Sending replay failed :(\n");
        }
        else
        {
            LOG.lprintf("-> BZ2 compression failed.\n");
        }

        SendUnsigned(0);
        return false;
    }
    else
    {
        LOG.lprintf("-> Already in replay mode, do not send replay\n");
    }

    return true;
}