From 7e17eaedb2e697581ace1bd038781f908e19a985 Mon Sep 17 00:00:00 2001 From: Rogier-5 Date: Thu, 10 Nov 2016 13:42:49 +0100 Subject: [PATCH] Fix mob deserialization errors in the client (#4743) The problem was seen while using the mobf mod package. The problem happens when the server serializes entity attachments. Sometimes, such attachments no longer exist. The serialization code skips those. However, the total number of attachments was serialized earlier. Therefore the client expects more than it gets, and logs a serialization error. --- src/content_sao.cpp | 48 ++++++++++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/src/content_sao.cpp b/src/content_sao.cpp index dff222f42..6caea5198 100644 --- a/src/content_sao.cpp +++ b/src/content_sao.cpp @@ -383,23 +383,30 @@ std::string LuaEntitySAO::getClientInitializationData(u16 protocol_version) writeF1000(os, m_yaw); writeS16(os, m_hp); - writeU8(os, 4 + m_bone_position.size() + m_attachment_child_ids.size()); // number of messages stuffed in here - os< >::const_iterator ii = m_bone_position.begin(); ii != m_bone_position.end(); ++ii) { - os << serializeLongString(gob_cmd_update_bone_position((*ii).first, + msg_os << serializeLongString(gob_cmd_update_bone_position((*ii).first, (*ii).second.X, (*ii).second.Y)); // m_bone_position.size } - os<::const_iterator ii = m_attachment_child_ids.begin(); (ii != m_attachment_child_ids.end()); ++ii) { if (ServerActiveObject *obj = m_env->getActiveObject(*ii)) { - os << serializeLongString(gob_cmd_update_infant(*ii, obj->getSendType(), obj->getClientInitializationData(protocol_version))); + message_count++; + msg_os << serializeLongString(gob_cmd_update_infant(*ii, obj->getSendType(), + obj->getClientInitializationData(protocol_version))); } } + + writeU8(os, message_count); + os.write(msg_os.str().c_str(), msg_os.str().size()); } else { @@ -865,26 +872,35 @@ std::string PlayerSAO::getClientInitializationData(u16 protocol_version) writeF1000(os, m_yaw); writeS16(os, getHP()); - writeU8(os, 6 + m_bone_position.size() + m_attachment_child_ids.size()); // number of messages stuffed in here - os< >::const_iterator ii = m_bone_position.begin(); ii != m_bone_position.end(); ++ii) { - os<::const_iterator ii = m_attachment_child_ids.begin(); ii != m_attachment_child_ids.end(); ++ii) { if (ServerActiveObject *obj = m_env->getActiveObject(*ii)) { - os << serializeLongString(gob_cmd_update_infant(*ii, obj->getSendType(), obj->getClientInitializationData(protocol_version))); + message_count++; + msg_os << serializeLongString(gob_cmd_update_infant(*ii, obj->getSendType(), + obj->getClientInitializationData(protocol_version))); } } + + writeU8(os, message_count); + os.write(msg_os.str().c_str(), msg_os.str().size()); } else { -- 2.25.1