blob: c1571d6c7d3455dadb601969a7139e8a5d7742d4 [file] [log] [blame] [raw]
package protocolsupport.protocol.packet.handler;
import java.util.List;
import java.util.zip.Inflater;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import protocolsupport.utils.netty.ChannelUtils;
public class PacketDecompressor extends net.minecraft.server.v1_9_R2.PacketDecompressor {
private final Inflater inflater = new Inflater();
public PacketDecompressor(int threshold) {
super(threshold);
}
@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
super.channelInactive(ctx);
inflater.end();
}
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf from, List<Object> list) throws Exception {
if (!from.isReadable()) {
return;
}
int uncompressedlength = ChannelUtils.readVarInt(from);
if (uncompressedlength == 0) {
list.add(from.readBytes(from.readableBytes()));
} else {
this.inflater.setInput(ChannelUtils.toArray(from));
byte[] uncompressed = new byte[uncompressedlength];
this.inflater.inflate(uncompressed);
list.add(Unpooled.wrappedBuffer(uncompressed));
this.inflater.reset();
}
}
}