initial commit
This commit is contained in:
parent
3c9ee26b06
commit
22186c33b9
1458 changed files with 282792 additions and 0 deletions
62
java/src/game/network/NettyCompressionDecoder.java
Executable file
62
java/src/game/network/NettyCompressionDecoder.java
Executable file
|
@ -0,0 +1,62 @@
|
|||
package game.network;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.zip.DataFormatException;
|
||||
import java.util.zip.Inflater;
|
||||
|
||||
import game.net.buffer.ByteBuf;
|
||||
import game.net.buffer.Unpooled;
|
||||
import game.net.channel.ChannelHandlerContext;
|
||||
import game.net.handler.codec.ByteToMessageDecoder;
|
||||
import game.net.handler.codec.DecoderException;
|
||||
|
||||
public class NettyCompressionDecoder extends ByteToMessageDecoder
|
||||
{
|
||||
private final Inflater inflater;
|
||||
private int treshold;
|
||||
|
||||
public NettyCompressionDecoder(int treshold)
|
||||
{
|
||||
this.treshold = treshold;
|
||||
this.inflater = new Inflater();
|
||||
}
|
||||
|
||||
protected void decode(ChannelHandlerContext p_decode_1_, ByteBuf p_decode_2_, List<Object> p_decode_3_) throws DataFormatException, Exception
|
||||
{
|
||||
if (p_decode_2_.readableBytes() != 0)
|
||||
{
|
||||
PacketBuffer packetbuffer = new PacketBuffer(p_decode_2_);
|
||||
int i = packetbuffer.readVarIntFromBuffer();
|
||||
|
||||
if (i == 0)
|
||||
{
|
||||
p_decode_3_.add(packetbuffer.readBytes(packetbuffer.readableBytes()));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (i < this.treshold)
|
||||
{
|
||||
throw new DecoderException("Badly compressed packet - size of " + i + " is below server threshold of " + this.treshold);
|
||||
}
|
||||
|
||||
if (i > 2097152)
|
||||
{
|
||||
throw new DecoderException("Badly compressed packet - size of " + i + " is larger than protocol maximum of " + 2097152);
|
||||
}
|
||||
|
||||
byte[] abyte = new byte[packetbuffer.readableBytes()];
|
||||
packetbuffer.readBytes(abyte);
|
||||
this.inflater.setInput(abyte);
|
||||
byte[] abyte1 = new byte[i];
|
||||
this.inflater.inflate(abyte1);
|
||||
p_decode_3_.add(Unpooled.wrappedBuffer(abyte1));
|
||||
this.inflater.reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setCompressionTreshold(int treshold)
|
||||
{
|
||||
this.treshold = treshold;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue