summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHowaner <franzi.moos@googlemail.com>2014-09-08 11:35:21 +0200
committerHowaner <franzi.moos@googlemail.com>2014-09-08 11:35:21 +0200
commit10a30a03e38116fe084138662bd59147331dd883 (patch)
tree0f992fcb2d4e32a0eebc7fe196388af8b9262cfa
parentImplemented packet compression. (diff)
downloadcuberite-10a30a03e38116fe084138662bd59147331dd883.tar
cuberite-10a30a03e38116fe084138662bd59147331dd883.tar.gz
cuberite-10a30a03e38116fe084138662bd59147331dd883.tar.bz2
cuberite-10a30a03e38116fe084138662bd59147331dd883.tar.lz
cuberite-10a30a03e38116fe084138662bd59147331dd883.tar.xz
cuberite-10a30a03e38116fe084138662bd59147331dd883.tar.zst
cuberite-10a30a03e38116fe084138662bd59147331dd883.zip
-rw-r--r--src/Protocol/Protocol.h7
-rw-r--r--src/Protocol/Protocol125.cpp3
-rw-r--r--src/Protocol/Protocol132.cpp2
-rw-r--r--src/Protocol/Protocol14x.cpp9
-rw-r--r--src/Protocol/Protocol17x.cpp26
-rw-r--r--src/Protocol/Protocol17x.h1
-rw-r--r--src/Protocol/Protocol18x.cpp3
-rw-r--r--src/Protocol/ProtocolRecognizer.cpp4
8 files changed, 29 insertions, 26 deletions
diff --git a/src/Protocol/Protocol.h b/src/Protocol/Protocol.h
index 8e1842ec1..5811e5bff 100644
--- a/src/Protocol/Protocol.h
+++ b/src/Protocol/Protocol.h
@@ -46,7 +46,8 @@ typedef unsigned char Byte;
class cProtocol
{
public:
- cProtocol(cClientHandle * a_Client) :
+ cProtocol(cClientHandle * a_Client, int a_ProtocolVersion) :
+ m_ProtocolVersion(a_ProtocolVersion),
m_Client(a_Client)
{
}
@@ -130,7 +131,11 @@ public:
/// Returns the ServerID used for authentication through session.minecraft.net
virtual AString GetAuthServerID(void) = 0;
+ /** Returns the protocol version of this protocol. */
+ int GetProtocolVersion(void) const { return m_ProtocolVersion; }
+
protected:
+ int m_ProtocolVersion;
cClientHandle * m_Client;
cCriticalSection m_CSPacket; // Each SendXYZ() function must acquire this CS in order to send the whole packet at once
diff --git a/src/Protocol/Protocol125.cpp b/src/Protocol/Protocol125.cpp
index a74be28a5..77939d933 100644
--- a/src/Protocol/Protocol125.cpp
+++ b/src/Protocol/Protocol125.cpp
@@ -16,6 +16,7 @@ Documentation:
#include "../ClientHandle.h"
#include "../World.h"
#include "ChunkDataSerializer.h"
+#include "ProtocolRecognizer.h"
#include "../Entities/Entity.h"
#include "../Entities/ExpOrb.h"
#include "../Mobs/Monster.h"
@@ -132,7 +133,7 @@ typedef unsigned char Byte;
cProtocol125::cProtocol125(cClientHandle * a_Client) :
- super(a_Client),
+ super(a_Client, cProtocolRecognizer::PROTO_VERSION_1_2_5),
m_ReceivedData(32 KiB),
m_LastSentDimension(dimNotSet)
{
diff --git a/src/Protocol/Protocol132.cpp b/src/Protocol/Protocol132.cpp
index 5fd2655b8..6fbc3a264 100644
--- a/src/Protocol/Protocol132.cpp
+++ b/src/Protocol/Protocol132.cpp
@@ -5,6 +5,7 @@
#include "Globals.h"
#include "ChunkDataSerializer.h"
+#include "ProtocolRecognizer.h"
#include "Protocol132.h"
#include "../Root.h"
#include "../Server.h"
@@ -78,6 +79,7 @@ cProtocol132::cProtocol132(cClientHandle * a_Client) :
super(a_Client),
m_IsEncrypted(false)
{
+ m_ProtocolVersion = cProtocolRecognizer::PROTO_VERSION_1_3_2;
}
diff --git a/src/Protocol/Protocol14x.cpp b/src/Protocol/Protocol14x.cpp
index 3b6b6a42a..2d737acb4 100644
--- a/src/Protocol/Protocol14x.cpp
+++ b/src/Protocol/Protocol14x.cpp
@@ -23,6 +23,7 @@ Implements the 1.4.x protocol classes representing these protocols:
#include "../UI/Window.h"
#include "../Entities/Pickup.h"
#include "../Entities/FallingBlock.h"
+#include "ProtocolRecognizer.h"
#ifdef _MSC_VER
#pragma warning(push)
@@ -72,6 +73,7 @@ enum
cProtocol142::cProtocol142(cClientHandle * a_Client) :
super(a_Client)
{
+ m_ProtocolVersion = cProtocolRecognizer::PROTO_VERSION_1_4_2;
}
@@ -132,12 +134,6 @@ void cProtocol142::SendSoundParticleEffect(int a_EffectID, int a_SrcX, int a_Src
void cProtocol142::SendTimeUpdate(Int64 a_WorldAge, Int64 a_TimeOfDay, bool a_DoDaylightCycle)
{
- if (!a_DoDaylightCycle)
- {
- // When writing a "-" before the number the client ignores it but it will stop the client-side time expiration.
- a_TimeOfDay = std::min(-a_TimeOfDay, -1LL);
- }
-
cCSLock Lock(m_CSPacket);
WriteByte (PACKET_UPDATE_TIME);
WriteInt64(a_WorldAge);
@@ -156,6 +152,7 @@ void cProtocol142::SendTimeUpdate(Int64 a_WorldAge, Int64 a_TimeOfDay, bool a_Do
cProtocol146::cProtocol146(cClientHandle * a_Client) :
super(a_Client)
{
+ m_ProtocolVersion = cProtocolRecognizer::PROTO_VERSION_1_4_6;
}
diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp
index 0bee40028..e34a61818 100644
--- a/src/Protocol/Protocol17x.cpp
+++ b/src/Protocol/Protocol17x.cpp
@@ -12,6 +12,7 @@ Implements the 1.7.x protocol classes:
#include "Globals.h"
#include "json/json.h"
#include "Protocol17x.h"
+#include "ProtocolRecognizer.h"
#include "ChunkDataSerializer.h"
#include "PolarSSL++/Sha1Checksum.h"
@@ -92,7 +93,7 @@ extern bool g_ShouldLogCommIn, g_ShouldLogCommOut;
// cProtocol172:
cProtocol172::cProtocol172(cClientHandle * a_Client, const AString & a_ServerAddress, UInt16 a_ServerPort, UInt32 a_State) :
- super(a_Client),
+ super(a_Client, cProtocolRecognizer::PROTO_VERSION_1_7_2),
m_ServerAddress(a_ServerAddress),
m_ServerPort(a_ServerPort),
m_State(a_State),
@@ -1534,7 +1535,7 @@ void cProtocol172::AddReceivedData(const char * a_Data, size_t a_Size)
bb.Write("\0", 1);
// 1.8 - Compressed packets
- if (m_State == 3)
+ if ((m_State == 3) && (GetProtocolVersion() == cProtocolRecognizer::PROTO_VERSION_1_8_0))
{
UInt32 CompressedSize;
if (!bb.ReadVarInt(CompressedSize))
@@ -2522,23 +2523,19 @@ cProtocol172::cPacketizer::~cPacketizer()
// Send the packet length
UInt32 PacketLen = (UInt32)m_Out.GetUsedSpace();
- if (m_Protocol.m_State == 3)
+
+ if ((m_Protocol.m_State == 3) && (m_Protocol.GetProtocolVersion() == cProtocolRecognizer::PROTO_VERSION_1_8_0))
{
- PacketLen += 1;
+ m_Protocol.m_OutPacketLenBuffer.WriteVarInt(PacketLen + 1);
+ m_Protocol.m_OutPacketLenBuffer.WriteVarInt(0);
+ }
+ else
+ {
+ m_Protocol.m_OutPacketLenBuffer.WriteVarInt(PacketLen);
}
-
- m_Protocol.m_OutPacketLenBuffer.WriteVarInt(PacketLen);
m_Protocol.m_OutPacketLenBuffer.ReadAll(DataToSend);
m_Protocol.SendData(DataToSend.data(), DataToSend.size());
m_Protocol.m_OutPacketLenBuffer.CommitRead();
-
- if (m_Protocol.m_State == 3)
- {
- m_Protocol.m_OutPacketLenBuffer.WriteVarInt(0);
- m_Protocol.m_OutPacketLenBuffer.ReadAll(DataToSend);
- m_Protocol.SendData(DataToSend.data(), DataToSend.size());
- m_Protocol.m_OutPacketLenBuffer.CommitRead();
- }
// Send the packet data:
m_Out.ReadAll(DataToSend);
@@ -3080,6 +3077,7 @@ void cProtocol172::cPacketizer::WriteEntityProperties(const cEntity & a_Entity)
cProtocol176::cProtocol176(cClientHandle * a_Client, const AString &a_ServerAddress, UInt16 a_ServerPort, UInt32 a_State) :
super(a_Client, a_ServerAddress, a_ServerPort, a_State)
{
+ m_ProtocolVersion = cProtocolRecognizer::PROTO_VERSION_1_7_6;
}
diff --git a/src/Protocol/Protocol17x.h b/src/Protocol/Protocol17x.h
index d715e1cec..289545bc7 100644
--- a/src/Protocol/Protocol17x.h
+++ b/src/Protocol/Protocol17x.h
@@ -211,7 +211,6 @@ protected:
}
void WriteItem(const cItem & a_Item);
- void WriteItem180(const cItem & a_Item);
void WriteByteAngle(double a_Angle); // Writes the specified angle using a single byte
void WriteFPInt(double a_Value); // Writes the double value as a 27:5 fixed-point integer
void WriteEntityMetadata(const cEntity & a_Entity); // Writes the metadata for the specified entity, not including the terminating 0x7f
diff --git a/src/Protocol/Protocol18x.cpp b/src/Protocol/Protocol18x.cpp
index bcb5c2036..302fcc836 100644
--- a/src/Protocol/Protocol18x.cpp
+++ b/src/Protocol/Protocol18x.cpp
@@ -12,8 +12,8 @@ Implements the 1.8.x protocol classes:
#include "Bindings/PluginManager.h"
#include "json/json.h"
#include "ChunkDataSerializer.h"
+#include "ProtocolRecognizer.h"
#include "Protocol18x.h"
-#include "zlib/zlib.h"
#include "../ClientHandle.h"
#include "../CompositeChat.h"
@@ -52,6 +52,7 @@ class cProtocol176;
cProtocol180::cProtocol180(cClientHandle * a_Client, const AString & a_ServerAddress, UInt16 a_ServerPort, UInt32 a_State) :
super(a_Client, a_ServerAddress, a_ServerPort, a_State)
{
+ m_ProtocolVersion = cProtocolRecognizer::PROTO_VERSION_1_8_0;
}
diff --git a/src/Protocol/ProtocolRecognizer.cpp b/src/Protocol/ProtocolRecognizer.cpp
index 642e96880..c535390cc 100644
--- a/src/Protocol/ProtocolRecognizer.cpp
+++ b/src/Protocol/ProtocolRecognizer.cpp
@@ -26,7 +26,7 @@
cProtocolRecognizer::cProtocolRecognizer(cClientHandle * a_Client) :
- super(a_Client),
+ super(a_Client, 0),
m_Protocol(NULL),
m_Buffer(512)
{
@@ -915,7 +915,7 @@ bool cProtocolRecognizer::TryRecognizeLengthlessProtocol(void)
m_Protocol = new cProtocol132(m_Client);
return true;
}
- case PROTO_VERSION_1_4_2:
+ //case PROTO_VERSION_1_4_2:
case PROTO_VERSION_1_4_4:
{
m_Protocol = new cProtocol142(m_Client);