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/Protocol_1_8.cpp | 42 ++++++++++++++---------------------------- 1 file changed, 14 insertions(+), 28 deletions(-) (limited to 'src/Protocol/Protocol_1_8.cpp') diff --git a/src/Protocol/Protocol_1_8.cpp b/src/Protocol/Protocol_1_8.cpp index ae3137eb6..5856a87d2 100644 --- a/src/Protocol/Protocol_1_8.cpp +++ b/src/Protocol/Protocol_1_8.cpp @@ -9,6 +9,7 @@ Implements the 1.8 protocol classes: #include "Globals.h" #include "Protocol_1_8.h" +#include "main.h" #include "../mbedTLS++/Sha1Checksum.h" #include "Packetizer.h" @@ -91,20 +92,13 @@ static const UInt32 CompressionThreshold = 256; // After how large a packet sho -// fwd: main.cpp: -extern bool g_ShouldLogCommIn, g_ShouldLogCommOut; - - - - - //////////////////////////////////////////////////////////////////////////////// // cProtocol_1_8_0: cProtocol_1_8_0::cProtocol_1_8_0(cClientHandle * a_Client, const AString & a_ServerAddress, State a_State) : Super(a_Client), - m_ServerAddress(a_ServerAddress), m_State(a_State), + m_ServerAddress(a_ServerAddress), m_IsEncrypted(false) { AStringVector Params; @@ -395,6 +389,13 @@ void cProtocol_1_8_0::SendDisconnect(const AString & a_Reason) Pkt.WriteString(Printf("{\"text\":\"%s\"}", EscapeString(a_Reason).c_str())); break; } + default: + { + FLOGERROR( + "Tried to send disconnect in invalid game state {0}", + static_cast(m_State) + ); + } } } @@ -1725,7 +1726,8 @@ bool cProtocol_1_8_0::CompressPacket(const AString & a_Packet, AString & a_Compr ---------------------------------------------- */ const UInt32 DataSize = 0; - const auto PacketSize = cByteBuffer::GetVarIntSize(DataSize) + UncompressedSize; + const auto PacketSize = static_cast( + cByteBuffer::GetVarIntSize(DataSize) + UncompressedSize); cByteBuffer LengthHeaderBuffer( cByteBuffer::GetVarIntSize(PacketSize) + @@ -1776,8 +1778,9 @@ bool cProtocol_1_8_0::CompressPacket(const AString & a_Packet, AString & a_Compr return false; } - const UInt32 DataSize = UncompressedSize; - const auto PacketSize = cByteBuffer::GetVarIntSize(DataSize) + CompressedSize; + const UInt32 DataSize = static_cast(UncompressedSize); + const auto PacketSize = static_cast( + cByteBuffer::GetVarIntSize(DataSize) + CompressedSize); cByteBuffer LengthHeaderBuffer( cByteBuffer::GetVarIntSize(PacketSize) + @@ -2272,23 +2275,6 @@ bool cProtocol_1_8_0::HandlePacket(cByteBuffer & a_ByteBuffer, UInt32 a_PacketTy } break; } - default: - { - // Received a packet in an unknown state, report: - LOGWARNING("Received a packet in an unknown protocol state %d. Ignoring further packets.", m_State); - - // Cannot kick the client - we don't know this state and thus the packet number for the kick packet - - // Switch to a state when all further packets are silently ignored: - m_State = State::Invalid; - return false; - } - case State::Invalid: - { - // This is the state used for "not processing packets anymore" when we receive a bad packet from a client. - // Do not output anything (the caller will do that for us), just return failure - return false; - } } // switch (m_State) // Unknown packet type, report to the ClientHandle: -- cgit v1.2.3