From 26f060b3348fe11982f51b7533af1730cdd9c090 Mon Sep 17 00:00:00 2001 From: Persson-dev Date: Wed, 1 Sep 2021 16:25:38 +0200 Subject: [PATCH] fix: 32 bit protocol --- include/misc/Compression.h | 2 +- src/game/Connexion.cpp | 4 ++-- src/misc/Compression.cpp | 4 ++-- src/misc/Random.cpp | 2 +- src/protocol/Protocol.cpp | 8 ++++---- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/include/misc/Compression.h b/include/misc/Compression.h index 7d8853e..14d02c6 100644 --- a/include/misc/Compression.h +++ b/include/misc/Compression.h @@ -8,7 +8,7 @@ namespace utils { DataBuffer Compress(const DataBuffer& buffer); DataBuffer Decompress(DataBuffer& buffer); -DataBuffer Decompress(DataBuffer& buffer, std::size_t packetLength); +DataBuffer Decompress(DataBuffer& buffer, std::uint64_t packetLength); } // namespace utils } // namespace td diff --git a/src/game/Connexion.cpp b/src/game/Connexion.cpp index 6525b4c..729a43f 100644 --- a/src/game/Connexion.cpp +++ b/src/game/Connexion.cpp @@ -33,9 +33,9 @@ bool Connexion::updateSocket(){ return false; DataBuffer buffer; - m_Socket.Receive(buffer, sizeof(std::size_t)); + m_Socket.Receive(buffer, sizeof(std::uint64_t)); if (buffer.GetSize() > 0){ - std::size_t packetLenght; + std::uint64_t packetLenght; buffer >> packetLenght; m_Socket.Receive(buffer, packetLenght); diff --git a/src/misc/Compression.cpp b/src/misc/Compression.cpp index 361b22c..ff031dd 100644 --- a/src/misc/Compression.cpp +++ b/src/misc/Compression.cpp @@ -49,12 +49,12 @@ DataBuffer Compress(const DataBuffer& buffer) { return packet; } -DataBuffer Decompress(DataBuffer& buffer, std::size_t packetLength){ +DataBuffer Decompress(DataBuffer& buffer, std::uint64_t packetLength){ std::uint64_t uncompressedLength; buffer >> uncompressedLength; - std::size_t compressedLength = packetLength - sizeof(uncompressedLength); + std::uint64_t compressedLength = packetLength - sizeof(uncompressedLength); if (uncompressedLength == 0) { // Uncompressed diff --git a/src/misc/Random.cpp b/src/misc/Random.cpp index 67adbf2..7c1c882 100644 --- a/src/misc/Random.cpp +++ b/src/misc/Random.cpp @@ -9,7 +9,7 @@ void initRandomizer(){ srand(time(0)); } -std::uint64_t getRandomNumber(std::size_t max){ +std::uint64_t getRandomNumber(std::uint64_t max){ return rand() % max; } diff --git a/src/protocol/Protocol.cpp b/src/protocol/Protocol.cpp index 3233218..64edc0c 100644 --- a/src/protocol/Protocol.cpp +++ b/src/protocol/Protocol.cpp @@ -122,7 +122,7 @@ void WorldBeginDataPacket::Deserialize(DataBuffer& data){ data >> m_RedSpawn >> m_RedTower; data >> m_BlueSpawn >> m_BlueTower; - std::size_t tilePaletteSize; + std::uint64_t tilePaletteSize; data >> tilePaletteSize; m_TilePalette.reserve(tilePaletteSize); @@ -145,7 +145,7 @@ DataBuffer WorldDataPacket::Serialize() const{ game::ChunkCoord coords = pair.first; game::ChunkPtr chunk = pair.second; - data << coords.first << coords.second << chunk->palette.size(); + data << coords.first << coords.second << (std::uint64_t) chunk->palette.size(); std::size_t bufferSize = data.GetSize(); data.Resize(data.GetSize() + chunk->palette.size() * sizeof(game::ChunkPalette::value_type)); @@ -182,7 +182,7 @@ DataBuffer WorldDataPacket::Serialize() const{ } void WorldDataPacket::Deserialize(DataBuffer& data){ - std::size_t chunkCount; + std::uint64_t chunkCount; data >> chunkCount; for (int chunkNumber = 0; chunkNumber < chunkCount; chunkNumber++){ @@ -191,7 +191,7 @@ void WorldDataPacket::Deserialize(DataBuffer& data){ game::ChunkCoord::first_type chunkX, chunkY; data >> chunkX >> chunkY; - std::size_t chunkPaletteSize; + std::uint64_t chunkPaletteSize; data >> chunkPaletteSize; game::ChunkPalette chunkPalette(chunkPaletteSize);