summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2013-04-04 13:47:31 +0200
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2013-04-04 13:47:31 +0200
commit4aed49a70fe2e4fa3600b31525766c52bff52e3d (patch)
treed17c4a960f4fea8c4020c0b5b6eba1d951fe25da
parentFixed CreateHexDump() filling the string with garbage (diff)
downloadcuberite-4aed49a70fe2e4fa3600b31525766c52bff52e3d.tar
cuberite-4aed49a70fe2e4fa3600b31525766c52bff52e3d.tar.gz
cuberite-4aed49a70fe2e4fa3600b31525766c52bff52e3d.tar.bz2
cuberite-4aed49a70fe2e4fa3600b31525766c52bff52e3d.tar.lz
cuberite-4aed49a70fe2e4fa3600b31525766c52bff52e3d.tar.xz
cuberite-4aed49a70fe2e4fa3600b31525766c52bff52e3d.tar.zst
cuberite-4aed49a70fe2e4fa3600b31525766c52bff52e3d.zip
-rw-r--r--source/ClientHandle.cpp8
-rw-r--r--source/ClientHandle.h2
-rw-r--r--source/Player.cpp19
-rw-r--r--source/Protocol/Protocol.h2
-rw-r--r--source/Protocol/Protocol125.cpp10
-rw-r--r--source/Protocol/Protocol125.h2
-rw-r--r--source/Protocol/ProtocolRecognizer.cpp4
-rw-r--r--source/Protocol/ProtocolRecognizer.h2
-rw-r--r--source/UI/Window.cpp7
-rw-r--r--source/UI/Window.h2
10 files changed, 22 insertions, 36 deletions
diff --git a/source/ClientHandle.cpp b/source/ClientHandle.cpp
index e6cc146c1..c1b696630 100644
--- a/source/ClientHandle.cpp
+++ b/source/ClientHandle.cpp
@@ -1359,18 +1359,18 @@ void cClientHandle::SendEntityEquipment(const cEntity & a_Entity, short a_SlotNu
-void cClientHandle::SendWindowOpen(char a_WindowID, char a_WindowType, const AString & a_WindowTitle, char a_NumSlots)
+void cClientHandle::SendWindowClose(const cWindow & a_Window)
{
- m_Protocol->SendWindowOpen(a_WindowID, a_WindowType, a_WindowTitle, a_NumSlots);
+ m_Protocol->SendWindowClose(a_Window);
}
-void cClientHandle::SendWindowClose(char a_WindowID)
+void cClientHandle::SendWindowOpen(char a_WindowID, char a_WindowType, const AString & a_WindowTitle, char a_NumSlots)
{
- m_Protocol->SendWindowClose(a_WindowID);
+ m_Protocol->SendWindowOpen(a_WindowID, a_WindowType, a_WindowTitle, a_NumSlots);
}
diff --git a/source/ClientHandle.h b/source/ClientHandle.h
index 0916ff82a..362e2b352 100644
--- a/source/ClientHandle.h
+++ b/source/ClientHandle.h
@@ -125,7 +125,7 @@ public:
void SendWeather (eWeather a_Weather);
void SendWholeInventory (const cInventory & a_Inventory);
void SendWholeInventory (const cWindow & a_Window);
- void SendWindowClose (char a_WindowID);
+ void SendWindowClose (const cWindow & a_Window);
void SendWindowOpen (char a_WindowID, char a_WindowType, const AString & a_WindowTitle, char a_NumSlots);
void SendUseBed (const cEntity & a_Entity, int a_BlockX, int a_BlockY, int a_BlockZ );
diff --git a/source/Player.cpp b/source/Player.cpp
index a96967360..af2e00570 100644
--- a/source/Player.cpp
+++ b/source/Player.cpp
@@ -455,27 +455,8 @@ void cPlayer::OpenWindow( cWindow* a_Window )
void cPlayer::CloseWindow(char a_WindowType)
{
- if (m_CurrentWindow == m_InventoryWindow)
- {
- // The inventory window must not be closed and must not be even sent a close packet
- if (IsDraggingItem()) // But we need to check if player is holding anything
- {
- LOGD("Player holds item in inventory window! Dropping it...");
- TossItem(true, GetDraggingItem().m_ItemCount);
- }
- return;
- }
-
if (m_CurrentWindow != NULL)
{
- // TODO: This code should be in cChestWindow instead
- if ((a_WindowType == 1) && (m_CurrentWindow->GetWindowType() == cWindow::Chest))
- {
- int x, y, z;
- m_CurrentWindow->GetOwner()->GetBlockPos(x, y, z);
- m_World->BroadcastBlockAction(x, y, z, 1, 0, E_BLOCK_CHEST);
- }
-
m_CurrentWindow->ClosedByPlayer(*this);
}
m_CurrentWindow = m_InventoryWindow;
diff --git a/source/Protocol/Protocol.h b/source/Protocol/Protocol.h
index 97c80ce35..4cf041cdf 100644
--- a/source/Protocol/Protocol.h
+++ b/source/Protocol/Protocol.h
@@ -96,7 +96,7 @@ public:
virtual void SendWeather (eWeather a_Weather) = 0;
virtual void SendWholeInventory (const cInventory & a_Inventory) = 0;
virtual void SendWholeInventory (const cWindow & a_Window) = 0;
- virtual void SendWindowClose (char a_WindowID) = 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;
/// Returns the ServerID used for authentication through session.minecraft.net
diff --git a/source/Protocol/Protocol125.cpp b/source/Protocol/Protocol125.cpp
index f09cf7178..8d212a4a2 100644
--- a/source/Protocol/Protocol125.cpp
+++ b/source/Protocol/Protocol125.cpp
@@ -863,11 +863,17 @@ void cProtocol125::SendWholeInventory(const cWindow & a_Window)
-void cProtocol125::SendWindowClose(char a_WindowID)
+void cProtocol125::SendWindowClose(const cWindow & a_Window)
{
+ if (a_Window.GetWindowType() == cWindow::Inventory)
+ {
+ // Do not send inventory-window-close
+ return;
+ }
+
cCSLock Lock(m_CSPacket);
WriteByte(PACKET_WINDOW_CLOSE);
- WriteByte(a_WindowID);
+ WriteByte(a_Window.GetWindowID());
Flush();
}
diff --git a/source/Protocol/Protocol125.h b/source/Protocol/Protocol125.h
index 8b724e036..4191d0793 100644
--- a/source/Protocol/Protocol125.h
+++ b/source/Protocol/Protocol125.h
@@ -73,7 +73,7 @@ public:
virtual void SendWeather (eWeather a_Weather) override;
virtual void SendWholeInventory (const cInventory & a_Inventory) override;
virtual void SendWholeInventory (const cWindow & a_Window) override;
- virtual void SendWindowClose (char a_WindowID) 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 AString GetAuthServerID(void) override;
diff --git a/source/Protocol/ProtocolRecognizer.cpp b/source/Protocol/ProtocolRecognizer.cpp
index 787672286..ad99839e4 100644
--- a/source/Protocol/ProtocolRecognizer.cpp
+++ b/source/Protocol/ProtocolRecognizer.cpp
@@ -556,10 +556,10 @@ void cProtocolRecognizer::SendWholeInventory(const cWindow & a_Window)
-void cProtocolRecognizer::SendWindowClose(char a_WindowID)
+void cProtocolRecognizer::SendWindowClose(const cWindow & a_Window)
{
ASSERT(m_Protocol != NULL);
- m_Protocol->SendWindowClose(a_WindowID);
+ m_Protocol->SendWindowClose(a_Window);
}
diff --git a/source/Protocol/ProtocolRecognizer.h b/source/Protocol/ProtocolRecognizer.h
index 866a84eb0..8218dbcaa 100644
--- a/source/Protocol/ProtocolRecognizer.h
+++ b/source/Protocol/ProtocolRecognizer.h
@@ -100,7 +100,7 @@ public:
virtual void SendWeather (eWeather a_Weather) override;
virtual void SendWholeInventory (const cInventory & a_Inventory) override;
virtual void SendWholeInventory (const cWindow & a_Window) override;
- virtual void SendWindowClose (char a_WindowID) 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 AString GetAuthServerID(void) override;
diff --git a/source/UI/Window.cpp b/source/UI/Window.cpp
index d22255105..12c3e7350 100644
--- a/source/UI/Window.cpp
+++ b/source/UI/Window.cpp
@@ -165,8 +165,6 @@ void cWindow::OpenedByPlayer(cPlayer & a_Player)
void cWindow::ClosedByPlayer(cPlayer & a_Player)
{
- ASSERT(m_WindowType != Inventory); // Inventory windows must not be closed (the client would repeat the close packet, looping forever)
-
// Checks whether the player is still holding an item
if (a_Player.IsDraggingItem())
{
@@ -177,7 +175,7 @@ void cWindow::ClosedByPlayer(cPlayer & a_Player)
cClientHandle * ClientHandle = a_Player.GetClientHandle();
if (ClientHandle != NULL)
{
- ClientHandle->SendWindowClose(m_WindowID);
+ ClientHandle->SendWindowClose(*this);
}
{
@@ -189,7 +187,8 @@ void cWindow::ClosedByPlayer(cPlayer & a_Player)
} // for itr - m_SlotAreas[]
m_OpenedBy.remove(&a_Player);
- if (m_OpenedBy.empty())
+
+ if ((m_WindowType != Inventory) && m_OpenedBy.empty())
{
Destroy();
}
diff --git a/source/UI/Window.h b/source/UI/Window.h
index 1c5fe4084..c119d79ab 100644
--- a/source/UI/Window.h
+++ b/source/UI/Window.h
@@ -62,7 +62,7 @@ public:
char GetWindowID(void) const { return m_WindowID; }
int GetWindowType(void) const { return m_WindowType; }
- cWindowOwner * GetOwner() { return m_Owner; }
+ cWindowOwner * GetOwner(void) { return m_Owner; }
void SetOwner( cWindowOwner * a_Owner ) { m_Owner = a_Owner; }
int GetNumSlots(void) const;