diff options
Diffstat (limited to '')
-rw-r--r-- | src/Protocol/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/Protocol/PacketID.cpp | 184 | ||||
-rw-r--r-- | src/Protocol/Packetizer.cpp | 85 | ||||
-rw-r--r-- | src/Protocol/Packetizer.h | 12 | ||||
-rw-r--r-- | src/Protocol/Protocol.h | 154 | ||||
-rw-r--r-- | src/Protocol/ProtocolRecognizer.cpp | 25 | ||||
-rw-r--r-- | src/Protocol/ProtocolRecognizer.h | 8 | ||||
-rw-r--r-- | src/Protocol/Protocol_1_10.cpp | 6 | ||||
-rw-r--r-- | src/Protocol/Protocol_1_10.h | 2 | ||||
-rw-r--r-- | src/Protocol/Protocol_1_11.cpp | 21 | ||||
-rw-r--r-- | src/Protocol/Protocol_1_11.h | 7 | ||||
-rw-r--r-- | src/Protocol/Protocol_1_12.cpp | 104 | ||||
-rw-r--r-- | src/Protocol/Protocol_1_12.h | 8 | ||||
-rw-r--r-- | src/Protocol/Protocol_1_8.cpp | 278 | ||||
-rw-r--r-- | src/Protocol/Protocol_1_8.h | 6 | ||||
-rw-r--r-- | src/Protocol/Protocol_1_9.cpp | 309 | ||||
-rw-r--r-- | src/Protocol/Protocol_1_9.h | 12 |
17 files changed, 705 insertions, 517 deletions
diff --git a/src/Protocol/CMakeLists.txt b/src/Protocol/CMakeLists.txt index 9fe16900c..b9ccf0d33 100644 --- a/src/Protocol/CMakeLists.txt +++ b/src/Protocol/CMakeLists.txt @@ -4,7 +4,6 @@ SET (SRCS ChunkDataSerializer.cpp ForgeHandshake.cpp MojangAPI.cpp - PacketID.cpp Packetizer.cpp Protocol_1_8.cpp Protocol_1_9.cpp diff --git a/src/Protocol/PacketID.cpp b/src/Protocol/PacketID.cpp deleted file mode 100644 index 135d60a6c..000000000 --- a/src/Protocol/PacketID.cpp +++ /dev/null @@ -1,184 +0,0 @@ -#include "Globals.h" - -#include "Protocol_1_9.h" -#include "Protocol_1_12.h" - - - - - -UInt32 cProtocol_1_9_0::GetPacketId(eOutgoingPackets a_Packet) -{ - switch (a_Packet) - { - case sendAttachEntity: return 0x40; - case sendBlockAction: return 0x0a; - case sendBlockBreakAnim: return 0x08; - case sendBlockChange: return 0x0b; - case sendBlockChanges: return 0x10; - case sendCameraSetTo: return 0x36; - case sendChatRaw: return 0x0f; - case sendCollectEntity: return 0x49; - case sendDestroyEntity: return 0x30; - case sendDifficulty: return 0x0d; - case sendDisconnectDuringGame: return 0x1a; - case sendDisconnectDuringLogin: return 0x0; - case sendDisplayObjective: return 0x38; - case sendEditSign: return 0x2a; - case sendEntityAnimation: return 0x06; - case sendEntityEffect: return 0x4c; - case sendEntityEquipment: return 0x3c; - case sendEntityHeadLook: return 0x34; - case sendEntityLook: return 0x27; - case sendEntityMeta: return 0x39; - case sendEntityProperties: return 0x4b; - case sendEntityRelMove: return 0x25; - case sendEntityRelMoveLook: return 0x26; - case sendEntityStatus: return 0x1b; - case sendEntityVelocity: return 0x3b; - case sendExperience: return 0x3d; - case sendExperienceOrb: return 0x01; - case sendExplosion: return 0x1c; - case sendGameMode: return 0x1e; - case sendHealth: return 0x3e; - case sendHeldItemChange: return 0x37; - case sendInventorySlot: return 0x16; - case sendJoinGame: return 0x23; - case sendKeepAlive: return 0x1f; - case sendLeashEntity: return 0x3a; - case sendMapData: return 0x24; - case sendPaintingSpawn: return 0x04; - case sendParticleEffect: return 0x22; - case sendPlayerAbilities: return 0x2b; - case sendPlayerList: return 0x2d; - case sendPlayerMaxSpeed: return 0x4b; - case sendPlayerMoveLook: return 0x2e; - case sendPlayerSpawn: return 0x05; - case sendPluginMessage: return 0x18; - case sendRemoveEntityEffect: return 0x31; - case sendRespawn: return 0x33; - case sendScoreboardObjective: return 0x3f; - case sendScoreUpdate: return 0x42; - case sendSpawnGlobalEntity: return 0x02; - case sendSpawnObject: return 0x00; - case sendSpawnPosition: return 0x43; - case sendSoundEffect: return 0x19; - case sendSoundParticleEffect: return 0x21; - case sendSpawnMob: return 0x03; - case sendStatistics: return 0x07; - case sendTabCompletion: return 0x0e; - case sendTeleportEntity: return 0x4a; - case sendTimeUpdate: return 0x44; - case sendTitle: return 0x45; - case sendUnloadChunk: return 0x1d; - case sendUpdateBlockEntity: return 0x09; - case sendUpdateSign: return 0x46; - case sendUseBed: return 0x2f; - case sendWeather: return 0x1e; - case sendWindowClose: return 0x12; - case sendWindowItems: return 0x14; - case sendWindowOpen: return 0x13; - case sendWindowProperty: return 0x15; - } - UNREACHABLE("Unsupported outgoing packet type"); -} - - - - - -UInt32 cProtocol_1_9_4::GetPacketId(eOutgoingPackets a_Packet) -{ - switch (a_Packet) - { - case sendCollectEntity: return 0x48; - case sendEntityEffect: return 0x4b; - case sendEntityProperties: return 0x4a; - case sendPlayerMaxSpeed: return 0x4a; - case sendTeleportEntity: return 0x49; - - default: return super::GetPacketId(a_Packet); - } -} - - - - - -UInt32 cProtocol_1_12::GetPacketId(eOutgoingPackets a_Packet) -{ - switch (a_Packet) - { - case sendAttachEntity: return 0x42; - case sendCameraSetTo: return 0x38; - case sendCollectEntity: return 0x4a; - case sendDestroyEntity: return 0x31; - case sendDisplayObjective: return 0x3a; - case sendEntityEffect: return 0x4e; - case sendEntityEquipment: return 0x3e; - case sendEntityHeadLook: return 0x35; - case sendEntityLook: return 0x28; - case sendEntityMeta: return 0x3b; - case sendEntityProperties: return 0x4d; - case sendEntityRelMove: return 0x26; - case sendEntityRelMoveLook: return 0x27; - case sendEntityVelocity: return 0x3d; - case sendExperience: return 0x3f; - case sendHealth: return 0x40; - case sendHeldItemChange: return 0x39; - case sendLeashEntity: return 0x3c; - case sendPlayerMaxSpeed: return 0x4d; - case sendRemoveEntityEffect: return 0x32; - case sendRespawn: return 0x34; - case sendScoreboardObjective: return 0x41; - case sendScoreUpdate: return 0x44; - case sendSpawnPosition: return 0x45; - case sendTeleportEntity: return 0x4b; - case sendTimeUpdate: return 0x46; - case sendTitle: return 0x47; - case sendUpdateBlockEntity: return 0x09; - - default: return super::GetPacketId(a_Packet); - } -} - - - - - -UInt32 cProtocol_1_12_1::GetPacketId(eOutgoingPackets a_Packet) -{ - switch (a_Packet) - { - case sendAttachEntity: return 0x43; - case sendCameraSetTo: return 0x39; - case sendCollectEntity: return 0x4b; - case sendDestroyEntity: return 0x32; - case sendDisplayObjective: return 0x3b; - case sendEntityEffect: return 0x4f; - case sendEntityEquipment: return 0x3f; - case sendEntityHeadLook: return 0x36; - case sendEntityMeta: return 0x3c; - case sendEntityProperties: return 0x4e; - case sendEntityVelocity: return 0x3e; - case sendExperience: return 0x40; - case sendHealth: return 0x41; - case sendHeldItemChange: return 0x3a; - case sendLeashEntity: return 0x3d; - case sendPlayerList: return 0x2e; - case sendPlayerAbilities: return 0x2c; - case sendPlayerMaxSpeed: return 0x4e; - case sendPlayerMoveLook: return 0x2f; - case sendRemoveEntityEffect: return 0x33; - case sendRespawn: return 0x35; - case sendScoreboardObjective: return 0x42; - case sendScoreUpdate: return 0x45; - case sendSpawnPosition: return 0x46; - case sendUseBed: return 0x30; - case sendTeleportEntity: return 0x4c; - case sendTimeUpdate: return 0x47; - case sendTitle: return 0x48; - - default: return super::GetPacketId(a_Packet); - } -} diff --git a/src/Protocol/Packetizer.cpp b/src/Protocol/Packetizer.cpp index 749b357b2..d477148bf 100644 --- a/src/Protocol/Packetizer.cpp +++ b/src/Protocol/Packetizer.cpp @@ -52,3 +52,88 @@ void cPacketizer::WriteUUID(const cUUID & a_UUID) + +AString cPacketizer::PacketTypeToStr(cProtocol::ePacketType a_PacketType) +{ + switch (a_PacketType) + { + case cProtocol::pktAttachEntity: return "pktAttachEntity"; + case cProtocol::pktBlockAction: return "pktBlockAction"; + case cProtocol::pktBlockBreakAnim: return "pktBlockBreakAnim"; + case cProtocol::pktBlockChange: return "pktBlockChange"; + case cProtocol::pktBlockChanges: return "pktBlockChanges"; + case cProtocol::pktCameraSetTo: return "pktCameraSetTo"; + case cProtocol::pktChatRaw: return "pktChatRaw"; + case cProtocol::pktCollectEntity: return "pktCollectEntity"; + case cProtocol::pktDestroyEntity: return "pktDestroyEntity"; + case cProtocol::pktDifficulty: return "pktDifficulty"; + case cProtocol::pktDisconnectDuringLogin: return "pktDisconnectDuringLogin"; + case cProtocol::pktDisconnectDuringGame: return "pktDisconnectDuringGame"; + case cProtocol::pktDisplayObjective: return "pktDisplayObjective"; + case cProtocol::pktEditSign: return "pktEditSign"; + case cProtocol::pktEncryptionRequest: return "pktEncryptionRequest"; + case cProtocol::pktEntityAnimation: return "pktEntityAnimation"; + case cProtocol::pktEntityEffect: return "pktEntityEffect"; + case cProtocol::pktEntityEquipment: return "pktEntityEquipment"; + case cProtocol::pktEntityHeadLook: return "pktEntityHeadLook"; + case cProtocol::pktEntityLook: return "pktEntityLook"; + case cProtocol::pktEntityMeta: return "pktEntityMeta"; + case cProtocol::pktEntityProperties: return "pktEntityProperties"; + case cProtocol::pktEntityRelMove: return "pktEntityRelMove"; + case cProtocol::pktEntityRelMoveLook: return "pktEntityRelMoveLook"; + case cProtocol::pktEntityStatus: return "pktEntityStatus"; + case cProtocol::pktEntityVelocity: return "pktEntityVelocity"; + case cProtocol::pktExperience: return "pktExperience"; + case cProtocol::pktExplosion: return "pktExplosion"; + case cProtocol::pktGameMode: return "pktGameMode"; + case cProtocol::pktHeldItemChange: return "pktHeldItemChange"; + case cProtocol::pktInventorySlot: return "pktInventorySlot"; + case cProtocol::pktJoinGame: return "pktJoinGame"; + case cProtocol::pktKeepAlive: return "pktKeepAlive"; + case cProtocol::pktLeashEntity: return "pktLeashEntity"; + case cProtocol::pktLoginSuccess: return "pktLoginSuccess"; + case cProtocol::pktMapData: return "pktMapData"; + case cProtocol::pktParticleEffect: return "pktParticleEffect"; + case cProtocol::pktPingResponse: return "pktPingResponse"; + case cProtocol::pktPlayerAbilities: return "pktPlayerAbilities"; + case cProtocol::pktPlayerList: return "pktPlayerList"; + case cProtocol::pktPlayerMaxSpeed: return "pktPlayerMaxSpeed"; + case cProtocol::pktPlayerMoveLook: return "pktPlayerMoveLook"; + case cProtocol::pktPluginMessage: return "pktPluginMessage"; + case cProtocol::pktRemoveEntityEffect: return "pktRemoveEntityEffect"; + case cProtocol::pktRespawn: return "pktRespawn"; + case cProtocol::pktScoreboardObjective: return "pktScoreboardObjective"; + case cProtocol::pktSpawnObject: return "pktSpawnObject"; + case cProtocol::pktSoundEffect: return "pktSoundEffect"; + case cProtocol::pktSoundParticleEffect: return "pktSoundParticleEffect"; + case cProtocol::pktSpawnExperienceOrb: return "pktSpawnExperienceOrb"; + case cProtocol::pktSpawnGlobalEntity: return "pktSpawnGlobalEntity"; + case cProtocol::pktSpawnMob: return "pktSpawnMob"; + case cProtocol::pktSpawnOtherPlayer: return "pktSpawnOtherPlayer"; + case cProtocol::pktSpawnPainting: return "pktSpawnPainting"; + case cProtocol::pktSpawnPosition: return "pktSpawnPosition"; + case cProtocol::pktStartCompression: return "pktStartCompression"; + case cProtocol::pktStatistics: return "pktStatistics"; + case cProtocol::pktStatusResponse: return "pktStatusResponse"; + case cProtocol::pktTabCompletionResults: return "pktTabCompletionResults"; + case cProtocol::pktTeleportEntity: return "pktTeleportEntity"; + case cProtocol::pktTimeUpdate: return "pktTimeUpdate"; + case cProtocol::pktTitle: return "pktTitle"; + case cProtocol::pktUnloadChunk: return "pktUnloadChunk"; + case cProtocol::pktUpdateBlockEntity: return "pktUpdateBlockEntity"; + case cProtocol::pktUpdateHealth: return "pktUpdateHealth"; + case cProtocol::pktUpdateScore: return "pktUpdateScore"; + case cProtocol::pktUpdateSign: return "pktUpdateSign"; + case cProtocol::pktUseBed: return "pktUseBed"; + case cProtocol::pktWeather: return "pktWeather"; + case cProtocol::pktWindowItems: return "pktWindowItems"; + case cProtocol::pktWindowClose: return "pktWindowClose"; + case cProtocol::pktWindowOpen: return "pktWindowOpen"; + case cProtocol::pktWindowProperty: return "pktWindowProperty"; + } + return Printf("Unknown packet type: 0x%02x", a_PacketType); +} + + + + diff --git a/src/Protocol/Packetizer.h b/src/Protocol/Packetizer.h index 6d2284976..e3a409cf0 100644 --- a/src/Protocol/Packetizer.h +++ b/src/Protocol/Packetizer.h @@ -30,13 +30,13 @@ class cPacketizer public: /** Starts serializing a new packet into the protocol's m_OutPacketBuffer. Locks the protocol's m_CSPacket to avoid multithreading issues. */ - cPacketizer(cProtocol & a_Protocol, UInt32 a_PacketType) : + cPacketizer(cProtocol & a_Protocol, cProtocol::ePacketType a_PacketType) : m_Protocol(a_Protocol), m_Out(a_Protocol.m_OutPacketBuffer), m_Lock(a_Protocol.m_CSPacket), m_PacketType(a_PacketType) // Used for logging purposes { - m_Out.WriteVarInt32(a_PacketType); + m_Out.WriteVarInt32(m_Protocol.GetPacketID(a_PacketType)); } /** Sends the packet via the contained protocol's SendPacket() function. */ @@ -140,7 +140,11 @@ public: /** Writes the specified UUID as a 128-bit BigEndian integer. */ void WriteUUID(const cUUID & a_UUID); - UInt32 GetPacketType(void) const { return m_PacketType; } + cProtocol::ePacketType GetPacketType() const { return m_PacketType; } + + /** Returns the human-readable representation of the packet type. + Used for logging the packets. */ + static AString PacketTypeToStr(cProtocol::ePacketType a_PacketType); protected: /** The protocol instance in which the packet is being constructed. */ @@ -154,7 +158,7 @@ protected: /** Type of the contained packet. Used for logging purposes, the packet type is encoded into m_Out immediately in constructor. */ - UInt32 m_PacketType; + cProtocol::ePacketType m_PacketType; } ; diff --git a/src/Protocol/Protocol.h b/src/Protocol/Protocol.h index 52dd7d0df..8707c3326 100644 --- a/src/Protocol/Protocol.h +++ b/src/Protocol/Protocol.h @@ -56,77 +56,85 @@ public: virtual ~cProtocol() {} - /** A list of all outgoing packets */ - enum eOutgoingPackets + + /** Logical types of outgoing packets. + These values get translated to on-wire packet IDs in GetPacketID(), specific for each protocol. + This is mainly useful for protocol sub-versions that re-number the packets while using mostly the same packet layout. */ + enum ePacketType { - sendAttachEntity = 0, - sendBlockAction, - sendBlockBreakAnim, - sendBlockChange, - sendBlockChanges, - sendCameraSetTo, - sendChatRaw, - sendCollectEntity, - sendDestroyEntity, - sendDifficulty, - sendDisconnectDuringLogin, - sendDisconnectDuringGame, - sendDisplayObjective, - sendEditSign, - sendEntityAnimation, - sendEntityEffect, - sendEntityEquipment, - sendEntityHeadLook, - sendEntityLook, - sendEntityMeta, - sendEntityProperties, - sendEntityRelMove, - sendEntityRelMoveLook, - sendEntityStatus, - sendEntityVelocity, - sendExperience, - sendExperienceOrb, - sendExplosion, - sendGameMode, - sendHealth, - sendHeldItemChange, - sendInventorySlot, - sendJoinGame, - sendKeepAlive, - sendLeashEntity, - sendMapData, - sendPaintingSpawn, - sendParticleEffect, - sendPlayerAbilities, - sendPlayerList, - sendPlayerMaxSpeed, - sendPlayerMoveLook, - sendPlayerSpawn, - sendPluginMessage, - sendRemoveEntityEffect, - sendRespawn, - sendScoreboardObjective, - sendScoreUpdate, - sendSpawnObject, - sendSoundEffect, - sendSoundParticleEffect, - sendSpawnGlobalEntity, - sendSpawnMob, - sendSpawnPosition, - sendStatistics, - sendTabCompletion, - sendTeleportEntity, - sendTimeUpdate, - sendTitle, - sendUnloadChunk, - sendUpdateBlockEntity, - sendUpdateSign, - sendUseBed, - sendWeather, - sendWindowItems, - sendWindowClose, - sendWindowOpen, - sendWindowProperty + pktAttachEntity = 0, + pktBlockAction, + pktBlockBreakAnim, + pktBlockChange, + pktBlockChanges, + pktCameraSetTo, + pktChatRaw, + pktCollectEntity, + pktDestroyEntity, + pktDifficulty, + pktDisconnectDuringLogin, + pktDisconnectDuringGame, + pktDisplayObjective, + pktEditSign, + pktEncryptionRequest, + pktEntityAnimation, + pktEntityEffect, + pktEntityEquipment, + pktEntityHeadLook, + pktEntityLook, + pktEntityMeta, + pktEntityProperties, + pktEntityRelMove, + pktEntityRelMoveLook, + pktEntityStatus, + pktEntityVelocity, + pktExperience, + pktExplosion, + pktGameMode, + pktHeldItemChange, + pktInventorySlot, + pktJoinGame, + pktKeepAlive, + pktLeashEntity, + pktLoginSuccess, + pktMapData, + pktParticleEffect, + pktPingResponse, + pktPlayerAbilities, + pktPlayerList, + pktPlayerMaxSpeed, + pktPlayerMoveLook, + pktPluginMessage, + pktRemoveEntityEffect, + pktRespawn, + pktScoreboardObjective, + pktSpawnObject, + pktSoundEffect, + pktSoundParticleEffect, + pktSpawnExperienceOrb, + pktSpawnGlobalEntity, + pktSpawnMob, + pktSpawnOtherPlayer, + pktSpawnPainting, + pktSpawnPosition, + pktStartCompression, + pktStatistics, + pktStatusResponse, + pktTabCompletionResults, + pktTeleportEntity, + pktTimeUpdate, + pktTitle, + pktUnloadChunk, + pktUpdateBlockEntity, + pktUpdateHealth, + pktUpdateScore, + pktUpdateSign, + pktUseBed, + pktWeather, + pktWindowItems, + pktWindowClose, + pktWindowOpen, + pktWindowProperty }; /** Called when client sends some data */ @@ -223,7 +231,9 @@ public: /** Returns the ServerID used for authentication through session.minecraft.net */ virtual AString GetAuthServerID(void) = 0; + protected: + friend class cPacketizer; cClientHandle * m_Client; @@ -239,8 +249,8 @@ protected: /** Buffer for composing packet length (so that each cPacketizer instance doesn't allocate a new cPacketBuffer) */ cByteBuffer m_OutPacketLenBuffer; - /** Returns the protocol-specific packet ID given the protocol-agnostic packet enum (see PacketID.cpp for implementations) */ - virtual UInt32 GetPacketId(eOutgoingPackets a_Packet) = 0; + /** Returns the protocol-specific packet ID given the protocol-agnostic packet enum. */ + virtual UInt32 GetPacketID(ePacketType a_Packet) = 0; /** A generic data-sending routine, all outgoing packet data needs to be routed through this so that descendants may override it. */ virtual void SendData(const char * a_Data, size_t a_Size) = 0; diff --git a/src/Protocol/ProtocolRecognizer.cpp b/src/Protocol/ProtocolRecognizer.cpp index a8d8b4cf5..9bfa0f105 100644 --- a/src/Protocol/ProtocolRecognizer.cpp +++ b/src/Protocol/ProtocolRecognizer.cpp @@ -281,7 +281,7 @@ void cProtocolRecognizer::SendDisconnect(const AString & a_Reason) else { AString Message = Printf("{\"text\":\"%s\"}", EscapeString(a_Reason).c_str()); - cPacketizer Pkt(*this, 0x00); // Disconnect packet (in login state) + cPacketizer Pkt(*this, pktDisconnectDuringLogin); Pkt.WriteString(Message); } } @@ -1196,6 +1196,25 @@ void cProtocolRecognizer::SendPacket(cPacketizer & a_Pkt) +UInt32 cProtocolRecognizer::GetPacketID(ePacketType a_PacketType) +{ + switch (a_PacketType) + { + case pktDisconnectDuringLogin: return 0x00; + case pktStatusResponse: return 0x00; + case pktPingResponse: return 0x01; + default: + { + ASSERT(!"cProtocolRecognizer::GetPacketID() called for an unhandled packet"); + return 0; + } + } +} + + + + + void cProtocolRecognizer::HandlePacketStatusRequest(void) { cServer * Server = cRoot::Get()->GetServer(); @@ -1233,7 +1252,7 @@ void cProtocolRecognizer::HandlePacketStatusRequest(void) Json::FastWriter Writer; AString Response = Writer.write(ResponseValue); - cPacketizer Pkt(*this, 0x00); // Response packet + cPacketizer Pkt(*this, pktStatusResponse); Pkt.WriteString(Response); } @@ -1249,6 +1268,6 @@ void cProtocolRecognizer::HandlePacketStatusPing() return; } - cPacketizer Pkt(*this, 0x01); // Pong packet + cPacketizer Pkt(*this, pktPingResponse); Pkt.WriteBEInt64(Timestamp); } diff --git a/src/Protocol/ProtocolRecognizer.h b/src/Protocol/ProtocolRecognizer.h index a6ae74c75..59cdfa6de 100644 --- a/src/Protocol/ProtocolRecognizer.h +++ b/src/Protocol/ProtocolRecognizer.h @@ -158,12 +158,8 @@ protected: /** Is a server list ping for an unrecognized version currently occuring? */ bool m_InPingForUnrecognizedVersion; - /** GetPacketId is implemented in each protocol version class */ - virtual UInt32 GetPacketId(eOutgoingPackets a_Packet) override - { - ASSERT(!"cProtocolRecognizer::GetPacketId should never be called! Something is horribly wrong! (this method being called implies that someone other than a Protocol-derived class is calling GetPacketId)"); - return 0; - } + /** Returns the protocol-specific packet ID given the protocol-agnostic packet enum. */ + virtual UInt32 GetPacketID(ePacketType a_PacketType) override; // Packet handlers while in status state (m_InPingForUnrecognizedVersion == true) void HandlePacketStatusRequest(); diff --git a/src/Protocol/Protocol_1_10.cpp b/src/Protocol/Protocol_1_10.cpp index 8f8ea137c..38abdb53b 100644 --- a/src/Protocol/Protocol_1_10.cpp +++ b/src/Protocol/Protocol_1_10.cpp @@ -292,7 +292,7 @@ namespace Metadata cProtocol_1_10_0::cProtocol_1_10_0(cClientHandle * a_Client, const AString & a_ServerAddress, UInt16 a_ServerPort, UInt32 a_State) : - super(a_Client, a_ServerAddress, a_ServerPort, a_State) + Super(a_Client, a_ServerAddress, a_ServerPort, a_State) { } @@ -304,7 +304,7 @@ void cProtocol_1_10_0::SendSoundEffect(const AString & a_SoundName, double a_X, { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendSoundEffect)); // Named sound effect packet + cPacketizer Pkt(*this, pktSoundEffect); Pkt.WriteString(a_SoundName); Pkt.WriteVarInt32(0); // Master sound category (may want to be changed to a parameter later) Pkt.WriteBEInt32(FloorC(a_X * 8.0)); @@ -356,7 +356,7 @@ void cProtocol_1_10_0::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) Json::FastWriter Writer; AString Response = Writer.write(ResponseValue); - cPacketizer Pkt(*this, 0x00); // Response packet + cPacketizer Pkt(*this, pktStatusResponse); Pkt.WriteString(Response); } diff --git a/src/Protocol/Protocol_1_10.h b/src/Protocol/Protocol_1_10.h index cd7c31fa0..003a4c9b9 100644 --- a/src/Protocol/Protocol_1_10.h +++ b/src/Protocol/Protocol_1_10.h @@ -22,7 +22,7 @@ Declares the 1.10 protocol classes: class cProtocol_1_10_0 : public cProtocol_1_9_4 { - typedef cProtocol_1_9_4 super; + typedef cProtocol_1_9_4 Super; public: cProtocol_1_10_0(cClientHandle * a_Client, const AString &a_ServerAddress, UInt16 a_ServerPort, UInt32 a_State); diff --git a/src/Protocol/Protocol_1_11.cpp b/src/Protocol/Protocol_1_11.cpp index bbfcd6d94..9c8e0c544 100644 --- a/src/Protocol/Protocol_1_11.cpp +++ b/src/Protocol/Protocol_1_11.cpp @@ -5,7 +5,8 @@ Implements the 1.11 protocol classes: - cProtocol_1_11_0 - release 1.11 protocol (#315) -(others may be added later in the future for the 1.11 release series) + - cProtocol_1_11_1 + - release 1.11.1 protocol (#316) */ #include "Globals.h" @@ -332,7 +333,7 @@ namespace Metadata cProtocol_1_11_0::cProtocol_1_11_0(cClientHandle * a_Client, const AString & a_ServerAddress, UInt16 a_ServerPort, UInt32 a_State) : - super(a_Client, a_ServerAddress, a_ServerPort, a_State) + Super(a_Client, a_ServerAddress, a_ServerPort, a_State) { } @@ -344,7 +345,7 @@ void cProtocol_1_11_0::SendCollectEntity(const cEntity & a_Entity, const cPlayer { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendCollectEntity)); // Collect Item packet + cPacketizer Pkt(*this, pktCollectEntity); Pkt.WriteVarInt32(a_Entity.GetUniqueID()); Pkt.WriteVarInt32(a_Player.GetUniqueID()); Pkt.WriteVarInt32(static_cast<UInt32>(a_Count)); @@ -358,7 +359,7 @@ void cProtocol_1_11_0::SendHideTitle(void) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendTitle)); // Title packet + cPacketizer Pkt(*this, pktTitle); Pkt.WriteVarInt32(4); // Hide title } @@ -370,7 +371,7 @@ void cProtocol_1_11_0::SendResetTitle(void) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendTitle)); // Title packet + cPacketizer Pkt(*this, pktTitle); Pkt.WriteVarInt32(5); // Reset title } @@ -382,7 +383,7 @@ void cProtocol_1_11_0::SendSpawnMob(const cMonster & a_Mob) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendSpawnMob)); // Spawn Mob packet + cPacketizer Pkt(*this, pktSpawnMob); Pkt.WriteVarInt32(a_Mob.GetUniqueID()); // TODO: Bad way to write a UUID, and it's not a true UUID, but this is functional for now. Pkt.WriteBEUInt64(0); @@ -526,7 +527,7 @@ void cProtocol_1_11_0::SendTitleTimes(int a_FadeInTicks, int a_DisplayTicks, int { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, 0x45); // Title packet + cPacketizer Pkt(*this, pktTitle); Pkt.WriteVarInt32(3); // Set title display times Pkt.WriteBEInt32(a_FadeInTicks); Pkt.WriteBEInt32(a_DisplayTicks); @@ -594,7 +595,7 @@ void cProtocol_1_11_0::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) // Serialize the response into a packet: Json::FastWriter Writer; - cPacketizer Pkt(*this, 0x00); // Response packet + cPacketizer Pkt(*this, pktStatusResponse); Pkt.WriteString(Writer.write(ResponseValue)); } @@ -1175,7 +1176,7 @@ void cProtocol_1_11_0::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_ cProtocol_1_11_1::cProtocol_1_11_1(cClientHandle * a_Client, const AString & a_ServerAddress, UInt16 a_ServerPort, UInt32 a_State) : - super(a_Client, a_ServerAddress, a_ServerPort, a_State) + Super(a_Client, a_ServerAddress, a_ServerPort, a_State) { } @@ -1220,6 +1221,6 @@ void cProtocol_1_11_1::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) // Serialize the response into a packet: Json::FastWriter Writer; - cPacketizer Pkt(*this, 0x00); // Response packet + cPacketizer Pkt(*this, pktStatusResponse); Pkt.WriteString(Writer.write(ResponseValue)); } diff --git a/src/Protocol/Protocol_1_11.h b/src/Protocol/Protocol_1_11.h index 128b7f7e4..362d4a310 100644 --- a/src/Protocol/Protocol_1_11.h +++ b/src/Protocol/Protocol_1_11.h @@ -5,7 +5,8 @@ Declares the 1.11 protocol classes: - cProtocol_1_11_0 - release 1.11 protocol (#315) -(others may be added later in the future for the 1.11 release series) + - cProtocol_1_11_1 + - release 1.11.1 protocol (#316) */ @@ -23,7 +24,7 @@ Declares the 1.11 protocol classes: class cProtocol_1_11_0 : public cProtocol_1_10_0 { - typedef cProtocol_1_10_0 super; + typedef cProtocol_1_10_0 Super; public: cProtocol_1_11_0(cClientHandle * a_Client, const AString &a_ServerAddress, UInt16 a_ServerPort, UInt32 a_State); @@ -51,7 +52,7 @@ protected: class cProtocol_1_11_1 : public cProtocol_1_11_0 { - typedef cProtocol_1_11_0 super; + typedef cProtocol_1_11_0 Super; public: cProtocol_1_11_1(cClientHandle * a_Client, const AString & a_ServerAddress, UInt16 a_ServerPort, UInt32 a_State); diff --git a/src/Protocol/Protocol_1_12.cpp b/src/Protocol/Protocol_1_12.cpp index 13494625c..deb0ee7a5 100644 --- a/src/Protocol/Protocol_1_12.cpp +++ b/src/Protocol/Protocol_1_12.cpp @@ -317,7 +317,7 @@ namespace Metadata cProtocol_1_12::cProtocol_1_12(cClientHandle * a_Client, const AString & a_ServerAddress, UInt16 a_ServerPort, UInt32 a_State) : - super(a_Client, a_ServerAddress, a_ServerPort, a_State) + Super(a_Client, a_ServerAddress, a_ServerPort, a_State) { } @@ -329,7 +329,7 @@ void cProtocol_1_12::SendSpawnMob(const cMonster & a_Mob) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, 0x03); // Spawn Mob packet + cPacketizer Pkt(*this, pktSpawnMob); Pkt.WriteVarInt32(a_Mob.GetUniqueID()); // TODO: Bad way to write a UUID, and it's not a true UUID, but this is functional for now. Pkt.WriteBEUInt64(0); @@ -409,7 +409,7 @@ void cProtocol_1_12::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) // Serialize the response into a packet: Json::FastWriter Writer; - cPacketizer Pkt(*this, 0x00); // Response packet + cPacketizer Pkt(*this, pktStatusResponse); Pkt.WriteString(Writer.write(ResponseValue)); } @@ -1019,6 +1019,47 @@ void cProtocol_1_12::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_Mo +UInt32 cProtocol_1_12::GetPacketID(cProtocol::ePacketType a_Packet) +{ + switch (a_Packet) + { + case pktAttachEntity: return 0x42; + case pktCameraSetTo: return 0x38; + case pktCollectEntity: return 0x4a; + case pktDestroyEntity: return 0x31; + case pktDisplayObjective: return 0x3a; + case pktEntityEffect: return 0x4e; + case pktEntityEquipment: return 0x3e; + case pktEntityHeadLook: return 0x35; + case pktEntityLook: return 0x28; + case pktEntityMeta: return 0x3b; + case pktEntityProperties: return 0x4d; + case pktEntityRelMove: return 0x26; + case pktEntityRelMoveLook: return 0x27; + case pktEntityVelocity: return 0x3d; + case pktExperience: return 0x3f; + case pktHeldItemChange: return 0x39; + case pktLeashEntity: return 0x3c; + case pktPlayerMaxSpeed: return 0x4d; + case pktRemoveEntityEffect: return 0x32; + case pktRespawn: return 0x34; + case pktScoreboardObjective: return 0x41; + case pktSpawnPosition: return 0x45; + case pktTeleportEntity: return 0x4b; + case pktTimeUpdate: return 0x46; + case pktTitle: return 0x47; + case pktUpdateBlockEntity: return 0x09; + case pktUpdateHealth: return 0x40; + case pktUpdateScore: return 0x44; + + default: return Super::GetPacketID(a_Packet); + } +} + + + + + void cProtocol_1_12::HandlePacketCraftingBookData(cByteBuffer & a_ByteBuffer) { a_ByteBuffer.SkipRead(a_ByteBuffer.GetReadableSpace() - 1); @@ -1043,7 +1084,7 @@ void cProtocol_1_12::SendTitleTimes(int a_FadeInTicks, int a_DisplayTicks, int a { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendTitle)); // Title packet + cPacketizer Pkt(*this, pktTitle); Pkt.WriteVarInt32(3); // Set title display times Pkt.WriteBEInt32(a_FadeInTicks); Pkt.WriteBEInt32(a_DisplayTicks); @@ -1058,7 +1099,7 @@ void cProtocol_1_12::SendHideTitle(void) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendTitle)); // Title packet + cPacketizer Pkt(*this, pktTitle); Pkt.WriteVarInt32(4); // Hide title } @@ -1070,7 +1111,7 @@ void cProtocol_1_12::SendResetTitle(void) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendTitle)); // Title packet + cPacketizer Pkt(*this, pktTitle); Pkt.WriteVarInt32(5); // Reset title } @@ -1082,7 +1123,7 @@ void cProtocol_1_12::SendCollectEntity(const cEntity & a_Entity, const cPlayer & { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendCollectEntity)); // Collect Item packet + cPacketizer Pkt(*this, pktCollectEntity); Pkt.WriteVarInt32(a_Entity.GetUniqueID()); Pkt.WriteVarInt32(a_Player.GetUniqueID()); Pkt.WriteVarInt32(static_cast<UInt32>(a_Count)); @@ -1188,7 +1229,7 @@ bool cProtocol_1_12::HandlePacket(cByteBuffer & a_ByteBuffer, UInt32 a_PacketTyp cProtocol_1_12_1::cProtocol_1_12_1(cClientHandle * a_Client, const AString & a_ServerAddress, UInt16 a_ServerPort, UInt32 a_State) : - super(a_Client, a_ServerAddress, a_ServerPort, a_State) + Super(a_Client, a_ServerAddress, a_ServerPort, a_State) { } @@ -1196,6 +1237,47 @@ cProtocol_1_12_1::cProtocol_1_12_1(cClientHandle * a_Client, const AString & a_S +UInt32 cProtocol_1_12_1::GetPacketID(ePacketType a_Packet) +{ + switch (a_Packet) + { + case pktAttachEntity: return 0x43; + case pktCameraSetTo: return 0x39; + case pktCollectEntity: return 0x4b; + case pktDestroyEntity: return 0x32; + case pktDisplayObjective: return 0x3b; + case pktEntityEffect: return 0x4f; + case pktEntityEquipment: return 0x3f; + case pktEntityHeadLook: return 0x36; + case pktEntityMeta: return 0x3c; + case pktEntityProperties: return 0x4e; + case pktEntityVelocity: return 0x3e; + case pktExperience: return 0x40; + case pktHeldItemChange: return 0x3a; + case pktLeashEntity: return 0x3d; + case pktPlayerList: return 0x2e; + case pktPlayerAbilities: return 0x2c; + case pktPlayerMaxSpeed: return 0x4e; + case pktPlayerMoveLook: return 0x2f; + case pktRemoveEntityEffect: return 0x33; + case pktRespawn: return 0x35; + case pktScoreboardObjective: return 0x42; + case pktSpawnPosition: return 0x46; + case pktUpdateHealth: return 0x41; + case pktUpdateScore: return 0x45; + case pktUseBed: return 0x30; + case pktTeleportEntity: return 0x4c; + case pktTimeUpdate: return 0x47; + case pktTitle: return 0x48; + + default: return Super::GetPacketID(a_Packet); + } +} + + + + + void cProtocol_1_12_1::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) { cServer * Server = cRoot::Get()->GetServer(); @@ -1232,7 +1314,7 @@ void cProtocol_1_12_1::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) // Serialize the response into a packet: Json::FastWriter Writer; - cPacketizer Pkt(*this, 0x00); // Response packet + cPacketizer Pkt(*this, pktStatusResponse); Pkt.WriteString(Writer.write(ResponseValue)); } @@ -1390,7 +1472,7 @@ void cProtocol_1_12_2::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) // Serialize the response into a packet: Json::FastWriter Writer; - cPacketizer Pkt(*this, 0x00); // Response packet + cPacketizer Pkt(*this, pktStatusResponse); Pkt.WriteString(Writer.write(ResponseValue)); } @@ -1407,6 +1489,6 @@ void cProtocol_1_12_2::SendKeepAlive(UInt32 a_PingID) return; } - cPacketizer Pkt(*this, GetPacketId(sendKeepAlive)); // Keep Alive packet + cPacketizer Pkt(*this, pktKeepAlive); Pkt.WriteBEInt64(a_PingID); } diff --git a/src/Protocol/Protocol_1_12.h b/src/Protocol/Protocol_1_12.h index fe518fdbd..25a103801 100644 --- a/src/Protocol/Protocol_1_12.h +++ b/src/Protocol/Protocol_1_12.h @@ -27,7 +27,7 @@ Declares the 1.12 protocol classes: class cProtocol_1_12 : public cProtocol_1_11_1 { - typedef cProtocol_1_11_1 super; + typedef cProtocol_1_11_1 Super; public: cProtocol_1_12(cClientHandle * a_Client, const AString &a_ServerAddress, UInt16 a_ServerPort, UInt32 a_State); @@ -48,7 +48,7 @@ protected: protected: - virtual UInt32 GetPacketId(eOutgoingPackets a_Packet) override; + virtual UInt32 GetPacketID(ePacketType a_Packet) override; }; @@ -58,13 +58,13 @@ protected: class cProtocol_1_12_1 : public cProtocol_1_12 { - typedef cProtocol_1_12 super; + typedef cProtocol_1_12 Super; public: cProtocol_1_12_1(cClientHandle * a_Client, const AString &a_ServerAddress, UInt16 a_ServerPort, UInt32 a_State); protected: - virtual UInt32 GetPacketId(eOutgoingPackets a_Packet) override; + virtual UInt32 GetPacketID(ePacketType a_Packet) override; virtual bool HandlePacket(cByteBuffer & a_ByteBuffer, UInt32 a_PacketType) override; virtual void HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) override; diff --git a/src/Protocol/Protocol_1_8.cpp b/src/Protocol/Protocol_1_8.cpp index e3022ab73..72fbb4678 100644 --- a/src/Protocol/Protocol_1_8.cpp +++ b/src/Protocol/Protocol_1_8.cpp @@ -183,7 +183,7 @@ void cProtocol_1_8_0::SendAttachEntity(const cEntity & a_Entity, const cEntity & { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, 0x1b); // Attach Entity packet + cPacketizer Pkt(*this, pktAttachEntity); Pkt.WriteBEUInt32(a_Entity.GetUniqueID()); Pkt.WriteBEUInt32(a_Vehicle.GetUniqueID()); Pkt.WriteBool(false); @@ -197,7 +197,7 @@ void cProtocol_1_8_0::SendBlockAction(int a_BlockX, int a_BlockY, int a_BlockZ, { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, 0x24); // Block Action packet + cPacketizer Pkt(*this, pktBlockAction); Pkt.WritePosition64(a_BlockX, a_BlockY, a_BlockZ); Pkt.WriteBEInt8(a_Byte1); Pkt.WriteBEInt8(a_Byte2); @@ -212,7 +212,7 @@ void cProtocol_1_8_0::SendBlockBreakAnim(UInt32 a_EntityID, int a_BlockX, int a_ { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, 0x25); // Block Break Animation packet + cPacketizer Pkt(*this, pktBlockBreakAnim); Pkt.WriteVarInt32(a_EntityID); Pkt.WritePosition64(a_BlockX, a_BlockY, a_BlockZ); Pkt.WriteBEInt8(a_Stage); @@ -226,7 +226,7 @@ void cProtocol_1_8_0::SendBlockChange(int a_BlockX, int a_BlockY, int a_BlockZ, { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, 0x23); // Block Change packet + cPacketizer Pkt(*this, pktBlockChange); Pkt.WritePosition64(a_BlockX, a_BlockY, a_BlockZ); Pkt.WriteVarInt32((static_cast<UInt32>(a_BlockType) << 4) | (static_cast<UInt32>(a_BlockMeta) & 15)); } @@ -239,7 +239,7 @@ void cProtocol_1_8_0::SendBlockChanges(int a_ChunkX, int a_ChunkZ, const sSetBlo { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, 0x22); // Multi Block Change packet + cPacketizer Pkt(*this, pktBlockChanges); Pkt.WriteBEInt32(a_ChunkX); Pkt.WriteBEInt32(a_ChunkZ); Pkt.WriteVarInt32(static_cast<UInt32>(a_Changes.size())); @@ -257,7 +257,7 @@ void cProtocol_1_8_0::SendBlockChanges(int a_ChunkX, int a_ChunkZ, const sSetBlo void cProtocol_1_8_0::SendCameraSetTo(const cEntity & a_Entity) { - cPacketizer Pkt(*this, 0x43); // Camera Packet (Attach the camera of a player at another entity in spectator mode) + cPacketizer Pkt(*this, pktCameraSetTo); Pkt.WriteVarInt32(a_Entity.GetUniqueID()); } @@ -292,7 +292,7 @@ void cProtocol_1_8_0::SendChatRaw(const AString & a_MessageRaw, eChatType a_Type ASSERT(m_State == 3); // In game mode? // Send the json string to the client: - cPacketizer Pkt(*this, 0x02); + cPacketizer Pkt(*this, pktChatRaw); Pkt.WriteString(a_MessageRaw); Pkt.WriteBEInt8(a_Type); } @@ -322,7 +322,7 @@ void cProtocol_1_8_0::SendCollectEntity(const cEntity & a_Entity, const cPlayer UNUSED(a_Count); ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, 0x0d); // Collect Item packet + cPacketizer Pkt(*this, pktCollectEntity); Pkt.WriteVarInt32(a_Entity.GetUniqueID()); Pkt.WriteVarInt32(a_Player.GetUniqueID()); } @@ -335,7 +335,7 @@ void cProtocol_1_8_0::SendDestroyEntity(const cEntity & a_Entity) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, 0x13); // Destroy Entities packet + cPacketizer Pkt(*this, pktDestroyEntity); Pkt.WriteVarInt32(1); Pkt.WriteVarInt32(a_Entity.GetUniqueID()); } @@ -348,7 +348,7 @@ void cProtocol_1_8_0::SendDetachEntity(const cEntity & a_Entity, const cEntity & { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, 0x1b); // Attach Entity packet + cPacketizer Pkt(*this, pktAttachEntity); Pkt.WriteBEUInt32(a_Entity.GetUniqueID()); Pkt.WriteBEUInt32(0); Pkt.WriteBool(false); @@ -365,14 +365,14 @@ void cProtocol_1_8_0::SendDisconnect(const AString & a_Reason) case 2: { // During login: - cPacketizer Pkt(*this, 0); + cPacketizer Pkt(*this, pktDisconnectDuringLogin); Pkt.WriteString(Printf("{\"text\":\"%s\"}", EscapeString(a_Reason).c_str())); break; } case 3: { // In-game: - cPacketizer Pkt(*this, 0x40); + cPacketizer Pkt(*this, pktDisconnectDuringGame); Pkt.WriteString(Printf("{\"text\":\"%s\"}", EscapeString(a_Reason).c_str())); break; } @@ -387,7 +387,7 @@ void cProtocol_1_8_0::SendEditSign(int a_BlockX, int a_BlockY, int a_BlockZ) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, 0x36); // Sign Editor Open packet + cPacketizer Pkt(*this, pktEditSign); Pkt.WritePosition64(a_BlockX, a_BlockY, a_BlockZ); } @@ -399,7 +399,7 @@ void cProtocol_1_8_0::SendEntityEffect(const cEntity & a_Entity, int a_EffectID, { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, 0x1D); // Entity Effect packet + cPacketizer Pkt(*this, pktEntityEffect); Pkt.WriteVarInt32(a_Entity.GetUniqueID()); Pkt.WriteBEUInt8(static_cast<UInt8>(a_EffectID)); Pkt.WriteBEUInt8(static_cast<UInt8>(a_Amplifier)); @@ -415,7 +415,7 @@ void cProtocol_1_8_0::SendEntityEquipment(const cEntity & a_Entity, short a_Slot { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, 0x04); // Entity Equipment packet + cPacketizer Pkt(*this, pktEntityEquipment); Pkt.WriteVarInt32(a_Entity.GetUniqueID()); Pkt.WriteBEInt16(a_SlotNum); WriteItem(Pkt, a_Item); @@ -429,7 +429,7 @@ void cProtocol_1_8_0::SendEntityHeadLook(const cEntity & a_Entity) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, 0x19); // Entity Head Look packet + cPacketizer Pkt(*this, pktEntityHeadLook); Pkt.WriteVarInt32(a_Entity.GetUniqueID()); Pkt.WriteByteAngle(a_Entity.GetHeadYaw()); } @@ -442,7 +442,7 @@ void cProtocol_1_8_0::SendEntityLook(const cEntity & a_Entity) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, 0x16); // Entity Look packet + cPacketizer Pkt(*this, pktEntityLook); Pkt.WriteVarInt32(a_Entity.GetUniqueID()); Pkt.WriteByteAngle(a_Entity.GetYaw()); Pkt.WriteByteAngle(a_Entity.GetPitch()); @@ -457,7 +457,7 @@ void cProtocol_1_8_0::SendEntityMetadata(const cEntity & a_Entity) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, 0x1c); // Entity Metadata packet + cPacketizer Pkt(*this, pktEntityMeta); Pkt.WriteVarInt32(a_Entity.GetUniqueID()); WriteEntityMetadata(Pkt, a_Entity); Pkt.WriteBEUInt8(0x7f); // The termination byte @@ -471,7 +471,7 @@ void cProtocol_1_8_0::SendEntityProperties(const cEntity & a_Entity) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, 0x20); // Entity Properties packet + cPacketizer Pkt(*this, pktEntityProperties); Pkt.WriteVarInt32(a_Entity.GetUniqueID()); WriteEntityProperties(Pkt, a_Entity); } @@ -484,7 +484,7 @@ void cProtocol_1_8_0::SendEntityRelMove(const cEntity & a_Entity, char a_RelX, c { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, 0x15); // Entity Relative Move packet + cPacketizer Pkt(*this, pktEntityRelMove); Pkt.WriteVarInt32(a_Entity.GetUniqueID()); Pkt.WriteBEInt8(a_RelX); Pkt.WriteBEInt8(a_RelY); @@ -500,7 +500,7 @@ void cProtocol_1_8_0::SendEntityRelMoveLook(const cEntity & a_Entity, char a_Rel { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, 0x17); // Entity Look And Relative Move packet + cPacketizer Pkt(*this, pktEntityRelMoveLook); Pkt.WriteVarInt32(a_Entity.GetUniqueID()); Pkt.WriteBEInt8(a_RelX); Pkt.WriteBEInt8(a_RelY); @@ -518,7 +518,7 @@ void cProtocol_1_8_0::SendEntityStatus(const cEntity & a_Entity, char a_Status) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, 0x1a); // Entity Status packet + cPacketizer Pkt(*this, pktEntityStatus); Pkt.WriteBEUInt32(a_Entity.GetUniqueID()); Pkt.WriteBEInt8(a_Status); } @@ -531,7 +531,7 @@ void cProtocol_1_8_0::SendEntityVelocity(const cEntity & a_Entity) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, 0x12); // Entity Velocity packet + cPacketizer Pkt(*this, pktEntityVelocity); Pkt.WriteVarInt32(a_Entity.GetUniqueID()); // 400 = 8000 / 20 ... Conversion from our speed in m / s to 8000 m / tick Pkt.WriteBEInt16(static_cast<Int16>(a_Entity.GetSpeedX() * 400)); @@ -547,7 +547,7 @@ void cProtocol_1_8_0::SendExplosion(double a_BlockX, double a_BlockY, double a_B { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, 0x27); // Explosion packet + cPacketizer Pkt(*this, pktExplosion); Pkt.WriteBEFloat(static_cast<float>(a_BlockX)); Pkt.WriteBEFloat(static_cast<float>(a_BlockY)); Pkt.WriteBEFloat(static_cast<float>(a_BlockZ)); @@ -572,7 +572,7 @@ void cProtocol_1_8_0::SendGameMode(eGameMode a_GameMode) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, 0x2b); // Change Game State packet + cPacketizer Pkt(*this, pktGameMode); Pkt.WriteBEUInt8(3); // Reason: Change game mode Pkt.WriteBEFloat(static_cast<float>(a_GameMode)); // The protocol really represents the value with a float! } @@ -585,7 +585,7 @@ void cProtocol_1_8_0::SendHealth(void) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, 0x06); // Update Health packet + cPacketizer Pkt(*this, pktUpdateHealth); cPlayer * Player = m_Client->GetPlayer(); Pkt.WriteBEFloat(static_cast<float>(Player->GetHealth())); Pkt.WriteVarInt32(static_cast<UInt32>(Player->GetFoodLevel())); @@ -600,7 +600,7 @@ void cProtocol_1_8_0::SendHeldItemChange(int a_ItemIndex) { ASSERT((a_ItemIndex >= 0) && (a_ItemIndex <= 8)); // Valid check - cPacketizer Pkt(*this, 0x09); // Held item change + cPacketizer Pkt(*this, pktHeldItemChange); cPlayer * Player = m_Client->GetPlayer(); Pkt.WriteBEInt8(static_cast<Int8>(Player->GetInventory().GetEquippedSlotNum())); } @@ -613,7 +613,7 @@ void cProtocol_1_8_0::SendHideTitle(void) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, 0x45); // Title packet + cPacketizer Pkt(*this, pktTitle); Pkt.WriteVarInt32(3); // Hide title } @@ -625,7 +625,7 @@ void cProtocol_1_8_0::SendInventorySlot(char a_WindowID, short a_SlotNum, const { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, 0x2f); // Set Slot packet + cPacketizer Pkt(*this, pktInventorySlot); Pkt.WriteBEInt8(a_WindowID); Pkt.WriteBEInt16(a_SlotNum); WriteItem(Pkt, a_Item); @@ -644,7 +644,7 @@ void cProtocol_1_8_0::SendKeepAlive(UInt32 a_PingID) return; } - cPacketizer Pkt(*this, 0x00); // Keep Alive packet + cPacketizer Pkt(*this, pktKeepAlive); Pkt.WriteVarInt32(a_PingID); } @@ -656,7 +656,7 @@ void cProtocol_1_8_0::SendLeashEntity(const cEntity & a_Entity, const cEntity & { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, 0x1b); // Attach Entity packet + cPacketizer Pkt(*this, pktLeashEntity); Pkt.WriteBEUInt32(a_Entity.GetUniqueID()); Pkt.WriteBEUInt32(a_EntityLeashedTo.GetUniqueID()); Pkt.WriteBool(true); @@ -670,7 +670,7 @@ void cProtocol_1_8_0::SendUnleashEntity(const cEntity & a_Entity) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, 0x1b); // Attach Entity packet + cPacketizer Pkt(*this, pktLeashEntity); Pkt.WriteBEUInt32(a_Entity.GetUniqueID()); Pkt.WriteBEInt32(-1); Pkt.WriteBool(true); @@ -685,7 +685,7 @@ void cProtocol_1_8_0::SendLogin(const cPlayer & a_Player, const cWorld & a_World // Send the Join Game packet: { cServer * Server = cRoot::Get()->GetServer(); - cPacketizer Pkt(*this, 0x01); // Join Game packet + cPacketizer Pkt(*this, pktJoinGame); Pkt.WriteBEUInt32(a_Player.GetUniqueID()); Pkt.WriteBEUInt8(static_cast<UInt8>(a_Player.GetEffectiveGameMode()) | (Server->IsHardcore() ? 0x08 : 0)); // Hardcore flag bit 4 Pkt.WriteBEInt8(static_cast<Int8>(a_World.GetDimension())); @@ -697,13 +697,13 @@ void cProtocol_1_8_0::SendLogin(const cPlayer & a_Player, const cWorld & a_World // Send the spawn position: { - cPacketizer Pkt(*this, 0x05); // Spawn Position packet + cPacketizer Pkt(*this, pktSpawnPosition); Pkt.WritePosition64(FloorC(a_World.GetSpawnX()), FloorC(a_World.GetSpawnY()), FloorC(a_World.GetSpawnZ())); } // Send the server difficulty: { - cPacketizer Pkt(*this, 0x41); + cPacketizer Pkt(*this, pktDifficulty); Pkt.WriteBEInt8(1); } @@ -721,14 +721,14 @@ void cProtocol_1_8_0::SendLoginSuccess(void) // Enable compression: { - cPacketizer Pkt(*this, 0x03); // Set compression packet + cPacketizer Pkt(*this, pktStartCompression); Pkt.WriteVarInt32(256); } m_State = 3; // State = Game { - cPacketizer Pkt(*this, 0x02); // Login success packet + cPacketizer Pkt(*this, pktLoginSuccess); Pkt.WriteString(m_Client->GetUUID().ToLongString()); Pkt.WriteString(m_Client->GetUsername()); } @@ -745,7 +745,7 @@ void cProtocol_1_8_0::SendPaintingSpawn(const cPainting & a_Painting) double PosY = a_Painting.GetPosY(); double PosZ = a_Painting.GetPosZ(); - cPacketizer Pkt(*this, 0x10); // Spawn Painting packet + cPacketizer Pkt(*this, pktSpawnPainting); Pkt.WriteVarInt32(a_Painting.GetUniqueID()); Pkt.WriteString(a_Painting.GetName().c_str()); Pkt.WritePosition64(static_cast<Int32>(PosX), static_cast<Int32>(PosY), static_cast<Int32>(PosZ)); @@ -760,7 +760,7 @@ void cProtocol_1_8_0::SendMapData(const cMap & a_Map, int a_DataStartX, int a_Da { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, 0x34); + cPacketizer Pkt(*this, pktMapData); Pkt.WriteVarInt32(a_Map.GetID()); Pkt.WriteBEUInt8(static_cast<UInt8>(a_Map.GetScale())); @@ -792,7 +792,7 @@ void cProtocol_1_8_0::SendPickupSpawn(const cPickup & a_Pickup) ASSERT(m_State == 3); // In game mode? { - cPacketizer Pkt(*this, 0x0e); // Spawn Object packet + cPacketizer Pkt(*this, pktSpawnObject); Pkt.WriteVarInt32(a_Pickup.GetUniqueID()); Pkt.WriteBEUInt8(2); // Type = Pickup Pkt.WriteFPInt(a_Pickup.GetPosX()); @@ -802,14 +802,7 @@ void cProtocol_1_8_0::SendPickupSpawn(const cPickup & a_Pickup) Pkt.WriteByteAngle(a_Pickup.GetPitch()); Pkt.WriteBEInt32(0); // No object data } - - { - cPacketizer Pkt(*this, 0x1c); // Entity Metadata packet - Pkt.WriteVarInt32(a_Pickup.GetUniqueID()); - Pkt.WriteBEUInt8((0x05 << 5) | 10); // Slot type + index 10 - WriteItem(Pkt, a_Pickup.GetItem()); - Pkt.WriteBEUInt8(0x7f); // End of metadata - } + SendEntityMetadata(a_Pickup); } @@ -820,7 +813,7 @@ void cProtocol_1_8_0::SendPlayerAbilities(void) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, 0x39); // Player Abilities packet + cPacketizer Pkt(*this, pktPlayerAbilities); Byte Flags = 0; cPlayer * Player = m_Client->GetPlayer(); if (Player->IsGameModeCreative()) @@ -849,7 +842,7 @@ void cProtocol_1_8_0::SendEntityAnimation(const cEntity & a_Entity, char a_Anima { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, 0x0b); // Animation packet + cPacketizer Pkt(*this, pktEntityAnimation); Pkt.WriteVarInt32(a_Entity.GetUniqueID()); Pkt.WriteBEInt8(a_Animation); } @@ -863,7 +856,7 @@ void cProtocol_1_8_0::SendParticleEffect(const AString & a_ParticleName, float a ASSERT(m_State == 3); // In game mode? int ParticleID = GetParticleID(a_ParticleName); - cPacketizer Pkt(*this, 0x2A); + cPacketizer Pkt(*this, pktParticleEffect); Pkt.WriteBEInt32(ParticleID); Pkt.WriteBool(false); Pkt.WriteBEFloat(a_SrcX); @@ -885,7 +878,7 @@ void cProtocol_1_8_0::SendParticleEffect(const AString & a_ParticleName, Vector3 ASSERT(m_State == 3); // In game mode? int ParticleID = GetParticleID(a_ParticleName); - cPacketizer Pkt(*this, 0x2A); + cPacketizer Pkt(*this, pktParticleEffect); Pkt.WriteBEInt32(ParticleID); Pkt.WriteBool(false); Pkt.WriteBEFloat(a_Src.x); @@ -928,7 +921,7 @@ void cProtocol_1_8_0::SendPlayerListAddPlayer(const cPlayer & a_Player) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, 0x38); // Playerlist Item packet + cPacketizer Pkt(*this, pktPlayerList); Pkt.WriteVarInt32(0); Pkt.WriteVarInt32(1); Pkt.WriteUUID(a_Player.GetUUID()); @@ -965,7 +958,7 @@ void cProtocol_1_8_0::SendPlayerListRemovePlayer(const cPlayer & a_Player) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, 0x38); // Playerlist Item packet + cPacketizer Pkt(*this, pktPlayerList); Pkt.WriteVarInt32(4); Pkt.WriteVarInt32(1); Pkt.WriteUUID(a_Player.GetUUID()); @@ -979,7 +972,7 @@ void cProtocol_1_8_0::SendPlayerListUpdateGameMode(const cPlayer & a_Player) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, 0x38); // Playerlist Item packet + cPacketizer Pkt(*this, pktPlayerList); Pkt.WriteVarInt32(1); Pkt.WriteVarInt32(1); Pkt.WriteUUID(a_Player.GetUUID()); @@ -997,7 +990,7 @@ void cProtocol_1_8_0::SendPlayerListUpdatePing(const cPlayer & a_Player) auto ClientHandle = a_Player.GetClientHandlePtr(); if (ClientHandle != nullptr) { - cPacketizer Pkt(*this, 0x38); // Playerlist Item packet + cPacketizer Pkt(*this, pktPlayerList); Pkt.WriteVarInt32(2); Pkt.WriteVarInt32(1); Pkt.WriteUUID(a_Player.GetUUID()); @@ -1013,7 +1006,7 @@ void cProtocol_1_8_0::SendPlayerListUpdateDisplayName(const cPlayer & a_Player, { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, 0x38); // Playerlist Item packet + cPacketizer Pkt(*this, pktPlayerList); Pkt.WriteVarInt32(3); Pkt.WriteVarInt32(1); Pkt.WriteUUID(a_Player.GetUUID()); @@ -1037,7 +1030,7 @@ void cProtocol_1_8_0::SendPlayerMaxSpeed(void) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, 0x20); // Entity Properties + cPacketizer Pkt(*this, pktEntityProperties); cPlayer * Player = m_Client->GetPlayer(); Pkt.WriteVarInt32(Player->GetUniqueID()); Pkt.WriteBEInt32(1); // Count @@ -1066,7 +1059,7 @@ void cProtocol_1_8_0::SendPlayerMoveLook(void) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, 0x08); // Player Position And Look packet + cPacketizer Pkt(*this, pktPlayerMoveLook); cPlayer * Player = m_Client->GetPlayer(); Pkt.WriteBEDouble(Player->GetPosX()); Pkt.WriteBEDouble(Player->GetPosY()); @@ -1093,7 +1086,7 @@ void cProtocol_1_8_0::SendPlayerPosition(void) void cProtocol_1_8_0::SendPlayerSpawn(const cPlayer & a_Player) { // Called to spawn another player for the client - cPacketizer Pkt(*this, 0x0c); // Spawn Player packet + cPacketizer Pkt(*this, pktSpawnOtherPlayer); Pkt.WriteVarInt32(a_Player.GetUniqueID()); Pkt.WriteUUID(a_Player.GetUUID()); Vector3d LastSentPos = a_Player.GetLastSentPos(); @@ -1119,7 +1112,7 @@ void cProtocol_1_8_0::SendPluginMessage(const AString & a_Channel, const AString { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, 0x3f); + cPacketizer Pkt(*this, pktPluginMessage); Pkt.WriteString(a_Channel); Pkt.WriteBuf(a_Message.data(), a_Message.size()); } @@ -1132,7 +1125,7 @@ void cProtocol_1_8_0::SendRemoveEntityEffect(const cEntity & a_Entity, int a_Eff { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, 0x1e); + cPacketizer Pkt(*this, pktRemoveEntityEffect); Pkt.WriteVarInt32(a_Entity.GetUniqueID()); Pkt.WriteBEUInt8(static_cast<UInt8>(a_EffectID)); } @@ -1145,7 +1138,7 @@ void cProtocol_1_8_0::SendResetTitle(void) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, 0x45); // Title packet + cPacketizer Pkt(*this, pktTitle); Pkt.WriteVarInt32(4); // Reset title } @@ -1156,7 +1149,7 @@ void cProtocol_1_8_0::SendResetTitle(void) void cProtocol_1_8_0::SendRespawn(eDimension a_Dimension) { - cPacketizer Pkt(*this, 0x07); // Respawn packet + cPacketizer Pkt(*this, pktRespawn); cPlayer * Player = m_Client->GetPlayer(); Pkt.WriteBEInt32(static_cast<Int32>(a_Dimension)); Pkt.WriteBEUInt8(2); // TODO: Difficulty (set to Normal) @@ -1172,7 +1165,7 @@ void cProtocol_1_8_0::SendExperience(void) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, 0x1f); // Experience Packet + cPacketizer Pkt(*this, pktExperience); cPlayer * Player = m_Client->GetPlayer(); Pkt.WriteBEFloat(Player->GetXpPercentage()); Pkt.WriteVarInt32(static_cast<UInt32>(Player->GetXpLevel())); @@ -1187,7 +1180,7 @@ void cProtocol_1_8_0::SendExperienceOrb(const cExpOrb & a_ExpOrb) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, 0x11); + cPacketizer Pkt(*this, pktSpawnExperienceOrb); Pkt.WriteVarInt32(a_ExpOrb.GetUniqueID()); Pkt.WriteFPInt(a_ExpOrb.GetPosX()); Pkt.WriteFPInt(a_ExpOrb.GetPosY()); @@ -1203,7 +1196,7 @@ void cProtocol_1_8_0::SendScoreboardObjective(const AString & a_Name, const AStr { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, 0x3b); + cPacketizer Pkt(*this, pktScoreboardObjective); Pkt.WriteString(a_Name); Pkt.WriteBEUInt8(a_Mode); if ((a_Mode == 0) || (a_Mode == 2)) @@ -1221,7 +1214,7 @@ void cProtocol_1_8_0::SendScoreUpdate(const AString & a_Objective, const AString { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, 0x3c); + cPacketizer Pkt(*this, pktUpdateScore); Pkt.WriteString(a_Player); Pkt.WriteBEUInt8(a_Mode); Pkt.WriteString(a_Objective); @@ -1240,7 +1233,7 @@ void cProtocol_1_8_0::SendDisplayObjective(const AString & a_Objective, cScorebo { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, 0x3d); + cPacketizer Pkt(*this, pktDisplayObjective); Pkt.WriteBEUInt8(static_cast<UInt8>(a_Display)); Pkt.WriteString(a_Objective); } @@ -1262,9 +1255,8 @@ void cProtocol_1_8_0::SendSetRawSubTitle(const AString & a_SubTitle) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, 0x45); // Title packet + cPacketizer Pkt(*this, pktTitle); Pkt.WriteVarInt32(1); // Set subtitle - Pkt.WriteString(a_SubTitle); } @@ -1285,9 +1277,8 @@ void cProtocol_1_8_0::SendSetRawTitle(const AString & a_Title) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, 0x45); // Title packet + cPacketizer Pkt(*this, pktTitle); Pkt.WriteVarInt32(0); // Set title - Pkt.WriteString(a_Title); } @@ -1299,7 +1290,7 @@ void cProtocol_1_8_0::SendSoundEffect(const AString & a_SoundName, double a_X, d { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, 0x29); // Sound Effect packet + cPacketizer Pkt(*this, pktSoundEffect); Pkt.WriteString(a_SoundName); Pkt.WriteBEInt32(static_cast<Int32>(a_X * 8.0)); Pkt.WriteBEInt32(static_cast<Int32>(a_Y * 8.0)); @@ -1316,7 +1307,7 @@ void cProtocol_1_8_0::SendSoundParticleEffect(const EffectID a_EffectID, int a_S { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, 0x28); // Effect packet + cPacketizer Pkt(*this, pktSoundParticleEffect); Pkt.WriteBEInt32(static_cast<int>(a_EffectID)); Pkt.WritePosition64(a_SrcX, a_SrcY, a_SrcZ); Pkt.WriteBEInt32(a_Data); @@ -1331,7 +1322,7 @@ void cProtocol_1_8_0::SendSpawnFallingBlock(const cFallingBlock & a_FallingBlock { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, 0x0e); // Spawn Object packet + cPacketizer Pkt(*this, pktSpawnObject); Pkt.WriteVarInt32(a_FallingBlock.GetUniqueID()); Pkt.WriteBEUInt8(70); // Falling block Vector3d LastSentPos = a_FallingBlock.GetLastSentPos(); @@ -1354,7 +1345,7 @@ void cProtocol_1_8_0::SendSpawnMob(const cMonster & a_Mob) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, 0x0f); // Spawn Mob packet + cPacketizer Pkt(*this, pktSpawnMob); Pkt.WriteVarInt32(a_Mob.GetUniqueID()); Pkt.WriteBEUInt8(static_cast<Byte>(a_Mob.GetMobType())); Vector3d LastSentPos = a_Mob.GetLastSentPos(); @@ -1386,7 +1377,7 @@ void cProtocol_1_8_0::SendSpawnObject(const cEntity & a_Entity, char a_ObjectTyp FixItemFramePositions(a_ObjectData, PosX, PosZ, Yaw); } - cPacketizer Pkt(*this, 0xe); // Spawn Object packet + cPacketizer Pkt(*this, pktSpawnObject); Pkt.WriteVarInt32(a_Entity.GetUniqueID()); Pkt.WriteBEUInt8(static_cast<UInt8>(a_ObjectType)); Pkt.WriteFPInt(PosX); @@ -1411,7 +1402,7 @@ void cProtocol_1_8_0::SendSpawnVehicle(const cEntity & a_Vehicle, char a_Vehicle { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, 0xe); // Spawn Object packet + cPacketizer Pkt(*this, pktSpawnObject); Pkt.WriteVarInt32(a_Vehicle.GetUniqueID()); Pkt.WriteBEUInt8(static_cast<UInt8>(a_VehicleType)); Vector3d LastSentPos = a_Vehicle.GetLastSentPos(); @@ -1437,7 +1428,7 @@ void cProtocol_1_8_0::SendStatistics(const cStatManager & a_Manager) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, 0x37); + cPacketizer Pkt(*this, pktStatistics); Pkt.WriteVarInt32(statCount); // TODO 2014-05-11 xdot: Optimization: Send "dirty" statistics only size_t Count = static_cast<size_t>(statCount); @@ -1459,7 +1450,7 @@ void cProtocol_1_8_0::SendTabCompletionResults(const AStringVector & a_Results) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, 0x3a); // Tab-Complete packet + cPacketizer Pkt(*this, pktTabCompletionResults); Pkt.WriteVarInt32(static_cast<UInt32>(a_Results.size())); for (AStringVector::const_iterator itr = a_Results.begin(), end = a_Results.end(); itr != end; ++itr) @@ -1476,7 +1467,7 @@ void cProtocol_1_8_0::SendTeleportEntity(const cEntity & a_Entity) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, 0x18); + cPacketizer Pkt(*this, pktTeleportEntity); Pkt.WriteVarInt32(a_Entity.GetUniqueID()); Pkt.WriteFPInt(a_Entity.GetPosX()); Pkt.WriteFPInt(a_Entity.GetPosY()); @@ -1494,7 +1485,7 @@ void cProtocol_1_8_0::SendThunderbolt(int a_BlockX, int a_BlockY, int a_BlockZ) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, 0x2c); // Spawn Global Entity packet + cPacketizer Pkt(*this, pktSpawnGlobalEntity); Pkt.WriteVarInt32(0); // EntityID = 0, always Pkt.WriteBEUInt8(1); // Type = Thunderbolt Pkt.WriteFPInt(a_BlockX); @@ -1510,7 +1501,7 @@ void cProtocol_1_8_0::SendTitleTimes(int a_FadeInTicks, int a_DisplayTicks, int { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, 0x45); // Title packet + cPacketizer Pkt(*this, pktTitle); // Title packet Pkt.WriteVarInt32(2); // Set title display times Pkt.WriteBEInt32(a_FadeInTicks); @@ -1531,7 +1522,7 @@ void cProtocol_1_8_0::SendTimeUpdate(Int64 a_WorldAge, Int64 a_TimeOfDay, bool a a_TimeOfDay = std::min(-a_TimeOfDay, -1LL); } - cPacketizer Pkt(*this, 0x03); + cPacketizer Pkt(*this, pktTimeUpdate); Pkt.WriteBEInt64(a_WorldAge); Pkt.WriteBEInt64(a_TimeOfDay); } @@ -1544,7 +1535,7 @@ void cProtocol_1_8_0::SendUnloadChunk(int a_ChunkX, int a_ChunkZ) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, 0x21); // Chunk Data packet + cPacketizer Pkt(*this, pktUnloadChunk); Pkt.WriteBEInt32(a_ChunkX); Pkt.WriteBEInt32(a_ChunkZ); Pkt.WriteBool(true); @@ -1560,7 +1551,7 @@ void cProtocol_1_8_0::SendUpdateBlockEntity(cBlockEntity & a_BlockEntity) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, 0x35); // Update tile entity packet + cPacketizer Pkt(*this, pktUpdateBlockEntity); Pkt.WritePosition64(a_BlockEntity.GetPosX(), a_BlockEntity.GetPosY(), a_BlockEntity.GetPosZ()); Byte Action = 0; @@ -1587,7 +1578,7 @@ void cProtocol_1_8_0::SendUpdateSign(int a_BlockX, int a_BlockY, int a_BlockZ, c { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, 0x33); + cPacketizer Pkt(*this, pktUpdateSign); Pkt.WritePosition64(a_BlockX, a_BlockY, a_BlockZ); Json::StyledWriter JsonWriter; @@ -1608,7 +1599,7 @@ void cProtocol_1_8_0::SendUseBed(const cEntity & a_Entity, int a_BlockX, int a_B { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, 0x0a); + cPacketizer Pkt(*this, pktUseBed); Pkt.WriteVarInt32(a_Entity.GetUniqueID()); Pkt.WritePosition64(a_BlockX, a_BlockY, a_BlockZ); } @@ -1622,7 +1613,7 @@ void cProtocol_1_8_0::SendWeather(eWeather a_Weather) ASSERT(m_State == 3); // In game mode? { - cPacketizer Pkt(*this, 0x2b); // Change Game State packet + cPacketizer Pkt(*this, pktWeather); Pkt.WriteBEUInt8((a_Weather == wSunny) ? 1 : 2); // End rain / begin rain Pkt.WriteBEFloat(0); // Unused for weather } @@ -1638,7 +1629,7 @@ void cProtocol_1_8_0::SendWholeInventory(const cWindow & a_Window) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, 0x30); // Window Items packet + cPacketizer Pkt(*this, pktWindowItems); Pkt.WriteBEInt8(a_Window.GetWindowID()); Pkt.WriteBEInt16(static_cast<Int16>(a_Window.GetNumSlots())); cItems Slots; @@ -1657,7 +1648,7 @@ void cProtocol_1_8_0::SendWindowClose(const cWindow & a_Window) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, 0x2e); + cPacketizer Pkt(*this, pktWindowClose); Pkt.WriteBEInt8(a_Window.GetWindowID()); } @@ -1675,7 +1666,7 @@ void cProtocol_1_8_0::SendWindowOpen(const cWindow & a_Window) return; } - cPacketizer Pkt(*this, 0x2d); + cPacketizer Pkt(*this, pktWindowOpen); Pkt.WriteBEInt8(a_Window.GetWindowID()); Pkt.WriteString(a_Window.GetWindowTypeName()); Pkt.WriteString(Printf("{\"text\":\"%s\"}", a_Window.GetWindowTitle().c_str())); @@ -1711,7 +1702,7 @@ void cProtocol_1_8_0::SendWindowProperty(const cWindow & a_Window, short a_Prope { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, 0x31); // Window Property packet + cPacketizer Pkt(*this, pktWindowProperty); Pkt.WriteBEInt8(a_Window.GetWindowID()); Pkt.WriteBEInt16(a_Property); Pkt.WriteBEInt16(a_Value); @@ -2067,6 +2058,95 @@ void cProtocol_1_8_0::AddReceivedData(const char * a_Data, size_t a_Size) +UInt32 cProtocol_1_8_0::GetPacketID(ePacketType a_PacketType) +{ + switch (a_PacketType) + { + case pktAttachEntity: return 0x1b; + case pktBlockAction: return 0x24; + case pktBlockBreakAnim: return 0x25; + case pktBlockChange: return 0x23; + case pktBlockChanges: return 0x22; + case pktCameraSetTo: return 0x43; + case pktChatRaw: return 0x02; + case pktCollectEntity: return 0x0d; + case pktDestroyEntity: return 0x13; + case pktDifficulty: return 0x41; + case pktDisconnectDuringGame: return 0x40; + case pktDisconnectDuringLogin: return 0x00; + case pktDisplayObjective: return 0x3d; + case pktEditSign: return 0x36; + case pktEncryptionRequest: return 0x01; + case pktEntityAnimation: return 0x0b; + case pktEntityEffect: return 0x1d; + case pktEntityEquipment: return 0x04; + case pktEntityHeadLook: return 0x19; + case pktEntityLook: return 0x16; + case pktEntityMeta: return 0x1c; + case pktEntityProperties: return 0x20; + case pktEntityRelMove: return 0x15; + case pktEntityRelMoveLook: return 0x17; + case pktEntityStatus: return 0x1a; + case pktEntityVelocity: return 0x12; + case pktExperience: return 0x1f; + case pktExplosion: return 0x27; + case pktGameMode: return 0x2b; + case pktHeldItemChange: return 0x09; + case pktInventorySlot: return 0x2f; + case pktJoinGame: return 0x01; + case pktKeepAlive: return 0x00; + case pktLeashEntity: return 0x1b; + case pktLoginSuccess: return 0x02; + case pktMapData: return 0x34; + case pktParticleEffect: return 0x2a; + case pktPingResponse: return 0x01; + case pktPlayerAbilities: return 0x39; + case pktPlayerList: return 0x38; + case pktPlayerMoveLook: return 0x08; + case pktPluginMessage: return 0x3f; + case pktRemoveEntityEffect: return 0x1e; + case pktRespawn: return 0x07; + case pktScoreboardObjective: return 0x3b; + case pktSoundEffect: return 0x29; + case pktSoundParticleEffect: return 0x28; + case pktSpawnExperienceOrb: return 0x11; + case pktSpawnGlobalEntity: return 0x2c; + case pktSpawnMob: return 0x0f; + case pktSpawnObject: return 0x0e; + case pktSpawnOtherPlayer: return 0x0c; + case pktSpawnPainting: return 0x10; + case pktSpawnPosition: return 0x05; + case pktStartCompression: return 0x03; + case pktStatistics: return 0x37; + case pktStatusResponse: return 0x00; + case pktTabCompletionResults: return 0x3a; + case pktTeleportEntity: return 0x18; + case pktTimeUpdate: return 0x03; + case pktTitle: return 0x45; + case pktUnloadChunk: return 0x21; + case pktUpdateBlockEntity: return 0x35; + case pktUpdateHealth: return 0x06; + case pktUpdateScore: return 0x3c; + case pktUpdateSign: return 0x33; + case pktUseBed: return 0x0a; + case pktWeather: return 0x2b; + case pktWindowClose: return 0x2e; + case pktWindowItems: return 0x30; + case pktWindowOpen: return 0x2d; + case pktWindowProperty: return 0x31; + default: + { + LOG("Unhandled outgoing packet type: %s (0x%02x)", cPacketizer::PacketTypeToStr(a_PacketType), a_PacketType); + ASSERT(!"Unhandled outgoing packet type"); + return 0; + } + } +} + + + + + bool cProtocol_1_8_0::HandlePacket(cByteBuffer & a_ByteBuffer, UInt32 a_PacketType) { switch (m_State) @@ -2158,7 +2238,7 @@ void cProtocol_1_8_0::HandlePacketStatusPing(cByteBuffer & a_ByteBuffer) { HANDLE_READ(a_ByteBuffer, ReadBEInt64, Int64, Timestamp); - cPacketizer Pkt(*this, 0x01); // Ping packet + cPacketizer Pkt(*this, pktPingResponse); Pkt.WriteBEInt64(Timestamp); } @@ -2204,7 +2284,7 @@ void cProtocol_1_8_0::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) Json::FastWriter Writer; AString Response = Writer.write(ResponseValue); - cPacketizer Pkt(*this, 0x00); // Response packet + cPacketizer Pkt(*this, pktStatusResponse); Pkt.WriteString(Response); } @@ -2294,7 +2374,7 @@ void cProtocol_1_8_0::HandlePacketLoginStart(cByteBuffer & a_ByteBuffer) // If auth is required, then send the encryption request: if (Server->ShouldAuthenticate()) { - cPacketizer Pkt(*this, 0x01); + cPacketizer Pkt(*this, pktEncryptionRequest); Pkt.WriteString(Server->GetServerID()); const AString & PubKeyDer = Server->GetPublicKeyDER(); Pkt.WriteVarInt32(static_cast<UInt32>(PubKeyDer.size())); @@ -3081,8 +3161,8 @@ void cProtocol_1_8_0::SendPacket(cPacketizer & a_Pkt) AString Hex; ASSERT(PacketData.size() > 0); CreateHexDump(Hex, PacketData.data(), PacketData.size(), 16); - m_CommLogFile.Printf("Outgoing packet: type %d (0x%x), length %u (0x%x), state %d. Payload (incl. type):\n%s\n", - a_Pkt.GetPacketType(), a_Pkt.GetPacketType(), PacketLen, PacketLen, m_State, Hex.c_str() + m_CommLogFile.Printf("Outgoing packet: type %s (0x%02x), length %u (0x%04x), state %d. Payload (incl. type):\n%s\n", + cPacketizer::PacketTypeToStr(a_Pkt.GetPacketType()), a_Pkt.GetPacketType(), PacketLen, PacketLen, m_State, Hex ); } } diff --git a/src/Protocol/Protocol_1_8.h b/src/Protocol/Protocol_1_8.h index 64a1a9e00..e71c8fbe5 100644 --- a/src/Protocol/Protocol_1_8.h +++ b/src/Protocol/Protocol_1_8.h @@ -162,11 +162,7 @@ protected: void AddReceivedData(const char * a_Data, size_t a_Size); /** Nobody inherits 1.8, so it doesn't use this method */ - virtual UInt32 GetPacketId(eOutgoingPackets a_Packet) override - { - ASSERT(!"GetPacketId for cProtocol_1_8_0 is not implemented."); - return 0; - } + virtual UInt32 GetPacketID(ePacketType a_Packet) override; /** Reads and handles the packet. The packet length and type have already been read. Returns true if the packet was understood, false if it was an unknown packet diff --git a/src/Protocol/Protocol_1_9.cpp b/src/Protocol/Protocol_1_9.cpp index f9a018a5c..29d8b1c34 100644 --- a/src/Protocol/Protocol_1_9.cpp +++ b/src/Protocol/Protocol_1_9.cpp @@ -116,7 +116,7 @@ extern bool g_ShouldLogCommIn, g_ShouldLogCommOut; // cProtocol_1_9_0: cProtocol_1_9_0::cProtocol_1_9_0(cClientHandle * a_Client, const AString & a_ServerAddress, UInt16 a_ServerPort, UInt32 a_State) : - super(a_Client), + Super(a_Client), m_ServerAddress(a_ServerAddress), m_ServerPort(a_ServerPort), m_State(a_State), @@ -227,7 +227,7 @@ void cProtocol_1_9_0::DataReceived(const char * a_Data, size_t a_Size) void cProtocol_1_9_0::SendAttachEntity(const cEntity & a_Entity, const cEntity & a_Vehicle) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendAttachEntity)); // Set passangers packet + cPacketizer Pkt(*this, pktAttachEntity); Pkt.WriteVarInt32(a_Vehicle.GetUniqueID()); Pkt.WriteVarInt32(1); // 1 passenger Pkt.WriteVarInt32(a_Entity.GetUniqueID()); @@ -241,7 +241,7 @@ void cProtocol_1_9_0::SendBlockAction(int a_BlockX, int a_BlockY, int a_BlockZ, { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendBlockAction)); // Block Action packet + cPacketizer Pkt(*this, pktBlockAction); Pkt.WritePosition64(a_BlockX, a_BlockY, a_BlockZ); Pkt.WriteBEInt8(a_Byte1); Pkt.WriteBEInt8(a_Byte2); @@ -256,7 +256,7 @@ void cProtocol_1_9_0::SendBlockBreakAnim(UInt32 a_EntityID, int a_BlockX, int a_ { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendBlockBreakAnim)); // Block Break Animation packet + cPacketizer Pkt(*this, pktBlockBreakAnim); Pkt.WriteVarInt32(a_EntityID); Pkt.WritePosition64(a_BlockX, a_BlockY, a_BlockZ); Pkt.WriteBEInt8(a_Stage); @@ -270,7 +270,7 @@ void cProtocol_1_9_0::SendBlockChange(int a_BlockX, int a_BlockY, int a_BlockZ, { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendBlockChange)); // Block Change packet + cPacketizer Pkt(*this, pktBlockChange); Pkt.WritePosition64(a_BlockX, a_BlockY, a_BlockZ); Pkt.WriteVarInt32((static_cast<UInt32>(a_BlockType) << 4) | (static_cast<UInt32>(a_BlockMeta) & 15)); } @@ -283,7 +283,7 @@ void cProtocol_1_9_0::SendBlockChanges(int a_ChunkX, int a_ChunkZ, const sSetBlo { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendBlockChanges)); // Multi Block Change packet + cPacketizer Pkt(*this, pktBlockChanges); Pkt.WriteBEInt32(a_ChunkX); Pkt.WriteBEInt32(a_ChunkZ); Pkt.WriteVarInt32(static_cast<UInt32>(a_Changes.size())); @@ -301,7 +301,7 @@ void cProtocol_1_9_0::SendBlockChanges(int a_ChunkX, int a_ChunkZ, const sSetBlo void cProtocol_1_9_0::SendCameraSetTo(const cEntity & a_Entity) { - cPacketizer Pkt(*this, GetPacketId(sendCameraSetTo)); // Camera Packet (Attach the camera of a player at another entity in spectator mode) + cPacketizer Pkt(*this, pktCameraSetTo); Pkt.WriteVarInt32(a_Entity.GetUniqueID()); } @@ -336,7 +336,7 @@ void cProtocol_1_9_0::SendChatRaw(const AString & a_MessageRaw, eChatType a_Type ASSERT(m_State == 3); // In game mode? // Send the json string to the client: - cPacketizer Pkt(*this, GetPacketId(sendChatRaw)); // Chat Message packet + cPacketizer Pkt(*this, pktChatRaw); Pkt.WriteString(a_MessageRaw); Pkt.WriteBEInt8(a_Type); } @@ -366,7 +366,7 @@ void cProtocol_1_9_0::SendCollectEntity(const cEntity & a_Entity, const cPlayer UNUSED(a_Count); ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendCollectEntity)); // Collect Item packet + cPacketizer Pkt(*this, pktCollectEntity); Pkt.WriteVarInt32(a_Entity.GetUniqueID()); Pkt.WriteVarInt32(a_Player.GetUniqueID()); } @@ -379,7 +379,7 @@ void cProtocol_1_9_0::SendDestroyEntity(const cEntity & a_Entity) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendDestroyEntity)); // Destroy Entities packet + cPacketizer Pkt(*this, pktDestroyEntity); Pkt.WriteVarInt32(1); Pkt.WriteVarInt32(a_Entity.GetUniqueID()); } @@ -391,7 +391,7 @@ void cProtocol_1_9_0::SendDestroyEntity(const cEntity & a_Entity) void cProtocol_1_9_0::SendDetachEntity(const cEntity & a_Entity, const cEntity & a_PreviousVehicle) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendAttachEntity)); // Set passangers packet + cPacketizer Pkt(*this, pktAttachEntity); Pkt.WriteVarInt32(a_PreviousVehicle.GetUniqueID()); Pkt.WriteVarInt32(0); // No passangers } @@ -407,14 +407,14 @@ void cProtocol_1_9_0::SendDisconnect(const AString & a_Reason) case 2: { // During login: - cPacketizer Pkt(*this, GetPacketId(sendDisconnectDuringLogin)); + cPacketizer Pkt(*this, pktDisconnectDuringLogin); Pkt.WriteString(Printf("{\"text\":\"%s\"}", EscapeString(a_Reason).c_str())); break; } case 3: { // In-game: - cPacketizer Pkt(*this, GetPacketId(sendDisconnectDuringGame)); + cPacketizer Pkt(*this, pktDisconnectDuringGame); Pkt.WriteString(Printf("{\"text\":\"%s\"}", EscapeString(a_Reason).c_str())); break; } @@ -429,7 +429,7 @@ void cProtocol_1_9_0::SendEditSign(int a_BlockX, int a_BlockY, int a_BlockZ) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendEditSign)); // Sign Editor Open packet + cPacketizer Pkt(*this, pktEditSign); Pkt.WritePosition64(a_BlockX, a_BlockY, a_BlockZ); } @@ -441,7 +441,7 @@ void cProtocol_1_9_0::SendEntityEffect(const cEntity & a_Entity, int a_EffectID, { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendEntityEffect)); // Entity Effect packet + cPacketizer Pkt(*this, pktEntityEffect); Pkt.WriteVarInt32(a_Entity.GetUniqueID()); Pkt.WriteBEUInt8(static_cast<UInt8>(a_EffectID)); Pkt.WriteBEUInt8(static_cast<UInt8>(a_Amplifier)); @@ -457,7 +457,7 @@ void cProtocol_1_9_0::SendEntityEquipment(const cEntity & a_Entity, short a_Slot { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendEntityEquipment)); // Entity Equipment packet + cPacketizer Pkt(*this, pktEntityEquipment); Pkt.WriteVarInt32(a_Entity.GetUniqueID()); // Needs to be adjusted due to the insertion of offhand at slot 1 if (a_SlotNum > 0) @@ -476,7 +476,7 @@ void cProtocol_1_9_0::SendEntityHeadLook(const cEntity & a_Entity) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendEntityHeadLook)); // Entity Head Look packet + cPacketizer Pkt(*this, pktEntityHeadLook); Pkt.WriteVarInt32(a_Entity.GetUniqueID()); Pkt.WriteByteAngle(a_Entity.GetHeadYaw()); } @@ -489,7 +489,7 @@ void cProtocol_1_9_0::SendEntityLook(const cEntity & a_Entity) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendEntityLook)); // Entity Look packet + cPacketizer Pkt(*this, pktEntityLook); Pkt.WriteVarInt32(a_Entity.GetUniqueID()); Pkt.WriteByteAngle(a_Entity.GetYaw()); Pkt.WriteByteAngle(a_Entity.GetPitch()); @@ -504,7 +504,7 @@ void cProtocol_1_9_0::SendEntityMetadata(const cEntity & a_Entity) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendEntityMeta)); // Entity Metadata packet + cPacketizer Pkt(*this, pktEntityMeta); Pkt.WriteVarInt32(a_Entity.GetUniqueID()); WriteEntityMetadata(Pkt, a_Entity); Pkt.WriteBEUInt8(0xff); // The termination byte @@ -518,7 +518,7 @@ void cProtocol_1_9_0::SendEntityProperties(const cEntity & a_Entity) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendEntityProperties)); // Entity Properties packet + cPacketizer Pkt(*this, pktEntityProperties); Pkt.WriteVarInt32(a_Entity.GetUniqueID()); WriteEntityProperties(Pkt, a_Entity); } @@ -531,7 +531,7 @@ void cProtocol_1_9_0::SendEntityRelMove(const cEntity & a_Entity, char a_RelX, c { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendEntityRelMove)); // Entity Relative Move packet + cPacketizer Pkt(*this, pktEntityRelMove); Pkt.WriteVarInt32(a_Entity.GetUniqueID()); // TODO: 1.9 changed these from chars to shorts, meaning that there can be more percision and data. Other code needs to be updated for that. Pkt.WriteBEInt16(a_RelX * 128); @@ -548,7 +548,7 @@ void cProtocol_1_9_0::SendEntityRelMoveLook(const cEntity & a_Entity, char a_Rel { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendEntityRelMoveLook)); // Entity Look And Relative Move packet + cPacketizer Pkt(*this, pktEntityRelMoveLook); Pkt.WriteVarInt32(a_Entity.GetUniqueID()); // TODO: 1.9 changed these from chars to shorts, meaning that there can be more percision and data. Other code needs to be updated for that. Pkt.WriteBEInt16(a_RelX * 128); @@ -567,7 +567,7 @@ void cProtocol_1_9_0::SendEntityStatus(const cEntity & a_Entity, char a_Status) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendEntityStatus)); // Entity Status packet + cPacketizer Pkt(*this, pktEntityStatus); Pkt.WriteBEUInt32(a_Entity.GetUniqueID()); Pkt.WriteBEInt8(a_Status); } @@ -580,7 +580,7 @@ void cProtocol_1_9_0::SendEntityVelocity(const cEntity & a_Entity) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendEntityVelocity)); // Entity Velocity packet + cPacketizer Pkt(*this, pktEntityVelocity); Pkt.WriteVarInt32(a_Entity.GetUniqueID()); // 400 = 8000 / 20 ... Conversion from our speed in m / s to 8000 m / tick Pkt.WriteBEInt16(static_cast<Int16>(a_Entity.GetSpeedX() * 400)); @@ -596,7 +596,7 @@ void cProtocol_1_9_0::SendExplosion(double a_BlockX, double a_BlockY, double a_B { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendExplosion)); // Explosion packet + cPacketizer Pkt(*this, pktExplosion); Pkt.WriteBEFloat(static_cast<float>(a_BlockX)); Pkt.WriteBEFloat(static_cast<float>(a_BlockY)); Pkt.WriteBEFloat(static_cast<float>(a_BlockZ)); @@ -621,7 +621,7 @@ void cProtocol_1_9_0::SendGameMode(eGameMode a_GameMode) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendGameMode)); // Change Game State packet + cPacketizer Pkt(*this, pktGameMode); Pkt.WriteBEUInt8(3); // Reason: Change game mode Pkt.WriteBEFloat(static_cast<float>(a_GameMode)); // The protocol really represents the value with a float! } @@ -634,7 +634,7 @@ void cProtocol_1_9_0::SendHealth(void) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendHealth)); // Update Health packet + cPacketizer Pkt(*this, pktUpdateHealth); cPlayer * Player = m_Client->GetPlayer(); Pkt.WriteBEFloat(static_cast<float>(Player->GetHealth())); Pkt.WriteVarInt32(static_cast<UInt32>(Player->GetFoodLevel())); @@ -649,7 +649,7 @@ void cProtocol_1_9_0::SendHeldItemChange(int a_ItemIndex) { ASSERT((a_ItemIndex >= 0) && (a_ItemIndex <= 8)); // Valid check - cPacketizer Pkt(*this, GetPacketId(sendHeldItemChange)); // Held item change + cPacketizer Pkt(*this, pktHeldItemChange); cPlayer * Player = m_Client->GetPlayer(); Pkt.WriteBEInt8(static_cast<Int8>(Player->GetInventory().GetEquippedSlotNum())); } @@ -662,7 +662,7 @@ void cProtocol_1_9_0::SendHideTitle(void) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendTitle)); // Title packet + cPacketizer Pkt(*this, pktTitle); Pkt.WriteVarInt32(3); // Hide title } @@ -674,7 +674,7 @@ void cProtocol_1_9_0::SendInventorySlot(char a_WindowID, short a_SlotNum, const { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendInventorySlot)); // Set Slot packet + cPacketizer Pkt(*this, pktInventorySlot); Pkt.WriteBEInt8(a_WindowID); Pkt.WriteBEInt16(a_SlotNum); WriteItem(Pkt, a_Item); @@ -689,11 +689,11 @@ void cProtocol_1_9_0::SendKeepAlive(UInt32 a_PingID) // Drop the packet if the protocol is not in the Game state yet (caused a client crash): if (m_State != 3) { - LOGWARNING("Trying to send a KeepAlive packet to a player who's not yet fully logged in (%d). The protocol class prevented the packet.", m_State); + LOG("Trying to send a KeepAlive packet to a player who's not yet fully logged in (%d). The protocol class prevented the packet.", m_State); return; } - cPacketizer Pkt(*this, GetPacketId(sendKeepAlive)); // Keep Alive packet + cPacketizer Pkt(*this, pktKeepAlive); Pkt.WriteVarInt32(a_PingID); } @@ -704,7 +704,7 @@ void cProtocol_1_9_0::SendKeepAlive(UInt32 a_PingID) void cProtocol_1_9_0::SendLeashEntity(const cEntity & a_Entity, const cEntity & a_EntityLeashedTo) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendLeashEntity)); // Set Attach Entity packet + cPacketizer Pkt(*this, pktLeashEntity); Pkt.WriteBEUInt32(a_Entity.GetUniqueID()); Pkt.WriteBEUInt32(a_EntityLeashedTo.GetUniqueID()); } @@ -716,7 +716,7 @@ void cProtocol_1_9_0::SendLeashEntity(const cEntity & a_Entity, const cEntity & void cProtocol_1_9_0::SendUnleashEntity(const cEntity & a_Entity) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendLeashEntity)); // Set Attach Entity packet + cPacketizer Pkt(*this, pktLeashEntity); Pkt.WriteBEUInt32(a_Entity.GetUniqueID()); Pkt.WriteBEInt32(-1); // Unleash a_Entity } @@ -730,7 +730,7 @@ void cProtocol_1_9_0::SendLogin(const cPlayer & a_Player, const cWorld & a_World // Send the Join Game packet: { cServer * Server = cRoot::Get()->GetServer(); - cPacketizer Pkt(*this, GetPacketId(sendJoinGame)); // Join Game packet + cPacketizer Pkt(*this, pktJoinGame); Pkt.WriteBEUInt32(a_Player.GetUniqueID()); Pkt.WriteBEUInt8(static_cast<UInt8>(a_Player.GetEffectiveGameMode()) | (Server->IsHardcore() ? 0x08 : 0)); // Hardcore flag bit 4 Pkt.WriteBEInt8(static_cast<Int8>(a_World.GetDimension())); @@ -742,13 +742,13 @@ void cProtocol_1_9_0::SendLogin(const cPlayer & a_Player, const cWorld & a_World // Send the spawn position: { - cPacketizer Pkt(*this, GetPacketId(sendSpawnPosition)); // Spawn Position packet + cPacketizer Pkt(*this, pktSpawnPosition); Pkt.WritePosition64(FloorC(a_World.GetSpawnX()), FloorC(a_World.GetSpawnY()), FloorC(a_World.GetSpawnZ())); } // Send the server difficulty: { - cPacketizer Pkt(*this, GetPacketId(sendDifficulty)); // Server difficulty packet + cPacketizer Pkt(*this, pktDifficulty); Pkt.WriteBEInt8(1); } @@ -766,14 +766,14 @@ void cProtocol_1_9_0::SendLoginSuccess(void) // Enable compression: { - cPacketizer Pkt(*this, 0x03); // Set compression packet + cPacketizer Pkt(*this, pktStartCompression); Pkt.WriteVarInt32(256); } m_State = 3; // State = Game { - cPacketizer Pkt(*this, 0x02); // Login success packet + cPacketizer Pkt(*this, pktLoginSuccess); Pkt.WriteString(m_Client->GetUUID().ToLongString()); Pkt.WriteString(m_Client->GetUsername()); } @@ -790,7 +790,7 @@ void cProtocol_1_9_0::SendPaintingSpawn(const cPainting & a_Painting) double PosY = a_Painting.GetPosY(); double PosZ = a_Painting.GetPosZ(); - cPacketizer Pkt(*this, GetPacketId(sendPaintingSpawn)); // Spawn Painting packet + cPacketizer Pkt(*this, pktSpawnPainting); Pkt.WriteVarInt32(a_Painting.GetUniqueID()); // TODO: Bad way to write a UUID, and it's not a true UUID, but this is functional for now. Pkt.WriteBEUInt64(0); @@ -808,7 +808,7 @@ void cProtocol_1_9_0::SendMapData(const cMap & a_Map, int a_DataStartX, int a_Da { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendMapData)); // Map packet + cPacketizer Pkt(*this, pktMapData); Pkt.WriteVarInt32(a_Map.GetID()); Pkt.WriteBEUInt8(static_cast<UInt8>(a_Map.GetScale())); @@ -841,7 +841,7 @@ void cProtocol_1_9_0::SendPickupSpawn(const cPickup & a_Pickup) ASSERT(m_State == 3); // In game mode? { // TODO Use SendSpawnObject - cPacketizer Pkt(*this, GetPacketId(sendSpawnObject)); // Spawn Object packet + cPacketizer Pkt(*this, pktSpawnObject); Pkt.WriteVarInt32(a_Pickup.GetUniqueID()); // TODO: Bad way to write a UUID, and it's not a true UUID, but this is functional for now. Pkt.WriteBEUInt64(0); @@ -869,7 +869,7 @@ void cProtocol_1_9_0::SendPlayerAbilities(void) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendPlayerAbilities)); // Player Abilities packet + cPacketizer Pkt(*this, pktPlayerAbilities); Byte Flags = 0; cPlayer * Player = m_Client->GetPlayer(); if (Player->IsGameModeCreative()) @@ -898,7 +898,7 @@ void cProtocol_1_9_0::SendEntityAnimation(const cEntity & a_Entity, char a_Anima { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendEntityAnimation)); // Animation packet + cPacketizer Pkt(*this, pktEntityAnimation); Pkt.WriteVarInt32(a_Entity.GetUniqueID()); Pkt.WriteBEInt8(a_Animation); } @@ -912,7 +912,7 @@ void cProtocol_1_9_0::SendParticleEffect(const AString & a_ParticleName, float a ASSERT(m_State == 3); // In game mode? int ParticleID = GetParticleID(a_ParticleName); - cPacketizer Pkt(*this, GetPacketId(sendParticleEffect)); // Particle effect packet + cPacketizer Pkt(*this, pktParticleEffect); Pkt.WriteBEInt32(ParticleID); Pkt.WriteBool(false); Pkt.WriteBEFloat(a_SrcX); @@ -934,7 +934,7 @@ void cProtocol_1_9_0::SendParticleEffect(const AString & a_ParticleName, Vector3 ASSERT(m_State == 3); // In game mode? int ParticleID = GetParticleID(a_ParticleName); - cPacketizer Pkt(*this, GetPacketId(sendParticleEffect)); // Particle effect packet + cPacketizer Pkt(*this, pktParticleEffect); Pkt.WriteBEInt32(ParticleID); Pkt.WriteBool(false); Pkt.WriteBEFloat(a_Src.x); @@ -977,7 +977,7 @@ void cProtocol_1_9_0::SendPlayerListAddPlayer(const cPlayer & a_Player) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendPlayerList)); // Playerlist Item packet + cPacketizer Pkt(*this, pktPlayerList); Pkt.WriteVarInt32(0); Pkt.WriteVarInt32(1); Pkt.WriteUUID(a_Player.GetUUID()); @@ -1014,7 +1014,7 @@ void cProtocol_1_9_0::SendPlayerListRemovePlayer(const cPlayer & a_Player) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendPlayerList)); // Playerlist Item packet + cPacketizer Pkt(*this, pktPlayerList); Pkt.WriteVarInt32(4); Pkt.WriteVarInt32(1); Pkt.WriteUUID(a_Player.GetUUID()); @@ -1028,7 +1028,7 @@ void cProtocol_1_9_0::SendPlayerListUpdateGameMode(const cPlayer & a_Player) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendPlayerList)); // Playerlist Item packet + cPacketizer Pkt(*this, pktPlayerList); Pkt.WriteVarInt32(1); Pkt.WriteVarInt32(1); Pkt.WriteUUID(a_Player.GetUUID()); @@ -1046,7 +1046,7 @@ void cProtocol_1_9_0::SendPlayerListUpdatePing(const cPlayer & a_Player) auto ClientHandle = a_Player.GetClientHandlePtr(); if (ClientHandle != nullptr) { - cPacketizer Pkt(*this, GetPacketId(sendPlayerList)); // Playerlist Item packet + cPacketizer Pkt(*this, pktPlayerList); Pkt.WriteVarInt32(2); Pkt.WriteVarInt32(1); Pkt.WriteUUID(a_Player.GetUUID()); @@ -1062,7 +1062,7 @@ void cProtocol_1_9_0::SendPlayerListUpdateDisplayName(const cPlayer & a_Player, { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendPlayerList)); // Playerlist Item packet + cPacketizer Pkt(*this, pktPlayerList); Pkt.WriteVarInt32(3); Pkt.WriteVarInt32(1); Pkt.WriteUUID(a_Player.GetUUID()); @@ -1086,7 +1086,7 @@ void cProtocol_1_9_0::SendPlayerMaxSpeed(void) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendPlayerMaxSpeed)); // Entity Properties + cPacketizer Pkt(*this, pktPlayerMaxSpeed); cPlayer * Player = m_Client->GetPlayer(); Pkt.WriteVarInt32(Player->GetUniqueID()); Pkt.WriteBEInt32(1); // Count @@ -1115,7 +1115,7 @@ void cProtocol_1_9_0::SendPlayerMoveLook(void) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendPlayerMoveLook)); // Player Position And Look packet + cPacketizer Pkt(*this, pktPlayerMoveLook); cPlayer * Player = m_Client->GetPlayer(); Pkt.WriteBEDouble(Player->GetPosX()); Pkt.WriteBEDouble(Player->GetPosY()); @@ -1146,7 +1146,7 @@ void cProtocol_1_9_0::SendPlayerPosition(void) void cProtocol_1_9_0::SendPlayerSpawn(const cPlayer & a_Player) { // Called to spawn another player for the client - cPacketizer Pkt(*this, GetPacketId(sendPlayerSpawn)); // Spawn Player packet + cPacketizer Pkt(*this, pktSpawnOtherPlayer); Pkt.WriteVarInt32(a_Player.GetUniqueID()); Pkt.WriteUUID(a_Player.GetUUID()); Vector3d LastSentPos = a_Player.GetLastSentPos(); @@ -1167,7 +1167,7 @@ void cProtocol_1_9_0::SendPluginMessage(const AString & a_Channel, const AString { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendPluginMessage)); // Plugin message packet + cPacketizer Pkt(*this, pktPluginMessage); Pkt.WriteString(a_Channel); Pkt.WriteBuf(a_Message.data(), a_Message.size()); } @@ -1180,7 +1180,7 @@ void cProtocol_1_9_0::SendRemoveEntityEffect(const cEntity & a_Entity, int a_Eff { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendRemoveEntityEffect)); // Remove entity effect packet + cPacketizer Pkt(*this, pktRemoveEntityEffect); Pkt.WriteVarInt32(a_Entity.GetUniqueID()); Pkt.WriteBEUInt8(static_cast<UInt8>(a_EffectID)); } @@ -1193,7 +1193,7 @@ void cProtocol_1_9_0::SendResetTitle(void) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendTitle)); // Title packet + cPacketizer Pkt(*this, pktTitle); Pkt.WriteVarInt32(4); // Reset title } @@ -1203,7 +1203,7 @@ void cProtocol_1_9_0::SendResetTitle(void) void cProtocol_1_9_0::SendRespawn(eDimension a_Dimension) { - cPacketizer Pkt(*this, GetPacketId(sendRespawn)); // Respawn packet + cPacketizer Pkt(*this, pktRespawn); cPlayer * Player = m_Client->GetPlayer(); Pkt.WriteBEInt32(static_cast<Int32>(a_Dimension)); Pkt.WriteBEUInt8(2); // TODO: Difficulty (set to Normal) @@ -1219,7 +1219,7 @@ void cProtocol_1_9_0::SendExperience(void) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendExperience)); // Experience Packet + cPacketizer Pkt(*this, pktExperience); cPlayer * Player = m_Client->GetPlayer(); Pkt.WriteBEFloat(Player->GetXpPercentage()); Pkt.WriteVarInt32(static_cast<UInt32>(Player->GetXpLevel())); @@ -1234,7 +1234,7 @@ void cProtocol_1_9_0::SendExperienceOrb(const cExpOrb & a_ExpOrb) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendExperienceOrb)); // Spawn experience orb packet + cPacketizer Pkt(*this, pktSpawnExperienceOrb); Pkt.WriteVarInt32(a_ExpOrb.GetUniqueID()); Pkt.WriteBEDouble(a_ExpOrb.GetPosX()); Pkt.WriteBEDouble(a_ExpOrb.GetPosY()); @@ -1250,7 +1250,7 @@ void cProtocol_1_9_0::SendScoreboardObjective(const AString & a_Name, const AStr { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendScoreboardObjective)); // Scoreboard objective packet + cPacketizer Pkt(*this, pktScoreboardObjective); Pkt.WriteString(a_Name); Pkt.WriteBEUInt8(a_Mode); if ((a_Mode == 0) || (a_Mode == 2)) @@ -1268,7 +1268,7 @@ void cProtocol_1_9_0::SendScoreUpdate(const AString & a_Objective, const AString { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendScoreUpdate)); // Update score packet + cPacketizer Pkt(*this, pktUpdateScore); Pkt.WriteString(a_Player); Pkt.WriteBEUInt8(a_Mode); Pkt.WriteString(a_Objective); @@ -1287,7 +1287,7 @@ void cProtocol_1_9_0::SendDisplayObjective(const AString & a_Objective, cScorebo { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendDisplayObjective)); // Display scoreboard packet + cPacketizer Pkt(*this, pktDisplayObjective); Pkt.WriteBEUInt8(static_cast<UInt8>(a_Display)); Pkt.WriteString(a_Objective); } @@ -1309,9 +1309,8 @@ void cProtocol_1_9_0::SendSetRawSubTitle(const AString & a_SubTitle) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendTitle)); // Title packet + cPacketizer Pkt(*this, pktTitle); Pkt.WriteVarInt32(1); // Set subtitle - Pkt.WriteString(a_SubTitle); } @@ -1332,9 +1331,8 @@ void cProtocol_1_9_0::SendSetRawTitle(const AString & a_Title) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendTitle)); // Title packet + cPacketizer Pkt(*this, pktTitle); Pkt.WriteVarInt32(0); // Set title - Pkt.WriteString(a_Title); } @@ -1346,7 +1344,7 @@ void cProtocol_1_9_0::SendSoundEffect(const AString & a_SoundName, double a_X, d { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendSoundEffect)); // Named sound effect packet + cPacketizer Pkt(*this, pktSoundEffect); Pkt.WriteString(a_SoundName); Pkt.WriteVarInt32(0); // Master sound category (may want to be changed to a parameter later) Pkt.WriteBEInt32(static_cast<Int32>(a_X * 8.0)); @@ -1364,7 +1362,7 @@ void cProtocol_1_9_0::SendSoundParticleEffect(const EffectID a_EffectID, int a_S { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendSoundParticleEffect)); // Effect packet + cPacketizer Pkt(*this, pktSoundParticleEffect); Pkt.WriteBEInt32(static_cast<int>(a_EffectID)); Pkt.WritePosition64(a_SrcX, a_SrcY, a_SrcZ); Pkt.WriteBEInt32(a_Data); @@ -1379,7 +1377,7 @@ void cProtocol_1_9_0::SendSpawnFallingBlock(const cFallingBlock & a_FallingBlock { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendSpawnObject)); // Spawn Object packet + cPacketizer Pkt(*this, pktSpawnObject); Pkt.WriteVarInt32(a_FallingBlock.GetUniqueID()); // TODO: Bad way to write a UUID, and it's not a true UUID, but this is functional for now. Pkt.WriteBEUInt64(0); @@ -1405,7 +1403,7 @@ void cProtocol_1_9_0::SendSpawnMob(const cMonster & a_Mob) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendSpawnMob)); // Spawn Mob packet + cPacketizer Pkt(*this, pktSpawnMob); Pkt.WriteVarInt32(a_Mob.GetUniqueID()); // TODO: Bad way to write a UUID, and it's not a true UUID, but this is functional for now. Pkt.WriteBEUInt64(0); @@ -1440,7 +1438,7 @@ void cProtocol_1_9_0::SendSpawnObject(const cEntity & a_Entity, char a_ObjectTyp FixItemFramePositions(a_ObjectData, PosX, PosZ, Yaw); } - cPacketizer Pkt(*this, GetPacketId(sendSpawnObject)); // Spawn Object packet + cPacketizer Pkt(*this, pktSpawnObject); Pkt.WriteVarInt32(a_Entity.GetUniqueID()); // TODO: Bad way to write a UUID, and it's not a true UUID, but this is functional for now. Pkt.WriteBEUInt64(0); @@ -1465,7 +1463,7 @@ void cProtocol_1_9_0::SendSpawnVehicle(const cEntity & a_Vehicle, char a_Vehicle { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendSpawnObject)); // Spawn Object packet + cPacketizer Pkt(*this, pktSpawnObject); Pkt.WriteVarInt32(a_Vehicle.GetUniqueID()); // TODO: Bad way to write a UUID, and it's not a true UUID, but this is functional for now. Pkt.WriteBEUInt64(0); @@ -1491,7 +1489,7 @@ void cProtocol_1_9_0::SendStatistics(const cStatManager & a_Manager) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendStatistics)); // Statistics packet + cPacketizer Pkt(*this, pktStatistics); Pkt.WriteVarInt32(statCount); // TODO 2014-05-11 xdot: Optimization: Send "dirty" statistics only size_t Count = static_cast<size_t>(statCount); @@ -1513,7 +1511,7 @@ void cProtocol_1_9_0::SendTabCompletionResults(const AStringVector & a_Results) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendTabCompletion)); // Tab-Complete packet + cPacketizer Pkt(*this, pktTabCompletionResults); Pkt.WriteVarInt32(static_cast<UInt32>(a_Results.size())); for (AStringVector::const_iterator itr = a_Results.begin(), end = a_Results.end(); itr != end; ++itr) @@ -1530,7 +1528,7 @@ void cProtocol_1_9_0::SendTeleportEntity(const cEntity & a_Entity) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendTeleportEntity)); // Entity teleport packet + cPacketizer Pkt(*this, pktTeleportEntity); Pkt.WriteVarInt32(a_Entity.GetUniqueID()); Pkt.WriteBEDouble(a_Entity.GetPosX()); Pkt.WriteBEDouble(a_Entity.GetPosY()); @@ -1548,7 +1546,7 @@ void cProtocol_1_9_0::SendThunderbolt(int a_BlockX, int a_BlockY, int a_BlockZ) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendSpawnGlobalEntity)); // Spawn Global Entity packet + cPacketizer Pkt(*this, pktSpawnGlobalEntity); Pkt.WriteVarInt32(0); // EntityID = 0, always Pkt.WriteBEUInt8(1); // Type = Thunderbolt Pkt.WriteBEDouble(a_BlockX); @@ -1564,9 +1562,8 @@ void cProtocol_1_9_0::SendTitleTimes(int a_FadeInTicks, int a_DisplayTicks, int { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendTitle)); // Title packet + cPacketizer Pkt(*this, pktTitle); Pkt.WriteVarInt32(2); // Set title display times - Pkt.WriteBEInt32(a_FadeInTicks); Pkt.WriteBEInt32(a_DisplayTicks); Pkt.WriteBEInt32(a_FadeOutTicks); @@ -1585,7 +1582,7 @@ void cProtocol_1_9_0::SendTimeUpdate(Int64 a_WorldAge, Int64 a_TimeOfDay, bool a a_TimeOfDay = std::min(-a_TimeOfDay, -1LL); } - cPacketizer Pkt(*this, GetPacketId(sendTimeUpdate)); // Time update packet + cPacketizer Pkt(*this, pktTimeUpdate); Pkt.WriteBEInt64(a_WorldAge); Pkt.WriteBEInt64(a_TimeOfDay); } @@ -1598,7 +1595,7 @@ void cProtocol_1_9_0::SendUnloadChunk(int a_ChunkX, int a_ChunkZ) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendUnloadChunk)); // Unload chunk packet + cPacketizer Pkt(*this, pktUnloadChunk); Pkt.WriteBEInt32(a_ChunkX); Pkt.WriteBEInt32(a_ChunkZ); } @@ -1611,9 +1608,8 @@ void cProtocol_1_9_0::SendUpdateBlockEntity(cBlockEntity & a_BlockEntity) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendUpdateBlockEntity)); // Update tile entity packet + cPacketizer Pkt(*this, pktUpdateBlockEntity); Pkt.WritePosition64(a_BlockEntity.GetPosX(), a_BlockEntity.GetPosY(), a_BlockEntity.GetPosZ()); - Byte Action = 0; switch (a_BlockEntity.GetBlockType()) { @@ -1638,7 +1634,7 @@ void cProtocol_1_9_0::SendUpdateSign(int a_BlockX, int a_BlockY, int a_BlockZ, c { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendUpdateSign)); // Update sign packet + cPacketizer Pkt(*this, pktUpdateSign); Pkt.WritePosition64(a_BlockX, a_BlockY, a_BlockZ); Json::StyledWriter JsonWriter; @@ -1659,7 +1655,7 @@ void cProtocol_1_9_0::SendUseBed(const cEntity & a_Entity, int a_BlockX, int a_B { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendUseBed)); // Use bed + cPacketizer Pkt(*this, pktUseBed); Pkt.WriteVarInt32(a_Entity.GetUniqueID()); Pkt.WritePosition64(a_BlockX, a_BlockY, a_BlockZ); } @@ -1673,7 +1669,7 @@ void cProtocol_1_9_0::SendWeather(eWeather a_Weather) ASSERT(m_State == 3); // In game mode? { - cPacketizer Pkt(*this, GetPacketId(sendWeather)); // Change Game State packet + cPacketizer Pkt(*this, pktWeather); Pkt.WriteBEUInt8((a_Weather == wSunny) ? 1 : 2); // End rain / begin rain Pkt.WriteBEFloat(0); // Unused for weather } @@ -1689,7 +1685,7 @@ void cProtocol_1_9_0::SendWholeInventory(const cWindow & a_Window) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendWindowItems)); // Window Items packet + cPacketizer Pkt(*this, pktWindowItems); Pkt.WriteBEInt8(a_Window.GetWindowID()); Pkt.WriteBEInt16(static_cast<Int16>(a_Window.GetNumSlots())); cItems Slots; @@ -1708,7 +1704,7 @@ void cProtocol_1_9_0::SendWindowClose(const cWindow & a_Window) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendWindowClose)); // Close window packet + cPacketizer Pkt(*this, pktWindowClose); Pkt.WriteBEInt8(a_Window.GetWindowID()); } @@ -1726,7 +1722,7 @@ void cProtocol_1_9_0::SendWindowOpen(const cWindow & a_Window) return; } - cPacketizer Pkt(*this, GetPacketId(sendWindowOpen)); // Open window packet + cPacketizer Pkt(*this, pktWindowOpen); Pkt.WriteBEInt8(a_Window.GetWindowID()); Pkt.WriteString(a_Window.GetWindowTypeName()); Pkt.WriteString(Printf("{\"text\":\"%s\"}", a_Window.GetWindowTitle().c_str())); @@ -1762,7 +1758,7 @@ void cProtocol_1_9_0::SendWindowProperty(const cWindow & a_Window, short a_Prope { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, GetPacketId(sendWindowProperty)); // Window Property packet + cPacketizer Pkt(*this, pktWindowProperty); Pkt.WriteBEInt8(a_Window.GetWindowID()); Pkt.WriteBEInt16(a_Property); Pkt.WriteBEInt16(a_Value); @@ -2118,6 +2114,91 @@ void cProtocol_1_9_0::AddReceivedData(const char * a_Data, size_t a_Size) +UInt32 cProtocol_1_9_0::GetPacketID(cProtocol::ePacketType a_Packet) +{ + switch (a_Packet) + { + case pktAttachEntity: return 0x40; + case pktBlockAction: return 0x0a; + case pktBlockBreakAnim: return 0x08; + case pktBlockChange: return 0x0b; + case pktBlockChanges: return 0x10; + case pktCameraSetTo: return 0x36; + case pktChatRaw: return 0x0f; + case pktCollectEntity: return 0x49; + case pktDestroyEntity: return 0x30; + case pktDifficulty: return 0x0d; + case pktDisconnectDuringGame: return 0x1a; + case pktDisconnectDuringLogin: return 0x0; + case pktDisplayObjective: return 0x38; + case pktEditSign: return 0x2a; + case pktEncryptionRequest: return 0x01; + case pktEntityAnimation: return 0x06; + case pktEntityEffect: return 0x4c; + case pktEntityEquipment: return 0x3c; + case pktEntityHeadLook: return 0x34; + case pktEntityLook: return 0x27; + case pktEntityMeta: return 0x39; + case pktEntityProperties: return 0x4b; + case pktEntityRelMove: return 0x25; + case pktEntityRelMoveLook: return 0x26; + case pktEntityStatus: return 0x1b; + case pktEntityVelocity: return 0x3b; + case pktExperience: return 0x3d; + case pktExplosion: return 0x1c; + case pktGameMode: return 0x1e; + case pktHeldItemChange: return 0x37; + case pktInventorySlot: return 0x16; + case pktJoinGame: return 0x23; + case pktKeepAlive: return 0x1f; + case pktLeashEntity: return 0x3a; + case pktLoginSuccess: return 0x02; + case pktMapData: return 0x24; + case pktParticleEffect: return 0x22; + case pktPingResponse: return 0x01; + case pktPlayerAbilities: return 0x2b; + case pktPlayerList: return 0x2d; + case pktPlayerMaxSpeed: return 0x4b; + case pktPlayerMoveLook: return 0x2e; + case pktPluginMessage: return 0x18; + case pktRemoveEntityEffect: return 0x31; + case pktRespawn: return 0x33; + case pktScoreboardObjective: return 0x3f; + case pktSpawnExperienceOrb: return 0x01; + case pktSpawnGlobalEntity: return 0x02; + case pktSpawnObject: return 0x00; + case pktSpawnOtherPlayer: return 0x05; + case pktSpawnPainting: return 0x04; + case pktSpawnPosition: return 0x43; + case pktSoundEffect: return 0x19; + case pktSoundParticleEffect: return 0x21; + case pktSpawnMob: return 0x03; + case pktStartCompression: return 0x03; + case pktStatistics: return 0x07; + case pktStatusResponse: return 0x00; + case pktTabCompletionResults: return 0x0e; + case pktTeleportEntity: return 0x4a; + case pktTimeUpdate: return 0x44; + case pktTitle: return 0x45; + case pktUnloadChunk: return 0x1d; + case pktUpdateBlockEntity: return 0x09; + case pktUpdateHealth: return 0x3e; + case pktUpdateScore: return 0x42; + case pktUpdateSign: return 0x46; + case pktUseBed: return 0x2f; + case pktWeather: return 0x1e; + case pktWindowClose: return 0x12; + case pktWindowItems: return 0x14; + case pktWindowOpen: return 0x13; + case pktWindowProperty: return 0x15; + } + UNREACHABLE("Unsupported outgoing packet type"); +} + + + + + bool cProtocol_1_9_0::HandlePacket(cByteBuffer & a_ByteBuffer, UInt32 a_PacketType) { switch (m_State) @@ -2214,7 +2295,7 @@ void cProtocol_1_9_0::HandlePacketStatusPing(cByteBuffer & a_ByteBuffer) { HANDLE_READ(a_ByteBuffer, ReadBEInt64, Int64, Timestamp); - cPacketizer Pkt(*this, 0x01); // Ping packet + cPacketizer Pkt(*this, pktPingResponse); Pkt.WriteBEInt64(Timestamp); } @@ -2260,7 +2341,7 @@ void cProtocol_1_9_0::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) Json::FastWriter Writer; AString Response = Writer.write(ResponseValue); - cPacketizer Pkt(*this, 0x00); // Response packet + cPacketizer Pkt(*this, pktStatusResponse); Pkt.WriteString(Response); } @@ -2350,7 +2431,7 @@ void cProtocol_1_9_0::HandlePacketLoginStart(cByteBuffer & a_ByteBuffer) // If auth is required, then send the encryption request: if (Server->ShouldAuthenticate()) { - cPacketizer Pkt(*this, 0x01); + cPacketizer Pkt(*this, pktEncryptionRequest); Pkt.WriteString(Server->GetServerID()); const AString & PubKeyDer = Server->GetPublicKeyDER(); Pkt.WriteVarInt32(static_cast<UInt32>(PubKeyDer.size())); @@ -3364,8 +3445,8 @@ void cProtocol_1_9_0::SendPacket(cPacketizer & a_Pkt) AString Hex; ASSERT(PacketData.size() > 0); CreateHexDump(Hex, PacketData.data(), PacketData.size(), 16); - m_CommLogFile.Printf("Outgoing packet: type %d (0x%x), length %u (0x%x), state %d. Payload (incl. type):\n%s\n", - a_Pkt.GetPacketType(), a_Pkt.GetPacketType(), PacketLen, PacketLen, m_State, Hex.c_str() + m_CommLogFile.Printf("Outgoing packet: type %s (0x%02x), length %u (0x%04x), state %d. Payload (incl. type):\n%s\n", + cPacketizer::PacketTypeToStr(a_Pkt.GetPacketType()), a_Pkt.GetPacketType(), PacketLen, PacketLen, m_State, Hex ); } } @@ -4212,7 +4293,7 @@ void cProtocol_1_9_0::WriteEntityProperties(cPacketizer & a_Pkt, const cEntity & // cProtocol_1_9_1: cProtocol_1_9_1::cProtocol_1_9_1(cClientHandle * a_Client, const AString & a_ServerAddress, UInt16 a_ServerPort, UInt32 a_State) : - super(a_Client, a_ServerAddress, a_ServerPort, a_State) + Super(a_Client, a_ServerAddress, a_ServerPort, a_State) { } @@ -4225,7 +4306,7 @@ void cProtocol_1_9_1::SendLogin(const cPlayer & a_Player, const cWorld & a_World // Send the Join Game packet: { cServer * Server = cRoot::Get()->GetServer(); - cPacketizer Pkt(*this, GetPacketId(sendJoinGame)); // Join Game packet + cPacketizer Pkt(*this, pktJoinGame); Pkt.WriteBEUInt32(a_Player.GetUniqueID()); Pkt.WriteBEUInt8(static_cast<UInt8>(a_Player.GetEffectiveGameMode()) | (Server->IsHardcore() ? 0x08 : 0)); // Hardcore flag bit 4 Pkt.WriteBEInt32(static_cast<Int32>(a_World.GetDimension())); // This is the change from 1.9.0 (Int8 to Int32) @@ -4237,13 +4318,13 @@ void cProtocol_1_9_1::SendLogin(const cPlayer & a_Player, const cWorld & a_World // Send the spawn position: { - cPacketizer Pkt(*this, GetPacketId(sendSpawnPosition)); // Spawn Position packet + cPacketizer Pkt(*this, pktSpawnPosition); Pkt.WritePosition64(FloorC(a_World.GetSpawnX()), FloorC(a_World.GetSpawnY()), FloorC(a_World.GetSpawnZ())); } // Send the server difficulty: { - cPacketizer Pkt(*this, GetPacketId(sendDifficulty)); // Server difficulty packet + cPacketizer Pkt(*this, pktDifficulty); Pkt.WriteBEInt8(1); } @@ -4293,7 +4374,7 @@ void cProtocol_1_9_1::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) Json::FastWriter Writer; AString Response = Writer.write(ResponseValue); - cPacketizer Pkt(*this, 0x00); // Response packet + cPacketizer Pkt(*this, pktStatusResponse); Pkt.WriteString(Response); } @@ -4305,7 +4386,7 @@ void cProtocol_1_9_1::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) // cProtocol_1_9_2: cProtocol_1_9_2::cProtocol_1_9_2(cClientHandle * a_Client, const AString & a_ServerAddress, UInt16 a_ServerPort, UInt32 a_State) : - super(a_Client, a_ServerAddress, a_ServerPort, a_State) + Super(a_Client, a_ServerAddress, a_ServerPort, a_State) { } @@ -4351,7 +4432,7 @@ void cProtocol_1_9_2::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) Json::FastWriter Writer; AString Response = Writer.write(ResponseValue); - cPacketizer Pkt(*this, 0x00); // Response packet + cPacketizer Pkt(*this, pktStatusResponse); Pkt.WriteString(Response); } @@ -4363,7 +4444,7 @@ void cProtocol_1_9_2::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) // cProtocol_1_9_4: cProtocol_1_9_4::cProtocol_1_9_4(cClientHandle * a_Client, const AString & a_ServerAddress, UInt16 a_ServerPort, UInt32 a_State) : - super(a_Client, a_ServerAddress, a_ServerPort, a_State) + Super(a_Client, a_ServerAddress, a_ServerPort, a_State) { } @@ -4409,7 +4490,7 @@ void cProtocol_1_9_4::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) Json::FastWriter Writer; AString Response = Writer.write(ResponseValue); - cPacketizer Pkt(*this, 0x00); // Response packet + cPacketizer Pkt(*this, pktStatusResponse); Pkt.WriteString(Response); } @@ -4438,7 +4519,7 @@ void cProtocol_1_9_4::SendUpdateSign(int a_BlockX, int a_BlockY, int a_BlockZ, c ASSERT(m_State == 3); // In game mode? // 1.9.4 removed the update sign packet and now uses Update Block Entity - cPacketizer Pkt(*this, 0x09); // Update tile entity packet + cPacketizer Pkt(*this, pktUpdateBlockEntity); Pkt.WritePosition64(a_BlockX, a_BlockY, a_BlockZ); Pkt.WriteBEUInt8(9); // Action 9 - update sign @@ -4465,3 +4546,21 @@ void cProtocol_1_9_4::SendUpdateSign(int a_BlockX, int a_BlockY, int a_BlockZ, c Writer.Finish(); Pkt.WriteBuf(Writer.GetResult().data(), Writer.GetResult().size()); } + + + + + +UInt32 cProtocol_1_9_4::GetPacketID(cProtocol::ePacketType a_Packet) +{ + switch (a_Packet) + { + case pktCollectEntity: return 0x48; + case pktEntityEffect: return 0x4b; + case pktEntityProperties: return 0x4a; + case pktPlayerMaxSpeed: return 0x4a; + case pktTeleportEntity: return 0x49; + + default: return Super::GetPacketID(a_Packet); + } +} diff --git a/src/Protocol/Protocol_1_9.h b/src/Protocol/Protocol_1_9.h index d43c2bf09..99d65c77a 100644 --- a/src/Protocol/Protocol_1_9.h +++ b/src/Protocol/Protocol_1_9.h @@ -32,7 +32,7 @@ Declares the 1.9 protocol classes: class cProtocol_1_9_0 : public cProtocol { - typedef cProtocol super; + typedef cProtocol Super; public: @@ -172,7 +172,7 @@ protected: void AddReceivedData(const char * a_Data, size_t a_Size); /** Get the packet ID for a given packet */ - virtual UInt32 GetPacketId(eOutgoingPackets a_Packet) override; + virtual UInt32 GetPacketID(ePacketType a_Packet) override; /** Reads and handles the packet. The packet length and type have already been read. Returns true if the packet was understood, false if it was an unknown packet. */ @@ -289,7 +289,7 @@ protected: class cProtocol_1_9_1 : public cProtocol_1_9_0 { - typedef cProtocol_1_9_0 super; + typedef cProtocol_1_9_0 Super; public: cProtocol_1_9_1(cClientHandle * a_Client, const AString & a_ServerAddress, UInt16 a_ServerPort, UInt32 a_State); @@ -308,7 +308,7 @@ public: class cProtocol_1_9_2 : public cProtocol_1_9_1 { - typedef cProtocol_1_9_1 super; + typedef cProtocol_1_9_1 Super; public: cProtocol_1_9_2(cClientHandle * a_Client, const AString & a_ServerAddress, UInt16 a_ServerPort, UInt32 a_State); @@ -326,7 +326,7 @@ public: class cProtocol_1_9_4 : public cProtocol_1_9_2 { - typedef cProtocol_1_9_2 super; + typedef cProtocol_1_9_2 Super; public: cProtocol_1_9_4(cClientHandle * a_Client, const AString & a_ServerAddress, UInt16 a_ServerPort, UInt32 a_State); @@ -339,6 +339,6 @@ public: protected: - virtual UInt32 GetPacketId(eOutgoingPackets a_Packet) override; + virtual UInt32 GetPacketID(ePacketType a_Packet) override; } ; |