NettyCompressionDecoder .java

net.minecraft.network.NettyCompressionDecoder (class): members: inflater, treshold, setCompressionTreshold, decode. imports: DecoderException, Unpooled.

net.minecraft.networkclass62 linescommonextends ByteToMessageDecoder2.0 KB

API Surface (2)

void decode(ChannelHandlerContext p_decode_1_, ByteBuf p_decode_2_, List<Object> p_decode_3_)
void setCompressionTreshold(int treshold)

Fields & Constants (2)

inflater
treshold

String literals (3)

"Badly compressed packet - size of "
" is below server threshold of "
" is larger than protocol maximum of "

Code Graph: Dependencies (1)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

NettyCompressionDecoder.java62 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.network;
2
3
import io.netty.buffer.ByteBuf;
4
import io.netty.buffer.Unpooled;
5
import io.netty.channel.ChannelHandlerContext;
6
import io.netty.handler.codec.ByteToMessageDecoder;
7
import io.netty.handler.codec.DecoderException;
8
import java.util.List;
9
import java.util.zip.DataFormatException;
10
import java.util.zip.Inflater;
11
12
public class NettyCompressionDecoder extends ByteToMessageDecoder
13
{
14
    private final Inflater inflater;
15
    private int treshold;
16
17
    public NettyCompressionDecoder(int treshold)
18
    {
19
        this.treshold = treshold;
20
        this.inflater = new Inflater();
21
    }
22
23
    protected void decode(ChannelHandlerContext p_decode_1_, ByteBuf p_decode_2_, List<Object> p_decode_3_) throws DataFormatException, Exception
24
    {
25
        if (p_decode_2_.readableBytes() != 0)
26
        {
27
            PacketBuffer packetbuffer = new PacketBuffer(p_decode_2_);
28
            int i = packetbuffer.readVarIntFromBuffer();
29
30
            if (i == 0)
31
            {
32
                p_decode_3_.add(packetbuffer.readBytes(packetbuffer.readableBytes()));
33
            }
34
            else
35
            {
36
                if (i < this.treshold)
37
                {
38
                    throw new DecoderException("Badly compressed packet - size of " + i + " is below server threshold of " + this.treshold);
39
                }
40
41
                if (i > 2097152)
42
                {
43
                    throw new DecoderException("Badly compressed packet - size of " + i + " is larger than protocol maximum of " + 2097152);
44
                }
45
46
                byte[] abyte = new byte[packetbuffer.readableBytes()];
47
                packetbuffer.readBytes(abyte);
48
                this.inflater.setInput(abyte);
49
                byte[] abyte1 = new byte[i];
50
                this.inflater.inflate(abyte1);
51
                p_decode_3_.add(Unpooled.wrappedBuffer(abyte1));
52
                this.inflater.reset();
53
            }
54
        }
55
    }
56
57
    public void setCompressionTreshold(int treshold)
58
    {
59
        this.treshold = treshold;
60
    }
61
}
62

Deobfuscated MCP 1.8.9 source of NettyCompressionDecoder from Marcelektro/MavenMCP-1.8.9 (net/minecraft/network/NettyCompressionDecoder.java), stored verbatim.