RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
OutgoingPacket.java
1package com.osroyale.net.packet;
2
3import com.osroyale.game.world.entity.mob.player.Player;
4import com.osroyale.net.session.GameSession;
5
28
29public abstract class OutgoingPacket {
30
31 private final int opcode;
32 private final PacketType type;
33 protected final PacketBuilder builder;
34
35 public OutgoingPacket(int opcode, int capacity) {
36 this(opcode, PacketType.FIXED, capacity);
37 }
38
39 public OutgoingPacket(int opcode, PacketType type) {
40 this.opcode = opcode;
41 this.type = type;
42 this.builder = PacketBuilder.alloc();
43 }
44
45 public OutgoingPacket(int opcode, PacketType type, int size) {
46 this.opcode = opcode;
47 this.type = type;
48 this.builder = PacketBuilder.alloc(size, size);
49 }
50
51 protected abstract boolean encode(Player player);
52
53 public void execute(Player player) {
54 if (player.isBot) {
55 builder.release();
56 return;
57 }
58 if (!encode(player)) {
59 builder.release();
60 return;
61 }
62
63 if (!player.getSession().isPresent()) {
64 builder.release();
65 return;
66 }
67
68 GameSession session = player.getSession().get();
69 session.queueServerPacket(builder.toPacket(opcode, type));
70 }
71
72}