diff --git a/minecraft/networking/connection.py b/minecraft/networking/connection.py index 659a6e2..4e71c00 100644 --- a/minecraft/networking/connection.py +++ b/minecraft/networking/connection.py @@ -335,11 +335,12 @@ class PacketReactor(object): packet_data.reset_cursor() if self.connection.options.compression_enabled: - compressed_size = VarInt.read(packet_data) - - if compressed_size > 0: - decompressed_packet = decompress( - packet_data.read(compressed_size)) + decompressed_size = VarInt.read(packet_data) + if decompressed_size > 0: + decompressed_packet = decompress(packet_data.read()) + assert len(decompressed_packet) == decompressed_size, \ + 'decompressed length %d, but expected %d' % \ + (len(decompressed_packet), decompressed_size) packet_data.reset() packet_data.send(decompressed_packet) packet_data.reset_cursor() diff --git a/minecraft/networking/packets.py b/minecraft/networking/packets.py index 5b31fea..4a71ddd 100644 --- a/minecraft/networking/packets.py +++ b/minecraft/networking/packets.py @@ -18,10 +18,10 @@ class PacketBuffer(object): """ self.bytes.write(value) - def read(self, length): + def read(self, length=None): return self.bytes.read(length) - def recv(self, length): + def recv(self, length=None): return self.read(length) def reset(self): @@ -123,10 +123,11 @@ class Packet(object): if compression_threshold is not None: if len(packet_buffer.get_writable()) > compression_threshold != -1: # compress the current payload - compressed_data = compress(packet_buffer.get_writable()) + packet_data = packet_buffer.get_writable() + compressed_data = compress(packet_data) packet_buffer.reset() - # write out the length of the compressed payload - VarInt.send(len(compressed_data), packet_buffer) + # write out the length of the uncompressed payload + VarInt.send(len(packet_data), packet_buffer) # write the compressed payload itself packet_buffer.send(compressed_data) else: