initial commit

This commit is contained in:
Sen 2025-03-11 00:23:54 +01:00 committed by Sen
parent 3c9ee26b06
commit 22186c33b9
1458 changed files with 282792 additions and 0 deletions

View file

@ -0,0 +1,53 @@
package game.network;
import java.util.zip.Deflater;
import game.net.buffer.ByteBuf;
import game.net.channel.ChannelHandlerContext;
import game.net.handler.codec.MessageToByteEncoder;
public class NettyCompressionEncoder extends MessageToByteEncoder<ByteBuf>
{
private final byte[] buffer = new byte[8192];
private final Deflater deflater;
private int treshold;
public NettyCompressionEncoder(int treshold)
{
this.treshold = treshold;
this.deflater = new Deflater();
}
protected void encode(ChannelHandlerContext p_encode_1_, ByteBuf p_encode_2_, ByteBuf p_encode_3_) throws Exception
{
int i = p_encode_2_.readableBytes();
PacketBuffer packetbuffer = new PacketBuffer(p_encode_3_);
if (i < this.treshold)
{
packetbuffer.writeVarIntToBuffer(0);
packetbuffer.writeBytes(p_encode_2_);
}
else
{
byte[] abyte = new byte[i];
p_encode_2_.readBytes(abyte);
packetbuffer.writeVarIntToBuffer(abyte.length);
this.deflater.setInput(abyte, 0, i);
this.deflater.finish();
while (!this.deflater.finished())
{
int j = this.deflater.deflate(this.buffer);
packetbuffer.writeBytes((byte[])this.buffer, 0, j);
}
this.deflater.reset();
}
}
public void setCompressionTreshold(int treshold)
{
this.treshold = treshold;
}
}