summaryrefslogtreecommitdiffstats
path: root/src/ClientHandle.cpp
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2014-01-18 20:39:42 +0100
committerMattes D <github@xoft.cz>2014-01-18 20:39:42 +0100
commit36b9d4281978970e78af07a8a627213a974d2a7b (patch)
tree0db776a618aa6d195c5cec24acb8da3174896e68 /src/ClientHandle.cpp
parentHTTP connections aren't kept alive unless explicitly enabled. (diff)
parentCommand block fixes (diff)
downloadcuberite-36b9d4281978970e78af07a8a627213a974d2a7b.tar
cuberite-36b9d4281978970e78af07a8a627213a974d2a7b.tar.gz
cuberite-36b9d4281978970e78af07a8a627213a974d2a7b.tar.bz2
cuberite-36b9d4281978970e78af07a8a627213a974d2a7b.tar.lz
cuberite-36b9d4281978970e78af07a8a627213a974d2a7b.tar.xz
cuberite-36b9d4281978970e78af07a8a627213a974d2a7b.tar.zst
cuberite-36b9d4281978970e78af07a8a627213a974d2a7b.zip
Diffstat (limited to '')
-rw-r--r--src/ClientHandle.cpp71
1 files changed, 71 insertions, 0 deletions
diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp
index c8513d516..faf583fbb 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,67 @@ 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;
+ }
+
+ cByteBuffer Buffer(a_Length);
+ Buffer.Write(a_Data, a_Length);
+
+ int BlockX, BlockY, BlockZ;
+
+ AString Command;
+
+ char Mode;
+
+ Buffer.ReadChar(Mode);
+
+ switch (Mode)
+ {
+ case 0x00:
+ {
+ Buffer.ReadBEInt(BlockX);
+ Buffer.ReadBEInt(BlockY);
+ Buffer.ReadBEInt(BlockZ);
+
+ Buffer.ReadVarUTF8String(Command);
+ 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",