1
0

Updated chunk sending to 1.8

This commit is contained in:
Howaner 2014-09-08 12:24:06 +02:00
parent 10a30a03e3
commit 38124bcce3
4 changed files with 22 additions and 26 deletions

View File

@ -182,25 +182,26 @@ void cChunkDataSerializer::Serialize80(AString & a_Data, int a_ChunkX, int a_Chu
// TODO: Do not copy data and then compress it; rather, compress partial blocks of data (zlib *can* stream) // TODO: Do not copy data and then compress it; rather, compress partial blocks of data (zlib *can* stream)
// Blocktypes converter (1.8 included the meta into the blocktype): // Blocktypes converter (1.8 included the meta into the blocktype):
/*unsigned short Blocks[ARRAYCOUNT(m_BlockTypes)]; unsigned char Blocks[cChunkDef::NumBlocks * 2];
size_t LastOffset = 0;
for (size_t Index = 0; Index < cChunkDef::NumBlocks; Index++) for (size_t Index = 0; Index < cChunkDef::NumBlocks; Index++)
{ {
BLOCKTYPE BlockType = m_BlockTypes[Index]; BLOCKTYPE BlockType = m_BlockTypes[Index] & 0xFF;
NIBBLETYPE BlockMeta = m_BlockMetas[Index / 2] >> ((Index & 1) * 4) & 0x0f; NIBBLETYPE BlockMeta = m_BlockMetas[Index / 2] >> ((Index & 1) * 4) & 0x0f;
Blocks[Index] = ((unsigned short)BlockType << 4) | ((unsigned short)BlockMeta); Blocks[LastOffset] = (BlockType << 4) | ((unsigned char)BlockMeta);
}*/ Blocks[LastOffset + 1] = (unsigned char)BlockType >> 4;
LastOffset += 2;
}
const int BiomeDataSize = cChunkDef::Width * cChunkDef::Width; const int BiomeDataSize = cChunkDef::Width * cChunkDef::Width;
const int MetadataOffset = sizeof(m_BlockTypes); const int BlockLightOffset = sizeof(Blocks);
const int BlockLightOffset = MetadataOffset + sizeof(m_BlockMetas);
const int SkyLightOffset = BlockLightOffset + sizeof(m_BlockLight); const int SkyLightOffset = BlockLightOffset + sizeof(m_BlockLight);
const int BiomeOffset = SkyLightOffset + sizeof(m_BlockSkyLight); const int BiomeOffset = SkyLightOffset + sizeof(m_BlockSkyLight);
const int DataSize = BiomeOffset + BiomeDataSize; const int DataSize = BiomeOffset + BiomeDataSize;
// Temporary buffer for the composed data: // Temporary buffer for the composed data:
char AllData [DataSize]; char AllData [DataSize];
memcpy(AllData, m_BlockTypes, sizeof(m_BlockTypes)); memcpy(AllData, Blocks, sizeof(Blocks));
memcpy(AllData + MetadataOffset, m_BlockMetas, sizeof(m_BlockMetas));
memcpy(AllData + BlockLightOffset, m_BlockLight, sizeof(m_BlockLight)); memcpy(AllData + BlockLightOffset, m_BlockLight, sizeof(m_BlockLight));
memcpy(AllData + SkyLightOffset, m_BlockSkyLight, sizeof(m_BlockSkyLight)); memcpy(AllData + SkyLightOffset, m_BlockSkyLight, sizeof(m_BlockSkyLight));
memcpy(AllData + BiomeOffset, m_BiomeData, BiomeDataSize); memcpy(AllData + BiomeOffset, m_BiomeData, BiomeDataSize);

View File

@ -1503,14 +1503,14 @@ void cProtocol172::AddReceivedData(const char * a_Data, size_t a_Size)
); );
m_CommLogFile.Flush(); m_CommLogFile.Flush();
} }
if (!m_ReceivedData.Write(a_Data, a_Size)) if (!m_ReceivedData.Write(a_Data, a_Size))
{ {
// Too much data in the incoming queue, report to caller: // Too much data in the incoming queue, report to caller:
m_Client->PacketBufferFull(); m_Client->PacketBufferFull();
return; return;
} }
// Handle all complete packets: // Handle all complete packets:
for (;;) for (;;)
{ {
@ -1530,10 +1530,7 @@ void cProtocol172::AddReceivedData(const char * a_Data, size_t a_Size)
cByteBuffer bb(PacketLen + 1); cByteBuffer bb(PacketLen + 1);
VERIFY(m_ReceivedData.ReadToByteBuffer(bb, (int)PacketLen)); VERIFY(m_ReceivedData.ReadToByteBuffer(bb, (int)PacketLen));
m_ReceivedData.CommitRead(); m_ReceivedData.CommitRead();
// Write one NUL extra, so that we can detect over-reads
bb.Write("\0", 1);
// 1.8 - Compressed packets // 1.8 - Compressed packets
if ((m_State == 3) && (GetProtocolVersion() == cProtocolRecognizer::PROTO_VERSION_1_8_0)) if ((m_State == 3) && (GetProtocolVersion() == cProtocolRecognizer::PROTO_VERSION_1_8_0))
{ {
@ -1544,6 +1541,9 @@ void cProtocol172::AddReceivedData(const char * a_Data, size_t a_Size)
break; break;
} }
} }
// Write one NUL extra, so that we can detect over-reads
bb.Write("\0", 1);
UInt32 PacketType; UInt32 PacketType;
if (!bb.ReadVarInt(PacketType)) if (!bb.ReadVarInt(PacketType))

