initial commit
This commit is contained in:
parent
3c9ee26b06
commit
22186c33b9
1458 changed files with 282792 additions and 0 deletions
55
java/src/game/network/PacketSplitter.java
Executable file
55
java/src/game/network/PacketSplitter.java
Executable file
|
@ -0,0 +1,55 @@
|
|||
package game.network;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
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.CorruptedFrameException;
|
||||
|
||||
public class PacketSplitter extends ByteToMessageDecoder
|
||||
{
|
||||
protected void decode(ChannelHandlerContext p_decode_1_, ByteBuf p_decode_2_, List<Object> p_decode_3_) throws Exception
|
||||
{
|
||||
p_decode_2_.markReaderIndex();
|
||||
byte[] abyte = new byte[3];
|
||||
|
||||
for (int i = 0; i < abyte.length; ++i)
|
||||
{
|
||||
if (!p_decode_2_.isReadable())
|
||||
{
|
||||
p_decode_2_.resetReaderIndex();
|
||||
return;
|
||||
}
|
||||
|
||||
abyte[i] = p_decode_2_.readByte();
|
||||
|
||||
if (abyte[i] >= 0)
|
||||
{
|
||||
PacketBuffer packetbuffer = new PacketBuffer(Unpooled.wrappedBuffer(abyte));
|
||||
|
||||
try
|
||||
{
|
||||
int j = packetbuffer.readVarIntFromBuffer();
|
||||
|
||||
if (p_decode_2_.readableBytes() >= j)
|
||||
{
|
||||
p_decode_3_.add(p_decode_2_.readBytes(j));
|
||||
return;
|
||||
}
|
||||
|
||||
p_decode_2_.resetReaderIndex();
|
||||
}
|
||||
finally
|
||||
{
|
||||
packetbuffer.release();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
throw new CorruptedFrameException("length wider than 21-bit");
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue