From 70a4ca5bc196676e8926028b2187fe7bd2874d42 Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Fri, 17 Aug 2012 10:18:07 +0000 Subject: Packets now parse themselves from a cByteBuffer object (1st part of packeting rewrite, http://forum.mc-server.org/showthread.php?tid=524 ) git-svn-id: http://mc-server.googlecode.com/svn/trunk@744 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/packets/cPacket.cpp | 154 --------------------- source/packets/cPacket.h | 41 ++---- source/packets/cPacket_13.cpp | 6 +- source/packets/cPacket_13.h | 2 +- source/packets/cPacket_ArmAnim.cpp | 6 +- source/packets/cPacket_ArmAnim.h | 2 +- source/packets/cPacket_BlockDig.cpp | 12 +- source/packets/cPacket_BlockDig.h | 2 +- source/packets/cPacket_BlockPlace.cpp | 12 +- source/packets/cPacket_BlockPlace.h | 2 +- source/packets/cPacket_Chat.cpp | 4 +- source/packets/cPacket_Chat.h | 2 +- source/packets/cPacket_CreativeInventoryAction.cpp | 6 +- source/packets/cPacket_CreativeInventoryAction.h | 2 +- source/packets/cPacket_Disconnect.cpp | 4 +- source/packets/cPacket_Disconnect.h | 2 +- source/packets/cPacket_EntityEquipment.cpp | 10 +- source/packets/cPacket_EntityEquipment.h | 2 +- source/packets/cPacket_Flying.cpp | 2 +- source/packets/cPacket_Flying.h | 2 +- source/packets/cPacket_Handshake.cpp | 4 +- source/packets/cPacket_Handshake.h | 2 +- source/packets/cPacket_ItemData.cpp | 10 +- source/packets/cPacket_ItemData.h | 2 +- source/packets/cPacket_ItemSwitch.cpp | 4 +- source/packets/cPacket_ItemSwitch.h | 2 +- source/packets/cPacket_KeepAlive.cpp | 4 +- source/packets/cPacket_KeepAlive.h | 2 +- source/packets/cPacket_Login.cpp | 18 +-- source/packets/cPacket_Login.h | 2 +- source/packets/cPacket_NewInvalidState.cpp | 6 +- source/packets/cPacket_NewInvalidState.h | 2 +- source/packets/cPacket_PickupSpawn.cpp | 22 +-- source/packets/cPacket_PickupSpawn.h | 2 +- source/packets/cPacket_Ping.h | 2 +- source/packets/cPacket_Player.cpp | 61 ++++---- source/packets/cPacket_Player.h | 10 +- source/packets/cPacket_Respawn.cpp | 12 +- source/packets/cPacket_Respawn.h | 2 +- source/packets/cPacket_TimeUpdate.cpp | 4 +- source/packets/cPacket_TimeUpdate.h | 2 +- source/packets/cPacket_UpdateSign.cpp | 16 +-- source/packets/cPacket_UpdateSign.h | 2 +- source/packets/cPacket_UseEntity.cpp | 8 +- source/packets/cPacket_UseEntity.h | 2 +- source/packets/cPacket_WindowClick.cpp | 15 +- source/packets/cPacket_WindowClick.h | 2 +- source/packets/cPacket_WindowClose.cpp | 4 +- source/packets/cPacket_WindowClose.h | 2 +- 49 files changed, 166 insertions(+), 335 deletions(-) (limited to 'source/packets') diff --git a/source/packets/cPacket.cpp b/source/packets/cPacket.cpp index 6fad331ed..8307e67fa 100644 --- a/source/packets/cPacket.cpp +++ b/source/packets/cPacket.cpp @@ -28,160 +28,6 @@ -int cPacket::ReadString16(const char * a_Data, int a_Size, AString & a_OutString ) -{ - int TotalBytes = 0; - short StrLen; - HANDLE_PACKET_READ(ReadShort, StrLen, TotalBytes); - - if (2 * StrLen > a_Size - TotalBytes) - { - // The string is not yet complete in the buffer - return PACKET_INCOMPLETE; - } - - // Simple UTF-16 to UTF-8 conversion - discard higher bits, ignore multishort sequences: - a_OutString.clear(); - a_OutString.reserve(StrLen); - short * UTF16 = (short *)(a_Data + TotalBytes); - for ( int i = 0; i < StrLen; ++i ) - { - a_OutString.push_back( (char)ntohs(UTF16[i]) ); - } - - return TotalBytes + StrLen * sizeof(short); -} - - - - - -int cPacket::ReadShort(const char * a_Data, int a_Size, short & a_OutShort ) -{ - if (a_Size < 2) - { - return PACKET_INCOMPLETE; - } - a_OutShort = ntohs(*((short *)a_Data)); - return 2; -} - - - - - -int cPacket::ReadInteger(const char * a_Data, int a_Size, int & a_OutInteger ) -{ - if (a_Size < 4) - { - return PACKET_INCOMPLETE; - } - a_OutInteger = ntohl(*((int *)a_Data)); - return 4; -} - - - - - -int cPacket::ReadInteger(const char * a_Data, int a_Size, unsigned int & a_OutInteger ) -{ - if (a_Size < 4) - { - return PACKET_INCOMPLETE; - } - a_OutInteger = ntohl(*((unsigned int *)a_Data)); - return 4; -} - - - - - -int cPacket::ReadFloat(const char * a_Data, int a_Size, float & a_OutFloat ) -{ - if (a_Size < sizeof(float)) - { - return PACKET_INCOMPLETE; - } - a_OutFloat = NetworkToHostFloat4(a_Data); - return sizeof(float); -} - - - - - -int cPacket::ReadDouble(const char * a_Data, int a_Size, double & a_OutDouble ) -{ - if (a_Size < sizeof(double)) - { - return PACKET_INCOMPLETE; - } - a_OutDouble = NetworkToHostDouble8(a_Data); - return sizeof(double); -} - - - - - -int cPacket::ReadByte(const char * a_Data, int a_Size, char & a_OutByte ) -{ - if (a_Size < 1) - { - return PACKET_INCOMPLETE; - } - a_OutByte = *a_Data; - return 1; -} - - - - - -int cPacket::ReadByte(const char * a_Data, int a_Size, unsigned char & a_OutByte ) -{ - if (a_Size < 1) - { - return PACKET_INCOMPLETE; - } - a_OutByte = *((unsigned char *)a_Data); - return 1; -} - - - - - -int cPacket::ReadLong(const char * a_Data, int a_Size, long long & a_OutLong ) -{ - if (a_Size < sizeof(a_OutLong)) - { - return PACKET_INCOMPLETE; - } - a_OutLong = NetworkToHostLong8(a_Data); - return sizeof(a_OutLong); -} - - - - - -int cPacket::ReadBool(const char * a_Data, int a_Size, bool & a_OutBool ) -{ - if (a_Size < sizeof(bool)) - { - return PACKET_INCOMPLETE; - } - a_OutBool = (*a_Data != 0); - return sizeof(bool); -} - - - - - void cPacket::AppendString(AString & a_Dst, const AString & a_String) { AppendShort(a_Dst, (unsigned short)a_String.size()); diff --git a/source/packets/cPacket.h b/source/packets/cPacket.h index 1c0b24868..1d6e8506f 100644 --- a/source/packets/cPacket.h +++ b/source/packets/cPacket.h @@ -3,6 +3,7 @@ #include "../cSocket.h" #include "../PacketID.h" +#include "../ByteBuffer.h" @@ -10,6 +11,7 @@ #define PACKET_INCOMPLETE -2 #define PACKET_ERROR -1 +#define PACKET_OK 1 @@ -18,12 +20,11 @@ // Use this macro to simplify handling several ReadXXX in a row. It assumes that you want [a_Data, a_Size] parsed (which is true for all Parse() functions) #define HANDLE_PACKET_READ(Proc, Var, TotalBytes) \ { \ - int res = Proc(a_Data + TotalBytes, a_Size - TotalBytes, Var); \ - if (res < 0) \ + if (!a_Buffer.Proc(Var)) \ { \ - return res; \ + return PACKET_INCOMPLETE; \ } \ - TotalBytes += res; \ + TotalBytes = PACKET_OK; \ } @@ -38,22 +39,23 @@ public: {} virtual ~cPacket() {} - /// Called to parse the packet. Packet type has already been read and the correct packet type created. Return the number of characters processed, PACKET_INCOMPLETE for incomplete data, PACKET_ERROR for error - virtual int Parse(const char * a_Data, int a_Size) + /// Called to parse the packet. Packet type has already been read and the correct packet type created. Return PACKET_INCOMPLETE for incomplete data, PACKET_ERROR for error, any positive number for success + virtual int Parse(cByteBuffer & a_Buffer) { - UNUSED(a_Data); - UNUSED(a_Size); - LOGERROR("Undefined Parse function for packet type 0x%x\n", m_PacketID ); - ASSERT(!"Undefined Parse function"); - return -1; + // There are packets that are sent S->C only, those don't have a parsing function + UNUSED(a_Buffer); + LOGERROR("Packet type 0x%02x has no parser defined!", m_PacketID); + ASSERT(!"Unparsed packet type!"); + return PACKET_ERROR; } /// Called to serialize the packet into a string. Append all packet data to a_Data, including the packet type! virtual void Serialize(AString & a_Data) const { + // There are packets that are sent C->S only, those don't have a serializing function UNUSED(a_Data); - LOGERROR("Undefined Serialize function for packet type 0x%x\n", m_PacketID ); - ASSERT(!"Undefined Serialize function"); + LOGERROR("Packet type 0x%02x has no serializer defined!", m_PacketID); + ASSERT(!"Unserialized packet"); } virtual cPacket * Clone() const = 0; @@ -61,19 +63,6 @@ public: unsigned char m_PacketID; protected: - - // These return the number of characters processed, PACKET_INCOMPLETE for incomplete data, PACKET_ERROR for error: - static int ReadString16(const char * a_Data, int a_Size, AString & a_OutString ); - static int ReadShort (const char * a_Data, int a_Size, short & a_Short ); - static int ReadInteger (const char * a_Data, int a_Size, int & a_OutInteger ); - static int ReadInteger (const char * a_Data, int a_Size, unsigned int & a_OutInteger ); - static int ReadFloat (const char * a_Data, int a_Size, float & a_OutFloat ); - static int ReadDouble (const char * a_Data, int a_Size, double & a_OutDouble ); - static int ReadByte (const char * a_Data, int a_Size, char & a_OutByte ); - static int ReadByte (const char * a_Data, int a_Size, unsigned char & a_OutByte ); - static int ReadLong (const char * a_Data, int a_Size, long long & a_OutLong ); - static int ReadBool (const char * a_Data, int a_Size, bool & a_OutBool ); - // These append the data into the a_Dst string: static void AppendString ( AString & a_Dst, const AString & a_String); static void AppendString16( AString & a_Dst, const AString & a_String); diff --git a/source/packets/cPacket_13.cpp b/source/packets/cPacket_13.cpp index 4edeb8c95..f31c67704 100644 --- a/source/packets/cPacket_13.cpp +++ b/source/packets/cPacket_13.cpp @@ -7,11 +7,11 @@ -int cPacket_13::Parse(const char * a_Data, int a_Size) +int cPacket_13::Parse(cByteBuffer & a_Buffer) { int TotalBytes = 0; - HANDLE_PACKET_READ(ReadInteger, m_EntityID, TotalBytes); - HANDLE_PACKET_READ(ReadByte , m_ActionID, TotalBytes); + HANDLE_PACKET_READ(ReadBEInt, m_EntityID, TotalBytes); + HANDLE_PACKET_READ(ReadChar, m_ActionID, TotalBytes); return TotalBytes; } diff --git a/source/packets/cPacket_13.h b/source/packets/cPacket_13.h index d0a257302..24caf5cc0 100644 --- a/source/packets/cPacket_13.h +++ b/source/packets/cPacket_13.h @@ -21,7 +21,7 @@ public: { m_PacketID = E_PACKET_13; } virtual cPacket* Clone() const { return new cPacket_13( *this ); } - virtual int Parse(const char * a_Data, int a_Size) override; + virtual int Parse(cByteBuffer & a_Buffer) override; int m_EntityID; char m_ActionID; diff --git a/source/packets/cPacket_ArmAnim.cpp b/source/packets/cPacket_ArmAnim.cpp index dcd416449..6f7a261d4 100644 --- a/source/packets/cPacket_ArmAnim.cpp +++ b/source/packets/cPacket_ArmAnim.cpp @@ -7,11 +7,11 @@ -int cPacket_ArmAnim::Parse(const char * a_Data, int a_Size) +int cPacket_ArmAnim::Parse(cByteBuffer & a_Buffer) { int TotalBytes = 0; - HANDLE_PACKET_READ(ReadInteger, m_EntityID, TotalBytes); - HANDLE_PACKET_READ(ReadByte , m_Animation, TotalBytes); + HANDLE_PACKET_READ(ReadBEInt, m_EntityID, TotalBytes); + HANDLE_PACKET_READ(ReadChar, m_Animation, TotalBytes); return TotalBytes; } diff --git a/source/packets/cPacket_ArmAnim.h b/source/packets/cPacket_ArmAnim.h index 79670de1c..2fa613b83 100644 --- a/source/packets/cPacket_ArmAnim.h +++ b/source/packets/cPacket_ArmAnim.h @@ -12,7 +12,7 @@ public: { m_PacketID = E_ANIMATION; } virtual cPacket* Clone() const { return new cPacket_ArmAnim(*this); } - virtual int Parse(const char * a_Data, int a_Size) override; + virtual int Parse(cByteBuffer & a_Buffer) override; virtual void Serialize(AString & a_Data) const override; int m_EntityID; diff --git a/source/packets/cPacket_BlockDig.cpp b/source/packets/cPacket_BlockDig.cpp index be2088cd0..0c90436dd 100644 --- a/source/packets/cPacket_BlockDig.cpp +++ b/source/packets/cPacket_BlockDig.cpp @@ -20,14 +20,14 @@ void cPacket_BlockDig::Serialize(AString & a_Data) const -int cPacket_BlockDig::Parse(const char * a_Data, int a_Size) +int cPacket_BlockDig::Parse(cByteBuffer & a_Buffer) { int TotalBytes = 0; - HANDLE_PACKET_READ(ReadByte, m_Status, TotalBytes); - HANDLE_PACKET_READ(ReadInteger, m_PosX, TotalBytes); - HANDLE_PACKET_READ(ReadByte, m_PosY, TotalBytes); - HANDLE_PACKET_READ(ReadInteger, m_PosZ, TotalBytes); - HANDLE_PACKET_READ(ReadByte, m_Direction, TotalBytes); + HANDLE_PACKET_READ(ReadChar, m_Status, TotalBytes); + HANDLE_PACKET_READ(ReadBEInt, m_PosX, TotalBytes); + HANDLE_PACKET_READ(ReadChar, m_PosY, TotalBytes); + HANDLE_PACKET_READ(ReadBEInt, m_PosZ, TotalBytes); + HANDLE_PACKET_READ(ReadChar, m_Direction, TotalBytes); return TotalBytes; } diff --git a/source/packets/cPacket_BlockDig.h b/source/packets/cPacket_BlockDig.h index 1fde63db6..e1bdc14f1 100644 --- a/source/packets/cPacket_BlockDig.h +++ b/source/packets/cPacket_BlockDig.h @@ -15,7 +15,7 @@ public: { m_PacketID = E_BLOCK_DIG; } //tolua_export virtual cPacket* Clone() const { return new cPacket_BlockDig(*this); } //tolua_export - virtual int Parse(const char * a_Data, int a_Size) override; + virtual int Parse(cByteBuffer & a_Buffer) override; virtual void Serialize(AString & a_Data) const override; char m_Status; // tolua_export diff --git a/source/packets/cPacket_BlockPlace.cpp b/source/packets/cPacket_BlockPlace.cpp index 2033bd91e..f767456a2 100644 --- a/source/packets/cPacket_BlockPlace.cpp +++ b/source/packets/cPacket_BlockPlace.cpp @@ -8,16 +8,16 @@ -int cPacket_BlockPlace::Parse(const char * a_Data, int a_Size) +int cPacket_BlockPlace::Parse(cByteBuffer & a_Buffer) { int TotalBytes = 0; - HANDLE_PACKET_READ(ReadInteger, m_PosX, TotalBytes); - HANDLE_PACKET_READ(ReadByte, m_PosY, TotalBytes); - HANDLE_PACKET_READ(ReadInteger, m_PosZ, TotalBytes); - HANDLE_PACKET_READ(ReadByte, m_Direction, TotalBytes); + HANDLE_PACKET_READ(ReadBEInt, m_PosX, TotalBytes); + HANDLE_PACKET_READ(ReadByte, m_PosY, TotalBytes); + HANDLE_PACKET_READ(ReadBEInt, m_PosZ, TotalBytes); + HANDLE_PACKET_READ(ReadChar, m_Direction, TotalBytes); cPacket_ItemData Item; - int res = Item.Parse(a_Data + TotalBytes, a_Size - TotalBytes); + int res = Item.Parse(a_Buffer); if (res < 0) { return res; diff --git a/source/packets/cPacket_BlockPlace.h b/source/packets/cPacket_BlockPlace.h index b8db56fd0..fa8aae585 100644 --- a/source/packets/cPacket_BlockPlace.h +++ b/source/packets/cPacket_BlockPlace.h @@ -21,7 +21,7 @@ public: { m_PacketID = E_BLOCK_PLACE; } virtual cPacket* Clone() const { return new cPacket_BlockPlace(*this); } - virtual int Parse(const char * a_Data, int a_Size) override; + virtual int Parse(cByteBuffer & a_Buffer) override; int m_PosX; //tolua_export unsigned char m_PosY; //tolua_export diff --git a/source/packets/cPacket_Chat.cpp b/source/packets/cPacket_Chat.cpp index 43b1af3fa..da00c0aae 100644 --- a/source/packets/cPacket_Chat.cpp +++ b/source/packets/cPacket_Chat.cpp @@ -7,10 +7,10 @@ -int cPacket_Chat::Parse(const char * a_Data, int a_Size) +int cPacket_Chat::Parse(cByteBuffer & a_Buffer) { int TotalBytes = 0; - HANDLE_PACKET_READ(ReadString16, m_Message, TotalBytes); + HANDLE_PACKET_READ(ReadBEUTF16String16, m_Message, TotalBytes); return TotalBytes; } diff --git a/source/packets/cPacket_Chat.h b/source/packets/cPacket_Chat.h index fac4a4097..cb154f732 100644 --- a/source/packets/cPacket_Chat.h +++ b/source/packets/cPacket_Chat.h @@ -10,7 +10,7 @@ public: cPacket_Chat( const std::string & a_Message ) : m_Message( a_Message) { m_PacketID = E_CHAT; } virtual cPacket* Clone() const { return new cPacket_Chat(*this); } - virtual int Parse(const char * a_Data, int a_Size) override; + virtual int Parse(cByteBuffer & a_Buffer) override; virtual void Serialize(AString & a_Data) const override; AString m_Message; diff --git a/source/packets/cPacket_CreativeInventoryAction.cpp b/source/packets/cPacket_CreativeInventoryAction.cpp index 46f125701..a71585df3 100644 --- a/source/packets/cPacket_CreativeInventoryAction.cpp +++ b/source/packets/cPacket_CreativeInventoryAction.cpp @@ -21,13 +21,13 @@ cPacket_CreativeInventoryAction::cPacket_CreativeInventoryAction( const cPacket_ -int cPacket_CreativeInventoryAction::Parse(const char * a_Data, int a_Size) +int cPacket_CreativeInventoryAction::Parse(cByteBuffer & a_Buffer) { int TotalBytes = 0; - HANDLE_PACKET_READ(ReadShort, m_Slot, TotalBytes); + HANDLE_PACKET_READ(ReadBEShort, m_Slot, TotalBytes); cPacket_ItemData Item; - int res = Item.Parse(a_Data + TotalBytes, a_Size - TotalBytes); + int res = Item.Parse(a_Buffer); if (res < 0) { return res; diff --git a/source/packets/cPacket_CreativeInventoryAction.h b/source/packets/cPacket_CreativeInventoryAction.h index 4fbed4e71..4d983e51d 100644 --- a/source/packets/cPacket_CreativeInventoryAction.h +++ b/source/packets/cPacket_CreativeInventoryAction.h @@ -21,7 +21,7 @@ public: cPacket_CreativeInventoryAction( const cPacket_CreativeInventoryAction & a_Copy ); virtual cPacket* Clone() const { return new cPacket_CreativeInventoryAction(*this); } - virtual int Parse(const char * a_Data, int a_Size) override; + virtual int Parse(cByteBuffer & a_Buffer) override; virtual void Serialize(AString & a_Data) const override; short m_Slot; // 0 = hold 1-4 = armor diff --git a/source/packets/cPacket_Disconnect.cpp b/source/packets/cPacket_Disconnect.cpp index 0ddad3744..19eecd365 100644 --- a/source/packets/cPacket_Disconnect.cpp +++ b/source/packets/cPacket_Disconnect.cpp @@ -7,10 +7,10 @@ -int cPacket_Disconnect::Parse(const char * a_Data, int a_Size) +int cPacket_Disconnect::Parse(cByteBuffer & a_Buffer) { int TotalBytes = 0; - HANDLE_PACKET_READ(ReadString16, m_Reason, TotalBytes); + HANDLE_PACKET_READ(ReadBEUTF16String16, m_Reason, TotalBytes); return TotalBytes; } diff --git a/source/packets/cPacket_Disconnect.h b/source/packets/cPacket_Disconnect.h index e91a09980..f2a820607 100644 --- a/source/packets/cPacket_Disconnect.h +++ b/source/packets/cPacket_Disconnect.h @@ -14,7 +14,7 @@ public: cPacket_Disconnect(const AString & a_Reason) { m_PacketID = E_DISCONNECT; m_Reason = a_Reason; } virtual cPacket* Clone() const { return new cPacket_Disconnect(*this); } - virtual int Parse(const char * a_Data, int a_Size) override; + virtual int Parse(cByteBuffer & a_Buffer) override; virtual void Serialize(AString & a_Data) const override; AString m_Reason; diff --git a/source/packets/cPacket_EntityEquipment.cpp b/source/packets/cPacket_EntityEquipment.cpp index 08bf30a6e..c66b1b6b4 100644 --- a/source/packets/cPacket_EntityEquipment.cpp +++ b/source/packets/cPacket_EntityEquipment.cpp @@ -20,13 +20,13 @@ cPacket_EntityEquipment::cPacket_EntityEquipment( const cPacket_EntityEquipment -int cPacket_EntityEquipment::Parse(const char * a_Data, int a_Size) +int cPacket_EntityEquipment::Parse(cByteBuffer & a_Buffer) { int TotalBytes = 0; - HANDLE_PACKET_READ(ReadInteger, m_UniqueID, TotalBytes); - HANDLE_PACKET_READ(ReadShort, m_Slot, TotalBytes); - HANDLE_PACKET_READ(ReadShort, m_ItemID, TotalBytes); - HANDLE_PACKET_READ(ReadShort, m_Short, TotalBytes); + HANDLE_PACKET_READ(ReadBEInt, m_UniqueID, TotalBytes); + HANDLE_PACKET_READ(ReadBEShort, m_Slot, TotalBytes); + HANDLE_PACKET_READ(ReadBEShort, m_ItemID, TotalBytes); + HANDLE_PACKET_READ(ReadBEShort, m_Short, TotalBytes); return TotalBytes; } diff --git a/source/packets/cPacket_EntityEquipment.h b/source/packets/cPacket_EntityEquipment.h index ec09bbf5c..3c6197f32 100644 --- a/source/packets/cPacket_EntityEquipment.h +++ b/source/packets/cPacket_EntityEquipment.h @@ -18,7 +18,7 @@ public: cPacket_EntityEquipment( const cPacket_EntityEquipment & a_Copy ); virtual cPacket* Clone() const { return new cPacket_EntityEquipment(*this); } - virtual int Parse(const char * a_Data, int a_Size) override; + virtual int Parse(cByteBuffer & a_Buffer) override; virtual void Serialize(AString & a_Data) const override; int m_UniqueID; diff --git a/source/packets/cPacket_Flying.cpp b/source/packets/cPacket_Flying.cpp index 64fbf11ea..bc730cb5e 100644 --- a/source/packets/cPacket_Flying.cpp +++ b/source/packets/cPacket_Flying.cpp @@ -7,7 +7,7 @@ -int cPacket_Flying::Parse(const char * a_Data, int a_Size) +int cPacket_Flying::Parse(cByteBuffer & a_Buffer) { int TotalBytes= 0; HANDLE_PACKET_READ(ReadBool, m_bFlying, TotalBytes); diff --git a/source/packets/cPacket_Flying.h b/source/packets/cPacket_Flying.h index 2d19820de..52f33e7fd 100644 --- a/source/packets/cPacket_Flying.h +++ b/source/packets/cPacket_Flying.h @@ -16,7 +16,7 @@ public: { m_PacketID = E_FLYING; } virtual cPacket* Clone() const { return new cPacket_Flying(*this); } - virtual int Parse(const char * a_Data, int a_Size) override; + virtual int Parse(cByteBuffer & a_Buffer) override; bool m_bFlying; static const unsigned int c_Size = 2; diff --git a/source/packets/cPacket_Handshake.cpp b/source/packets/cPacket_Handshake.cpp index 737eca330..76d04883c 100644 --- a/source/packets/cPacket_Handshake.cpp +++ b/source/packets/cPacket_Handshake.cpp @@ -7,10 +7,10 @@ -int cPacket_Handshake::Parse(const char * a_Data, int a_Size) +int cPacket_Handshake::Parse(cByteBuffer & a_Buffer) { int TotalBytes = 0; - HANDLE_PACKET_READ(ReadString16, m_Username, TotalBytes); + HANDLE_PACKET_READ(ReadBEUTF16String16, m_Username, TotalBytes); return TotalBytes; } diff --git a/source/packets/cPacket_Handshake.h b/source/packets/cPacket_Handshake.h index 020be9eaf..d1b06dacc 100644 --- a/source/packets/cPacket_Handshake.h +++ b/source/packets/cPacket_Handshake.h @@ -13,7 +13,7 @@ public: cPacket_Handshake() { m_PacketID = E_HANDSHAKE; } virtual cPacket* Clone() const { return new cPacket_Handshake(*this); } - virtual int Parse(const char * a_Data, int a_Size) override; + virtual int Parse(cByteBuffer & a_Buffer) override; virtual void Serialize(AString & a_Data) const override; std::string m_Username; diff --git a/source/packets/cPacket_ItemData.cpp b/source/packets/cPacket_ItemData.cpp index 0892f433a..2e4203bfc 100644 --- a/source/packets/cPacket_ItemData.cpp +++ b/source/packets/cPacket_ItemData.cpp @@ -7,10 +7,10 @@ -int cPacket_ItemData::Parse(const char * a_Data, int a_Size) +int cPacket_ItemData::Parse(cByteBuffer & a_Buffer) { int TotalBytes = 0; - HANDLE_PACKET_READ(ReadShort, m_ItemID, TotalBytes); + HANDLE_PACKET_READ(ReadBEShort, m_ItemID, TotalBytes); if (m_ItemID <= -1) { @@ -19,12 +19,12 @@ int cPacket_ItemData::Parse(const char * a_Data, int a_Size) return TotalBytes; } - HANDLE_PACKET_READ(ReadByte , m_ItemCount, TotalBytes); - HANDLE_PACKET_READ(ReadShort, m_ItemUses, TotalBytes); + HANDLE_PACKET_READ(ReadChar, m_ItemCount, TotalBytes); + HANDLE_PACKET_READ(ReadBEShort, m_ItemUses, TotalBytes); if (cItem::IsEnchantable((ENUM_ITEM_ID) m_ItemID)) { - HANDLE_PACKET_READ(ReadShort, m_EnchantNums, TotalBytes); + HANDLE_PACKET_READ(ReadBEShort, m_EnchantNums, TotalBytes); if ( m_EnchantNums > -1 ) { diff --git a/source/packets/cPacket_ItemData.h b/source/packets/cPacket_ItemData.h index 47878969f..5a1554b19 100644 --- a/source/packets/cPacket_ItemData.h +++ b/source/packets/cPacket_ItemData.h @@ -17,7 +17,7 @@ public: virtual cPacket* Clone() const { return new cPacket_ItemData(*this); } - virtual int Parse(const char * a_Data, int a_Size) override; + virtual int Parse(cByteBuffer & a_Buffer) override; static void AppendItem(AString & a_Data, short a_ItemID, char a_Quantity, short a_Damage); static void AppendItem(AString & a_Data, const cItem * a_Item); diff --git a/source/packets/cPacket_ItemSwitch.cpp b/source/packets/cPacket_ItemSwitch.cpp index bd4532938..3ea9d26c2 100644 --- a/source/packets/cPacket_ItemSwitch.cpp +++ b/source/packets/cPacket_ItemSwitch.cpp @@ -7,10 +7,10 @@ -int cPacket_ItemSwitch::Parse(const char * a_Data, int a_Size) +int cPacket_ItemSwitch::Parse(cByteBuffer & a_Buffer) { int TotalBytes = 0; - HANDLE_PACKET_READ(ReadShort, m_SlotNum, TotalBytes); + HANDLE_PACKET_READ(ReadBEShort, m_SlotNum, TotalBytes); return TotalBytes; } diff --git a/source/packets/cPacket_ItemSwitch.h b/source/packets/cPacket_ItemSwitch.h index fb6860624..1b0323ea6 100644 --- a/source/packets/cPacket_ItemSwitch.h +++ b/source/packets/cPacket_ItemSwitch.h @@ -15,7 +15,7 @@ public: { m_PacketID = E_ITEM_SWITCH; } virtual cPacket* Clone() const { return new cPacket_ItemSwitch(*this); } - virtual int Parse(const char * a_Data, int a_Size) override; + virtual int Parse(cByteBuffer & a_Buffer) override; virtual void Serialize(AString & a_Data) const override; short m_SlotNum; diff --git a/source/packets/cPacket_KeepAlive.cpp b/source/packets/cPacket_KeepAlive.cpp index cfc6b99b3..0dc9302b3 100644 --- a/source/packets/cPacket_KeepAlive.cpp +++ b/source/packets/cPacket_KeepAlive.cpp @@ -17,10 +17,10 @@ void cPacket_KeepAlive::Serialize(AString & a_Data) const -int cPacket_KeepAlive::Parse(const char * a_Data, int a_Size) +int cPacket_KeepAlive::Parse(cByteBuffer & a_Buffer) { int TotalBytes = 0; - HANDLE_PACKET_READ(ReadInteger, m_KeepAliveID, TotalBytes); + HANDLE_PACKET_READ(ReadBEInt, m_KeepAliveID, TotalBytes); return TotalBytes; } diff --git a/source/packets/cPacket_KeepAlive.h b/source/packets/cPacket_KeepAlive.h index e94ec72a6..0eeb5e095 100644 --- a/source/packets/cPacket_KeepAlive.h +++ b/source/packets/cPacket_KeepAlive.h @@ -14,7 +14,7 @@ public: cPacket_KeepAlive(int a_PingID) { m_KeepAliveID = a_PingID; } virtual cPacket* Clone() const { return new cPacket_KeepAlive(*this); } - virtual int Parse(const char * a_Data, int a_Size) override; + virtual int Parse(cByteBuffer & a_Buffer) override; virtual void Serialize(AString & a_Data) const override; int m_KeepAliveID; diff --git a/source/packets/cPacket_Login.cpp b/source/packets/cPacket_Login.cpp index 2a8ae7135..90da4c009 100644 --- a/source/packets/cPacket_Login.cpp +++ b/source/packets/cPacket_Login.cpp @@ -14,19 +14,19 @@ const std::string cPacket_Login::LEVEL_TYPE_SUPERFLAT = "SUPERFLAT"; -int cPacket_Login::Parse(const char * a_Data, int a_Size) +int cPacket_Login::Parse(cByteBuffer & a_Buffer) { //printf("Parse: NEW Login\n"); int TotalBytes = 0; m_Username.clear(); - HANDLE_PACKET_READ(ReadInteger, m_ProtocolVersion, TotalBytes); - HANDLE_PACKET_READ(ReadString16, m_Username, TotalBytes); - HANDLE_PACKET_READ(ReadString16, m_LevelType, TotalBytes); - HANDLE_PACKET_READ(ReadInteger, m_ServerMode, TotalBytes); - HANDLE_PACKET_READ(ReadInteger, m_Dimension, TotalBytes); - HANDLE_PACKET_READ(ReadByte, m_Difficulty, TotalBytes); - HANDLE_PACKET_READ(ReadByte, m_WorldHeight, TotalBytes); - HANDLE_PACKET_READ(ReadByte, m_MaxPlayers, TotalBytes); + HANDLE_PACKET_READ(ReadBEInt, m_ProtocolVersion, TotalBytes); + HANDLE_PACKET_READ(ReadBEUTF16String16, m_Username, TotalBytes); + HANDLE_PACKET_READ(ReadBEUTF16String16, m_LevelType, TotalBytes); + HANDLE_PACKET_READ(ReadBEInt, m_ServerMode, TotalBytes); + HANDLE_PACKET_READ(ReadBEInt, m_Dimension, TotalBytes); + HANDLE_PACKET_READ(ReadChar, m_Difficulty, TotalBytes); + HANDLE_PACKET_READ(ReadByte, m_WorldHeight, TotalBytes); + HANDLE_PACKET_READ(ReadByte, m_MaxPlayers, TotalBytes); return TotalBytes; } diff --git a/source/packets/cPacket_Login.h b/source/packets/cPacket_Login.h index b9769fdec..f512b098a 100644 --- a/source/packets/cPacket_Login.h +++ b/source/packets/cPacket_Login.h @@ -21,7 +21,7 @@ public: { m_PacketID = E_LOGIN; } virtual cPacket* Clone() const { return new cPacket_Login(*this); } - virtual int Parse(const char * a_Data, int a_Size) override; + virtual int Parse(cByteBuffer & a_Buffer) override; virtual void Serialize(AString & a_Data) const override; int m_ProtocolVersion; //tolua_export diff --git a/source/packets/cPacket_NewInvalidState.cpp b/source/packets/cPacket_NewInvalidState.cpp index a243a0e51..3e44a4877 100644 --- a/source/packets/cPacket_NewInvalidState.cpp +++ b/source/packets/cPacket_NewInvalidState.cpp @@ -18,11 +18,11 @@ cPacket_NewInvalidState::cPacket_NewInvalidState( const cPacket_NewInvalidState -int cPacket_NewInvalidState::Parse(const char * a_Data, int a_Size) +int cPacket_NewInvalidState::Parse(cByteBuffer & a_Buffer) { int TotalBytes = 0; - HANDLE_PACKET_READ(ReadByte, m_Reason, TotalBytes); - HANDLE_PACKET_READ(ReadByte, m_GameMode, TotalBytes); + HANDLE_PACKET_READ(ReadChar, m_Reason, TotalBytes); + HANDLE_PACKET_READ(ReadChar, m_GameMode, TotalBytes); return TotalBytes; } diff --git a/source/packets/cPacket_NewInvalidState.h b/source/packets/cPacket_NewInvalidState.h index 2c7565e63..6bfacd17c 100644 --- a/source/packets/cPacket_NewInvalidState.h +++ b/source/packets/cPacket_NewInvalidState.h @@ -17,7 +17,7 @@ public: cPacket_NewInvalidState( const cPacket_NewInvalidState & a_Copy ); virtual cPacket* Clone() const { return new cPacket_NewInvalidState(*this); } - virtual int Parse(const char * a_Data, int a_Size) override; + virtual int Parse(cByteBuffer & a_Buffer) override; virtual void Serialize(AString & a_Data) const override; char m_Reason; // 0 = Invalid Bed, 1 = Begin Raining, 2 End Raining, 3 = Change Gamemode diff --git a/source/packets/cPacket_PickupSpawn.cpp b/source/packets/cPacket_PickupSpawn.cpp index a1a60947d..0a858ba76 100644 --- a/source/packets/cPacket_PickupSpawn.cpp +++ b/source/packets/cPacket_PickupSpawn.cpp @@ -7,19 +7,19 @@ -int cPacket_PickupSpawn::Parse(const char * a_Data, int a_Size) +int cPacket_PickupSpawn::Parse(cByteBuffer & a_Buffer) { int TotalBytes = 0; - HANDLE_PACKET_READ(ReadInteger, m_UniqueID, TotalBytes); - HANDLE_PACKET_READ(ReadShort, m_Item, TotalBytes); - HANDLE_PACKET_READ(ReadByte, m_Count, TotalBytes); - HANDLE_PACKET_READ(ReadShort, m_Health, TotalBytes); - HANDLE_PACKET_READ(ReadInteger, m_PosX, TotalBytes); - HANDLE_PACKET_READ(ReadInteger, m_PosY, TotalBytes); - HANDLE_PACKET_READ(ReadInteger, m_PosZ, TotalBytes); - HANDLE_PACKET_READ(ReadByte, m_Rotation, TotalBytes); - HANDLE_PACKET_READ(ReadByte, m_Pitch, TotalBytes); - HANDLE_PACKET_READ(ReadByte, m_Roll, TotalBytes); + HANDLE_PACKET_READ(ReadBEInt, m_UniqueID, TotalBytes); + HANDLE_PACKET_READ(ReadBEShort, m_Item, TotalBytes); + HANDLE_PACKET_READ(ReadChar, m_Count, TotalBytes); + HANDLE_PACKET_READ(ReadBEShort, m_Health, TotalBytes); + HANDLE_PACKET_READ(ReadBEInt, m_PosX, TotalBytes); + HANDLE_PACKET_READ(ReadBEInt, m_PosY, TotalBytes); + HANDLE_PACKET_READ(ReadBEInt, m_PosZ, TotalBytes); + HANDLE_PACKET_READ(ReadChar, m_Rotation, TotalBytes); + HANDLE_PACKET_READ(ReadChar, m_Pitch, TotalBytes); + HANDLE_PACKET_READ(ReadChar, m_Roll, TotalBytes); return TotalBytes; } diff --git a/source/packets/cPacket_PickupSpawn.h b/source/packets/cPacket_PickupSpawn.h index 1c1a6c640..ea004b730 100644 --- a/source/packets/cPacket_PickupSpawn.h +++ b/source/packets/cPacket_PickupSpawn.h @@ -24,7 +24,7 @@ public: { m_PacketID = E_PICKUP_SPAWN; } virtual cPacket* Clone() const { return new cPacket_PickupSpawn(*this); } - virtual int Parse(const char * a_Data, int a_Size) override; + virtual int Parse(cByteBuffer & a_Buffer) override; virtual void Serialize(AString & a_Data) const override; int m_UniqueID; diff --git a/source/packets/cPacket_Ping.h b/source/packets/cPacket_Ping.h index 0a856c7ec..f74385a81 100644 --- a/source/packets/cPacket_Ping.h +++ b/source/packets/cPacket_Ping.h @@ -14,7 +14,7 @@ public: { m_PacketID = E_PING; } virtual cPacket* Clone() const { return new cPacket_Ping(*this); } - virtual int Parse(const char * a_Data, int a_Size) override {return 0; } + virtual int Parse(cByteBuffer & a_Buffer) override {return 0; } static const unsigned int c_Size = 1; }; diff --git a/source/packets/cPacket_Player.cpp b/source/packets/cPacket_Player.cpp index 7d9a5de6b..a71cdee33 100644 --- a/source/packets/cPacket_Player.cpp +++ b/source/packets/cPacket_Player.cpp @@ -22,17 +22,14 @@ /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cPacket_PlayerAbilities: -int cPacket_PlayerAbilities::Parse(const char * a_Data, int a_Size) +int cPacket_PlayerAbilities::Parse(cByteBuffer & a_Buffer) { - if (a_Size < 4) - { - return PACKET_INCOMPLETE; - } - m_Invulnerable = (a_Data[0] != 0); - m_IsFlying = (a_Data[1] != 0); - m_CanFly = (a_Data[2] != 0); - m_InstaMine = (a_Data[3] != 0); - return 4; + int TotalBytes = 0; + HANDLE_PACKET_READ(ReadBool, m_Invulnerable, TotalBytes); + HANDLE_PACKET_READ(ReadBool, m_IsFlying, TotalBytes); + HANDLE_PACKET_READ(ReadBool, m_CanFly, TotalBytes); + HANDLE_PACKET_READ(ReadBool, m_InstaMine, TotalBytes); + return TotalBytes; } @@ -69,12 +66,12 @@ cPacket_PlayerListItem::cPacket_PlayerListItem(const AString & a_PlayerName, boo -int cPacket_PlayerListItem::Parse(const char * a_Data, int a_Size) +int cPacket_PlayerListItem::Parse(cByteBuffer & a_Buffer) { int TotalBytes = 0; - HANDLE_PACKET_READ(ReadString16, m_PlayerName, TotalBytes); - HANDLE_PACKET_READ(ReadBool, m_Online, TotalBytes); - HANDLE_PACKET_READ(ReadShort, m_Ping, TotalBytes); + HANDLE_PACKET_READ(ReadBEUTF16String16, m_PlayerName, TotalBytes); + HANDLE_PACKET_READ(ReadBool, m_Online, TotalBytes); + HANDLE_PACKET_READ(ReadBEShort, m_Ping, TotalBytes); return TotalBytes; } @@ -119,12 +116,12 @@ cPacket_PlayerLook::cPacket_PlayerLook( cPlayer* a_Player ) -int cPacket_PlayerLook::Parse(const char * a_Data, int a_Size) +int cPacket_PlayerLook::Parse(cByteBuffer & a_Buffer) { int TotalBytes = 0; - HANDLE_PACKET_READ(ReadFloat, m_Rotation, TotalBytes); - HANDLE_PACKET_READ(ReadFloat, m_Pitch, TotalBytes); - HANDLE_PACKET_READ(ReadBool, m_bFlying, TotalBytes); + HANDLE_PACKET_READ(ReadBEFloat, m_Rotation, TotalBytes); + HANDLE_PACKET_READ(ReadBEFloat, m_Pitch, TotalBytes); + HANDLE_PACKET_READ(ReadBool, m_bFlying, TotalBytes); return TotalBytes; } @@ -162,16 +159,16 @@ cPacket_PlayerMoveLook::cPacket_PlayerMoveLook( cPlayer* a_Player ) -int cPacket_PlayerMoveLook::Parse(const char * a_Data, int a_Size) +int cPacket_PlayerMoveLook::Parse(cByteBuffer & a_Buffer) { int TotalBytes = 0; - HANDLE_PACKET_READ(ReadDouble, m_PosX, TotalBytes); - HANDLE_PACKET_READ(ReadDouble, m_PosY, TotalBytes); - HANDLE_PACKET_READ(ReadDouble, m_Stance, TotalBytes); - HANDLE_PACKET_READ(ReadDouble, m_PosZ, TotalBytes); - HANDLE_PACKET_READ(ReadFloat, m_Rotation, TotalBytes); - HANDLE_PACKET_READ(ReadFloat, m_Pitch, TotalBytes); - HANDLE_PACKET_READ(ReadBool, m_bFlying, TotalBytes); + HANDLE_PACKET_READ(ReadBEDouble, m_PosX, TotalBytes); + HANDLE_PACKET_READ(ReadBEDouble, m_PosY, TotalBytes); + HANDLE_PACKET_READ(ReadBEDouble, m_Stance, TotalBytes); + HANDLE_PACKET_READ(ReadBEDouble, m_PosZ, TotalBytes); + HANDLE_PACKET_READ(ReadBEFloat, m_Rotation, TotalBytes); + HANDLE_PACKET_READ(ReadBEFloat, m_Pitch, TotalBytes); + HANDLE_PACKET_READ(ReadBool, m_bFlying, TotalBytes); return TotalBytes; } @@ -213,14 +210,14 @@ cPacket_PlayerPosition::cPacket_PlayerPosition( cPlayer* a_Player ) -int cPacket_PlayerPosition::Parse(const char * a_Data, int a_Size) +int cPacket_PlayerPosition::Parse(cByteBuffer & a_Buffer) { int TotalBytes = 0; - HANDLE_PACKET_READ(ReadDouble, m_PosX, TotalBytes); - HANDLE_PACKET_READ(ReadDouble, m_PosY, TotalBytes); - HANDLE_PACKET_READ(ReadDouble, m_Stance, TotalBytes); - HANDLE_PACKET_READ(ReadDouble, m_PosZ, TotalBytes); - HANDLE_PACKET_READ(ReadBool, m_bFlying, TotalBytes); + HANDLE_PACKET_READ(ReadBEDouble, m_PosX, TotalBytes); + HANDLE_PACKET_READ(ReadBEDouble, m_PosY, TotalBytes); + HANDLE_PACKET_READ(ReadBEDouble, m_Stance, TotalBytes); + HANDLE_PACKET_READ(ReadBEDouble, m_PosZ, TotalBytes); + HANDLE_PACKET_READ(ReadBool, m_bFlying, TotalBytes); return TotalBytes; } diff --git a/source/packets/cPacket_Player.h b/source/packets/cPacket_Player.h index 5b17feabf..8dadcdaea 100644 --- a/source/packets/cPacket_Player.h +++ b/source/packets/cPacket_Player.h @@ -33,7 +33,7 @@ class cPacket_PlayerAbilities : public cPacket public: cPacket_PlayerAbilities(void) { m_PacketID = E_PLAYER_LIST_ITEM; } - virtual int Parse(const char * a_Data, int a_Size) override; + virtual int Parse(cByteBuffer & a_Buffer) override; virtual void Serialize(AString & a_Data) const override; virtual cPacket * Clone() const { return new cPacket_PlayerAbilities(*this); } @@ -54,7 +54,7 @@ public: cPacket_PlayerListItem() { m_PacketID = E_PLAYER_LIST_ITEM; } cPacket_PlayerListItem(const AString & a_PlayerName, bool a_Online, short a_Ping); - virtual int Parse(const char * a_Data, int a_Size) override; + virtual int Parse(cByteBuffer & a_Buffer) override; virtual void Serialize(AString & a_Data) const override; virtual cPacket* Clone() const { return new cPacket_PlayerListItem(*this); } @@ -79,7 +79,7 @@ public: cPacket_PlayerLook( cPlayer* a_Player ); virtual cPacket* Clone() const { return new cPacket_PlayerLook(*this); } - virtual int Parse(const char * a_Data, int a_Size) override; + virtual int Parse(cByteBuffer & a_Buffer) override; virtual void Serialize(AString & a_Data) const override; float m_Rotation; @@ -106,7 +106,7 @@ public: cPacket_PlayerMoveLook( cPlayer* a_Player ); virtual cPacket* Clone() const { return new cPacket_PlayerMoveLook(*this); } - virtual int Parse(const char * a_Data, int a_Size) override; + virtual int Parse(cByteBuffer & a_Buffer) override; virtual void Serialize(AString & a_Data) const override; double m_PosX; @@ -135,7 +135,7 @@ public: { m_PacketID = E_PLAYERPOS; } virtual cPacket* Clone() const { return new cPacket_PlayerPosition(*this); } - virtual int Parse(const char * a_Data, int a_Size) override; + virtual int Parse(cByteBuffer & a_Buffer) override; virtual void Serialize(AString & a_Data) const override; double m_PosX; diff --git a/source/packets/cPacket_Respawn.cpp b/source/packets/cPacket_Respawn.cpp index 657fd70b5..94c757003 100644 --- a/source/packets/cPacket_Respawn.cpp +++ b/source/packets/cPacket_Respawn.cpp @@ -22,15 +22,15 @@ void cPacket_Respawn::Serialize(AString & a_Data) const -int cPacket_Respawn::Parse(const char * a_Data, int a_Size) +int cPacket_Respawn::Parse(cByteBuffer & a_Buffer) { int TotalBytes = 0; - HANDLE_PACKET_READ(ReadInteger, m_Dimension, TotalBytes); - HANDLE_PACKET_READ(ReadByte, m_Difficulty, TotalBytes); - HANDLE_PACKET_READ(ReadByte, m_CreativeMode, TotalBytes); - HANDLE_PACKET_READ(ReadShort, m_WorldHeight, TotalBytes); - HANDLE_PACKET_READ(ReadString16, m_LevelType, TotalBytes); + HANDLE_PACKET_READ(ReadBEInt, m_Dimension, TotalBytes); + HANDLE_PACKET_READ(ReadChar, m_Difficulty, TotalBytes); + HANDLE_PACKET_READ(ReadChar, m_CreativeMode, TotalBytes); + HANDLE_PACKET_READ(ReadBEShort, m_WorldHeight, TotalBytes); + HANDLE_PACKET_READ(ReadBEUTF16String16, m_LevelType, TotalBytes); return TotalBytes; } diff --git a/source/packets/cPacket_Respawn.h b/source/packets/cPacket_Respawn.h index 302dbe25e..d51869cda 100644 --- a/source/packets/cPacket_Respawn.h +++ b/source/packets/cPacket_Respawn.h @@ -22,7 +22,7 @@ public: virtual cPacket* Clone() const { return new cPacket_Respawn( *this ); } - virtual int Parse(const char * a_Data, int a_Size) override; + virtual int Parse(cByteBuffer & a_Buffer) override; virtual void Serialize(AString & a_Data) const override; int m_Dimension; diff --git a/source/packets/cPacket_TimeUpdate.cpp b/source/packets/cPacket_TimeUpdate.cpp index be54e1484..1195305d4 100644 --- a/source/packets/cPacket_TimeUpdate.cpp +++ b/source/packets/cPacket_TimeUpdate.cpp @@ -7,10 +7,10 @@ -int cPacket_TimeUpdate::Parse(const char * a_Data, int a_Size) +int cPacket_TimeUpdate::Parse(cByteBuffer & a_Buffer) { int TotalBytes = 0; - HANDLE_PACKET_READ(ReadLong, m_Time, TotalBytes); + HANDLE_PACKET_READ(ReadBEInt64, m_Time, TotalBytes); return TotalBytes; } diff --git a/source/packets/cPacket_TimeUpdate.h b/source/packets/cPacket_TimeUpdate.h index 8864c9b00..9aaa02cae 100644 --- a/source/packets/cPacket_TimeUpdate.h +++ b/source/packets/cPacket_TimeUpdate.h @@ -16,7 +16,7 @@ public: cPacket_TimeUpdate( long long a_Time ) { m_PacketID = E_UPDATE_TIME; m_Time = a_Time; } virtual cPacket* Clone() const { return new cPacket_TimeUpdate(*this); } - virtual int Parse(const char * a_Data, int a_Size) override; + virtual int Parse(cByteBuffer & a_Buffer) override; virtual void Serialize(AString & a_Data) const override; long long m_Time; diff --git a/source/packets/cPacket_UpdateSign.cpp b/source/packets/cPacket_UpdateSign.cpp index a3ea53968..3ef587f13 100644 --- a/source/packets/cPacket_UpdateSign.cpp +++ b/source/packets/cPacket_UpdateSign.cpp @@ -7,16 +7,16 @@ -int cPacket_UpdateSign::Parse(const char * a_Data, int a_Size) +int cPacket_UpdateSign::Parse(cByteBuffer & a_Buffer) { int TotalBytes = 0; - HANDLE_PACKET_READ(ReadInteger, m_PosX, TotalBytes); - HANDLE_PACKET_READ(ReadShort, m_PosY, TotalBytes); - HANDLE_PACKET_READ(ReadInteger, m_PosZ, TotalBytes); - HANDLE_PACKET_READ(ReadString16, m_Line1, TotalBytes); - HANDLE_PACKET_READ(ReadString16, m_Line2, TotalBytes); - HANDLE_PACKET_READ(ReadString16, m_Line3, TotalBytes); - HANDLE_PACKET_READ(ReadString16, m_Line4, TotalBytes); + HANDLE_PACKET_READ(ReadBEInt, m_PosX, TotalBytes); + HANDLE_PACKET_READ(ReadBEShort, m_PosY, TotalBytes); + HANDLE_PACKET_READ(ReadBEInt, m_PosZ, TotalBytes); + HANDLE_PACKET_READ(ReadBEUTF16String16, m_Line1, TotalBytes); + HANDLE_PACKET_READ(ReadBEUTF16String16, m_Line2, TotalBytes); + HANDLE_PACKET_READ(ReadBEUTF16String16, m_Line3, TotalBytes); + HANDLE_PACKET_READ(ReadBEUTF16String16, m_Line4, TotalBytes); return TotalBytes; } diff --git a/source/packets/cPacket_UpdateSign.h b/source/packets/cPacket_UpdateSign.h index b2c0effad..9c3790c77 100644 --- a/source/packets/cPacket_UpdateSign.h +++ b/source/packets/cPacket_UpdateSign.h @@ -17,7 +17,7 @@ public: { m_PacketID = E_UPDATE_SIGN; } virtual cPacket* Clone() const { return new cPacket_UpdateSign( *this ); } - virtual int Parse(const char * a_Data, int a_Size) override; + virtual int Parse(cByteBuffer & a_Buffer) override; virtual void Serialize(AString & a_Data) const override; int m_PosX; diff --git a/source/packets/cPacket_UseEntity.cpp b/source/packets/cPacket_UseEntity.cpp index 6f296e96b..73b4f7f82 100644 --- a/source/packets/cPacket_UseEntity.cpp +++ b/source/packets/cPacket_UseEntity.cpp @@ -7,12 +7,12 @@ -int cPacket_UseEntity::Parse(const char * a_Data, int a_Size) +int cPacket_UseEntity::Parse(cByteBuffer & a_Buffer) { int TotalBytes = 0; - HANDLE_PACKET_READ(ReadInteger, m_UniqueID, TotalBytes); - HANDLE_PACKET_READ(ReadInteger, m_TargetID, TotalBytes); - HANDLE_PACKET_READ(ReadBool, m_bLeftClick, TotalBytes); + HANDLE_PACKET_READ(ReadBEInt, m_UniqueID, TotalBytes); + HANDLE_PACKET_READ(ReadBEInt, m_TargetID, TotalBytes); + HANDLE_PACKET_READ(ReadBool, m_bLeftClick, TotalBytes); return TotalBytes; } diff --git a/source/packets/cPacket_UseEntity.h b/source/packets/cPacket_UseEntity.h index 7a35bd54c..799122bf9 100644 --- a/source/packets/cPacket_UseEntity.h +++ b/source/packets/cPacket_UseEntity.h @@ -17,7 +17,7 @@ public: { m_PacketID = E_USE_ENTITY; } virtual cPacket* Clone() const { return new cPacket_UseEntity(*this); } - virtual int Parse(const char * a_Data, int a_Size) override; + virtual int Parse(cByteBuffer & a_Buffer) override; int m_UniqueID; int m_TargetID; diff --git a/source/packets/cPacket_WindowClick.cpp b/source/packets/cPacket_WindowClick.cpp index 05be3c53c..c250c187e 100644 --- a/source/packets/cPacket_WindowClick.cpp +++ b/source/packets/cPacket_WindowClick.cpp @@ -9,18 +9,17 @@ -int cPacket_WindowClick::Parse(const char * a_Data, int a_Size) +int cPacket_WindowClick::Parse(cByteBuffer & a_Buffer) { int TotalBytes = 0; - HANDLE_PACKET_READ(ReadByte, m_WindowID, TotalBytes); - HANDLE_PACKET_READ(ReadShort, m_SlotNum, TotalBytes); - HANDLE_PACKET_READ(ReadByte, m_RightMouse, TotalBytes); - HANDLE_PACKET_READ(ReadShort, m_NumClicks, TotalBytes); - HANDLE_PACKET_READ(ReadBool, m_IsShiftPressed, TotalBytes); + HANDLE_PACKET_READ(ReadChar, m_WindowID, TotalBytes); + HANDLE_PACKET_READ(ReadBEShort, m_SlotNum, TotalBytes); + HANDLE_PACKET_READ(ReadChar, m_RightMouse, TotalBytes); + HANDLE_PACKET_READ(ReadBEShort, m_NumClicks, TotalBytes); + HANDLE_PACKET_READ(ReadBool, m_IsShiftPressed, TotalBytes); cPacket_ItemData Item; - - int res = Item.Parse(a_Data + TotalBytes, a_Size - TotalBytes); + int res = Item.Parse(a_Buffer); if (res < 0) { return res; diff --git a/source/packets/cPacket_WindowClick.h b/source/packets/cPacket_WindowClick.h index 93dc5dc2e..72ebad2a1 100644 --- a/source/packets/cPacket_WindowClick.h +++ b/source/packets/cPacket_WindowClick.h @@ -23,7 +23,7 @@ public: { m_PacketID = E_WINDOW_CLICK; } virtual cPacket* Clone() const { return new cPacket_WindowClick(*this); } - virtual int Parse(const char * a_Data, int a_Size) override; + virtual int Parse(cByteBuffer & a_Buffer) override; char m_WindowID; short m_SlotNum; // Slot diff --git a/source/packets/cPacket_WindowClose.cpp b/source/packets/cPacket_WindowClose.cpp index f4361e4a1..c15e90d3d 100644 --- a/source/packets/cPacket_WindowClose.cpp +++ b/source/packets/cPacket_WindowClose.cpp @@ -7,10 +7,10 @@ -int cPacket_WindowClose::Parse(const char * a_Data, int a_Size) +int cPacket_WindowClose::Parse(cByteBuffer & a_Buffer) { int TotalBytes = 0; - HANDLE_PACKET_READ(ReadByte, m_Close, TotalBytes); + HANDLE_PACKET_READ(ReadChar, m_Close, TotalBytes); return TotalBytes; } diff --git a/source/packets/cPacket_WindowClose.h b/source/packets/cPacket_WindowClose.h index 674c071d1..3bf7b8240 100644 --- a/source/packets/cPacket_WindowClose.h +++ b/source/packets/cPacket_WindowClose.h @@ -15,7 +15,7 @@ public: { m_PacketID = E_WINDOW_CLOSE; } virtual cPacket* Clone() const { return new cPacket_WindowClose(*this); } - virtual int Parse(const char * a_Data, int a_Size) override; + virtual int Parse(cByteBuffer & a_Buffer) override; virtual void Serialize(AString & a_Data) const override; char m_Close; // m_Close == cWindow WindowType number -- cgit v1.2.3