summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@outlook.com>2020-07-19 01:41:29 +0200
committerTiger Wang <ziwei.tiger@outlook.com>2020-07-19 01:43:33 +0200
commitc99ddbc376523bbf9b67c5e5c786f13a4363a533 (patch)
tree13bc3a83ec40eb33a2f031bfccbb8b1cf1a42655
parentAdd 1.13.1 to 1.15.2 mappings (diff)
downloadcuberite-c99ddbc376523bbf9b67c5e5c786f13a4363a533.tar
cuberite-c99ddbc376523bbf9b67c5e5c786f13a4363a533.tar.gz
cuberite-c99ddbc376523bbf9b67c5e5c786f13a4363a533.tar.bz2
cuberite-c99ddbc376523bbf9b67c5e5c786f13a4363a533.tar.lz
cuberite-c99ddbc376523bbf9b67c5e5c786f13a4363a533.tar.xz
cuberite-c99ddbc376523bbf9b67c5e5c786f13a4363a533.tar.zst
cuberite-c99ddbc376523bbf9b67c5e5c786f13a4363a533.zip
Diffstat (limited to '')
-rw-r--r--src/Protocol/Protocol.h4
-rw-r--r--src/Protocol/ProtocolRecognizer.cpp4
-rw-r--r--src/Protocol/Protocol_1_13.cpp144
-rw-r--r--src/Protocol/Protocol_1_13.h46
4 files changed, 185 insertions, 13 deletions
diff --git a/src/Protocol/Protocol.h b/src/Protocol/Protocol.h
index c2b3cd3f0..817d0bef0 100644
--- a/src/Protocol/Protocol.h
+++ b/src/Protocol/Protocol.h
@@ -339,7 +339,9 @@ public:
Version_1_12 = 335,
Version_1_12_1 = 338,
Version_1_12_2 = 340,
- Version_1_13 = 393
+ Version_1_13 = 393,
+ Version_1_13_1 = 401,
+ Version_1_13_2 = 404 // TODO: this constant should be in WebServer
};
/** Called when client sends some data */
diff --git a/src/Protocol/ProtocolRecognizer.cpp b/src/Protocol/ProtocolRecognizer.cpp
index 46c2d239f..a6aa901c9 100644
--- a/src/Protocol/ProtocolRecognizer.cpp
+++ b/src/Protocol/ProtocolRecognizer.cpp
@@ -74,6 +74,8 @@ AString cMultiVersionProtocol::GetVersionTextFromInt(cProtocol::Version a_Protoc
case cProtocol::Version::Version_1_12_1: return "1.12.1";
case cProtocol::Version::Version_1_12_2: return "1.12.2";
case cProtocol::Version::Version_1_13: return "1.13";
+ case cProtocol::Version::Version_1_13_1: return "1.13.1";
+ case cProtocol::Version::Version_1_13_2: return "1.13.2";
}
ASSERT(!"Unknown protocol version");
return Printf("Unknown protocol (%d)", a_ProtocolVersion);
@@ -295,6 +297,8 @@ std::unique_ptr<cProtocol> cMultiVersionProtocol::TryRecognizeLengthedProtocol(c
case cProtocol::Version::Version_1_12_1: return std::make_unique<cProtocol_1_12_1>(&a_Client, ServerAddress, ServerPort, NextState);
case cProtocol::Version::Version_1_12_2: return std::make_unique<cProtocol_1_12_2>(&a_Client, ServerAddress, ServerPort, NextState);
case cProtocol::Version::Version_1_13: return std::make_unique<cProtocol_1_13>(&a_Client, ServerAddress, ServerPort, NextState);
+ case cProtocol::Version::Version_1_13_1: return std::make_unique<cProtocol_1_13_1>(&a_Client, ServerAddress, ServerPort, NextState);
+ case cProtocol::Version::Version_1_13_2: return std::make_unique<cProtocol_1_13_2>(&a_Client, ServerAddress, ServerPort, NextState);
default:
{
LOGD("Client \"%s\" uses an unsupported protocol (lengthed, version %u (0x%x))",
diff --git a/src/Protocol/Protocol_1_13.cpp b/src/Protocol/Protocol_1_13.cpp
index f26b1900a..b08622fc6 100644
--- a/src/Protocol/Protocol_1_13.cpp
+++ b/src/Protocol/Protocol_1_13.cpp
@@ -33,6 +33,7 @@ Implements the 1.13 protocol classes:
#include "Palettes/Upgrade.h"
#include "Palettes/Palette_1_13.h"
+#include "Palettes/Palette_1_13_1.h"
@@ -68,14 +69,8 @@ Implements the 1.13 protocol classes:
-cProtocol_1_13::cProtocol_1_13(cClientHandle * a_Client, const AString & a_ServerAddress, UInt16 a_ServerPort, UInt32 a_State) :
- Super(a_Client, a_ServerAddress, a_ServerPort, a_State)
-{
-}
-
-
-
-
+////////////////////////////////////////////////////////////////////////////////
+// cProtocol_1_13:
void cProtocol_1_13::SendBlockChange(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
{
@@ -562,6 +557,24 @@ UInt8 cProtocol_1_13::GetEntityMetadataID(eEntityMetadataType a_FieldType)
+std::pair<short, short> cProtocol_1_13::GetItemFromProtocolID(UInt32 a_ProtocolID)
+{
+ return PaletteUpgrade::ToItem(Palette_1_13::ToItem(a_ProtocolID));
+}
+
+
+
+
+
+UInt32 cProtocol_1_13::GetProtocolIDFromItem(short a_ItemID, short a_ItemDamage)
+{
+ return Palette_1_13::FromItem(PaletteUpgrade::FromItem(a_ItemID, a_ItemDamage));
+}
+
+
+
+
+
bool cProtocol_1_13::ReadItem(cByteBuffer & a_ByteBuffer, cItem & a_Item, size_t a_KeepRemainingBytes)
{
HANDLE_PACKET_READ(a_ByteBuffer, ReadBEInt16, Int16, ItemID);
@@ -572,7 +585,7 @@ bool cProtocol_1_13::ReadItem(cByteBuffer & a_ByteBuffer, cItem & a_Item, size_t
return true;
}
- const auto Translated = PaletteUpgrade::ToItem(Palette_1_13::ToItem(ItemID));
+ const auto Translated = GetItemFromProtocolID(ItemID);
a_Item.m_ItemType = Translated.first;
a_Item.m_ItemDamage = Translated.second;
@@ -615,8 +628,7 @@ void cProtocol_1_13::WriteItem(cPacketizer & a_Pkt, const cItem & a_Item)
}
// Normal item
- // TODO: use new item ids
- a_Pkt.WriteBEInt16(Palette_1_13::FromItem(PaletteUpgrade::FromItem(a_Item.m_ItemType, a_Item.m_ItemDamage)));
+ a_Pkt.WriteBEInt16(GetProtocolIDFromItem(a_Item.m_ItemType, a_Item.m_ItemDamage));
a_Pkt.WriteBEInt8(a_Item.m_ItemCount);
// TODO: NBT
@@ -1157,3 +1169,113 @@ void cProtocol_1_13::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_Mo
}
} // switch (a_Mob.GetType())
}
+
+
+
+
+
+////////////////////////////////////////////////////////////////////////////////
+// cProtocol_1_13_1:
+
+cProtocol::Version cProtocol_1_13_1::GetProtocolVersion()
+{
+ return Version::Version_1_13_1;
+}
+
+
+
+
+
+std::pair<short, short> cProtocol_1_13_1::GetItemFromProtocolID(UInt32 a_ProtocolID)
+{
+ return PaletteUpgrade::ToItem(Palette_1_13_1::ToItem(a_ProtocolID));
+}
+
+
+
+
+
+UInt32 cProtocol_1_13_1::GetProtocolIDFromItem(short a_ItemID, short a_ItemDamage)
+{
+ return Palette_1_13_1::FromItem(PaletteUpgrade::FromItem(a_ItemID, a_ItemDamage));
+}
+
+
+
+
+
+////////////////////////////////////////////////////////////////////////////////
+// cProtocol_1_13_2:
+
+cProtocol::Version cProtocol_1_13_2::GetProtocolVersion()
+{
+ return Version::Version_1_13_2;
+}
+
+
+
+
+
+bool cProtocol_1_13_2::ReadItem(cByteBuffer & a_ByteBuffer, cItem & a_Item, size_t a_KeepRemainingBytes)
+{
+ HANDLE_PACKET_READ(a_ByteBuffer, ReadBool, bool, Present);
+ if (!Present)
+ {
+ // The item is empty, no more data follows
+ a_Item.Empty();
+ return true;
+ }
+
+ HANDLE_PACKET_READ(a_ByteBuffer, ReadVarInt32, UInt32, ItemID);
+ const auto Translated = GetItemFromProtocolID(ItemID);
+ a_Item.m_ItemType = Translated.first;
+ a_Item.m_ItemDamage = Translated.second;
+
+ HANDLE_PACKET_READ(a_ByteBuffer, ReadBEInt8, Int8, ItemCount);
+ a_Item.m_ItemCount = ItemCount;
+ if (ItemCount <= 0)
+ {
+ a_Item.Empty();
+ }
+
+ AString Metadata;
+ if (!a_ByteBuffer.ReadString(Metadata, a_ByteBuffer.GetReadableSpace() - a_KeepRemainingBytes - 1) || (Metadata.size() == 0) || (Metadata[0] == 0))
+ {
+ // No metadata
+ return true;
+ }
+
+ ParseItemMetadata(a_Item, Metadata);
+ return true;
+}
+
+
+
+
+
+void cProtocol_1_13_2::WriteItem(cPacketizer & a_Pkt, const cItem & a_Item)
+{
+ short ItemType = a_Item.m_ItemType;
+ ASSERT(ItemType >= -1); // Check validity of packets in debug runtime
+ if (ItemType <= 0)
+ {
+ // Fix, to make sure no invalid values are sent.
+ ItemType = -1;
+ }
+
+ if (a_Item.IsEmpty())
+ {
+ a_Pkt.WriteBool(false);
+ return;
+ }
+
+ // Item present
+ a_Pkt.WriteBool(true);
+
+ // Normal item
+ a_Pkt.WriteVarInt32(GetProtocolIDFromItem(a_Item.m_ItemType, a_Item.m_ItemDamage));
+ a_Pkt.WriteBEInt8(a_Item.m_ItemCount);
+
+ // TODO: NBT
+ a_Pkt.WriteBEInt8(0);
+}
diff --git a/src/Protocol/Protocol_1_13.h b/src/Protocol/Protocol_1_13.h
index b315768ba..62f9cf2e4 100644
--- a/src/Protocol/Protocol_1_13.h
+++ b/src/Protocol/Protocol_1_13.h
@@ -35,7 +35,7 @@ class cProtocol_1_13:
public:
- cProtocol_1_13(cClientHandle * a_Client, const AString & a_ServerAddress, UInt16 a_ServerPort, UInt32 a_State);
+ using Super::cProtocol_1_12_2;
protected:
@@ -67,6 +67,8 @@ protected:
virtual UInt8 GetEntityMetadataID(eEntityMetadata a_Metadata);
virtual UInt8 GetEntityMetadataID(eEntityMetadataType a_FieldType);
+ virtual std::pair<short, short> GetItemFromProtocolID(UInt32 a_ProtocolID);
+ virtual UInt32 GetProtocolIDFromItem(short a_ItemID, short a_ItemDamage);
virtual bool ReadItem(cByteBuffer & a_ByteBuffer, cItem & a_Item, size_t a_KeepRemainingBytes) override;
virtual void WriteItem(cPacketizer & a_Pkt, const cItem & a_Item) override;
@@ -74,3 +76,45 @@ protected:
virtual void WriteEntityMetadata(cPacketizer & a_Pkt, const cEntity & a_Entity) override;
virtual void WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_Mob) override;
};
+
+
+
+
+
+class cProtocol_1_13_1 :
+ public cProtocol_1_13
+{
+ using Super = cProtocol_1_13;
+
+public:
+
+ using Super::cProtocol_1_13;
+
+protected:
+
+ /** Returns 1.13.1 */
+ virtual Version GetProtocolVersion() override;
+ virtual std::pair<short, short> GetItemFromProtocolID(UInt32 a_ProtocolID) override;
+ virtual UInt32 GetProtocolIDFromItem(short a_ItemID, short a_ItemDamage) override;
+};
+
+
+
+
+
+class cProtocol_1_13_2 :
+ public cProtocol_1_13_1
+{
+ using Super = cProtocol_1_13_1;
+
+public:
+
+ using Super::Super;
+
+protected:
+
+ /** Returns 1.13.2 */
+ virtual Version GetProtocolVersion() override;
+ virtual bool ReadItem(cByteBuffer & a_ByteBuffer, cItem & a_Item, size_t a_KeepRemainingBytes) override;
+ virtual void WriteItem(cPacketizer & a_Pkt, const cItem & a_Item) override;
+};