//endregion
}
protected void SendPacketFinal(NetworkManager.OutgoingPacket outgoingPacket)
{
UDPPacketBuffer buffer = outgoingPacket.Buffer;
byte flags = buffer.getData()[0];
boolean isResend = (flags & Helpers.MSG_RESENT) != 0;
boolean isReliable = (flags & Helpers.MSG_RELIABLE) != 0;
// Keep track of when this packet was sent out (right now)
outgoingPacket.TickCount = Utils.getUnixTime();
//region ACK Appending
int dataLength = buffer.getDataLength();
// Keep appending ACKs until there is no room left in the packet or there are
// no more ACKs to append
//uint
long ackCount = 0;
//uint
Long ack;
while (dataLength + 5 < Packet.MTU && ((ack = PendingAcks.poll())!=null))
{
Utils.uintToBytes(ack, buffer.getData(), dataLength);
dataLength += 4;
++ackCount;
}
if (ackCount > 0)
{
// Set the last byte of the packet equal to the number of appended ACKs
buffer.getData()[dataLength++] = (byte)ackCount;
// Set the appended ACKs flag on this packet
buffer.getData()[0] |= Helpers.MSG_APPENDED_ACKS;
}
buffer.setDataLength(dataLength);
//endregion ACK Appending
if (!isResend)
{
// Not a resend, assign a new sequence number
//uint
long sequenceNumber = Sequence.incrementAndGet();
Utils.uintToBytes(sequenceNumber, buffer.getData(), 1);
outgoingPacket.SequenceNumber = sequenceNumber;
if (isReliable)
{
// Add this packet to the list of ACK responses we are waiting on from the server