quakeball/Assets/Scripts/TeaNet/Peers/Connection.cs

62 lines
2.4 KiB
C#

using System.Collections;
using System.Collections.Generic;
using System.Net;
using System;
using NeonTea.Quakeball.TeaNet.Packets;
namespace NeonTea.Quakeball.TeaNet.Peers {
public class Connection {
public IPEndPoint Endpoint;
public ulong uid;
public ConnectionStatus Status;
public ClosingReason ClosingReason;
public ConnectionInternalData Internal = new ConnectionInternalData();
public Connection(IPEndPoint endpoint, ConnectionStatus status = ConnectionStatus.Establishing) {
Endpoint = endpoint;
Status = status;
Internal.LastMessage = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
Internal.LatestInwardReliable = -1;
Internal.LatestInwardUnreliable = -1;
Internal.LatestOutwardReliable = -1;
Internal.LatestOutwardUnreliable = -1;
}
public bool IsReady() {
return Status == ConnectionStatus.Ready;
}
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
}
public enum ConnectionStatus {
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
}
}