private void ResendUnacked()
{
if (NeedAck.Count > 0)
{
NetworkManager.OutgoingPacket[] array;
lock (NeedAck)
{
// Create a temporary copy of the outgoing packets array to iterate over
array = new NetworkManager.OutgoingPacket[NeedAck.Count];
NeedAck.Values.CopyTo(array, 0);
}
int now = Environment.TickCount;
// Resend packets
for (int i = 0; i < array.Length; i++)
{
NetworkManager.OutgoingPacket outgoing = array[i];
if (outgoing.TickCount != 0 && now - outgoing.TickCount > Client.Settings.RESEND_TIMEOUT)
{
if (outgoing.ResendCount < Client.Settings.MAX_RESEND_COUNT)
{
if (Client.Settings.LOG_RESENDS)
{
Logger.DebugLog(String.Format("Resending packet #{0} ({1}), {2}ms have passed",
outgoing.Packet.Header.Sequence, outgoing.Packet.GetType(),
now - outgoing.TickCount), Client);
}
// The TickCount will be set to the current time when the packet
// is actually sent out again
outgoing.TickCount = 0;
outgoing.SetSequence = false;
outgoing.Packet.Header.Resent = true;
++outgoing.ResendCount;
++Stats.ResentPackets;
SendPacket(outgoing);
}
else
{
Logger.DebugLog(String.Format("Dropping packet #{0} ({1}) after {2} failed attempts",
outgoing.Packet.Header.Sequence, outgoing.Packet.GetType(), outgoing.ResendCount));
lock (NeedAck) NeedAck.Remove(outgoing.Packet.Header.Sequence);
}
}
}
}
}