summaryrefslogtreecommitdiffstats
path: root/src/Protocol
diff options
context:
space:
mode:
Diffstat (limited to 'src/Protocol')
-rw-r--r--src/Protocol/ChunkDataSerializer.cpp13
-rw-r--r--src/Protocol/ProtocolRecognizer.cpp27
-rw-r--r--src/Protocol/Protocol_1_13.cpp4
-rw-r--r--src/Protocol/Protocol_1_14.cpp2
-rw-r--r--src/Protocol/Protocol_1_8.cpp12
5 files changed, 24 insertions, 34 deletions
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<UInt64>(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<UInt64>(Value) << BitIndex;
// The _signed_ count of bits in Value left to write
- if (BitIndex + a_BitsPerEntry >= 64)
+ const auto Remaining = static_cast<char>(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<UInt64>(Value >> (a_BitsPerEntry - Remaining));
+ BitIndex = static_cast<unsigned char>(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<cProtocol> 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<cProtocol> 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<int>(Effect1), static_cast<int>(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<Int32>(a_World.GetDimension()));
Pkt.WriteBEUInt8(static_cast<UInt8>(Clamp<size_t>(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<size_t>(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<UInt32>(
- cByteBuffer::GetVarIntSize(DataSize) + UncompressedSize);
+ const auto PacketSize = static_cast<UInt32>(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<UInt32>(UncompressedSize);
- const auto PacketSize = static_cast<UInt32>(
- cByteBuffer::GetVarIntSize(DataSize) + CompressedSize);
+ const auto PacketSize = static_cast<UInt32>(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;
}