/** * * @author OLiver */ bool SavedFile::ValidateFile(BinaryFile& file, unsigned int signature_length, const char* signature, unsigned short version) { char read_signature[32]; file.ReadRawData(read_signature, signature_length); // Signatur überprüfen if(memcmp(read_signature, signature, signature_length)) { // unterscheiden sich! --> raus LOG.lprintf("SavedFile::Load: ERROR: Not a valid file!\n"); return false; } // Programmversion überspringen file.Seek(8, SEEK_CUR); // Version überprüfen unsigned short read_version = file.ReadUnsignedShort(); if(read_version != version) { // anderes Dateiformat --> raus LOG.lprintf("SavedFile::Load: ERROR: Old file version (version: %u; expected: %u)!\n", read_version, version); return false; } return true; }
bool SavedFile::ValidateFile(BinaryFile& file, unsigned int signature_length, const char* signature, unsigned short version) { char read_signature[32]; file.ReadRawData(read_signature, signature_length); // Signatur überprüfen if(memcmp(read_signature, signature, signature_length) != 0) { // unterscheiden sich! --> raus LOG.lprintf("Error: File is not in a valid format! File path: %s\n", file.getFilePath().c_str()); return false; } // Programmversion überspringen file.Seek(8, SEEK_CUR); // Version überprüfen unsigned short read_version = file.ReadUnsignedShort(); if(read_version != version) { // anderes Dateiformat --> raus LOG.lprintf("Warning: File has an old version and cannot be used (version: %u; expected: %u, file path: %s)!\n", read_version, version, file.getFilePath().c_str()); return false; } return true; }
/** * liest die GlobalGameSettings aus der Datei. * * @author OLiver */ void SavedFile::ReadGGS(BinaryFile& file) { unsigned length = file.ReadUnsignedInt(); boost::interprocess::unique_ptr<unsigned char, Deleter<unsigned char[]> > buffer(new unsigned char[length]); file.ReadRawData(buffer.get(), length); Serializer ser(buffer.get(), length); ggs.Deserialize(ser); }
/** * liest die GlobalGameSettings aus der Datei. * * @author OLiver */ void SavedFile::ReadGGS(BinaryFile& file) { unsigned length = file.ReadUnsignedInt(); unsigned char* buffer = new unsigned char[length]; file.ReadRawData(buffer, length); Serializer ser(buffer, length); ggs.Deserialize(&ser); delete[] buffer; }
/** * * @author OLiver */ bool Savegame::Load(BinaryFile& file, const bool load_players, const bool load_sgd) { // Signatur und Version einlesen if(!ValidateFile(file, 8, SAVE_SIGNATURE, SAVE_VERSION)) { LOG.lprintf("Savegame::Load: ERROR: File is not a valid RTTR savegame!\n"); return false; } // Zeitstempel file.ReadRawData(&save_time, 8); // Map-Name file.ReadShortString(map_name); // Anzahl Spieler player_count = file.ReadUnsignedChar(); // Spielerzeug if(load_players) { // Größe des Spielerblocks überspringen file.Seek(4, SEEK_CUR); ReadPlayerData(file); } else { // Überspringen players = 0; unsigned player_size = file.ReadUnsignedInt(); file.Seek(player_size, SEEK_CUR); } // GGS ReadGGS(file); // Start-GF start_gf = file.ReadUnsignedInt(); if(load_sgd) { // Serialisiertes Spielzeug lesen sgd.ReadFromFile(file); } return true; }
/** * * @author OLiver */ bool Savegame::Load(BinaryFile& file, const bool load_players, const bool load_sgd) { // Signatur und Version einlesen if(!ValidateFile(file, sizeof(SAVE_SIGNATURE), SAVE_SIGNATURE, SAVE_VERSION)) return false; // Zeitstempel file.ReadRawData(&save_time, 8); save_time = libendian::ConvertEndianess<false>::toNative(save_time); // Map-Name map_name = file.ReadShortString(); // Anzahl Spieler SetPlayerCount(file.ReadUnsignedChar()); // Spielerzeug if(load_players) { // Größe des Spielerblocks überspringen file.Seek(4, SEEK_CUR); ReadPlayerData(file); } else { // Überspringen unsigned player_size = file.ReadUnsignedInt(); file.Seek(player_size, SEEK_CUR); } // GGS ReadGGS(file); // Start-GF start_gf = file.ReadUnsignedInt(); if(load_sgd) { // Serialisiertes Spielzeug lesen sgd.ReadFromFile(file); } return true; }
bool Savegame::Load(BinaryFile& file, const bool load_players, const bool load_sgd) { // Signatur und Version einlesen if(!ReadFileHeader(file)) return false; // Zeitstempel file.ReadRawData(&save_time, sizeof(save_time)); save_time = libendian::ConvertEndianess<false>::toNative(save_time); // Map-Name mapName = file.ReadShortString(); ReadPlayerData(file); ReadGGS(file); // Start-GF start_gf = file.ReadUnsignedInt(); if(load_sgd) sgd.ReadFromFile(file); // Serialisiertes Spielzeug lesen return true; }
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; }