From dc49092ae5439c1fcc711fbfc2784a8de6b70840 Mon Sep 17 00:00:00 2001 From: Lane Kolbly Date: Wed, 2 Aug 2017 09:46:29 -0500 Subject: Handle Teleport Confirmation Packet (#3884) + Added code to drop incoming client position packets until the most recent teleport was confirmed. --- src/Protocol/Protocol_1_9.cpp | 26 ++++++++++++++++++++++---- src/Protocol/Protocol_1_9.h | 4 ++++ 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/Protocol/Protocol_1_9.cpp b/src/Protocol/Protocol_1_9.cpp index 4e888bd64..3e0171b24 100644 --- a/src/Protocol/Protocol_1_9.cpp +++ b/src/Protocol/Protocol_1_9.cpp @@ -118,6 +118,8 @@ cProtocol_1_9_0::cProtocol_1_9_0(cClientHandle * a_Client, const AString & a_Ser m_ServerAddress(a_ServerAddress), m_ServerPort(a_ServerPort), m_State(a_State), + m_IsTeleportIdConfirmed(true), + m_OutstandingTeleportId(0), m_ReceivedData(32 KiB), m_IsEncrypted(false) { @@ -1043,7 +1045,10 @@ void cProtocol_1_9_0::SendPlayerMoveLook(void) Pkt.WriteBEFloat(static_cast(Player->GetYaw())); Pkt.WriteBEFloat(static_cast(Player->GetPitch())); Pkt.WriteBEUInt8(0); - Pkt.WriteVarInt32(0); // Teleport ID - not implemented here + Pkt.WriteVarInt32(++m_OutstandingTeleportId); + + // This teleport ID hasn't been confirmed yet + m_IsTeleportIdConfirmed = false; } @@ -2413,7 +2418,12 @@ void cProtocol_1_9_0::HandlePacketClientStatus(cByteBuffer & a_ByteBuffer) void cProtocol_1_9_0::HandleConfirmTeleport(cByteBuffer & a_ByteBuffer) { HANDLE_READ(a_ByteBuffer, ReadVarInt32, UInt32, TeleportID); - // We don't actually validate that this packet is sent or anything yet, but it still needs to be read. + + // Can we stop throwing away incoming player position packets? + if (TeleportID == m_OutstandingTeleportId) + { + m_IsTeleportIdConfirmed = true; + } } @@ -2517,7 +2527,11 @@ void cProtocol_1_9_0::HandlePacketPlayerPos(cByteBuffer & a_ByteBuffer) HANDLE_READ(a_ByteBuffer, ReadBEDouble, double, PosY); HANDLE_READ(a_ByteBuffer, ReadBEDouble, double, PosZ); HANDLE_READ(a_ByteBuffer, ReadBool, bool, IsOnGround); - m_Client->HandlePlayerPos(PosX, PosY, PosZ, PosY + (m_Client->GetPlayer()->IsCrouched() ? 1.54 : 1.62), IsOnGround); + + if (m_IsTeleportIdConfirmed) + { + m_Client->HandlePlayerPos(PosX, PosY, PosZ, PosY + (m_Client->GetPlayer()->IsCrouched() ? 1.54 : 1.62), IsOnGround); + } } @@ -2532,7 +2546,11 @@ void cProtocol_1_9_0::HandlePacketPlayerPosLook(cByteBuffer & a_ByteBuffer) HANDLE_READ(a_ByteBuffer, ReadBEFloat, float, Yaw); HANDLE_READ(a_ByteBuffer, ReadBEFloat, float, Pitch); HANDLE_READ(a_ByteBuffer, ReadBool, bool, IsOnGround); - m_Client->HandlePlayerMoveLook(PosX, PosY, PosZ, PosY + 1.62, Yaw, Pitch, IsOnGround); + + if (m_IsTeleportIdConfirmed) + { + m_Client->HandlePlayerMoveLook(PosX, PosY, PosZ, PosY + 1.62, Yaw, Pitch, IsOnGround); + } } diff --git a/src/Protocol/Protocol_1_9.h b/src/Protocol/Protocol_1_9.h index d6533c5da..2c83168c2 100644 --- a/src/Protocol/Protocol_1_9.h +++ b/src/Protocol/Protocol_1_9.h @@ -173,6 +173,10 @@ protected: /** State of the protocol. 1 = status, 2 = login, 3 = game */ UInt32 m_State; + /** The current teleport ID, and whether it has been confirmed by the client */ + bool m_IsTeleportIdConfirmed; + UInt32 m_OutstandingTeleportId; + /** Buffer for the received data */ cByteBuffer m_ReceivedData; -- cgit v1.2.3