Full protocol 13 compatibility on server side
authorPerttu Ahola <celeron55@gmail.com>
Mon, 26 Nov 2012 22:47:03 +0000 (00:47 +0200)
committerPerttu Ahola <celeron55@gmail.com>
Thu, 29 Nov 2012 20:08:25 +0000 (22:08 +0200)
src/content_sao.cpp
src/content_sao.h
src/server.cpp
src/serverobject.h

index efc14570a5f6a98958ef7f4da5089e42f604081d..8916b492617462e9ca1129b885421355cd80c9a0 100644 (file)
@@ -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();
index 392c3f92399bcf33f4b73bd4b9d4b59f6742a6d1..065c6a0397da31d040afc1c139ac5926dd7cf07d 100644 (file)
@@ -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);
index 684e3bb087d619d4ac22128d2b44b407b49d0ebf..961bdeaf92f1aacba8767137a7e3641c8eeac652 100644 (file)
@@ -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);
index 1bbd3e4e8ba934983cc9d36a819e9843442d5625..14752878ffac608e47e730917386ad66b47f2c36 100644 (file)
@@ -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