/// <summary>
    /// Checks the packets that were send and triggers the OnMessageLost if a packet was in the list for too long.
    /// </summary>
    public void CheckPacketsSend()
    {
        //gets all the packets send
        Dictionary <int, Packet> .ValueCollection values = _packetsSend.Values;

        int keyToRemove = 0;

        //check the time of each packet
        foreach (Packet packet in values)
        {
            //if the time difference between the current time and the time send is too big it will save the sequence number of the "lost" packet and break out of the loop
            if (Mathf.Abs(packet.GetTimeSent() - Time.time) > 0.2f)
            {
                Debug.Log("Packet: " + packet.GetPacketSequenceNumber() + " was lost on his epic quest." + Time.time);

                keyToRemove = packet.GetPacketSequenceNumber();

                OnMessageLost?.Invoke(packet);

                break;
            }
        }

        //if it found a key (packet sequence number) it will remove the packet and writes the packet sequence number to a debug document
        if (keyToRemove > 0)
        {
            _packetsSend.Remove(keyToRemove);

            if (!File.Exists(_path))
            {
                File.WriteAllText(_path, keyToRemove + Environment.NewLine);
            }
            else
            {
                File.AppendAllText(_path, keyToRemove + Environment.NewLine);
            }
        }
    }
Ejemplo n.º 2
0
 public override void OnLost(Message message)
 {
     OnMessageLost?.Invoke(message.Type, message.GetContent());
 }