Full protocol 13 compatibility on server side

master
Perttu Ahola 2012-11-27 00:47:03 +02:00
parent 96a286dcf5
commit 7b6d642300
4 changed files with 71 additions and 37 deletions

View File

@ -245,7 +245,7 @@ public:
}
}
std::string getClientInitializationData()
std::string getClientInitializationData(u16 protocol_version)
{
std::ostringstream os(std::ios::binary);
// version
@ -564,9 +564,12 @@ 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);
if(protocol_version >= 14)
{
writeU8(os, 1); // version
os<<serializeString(""); // name
writeU8(os, 0); // is_player
@ -583,6 +586,19 @@ std::string LuaEntitySAO::getClientInitializationData()
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
}
// return result
return os.str();
@ -962,9 +978,12 @@ 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);
if(protocol_version >= 15)
{
writeU8(os, 1); // version
os<<serializeString(m_player->getName()); // name
writeU8(os, 1); // is_player
@ -981,6 +1000,19 @@ std::string PlayerSAO::getClientInitializationData()
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
}
// return result
return os.str();

View 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);

View 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);

View 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