Search in sources :

Example 1 with PackettoPlayerEvent

use of org.dragonet.proxy.events.defaults.packets.PackettoPlayerEvent in project DragonProxy by DragonetMC.

the class UpstreamSession method sendPacket.

// if sending a packer before spawn, you should set high_priority to true !
public void sendPacket(PEPacket packet, boolean high_priority) {
    if (packet == null)
        return;
    if (!proxy.getConfig().disable_packet_events) {
        PackettoPlayerEvent packetEvent = new PackettoPlayerEvent(this, packet);
        proxy.getEventManager().callEvent(packetEvent);
        packet = packetEvent.getPacket();
    }
    // cache in case of not spawned and no high priority
    if (!spawned && !high_priority) {
        putCachePacket(packet);
        return;
    }
    while (!cachedPackets.isEmpty()) // TODO sendAllPackets
    sendPacket(cachedPackets.poll(), true);
    try (Timing timing = Timings.getSendDataPacketTiming(packet)) {
        packet.encode();
        byte[] buffer;
        try {
            buffer = Zlib.deflate(Binary.appendBytes(Binary.writeUnsignedVarInt(packet.getBuffer().length), packet.getBuffer()), Deflater.BEST_COMPRESSION);
        } catch (Exception e) {
            timing.stopTiming();
            e.printStackTrace();
            return;
        }
        raknetClient.sendMessage(Reliability.RELIABLE_ORDERED, 0, new com.whirvis.jraknet.Packet(Binary.appendBytes((byte) 0xfe, buffer)));
    }
}
Also used : PackettoPlayerEvent(org.dragonet.proxy.events.defaults.packets.PackettoPlayerEvent) Timing(co.aikar.timings.Timing) RequestException(com.github.steveice10.mc.auth.exception.request.RequestException)

Aggregations

Timing (co.aikar.timings.Timing)1 RequestException (com.github.steveice10.mc.auth.exception.request.RequestException)1 PackettoPlayerEvent (org.dragonet.proxy.events.defaults.packets.PackettoPlayerEvent)1