summaryrefslogtreecommitdiffstats
path: root/src/ClientHandle.cpp
diff options
context:
space:
mode:
authorTycho <work.tycho+git@gmail.com>2014-01-20 18:21:47 +0100
committerTycho <work.tycho+git@gmail.com>2014-01-20 18:21:47 +0100
commit16375f6aad355333d1d3aff6140cdb4439a9b62f (patch)
treeeb4192092b928e90aebaf914288d12c9cafaf5a5 /src/ClientHandle.cpp
parentAdded Inifile and OSSupport Linking (diff)
parentAPIDump: Added notes about objects across cWorld's task execution. (diff)
downloadcuberite-16375f6aad355333d1d3aff6140cdb4439a9b62f.tar
cuberite-16375f6aad355333d1d3aff6140cdb4439a9b62f.tar.gz
cuberite-16375f6aad355333d1d3aff6140cdb4439a9b62f.tar.bz2
cuberite-16375f6aad355333d1d3aff6140cdb4439a9b62f.tar.lz
cuberite-16375f6aad355333d1d3aff6140cdb4439a9b62f.tar.xz
cuberite-16375f6aad355333d1d3aff6140cdb4439a9b62f.tar.zst
cuberite-16375f6aad355333d1d3aff6140cdb4439a9b62f.zip
Diffstat (limited to 'src/ClientHandle.cpp')
-rw-r--r--src/ClientHandle.cpp95
1 files changed, 90 insertions, 5 deletions
diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp
index c8513d516..74d192129 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"
@@ -119,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();
@@ -159,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;
@@ -545,6 +542,21 @@ 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, 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;
+ }
+
cPluginManager::Get()->CallHookPluginMessage(*this, a_Channel, a_Message);
}
@@ -552,6 +564,71 @@ void cClientHandle::HandlePluginMessage(const AString & a_Channel, const AString
+void cClientHandle::HandleCommandBlockMessage(const char* a_Data, unsigned int a_Length)
+{
+ 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;
+ }
+
+ 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:
+ {
+ 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;
+ }
+ }
+
+ 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);
+
+ SendChat(Printf("%s[INFO]%s Successfully set command block command", cChatColor::Green.c_str(), cChatColor::White.c_str()));
+}
+
+
+
+
+
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",
@@ -2132,6 +2209,14 @@ void cClientHandle::SendUnloadChunk(int a_ChunkX, int a_ChunkZ)
+void cClientHandle::SendUpdateBlockEntity(cBlockEntity & a_BlockEntity)
+{
+ m_Protocol->SendUpdateBlockEntity(a_BlockEntity);
+}
+
+
+
+
void cClientHandle::SendUpdateSign(
int a_BlockX, int a_BlockY, int a_BlockZ,