RuneHive-Game
Loading...
Searching...
No Matches
com.runehive.net.codec.game.GamePacketDecoder Class Reference

The class that reads packets from the client into GamePacket's. More...

Inheritance diagram for com.runehive.net.codec.game.GamePacketDecoder:
Collaboration diagram for com.runehive.net.codec.game.GamePacketDecoder:

Classes

enum  State
 Represents the current state of this class. More...

Public Member Functions

 GamePacketDecoder (IsaacCipher decryptor)

Protected Member Functions

void decode (ChannelHandlerContext ctx, ByteBuf in, List< Object > out) throws Exception

Private Member Functions

void decodeOpcode (ByteBuf in, List< Object > out)
 Decodes the packet identifier.
void decodePayload (ByteBuf in, List< Object > out)
 Decodes the packets payload.
void decodeSize (ByteBuf in)
 Decodes the packets size.

Private Attributes

final IsaacCipher decryptor
 The isaac random used to decrypt a packets opcode.
int opcode
 The current packet opcode.
int size
 The current packet size.
State state = State.OPCODE
 The current state of this class.
PacketType type = PacketType.EMPTY
 The current packet type.

Static Private Attributes

static final Logger logger = LogManager.getLogger(GamePacketDecoder.class)
 The single logger for this class.

Detailed Description

The class that reads packets from the client into GamePacket's.

Author
nshusa

Definition at line 22 of file GamePacketDecoder.java.

Constructor & Destructor Documentation

◆ GamePacketDecoder()

com.runehive.net.codec.game.GamePacketDecoder.GamePacketDecoder ( IsaacCipher decryptor)

Definition at line 54 of file GamePacketDecoder.java.

54 {
55 this.decryptor = decryptor;
56 }

References decryptor.

Member Function Documentation

◆ decode()

void com.runehive.net.codec.game.GamePacketDecoder.decode ( ChannelHandlerContext ctx,
ByteBuf in,
List< Object > out ) throws Exception
protected

Definition at line 59 of file GamePacketDecoder.java.

59 {
60 if (state == State.OPCODE) {
61 decodeOpcode(in, out);
62 } else if (state == State.SIZE) {
63 decodeSize(in);
64 } else {
65 decodePayload(in, out);
66 }
67 }

References decodeOpcode(), decodePayload(), decodeSize(), com.runehive.net.codec.game.GamePacketDecoder.State.OPCODE, com.runehive.net.codec.game.GamePacketDecoder.State.SIZE, and state.

Here is the call graph for this function:

◆ decodeOpcode()

void com.runehive.net.codec.game.GamePacketDecoder.decodeOpcode ( ByteBuf in,
List< Object > out )
private

Decodes the packet identifier.

Parameters
inThe payload from the client.
outThe collection of upstream messages.

Definition at line 75 of file GamePacketDecoder.java.

75 {
76 if (in.isReadable()) {
77 opcode = (in.readByte() - decryptor.getKey()) & 0xFF;
78 type = PacketRepository.lookupType(opcode);
79 size = PacketRepository.lookupSize(opcode);
80 if (type == PacketType.EMPTY) {
81 state = State.OPCODE;
82 out.add(new GamePacket(opcode, type, Unpooled.EMPTY_BUFFER));
83 } else if (type == PacketType.FIXED) {
84 state = State.PAYLOAD;
85 } else if (type == PacketType.VAR_BYTE || type == PacketType.VAR_SHORT) {
86 state = State.SIZE;
87 } else {
88 throw new IllegalStateException(String.format("Illegal packet type=%s", type.name()));
89 }
90 }
91 }

References decryptor, com.runehive.net.packet.PacketType.EMPTY, com.runehive.net.packet.PacketType.FIXED, com.runehive.net.packet.PacketRepository.lookupSize(), com.runehive.net.packet.PacketRepository.lookupType(), com.runehive.net.codec.game.GamePacketDecoder.State.OPCODE, opcode, com.runehive.net.codec.game.GamePacketDecoder.State.PAYLOAD, com.runehive.net.codec.game.GamePacketDecoder.State.SIZE, size, state, type, com.runehive.net.packet.PacketType.VAR_BYTE, and com.runehive.net.packet.PacketType.VAR_SHORT.

Referenced by decode().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ decodePayload()

void com.runehive.net.codec.game.GamePacketDecoder.decodePayload ( ByteBuf in,
List< Object > out )
private

Decodes the packets payload.

Parameters
inThe payload from the client.
outThe collection of upstream messages.

Definition at line 113 of file GamePacketDecoder.java.

113 {
114 if (in.isReadable(size)) {
115 final PacketListener listener = PacketRepository.lookupListener(opcode);
116
117 if (listener != null) {
118 final ByteBuf payload = in.readBytes(size);
119 final GamePacket packet = new GamePacket(opcode, type, payload);
120 packet.retain();
121 out.add(packet);
122 } else {
123 in.skipBytes(size);
124 logger.info("No listener for client -> server packet={}", opcode);
125 }
126
127 state = State.OPCODE;
128 }
129 }

References logger, com.runehive.net.packet.PacketRepository.lookupListener(), com.runehive.net.codec.game.GamePacketDecoder.State.OPCODE, opcode, size, state, and type.

Referenced by decode().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ decodeSize()

void com.runehive.net.codec.game.GamePacketDecoder.decodeSize ( ByteBuf in)
private

Decodes the packets size.

Parameters
inThe payload from the client.

Definition at line 98 of file GamePacketDecoder.java.

98 {
99 if (in.isReadable()) {
100 size = in.readUnsignedByte();
101 if (size != 0) {
102 state = State.PAYLOAD;
103 }
104 }
105 }

References com.runehive.net.codec.game.GamePacketDecoder.State.PAYLOAD, size, and state.

Referenced by decode().

Here is the caller graph for this function:

Member Data Documentation

◆ decryptor

final IsaacCipher com.runehive.net.codec.game.GamePacketDecoder.decryptor
private

The isaac random used to decrypt a packets opcode.

Definition at line 32 of file GamePacketDecoder.java.

Referenced by decodeOpcode(), and GamePacketDecoder().

◆ logger

final Logger com.runehive.net.codec.game.GamePacketDecoder.logger = LogManager.getLogger(GamePacketDecoder.class)
staticprivate

The single logger for this class.

Definition at line 27 of file GamePacketDecoder.java.

Referenced by decodePayload().

◆ opcode

int com.runehive.net.codec.game.GamePacketDecoder.opcode
private

The current packet opcode.

Definition at line 37 of file GamePacketDecoder.java.

Referenced by decodeOpcode(), and decodePayload().

◆ size

int com.runehive.net.codec.game.GamePacketDecoder.size
private

The current packet size.

Definition at line 42 of file GamePacketDecoder.java.

Referenced by decodeOpcode(), decodePayload(), and decodeSize().

◆ state

State com.runehive.net.codec.game.GamePacketDecoder.state = State.OPCODE
private

The current state of this class.

Definition at line 52 of file GamePacketDecoder.java.

Referenced by decode(), decodeOpcode(), decodePayload(), and decodeSize().

◆ type

PacketType com.runehive.net.codec.game.GamePacketDecoder.type = PacketType.EMPTY
private

The current packet type.

Definition at line 47 of file GamePacketDecoder.java.

Referenced by decodeOpcode(), and decodePayload().


The documentation for this class was generated from the following file: