2020-08-02 02:50:01 +02:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Net;
|
2020-08-05 03:21:04 +02:00
|
|
|
|
using System;
|
|
|
|
|
|
2020-08-05 18:50:28 +02:00
|
|
|
|
using NeonTea.Quakeball.TeaNet.Packets;
|
2020-08-02 02:50:01 +02:00
|
|
|
|
|
2020-08-05 18:50:28 +02:00
|
|
|
|
namespace NeonTea.Quakeball.TeaNet.Peers {
|
2020-08-02 02:50:01 +02:00
|
|
|
|
public class Connection {
|
|
|
|
|
|
|
|
|
|
public IPEndPoint Endpoint;
|
2020-08-05 19:39:52 +02:00
|
|
|
|
public ulong uid;
|
2020-08-05 03:21:04 +02:00
|
|
|
|
public ConnectionStatus Status;
|
|
|
|
|
public ClosingReason ClosingReason;
|
|
|
|
|
|
2020-08-05 19:39:52 +02:00
|
|
|
|
public ConnectionInternalData Internal = new ConnectionInternalData();
|
2020-08-02 02:50:01 +02:00
|
|
|
|
|
2020-08-05 03:21:04 +02:00
|
|
|
|
public Connection(IPEndPoint endpoint, ConnectionStatus status = ConnectionStatus.Establishing) {
|
|
|
|
|
Endpoint = endpoint;
|
|
|
|
|
Status = status;
|
2020-08-05 19:39:52 +02:00
|
|
|
|
|
|
|
|
|
Internal.LastMessage = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
|
|
|
|
Internal.LatestInwardReliable = -1;
|
|
|
|
|
Internal.LatestInwardUnreliable = -1;
|
|
|
|
|
Internal.LatestOutwardReliable = -1;
|
|
|
|
|
Internal.LatestOutwardUnreliable = -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsReady() {
|
|
|
|
|
return Status == ConnectionStatus.Ready;
|
2020-08-02 02:50:01 +02:00
|
|
|
|
}
|
2020-08-05 19:39:52 +02:00
|
|
|
|
|
|
|
|
|
public bool IsDisconnected() {
|
|
|
|
|
return !(Status == ConnectionStatus.Ready
|
|
|
|
|
|| Status == ConnectionStatus.Awaiting
|
|
|
|
|
|| Status == ConnectionStatus.Establishing);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public struct ConnectionInternalData {
|
|
|
|
|
public byte AssignedProtocol;
|
|
|
|
|
public long LastMessage;
|
|
|
|
|
public int LatestOutwardReliable; // Last reliable Packet ID the connection has told us they have
|
|
|
|
|
public int LatestOutwardUnreliable; // Last unreliablePacket ID the connection has told us they have
|
|
|
|
|
public int LatestInwardReliable; // Last reliable Packet ID we've received from the connection
|
|
|
|
|
public int LatestInwardUnreliable; // Last unreliable Packet ID we've received from the connection
|
|
|
|
|
|
|
|
|
|
public int ReliablePacketIDCounter; // Reliable Packet ID counter for packets we're sending them
|
|
|
|
|
public int UnreliablePacketIDCounter; // Unreliable Packet ID counter for packets we're sending them
|
2020-08-02 02:50:01 +02:00
|
|
|
|
}
|
2020-08-02 20:32:30 +02:00
|
|
|
|
|
|
|
|
|
public enum ConnectionStatus {
|
2020-08-05 03:21:04 +02:00
|
|
|
|
Awaiting, // Awaiting an establishing
|
|
|
|
|
Establishing, // Attempting to establish
|
|
|
|
|
Ready, // Ready for packet sending
|
|
|
|
|
Rejected, // Rejected connection at endpoint, sending Rejected
|
|
|
|
|
Closed, // Closed connection at endpoint, sending Closed
|
|
|
|
|
Stopped, // Not sending packages
|
|
|
|
|
Lost, // Connection Lost
|
2020-08-02 20:32:30 +02:00
|
|
|
|
}
|
2020-08-02 02:50:01 +02:00
|
|
|
|
}
|