From 02c9aa2b1e86974df4ef8ea152465719169bdac5 Mon Sep 17 00:00:00 2001 From: andrew Date: Sat, 18 Jan 2014 19:58:46 +0200 Subject: Parse the MC|AdvCdm plugin message --- src/ClientHandle.cpp | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) (limited to 'src/ClientHandle.cpp') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index c8513d516..0a97ba6c8 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -8,6 +8,7 @@ #include "Entities/Player.h" #include "Inventory.h" #include "BlockEntities/ChestEntity.h" +#include "BlockEntities/CommandBlockEntity.h" #include "BlockEntities/SignEntity.h" #include "UI/Window.h" #include "Item.h" @@ -545,6 +546,15 @@ void cClientHandle::HandlePlayerPos(double a_PosX, double a_PosY, double a_PosZ, void cClientHandle::HandlePluginMessage(const AString & a_Channel, const AString & a_Message) { + if (a_Channel == "MC|AdvCdm") // Command block + { + const char* Data = a_Message.c_str(); + + HandleCommandBlockMessage(Data, a_Message.size()); + + return; + } + cPluginManager::Get()->CallHookPluginMessage(*this, a_Channel, a_Message); } @@ -552,6 +562,60 @@ void cClientHandle::HandlePluginMessage(const AString & a_Channel, const AString +void cClientHandle::HandleCommandBlockMessage(const char* a_Data, unsigned int a_Length) +{ + if (a_Length < 14) + { + LOGD("Malformed MC|AdvCdm packet."); + return; + } + + int BlockX, BlockY, BlockZ; + + AString Command; + + switch (a_Data[0]) + { + case 0x00: + { + BlockX = GetBEInt(a_Data + 1); + BlockY = GetBEInt(a_Data + 5); + BlockZ = GetBEInt(a_Data + 9); + + Command = AString(a_Data + 14, (int)a_Data[13]); + break; + } + + default: + { + LOGD("Unhandled MC|AdvCdm packet mode."); + return; + } + } + + class cUpdateCommandBlock : + public cCommandBlockCallback + { + AString m_Command; + public: + cUpdateCommandBlock(const AString & a_Command) : m_Command(a_Command) {} + + virtual bool Item(cCommandBlockEntity * a_CommandBlock) override + { + a_CommandBlock->SetCommand(m_Command); + return false; + } + } CmdBlockCB (Command); + + cWorld * World = m_Player->GetWorld(); + + World->DoWithCommandBlockAt(BlockX, BlockY, BlockZ, CmdBlockCB); +} + + + + + void cClientHandle::HandleLeftClick(int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, char a_Status) { LOGD("HandleLeftClick: {%i, %i, %i}; Face: %i; Stat: %i", -- cgit v1.2.3 From a037172465932de7d0d7d725c3c8ec5b2fa44029 Mon Sep 17 00:00:00 2001 From: andrew Date: Sat, 18 Jan 2014 21:27:54 +0200 Subject: Command block fixes --- src/ClientHandle.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'src/ClientHandle.cpp') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 0a97ba6c8..faf583fbb 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -570,19 +570,26 @@ void cClientHandle::HandleCommandBlockMessage(const char* a_Data, unsigned int a return; } + cByteBuffer Buffer(a_Length); + Buffer.Write(a_Data, a_Length); + int BlockX, BlockY, BlockZ; AString Command; - switch (a_Data[0]) + char Mode; + + Buffer.ReadChar(Mode); + + switch (Mode) { case 0x00: { - BlockX = GetBEInt(a_Data + 1); - BlockY = GetBEInt(a_Data + 5); - BlockZ = GetBEInt(a_Data + 9); + Buffer.ReadBEInt(BlockX); + Buffer.ReadBEInt(BlockY); + Buffer.ReadBEInt(BlockZ); - Command = AString(a_Data + 14, (int)a_Data[13]); + Buffer.ReadVarUTF8String(Command); break; } -- cgit v1.2.3 From f8c8dcc7f36366dc6b59e6741d466e739322d5d1 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 19 Jan 2014 00:54:38 +0000 Subject: Improved command blocks * Their command and previous output are displayed on the client * They have a BlockHandler implementation, so you can't place blocks on them anymore + As a side effect, implemented UpdateBlockEntity --- src/ClientHandle.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/ClientHandle.cpp') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index faf583fbb..93dc78642 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -20,6 +20,7 @@ #include "Items/ItemHandler.h" #include "Blocks/BlockHandler.h" #include "Blocks/BlockSlab.h" +#include "WorldStorage/FastNBT.h" #include "Vector3f.h" #include "Vector3d.h" @@ -2203,6 +2204,14 @@ void cClientHandle::SendUnloadChunk(int a_ChunkX, int a_ChunkZ) +void cClientHandle::SendUpdateBlockEntity(int a_BlockX, int a_BlockY, int a_BlockZ, Byte a_Action, cFastNBTWriter & a_NBT) +{ + m_Protocol->SendUpdateBlockEntity(a_BlockX, a_BlockY, a_BlockZ, a_Action, a_NBT); +} + + + + void cClientHandle::SendUpdateSign( int a_BlockX, int a_BlockY, int a_BlockZ, -- cgit v1.2.3 From a85b2897e0e9563be69ed2fde944573459103d56 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 19 Jan 2014 01:06:19 +0000 Subject: Implemented MC|Brand response --- src/ClientHandle.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src/ClientHandle.cpp') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 93dc78642..8f95212e1 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -547,12 +547,18 @@ void cClientHandle::HandlePlayerPos(double a_PosX, double a_PosY, double a_PosZ, void cClientHandle::HandlePluginMessage(const AString & a_Channel, const AString & a_Message) { - if (a_Channel == "MC|AdvCdm") // Command block + if (a_Channel == "MC|AdvCdm") // Command block, set text, Client -> Server { const char* Data = a_Message.c_str(); - HandleCommandBlockMessage(Data, a_Message.size()); - + return; + } + else if (a_Channel == "MC|Brand") // Client <-> Server branding exchange + { + // We are custom, + // We are awesome, + // We are MCServer. + SendPluginMessage("MC|Brand", "MCServer"); return; } -- cgit v1.2.3 From 1af89a8b50a382ef0f5c137a84ab2816c45cc73c Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 19 Jan 2014 13:25:35 +0000 Subject: Changed SendBlockEntity format slightly * Writing NBT is now in Protocol, not BlockEntity files * Fixed a last output bug --- src/ClientHandle.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/ClientHandle.cpp') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 8f95212e1..327fc0358 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -20,7 +20,6 @@ #include "Items/ItemHandler.h" #include "Blocks/BlockHandler.h" #include "Blocks/BlockSlab.h" -#include "WorldStorage/FastNBT.h" #include "Vector3f.h" #include "Vector3d.h" @@ -573,6 +572,7 @@ void cClientHandle::HandleCommandBlockMessage(const char* a_Data, unsigned int a { if (a_Length < 14) { + SendChat(Printf("%s[INFO]%s Failure setting command block command; bad request", cChatColor::Red.c_str(), cChatColor::White.c_str())); LOGD("Malformed MC|AdvCdm packet."); return; } @@ -602,6 +602,7 @@ void cClientHandle::HandleCommandBlockMessage(const char* a_Data, unsigned int a default: { + SendChat(Printf("%s[INFO]%s Failure setting command block command; unhandled mode", cChatColor::Red.c_str(), cChatColor::White.c_str())); LOGD("Unhandled MC|AdvCdm packet mode."); return; } @@ -624,6 +625,8 @@ void cClientHandle::HandleCommandBlockMessage(const char* a_Data, unsigned int a cWorld * World = m_Player->GetWorld(); World->DoWithCommandBlockAt(BlockX, BlockY, BlockZ, CmdBlockCB); + + SendChat(Printf("%s[INFO]%s Successfully set command block command", cChatColor::Green.c_str(), cChatColor::White.c_str())); } @@ -2210,9 +2213,9 @@ void cClientHandle::SendUnloadChunk(int a_ChunkX, int a_ChunkZ) -void cClientHandle::SendUpdateBlockEntity(int a_BlockX, int a_BlockY, int a_BlockZ, Byte a_Action, cFastNBTWriter & a_NBT) +void cClientHandle::SendUpdateBlockEntity(int a_BlockX, int a_BlockY, int a_BlockZ, Byte a_Action, cBlockEntity & a_BlockEntity) { - m_Protocol->SendUpdateBlockEntity(a_BlockX, a_BlockY, a_BlockZ, a_Action, a_NBT); + m_Protocol->SendUpdateBlockEntity(a_BlockX, a_BlockY, a_BlockZ, a_Action, a_BlockEntity); } -- cgit v1.2.3 From 3c0e8c8da0e397f3fda6b1565e7b2e9eeb4a747b Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 19 Jan 2014 19:31:43 +0100 Subject: Rewritten SocketThreads for proper shutdown scenario. This fixes #560 and #390. --- src/ClientHandle.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'src/ClientHandle.cpp') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index faf583fbb..1eec00bc3 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -120,9 +120,6 @@ cClientHandle::~cClientHandle() LOGD("Deleting client \"%s\" at %p", GetUsername().c_str(), this); - // Remove from cSocketThreads, we're not to be called anymore: - cRoot::Get()->GetServer()->ClientDestroying(this); - { cCSLock Lock(m_CSChunkLists); m_LoadedChunks.clear(); @@ -160,8 +157,7 @@ cClientHandle::~cClientHandle() cRoot::Get()->GetServer()->WriteToClient(this, Data); } - // Queue the socket to close as soon as it sends all outgoing data: - cRoot::Get()->GetServer()->QueueClientClose(this); + // Close the socket as soon as it sends all outgoing data: cRoot::Get()->GetServer()->RemoveClient(this); delete m_Protocol; -- cgit v1.2.3 From e4c3d799ffddb93c658062f9663ec027fc2f1d5a Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 19 Jan 2014 19:42:25 +0000 Subject: Removed unneeded paramters --- src/ClientHandle.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/ClientHandle.cpp') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 327fc0358..ec71f8fe8 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -2213,9 +2213,9 @@ void cClientHandle::SendUnloadChunk(int a_ChunkX, int a_ChunkZ) -void cClientHandle::SendUpdateBlockEntity(int a_BlockX, int a_BlockY, int a_BlockZ, Byte a_Action, cBlockEntity & a_BlockEntity) +void cClientHandle::SendUpdateBlockEntity(cBlockEntity & a_BlockEntity) { - m_Protocol->SendUpdateBlockEntity(a_BlockX, a_BlockY, a_BlockZ, a_Action, a_BlockEntity); + m_Protocol->SendUpdateBlockEntity(a_BlockEntity); } -- cgit v1.2.3