From 07fa8313b184e2a9d7666cf6f7b10d5def8dc928 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 8 Nov 2013 21:32:14 +0100 Subject: cProtocol::SendWindowOpen() signature changed. This implements #313. --- source/ClientHandle.cpp | 4 ++-- source/ClientHandle.h | 6 +++--- source/Protocol/Protocol.h | 2 +- source/Protocol/Protocol125.cpp | 12 ++++++------ source/Protocol/Protocol125.h | 2 +- source/Protocol/Protocol15x.cpp | 13 +++++++------ source/Protocol/Protocol15x.h | 2 +- source/Protocol/Protocol16x.cpp | 17 +++++++++-------- source/Protocol/Protocol16x.h | 2 +- source/Protocol/Protocol17x.cpp | 23 +++++++++++++---------- source/Protocol/Protocol17x.h | 6 +++--- source/Protocol/ProtocolRecognizer.cpp | 4 ++-- source/Protocol/ProtocolRecognizer.h | 6 +++--- source/UI/Window.cpp | 2 +- source/UI/Window.h | 6 ++++++ 15 files changed, 59 insertions(+), 48 deletions(-) (limited to 'source') diff --git a/source/ClientHandle.cpp b/source/ClientHandle.cpp index 86a4aecc8..3548b4035 100644 --- a/source/ClientHandle.cpp +++ b/source/ClientHandle.cpp @@ -2022,9 +2022,9 @@ void cClientHandle::SendWindowClose(const cWindow & a_Window) -void cClientHandle::SendWindowOpen(char a_WindowID, char a_WindowType, const AString & a_WindowTitle, char a_NumSlots) +void cClientHandle::SendWindowOpen(const cWindow & a_Window) { - m_Protocol->SendWindowOpen(a_WindowID, a_WindowType, a_WindowTitle, a_NumSlots); + m_Protocol->SendWindowOpen(a_Window); } diff --git a/source/ClientHandle.h b/source/ClientHandle.h index f7fa2b36f..3844937ad 100644 --- a/source/ClientHandle.h +++ b/source/ClientHandle.h @@ -134,9 +134,9 @@ public: void SendUpdateSign (int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4); void SendUseBed (const cEntity & a_Entity, int a_BlockX, int a_BlockY, int a_BlockZ ); void SendWeather (eWeather a_Weather); - void SendWholeInventory (const cWindow & a_Window); - void SendWindowClose (const cWindow & a_Window); - void SendWindowOpen (char a_WindowID, char a_WindowType, const AString & a_WindowTitle, char a_NumSlots); + void SendWholeInventory (const cWindow & a_Window); + void SendWindowClose (const cWindow & a_Window); + void SendWindowOpen (const cWindow & a_Window); void SendWindowProperty (const cWindow & a_Window, int a_Property, int a_Value); const AString & GetUsername(void) const; // tolua_export diff --git a/source/Protocol/Protocol.h b/source/Protocol/Protocol.h index 5d66808cf..5023ea227 100644 --- a/source/Protocol/Protocol.h +++ b/source/Protocol/Protocol.h @@ -101,7 +101,7 @@ public: virtual void SendWeather (eWeather a_Weather) = 0; virtual void SendWholeInventory (const cWindow & a_Window) = 0; virtual void SendWindowClose (const cWindow & a_Window) = 0; - virtual void SendWindowOpen (char a_WindowID, char a_WindowType, const AString & a_WindowTitle, char a_NumSlots) = 0; + virtual void SendWindowOpen (const cWindow & a_Window) = 0; virtual void SendWindowProperty (const cWindow & a_Window, short a_Property, short a_Value) = 0; /// Returns the ServerID used for authentication through session.minecraft.net diff --git a/source/Protocol/Protocol125.cpp b/source/Protocol/Protocol125.cpp index e53ab948c..9f2770815 100644 --- a/source/Protocol/Protocol125.cpp +++ b/source/Protocol/Protocol125.cpp @@ -956,19 +956,19 @@ void cProtocol125::SendWindowClose(const cWindow & a_Window) -void cProtocol125::SendWindowOpen(char a_WindowID, char a_WindowType, const AString & a_WindowTitle, char a_NumSlots) +void cProtocol125::SendWindowOpen(const cWindow & a_Window) { - if (a_WindowType < 0) + if (a_Window.GetWindowType() < 0) { // Do not send for inventory windows return; } cCSLock Lock(m_CSPacket); WriteByte (PACKET_WINDOW_OPEN); - WriteByte (a_WindowID); - WriteByte (a_WindowType); - WriteString(a_WindowTitle); - WriteByte (a_NumSlots); + WriteByte (a_Window.GetWindowID()); + WriteByte (a_Window.GetWindowType()); + WriteString(a_Window.GetWindowTitle()); + WriteByte (a_Window.GetNumNonInventorySlots()); Flush(); } diff --git a/source/Protocol/Protocol125.h b/source/Protocol/Protocol125.h index ad61dea74..db913bb57 100644 --- a/source/Protocol/Protocol125.h +++ b/source/Protocol/Protocol125.h @@ -78,7 +78,7 @@ public: virtual void SendWeather (eWeather a_Weather) override; virtual void SendWholeInventory (const cWindow & a_Window) override; virtual void SendWindowClose (const cWindow & a_Window) override; - virtual void SendWindowOpen (char a_WindowID, char a_WindowType, const AString & a_WindowTitle, char a_NumSlots) override; + virtual void SendWindowOpen (const cWindow & a_Window) override; virtual void SendWindowProperty (const cWindow & a_Window, short a_Property, short a_Value) override; virtual AString GetAuthServerID(void) override; diff --git a/source/Protocol/Protocol15x.cpp b/source/Protocol/Protocol15x.cpp index cbae0700e..c337d26e7 100644 --- a/source/Protocol/Protocol15x.cpp +++ b/source/Protocol/Protocol15x.cpp @@ -12,6 +12,7 @@ Implements the 1.5.x protocol classes: #include "Protocol15x.h" #include "../ClientHandle.h" #include "../Item.h" +#include "../UI/Window.h" @@ -54,19 +55,19 @@ cProtocol150::cProtocol150(cClientHandle * a_Client) : -void cProtocol150::SendWindowOpen(char a_WindowID, char a_WindowType, const AString & a_WindowTitle, char a_NumSlots) +void cProtocol150::SendWindowOpen(const cWindow & a_Window) { - if (a_WindowType < 0) + if (a_Window.GetWindowType() < 0) { // Do not send for inventory windows return; } cCSLock Lock(m_CSPacket); WriteByte (PACKET_WINDOW_OPEN); - WriteByte (a_WindowID); - WriteByte (a_WindowType); - WriteString(a_WindowTitle); - WriteByte (a_NumSlots); + WriteByte (a_Window.GetWindowID()); + WriteByte (a_Window.GetWindowType()); + WriteString(a_Window.GetWindowTitle()); + WriteByte (a_Window.GetNumNonInventorySlots()); WriteByte (1); // Use title Flush(); } diff --git a/source/Protocol/Protocol15x.h b/source/Protocol/Protocol15x.h index 3e1547df8..e554fe130 100644 --- a/source/Protocol/Protocol15x.h +++ b/source/Protocol/Protocol15x.h @@ -28,7 +28,7 @@ class cProtocol150 : public: cProtocol150(cClientHandle * a_Client); - virtual void SendWindowOpen(char a_WindowID, char a_WindowType, const AString & a_WindowTitle, char a_NumSlots) override; + virtual void SendWindowOpen(const cWindow & a_Window) override; virtual int ParseWindowClick(void); } ; diff --git a/source/Protocol/Protocol16x.cpp b/source/Protocol/Protocol16x.cpp index 23e23d463..cfa27b3c4 100644 --- a/source/Protocol/Protocol16x.cpp +++ b/source/Protocol/Protocol16x.cpp @@ -17,6 +17,7 @@ Implements the 1.6.x protocol classes: #include "../ClientHandle.h" #include "../Entities/Entity.h" #include "../Entities/Player.h" +#include "../UI/Window.h" @@ -153,23 +154,23 @@ void cProtocol161::SendRespawn(void) -void cProtocol161::SendWindowOpen(char a_WindowID, char a_WindowType, const AString & a_WindowTitle, char a_NumSlots) +void cProtocol161::SendWindowOpen(const cWindow & a_Window) { - if (a_WindowType < 0) + if (a_Window.GetWindowType() < 0) { // Do not send for inventory windows return; } cCSLock Lock(m_CSPacket); WriteByte (PACKET_WINDOW_OPEN); - WriteByte (a_WindowID); - WriteByte (a_WindowType); - WriteString(a_WindowTitle); - WriteByte (a_NumSlots); + WriteByte (a_Window.GetWindowID()); + WriteByte (a_Window.GetWindowType()); + WriteString(a_Window.GetWindowTitle()); + WriteByte (a_Window.GetNumNonInventorySlots()); WriteByte (1); // Use title - if (a_WindowType == 11) // horse / donkey + if (a_Window.GetWindowType() == cWindow::wtAnimalChest) { - WriteInt(0); // Unknown value sent only when window type is 11 (horse / donkey) + WriteInt(0); // TODO: The animal's EntityID } Flush(); } diff --git a/source/Protocol/Protocol16x.h b/source/Protocol/Protocol16x.h index 2447f90a7..325e41c5a 100644 --- a/source/Protocol/Protocol16x.h +++ b/source/Protocol/Protocol16x.h @@ -42,7 +42,7 @@ protected: virtual void SendHealth (void) override; virtual void SendPlayerMaxSpeed(void) override; virtual void SendRespawn (void) override; - virtual void SendWindowOpen (char a_WindowID, char a_WindowType, const AString & a_WindowTitle, char a_NumSlots) override; + virtual void SendWindowOpen (const cWindow & a_Window) override; virtual int ParseEntityAction (void) override; virtual int ParsePlayerAbilities(void) override; diff --git a/source/Protocol/Protocol17x.cpp b/source/Protocol/Protocol17x.cpp index a2b3a7a56..eee4f7d0e 100644 --- a/source/Protocol/Protocol17x.cpp +++ b/source/Protocol/Protocol17x.cpp @@ -841,21 +841,24 @@ void cProtocol172::SendWindowClose(const cWindow & a_Window) -void cProtocol172::SendWindowOpen(char a_WindowID, char a_WindowType, const AString & a_WindowTitle, char a_NumSlots) +void cProtocol172::SendWindowOpen(const cWindow & a_Window) { + if (a_Window.GetWindowType() < 0) + { + // Do not send this packet for player inventory windows + return; + } + cPacketizer Pkt(*this, 0x2d); - Pkt.WriteChar(a_WindowID); - Pkt.WriteChar(a_WindowType); - Pkt.WriteString(a_WindowTitle); - Pkt.WriteChar(a_NumSlots); + Pkt.WriteChar(a_Window.GetWindowID()); + Pkt.WriteChar(a_Window.GetWindowType()); + Pkt.WriteString(a_Window.GetWindowTitle()); + Pkt.WriteChar(a_Window.GetNumNonInventorySlots()); Pkt.WriteBool(true); - /* - // TODO: - if (a_WindowType == cWindow::wtHorse) + if (a_Window.GetWindowType() == cWindow::wtAnimalChest) { - Pkt.WriteInt(HorseID); + Pkt.WriteInt(0); // TODO: The animal's EntityID } - */ } diff --git a/source/Protocol/Protocol17x.h b/source/Protocol/Protocol17x.h index ea7f7461f..844069403 100644 --- a/source/Protocol/Protocol17x.h +++ b/source/Protocol/Protocol17x.h @@ -85,9 +85,9 @@ public: virtual void SendUpdateSign (int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4) override; virtual void SendUseBed (const cEntity & a_Entity, int a_BlockX, int a_BlockY, int a_BlockZ ) override; virtual void SendWeather (eWeather a_Weather) override; - virtual void SendWholeInventory (const cWindow & a_Window) override; - virtual void SendWindowClose (const cWindow & a_Window) override; - virtual void SendWindowOpen (char a_WindowID, char a_WindowType, const AString & a_WindowTitle, char a_NumSlots) override; + virtual void SendWholeInventory (const cWindow & a_Window) override; + virtual void SendWindowClose (const cWindow & a_Window) override; + virtual void SendWindowOpen (const cWindow & a_Window) override; virtual void SendWindowProperty (const cWindow & a_Window, short a_Property, short a_Value) override; virtual AString GetAuthServerID(void) override { return m_AuthServerID; } diff --git a/source/Protocol/ProtocolRecognizer.cpp b/source/Protocol/ProtocolRecognizer.cpp index 501e8bbe0..6d0d71524 100644 --- a/source/Protocol/ProtocolRecognizer.cpp +++ b/source/Protocol/ProtocolRecognizer.cpp @@ -625,10 +625,10 @@ void cProtocolRecognizer::SendWindowClose(const cWindow & a_Window) -void cProtocolRecognizer::SendWindowOpen(char a_WindowID, char a_WindowType, const AString & a_WindowTitle, char a_NumSlots) +void cProtocolRecognizer::SendWindowOpen(const cWindow & a_Window) { ASSERT(m_Protocol != NULL); - m_Protocol->SendWindowOpen(a_WindowID, a_WindowType, a_WindowTitle, a_NumSlots); + m_Protocol->SendWindowOpen(a_Window); } diff --git a/source/Protocol/ProtocolRecognizer.h b/source/Protocol/ProtocolRecognizer.h index 9bf550309..2f217833a 100644 --- a/source/Protocol/ProtocolRecognizer.h +++ b/source/Protocol/ProtocolRecognizer.h @@ -111,9 +111,9 @@ public: virtual void SendUpdateSign (int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4) override; virtual void SendUseBed (const cEntity & a_Entity, int a_BlockX, int a_BlockY, int a_BlockZ ) override; virtual void SendWeather (eWeather a_Weather) override; - virtual void SendWholeInventory (const cWindow & a_Window) override; - virtual void SendWindowClose (const cWindow & a_Window) override; - virtual void SendWindowOpen (char a_WindowID, char a_WindowType, const AString & a_WindowTitle, char a_NumSlots) override; + virtual void SendWholeInventory (const cWindow & a_Window) override; + virtual void SendWindowClose (const cWindow & a_Window) override; + virtual void SendWindowOpen (const cWindow & a_Window) override; virtual void SendWindowProperty (const cWindow & a_Window, short a_Property, short a_Value) override; virtual AString GetAuthServerID(void) override; diff --git a/source/UI/Window.cpp b/source/UI/Window.cpp index 1318cbca8..1f023cb03 100644 --- a/source/UI/Window.cpp +++ b/source/UI/Window.cpp @@ -245,7 +245,7 @@ void cWindow::OpenedByPlayer(cPlayer & a_Player) } // for itr - m_SlotAreas[] } - a_Player.GetClientHandle()->SendWindowOpen(m_WindowID, m_WindowType, m_WindowTitle, GetNumSlots() - c_NumInventorySlots); + a_Player.GetClientHandle()->SendWindowOpen(*this); } diff --git a/source/UI/Window.h b/source/UI/Window.h index 2d5e81e9e..6927cd3ac 100644 --- a/source/UI/Window.h +++ b/source/UI/Window.h @@ -60,6 +60,8 @@ public: wtBeacon = 7, wtAnvil = 8, wtHopper = 9, + // Unknown: 10 + wtAnimalChest = 11, }; // tolua_end @@ -75,8 +77,12 @@ public: cWindowOwner * GetOwner(void) { return m_Owner; } void SetOwner( cWindowOwner * a_Owner ) { m_Owner = a_Owner; } + /// Returns the total number of slots int GetNumSlots(void) const; + /// Returns the number of slots, excluding the player's inventory (used for network protocols) + int GetNumNonInventorySlots(void) const { return GetNumSlots() - c_NumInventorySlots; } + // tolua_begin /// Returns the item at the specified slot for the specified player. Returns NULL if invalid SlotNum requested -- cgit v1.2.3