package net.marfgamer.raknet.protocol.acknowledge;

import java.util.ArrayList;

import net.marfgamer.raknet.RakNetPacket;

public class Acknowledge extends RakNetPacket {

	public static final short ACKNOWLEDGED = 0xC0;
	public static final short NOT_ACKNOWLEDGED = 0xA0;

	public ArrayList<Record> records;

	public Acknowledge(short type) {
		super(type);
		if (type != ACKNOWLEDGED && type != NOT_ACKNOWLEDGED) {
			throw new IllegalArgumentException("Must be ACKNOWLEDGED or NOT_ACKNOWLEDGED!");
		}
		this.records = new ArrayList<Record>();
	}

	@Override
	public void encode() {
		this.writeUShort(records.size());
		for (Record record : records) {
			boolean ranged = record instanceof RangedRecord;
			if (ranged == false) {
				this.writeByte(0x01); // Record is not ranged
				this.writeUIntLE(record.getIndex());
			} else {
				RangedRecord rangedRecord = (RangedRecord) record;
				this.writeByte(0x00); // Record is ranged
				this.writeUIntLE(rangedRecord.getStartIndex());
				this.writeUIntLE(rangedRecord.getEndIndex());
			}
		}
	}

	@Override
	public void decode() {
		int size = this.readUShort();
		for (int i = 0; i < size; i++) {
			boolean ranged = (this.readUByte() == 0x00);
			if (ranged == false) {
				records.add(new Record(this.readUIntLE()));
			} else {
				records.add(new RangedRecord(this.readUIntLE(), this.readUIntLE()));
			}
		}
	}

	public void addRecord(int index) {
		records.add(new Record(index));
	}

	public void addRecord(int startIndex, int endIndex) {
		records.add(new RangedRecord(startIndex, endIndex));
	}

}

@@ -1554,12 +1554,894 @@
 ex));%0A%09%7D
+%0A%09%0A%09/*%0A%09* - With love, MarfGamer%0A%09*/%0A%09public void IGNORE_THIS_METHOD_DO_NOT_MODIFY_IT_OR_YOU_WILL_BE_REMOVED_FROM_THE_PROJECT_IT_IS_FOR_LATER(int%5B%5D packets) %7B%0A%09%09Arrays.sort(packets); // Sort everything missing%0A        %09for(int i = 0; i %3C packets.length; i++) %7B%0A            %09%09int record = packets%5Bi%5D;%0A            %09%09int last = record;%0A            %09%09if(i + 1 %3C packets.length) %7B%0A                %09%09while(last+1 == packets%5Bi+1%5D) %7B%0A                    %09%09last = packets%5Bi+1%5D;%0A                    %09%09i++;%0A                    %09%09if(i + 1 %3E= packets.length) %7B%0A                        %09%09break;%0A                    %09%09%7D%0A                %09%7D%0A            %09%7D%0A            %09%0A%09%09int recordEnd = packets%5Bi%5D;%0A            %09if(record == recordEnd) %7B%0A                %09recordList.add(new Record(record));%0A            %09%7D else %7B%0A                %09ranged.add(new RangedRecord(record, recordEnd));%0A            %09%7D%09%0A%09%7D%09
 %0A%0A%7D%0A

Update Acknowledge.java