From a9031b6bae742b333b1b390192fa590f2ecb07ea Mon Sep 17 00:00:00 2001 From: peterbell10 Date: Mon, 5 Oct 2020 11:27:14 +0100 Subject: Fix cmake not adding Werror on clang, and _lots_ of warnings (#4963) * Fix cmake not adding Werror on clang, and _lots_ of warnings * WIP: Build fixes * Cannot make intermediate blockhandler instance * Tiger's changes * Fix BitIndex check * Handle invalid NextState values in cMultiVersionProtocol Co-authored-by: Tiger Wang --- src/Protocol/ProtocolRecognizer.cpp | 52 ++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 18 deletions(-) (limited to 'src/Protocol/ProtocolRecognizer.cpp') diff --git a/src/Protocol/ProtocolRecognizer.cpp b/src/Protocol/ProtocolRecognizer.cpp index b72f73f3d..94208cbf3 100644 --- a/src/Protocol/ProtocolRecognizer.cpp +++ b/src/Protocol/ProtocolRecognizer.cpp @@ -244,7 +244,7 @@ std::unique_ptr cMultiVersionProtocol::TryRecognizeLengthedProtocol(c UInt32 ProtocolVersion; AString ServerAddress; UInt16 ServerPort; - cProtocol::State NextState; + UInt32 NextStateValue; if (!m_Buffer.ReadVarInt(PacketType) || (PacketType != 0x00)) { @@ -262,7 +262,7 @@ std::unique_ptr cMultiVersionProtocol::TryRecognizeLengthedProtocol(c !m_Buffer.ReadVarInt(ProtocolVersion) || !m_Buffer.ReadVarUTF8String(ServerAddress) || !m_Buffer.ReadBEUInt16(ServerPort) || - !m_Buffer.ReadVarInt(NextState) + !m_Buffer.ReadVarInt(NextStateValue) ) { // TryRecognizeProtocol guarantees that we will have as much @@ -270,6 +270,22 @@ std::unique_ptr cMultiVersionProtocol::TryRecognizeLengthedProtocol(c throw TriedToJoinWithUnsupportedProtocolException("Incorrect amount of data received - hacked client?"); } + cProtocol::State NextState = [&] + { + switch (NextStateValue) + { + case cProtocol::State::Status: return cProtocol::State::Status; + case cProtocol::State::Login: return cProtocol::State::Login; + case cProtocol::State::Game: return cProtocol::State::Game; + default: + { + throw TriedToJoinWithUnsupportedProtocolException( + fmt::format("Invalid next game state: {}", NextStateValue) + ); + } + } + }(); + // TODO: this should be a protocol property, not ClientHandle: a_Client.SetProtocolVersion(ProtocolVersion); @@ -285,23 +301,23 @@ std::unique_ptr cMultiVersionProtocol::TryRecognizeLengthedProtocol(c // All good, eat up the data: m_Buffer.CommitRead(); - switch (static_cast(ProtocolVersion)) + switch (ProtocolVersion) { - case cProtocol::Version::v1_8_0: return std::make_unique (&a_Client, ServerAddress, NextState); - case cProtocol::Version::v1_9_0: return std::make_unique (&a_Client, ServerAddress, NextState); - case cProtocol::Version::v1_9_1: return std::make_unique (&a_Client, ServerAddress, NextState); - case cProtocol::Version::v1_9_2: return std::make_unique (&a_Client, ServerAddress, NextState); - case cProtocol::Version::v1_9_4: return std::make_unique (&a_Client, ServerAddress, NextState); - case cProtocol::Version::v1_10_0: return std::make_unique(&a_Client, ServerAddress, NextState); - case cProtocol::Version::v1_11_0: return std::make_unique(&a_Client, ServerAddress, NextState); - case cProtocol::Version::v1_11_1: return std::make_unique(&a_Client, ServerAddress, NextState); - case cProtocol::Version::v1_12: return std::make_unique (&a_Client, ServerAddress, NextState); - case cProtocol::Version::v1_12_1: return std::make_unique(&a_Client, ServerAddress, NextState); - case cProtocol::Version::v1_12_2: return std::make_unique(&a_Client, ServerAddress, NextState); - case cProtocol::Version::v1_13: return std::make_unique (&a_Client, ServerAddress, NextState); - case cProtocol::Version::v1_13_1: return std::make_unique(&a_Client, ServerAddress, NextState); - case cProtocol::Version::v1_13_2: return std::make_unique(&a_Client, ServerAddress, NextState); - case cProtocol::Version::v1_14: return std::make_unique (&a_Client, ServerAddress, NextState); + case static_cast(cProtocol::Version::v1_8_0): return std::make_unique (&a_Client, ServerAddress, NextState); + case static_cast(cProtocol::Version::v1_9_0): return std::make_unique (&a_Client, ServerAddress, NextState); + case static_cast(cProtocol::Version::v1_9_1): return std::make_unique (&a_Client, ServerAddress, NextState); + case static_cast(cProtocol::Version::v1_9_2): return std::make_unique (&a_Client, ServerAddress, NextState); + case static_cast(cProtocol::Version::v1_9_4): return std::make_unique (&a_Client, ServerAddress, NextState); + case static_cast(cProtocol::Version::v1_10_0): return std::make_unique(&a_Client, ServerAddress, NextState); + case static_cast(cProtocol::Version::v1_11_0): return std::make_unique(&a_Client, ServerAddress, NextState); + case static_cast(cProtocol::Version::v1_11_1): return std::make_unique(&a_Client, ServerAddress, NextState); + case static_cast(cProtocol::Version::v1_12): return std::make_unique (&a_Client, ServerAddress, NextState); + case static_cast(cProtocol::Version::v1_12_1): return std::make_unique(&a_Client, ServerAddress, NextState); + case static_cast(cProtocol::Version::v1_12_2): return std::make_unique(&a_Client, ServerAddress, NextState); + case static_cast(cProtocol::Version::v1_13): return std::make_unique (&a_Client, ServerAddress, NextState); + case static_cast(cProtocol::Version::v1_13_1): return std::make_unique(&a_Client, ServerAddress, NextState); + case static_cast(cProtocol::Version::v1_13_2): return std::make_unique(&a_Client, ServerAddress, NextState); + case static_cast(cProtocol::Version::v1_14): return std::make_unique (&a_Client, ServerAddress, NextState); default: { LOGD("Client \"%s\" uses an unsupported protocol (lengthed, version %u (0x%x))", -- cgit v1.2.3