From 090d8305e4e3c3ee085a897b72f2b4708e183eb8 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Mon, 5 Oct 2020 13:09:42 +0100 Subject: Warnings improvements * Turn off global-constructors warning. These are needed to implement cRoot signal handler functionality * Add Clang flags based on version lookup instead of a compile test. The CMake config process is single threaded and slow enough already * Reduced GetStackValue verbosity + Clarify EnchantmentLevel, StayCount, AlwaysTicked, ViewDistance signedness + Give SettingsRepositoryInterface a move constructor to simplify main.cpp code - Remove do {} while (false) construction in redstone handler --- src/Protocol/ChunkDataSerializer.cpp | 13 +++++++------ src/Protocol/ProtocolRecognizer.cpp | 27 ++++++++++----------------- src/Protocol/Protocol_1_13.cpp | 4 +--- src/Protocol/Protocol_1_14.cpp | 2 +- src/Protocol/Protocol_1_8.cpp | 12 +++++------- 5 files changed, 24 insertions(+), 34 deletions(-) (limited to 'src/Protocol') diff --git a/src/Protocol/ChunkDataSerializer.cpp b/src/Protocol/ChunkDataSerializer.cpp index 9f8b91ac1..d2b8489ea 100644 --- a/src/Protocol/ChunkDataSerializer.cpp +++ b/src/Protocol/ChunkDataSerializer.cpp @@ -503,26 +503,27 @@ inline void cChunkDataSerializer::WriteSectionDataSeamless(const cChunkData::sCh ASSERT(a_BitsPerEntry < 64); UInt64 Buffer = 0; // A buffer to compose multiple smaller bitsizes into one 64-bit number - int BitIndex = 0; // The bit-position in Buffer that represents where to write next + unsigned char BitIndex = 0; // The bit-position in Buffer that represents where to write next for (size_t Index = 0; Index != cChunkData::SectionBlockCount; Index++) { const BLOCKTYPE BlockType = a_Section.m_BlockTypes[Index]; const NIBBLETYPE BlockMeta = (a_Section.m_BlockMetas[Index / 2] >> ((Index % 2) * 4)) & 0x0f; - const auto Value = static_cast(Palette(BlockType, BlockMeta)); + const auto Value = Palette(BlockType, BlockMeta); // Write as much as possible of Value, starting from BitIndex, into Buffer: - Buffer |= Value << BitIndex; + Buffer |= static_cast(Value) << BitIndex; // The _signed_ count of bits in Value left to write - if (BitIndex + a_BitsPerEntry >= 64) + const auto Remaining = static_cast(a_BitsPerEntry - (64 - BitIndex)); + if (Remaining >= 0) { // There were some bits remaining: we've filled the buffer. Flush it: m_Packet.WriteBEUInt64(Buffer); // And write the remaining bits, setting the new BitIndex: - Buffer = Value >> (64 - BitIndex); - BitIndex = a_BitsPerEntry - (64 - BitIndex); + Buffer = static_cast(Value >> (a_BitsPerEntry - Remaining)); + BitIndex = static_cast(Remaining); } else { diff --git a/src/Protocol/ProtocolRecognizer.cpp b/src/Protocol/ProtocolRecognizer.cpp index 94208cbf3..5d146c46a 100644 --- a/src/Protocol/ProtocolRecognizer.cpp +++ b/src/Protocol/ProtocolRecognizer.cpp @@ -253,9 +253,7 @@ std::unique_ptr cMultiVersionProtocol::TryRecognizeLengthedProtocol(c a_Client.GetIPString().c_str(), PacketType ); - throw TriedToJoinWithUnsupportedProtocolException( - Printf("Your client isn't supported.\nTry connecting with Minecraft " MCS_CLIENT_VERSIONS, ProtocolVersion) - ); + throw TriedToJoinWithUnsupportedProtocolException("Your client isn't supported.\nTry connecting with Minecraft " MCS_CLIENT_VERSIONS); } if ( @@ -270,21 +268,16 @@ std::unique_ptr cMultiVersionProtocol::TryRecognizeLengthedProtocol(c throw TriedToJoinWithUnsupportedProtocolException("Incorrect amount of data received - hacked client?"); } - cProtocol::State NextState = [&] + const auto NextState = [NextStateValue] + { + switch (NextStateValue) { - 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) - ); - } - } - }(); + case 1: return cProtocol::State::Status; + case 2: return cProtocol::State::Login; + case 3: return cProtocol::State::Game; + default: throw TriedToJoinWithUnsupportedProtocolException("Your client isn't supported.\nTry connecting with Minecraft " MCS_CLIENT_VERSIONS); + } + }(); // TODO: this should be a protocol property, not ClientHandle: a_Client.SetProtocolVersion(ProtocolVersion); diff --git a/src/Protocol/Protocol_1_13.cpp b/src/Protocol/Protocol_1_13.cpp index 9497012e3..84185a258 100644 --- a/src/Protocol/Protocol_1_13.cpp +++ b/src/Protocol/Protocol_1_13.cpp @@ -316,9 +316,7 @@ void cProtocol_1_13::HandlePacketSetBeaconEffect(cByteBuffer & a_ByteBuffer) { HANDLE_READ(a_ByteBuffer, ReadVarInt32, UInt32, Effect1); HANDLE_READ(a_ByteBuffer, ReadVarInt32, UInt32, Effect2); - m_Client->HandleBeaconSelection( - static_cast(Effect1), static_cast(Effect2) - ); + m_Client->HandleBeaconSelection(Effect1, Effect2); } diff --git a/src/Protocol/Protocol_1_14.cpp b/src/Protocol/Protocol_1_14.cpp index a77cd2d7d..f93a044d7 100644 --- a/src/Protocol/Protocol_1_14.cpp +++ b/src/Protocol/Protocol_1_14.cpp @@ -59,7 +59,7 @@ void cProtocol_1_14::SendLogin(const cPlayer & a_Player, const cWorld & a_World) Pkt.WriteBEInt32(static_cast(a_World.GetDimension())); Pkt.WriteBEUInt8(static_cast(Clamp(Server->GetMaxPlayers(), 0, 255))); Pkt.WriteString("default"); - Pkt.WriteVarInt32(ToUnsigned(a_World.GetMaxViewDistance())); + Pkt.WriteVarInt32(a_World.GetMaxViewDistance()); Pkt.WriteBool(false); } diff --git a/src/Protocol/Protocol_1_8.cpp b/src/Protocol/Protocol_1_8.cpp index acfa676b5..49418b475 100644 --- a/src/Protocol/Protocol_1_8.cpp +++ b/src/Protocol/Protocol_1_8.cpp @@ -1719,7 +1719,7 @@ void cProtocol_1_8_0::SendWindowProperty(const cWindow & a_Window, size_t a_Prop bool cProtocol_1_8_0::CompressPacket(const AString & a_Packet, AString & a_CompressedData) { - const auto UncompressedSize = static_cast(a_Packet.size()); + const auto UncompressedSize = a_Packet.size(); if (UncompressedSize < CompressionThreshold) { @@ -1734,8 +1734,7 @@ bool cProtocol_1_8_0::CompressPacket(const AString & a_Packet, AString & a_Compr ---------------------------------------------- */ const UInt32 DataSize = 0; - const auto PacketSize = static_cast( - cByteBuffer::GetVarIntSize(DataSize) + UncompressedSize); + const auto PacketSize = static_cast(cByteBuffer::GetVarIntSize(DataSize) + UncompressedSize); cByteBuffer LengthHeaderBuffer( cByteBuffer::GetVarIntSize(PacketSize) + @@ -1787,8 +1786,7 @@ bool cProtocol_1_8_0::CompressPacket(const AString & a_Packet, AString & a_Compr } const UInt32 DataSize = static_cast(UncompressedSize); - const auto PacketSize = static_cast( - cByteBuffer::GetVarIntSize(DataSize) + CompressedSize); + const auto PacketSize = static_cast(cByteBuffer::GetVarIntSize(DataSize) + CompressedSize); cByteBuffer LengthHeaderBuffer( cByteBuffer::GetVarIntSize(PacketSize) + @@ -2987,8 +2985,8 @@ void cProtocol_1_8_0::HandleVanillaPluginMessage(cByteBuffer & a_ByteBuffer, con } else if (a_Channel == "MC|Beacon") { - HANDLE_READ(a_ByteBuffer, ReadBEInt32, Int32, Effect1); - HANDLE_READ(a_ByteBuffer, ReadBEInt32, Int32, Effect2); + HANDLE_READ(a_ByteBuffer, ReadBEUInt32, UInt32, Effect1); + HANDLE_READ(a_ByteBuffer, ReadBEUInt32, UInt32, Effect2); m_Client->HandleBeaconSelection(Effect1, Effect2); return; } -- cgit v1.2.3