Search in sources :

Example 6 with EncapsulatedPacket

use of org.dragonet.raknet.protocol.EncapsulatedPacket in project Dragonet-Legacy by DragonetMC.

the class RakNetInterface method sendPacket.

public void sendPacket(String identifier, PEPacket packet, boolean needACK, boolean immediate) {
    packet.encode();
    byte[] buffer = packet.getData();
    if (buffer.length > 1024 && !BatchPacket.class.isAssignableFrom(packet.getClass())) {
        BatchPacket batch = new BatchPacket();
        batch.packets.add(packet);
        sendPacket(identifier, batch, needACK, immediate);
        return;
    }
    EncapsulatedPacket encapsulated = new EncapsulatedPacket();
    encapsulated.buffer = buffer;
    encapsulated.needACK = needACK;
    encapsulated.reliability = needACK ? (byte) 2 : (byte) 3;
    encapsulated.messageIndex = 0;
    this.handler.sendEncapsulated(identifier, encapsulated, (needACK ? RakNet.FLAG_NEED_ACK : 0) | (immediate ? RakNet.PRIORITY_IMMEDIATE : RakNet.PRIORITY_NORMAL));
}
Also used : BatchPacket(org.dragonet.net.packet.minecraft.BatchPacket) EncapsulatedPacket(org.dragonet.raknet.protocol.EncapsulatedPacket)

Aggregations

EncapsulatedPacket (org.dragonet.raknet.protocol.EncapsulatedPacket)6 CLIENT_CONNECT_DataPacket (org.dragonet.raknet.protocol.packet.CLIENT_CONNECT_DataPacket)2 CLIENT_HANDSHAKE_DataPacket (org.dragonet.raknet.protocol.packet.CLIENT_HANDSHAKE_DataPacket)2 PING_DataPacket (org.dragonet.raknet.protocol.packet.PING_DataPacket)2 PONG_DataPacket (org.dragonet.raknet.protocol.packet.PONG_DataPacket)2 SERVER_HANDSHAKE_DataPacket (org.dragonet.raknet.protocol.packet.SERVER_HANDSHAKE_DataPacket)2 BatchPacket (org.dragonet.net.packet.minecraft.BatchPacket)1 DataPacket (org.dragonet.raknet.protocol.DataPacket)1 ACK (org.dragonet.raknet.protocol.packet.ACK)1 CLIENT_DISCONNECT_DataPacket (org.dragonet.raknet.protocol.packet.CLIENT_DISCONNECT_DataPacket)1 NACK (org.dragonet.raknet.protocol.packet.NACK)1 OPEN_CONNECTION_REPLY_1 (org.dragonet.raknet.protocol.packet.OPEN_CONNECTION_REPLY_1)1 OPEN_CONNECTION_REPLY_2 (org.dragonet.raknet.protocol.packet.OPEN_CONNECTION_REPLY_2)1 OPEN_CONNECTION_REQUEST_1 (org.dragonet.raknet.protocol.packet.OPEN_CONNECTION_REQUEST_1)1 OPEN_CONNECTION_REQUEST_2 (org.dragonet.raknet.protocol.packet.OPEN_CONNECTION_REQUEST_2)1 BinaryStream (org.dragonet.utilities.BinaryStream)1