summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLane Kolbly <lane@rscheme.org>2017-08-02 16:46:29 +0200
committerTiger Wang <ziwei.tiger@outlook.com>2017-08-02 16:46:29 +0200
commitdc49092ae5439c1fcc711fbfc2784a8de6b70840 (patch)
tree11d72b9b58b9708fb1d2e316c0ff66c43c8a1828
parentcBlockHandler: take player by ref (diff)
downloadcuberite-dc49092ae5439c1fcc711fbfc2784a8de6b70840.tar
cuberite-dc49092ae5439c1fcc711fbfc2784a8de6b70840.tar.gz
cuberite-dc49092ae5439c1fcc711fbfc2784a8de6b70840.tar.bz2
cuberite-dc49092ae5439c1fcc711fbfc2784a8de6b70840.tar.lz
cuberite-dc49092ae5439c1fcc711fbfc2784a8de6b70840.tar.xz
cuberite-dc49092ae5439c1fcc711fbfc2784a8de6b70840.tar.zst
cuberite-dc49092ae5439c1fcc711fbfc2784a8de6b70840.zip
-rw-r--r--src/Protocol/Protocol_1_9.cpp26
-rw-r--r--src/Protocol/Protocol_1_9.h4
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<float>(Player->GetYaw()));
Pkt.WriteBEFloat(static_cast<float>(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;