Skip to content

Commit

Permalink
[CompressedPacket] Fixed #97. [gamekit] Updated.
Browse files Browse the repository at this point in the history
  • Loading branch information
Unarelith committed May 14, 2020
1 parent 98783f3 commit a2c2dba
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion external/gamekit
Submodule gamekit updated 1 files
+4 −1 CMakeLists.txt
12 changes: 9 additions & 3 deletions source/common/network/CompressedPacket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
*/
#include <cassert>

#include <gk/core/Debug.hpp>

#include "CompressedPacket.hpp"

// Note: This class was implemented thanks to this SFML forum topic:
Expand Down Expand Up @@ -57,7 +59,9 @@ const void* CompressedPacket::onSend(std::size_t& size) {
m_compressionBuffer[1] = (srcSize >> 8) & 0xFF;

// Compress the data into the rest of the buffer
compress(m_compressionBuffer.data() + 2, &dstSize, srcData, srcSize);
int result = compress(m_compressionBuffer.data() + 2, &dstSize, srcData, srcSize);
if (result != Z_OK)
gkError() << "Failed to compress packet";

// Set the size to the compressed size plus
// two bytes for the size marker
Expand All @@ -79,10 +83,12 @@ void CompressedPacket::onReceive(const void* data, std::size_t size) {
m_compressionBuffer.resize(uncompressedSize);

// Declare a variable for the destination size
uLong dstSize;
uLong dstSize = uncompressedSize;

// Uncompress the data (remove the first two bytes)
uncompress(m_compressionBuffer.data(), &dstSize, (srcData + 2), size - 2);
int result = uncompress(m_compressionBuffer.data(), &dstSize, (srcData + 2), size - 2);
if (result != Z_OK)
gkError() << "Failed to uncompress packet";

// Assert that the uncompressed size is the same as the
// size we were sent for the buffer
Expand Down

0 comments on commit a2c2dba

Please sign in to comment.