1
0
Fork 0

Added GetProtocolVersion() to cProtocol.

This commit is contained in:
Howaner 2014-09-08 11:35:21 +02:00
parent 09ff17b71e
commit 10a30a03e3
8 changed files with 30 additions and 27 deletions

View File

@ -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

View File

@ -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)
{

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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)
{
PacketLen += 1;
}
m_Protocol.m_OutPacketLenBuffer.WriteVarInt(PacketLen);
if ((m_Protocol.m_State == 3) && (m_Protocol.GetProtocolVersion() == cProtocolRecognizer::PROTO_VERSION_1_8_0))
{
m_Protocol.m_OutPacketLenBuffer.WriteVarInt(PacketLen + 1);
m_Protocol.m_OutPacketLenBuffer.WriteVarInt(0);
}
else
{
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;
}

View File

@ -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

View File

@ -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;
}

View File

@ -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);