summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@hotmail.co.uk>2014-01-19 14:25:35 +0100
committerTiger Wang <ziwei.tiger@hotmail.co.uk>2014-01-19 14:25:35 +0100
commit1af89a8b50a382ef0f5c137a84ab2816c45cc73c (patch)
tree710e4ef25d4785515a3ca07a94dc4b516dd15286
parentImplemented MC|Brand response (diff)
downloadcuberite-1af89a8b50a382ef0f5c137a84ab2816c45cc73c.tar
cuberite-1af89a8b50a382ef0f5c137a84ab2816c45cc73c.tar.gz
cuberite-1af89a8b50a382ef0f5c137a84ab2816c45cc73c.tar.bz2
cuberite-1af89a8b50a382ef0f5c137a84ab2816c45cc73c.tar.lz
cuberite-1af89a8b50a382ef0f5c137a84ab2816c45cc73c.tar.xz
cuberite-1af89a8b50a382ef0f5c137a84ab2816c45cc73c.tar.zst
cuberite-1af89a8b50a382ef0f5c137a84ab2816c45cc73c.zip
-rw-r--r--src/BlockEntities/CommandBlockEntity.cpp26
-rw-r--r--src/ClientHandle.cpp9
-rw-r--r--src/ClientHandle.h3
-rw-r--r--src/Protocol/Protocol.h3
-rw-r--r--src/Protocol/Protocol125.h2
-rw-r--r--src/Protocol/Protocol17x.cpp43
-rw-r--r--src/Protocol/Protocol17x.h4
-rw-r--r--src/Protocol/ProtocolRecognizer.cpp4
-rw-r--r--src/Protocol/ProtocolRecognizer.h3
9 files changed, 55 insertions, 42 deletions
diff --git a/src/BlockEntities/CommandBlockEntity.cpp b/src/BlockEntities/CommandBlockEntity.cpp
index 6e5c8087e..38737d619 100644
--- a/src/BlockEntities/CommandBlockEntity.cpp
+++ b/src/BlockEntities/CommandBlockEntity.cpp
@@ -58,6 +58,7 @@ void cCommandBlockEntity::SetCommand(const AString & a_Cmd)
void cCommandBlockEntity::SetLastOutput(const AString & a_LastOut)
{
+ m_World->BroadcastBlockEntity(GetPosX(), GetPosY(), GetPosZ());
m_LastOutput = a_LastOut;
}
@@ -141,30 +142,7 @@ bool cCommandBlockEntity::Tick(float a_Dt, cChunk & a_Chunk)
void cCommandBlockEntity::SendTo(cClientHandle & a_Client)
{
- cFastNBTWriter Writer;
- Writer.AddByte("TrackOutput", 1); // Neither I nor the MC wiki has any idea about this
- Writer.AddInt("SuccessCount", GetResult());
- Writer.AddInt("x", GetPosX());
- Writer.AddInt("y", GetPosY());
- Writer.AddInt("z", GetPosZ());
- Writer.AddString("Command", GetCommand().c_str());
- // You can set custom names for windows in Vanilla
- // For a command block, this would be the 'name' prepended to anything it outputs into global chat
- // MCS doesn't have this, so just leave it @ '@'. (geddit?)
- Writer.AddString("CustomName", "@");
- Writer.AddString("id", "Control"); // "Tile Entity ID" - MC wiki; vanilla server always seems to send this though
-
- if (!GetLastOutput().empty())
- {
- AString Output;
- Printf(Output, "{\"text\":\"%s\"}", GetLastOutput().c_str());
-
- Writer.AddString("LastOutput", Output.c_str());
- }
-
- Writer.Finish();
-
- a_Client.SendUpdateBlockEntity(GetPosX(), GetPosY(), GetPosZ(), 2, Writer);
+ a_Client.SendUpdateBlockEntity(GetPosX(), GetPosY(), GetPosZ(), 2, *this);
}
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);
}
diff --git a/src/ClientHandle.h b/src/ClientHandle.h
index 2ac240b17..daa185ca0 100644
--- a/src/ClientHandle.h
+++ b/src/ClientHandle.h
@@ -16,7 +16,6 @@
#include "OSSupport/SocketThreads.h"
#include "ChunkDef.h"
#include "ByteBuffer.h"
-#include "WorldStorage/FastNBT.h"
@@ -137,7 +136,7 @@ public:
void SendThunderbolt (int a_BlockX, int a_BlockY, int a_BlockZ);
void SendTimeUpdate (Int64 a_WorldAge, Int64 a_TimeOfDay);
void SendUnloadChunk (int a_ChunkX, int a_ChunkZ);
- void SendUpdateBlockEntity (int a_BlockX, int a_BlockY, int a_BlockZ, Byte a_Action, cFastNBTWriter & a_NBT);
+ void SendUpdateBlockEntity (int a_BlockX, int a_BlockY, int a_BlockZ, Byte a_Action, cBlockEntity & a_BlockEntity);
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);
diff --git a/src/Protocol/Protocol.h b/src/Protocol/Protocol.h
index 6af0af25d..ac925e382 100644
--- a/src/Protocol/Protocol.h
+++ b/src/Protocol/Protocol.h
@@ -12,7 +12,6 @@
#include "../Defines.h"
#include "../Endianness.h"
-#include "../WorldStorage/FastNBT.h"
@@ -104,7 +103,7 @@ public:
virtual void SendThunderbolt (int a_BlockX, int a_BlockY, int a_BlockZ) = 0;
virtual void SendTimeUpdate (Int64 a_WorldAge, Int64 a_TimeOfDay) = 0;
virtual void SendUnloadChunk (int a_ChunkX, int a_ChunkZ) = 0;
- virtual void SendUpdateBlockEntity (int a_BlockX, int a_BlockY, int a_BlockZ, Byte a_Action, cFastNBTWriter & a_NBT) = 0;
+ virtual void SendUpdateBlockEntity (int a_BlockX, int a_BlockY, int a_BlockZ, Byte a_Action, cBlockEntity & a_BlockEntity) = 0;
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) = 0;
virtual void SendUseBed (const cEntity & a_Entity, int a_BlockX, int a_BlockY, int a_BlockZ ) = 0;
virtual void SendWeather (eWeather a_Weather) = 0;
diff --git a/src/Protocol/Protocol125.h b/src/Protocol/Protocol125.h
index 97b194d76..ec72ddd01 100644
--- a/src/Protocol/Protocol125.h
+++ b/src/Protocol/Protocol125.h
@@ -79,7 +79,7 @@ public:
virtual void SendThunderbolt (int a_BlockX, int a_BlockY, int a_BlockZ) override;
virtual void SendTimeUpdate (Int64 a_WorldAge, Int64 a_TimeOfDay) override;
virtual void SendUnloadChunk (int a_ChunkX, int a_ChunkZ) override;
- virtual void SendUpdateBlockEntity (int a_BlockX, int a_BlockY, int a_BlockZ, Byte a_Action, cFastNBTWriter & a_NBT) override {};
+ virtual void SendUpdateBlockEntity (int a_BlockX, int a_BlockY, int a_BlockZ, Byte a_Action, cBlockEntity & a_BlockEntity) override {};
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;
diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp
index 01a6b0bde..c85641ca8 100644
--- a/src/Protocol/Protocol17x.cpp
+++ b/src/Protocol/Protocol17x.cpp
@@ -24,6 +24,7 @@ Implements the 1.7.x protocol classes:
#include "../Entities/Player.h"
#include "../Mobs/IncludeAllMonsters.h"
#include "../UI/Window.h"
+#include "../BlockEntities/CommandBlockEntity.h"
@@ -892,7 +893,7 @@ void cProtocol172::SendUnloadChunk(int a_ChunkX, int a_ChunkZ)
-void cProtocol172::SendUpdateBlockEntity(int a_BlockX, int a_BlockY, int a_BlockZ, Byte a_Action, cFastNBTWriter & a_NBT)
+void cProtocol172::SendUpdateBlockEntity(int a_BlockX, int a_BlockY, int a_BlockZ, Byte a_Action, cBlockEntity & a_BlockEntity)
{
cPacketizer Pkt(*this, 0x35); // Update tile entity packet
Pkt.WriteInt(a_BlockX);
@@ -900,7 +901,7 @@ void cProtocol172::SendUpdateBlockEntity(int a_BlockX, int a_BlockY, int a_Block
Pkt.WriteInt(a_BlockZ);
Pkt.WriteByte(a_Action);
- Pkt.WriteBlockEntity(a_NBT);
+ Pkt.WriteBlockEntity(a_BlockEntity);
}
@@ -1833,10 +1834,44 @@ void cProtocol172::cPacketizer::WriteItem(const cItem & a_Item)
-void cProtocol172::cPacketizer::WriteBlockEntity(const cFastNBTWriter & a_NBT)
+void cProtocol172::cPacketizer::WriteBlockEntity(const cBlockEntity & a_BlockEntity)
{
+ cFastNBTWriter Writer;
+
+ switch (a_BlockEntity.GetBlockType())
+ {
+ case E_BLOCK_COMMAND_BLOCK:
+ {
+ cCommandBlockEntity & CommandBlockEntity = (cCommandBlockEntity &)a_BlockEntity;
+
+ Writer.AddByte("TrackOutput", 1); // Neither I nor the MC wiki has any idea about this
+ Writer.AddInt("SuccessCount", CommandBlockEntity.GetResult());
+ Writer.AddInt("x", CommandBlockEntity.GetPosX());
+ Writer.AddInt("y", CommandBlockEntity.GetPosY());
+ Writer.AddInt("z", CommandBlockEntity.GetPosZ());
+ Writer.AddString("Command", CommandBlockEntity.GetCommand().c_str());
+ // You can set custom names for windows in Vanilla
+ // For a command block, this would be the 'name' prepended to anything it outputs into global chat
+ // MCS doesn't have this, so just leave it @ '@'. (geddit?)
+ Writer.AddString("CustomName", "@");
+ Writer.AddString("id", "Control"); // "Tile Entity ID" - MC wiki; vanilla server always seems to send this though
+
+ if (!CommandBlockEntity.GetLastOutput().empty())
+ {
+ AString Output;
+ Printf(Output, "{\"text\":\"%s\"}", CommandBlockEntity.GetLastOutput().c_str());
+
+ Writer.AddString("LastOutput", Output.c_str());
+ }
+ break;
+ }
+ default: break;
+ }
+
+ Writer.Finish();
+
AString Compressed;
- CompressStringGZIP(a_NBT.GetResult().data(), a_NBT.GetResult().size(), Compressed);
+ CompressStringGZIP(Writer.GetResult().data(), Writer.GetResult().size(), Compressed);
WriteShort(Compressed.size());
WriteBuf(Compressed.data(), Compressed.size());
}
diff --git a/src/Protocol/Protocol17x.h b/src/Protocol/Protocol17x.h
index 6e04a0ffb..b1d902507 100644
--- a/src/Protocol/Protocol17x.h
+++ b/src/Protocol/Protocol17x.h
@@ -102,7 +102,7 @@ public:
virtual void SendThunderbolt (int a_BlockX, int a_BlockY, int a_BlockZ) override;
virtual void SendTimeUpdate (Int64 a_WorldAge, Int64 a_TimeOfDay) override;
virtual void SendUnloadChunk (int a_ChunkX, int a_ChunkZ) override;
- virtual void SendUpdateBlockEntity (int a_BlockX, int a_BlockY, int a_BlockZ, Byte a_Action, cFastNBTWriter & a_NBT) override;
+ virtual void SendUpdateBlockEntity (int a_BlockX, int a_BlockY, int a_BlockZ, Byte a_Action, cBlockEntity & a_BlockEntity) override;
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;
@@ -190,7 +190,7 @@ protected:
void WriteEntityMetadata(const cEntity & a_Entity); // Writes the metadata for the specified entity, not including the terminating 0x7f
void WriteMobMetadata(const cMonster & a_Mob); // Writes the mob-specific metadata for the specified mob
void WriteEntityProperties(const cEntity & a_Entity); // Writes the entity properties for the specified entity, including the Count field
- void WriteBlockEntity(const cFastNBTWriter & a_NBT);
+ void WriteBlockEntity(const cBlockEntity & a_BlockEntity);
protected:
cProtocol172 & m_Protocol;
diff --git a/src/Protocol/ProtocolRecognizer.cpp b/src/Protocol/ProtocolRecognizer.cpp
index 579469fb4..86f46f02f 100644
--- a/src/Protocol/ProtocolRecognizer.cpp
+++ b/src/Protocol/ProtocolRecognizer.cpp
@@ -636,10 +636,10 @@ void cProtocolRecognizer::SendUnloadChunk(int a_ChunkX, int a_ChunkZ)
-void cProtocolRecognizer::SendUpdateBlockEntity(int a_BlockX, int a_BlockY, int a_BlockZ, Byte a_Action, cFastNBTWriter & a_NBT)
+void cProtocolRecognizer::SendUpdateBlockEntity(int a_BlockX, int a_BlockY, int a_BlockZ, Byte a_Action, cBlockEntity & a_BlockEntity)
{
ASSERT(m_Protocol != NULL);
- 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);
}
diff --git a/src/Protocol/ProtocolRecognizer.h b/src/Protocol/ProtocolRecognizer.h
index 410ba556e..c1c8abdd5 100644
--- a/src/Protocol/ProtocolRecognizer.h
+++ b/src/Protocol/ProtocolRecognizer.h
@@ -12,7 +12,6 @@
#include "Protocol.h"
#include "../ByteBuffer.h"
-#include "../WorldStorage/FastNBT.h"
@@ -115,7 +114,7 @@ public:
virtual void SendThunderbolt (int a_BlockX, int a_BlockY, int a_BlockZ) override;
virtual void SendTimeUpdate (Int64 a_WorldAge, Int64 a_TimeOfDay) override;
virtual void SendUnloadChunk (int a_ChunkX, int a_ChunkZ) override;
- virtual void SendUpdateBlockEntity (int a_BlockX, int a_BlockY, int a_BlockZ, Byte a_Action, cFastNBTWriter & a_NBT) override;
+ virtual void SendUpdateBlockEntity (int a_BlockX, int a_BlockY, int a_BlockZ, Byte a_Action, cBlockEntity & a_BlockEntity) override;
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;