RuneHive-Game
Loading...
Searching...
No Matches
GamePacketEncoder.java
Go to the documentation of this file.
1package com.runehive.net.codec.game;
2
3import com.runehive.net.packet.GamePacket;
4import com.runehive.net.packet.PacketType;
5import com.runehive.net.codec.IsaacCipher;
6import io.netty.buffer.ByteBuf;
7import io.netty.channel.ChannelHandlerContext;
8import io.netty.handler.codec.MessageToByteEncoder;
9
10public class GamePacketEncoder extends MessageToByteEncoder<GamePacket> {
11
12 private final IsaacCipher encryptor;
13
15 this.encryptor = encryptor;
16 }
17
18 @Override
19 protected void encode(ChannelHandlerContext ctx, GamePacket packet, ByteBuf out) throws Exception {
20 out.writeByte((packet.getOpcode() + (encryptor.getKey() & 0xFF)) & 0xFF);
21 if (packet.getHeader() == PacketType.VAR_BYTE) {
22 out.writeByte(packet.getSize());
23 } else if (packet.getHeader() == PacketType.VAR_SHORT) {
24 out.writeShort(packet.getSize());
25 }
26 out.writeBytes(packet.getPayload());
27 }
28
29}
An implementation of an ISAAC cipher.
void encode(ChannelHandlerContext ctx, GamePacket packet, ByteBuf out)
Represents a single game packet.
Represents a type of packet.
VAR_SHORT
A variable packet where the size is indicated by a short.
VAR_BYTE
A variable packet where the size is indicated by a byte.