From 683ab3a154a40f13dd1bcd54ba111f7b21e98483 Mon Sep 17 00:00:00 2001 From: Rui Date: Mon, 12 Jun 2017 04:20:50 +0900 Subject: [PATCH] Fix the serialization error by ff73c7a (#5964) --- src/network/networkprotocol.h | 5 ++-- src/nodedef.cpp | 53 +++++++++++++++++++---------------- 2 files changed, 32 insertions(+), 26 deletions(-) diff --git a/src/network/networkprotocol.h b/src/network/networkprotocol.h index f003cf26a..8304d3003 100644 --- a/src/network/networkprotocol.h +++ b/src/network/networkprotocol.h @@ -158,10 +158,11 @@ with this program; if not, write to the Free Software Foundation, Inc., PROTOCOL VERSION 33: Add TOCLIENT_UPDATE_PLAYER_LIST and send the player list to the client, instead of guessing based on the active object list. - + PROTOCOL VERSION 34: + Add sound pitch */ -#define LATEST_PROTOCOL_VERSION 33 +#define LATEST_PROTOCOL_VERSION 34 // Server's supported network protocol range #define SERVER_PROTOCOL_VERSION_MIN 24 diff --git a/src/nodedef.cpp b/src/nodedef.cpp index 02e967384..db7e36620 100644 --- a/src/nodedef.cpp +++ b/src/nodedef.cpp @@ -248,17 +248,21 @@ void TileDef::deSerialize(std::istream &is, const u8 contenfeatures_version, con */ static void serializeSimpleSoundSpec(const SimpleSoundSpec &ss, - std::ostream &os) + std::ostream &os, u8 version) { os<= 11) + writeF1000(os, ss.pitch); } -static void deSerializeSimpleSoundSpec(SimpleSoundSpec &ss, std::istream &is) +static void deSerializeSimpleSoundSpec(SimpleSoundSpec &ss, std::istream &is, u8 version) { ss.name = deSerializeString(is); ss.gain = readF1000(is); - ss.pitch = readF1000(is); + + if (version >= 11) + ss.pitch = readF1000(is); } void TextureSettings::readSettings() @@ -386,7 +390,8 @@ void ContentFeatures::serialize(std::ostream &os, u16 protocol_version) const } // version - writeU8(os, 10); + u8 version = (protocol_version >= 34) ? 11 : 10; + writeU8(os, version); // general os << serializeString(name); @@ -462,9 +467,9 @@ void ContentFeatures::serialize(std::ostream &os, u16 protocol_version) const collision_box.serialize(os, protocol_version); // sound - serializeSimpleSoundSpec(sound_footstep, os); - serializeSimpleSoundSpec(sound_dig, os); - serializeSimpleSoundSpec(sound_dug, os); + serializeSimpleSoundSpec(sound_footstep, os, version); + serializeSimpleSoundSpec(sound_dig, os, version); + serializeSimpleSoundSpec(sound_dug, os, version); // legacy writeU8(os, legacy_facedir_simple); @@ -493,7 +498,7 @@ void ContentFeatures::deSerialize(std::istream &is) if (version < 9) { deSerializeOld(is, version); return; - } else if (version > 10) { + } else if (version > 11) { throw SerializationError("unsupported ContentFeatures version"); } @@ -575,9 +580,9 @@ void ContentFeatures::deSerialize(std::istream &is) collision_box.deSerialize(is); // sounds - deSerializeSimpleSoundSpec(sound_footstep, is); - deSerializeSimpleSoundSpec(sound_dig, is); - deSerializeSimpleSoundSpec(sound_dug, is); + deSerializeSimpleSoundSpec(sound_footstep, is, version); + deSerializeSimpleSoundSpec(sound_dig, is, version); + deSerializeSimpleSoundSpec(sound_dug, is, version); // read legacy properties legacy_facedir_simple = readU8(is); @@ -1606,9 +1611,9 @@ void ContentFeatures::serializeOld(std::ostream &os, u16 protocol_version) const selection_box.serialize(os, protocol_version); writeU8(os, legacy_facedir_simple); writeU8(os, legacy_wallmounted); - serializeSimpleSoundSpec(sound_footstep, os); - serializeSimpleSoundSpec(sound_dig, os); - serializeSimpleSoundSpec(sound_dug, os); + serializeSimpleSoundSpec(sound_footstep, os, 10); + serializeSimpleSoundSpec(sound_dig, os, 10); + serializeSimpleSoundSpec(sound_dug, os, 10); writeU8(os, rightclickable); writeU8(os, drowning); writeU8(os, leveled); @@ -1678,9 +1683,9 @@ void ContentFeatures::deSerializeOld(std::istream &is, int version) selection_box.deSerialize(is); legacy_facedir_simple = readU8(is); legacy_wallmounted = readU8(is); - deSerializeSimpleSoundSpec(sound_footstep, is); - deSerializeSimpleSoundSpec(sound_dig, is); - deSerializeSimpleSoundSpec(sound_dug, is); + deSerializeSimpleSoundSpec(sound_footstep, is, version); + deSerializeSimpleSoundSpec(sound_dig, is, version); + deSerializeSimpleSoundSpec(sound_dug, is, version); } else if (version == 6) { name = deSerializeString(is); groups.clear(); @@ -1728,9 +1733,9 @@ void ContentFeatures::deSerializeOld(std::istream &is, int version) selection_box.deSerialize(is); legacy_facedir_simple = readU8(is); legacy_wallmounted = readU8(is); - deSerializeSimpleSoundSpec(sound_footstep, is); - deSerializeSimpleSoundSpec(sound_dig, is); - deSerializeSimpleSoundSpec(sound_dug, is); + deSerializeSimpleSoundSpec(sound_footstep, is, version); + deSerializeSimpleSoundSpec(sound_dig, is, version); + deSerializeSimpleSoundSpec(sound_dug, is, version); rightclickable = readU8(is); drowning = readU8(is); leveled = readU8(is); @@ -1783,9 +1788,9 @@ void ContentFeatures::deSerializeOld(std::istream &is, int version) selection_box.deSerialize(is); legacy_facedir_simple = readU8(is); legacy_wallmounted = readU8(is); - deSerializeSimpleSoundSpec(sound_footstep, is); - deSerializeSimpleSoundSpec(sound_dig, is); - deSerializeSimpleSoundSpec(sound_dug, is); + deSerializeSimpleSoundSpec(sound_footstep, is, version); + deSerializeSimpleSoundSpec(sound_dig, is, version); + deSerializeSimpleSoundSpec(sound_dug, is, version); rightclickable = readU8(is); drowning = readU8(is); leveled = readU8(is);