From b7ee608e70f8e031e3e01c9672bedb16efa648b8 Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Tue, 29 Aug 2017 19:26:55 +0200 Subject: [PATCH] Bump minimal protocol version to 36 (#6319) * Bump minimal protocol version to 36 Item/Node/TileDef, NodeBox, TileAnimation: Remove old compat code * Accept future serialisation versions --- src/content_cao.cpp | 5 - src/itemdef.cpp | 67 +++--- src/network/networkprotocol.h | 8 +- src/nodedef.cpp | 412 ++++------------------------------ src/nodedef.h | 3 +- src/object_properties.cpp | 90 ++++---- src/tileanimation.cpp | 25 +-- src/tileanimation.h | 4 +- src/tool.cpp | 25 +-- 9 files changed, 136 insertions(+), 503 deletions(-) diff --git a/src/content_cao.cpp b/src/content_cao.cpp index c34b47d51..b3b6fa5f2 100644 --- a/src/content_cao.cpp +++ b/src/content_cao.cpp @@ -300,8 +300,6 @@ void GenericCAO::initialize(const std::string &data) m_is_visible = false; player->setCAO(this); } - if (m_client->getProtoVersion() < 33) - m_env->addPlayerName(m_name); } } @@ -337,9 +335,6 @@ void GenericCAO::processInitData(const std::string &data) GenericCAO::~GenericCAO() { - if (m_is_player && m_client->getProtoVersion() < 33) { - m_env->removePlayerName(m_name); - } removeFromScene(true); } diff --git a/src/itemdef.cpp b/src/itemdef.cpp index 3d8116bf6..f7d366c8a 100644 --- a/src/itemdef.cpp +++ b/src/itemdef.cpp @@ -128,7 +128,8 @@ void ItemDefinition::reset() void ItemDefinition::serialize(std::ostream &os, u16 protocol_version) const { - u8 version = (protocol_version >= 34) ? 4 : 3; + // protocol_version >= 36 + u8 version = 5; writeU8(os, version); writeU8(os, type); os << serializeString(name); @@ -158,14 +159,12 @@ void ItemDefinition::serialize(std::ostream &os, u16 protocol_version) const os << serializeString(sound_place_failed.name); writeF1000(os, sound_place_failed.gain); os << serializeString(palette_image); - writeU32(os, color.color); + writeARGB8(os, color); - if (version >= 4) { - writeF1000(os, sound_place.pitch); - writeF1000(os, sound_place_failed.pitch); - os << serializeString(inventory_overlay); - os << serializeString(wield_overlay); - } + writeF1000(os, sound_place.pitch); + writeF1000(os, sound_place_failed.pitch); + os << serializeString(inventory_overlay); + os << serializeString(wield_overlay); } void ItemDefinition::deSerialize(std::istream &is) @@ -175,8 +174,9 @@ void ItemDefinition::deSerialize(std::istream &is) // Deserialize int version = readU8(is); - if (version < 1 || version > 4) + if (version < 5) throw SerializationError("unsupported ItemDefinition version"); + type = (enum ItemType)readU8(is); name = deSerializeString(is); description = deSerializeString(is); @@ -200,38 +200,27 @@ void ItemDefinition::deSerialize(std::istream &is) int value = readS16(is); groups[name] = value; } - if(version == 1){ - // We cant be sure that node_placement_prediction is send in version 1 - try{ - node_placement_prediction = deSerializeString(is); - }catch(SerializationError &e) {}; - // Set the old default sound - sound_place.name = "default_place_node"; - sound_place.gain = 0.5; - } else if(version >= 2) { - node_placement_prediction = deSerializeString(is); - //deserializeSimpleSoundSpec(sound_place, is); - sound_place.name = deSerializeString(is); - sound_place.gain = readF1000(is); - } - if(version >= 3) { - range = readF1000(is); - } + + node_placement_prediction = deSerializeString(is); + //deserializeSimpleSoundSpec(sound_place, is); + sound_place.name = deSerializeString(is); + sound_place.gain = readF1000(is); + range = readF1000(is); + + sound_place_failed.name = deSerializeString(is); + sound_place_failed.gain = readF1000(is); + palette_image = deSerializeString(is); + color = readARGB8(is); + + sound_place.pitch = readF1000(is); + sound_place_failed.pitch = readF1000(is); + inventory_overlay = deSerializeString(is); + wield_overlay = deSerializeString(is); + // If you add anything here, insert it primarily inside the try-catch // block to not need to increase the version. - try { - sound_place_failed.name = deSerializeString(is); - sound_place_failed.gain = readF1000(is); - palette_image = deSerializeString(is); - color.set(readU32(is)); - - if (version >= 4) { - sound_place.pitch = readF1000(is); - sound_place_failed.pitch = readF1000(is); - inventory_overlay = deSerializeString(is); - wield_overlay = deSerializeString(is); - } - } catch(SerializationError &e) {}; + //try { + //} catch(SerializationError &e) {}; } /* diff --git a/src/network/networkprotocol.h b/src/network/networkprotocol.h index c90e9456a..7eefaccaa 100644 --- a/src/network/networkprotocol.h +++ b/src/network/networkprotocol.h @@ -176,18 +176,20 @@ with this program; if not, write to the Free Software Foundation, Inc., position Add settable player stepheight using existing object property. Breaks compatibility with older clients. + PROTOCOL VERSION 36: + Backwards compatibility drop */ -#define LATEST_PROTOCOL_VERSION 35 +#define LATEST_PROTOCOL_VERSION 36 // Server's supported network protocol range -#define SERVER_PROTOCOL_VERSION_MIN 24 +#define SERVER_PROTOCOL_VERSION_MIN 36 #define SERVER_PROTOCOL_VERSION_MAX LATEST_PROTOCOL_VERSION // Client's supported network protocol range // The minimal version depends on whether // send_pre_v25_init is enabled or not -#define CLIENT_PROTOCOL_VERSION_MIN 25 +#define CLIENT_PROTOCOL_VERSION_MIN 36 #define CLIENT_PROTOCOL_VERSION_MIN_LEGACY 24 #define CLIENT_PROTOCOL_VERSION_MAX LATEST_PROTOCOL_VERSION diff --git a/src/nodedef.cpp b/src/nodedef.cpp index dd3ceb021..89e9b4d46 100644 --- a/src/nodedef.cpp +++ b/src/nodedef.cpp @@ -63,19 +63,14 @@ void NodeBox::reset() void NodeBox::serialize(std::ostream &os, u16 protocol_version) const { - // Protocol >= 21 - int version = 2; - if (protocol_version >= 27) - version = 3; + // Protocol >= 36 + int version = 4; writeU8(os, version); switch (type) { case NODEBOX_LEVELED: case NODEBOX_FIXED: - if (version == 1) - writeU8(os, NODEBOX_FIXED); - else - writeU8(os, type); + writeU8(os, type); writeU16(os, fixed.size()); for (const aabb3f &nodebox : fixed) { @@ -94,16 +89,7 @@ void NodeBox::serialize(std::ostream &os, u16 protocol_version) const writeV3F1000(os, wall_side.MaxEdge); break; case NODEBOX_CONNECTED: - if (version <= 2) { - // send old clients nodes that can't be walked through - // to prevent abuse - writeU8(os, NODEBOX_FIXED); - - writeU16(os, 1); - writeV3F1000(os, v3f(-BS/2, -BS/2, -BS/2)); - writeV3F1000(os, v3f(BS/2, BS/2, BS/2)); - } else { - writeU8(os, type); + writeU8(os, type); #define WRITEBOX(box) \ writeU16(os, (box).size()); \ @@ -112,14 +98,13 @@ void NodeBox::serialize(std::ostream &os, u16 protocol_version) const writeV3F1000(os, i.MaxEdge); \ }; - WRITEBOX(fixed); - WRITEBOX(connect_top); - WRITEBOX(connect_bottom); - WRITEBOX(connect_front); - WRITEBOX(connect_left); - WRITEBOX(connect_back); - WRITEBOX(connect_right); - } + WRITEBOX(fixed); + WRITEBOX(connect_top); + WRITEBOX(connect_bottom); + WRITEBOX(connect_front); + WRITEBOX(connect_left); + WRITEBOX(connect_back); + WRITEBOX(connect_right); break; default: writeU8(os, type); @@ -130,7 +115,7 @@ void NodeBox::serialize(std::ostream &os, u16 protocol_version) const void NodeBox::deSerialize(std::istream &is) { int version = readU8(is); - if (version < 1 || version > 3) + if (version < 4) throw SerializationError("unsupported NodeBox version"); reset(); @@ -185,58 +170,38 @@ void NodeBox::deSerialize(std::istream &is) void TileDef::serialize(std::ostream &os, u16 protocol_version) const { - if (protocol_version >= 30) - writeU8(os, 4); - else if (protocol_version >= 29) - writeU8(os, 3); - else if (protocol_version >= 26) - writeU8(os, 2); - else - writeU8(os, 1); + // protocol_version >= 36 + u8 version = 5; + writeU8(os, version); os << serializeString(name); - animation.serialize(os, protocol_version); + animation.serialize(os, version); writeU8(os, backface_culling); - if (protocol_version >= 26) { - writeU8(os, tileable_horizontal); - writeU8(os, tileable_vertical); - } - if (protocol_version >= 30) { - writeU8(os, has_color); - if (has_color) { - writeU8(os, color.getRed()); - writeU8(os, color.getGreen()); - writeU8(os, color.getBlue()); - } + writeU8(os, tileable_horizontal); + writeU8(os, tileable_vertical); + writeU8(os, has_color); + if (has_color) { + writeU8(os, color.getRed()); + writeU8(os, color.getGreen()); + writeU8(os, color.getBlue()); } } -void TileDef::deSerialize(std::istream &is, const u8 contenfeatures_version, const NodeDrawType drawtype) +void TileDef::deSerialize(std::istream &is, u8 contentfeatures_version, + cNodeDrawType drawtype) { int version = readU8(is); name = deSerializeString(is); - animation.deSerialize(is, version >= 3 ? 29 : 26); - if (version >= 1) - backface_culling = readU8(is); - if (version >= 2) { - tileable_horizontal = readU8(is); - tileable_vertical = readU8(is); - } - if (version >= 4) { - has_color = readU8(is); - if (has_color) { - color.setRed(readU8(is)); - color.setGreen(readU8(is)); - color.setBlue(readU8(is)); - } + animation.deSerialize(is, version); + backface_culling = readU8(is); + tileable_horizontal = readU8(is); + tileable_vertical = readU8(is); + has_color = readU8(is); + if (has_color) { + color.setRed(readU8(is)); + color.setGreen(readU8(is)); + color.setBlue(readU8(is)); } - - if ((contenfeatures_version < 8) && - ((drawtype == NDT_MESH) || - (drawtype == NDT_FIRELIKE) || - (drawtype == NDT_LIQUID) || - (drawtype == NDT_PLANTLIKE))) - backface_culling = false; } @@ -249,17 +214,14 @@ static void serializeSimpleSoundSpec(const SimpleSoundSpec &ss, { os<= 11) - writeF1000(os, ss.pitch); + writeF1000(os, ss.pitch); } -static void deSerializeSimpleSoundSpec(SimpleSoundSpec &ss, std::istream &is, u8 version) +static void deSerializeSimpleSoundSpec(SimpleSoundSpec &ss, + std::istream &is, u8 version) { ss.name = deSerializeString(is); ss.gain = readF1000(is); - - if (version >= 11) - ss.pitch = readF1000(is); + ss.pitch = readF1000(is); } void TextureSettings::readSettings() @@ -377,13 +339,8 @@ void ContentFeatures::reset() void ContentFeatures::serialize(std::ostream &os, u16 protocol_version) const { - if (protocol_version < 31) { - serializeOld(os, protocol_version); - return; - } - - // version - u8 version = (protocol_version >= 34) ? 11 : 10; + // protocol_version >= 36 + u8 version = 12; writeU8(os, version); // general @@ -486,14 +443,8 @@ void ContentFeatures::deSerialize(std::istream &is) { // version detection int version = readU8(is); - if (version < 9) { - deSerializeOld(is, version); - return; - } - - if (version > 11) { + if (version < 12) throw SerializationError("unsupported ContentFeatures version"); - } // general name = deSerializeString(is); @@ -515,9 +466,8 @@ void ContentFeatures::deSerialize(std::istream &is) throw SerializationError("unsupported tile count"); for (TileDef &td : tiledef) td.deSerialize(is, version, drawtype); - if (version >= 10) - for (TileDef &td : tiledef_overlay) - td.deSerialize(is, version, drawtype); + for (TileDef &td : tiledef_overlay) + td.deSerialize(is, version, drawtype); if (readU8(is) != CF_SPECIAL_COUNT) throw SerializationError("unsupported CF_SPECIAL_COUNT"); for (TileDef &td : tiledef_special) @@ -1532,282 +1482,6 @@ IWritableNodeDefManager *createNodeDefManager() return new CNodeDefManager(); } - -//// Serialization of old ContentFeatures formats -void ContentFeatures::serializeOld(std::ostream &os, u16 protocol_version) const -{ - u8 compatible_param_type_2 = param_type_2; - if ((protocol_version < 28) - && (compatible_param_type_2 == CPT2_MESHOPTIONS)) - compatible_param_type_2 = CPT2_NONE; - else if (protocol_version < 30) { - if (compatible_param_type_2 == CPT2_COLOR) - compatible_param_type_2 = CPT2_NONE; - else if (compatible_param_type_2 == CPT2_COLORED_FACEDIR) - compatible_param_type_2 = CPT2_FACEDIR; - else if (compatible_param_type_2 == CPT2_COLORED_WALLMOUNTED) - compatible_param_type_2 = CPT2_WALLMOUNTED; - } - - float compatible_visual_scale = visual_scale; - if (protocol_version < 30 && drawtype == NDT_PLANTLIKE) - compatible_visual_scale = sqrt(visual_scale); - - TileDef compatible_tiles[6]; - for (u8 i = 0; i < 6; i++) { - compatible_tiles[i] = tiledef[i]; - if (!tiledef_overlay[i].name.empty()) { - std::stringstream s; - s << "(" << tiledef[i].name << ")^(" << tiledef_overlay[i].name - << ")"; - compatible_tiles[i].name = s.str(); - } - } - - // Protocol >= 24 - if (protocol_version < 31) { - writeU8(os, protocol_version < 27 ? 7 : 8); - - os << serializeString(name); - writeU16(os, groups.size()); - for (const auto &group : groups) { - os << serializeString(group.first); - writeS16(os, group.second); - } - writeU8(os, drawtype); - writeF1000(os, compatible_visual_scale); - writeU8(os, 6); - for (const auto &compatible_tile : compatible_tiles) - compatible_tile.serialize(os, protocol_version); - writeU8(os, CF_SPECIAL_COUNT); - for (const TileDef &i : tiledef_special) - i.serialize(os, protocol_version); - writeU8(os, alpha); - writeU8(os, post_effect_color.getAlpha()); - writeU8(os, post_effect_color.getRed()); - writeU8(os, post_effect_color.getGreen()); - writeU8(os, post_effect_color.getBlue()); - writeU8(os, param_type); - writeU8(os, compatible_param_type_2); - writeU8(os, is_ground_content); - writeU8(os, light_propagates); - writeU8(os, sunlight_propagates); - writeU8(os, walkable); - writeU8(os, pointable); - writeU8(os, diggable); - writeU8(os, climbable); - writeU8(os, buildable_to); - os << serializeString(""); // legacy: used to be metadata_name - writeU8(os, liquid_type); - os << serializeString(liquid_alternative_flowing); - os << serializeString(liquid_alternative_source); - writeU8(os, liquid_viscosity); - writeU8(os, liquid_renewable); - writeU8(os, light_source); - writeU32(os, damage_per_second); - node_box.serialize(os, protocol_version); - selection_box.serialize(os, protocol_version); - writeU8(os, legacy_facedir_simple); - writeU8(os, legacy_wallmounted); - serializeSimpleSoundSpec(sound_footstep, os, 10); - serializeSimpleSoundSpec(sound_dig, os, 10); - serializeSimpleSoundSpec(sound_dug, os, 10); - writeU8(os, rightclickable); - writeU8(os, drowning); - writeU8(os, leveled); - writeU8(os, liquid_range); - writeU8(os, waving); - os << serializeString(mesh); - collision_box.serialize(os, protocol_version); - writeU8(os, floodable); - writeU16(os, connects_to_ids.size()); - for (content_t connects_to_id : connects_to_ids) - writeU16(os, connects_to_id); - writeU8(os, connect_sides); - } else { - throw SerializationError("ContentFeatures::serialize(): " - "Unsupported version requested"); - } -} - -void ContentFeatures::deSerializeOld(std::istream &is, int version) -{ - if (version == 5) // In PROTOCOL_VERSION 13 - { - name = deSerializeString(is); - groups.clear(); - u32 groups_size = readU16(is); - for(u32 i=0; i= 36 writeS16(os, hp_max); writeU8(os, physical); writeF1000(os, weight); writeV3F1000(os, collisionbox.MinEdge); writeV3F1000(os, collisionbox.MaxEdge); - os<= 18) + writeU8(os, 3); // protocol_version >= 36 writeF1000(os, full_punch_interval); writeS16(os, max_drop_level); writeU32(os, groupcaps.size()); @@ -55,33 +55,32 @@ void ToolCapabilities::serialize(std::ostream &os, u16 protocol_version) const void ToolCapabilities::deSerialize(std::istream &is) { int version = readU8(is); - if(version != 1 && version != 2) throw SerializationError( - "unsupported ToolCapabilities version"); + if (version < 3) + throw SerializationError("unsupported ToolCapabilities version"); + full_punch_interval = readF1000(is); max_drop_level = readS16(is); groupcaps.clear(); u32 groupcaps_size = readU32(is); - for(u32 i=0; i