summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorHowaner <franzi.moos@googlemail.com>2014-09-04 19:03:21 +0200
committerHowaner <franzi.moos@googlemail.com>2014-09-04 19:03:21 +0200
commitda28c70def4be849925709b2c4d4857b6db1abb8 (patch)
treee334f02678b7efe7c0bdaaa5672b0ce8528dc340 /src
parentAdded more 1.8 protocol things. (diff)
downloadcuberite-da28c70def4be849925709b2c4d4857b6db1abb8.tar
cuberite-da28c70def4be849925709b2c4d4857b6db1abb8.tar.gz
cuberite-da28c70def4be849925709b2c4d4857b6db1abb8.tar.bz2
cuberite-da28c70def4be849925709b2c4d4857b6db1abb8.tar.lz
cuberite-da28c70def4be849925709b2c4d4857b6db1abb8.tar.xz
cuberite-da28c70def4be849925709b2c4d4857b6db1abb8.tar.zst
cuberite-da28c70def4be849925709b2c4d4857b6db1abb8.zip
Diffstat (limited to '')
-rw-r--r--src/Protocol/ChunkDataSerializer.cpp32
-rw-r--r--src/Protocol/Protocol17x.cpp2
-rw-r--r--src/Protocol/Protocol17x.h3
-rw-r--r--src/Protocol/Protocol18x.cpp90
-rw-r--r--src/Protocol/Protocol18x.h4
5 files changed, 79 insertions, 52 deletions
diff --git a/src/Protocol/ChunkDataSerializer.cpp b/src/Protocol/ChunkDataSerializer.cpp
index 9eadc4f0b..29e32ce32 100644
--- a/src/Protocol/ChunkDataSerializer.cpp
+++ b/src/Protocol/ChunkDataSerializer.cpp
@@ -182,19 +182,11 @@ void cChunkDataSerializer::Serialize80(AString & a_Data)
// Blocktypes converter (1.8 included the meta into the blocktype):
unsigned short Blocks[ARRAYCOUNT(m_BlockTypes)];
- for (int RelX = 0; RelX < cChunkDef::Width; RelX++)
+ for (size_t Index = 0; Index < cChunkDef::NumBlocks; Index++)
{
- for (int RelZ = 0; RelZ < cChunkDef::Width; RelZ++)
- {
- for (int RelY = 0; RelY < cChunkDef::Height; RelY++)
- {
- int Index = cChunkDef::MakeIndexNoCheck(RelX, RelY, RelZ);
- BLOCKTYPE BlockType = m_BlockTypes[Index];
- NIBBLETYPE BlockMeta = m_BlockMetas[Index / 2] >> ((Index & 1) * 4) & 0x0f;
-
- Blocks[Index] = ((unsigned short)BlockType << 4) | ((unsigned short)BlockMeta & 15);
- }
- }
+ BLOCKTYPE BlockType = m_BlockTypes[Index];
+ NIBBLETYPE BlockMeta = m_BlockMetas[Index / 2] >> ((Index & 1) * 4) & 0x0f;
+ Blocks[Index] = ((unsigned short)BlockType << 4) | ((unsigned short)BlockMeta);
}
const int BiomeDataSize = cChunkDef::Width * cChunkDef::Width;
@@ -216,23 +208,13 @@ void cChunkDataSerializer::Serialize80(AString & a_Data)
// Two bitmaps; we're aways sending the full chunk with no additional data, so the bitmaps are 0xffff and 0, respectively
// Also, no endian flipping is needed because of the const values
unsigned short BitMap = 0xffff;
- a_Data.append((const char *)&BitMap, sizeof(short));
+ a_Data.append((const char *)&BitMap, sizeof(unsigned short));
// Write chunk size:
UInt32 ChunkSize = htonl((UInt32)DataSize);
+ a_Data.append((const char *)&ChunkSize, 4);
- unsigned char b[5]; // // A 32-bit integer can be encoded by at most 5 bytes
- size_t idx = 0;
- UInt32 Value = ChunkSize;
- do
- {
- b[idx] = (Value & 0x7f) | ((Value > 0x7f) ? 0x80 : 0x00);
- Value = Value >> 7;
- idx++;
- } while (Value > 0);
- a_Data.append((const char *)b, idx);
-
- a_Data.append(AllData, ChunkSize); // Chunk data
+ a_Data.append(AllData, DataSize); // Chunk data
}
diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp
index 88b4693c9..b4f30b639 100644
--- a/src/Protocol/Protocol17x.cpp
+++ b/src/Protocol/Protocol17x.cpp
@@ -1924,7 +1924,7 @@ void cProtocol172::HandlePacketClientSettings(cByteBuffer & a_ByteBuffer)
HANDLE_READ(a_ByteBuffer, ReadByte, Byte, ShowCape);
m_Client->SetLocale(Locale);
- // TODO: handle in m_Client
+ // TODO: Do anything with the other values.
}
diff --git a/src/Protocol/Protocol17x.h b/src/Protocol/Protocol17x.h
index be94c0d61..d715e1cec 100644
--- a/src/Protocol/Protocol17x.h
+++ b/src/Protocol/Protocol17x.h
@@ -146,7 +146,6 @@ protected:
m_Lock(a_Protocol.m_CSPacket)
{
m_Out.WriteVarInt(a_PacketType);
- LOG("Send packet %i", a_PacketType);
}
~cPacketizer();
@@ -278,7 +277,7 @@ protected:
void HandlePacketBlockDig (cByteBuffer & a_ByteBuffer);
void HandlePacketBlockPlace (cByteBuffer & a_ByteBuffer);
void HandlePacketChatMessage (cByteBuffer & a_ByteBuffer);
- void HandlePacketClientSettings (cByteBuffer & a_ByteBuffer);
+ virtual void HandlePacketClientSettings (cByteBuffer & a_ByteBuffer);
virtual void HandlePacketClientStatus (cByteBuffer & a_ByteBuffer);
void HandlePacketCreativeInventoryAction(cByteBuffer & a_ByteBuffer);
virtual void HandlePacketEntityAction (cByteBuffer & a_ByteBuffer);
diff --git a/src/Protocol/Protocol18x.cpp b/src/Protocol/Protocol18x.cpp
index 4dbb2207c..a3e72d4dd 100644
--- a/src/Protocol/Protocol18x.cpp
+++ b/src/Protocol/Protocol18x.cpp
@@ -57,6 +57,29 @@ cProtocol180::cProtocol180(cClientHandle * a_Client, const AString & a_ServerAdd
+void cProtocol180::SendLoginSuccess(void)
+{
+ ASSERT(m_State == 2); // State: login?
+
+ // Disable compression:
+ {
+ cPacketizer Pkt(*this, 0x03); // Set compression packet
+ Pkt.WriteVarInt(-1);
+ }
+
+ {
+ cPacketizer Pkt(*this, 0x02); // Login success packet
+ Pkt.WriteString(cMojangAPI::MakeUUIDDashed(m_Client->GetUUID()));
+ Pkt.WriteString(m_Client->GetUsername());
+ }
+
+ m_State = 3; // State = Game
+}
+
+
+
+
+
void cProtocol180::SendParticleEffect(const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmmount)
{
ASSERT(m_State == 3); // In game mode?
@@ -81,7 +104,7 @@ void cProtocol180::SendPlayerMoveLook(void)
{
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();
Pkt.WriteDouble(Player->GetPosX());
@@ -91,7 +114,7 @@ void cProtocol180::SendPlayerMoveLook(void)
Pkt.WriteDouble(Player->GetPosZ());
Pkt.WriteFloat((float)Player->GetYaw());
Pkt.WriteFloat((float)Player->GetPitch());
- Pkt.WriteByte(0);
+ Pkt.WriteByte(0);*/
}
@@ -128,12 +151,12 @@ void cProtocol180::SendEntityVelocity(const cEntity & a_Entity)
{
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());
// 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.GetSpeedY() * 400));
- Pkt.WriteShort((short)(a_Entity.GetSpeedZ() * 400));
+ Pkt.WriteShort((short)(a_Entity.GetSpeedZ() * 400));*/
}
@@ -144,9 +167,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());*/
}
@@ -157,12 +180,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*/
}
@@ -173,14 +196,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*/
}
@@ -191,11 +214,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*/
}
@@ -206,14 +229,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*/
}
@@ -224,9 +247,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());*/
}
@@ -237,10 +260,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*/
}
@@ -340,11 +363,11 @@ void cProtocol180::SendPaintingSpawn(const cPainting & a_Painting)
{
ASSERT(m_State == 3); // In game mode?
- cPacketizer Pkt(*this, 0x10); // Spawn Painting packet
+ /*cPacketizer Pkt(*this, 0x10); // Spawn Painting packet
Pkt.WriteVarInt(a_Painting.GetUniqueID());
Pkt.WriteString(a_Painting.GetName().c_str());
Pkt.WritePosition(Vector3i(a_Painting.GetPosX(), a_Painting.GetPosY(), a_Painting.GetPosZ()));
- Pkt.WriteChar(a_Painting.GetDirection());
+ Pkt.WriteChar(a_Painting.GetDirection());*/
}
@@ -384,14 +407,14 @@ void cProtocol180::SendChunkData(int a_ChunkX, int a_ChunkZ, cChunkDataSerialize
{
ASSERT(m_State == 3); // In game mode?
- /*// Serialize first, before creating the Packetizer (the packetizer locks a CS)
+ // Serialize first, before creating the Packetizer (the packetizer locks a CS)
// This contains the flags and bitmasks, too
const AString & ChunkData = a_Serializer.Serialize(cChunkDataSerializer::RELEASE_1_8_0);
cPacketizer Pkt(*this, 0x21); // Chunk Data packet
Pkt.WriteInt(a_ChunkX);
Pkt.WriteInt(a_ChunkZ);
- Pkt.WriteBuf(ChunkData.data(), ChunkData.size());*/
+ Pkt.WriteBuf(ChunkData.data(), ChunkData.size());
}
@@ -451,7 +474,7 @@ void cProtocol180::SendChat(const AString & a_Message)
void cProtocol180::SendChat(const cCompositeChat & a_Message)
{
ASSERT(m_State == 3); // In game mode?
-
+
// Compose the complete Json string to send:
Json::Value msg;
cWorld * World = m_Client->GetPlayer()->GetWorld();
@@ -634,7 +657,10 @@ void cProtocol180::HandlePacketPluginMessage(cByteBuffer & a_ByteBuffer)
{
HANDLE_READ(a_ByteBuffer, ReadVarUTF8String, AString, Channel);
AString Data;
- a_ByteBuffer.ReadAll(Data);
+ if (!a_ByteBuffer.ReadString(Data, a_ByteBuffer.GetReadableSpace() - 1))
+ {
+ return;
+ }
m_Client->HandlePluginMessage(Channel, Data);
}
@@ -896,3 +922,19 @@ void cProtocol180::HandlePacketPlayerPosLook(cByteBuffer & a_ByteBuffer)
+
+void cProtocol180::HandlePacketClientSettings(cByteBuffer & a_ByteBuffer)
+{
+ HANDLE_READ(a_ByteBuffer, ReadVarUTF8String, AString, Locale);
+ HANDLE_READ(a_ByteBuffer, ReadByte, Byte, ViewDistance);
+ HANDLE_READ(a_ByteBuffer, ReadByte, Byte, ChatFlags);
+ HANDLE_READ(a_ByteBuffer, ReadByte, Byte, ChatColors);
+ HANDLE_READ(a_ByteBuffer, ReadChar, char, SkinFlags);
+
+ m_Client->SetLocale(Locale);
+ // TODO: Handle other values
+}
+
+
+
+
diff --git a/src/Protocol/Protocol18x.h b/src/Protocol/Protocol18x.h
index 6604cbc3e..5c6111958 100644
--- a/src/Protocol/Protocol18x.h
+++ b/src/Protocol/Protocol18x.h
@@ -54,6 +54,9 @@ public:
cProtocol180(cClientHandle * a_Client, const AString & a_ServerAddress, UInt16 a_ServerPort, UInt32 a_State);
+ 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 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 {}
@@ -105,6 +108,7 @@ protected:
virtual void HandlePacketKeepAlive(cByteBuffer & a_ByteBuffer) override;
virtual void HandlePacketPlayerPos(cByteBuffer & a_ByteBuffer) override;
virtual void HandlePacketPlayerPosLook(cByteBuffer & a_ByteBuffer) override;
+ virtual void HandlePacketClientSettings(cByteBuffer & a_ByteBuffer) override;
} ;