diff options
author | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2012-08-19 13:51:17 +0200 |
---|---|---|
committer | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2012-08-19 13:51:17 +0200 |
commit | eb3ed1aec1fb9e4468a7829cabd42572b7554d70 (patch) | |
tree | 4b5f428bf612785af8c306ba40f46c66fe0681a0 /source/packets | |
parent | Fixed Bug #236 (diff) | |
download | cuberite-eb3ed1aec1fb9e4468a7829cabd42572b7554d70.tar cuberite-eb3ed1aec1fb9e4468a7829cabd42572b7554d70.tar.gz cuberite-eb3ed1aec1fb9e4468a7829cabd42572b7554d70.tar.bz2 cuberite-eb3ed1aec1fb9e4468a7829cabd42572b7554d70.tar.lz cuberite-eb3ed1aec1fb9e4468a7829cabd42572b7554d70.tar.xz cuberite-eb3ed1aec1fb9e4468a7829cabd42572b7554d70.tar.zst cuberite-eb3ed1aec1fb9e4468a7829cabd42572b7554d70.zip |
Diffstat (limited to 'source/packets')
-rw-r--r-- | source/packets/cPacket_EntityEquipment.cpp | 24 | ||||
-rw-r--r-- | source/packets/cPacket_EntityEquipment.h | 23 | ||||
-rw-r--r-- | source/packets/cPacket_Player.cpp | 48 | ||||
-rw-r--r-- | source/packets/cPacket_Player.h | 20 | ||||
-rw-r--r-- | source/packets/cPacket_WholeInventory.cpp | 20 | ||||
-rw-r--r-- | source/packets/cPacket_WholeInventory.h | 24 | ||||
-rw-r--r-- | source/packets/cPacket_WindowClose.cpp | 4 | ||||
-rw-r--r-- | source/packets/cPacket_WindowClose.h | 13 |
8 files changed, 92 insertions, 84 deletions
diff --git a/source/packets/cPacket_EntityEquipment.cpp b/source/packets/cPacket_EntityEquipment.cpp index c66b1b6b4..6358c4a1f 100644 --- a/source/packets/cPacket_EntityEquipment.cpp +++ b/source/packets/cPacket_EntityEquipment.cpp @@ -9,11 +9,11 @@ cPacket_EntityEquipment::cPacket_EntityEquipment( const cPacket_EntityEquipment & a_Copy ) { - m_PacketID = E_ENTITY_EQUIPMENT; - m_UniqueID = a_Copy.m_UniqueID; - m_Slot = a_Copy.m_Slot; - m_ItemID = a_Copy.m_ItemID; - m_Short = 0; + m_PacketID = E_ENTITY_EQUIPMENT; + m_UniqueID = a_Copy.m_UniqueID; + m_SlotNum = a_Copy.m_SlotNum; + m_ItemType = a_Copy.m_ItemType; + m_ItemDamage = a_Copy.m_ItemDamage; } @@ -23,10 +23,10 @@ cPacket_EntityEquipment::cPacket_EntityEquipment( const cPacket_EntityEquipment int cPacket_EntityEquipment::Parse(cByteBuffer & a_Buffer) { int TotalBytes = 0; - 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); + HANDLE_PACKET_READ(ReadBEInt, m_UniqueID, TotalBytes); + HANDLE_PACKET_READ(ReadBEShort, m_SlotNum, TotalBytes); + HANDLE_PACKET_READ(ReadBEShort, m_ItemType, TotalBytes); + HANDLE_PACKET_READ(ReadBEShort, m_ItemDamage, TotalBytes); return TotalBytes; } @@ -38,9 +38,9 @@ void cPacket_EntityEquipment::Serialize(AString & a_Data) const { AppendByte (a_Data, m_PacketID); AppendInteger(a_Data, m_UniqueID); - AppendShort (a_Data, m_Slot); - AppendShort (a_Data, m_ItemID); - AppendShort (a_Data, m_Short); + AppendShort (a_Data, m_SlotNum); + AppendShort (a_Data, m_ItemType); + AppendShort (a_Data, m_ItemDamage); } diff --git a/source/packets/cPacket_EntityEquipment.h b/source/packets/cPacket_EntityEquipment.h index 3c6197f32..69260fae4 100644 --- a/source/packets/cPacket_EntityEquipment.h +++ b/source/packets/cPacket_EntityEquipment.h @@ -11,22 +11,23 @@ class cPacket_EntityEquipment : public cPacket public: cPacket_EntityEquipment() : m_UniqueID( 0 ) - , m_Slot( 0 ) - , m_ItemID( 0 ) - , m_Short( 0 ) - { m_PacketID = E_ENTITY_EQUIPMENT; m_Short = 0; } + , m_SlotNum( 0 ) + , m_ItemType( 0 ) + , m_ItemDamage( 0 ) + { + m_PacketID = E_ENTITY_EQUIPMENT; + } + cPacket_EntityEquipment( const cPacket_EntityEquipment & a_Copy ); - virtual cPacket* Clone() const { return new cPacket_EntityEquipment(*this); } + virtual cPacket * Clone() const { return new cPacket_EntityEquipment(*this); } - virtual int Parse(cByteBuffer & a_Buffer) override; + virtual int Parse(cByteBuffer & a_Buffer) override; virtual void Serialize(AString & a_Data) const override; int m_UniqueID; - short m_Slot; // 0 = hold 1-4 = armor - short m_ItemID; - short m_Short; - - static const unsigned int c_Size = 1 + 4 + 2 + 2 + 2; + short m_SlotNum; // 0 = hold 1-4 = armor + short m_ItemType; + short m_ItemDamage; }; diff --git a/source/packets/cPacket_Player.cpp b/source/packets/cPacket_Player.cpp index 3a897a1ea..c24905e15 100644 --- a/source/packets/cPacket_Player.cpp +++ b/source/packets/cPacket_Player.cpp @@ -106,10 +106,10 @@ void cPacket_PlayerListItem::Serialize(AString & a_Data) const cPacket_PlayerLook::cPacket_PlayerLook( cPlayer* a_Player ) { - m_PacketID = E_PLAYERLOOK; - m_Rotation = a_Player->GetRotation(); - m_Pitch = a_Player->GetPitch(); - m_bFlying = a_Player->GetFlying(); + m_PacketID = E_PLAYERLOOK; + m_Rotation = a_Player->GetRotation(); + m_Pitch = a_Player->GetPitch(); + m_IsOnGround = a_Player->IsOnGround(); } @@ -119,9 +119,9 @@ cPacket_PlayerLook::cPacket_PlayerLook( cPlayer* a_Player ) int cPacket_PlayerLook::Parse(cByteBuffer & a_Buffer) { int TotalBytes = 0; - HANDLE_PACKET_READ(ReadBEFloat, m_Rotation, TotalBytes); - HANDLE_PACKET_READ(ReadBEFloat, 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_IsOnGround, TotalBytes); return TotalBytes; } @@ -134,7 +134,7 @@ void cPacket_PlayerLook::Serialize(AString & a_Data) const AppendByte (a_Data, m_PacketID); AppendFloat (a_Data, m_Rotation); AppendFloat (a_Data, m_Pitch); - AppendBool (a_Data, m_bFlying); + AppendBool (a_Data, m_IsOnGround); } @@ -145,14 +145,14 @@ void cPacket_PlayerLook::Serialize(AString & a_Data) const cPacket_PlayerMoveLook::cPacket_PlayerMoveLook( cPlayer* a_Player ) { - m_PacketID = E_PLAYERMOVELOOK; - m_PosX = a_Player->GetPosX(); - m_PosY = a_Player->GetPosY() + 1.65; - m_PosZ = a_Player->GetPosZ(); - m_Stance = a_Player->GetStance(); - m_Rotation = a_Player->GetRotation(); - m_Pitch = a_Player->GetPitch(); - m_bFlying = a_Player->GetFlying(); + m_PacketID = E_PLAYERMOVELOOK; + m_PosX = a_Player->GetPosX(); + m_PosY = a_Player->GetPosY() + 1.65; + m_PosZ = a_Player->GetPosZ(); + m_Stance = a_Player->GetStance(); + m_Rotation = a_Player->GetRotation(); + m_Pitch = a_Player->GetPitch(); + m_IsOnGround = a_Player->IsOnGround(); } @@ -162,13 +162,13 @@ cPacket_PlayerMoveLook::cPacket_PlayerMoveLook( cPlayer* a_Player ) int cPacket_PlayerMoveLook::Parse(cByteBuffer & a_Buffer) { int TotalBytes = 0; - 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); + 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_IsOnGround, TotalBytes); return TotalBytes; } @@ -185,7 +185,7 @@ void cPacket_PlayerMoveLook::Serialize(AString & a_Data) const AppendDouble(a_Data, m_PosZ); AppendFloat (a_Data, m_Rotation); AppendFloat (a_Data, m_Pitch); - AppendBool (a_Data, m_bFlying); + AppendBool (a_Data, m_IsOnGround); } diff --git a/source/packets/cPacket_Player.h b/source/packets/cPacket_Player.h index 05b75d9d1..d9f7c0057 100644 --- a/source/packets/cPacket_Player.h +++ b/source/packets/cPacket_Player.h @@ -74,8 +74,11 @@ public: cPacket_PlayerLook() : m_Rotation( 0 ) , m_Pitch( 0 ) - , m_bFlying( false ) - { m_PacketID = E_PLAYERLOOK; } + , m_IsOnGround( false ) + { + m_PacketID = E_PLAYERLOOK; + } + cPacket_PlayerLook( cPlayer* a_Player ); virtual cPacket* Clone() const { return new cPacket_PlayerLook(*this); } @@ -84,7 +87,7 @@ public: float m_Rotation; float m_Pitch; - bool m_bFlying; // Yeah.. wtf + bool m_IsOnGround; } ; @@ -101,12 +104,15 @@ public: , m_PosZ( 0.0 ) , m_Rotation( 0.f ) , m_Pitch( 0.f ) - , m_bFlying( false ) - { m_PacketID = E_PLAYERMOVELOOK; } + , m_IsOnGround( false ) + { + m_PacketID = E_PLAYERMOVELOOK; + } + cPacket_PlayerMoveLook( cPlayer* a_Player ); virtual cPacket* Clone() const { return new cPacket_PlayerMoveLook(*this); } - virtual int Parse(cByteBuffer & a_Buffer) override; + virtual int Parse(cByteBuffer & a_Buffer) override; virtual void Serialize(AString & a_Data) const override; double m_PosX; @@ -115,7 +121,7 @@ public: double m_PosZ; float m_Rotation; float m_Pitch; - bool m_bFlying; // Yeah.. wtf + bool m_IsOnGround; } ; diff --git a/source/packets/cPacket_WholeInventory.cpp b/source/packets/cPacket_WholeInventory.cpp index fd6a6b457..69ea33580 100644 --- a/source/packets/cPacket_WholeInventory.cpp +++ b/source/packets/cPacket_WholeInventory.cpp @@ -25,28 +25,28 @@ cPacket_WholeInventory::cPacket_WholeInventory( const cPacket_WholeInventory & a -cPacket_WholeInventory::cPacket_WholeInventory(cInventory * a_Inventory) +cPacket_WholeInventory::cPacket_WholeInventory(const cInventory & a_Inventory) { m_PacketID = E_INVENTORY_WHOLE; - m_WindowID = 0; - m_Count = a_Inventory->c_NumSlots; - m_Items = new cItem[m_Count]; + m_WindowID = 0; // Inventory window has a constant ID of 0 + m_Count = a_Inventory.c_NumSlots; + m_Items = new cItem[m_Count]; // TODO: copy items one by one, they may have some values that needn't be shallow-copiable - memcpy( m_Items, a_Inventory->GetSlots(), sizeof(cItem)*m_Count ); + memcpy( m_Items, a_Inventory.GetSlots(), sizeof(cItem) * m_Count); } -cPacket_WholeInventory::cPacket_WholeInventory(cWindow * a_Window) +cPacket_WholeInventory::cPacket_WholeInventory(const cWindow & a_Window) { m_PacketID = E_INVENTORY_WHOLE; - m_WindowID = (char)a_Window->GetWindowID(); - m_Count = (short)a_Window->GetNumSlots(); - m_Items = new cItem[m_Count]; + m_WindowID = (char)a_Window.GetWindowID(); + m_Count = (short)a_Window.GetNumSlots(); + m_Items = new cItem[m_Count]; // TODO: copy items one by one, they may have some values that needn't be shallow-copiable - memcpy( m_Items, a_Window->GetSlots(), sizeof(cItem) * m_Count); + memcpy( m_Items, a_Window.GetSlots(), sizeof(cItem) * m_Count); } diff --git a/source/packets/cPacket_WholeInventory.h b/source/packets/cPacket_WholeInventory.h index 3a9cc0a1b..6582fe6fe 100644 --- a/source/packets/cPacket_WholeInventory.h +++ b/source/packets/cPacket_WholeInventory.h @@ -17,29 +17,29 @@ class cItem; -class cPacket_WholeInventory : public cPacket // full inventory [S -> C] ? +class cPacket_WholeInventory : + public cPacket // full inventory [S -> C] ? { public: - cPacket_WholeInventory( const cPacket_WholeInventory & a_Clone ); - cPacket_WholeInventory( cInventory* a_Inventory ); - cPacket_WholeInventory( cWindow* a_Window ); + cPacket_WholeInventory(const cPacket_WholeInventory & a_Clone); + cPacket_WholeInventory(const cInventory & a_Inventory); + cPacket_WholeInventory(const cWindow & a_Window); ~cPacket_WholeInventory(); cPacket_WholeInventory() : m_WindowID( 0 ) , m_Count( 0 ) , m_Items( 0 ) - { m_PacketID = E_INVENTORY_WHOLE; } + { + m_PacketID = E_INVENTORY_WHOLE; + } - - virtual cPacket* Clone() const { return new cPacket_WholeInventory(*this); } + virtual cPacket * Clone() const { return new cPacket_WholeInventory(*this); } virtual void Serialize(AString & a_Data) const override; - char m_WindowID; // WTF? - short m_Count; // Number of items - cItem * m_Items; // Array of m_Count items - - static const unsigned int c_Size = 1 + 1 + 2; // Minimal size + char m_WindowID; + short m_Count; + cItem * m_Items; }; diff --git a/source/packets/cPacket_WindowClose.cpp b/source/packets/cPacket_WindowClose.cpp index c15e90d3d..9991ab500 100644 --- a/source/packets/cPacket_WindowClose.cpp +++ b/source/packets/cPacket_WindowClose.cpp @@ -10,7 +10,7 @@ int cPacket_WindowClose::Parse(cByteBuffer & a_Buffer) { int TotalBytes = 0; - HANDLE_PACKET_READ(ReadChar, m_Close, TotalBytes); + HANDLE_PACKET_READ(ReadChar, m_WindowID, TotalBytes); return TotalBytes; } @@ -21,7 +21,7 @@ int cPacket_WindowClose::Parse(cByteBuffer & a_Buffer) void cPacket_WindowClose::Serialize(AString & a_Data) const { AppendByte(a_Data, m_PacketID); - AppendByte(a_Data, m_Close); + AppendByte(a_Data, m_WindowID); } diff --git a/source/packets/cPacket_WindowClose.h b/source/packets/cPacket_WindowClose.h index 3bf7b8240..de40ab446 100644 --- a/source/packets/cPacket_WindowClose.h +++ b/source/packets/cPacket_WindowClose.h @@ -11,16 +11,17 @@ class cPacket_WindowClose : public cPacket { public: cPacket_WindowClose() - : m_Close( 0 ) - { m_PacketID = E_WINDOW_CLOSE; } + : m_WindowID( 0 ) + { + m_PacketID = E_WINDOW_CLOSE; + } + virtual cPacket* Clone() const { return new cPacket_WindowClose(*this); } - virtual int Parse(cByteBuffer & a_Buffer) override; + virtual int Parse(cByteBuffer & a_Buffer) override; virtual void Serialize(AString & a_Data) const override; - char m_Close; // m_Close == cWindow WindowType number - - static const unsigned int c_Size = 1 + 1; + char m_WindowID; }; |