def read_packet_buffer(self, client_file): length = types.VarInt.read(client_file) buffer = packets.PacketBuffer() while len(buffer.get_writable()) < length: buffer.send(client_file.read(length - len(buffer.get_writable()))) buffer.reset_cursor() return buffer
def read_packet_buffer(self, client_file): length = types.VarInt.read(client_file) buffer = packets.PacketBuffer() while len(buffer.get_writable()) < length: buffer.send(client_file.read(length - len(buffer.get_writable()))) buffer.reset_cursor() if self.compression_enabled: data_length = types.VarInt.read(buffer) if data_length > 0: data = zlib.decompress(buffer.read()) assert len(data) == data_length, \ '%s != %s' % (len(data), data_length) buffer.reset() buffer.send(data) buffer.reset_cursor() return buffer
def _read_packet_buffer(self): # Read a serverbound packet in the form of a raw buffer, or raises # FakeClientDisconnect if the client has cleanly disconnected. try: length = types.VarInt.read(self.socket_file) except EOFError: raise FakeClientDisconnect buffer = packets.PacketBuffer() while len(buffer.get_writable()) < length: data = self.socket_file.read(length - len(buffer.get_writable())) buffer.send(data) buffer.reset_cursor() if self.compression_enabled: data_length = types.VarInt.read(buffer) if data_length > 0: data = zlib.decompress(buffer.read()) assert len(data) == data_length, \ '%s != %s' % (len(data), data_length) buffer.reset() buffer.send(data) buffer.reset_cursor() return buffer