RuneHive-Game
Loading...
Searching...
No Matches
OutgoingPacket.java
Go to the documentation of this file.
1package com.runehive.net.packet;
2
3import com.runehive.game.world.entity.mob.player.Player;
4import com.runehive.net.session.GameSession;
5
6public abstract class OutgoingPacket {
7
8 private final int opcode;
9 private final PacketType type;
10 protected final PacketBuilder builder;
11
12 public OutgoingPacket(int opcode, int capacity) {
13 this(opcode, PacketType.FIXED, capacity);
14 }
15
17 this.opcode = opcode;
18 this.type = type;
19 this.builder = PacketBuilder.alloc();
20 }
21
22 public OutgoingPacket(int opcode, PacketType type, int size) {
23 this.opcode = opcode;
24 this.type = type;
25 this.builder = PacketBuilder.alloc(size, size);
26 }
27
28 protected abstract boolean encode(Player player);
29
30 public void execute(Player player) {
31 if (player.isBot) {
32 builder.release();
33 return;
34 }
35 if (!encode(player)) {
36 builder.release();
37 return;
38 }
39
40 if (!player.getSession().isPresent()) {
41 builder.release();
42 return;
43 }
44
45 GameSession session = player.getSession().get();
46 session.queueServerPacket(builder.toPacket(opcode, type));
47 }
48
49}
This class represents a character controlled by a player.
Definition Player.java:125
abstract boolean encode(Player player)
OutgoingPacket(int opcode, PacketType type)
OutgoingPacket(int opcode, int capacity)
OutgoingPacket(int opcode, PacketType type, int size)
The implementation that functions as a dynamic buffer wrapper backed by a ByteBuf that is used for re...
static PacketBuilder alloc(int initialCapacity, int maxCapacity)
Represents a Session when a Player has been authenticated and active in the game world.
Represents a type of packet.
FIXED
A fixed size packet where the size never changes.