1package com.runehive.net.codec.game;
3import com.runehive.net.codec.IsaacCipher;
4import com.runehive.net.packet.GamePacket;
5import com.runehive.net.packet.PacketListener;
6import com.runehive.net.packet.PacketRepository;
7import com.runehive.net.packet.PacketType;
8import io.netty.buffer.ByteBuf;
9import io.netty.buffer.Unpooled;
10import io.netty.channel.ChannelHandlerContext;
11import io.netty.handler.codec.ByteToMessageDecoder;
12import org.apache.logging.log4j.LogManager;
13import org.apache.logging.log4j.Logger;
59 protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out)
throws Exception {
76 if (in.isReadable()) {
88 throw new IllegalStateException(String.format(
"Illegal packet type=%s",
type.name()));
99 if (in.isReadable()) {
100 size = in.readUnsignedByte();
114 if (in.isReadable(
size)) {
117 if (listener !=
null) {
118 final ByteBuf payload = in.readBytes(
size);
124 logger.info(
"No listener for client -> server packet={}",
opcode);
An implementation of an ISAAC cipher.
PacketType type
The current packet type.
int opcode
The current packet opcode.
void decode(ChannelHandlerContext ctx, ByteBuf in, List< Object > out)
void decodePayload(ByteBuf in, List< Object > out)
Decodes the packets payload.
GamePacketDecoder(IsaacCipher decryptor)
final IsaacCipher decryptor
The isaac random used to decrypt a packets opcode.
static final Logger logger
The single logger for this class.
State state
The current state of this class.
void decodeSize(ByteBuf in)
Decodes the packets size.
int size
The current packet size.
void decodeOpcode(ByteBuf in, List< Object > out)
Decodes the packet identifier.
Represents a single game packet.
The repository that stores packets sizes and listeners for how to execute the packets.
static PacketListener lookupListener(final int opcode)
Looks up the listener for this packet.
static PacketType lookupType(int opcode)
The method that looks up the packets type.
static int lookupSize(int opcode)
Looks up the reference size of a packet.
Represents the current state of this class.
Represents a type of packet.
VAR_SHORT
A variable packet where the size is indicated by a short.
FIXED
A fixed size packet where the size never changes.
VAR_BYTE
A variable packet where the size is indicated by a byte.