View File

@ -121,7 +121,7 @@ void cProtocol180::SendPlayerMoveLook(void)
{ {
ASSERT(m_State == 3); // In game mode? ASSERT(m_State == 3); // In game mode?
/*cPacketizer Pkt(*this, 0x08); // Player Position And Look packet cPacketizer Pkt(*this, 0x08); // Player Position And Look packet
cPlayer * Player = m_Client->GetPlayer(); cPlayer * Player = m_Client->GetPlayer();
Pkt.WriteDouble(Player->GetPosX()); Pkt.WriteDouble(Player->GetPosX());
@ -131,7 +131,7 @@ void cProtocol180::SendPlayerMoveLook(void)
Pkt.WriteDouble(Player->GetPosZ()); Pkt.WriteDouble(Player->GetPosZ());
Pkt.WriteFloat((float)Player->GetYaw()); Pkt.WriteFloat((float)Player->GetYaw());
Pkt.WriteFloat((float)Player->GetPitch()); Pkt.WriteFloat((float)Player->GetPitch());
Pkt.WriteByte(0);*/ Pkt.WriteByte(0);
} }
@ -168,12 +168,12 @@ void cProtocol180::SendEntityVelocity(const cEntity & a_Entity)
{ {
ASSERT(m_State == 3); // In game mode? ASSERT(m_State == 3); // In game mode?
/*cPacketizer Pkt(*this, 0x12); // Entity Velocity packet cPacketizer Pkt(*this, 0x12); // Entity Velocity packet
Pkt.WriteVarInt(a_Entity.GetUniqueID()); Pkt.WriteVarInt(a_Entity.GetUniqueID());
// 400 = 8000 / 20 ... Conversion from our speed in m/s to 8000 m/tick // 400 = 8000 / 20 ... Conversion from our speed in m/s to 8000 m/tick
Pkt.WriteShort((short)(a_Entity.GetSpeedX() * 400)); Pkt.WriteShort((short)(a_Entity.GetSpeedX() * 400));
Pkt.WriteShort((short)(a_Entity.GetSpeedY() * 400)); Pkt.WriteShort((short)(a_Entity.GetSpeedY() * 400));
Pkt.WriteShort((short)(a_Entity.GetSpeedZ() * 400));*/ Pkt.WriteShort((short)(a_Entity.GetSpeedZ() * 400));
} }
@ -395,9 +395,9 @@ void cProtocol180::SendPluginMessage(const AString & a_Channel, const AString &
{ {
ASSERT(m_State == 3); // In game mode? ASSERT(m_State == 3); // In game mode?
/*cPacketizer Pkt(*this, 0x3f); cPacketizer Pkt(*this, 0x3f);
Pkt.WriteString(a_Channel); Pkt.WriteString(a_Channel);
Pkt.WriteBuf(a_Message.data(), a_Message.size());*/ Pkt.WriteBuf(a_Message.data(), a_Message.size());
} }
@ -672,10 +672,7 @@ void cProtocol180::HandlePacketPluginMessage(cByteBuffer & a_ByteBuffer)
{ {
HANDLE_READ(a_ByteBuffer, ReadVarUTF8String, AString, Channel); HANDLE_READ(a_ByteBuffer, ReadVarUTF8String, AString, Channel);
AString Data; AString Data;
if (!a_ByteBuffer.ReadString(Data, a_ByteBuffer.GetReadableSpace() - 1)) a_ByteBuffer.ReadAll(Data);
{
return;
}
m_Client->HandlePluginMessage(Channel, Data); m_Client->HandlePluginMessage(Channel, Data);
} }

View File

@ -56,8 +56,6 @@ public:
virtual void SendSoundParticleEffect (int a_EffectID, int a_SrcX, int a_SrcY, int a_SrcZ, int a_Data) override; virtual void SendSoundParticleEffect (int a_EffectID, int a_SrcX, int a_SrcY, int a_SrcZ, int a_Data) override;
virtual void SendLoginSuccess (void) override; virtual void SendLoginSuccess (void) override;
virtual void SendPlayerAbilities (void) override {}
virtual void SendWindowClose (const cWindow & a_Window) override {}
virtual void SendPickupSpawn (const cPickup & a_Pickup) override {} virtual void SendPickupSpawn (const cPickup & a_Pickup) override {}
virtual void SendSpawnObject (const cEntity & a_Entity, char a_ObjectType, int a_ObjectData, Byte a_Yaw, Byte a_Pitch) override {} virtual void SendSpawnObject (const cEntity & a_Entity, char a_ObjectType, int a_ObjectData, Byte a_Yaw, Byte a_Pitch) override {}
virtual void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item) override {} virtual void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item) override {}