diff options
Diffstat (limited to 'source/Protocol')
-rw-r--r-- | source/Protocol/Protocol.h | 1 | ||||
-rw-r--r-- | source/Protocol/Protocol125.cpp | 9 | ||||
-rw-r--r-- | source/Protocol/Protocol125.h | 1 | ||||
-rw-r--r-- | source/Protocol/Protocol17x.cpp | 223 | ||||
-rw-r--r-- | source/Protocol/Protocol17x.h | 3 | ||||
-rw-r--r-- | source/Protocol/ProtocolRecognizer.cpp | 10 | ||||
-rw-r--r-- | source/Protocol/ProtocolRecognizer.h | 1 |
7 files changed, 193 insertions, 55 deletions
diff --git a/source/Protocol/Protocol.h b/source/Protocol/Protocol.h index 6bea4edbb..5d66808cf 100644 --- a/source/Protocol/Protocol.h +++ b/source/Protocol/Protocol.h @@ -99,7 +99,6 @@ public: virtual void SendUpdateSign (int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4) = 0; virtual void SendUseBed (const cEntity & a_Entity, int a_BlockX, int a_BlockY, int a_BlockZ ) = 0; virtual void SendWeather (eWeather a_Weather) = 0; - virtual void SendWholeInventory (const cInventory & a_Inventory) = 0; virtual void SendWholeInventory (const cWindow & a_Window) = 0; virtual void SendWindowClose (const cWindow & a_Window) = 0; virtual void SendWindowOpen (char a_WindowID, char a_WindowType, const AString & a_WindowTitle, char a_NumSlots) = 0; diff --git a/source/Protocol/Protocol125.cpp b/source/Protocol/Protocol125.cpp index ef40f265a..4cb1197da 100644 --- a/source/Protocol/Protocol125.cpp +++ b/source/Protocol/Protocol125.cpp @@ -940,15 +940,6 @@ void cProtocol125::SendWeather(eWeather a_Weather) -void cProtocol125::SendWholeInventory(const cInventory & a_Inventory) -{ - SendWholeInventory(*(a_Inventory.GetOwner().GetWindow())); -} - - - - - void cProtocol125::SendWholeInventory(const cWindow & a_Window) { cCSLock Lock(m_CSPacket); diff --git a/source/Protocol/Protocol125.h b/source/Protocol/Protocol125.h index 1da50a1d4..ad61dea74 100644 --- a/source/Protocol/Protocol125.h +++ b/source/Protocol/Protocol125.h @@ -76,7 +76,6 @@ public: virtual void SendUpdateSign (int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4) override; virtual void SendUseBed (const cEntity & a_Entity, int a_BlockX, int a_BlockY, int a_BlockZ ) override; virtual void SendWeather (eWeather a_Weather) override; - virtual void SendWholeInventory (const cInventory & a_Inventory) override; virtual void SendWholeInventory (const cWindow & a_Window) override; virtual void SendWindowClose (const cWindow & a_Window) override; virtual void SendWindowOpen (char a_WindowID, char a_WindowType, const AString & a_WindowTitle, char a_NumSlots) override; diff --git a/source/Protocol/Protocol17x.cpp b/source/Protocol/Protocol17x.cpp index e23ee66a5..d0ecc5583 100644 --- a/source/Protocol/Protocol17x.cpp +++ b/source/Protocol/Protocol17x.cpp @@ -10,15 +10,16 @@ Implements the 1.7.x protocol classes: #include "Globals.h" #include "Protocol17x.h" +#include "ChunkDataSerializer.h" #include "../ClientHandle.h" #include "../Root.h" #include "../Server.h" -#include "../Entities/Player.h" #include "../World.h" -#include "ChunkDataSerializer.h" -#include "../Entities/Pickup.h" #include "../WorldStorage/FastNBT.h" #include "../StringCompression.h" +#include "../Entities/FallingBlock.h" +#include "../Entities/Pickup.h" +#include "../Entities/Player.h" @@ -158,7 +159,10 @@ void cProtocol172::SendChat(const AString & a_Message) void cProtocol172::SendChunkData(int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer) { - const AString & ChunkData = a_Serializer.Serialize(cChunkDataSerializer::RELEASE_1_3_2); // This contains the flags and bitmasks, too + // 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_3_2); + cPacketizer Pkt(*this, 0x21); // Chunk Data packet Pkt.WriteInt(a_ChunkX); Pkt.WriteInt(a_ChunkZ); @@ -250,12 +254,10 @@ void cProtocol172::SendEntityLook(const cEntity & a_Entity) void cProtocol172::SendEntityMetadata(const cEntity & a_Entity) { - /* - // TODO cPacketizer Pkt(*this, 0x1c); // Entity Metadata packet Pkt.WriteInt(a_Entity.GetUniqueID()); - WriteEntityMetadata(Pkt, a_Entity); - */ + Pkt.WriteEntityMetadata(a_Entity); + Pkt.WriteByte(0x7f); // The termination byte } @@ -565,7 +567,13 @@ void cProtocol172::SendRespawn(void) void cProtocol172::SendSoundEffect(const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch) // a_Src coords are Block * 8 { - // TODO + cPacketizer Pkt(*this, 0x29); // Sound Effect packet + Pkt.WriteString(a_SoundName); + Pkt.WriteInt(a_SrcX); + Pkt.WriteInt(a_SrcY); + Pkt.WriteInt(a_SrcZ); + Pkt.WriteFloat(a_Volume); + Pkt.WriteByte((Byte)(a_Pitch * 63)); } @@ -574,7 +582,15 @@ void cProtocol172::SendSoundEffect(const AString & a_SoundName, int a_SrcX, int void cProtocol172::SendSoundParticleEffect(int a_EffectID, int a_SrcX, int a_SrcY, int a_SrcZ, int a_Data) { - // TODO + cPacketizer Pkt(*this, 0x28); // Effect packet + Pkt.WriteInt(a_EffectID); + Pkt.WriteInt(a_SrcX); + // TODO: Check if this is really an int + // wiki.vg says it's a byte, but that wouldn't cover the entire range needed (Y location * 8 = 0..2048) + Pkt.WriteInt(a_SrcY); + Pkt.WriteInt(a_SrcZ); + Pkt.WriteInt(a_Data); + Pkt.WriteBool(false); } @@ -583,7 +599,18 @@ void cProtocol172::SendSoundParticleEffect(int a_EffectID, int a_SrcX, int a_Src void cProtocol172::SendSpawnFallingBlock(const cFallingBlock & a_FallingBlock) { - // TODO + cPacketizer Pkt(*this, 0x0e); // Spawn Object packet + Pkt.WriteInt(a_FallingBlock.GetUniqueID()); + Pkt.WriteByte(70); // Falling block + Pkt.WriteFPInt(a_FallingBlock.GetPosX()); + Pkt.WriteFPInt(a_FallingBlock.GetPosY()); + Pkt.WriteFPInt(a_FallingBlock.GetPosZ()); + Pkt.WriteByteAngle(a_FallingBlock.GetYaw()); + Pkt.WriteByteAngle(a_FallingBlock.GetPitch()); + Pkt.WriteInt(((int)a_FallingBlock.GetBlockType()) | (((int)a_FallingBlock.GetBlockMeta()) << 12)); + Pkt.WriteShort((short)(a_FallingBlock.GetSpeedX() * 400)); + Pkt.WriteShort((short)(a_FallingBlock.GetSpeedY() * 400)); + Pkt.WriteShort((short)(a_FallingBlock.GetSpeedZ() * 400)); } @@ -592,7 +619,20 @@ void cProtocol172::SendSpawnFallingBlock(const cFallingBlock & a_FallingBlock) void cProtocol172::SendSpawnMob(const cMonster & a_Mob) { - // TODO + cPacketizer Pkt(*this, 0x0f); // Spawn Mob packet + Pkt.WriteInt(a_Mob.GetUniqueID()); + Pkt.WriteByte((Byte)a_Mob.GetMobType()); + Pkt.WriteFPInt(a_Mob.GetPosX()); + Pkt.WriteFPInt(a_Mob.GetPosY()); + Pkt.WriteFPInt(a_Mob.GetPosZ()); + Pkt.WriteByteAngle(a_Mob.GetPitch()); + Pkt.WriteByteAngle(a_Mob.GetHeadYaw()); + Pkt.WriteByteAngle(a_Mob.GetYaw()); + Pkt.WriteShort((short)(a_Mob.GetSpeedX() * 400)); + Pkt.WriteShort((short)(a_Mob.GetSpeedY() * 400)); + Pkt.WriteShort((short)(a_Mob.GetSpeedZ() * 400)); + Pkt.WriteEntityMetadata(a_Mob); + Pkt.WriteByte(0x7f); // Metadata terminator } @@ -601,7 +641,21 @@ void cProtocol172::SendSpawnMob(const cMonster & a_Mob) void cProtocol172::SendSpawnObject(const cEntity & a_Entity, char a_ObjectType, int a_ObjectData, Byte a_Yaw, Byte a_Pitch) { - // TODO + cPacketizer Pkt(*this, 0xe); // Spawn Object packet + Pkt.WriteInt(a_Entity.GetUniqueID()); + Pkt.WriteByte(a_ObjectType); + 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.WriteInt(a_ObjectData); + if (a_ObjectData != 0) + { + Pkt.WriteShort((short)(a_Entity.GetSpeedX() * 400)); + Pkt.WriteShort((short)(a_Entity.GetSpeedY() * 400)); + Pkt.WriteShort((short)(a_Entity.GetSpeedZ() * 400)); + } } @@ -610,7 +664,21 @@ void cProtocol172::SendSpawnObject(const cEntity & a_Entity, char a_ObjectType, void cProtocol172::SendSpawnVehicle(const cEntity & a_Vehicle, char a_VehicleType, char a_VehicleSubType) { - // TODO + cPacketizer Pkt(*this, 0xe); // Spawn Object packet + Pkt.WriteInt(a_Vehicle.GetUniqueID()); + Pkt.WriteByte(a_VehicleType); + Pkt.WriteFPInt(a_Vehicle.GetPosX()); + Pkt.WriteFPInt(a_Vehicle.GetPosY()); + Pkt.WriteFPInt(a_Vehicle.GetPosZ()); + Pkt.WriteByteAngle(a_Vehicle.GetYaw()); + Pkt.WriteByteAngle(a_Vehicle.GetPitch()); + Pkt.WriteInt(a_VehicleSubType); + if (a_VehicleSubType != 0) + { + Pkt.WriteShort((short)(a_Vehicle.GetSpeedX() * 400)); + Pkt.WriteShort((short)(a_Vehicle.GetSpeedY() * 400)); + Pkt.WriteShort((short)(a_Vehicle.GetSpeedZ() * 400)); + } } @@ -619,7 +687,17 @@ void cProtocol172::SendSpawnVehicle(const cEntity & a_Vehicle, char a_VehicleTyp void cProtocol172::SendTabCompletionResults(const AStringVector & a_Results) { - // TODO + AString Results; + Results.reserve(500); // Make a moderate reservation to avoid excessive reallocations + for (AStringVector::const_iterator itr = a_Results.begin(), end = a_Results.end(); itr != end; ++itr) + { + Results.append(*itr); + Results.push_back(0); + } + + cPacketizer Pkt(*this, 0x3a); // Tab-Complete packet + Pkt.WriteVarInt(a_Results.size()); + Pkt.WriteString(Results); } @@ -628,7 +706,13 @@ void cProtocol172::SendTabCompletionResults(const AStringVector & a_Results) void cProtocol172::SendTeleportEntity(const cEntity & a_Entity) { - // TODO + cPacketizer Pkt(*this, 0x18); + Pkt.WriteInt(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()); } @@ -637,7 +721,12 @@ void cProtocol172::SendTeleportEntity(const cEntity & a_Entity) void cProtocol172::SendThunderbolt(int a_BlockX, int a_BlockY, int a_BlockZ) { - // TODO + cPacketizer Pkt(*this, 0x2c); // Spawn Global Entity packet + Pkt.WriteVarInt(0); // EntityID = 0, always + Pkt.WriteByte(1); // Type = Thunderbolt + Pkt.WriteFPInt(a_BlockX); + Pkt.WriteFPInt(a_BlockY); + Pkt.WriteFPInt(a_BlockZ); } @@ -646,7 +735,9 @@ void cProtocol172::SendThunderbolt(int a_BlockX, int a_BlockY, int a_BlockZ) void cProtocol172::SendTimeUpdate(Int64 a_WorldAge, Int64 a_TimeOfDay) { - // TODO + cPacketizer Pkt(*this, 0x03); + Pkt.WriteInt64(a_WorldAge); + Pkt.WriteInt64(a_TimeOfDay); } @@ -655,7 +746,13 @@ void cProtocol172::SendTimeUpdate(Int64 a_WorldAge, Int64 a_TimeOfDay) void cProtocol172::SendUnloadChunk(int a_ChunkX, int a_ChunkZ) { - // TODO + cPacketizer Pkt(*this, 0x21); // Chunk Data packet + Pkt.WriteInt(a_ChunkX); + Pkt.WriteInt(a_ChunkZ); + Pkt.WriteBool(true); + Pkt.WriteShort(0); // Primary bitmap + Pkt.WriteShort(0); // Add bitmap + Pkt.WriteInt(0); // Compressed data size } @@ -664,16 +761,27 @@ void cProtocol172::SendUnloadChunk(int a_ChunkX, int a_ChunkZ) void cProtocol172::SendUpdateSign(int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4) { - // TODO + cPacketizer Pkt(*this, 0x33); + Pkt.WriteInt(a_BlockX); + Pkt.WriteShort((short)a_BlockY); + Pkt.WriteInt(a_BlockZ); + Pkt.WriteString(a_Line1); + Pkt.WriteString(a_Line2); + Pkt.WriteString(a_Line3); + Pkt.WriteString(a_Line4); } -void cProtocol172::SendUseBed(const cEntity & a_Entity, int a_BlockX, int a_BlockY, int a_BlockZ ) +void cProtocol172::SendUseBed(const cEntity & a_Entity, int a_BlockX, int a_BlockY, int a_BlockZ) { - // TODO + cPacketizer Pkt(*this, 0x0a); + Pkt.WriteInt(a_Entity.GetUniqueID()); + Pkt.WriteInt(a_BlockX); + Pkt.WriteByte((Byte)a_BlockY); + Pkt.WriteInt(a_BlockZ); } @@ -682,16 +790,9 @@ void cProtocol172::SendUseBed(const cEntity & a_Entity, int a_BlockX, int a_Bloc void cProtocol172::SendWeather(eWeather a_Weather) { - // TODO -} - - - - - -void cProtocol172::SendWholeInventory(const cInventory & a_Inventory) -{ - // TODO + cPacketizer Pkt(*this, 0x2b); + Pkt.WriteByte((a_Weather == wSunny) ? 2 : 1); // begin rain / end rain + Pkt.WriteFloat(0); // unused } @@ -1294,3 +1395,61 @@ void cProtocol172::cPacketizer::WriteFPInt(double a_Value) + +void cProtocol172::cPacketizer::WriteEntityMetadata(const cEntity & a_Entity) +{ + // Common metadata: + Byte Flags = 0; + if (a_Entity.IsOnFire()) + { + Flags |= 0x01; + } + if (a_Entity.IsCrouched()) + { + Flags |= 0x02; + } + if (a_Entity.IsSprinting()) + { + Flags |= 0x08; + } + if (a_Entity.IsRclking()) + { + Flags |= 0x10; + } + if (a_Entity.IsInvisible()) + { + Flags |= 0x20; + } + WriteByte(0); // Byte(0) + index 0 + WriteByte(Flags); + + switch (a_Entity.GetEntityType()) + { + case cEntity::etPlayer: break; // TODO? + case cEntity::etPickup: + { + WriteByte((5 << 5) | 10); // Slot(5) + index 10 + WriteItem(((const cPickup &)a_Entity).GetItem()); + break; + } + case cEntity::etMonster: + { + WriteMobMetadata((const cMonster &)a_Entity); + break; + } + // TODO: Other types + } +} + + + + + +void cProtocol172::cPacketizer::WriteMobMetadata(const cMonster & a_Mob) +{ + // TODO +} + + + + diff --git a/source/Protocol/Protocol17x.h b/source/Protocol/Protocol17x.h index 4be166814..f63cd8187 100644 --- a/source/Protocol/Protocol17x.h +++ b/source/Protocol/Protocol17x.h @@ -85,7 +85,6 @@ public: virtual void SendUpdateSign (int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4) override; virtual void SendUseBed (const cEntity & a_Entity, int a_BlockX, int a_BlockY, int a_BlockZ ) override; virtual void SendWeather (eWeather a_Weather) override; - virtual void SendWholeInventory (const cInventory & a_Inventory) override; virtual void SendWholeInventory (const cWindow & a_Window) override; virtual void SendWindowClose (const cWindow & a_Window) override; virtual void SendWindowOpen (char a_WindowID, char a_WindowType, const AString & a_WindowTitle, char a_NumSlots) override; @@ -167,6 +166,8 @@ protected: void WriteItem(const cItem & a_Item); void WriteByteAngle(double a_Angle); // Writes the specified angle using a single byte void WriteFPInt(double a_Value); // Writes the double value as a 27:5 fixed-point integer + void WriteEntityMetadata(const cEntity & a_Entity); // Writes the metadata for the specified entity, not including the terminating 0x7f + void WriteMobMetadata(const cMonster & a_Mob); // Writes the mob-specific metadata for the specified mob protected: cProtocol172 & m_Protocol; diff --git a/source/Protocol/ProtocolRecognizer.cpp b/source/Protocol/ProtocolRecognizer.cpp index 67f924d7e..501e8bbe0 100644 --- a/source/Protocol/ProtocolRecognizer.cpp +++ b/source/Protocol/ProtocolRecognizer.cpp @@ -605,16 +605,6 @@ void cProtocolRecognizer::SendWeather(eWeather a_Weather) -void cProtocolRecognizer::SendWholeInventory(const cInventory & a_Inventory) -{ - ASSERT(m_Protocol != NULL); - m_Protocol->SendWholeInventory(a_Inventory); -} - - - - - void cProtocolRecognizer::SendWholeInventory(const cWindow & a_Window) { ASSERT(m_Protocol != NULL); diff --git a/source/Protocol/ProtocolRecognizer.h b/source/Protocol/ProtocolRecognizer.h index 79dc5568f..9bf550309 100644 --- a/source/Protocol/ProtocolRecognizer.h +++ b/source/Protocol/ProtocolRecognizer.h @@ -111,7 +111,6 @@ public: virtual void SendUpdateSign (int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4) override; virtual void SendUseBed (const cEntity & a_Entity, int a_BlockX, int a_BlockY, int a_BlockZ ) override; virtual void SendWeather (eWeather a_Weather) override; - virtual void SendWholeInventory (const cInventory & a_Inventory) override; virtual void SendWholeInventory (const cWindow & a_Window) override; virtual void SendWindowClose (const cWindow & a_Window) override; virtual void SendWindowOpen (char a_WindowID, char a_WindowType, const AString & a_WindowTitle, char a_NumSlots) override; |