diff options
-rw-r--r-- | src/content_sao.cpp | 96 | ||||
-rw-r--r-- | src/content_sao.h | 4 | ||||
-rw-r--r-- | src/server.cpp | 8 | ||||
-rw-r--r-- | src/serverobject.h | 2 |
4 files changed, 72 insertions, 38 deletions
diff --git a/src/content_sao.cpp b/src/content_sao.cpp index efc14570a..8916b4926 100644 --- a/src/content_sao.cpp +++ b/src/content_sao.cpp @@ -245,7 +245,7 @@ public: } } - std::string getClientInitializationData() + std::string getClientInitializationData(u16 protocol_version) { std::ostringstream os(std::ios::binary); // version @@ -564,25 +564,41 @@ void LuaEntitySAO::step(float dtime, bool send_recommended) } } -std::string LuaEntitySAO::getClientInitializationData() +std::string LuaEntitySAO::getClientInitializationData(u16 protocol_version) { std::ostringstream os(std::ios::binary); - writeU8(os, 1); // version - os<<serializeString(""); // name - writeU8(os, 0); // is_player - writeS16(os, getId()); //id - writeV3F1000(os, m_base_position); - writeF1000(os, m_yaw); - writeS16(os, m_hp); - writeU8(os, 4 + m_bone_position.size()); // number of messages stuffed in here - os<<serializeLongString(getPropertyPacket()); // message 1 - os<<serializeLongString(gob_cmd_update_armor_groups(m_armor_groups)); // 2 - os<<serializeLongString(gob_cmd_update_animation(m_animation_range, m_animation_speed, m_animation_blend)); // 3 - for(std::map<std::string, core::vector2d<v3f> >::const_iterator ii = m_bone_position.begin(); ii != m_bone_position.end(); ++ii){ - os<<serializeLongString(gob_cmd_update_bone_position((*ii).first, (*ii).second.X, (*ii).second.Y)); // m_bone_position.size + if(protocol_version >= 14) + { + writeU8(os, 1); // version + os<<serializeString(""); // name + writeU8(os, 0); // is_player + writeS16(os, getId()); //id + writeV3F1000(os, m_base_position); + writeF1000(os, m_yaw); + writeS16(os, m_hp); + + writeU8(os, 4 + m_bone_position.size()); // number of messages stuffed in here + os<<serializeLongString(getPropertyPacket()); // message 1 + os<<serializeLongString(gob_cmd_update_armor_groups(m_armor_groups)); // 2 + os<<serializeLongString(gob_cmd_update_animation(m_animation_range, m_animation_speed, m_animation_blend)); // 3 + for(std::map<std::string, core::vector2d<v3f> >::const_iterator ii = m_bone_position.begin(); ii != m_bone_position.end(); ++ii){ + os<<serializeLongString(gob_cmd_update_bone_position((*ii).first, (*ii).second.X, (*ii).second.Y)); // m_bone_position.size + } + os<<serializeLongString(gob_cmd_update_attachment(m_attachment_parent_id, m_attachment_bone, m_attachment_position, m_attachment_rotation)); // 4 + } + else + { + writeU8(os, 0); // version + os<<serializeString(""); // name + writeU8(os, 0); // is_player + writeV3F1000(os, m_base_position); + writeF1000(os, m_yaw); + writeS16(os, m_hp); + writeU8(os, 2); // number of messages stuffed in here + os<<serializeLongString(getPropertyPacket()); // message 1 + os<<serializeLongString(gob_cmd_update_armor_groups(m_armor_groups)); // 2 } - os<<serializeLongString(gob_cmd_update_attachment(m_attachment_parent_id, m_attachment_bone, m_attachment_position, m_attachment_rotation)); // 4 // return result return os.str(); @@ -962,25 +978,41 @@ bool PlayerSAO::unlimitedTransferDistance() const return g_settings->getBool("unlimited_player_transfer_distance"); } -std::string PlayerSAO::getClientInitializationData() +std::string PlayerSAO::getClientInitializationData(u16 protocol_version) { std::ostringstream os(std::ios::binary); - writeU8(os, 1); // version - os<<serializeString(m_player->getName()); // name - writeU8(os, 1); // is_player - writeS16(os, getId()); //id - writeV3F1000(os, m_player->getPosition() + v3f(0,BS*1,0)); - writeF1000(os, m_player->getYaw()); - writeS16(os, getHP()); - - writeU8(os, 4 + m_bone_position.size()); // number of messages stuffed in here - os<<serializeLongString(getPropertyPacket()); // message 1 - os<<serializeLongString(gob_cmd_update_armor_groups(m_armor_groups)); // 2 - os<<serializeLongString(gob_cmd_update_animation(m_animation_range, m_animation_speed, m_animation_blend)); // 3 - for(std::map<std::string, core::vector2d<v3f> >::const_iterator ii = m_bone_position.begin(); ii != m_bone_position.end(); ++ii){ - os<<serializeLongString(gob_cmd_update_bone_position((*ii).first, (*ii).second.X, (*ii).second.Y)); // m_bone_position.size + + if(protocol_version >= 15) + { + writeU8(os, 1); // version + os<<serializeString(m_player->getName()); // name + writeU8(os, 1); // is_player + writeS16(os, getId()); //id + writeV3F1000(os, m_player->getPosition() + v3f(0,BS*1,0)); + writeF1000(os, m_player->getYaw()); + writeS16(os, getHP()); + + writeU8(os, 4 + m_bone_position.size()); // number of messages stuffed in here + os<<serializeLongString(getPropertyPacket()); // message 1 + os<<serializeLongString(gob_cmd_update_armor_groups(m_armor_groups)); // 2 + os<<serializeLongString(gob_cmd_update_animation(m_animation_range, m_animation_speed, m_animation_blend)); // 3 + for(std::map<std::string, core::vector2d<v3f> >::const_iterator ii = m_bone_position.begin(); ii != m_bone_position.end(); ++ii){ + os<<serializeLongString(gob_cmd_update_bone_position((*ii).first, (*ii).second.X, (*ii).second.Y)); // m_bone_position.size + } + os<<serializeLongString(gob_cmd_update_attachment(m_attachment_parent_id, m_attachment_bone, m_attachment_position, m_attachment_rotation)); // 4 + } + else + { + writeU8(os, 0); // version + os<<serializeString(m_player->getName()); // name + writeU8(os, 1); // is_player + writeV3F1000(os, m_player->getPosition() + v3f(0,BS*1,0)); + writeF1000(os, m_player->getYaw()); + writeS16(os, getHP()); + writeU8(os, 2); // number of messages stuffed in here + os<<serializeLongString(getPropertyPacket()); // message 1 + os<<serializeLongString(gob_cmd_update_armor_groups(m_armor_groups)); // 2 } - os<<serializeLongString(gob_cmd_update_attachment(m_attachment_parent_id, m_attachment_bone, m_attachment_position, m_attachment_rotation)); // 4 // return result return os.str(); diff --git a/src/content_sao.h b/src/content_sao.h index 392c3f923..065c6a039 100644 --- a/src/content_sao.h +++ b/src/content_sao.h @@ -48,7 +48,7 @@ public: const std::string &data); bool isAttached(); void step(float dtime, bool send_recommended); - std::string getClientInitializationData(); + std::string getClientInitializationData(u16 protocol_version); std::string getStaticData(); int punch(v3f dir, const ToolCapabilities *toolcap=NULL, @@ -140,7 +140,7 @@ public: void removingFromEnvironment(); bool isStaticAllowed() const; bool unlimitedTransferDistance() const; - std::string getClientInitializationData(); + std::string getClientInitializationData(u16 protocol_version); std::string getStaticData(); bool isAttached(); void step(float dtime, bool send_recommended); diff --git a/src/server.cpp b/src/server.cpp index 684e3bb08..961bdeaf9 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -1568,7 +1568,7 @@ void Server::AsyncRunStep() if(obj) data_buffer.append(serializeLongString( - obj->getClientInitializationData())); + obj->getClientInitializationData(client->net_proto_version))); else data_buffer.append(serializeLongString("")); @@ -2407,7 +2407,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id) if(command == TOSERVER_PLAYERPOS) { - if(datasize < 2+12+12+4+4+4) + if(datasize < 2+12+12+4+4) return; u32 start = 0; @@ -2415,7 +2415,9 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id) v3s32 ss = readV3S32(&data[start+2+12]); f32 pitch = (f32)readS32(&data[2+12+12]) / 100.0; f32 yaw = (f32)readS32(&data[2+12+12+4]) / 100.0; - u32 keyPressed = (u32)readU32(&data[2+12+12+4+4]); + u32 keyPressed = 0; + if(datasize >= 2+12+12+4+4+4) + keyPressed = (u32)readU32(&data[2+12+12+4+4]); v3f position((f32)ps.X/100., (f32)ps.Y/100., (f32)ps.Z/100.); v3f speed((f32)ss.X/100., (f32)ss.Y/100., (f32)ss.Z/100.); pitch = wrapDegrees(pitch); diff --git a/src/serverobject.h b/src/serverobject.h index 1bbd3e4e8..14752878f 100644 --- a/src/serverobject.h +++ b/src/serverobject.h @@ -118,7 +118,7 @@ public: The return value of this is passed to the client-side object when it is created */ - virtual std::string getClientInitializationData(){return "";} + virtual std::string getClientInitializationData(u16 protocol_version){return "";} /* The return value of this is passed to the server-side object |