Search in sources :

Example 6 with EncapsulatedPacket

use of cn.nukkit.raknet.protocol.EncapsulatedPacket in project Nukkit by Nukkit.

the class Session method handleSplit.

private void handleSplit(EncapsulatedPacket packet) throws Exception {
    if (packet.splitCount >= MAX_SPLIT_SIZE || packet.splitIndex >= MAX_SPLIT_SIZE || packet.splitIndex < 0) {
        return;
    }
    if (!this.splitPackets.containsKey(packet.splitID)) {
        if (this.splitPackets.size() >= MAX_SPLIT_COUNT) {
            return;
        }
        this.splitPackets.put(packet.splitID, new HashMap<Integer, EncapsulatedPacket>() {

            {
                put(packet.splitIndex, packet);
            }
        });
    } else {
        this.splitPackets.get(packet.splitID).put(packet.splitIndex, packet);
    }
    if (this.splitPackets.get(packet.splitID).size() == packet.splitCount) {
        EncapsulatedPacket pk = new EncapsulatedPacket();
        BinaryStream stream = new BinaryStream();
        for (int i = 0; i < packet.splitCount; i++) {
            stream.put(this.splitPackets.get(packet.splitID).get(i).buffer);
        }
        pk.buffer = stream.getBuffer();
        pk.length = pk.buffer.length;
        this.splitPackets.remove(packet.splitID);
        this.handleEncapsulatedPacketRoute(pk);
    }
}
Also used : BinaryStream(cn.nukkit.utils.BinaryStream) EncapsulatedPacket(cn.nukkit.raknet.protocol.EncapsulatedPacket)

Aggregations

EncapsulatedPacket (cn.nukkit.raknet.protocol.EncapsulatedPacket)6 Player (cn.nukkit.Player)1 DataPacket (cn.nukkit.network.protocol.DataPacket)1 DataPacket (cn.nukkit.raknet.protocol.DataPacket)1 PING_DataPacket (cn.nukkit.raknet.protocol.packet.PING_DataPacket)1 BinaryStream (cn.nukkit.utils.BinaryStream)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1