1.8: Added MultiBlockChange packet.
This commit is contained in:
parent
a880813f27
commit
71c3369e08
@ -362,13 +362,14 @@ void cClientHandle::Authenticate(const AString & a_Name, const AString & a_UUID,
|
||||
|
||||
// Send experience
|
||||
m_Player->SendExperience();
|
||||
|
||||
m_Player->Initialize(*World);
|
||||
m_State = csAuthenticated;
|
||||
|
||||
// Send player list items
|
||||
SendPlayerListItem(*m_Player, 0);
|
||||
World->BroadcastPlayerListItem(*m_Player, 0);
|
||||
World->SendPlayerList(m_Player);
|
||||
|
||||
m_Player->Initialize(*World);
|
||||
m_State = csAuthenticated;
|
||||
|
||||
// Query player team
|
||||
m_Player->UpdateTeam();
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "ChunkDataSerializer.h"
|
||||
#include "zlib/zlib.h"
|
||||
#include "ByteBuffer.h"
|
||||
#include "Protocol18x.h"
|
||||
|
||||
|
||||
|
||||
@ -54,7 +55,10 @@ const AString & cChunkDataSerializer::Serialize(int a_Version, int a_ChunkX, int
|
||||
break;
|
||||
}
|
||||
}
|
||||
m_Serializations[a_Version] = data;
|
||||
if (!data.empty())
|
||||
{
|
||||
m_Serializations[a_Version] = data;
|
||||
}
|
||||
return m_Serializations[a_Version];
|
||||
}
|
||||
|
||||
@ -219,40 +223,23 @@ void cChunkDataSerializer::Serialize80(AString & a_Data, int a_ChunkX, int a_Chu
|
||||
Packet.ReadAll(PacketData);
|
||||
Packet.CommitRead();
|
||||
|
||||
cByteBuffer NumberBuffer(20);
|
||||
cByteBuffer Buffer(20);
|
||||
if (PacketData.size() >= 256)
|
||||
{
|
||||
AString PostData;
|
||||
NumberBuffer.WriteVarInt(PacketData.size());
|
||||
NumberBuffer.ReadAll(PostData);
|
||||
NumberBuffer.CommitRead();
|
||||
|
||||
// Compress the data:
|
||||
const uLongf CompressedMaxSize = 200000;
|
||||
char CompressedData[CompressedMaxSize];
|
||||
|
||||
uLongf CompressedSize = compressBound(PacketData.size());
|
||||
// Run-time check that our compile-time guess about CompressedMaxSize was enough:
|
||||
ASSERT(CompressedSize <= CompressedMaxSize);
|
||||
compress2((Bytef*)CompressedData, &CompressedSize, (const Bytef*)PacketData.data(), PacketData.size(), Z_DEFAULT_COMPRESSION);
|
||||
|
||||
NumberBuffer.WriteVarInt(CompressedSize + PostData.size());
|
||||
NumberBuffer.WriteVarInt(PacketData.size());
|
||||
NumberBuffer.ReadAll(PostData);
|
||||
NumberBuffer.CommitRead();
|
||||
|
||||
a_Data.clear();
|
||||
a_Data.resize(PostData.size() + CompressedSize);
|
||||
a_Data.append(PostData.data(), PostData.size());
|
||||
a_Data.append(CompressedData, CompressedSize);
|
||||
if (!cProtocol180::CompressPacket(PacketData, a_Data))
|
||||
{
|
||||
ASSERT(!"Packet compression failed.");
|
||||
a_Data.clear();
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
AString PostData;
|
||||
NumberBuffer.WriteVarInt(Packet.GetUsedSpace() + 1);
|
||||
NumberBuffer.WriteVarInt(0);
|
||||
NumberBuffer.ReadAll(PostData);
|
||||
NumberBuffer.CommitRead();
|
||||
Buffer.WriteVarInt(Packet.GetUsedSpace() + 1);
|
||||
Buffer.WriteVarInt(0);
|
||||
Buffer.ReadAll(PostData);
|
||||
Buffer.CommitRead();
|
||||
|
||||
a_Data.clear();
|
||||
a_Data.resize(PostData.size() + PacketData.size());
|
||||
|
@ -200,18 +200,16 @@ void cProtocol180::SendBlockChanges(int a_ChunkX, int a_ChunkZ, const sSetBlockV
|
||||
{
|
||||
ASSERT(m_State == 3); // In game mode?
|
||||
|
||||
/*cPacketizer Pkt(*this, 0x22); // Multi Block Change packet
|
||||
cPacketizer Pkt(*this, 0x22); // Multi Block Change packet
|
||||
Pkt.WriteInt(a_ChunkX);
|
||||
Pkt.WriteInt(a_ChunkZ);
|
||||
Pkt.WriteVarInt((UInt32)a_Changes.size());
|
||||
for (sSetBlockVector::const_iterator itr = a_Changes.begin(), end = a_Changes.end(); itr != end; ++itr)
|
||||
{
|
||||
short Coords = itr->y | (itr->z << 8) | (itr->x << 12);
|
||||
short Coords = (short) (itr->y | (itr->z << 8) | (itr->x << 12));
|
||||
Pkt.WriteShort(Coords);
|
||||
|
||||
UInt32 Block = ((UInt32)itr->BlockType << 4) | ((UInt32)itr->BlockMeta & 15);
|
||||
Pkt.WriteVarInt(Block);
|
||||
} // for itr - a_Changes[]*/
|
||||
Pkt.WriteVarInt((itr->BlockType & 0xFFF) << 4 | (itr->BlockMeta & 0xF));
|
||||
} // for itr - a_Changes[]
|
||||
}
|
||||
|
||||
|
||||
@ -369,9 +367,9 @@ void cProtocol180::SendDestroyEntity(const cEntity & a_Entity)
|
||||
{
|
||||
ASSERT(m_State == 3); // In game mode?
|
||||
|
||||
/*cPacketizer Pkt(*this, 0x13); // Destroy Entities packet
|
||||
cPacketizer Pkt(*this, 0x13); // Destroy Entities packet
|
||||
Pkt.WriteVarInt(1);
|
||||
Pkt.WriteVarInt(a_Entity.GetUniqueID());*/
|
||||
Pkt.WriteVarInt(a_Entity.GetUniqueID());
|
||||
}
|
||||
|
||||
|
||||
@ -437,10 +435,10 @@ void cProtocol180::SendEntityEquipment(const cEntity & a_Entity, short a_SlotNum
|
||||
{
|
||||
ASSERT(m_State == 3); // In game mode?
|
||||
|
||||
/*cPacketizer Pkt(*this, 0x04); // Entity Equipment packet
|
||||
cPacketizer Pkt(*this, 0x04); // Entity Equipment packet
|
||||
Pkt.WriteVarInt((UInt32)a_Entity.GetUniqueID());
|
||||
Pkt.WriteShort(a_SlotNum);
|
||||
Pkt.WriteItem(a_Item);*/
|
||||
Pkt.WriteItem(a_Item);
|
||||
}
|
||||
|
||||
|
||||
@ -451,9 +449,9 @@ void cProtocol180::SendEntityHeadLook(const cEntity & a_Entity)
|
||||
{
|
||||
ASSERT(m_State == 3); // In game mode?
|
||||
|
||||
/*cPacketizer Pkt(*this, 0x19); // Entity Head Look packet
|
||||
cPacketizer Pkt(*this, 0x19); // Entity Head Look packet
|
||||
Pkt.WriteVarInt((UInt32)a_Entity.GetUniqueID());
|
||||
Pkt.WriteByteAngle(a_Entity.GetHeadYaw());*/
|
||||
Pkt.WriteByteAngle(a_Entity.GetHeadYaw());
|
||||
}
|
||||
|
||||
|
||||
@ -464,11 +462,11 @@ void cProtocol180::SendEntityLook(const cEntity & a_Entity)
|
||||
{
|
||||
ASSERT(m_State == 3); // In game mode?
|
||||
|
||||
/*cPacketizer Pkt(*this, 0x16); // Entity Look packet
|
||||
cPacketizer Pkt(*this, 0x16); // Entity Look packet
|
||||
Pkt.WriteVarInt(a_Entity.GetUniqueID());
|
||||
Pkt.WriteByteAngle(a_Entity.GetYaw());
|
||||
Pkt.WriteByteAngle(a_Entity.GetPitch());
|
||||
Pkt.WriteBool(true); // TODO: IsOnGround() on entities*/
|
||||
Pkt.WriteBool(true); // TODO: IsOnGround() on entities
|
||||
}
|
||||
|
||||
|
||||
@ -479,10 +477,10 @@ void cProtocol180::SendEntityMetadata(const cEntity & a_Entity)
|
||||
{
|
||||
ASSERT(m_State == 3); // In game mode?
|
||||
|
||||
/*cPacketizer Pkt(*this, 0x1c); // Entity Metadata packet
|
||||
cPacketizer Pkt(*this, 0x1c); // Entity Metadata packet
|
||||
Pkt.WriteVarInt(a_Entity.GetUniqueID());
|
||||
Pkt.WriteEntityMetadata(a_Entity);
|
||||
Pkt.WriteByte(0x7f); // The termination byte*/
|
||||
Pkt.WriteByte(0x7f); // The termination byte
|
||||
}
|
||||
|
||||
|
||||
@ -506,12 +504,12 @@ void cProtocol180::SendEntityRelMove(const cEntity & a_Entity, char a_RelX, char
|
||||
{
|
||||
ASSERT(m_State == 3); // In game mode?
|
||||
|
||||
/*cPacketizer Pkt(*this, 0x15); // Entity Relative Move packet
|
||||
cPacketizer Pkt(*this, 0x15); // Entity Relative Move packet
|
||||
Pkt.WriteVarInt(a_Entity.GetUniqueID());
|
||||
Pkt.WriteByte(a_RelX);
|
||||
Pkt.WriteByte(a_RelY);
|
||||
Pkt.WriteByte(a_RelZ);
|
||||
Pkt.WriteBool(true); // TODO: IsOnGround() on entities*/
|
||||
Pkt.WriteBool(true); // TODO: IsOnGround() on entities
|
||||
}
|
||||
|
||||
|
||||
@ -522,14 +520,14 @@ void cProtocol180::SendEntityRelMoveLook(const cEntity & a_Entity, char a_RelX,
|
||||
{
|
||||
ASSERT(m_State == 3); // In game mode?
|
||||
|
||||
/*cPacketizer Pkt(*this, 0x17); // Entity Look And Relative Move packet
|
||||
cPacketizer Pkt(*this, 0x17); // Entity Look And Relative Move packet
|
||||
Pkt.WriteVarInt(a_Entity.GetUniqueID());
|
||||
Pkt.WriteByte(a_RelX);
|
||||
Pkt.WriteByte(a_RelY);
|
||||
Pkt.WriteByte(a_RelZ);
|
||||
Pkt.WriteByteAngle(a_Entity.GetYaw());
|
||||
Pkt.WriteByteAngle(a_Entity.GetPitch());
|
||||
Pkt.WriteBool(true); // TODO: IsOnGround() on entities*/
|
||||
Pkt.WriteBool(true); // TODO: IsOnGround() on entities
|
||||
}
|
||||
|
||||
|
||||
@ -1320,14 +1318,14 @@ void cProtocol180::SendTeleportEntity(const cEntity & a_Entity)
|
||||
{
|
||||
ASSERT(m_State == 3); // In game mode?
|
||||
|
||||
/*cPacketizer Pkt(*this, 0x18);
|
||||
cPacketizer Pkt(*this, 0x18);
|
||||
Pkt.WriteVarInt(a_Entity.GetUniqueID());
|
||||
Pkt.WriteFPInt(a_Entity.GetPosX());
|
||||
Pkt.WriteFPInt(a_Entity.GetPosY());
|
||||
Pkt.WriteFPInt(a_Entity.GetPosZ());
|
||||
Pkt.WriteByteAngle(a_Entity.GetYaw());
|
||||
Pkt.WriteByteAngle(a_Entity.GetPitch());
|
||||
Pkt.WriteBool(true); // TODO: IsOnGrond() on entities*/
|
||||
Pkt.WriteBool(true); // TODO: IsOnGrond() on entities
|
||||
}
|
||||
|
||||
|
||||
@ -1531,6 +1529,47 @@ void cProtocol180::SendWindowProperty(const cWindow & a_Window, int a_Property,
|
||||
|
||||
|
||||
|
||||
bool cProtocol180::CompressPacket(const AString & a_Packet, AString & a_CompressedData)
|
||||
{
|
||||
// Compress the data:
|
||||
const uLongf CompressedMaxSize = 200000;
|
||||
char CompressedData[CompressedMaxSize];
|
||||
|
||||
uLongf CompressedSize = compressBound(a_Packet.size());
|
||||
if (CompressedSize >= CompressedMaxSize)
|
||||
{
|
||||
ASSERT(!"Too high packet size.");
|
||||
return false;
|
||||
}
|
||||
|
||||
int Status = compress2((Bytef*)CompressedData, &CompressedSize, (const Bytef*)a_Packet.data(), a_Packet.size(), Z_DEFAULT_COMPRESSION);
|
||||
if (Status != Z_OK)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
AString LengthData;
|
||||
cByteBuffer Buffer(20);
|
||||
Buffer.WriteVarInt((UInt32)a_Packet.size());
|
||||
Buffer.ReadAll(LengthData);
|
||||
Buffer.CommitRead();
|
||||
|
||||
Buffer.WriteVarInt(CompressedSize + LengthData.size());
|
||||
Buffer.WriteVarInt(a_Packet.size());
|
||||
Buffer.ReadAll(LengthData);
|
||||
Buffer.CommitRead();
|
||||
|
||||
a_CompressedData.clear();
|
||||
a_CompressedData.resize(LengthData.size() + CompressedSize);
|
||||
a_CompressedData.append(LengthData.data(), LengthData.size());
|
||||
a_CompressedData.append(CompressedData, CompressedSize);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cProtocol180::AddReceivedData(const char * a_Data, size_t a_Size)
|
||||
{
|
||||
// Write the incoming data into the comm log file:
|
||||
|
@ -133,6 +133,11 @@ public:
|
||||
|
||||
virtual AString GetAuthServerID(void) override { return m_AuthServerID; }
|
||||
|
||||
/** Compress the packet. a_Packet must be without packet length.
|
||||
a_Compressed will be set to the compressed packet includes packet length and data length.
|
||||
If compression fails, the function returns false. */
|
||||
static bool CompressPacket(const AString & a_Packet, AString & a_Compressed);
|
||||
|
||||
protected:
|
||||
|
||||
/** Composes individual packets in the protocol's m_OutPacketBuffer; sends them upon being destructed */
|
||||
|
Loading…
Reference in New Issue
Block a user