diff options
author | Mattes D <github@xoft.cz> | 2017-06-16 14:03:13 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-16 14:03:13 +0200 |
commit | e4b60b6a26505a7ee35d009e3fd540a5facc87d2 (patch) | |
tree | 7e83f09d71f0bcd912f49f4a7c7a53ca705b0907 /src | |
parent | Remove sign conversion (diff) | |
download | cuberite-e4b60b6a26505a7ee35d009e3fd540a5facc87d2.tar cuberite-e4b60b6a26505a7ee35d009e3fd540a5facc87d2.tar.gz cuberite-e4b60b6a26505a7ee35d009e3fd540a5facc87d2.tar.bz2 cuberite-e4b60b6a26505a7ee35d009e3fd540a5facc87d2.tar.lz cuberite-e4b60b6a26505a7ee35d009e3fd540a5facc87d2.tar.xz cuberite-e4b60b6a26505a7ee35d009e3fd540a5facc87d2.tar.zst cuberite-e4b60b6a26505a7ee35d009e3fd540a5facc87d2.zip |
Diffstat (limited to '')
-rw-r--r-- | src/Protocol/ProtocolRecognizer.cpp | 73 |
1 files changed, 38 insertions, 35 deletions
diff --git a/src/Protocol/ProtocolRecognizer.cpp b/src/Protocol/ProtocolRecognizer.cpp index 4487cdf6b..812d81721 100644 --- a/src/Protocol/ProtocolRecognizer.cpp +++ b/src/Protocol/ProtocolRecognizer.cpp @@ -70,56 +70,59 @@ AString cProtocolRecognizer::GetVersionTextFromInt(int a_ProtocolVersion) void cProtocolRecognizer::DataReceived(const char * a_Data, size_t a_Size) { - if (m_Protocol == nullptr) + if (m_Protocol != nullptr) { - if (!m_Buffer.Write(a_Data, a_Size)) + // Protocol was already recognized, send to the handler: + m_Protocol->DataReceived(a_Data, a_Size); + return; + } + + if (!m_Buffer.Write(a_Data, a_Size)) + { + m_Client->Kick("Unsupported protocol version"); + return; + } + + if (m_InPingForUnrecognizedVersion) + { + // We already know the verison; handle it here. + UInt32 PacketLen; + UInt32 PacketID; + if (!m_Buffer.ReadVarInt32(PacketLen)) { - m_Client->Kick("Unsupported protocol version"); return; } - - if (m_InPingForUnrecognizedVersion) + if (!m_Buffer.ReadVarInt32(PacketID)) { - // We already know the verison; handle it here. - UInt32 PacketLen; - UInt32 PacketID; - if (!m_Buffer.ReadVarInt32(PacketLen)) - { - return; - } - if (!m_Buffer.ReadVarInt32(PacketID)) - { - return; - } - ASSERT(PacketID == 0x01); // Ping packet - ASSERT(PacketLen == 9); // Payload of the packet ID and a UInt64 - - Int64 Data; - if (!m_Buffer.ReadBEInt64(Data)) - { - return; - } - - cPacketizer Pkt(*this, 0x01); // Pong packet - Pkt.WriteBEInt64(Data); + return; + } + if ((PacketID != 0x01) || (PacketLen != 9)) + { + // Not a Ping packet return; } - if (!TryRecognizeProtocol()) + Int64 Data; + if (!m_Buffer.ReadBEInt64(Data)) { return; } - // The protocol has just been recognized, dump the whole m_Buffer contents into it for parsing: - AString Dump; - m_Buffer.ResetRead(); - m_Buffer.ReadAll(Dump); - m_Protocol->DataReceived(Dump.data(), Dump.size()); + cPacketizer Pkt(*this, 0x01); // Pong packet + Pkt.WriteBEInt64(Data); + return; } - else + + if (!TryRecognizeProtocol()) { - m_Protocol->DataReceived(a_Data, a_Size); + return; } + + // The protocol has just been recognized, dump the whole m_Buffer contents into it for parsing: + AString Dump; + m_Buffer.ResetRead(); + m_Buffer.ReadAll(Dump); + m_Protocol->DataReceived(Dump.data(), Dump.size()); } |