Search in sources :

Example 1 with BinaryStream

use of org.dragonet.utilities.BinaryStream in project Dragonet-Legacy by DragonetMC.

the class AcknowledgePacket method encode.

@Override
public void encode() {
    super.encode();
    int count = this.packets.size();
    int[] packets = new int[count];
    int index = 0;
    for (int i : this.packets.values()) {
        packets[index++] = i;
    }
    short records = 0;
    BinaryStream payload = new BinaryStream();
    if (count > 0) {
        int pointer = 1;
        int start = packets[0];
        int last = packets[0];
        while (pointer < count) {
            int current = packets[pointer++];
            int diff = current - last;
            if (diff == 1) {
                last = current;
            } else if (diff > 1) {
                if (start == last) {
                    payload.putByte((byte) 0x01);
                    payload.put(Binary.writeLTriad(start));
                    start = last = current;
                } else {
                    payload.putByte((byte) 0x00);
                    payload.put(Binary.writeLTriad(start));
                    payload.put(Binary.writeLTriad(last));
                    start = last = current;
                }
                ++records;
            }
        }
        if (start == last) {
            payload.putByte((byte) 0x01);
            payload.put(Binary.writeLTriad(start));
        } else {
            payload.putByte((byte) 0x00);
            payload.put(Binary.writeLTriad(start));
            payload.put(Binary.writeLTriad(last));
        }
        ++records;
    }
    this.putShort(records);
    this.buffer = Binary.appendBytes(this.buffer, payload.getBuffer());
}
Also used : BinaryStream(org.dragonet.utilities.BinaryStream)

Example 2 with BinaryStream

use of org.dragonet.utilities.BinaryStream in project Dragonet-Legacy by DragonetMC.

the class Session method handleSplit.

private void handleSplit(final 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(org.dragonet.utilities.BinaryStream) EncapsulatedPacket(org.dragonet.raknet.protocol.EncapsulatedPacket)

Aggregations

BinaryStream (org.dragonet.utilities.BinaryStream)2 EncapsulatedPacket (org.dragonet.raknet.protocol.EncapsulatedPacket)1