Make some neatness updates
This commit is contained in:
parent
63eddfa43b
commit
7b426f4f8c
@ -12,10 +12,9 @@ namespace NeonTea.Quakeball.Net.Peers {
|
|||||||
private Peer Peer;
|
private Peer Peer;
|
||||||
|
|
||||||
private Thread UpdateThread;
|
private Thread UpdateThread;
|
||||||
private long LastUpdate;
|
|
||||||
|
|
||||||
public long Timeout = 8000;
|
public long Timeout = 8000;
|
||||||
public long Frequency = 100;
|
public long Interval = 100;
|
||||||
|
|
||||||
public ConnectionManager(Peer peer) {
|
public ConnectionManager(Peer peer) {
|
||||||
Peer = peer;
|
Peer = peer;
|
||||||
@ -159,40 +158,38 @@ namespace NeonTea.Quakeball.Net.Peers {
|
|||||||
|
|
||||||
private void UpdateThreadMethod() {
|
private void UpdateThreadMethod() {
|
||||||
try {
|
try {
|
||||||
while (true) {
|
while (Thread.CurrentThread.IsAlive) {
|
||||||
long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
||||||
if ((now - LastUpdate) > Frequency) {
|
List<KeyValuePair<IPEndPoint, Connection>> timedOut = new List<KeyValuePair<IPEndPoint, Connection>>();
|
||||||
LastUpdate = now;
|
foreach (KeyValuePair<IPEndPoint, Connection> pair in Connections) {
|
||||||
List<KeyValuePair<IPEndPoint, Connection>> timedOut = new List<KeyValuePair<IPEndPoint, Connection>>();
|
Connection conn = pair.Value;
|
||||||
foreach (KeyValuePair<IPEndPoint, Connection> pair in Connections) {
|
if ((now - conn.LastMessage) > Timeout || conn.Status == ConnectionStatus.Lost) {
|
||||||
Connection conn = pair.Value;
|
timedOut.Add(pair);
|
||||||
if ((now - conn.LastMessage) > Timeout || conn.Status == ConnectionStatus.Lost) {
|
|
||||||
timedOut.Add(pair);
|
|
||||||
}
|
|
||||||
if (conn.Status != ConnectionStatus.Awaiting || conn.Status != ConnectionStatus.Stopped) {
|
|
||||||
if (conn.Status == ConnectionStatus.Ready) {
|
|
||||||
SendPacketQueue(conn);
|
|
||||||
} else {
|
|
||||||
SendPlain(conn);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
foreach (KeyValuePair<IPEndPoint, Connection> pair in timedOut) {
|
if (conn.Status != ConnectionStatus.Awaiting || conn.Status != ConnectionStatus.Stopped) {
|
||||||
Connections.Remove(pair.Key);
|
if (conn.Status == ConnectionStatus.Ready) {
|
||||||
PacketQueue.Remove(pair.Value);
|
SendPacketQueue(conn);
|
||||||
if (pair.Value.Status == ConnectionStatus.Ready
|
} else {
|
||||||
|| pair.Value.Status == ConnectionStatus.Establishing
|
SendPlain(conn);
|
||||||
|| pair.Value.Status == ConnectionStatus.Awaiting
|
|
||||||
|| pair.Value.Status == ConnectionStatus.Lost) {
|
|
||||||
Protocol protocol = Peer.GetProtocol(pair.Value.AssignedProtocol);
|
|
||||||
if (protocol != null) {
|
|
||||||
protocol.Timeout(pair.Value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
foreach (KeyValuePair<IPEndPoint, Connection> pair in timedOut) {
|
||||||
|
Connections.Remove(pair.Key);
|
||||||
|
PacketQueue.Remove(pair.Value);
|
||||||
|
if (pair.Value.Status == ConnectionStatus.Ready
|
||||||
|
|| pair.Value.Status == ConnectionStatus.Establishing
|
||||||
|
|| pair.Value.Status == ConnectionStatus.Awaiting
|
||||||
|
|| pair.Value.Status == ConnectionStatus.Lost) {
|
||||||
|
Protocol protocol = Peer.GetProtocol(pair.Value.AssignedProtocol);
|
||||||
|
if (protocol != null) {
|
||||||
|
protocol.Timeout(pair.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Thread.Sleep((int)Interval);
|
||||||
}
|
}
|
||||||
} catch (ThreadAbortException e) {
|
} catch (ThreadAbortException) {
|
||||||
Debug.Log("Connection Thread Stopped");
|
Debug.Log("Connection Thread Stopped");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,26 +44,28 @@ namespace NeonTea.Quakeball.Net.Peers {
|
|||||||
|
|
||||||
private void ListenThreadMethod() {
|
private void ListenThreadMethod() {
|
||||||
try {
|
try {
|
||||||
while (true) {
|
while (Thread.CurrentThread.IsAlive) {
|
||||||
IPEndPoint Listened = new IPEndPoint(EndPoint.Address, EndPoint.Port);
|
if (Peer.UdpClient.Available > 0) {
|
||||||
ByteBuffer Buffer = new ByteBuffer();
|
IPEndPoint Listened = new IPEndPoint(EndPoint.Address, EndPoint.Port);
|
||||||
try {
|
ByteBuffer Buffer = new ByteBuffer();
|
||||||
Buffer = new ByteBuffer(Peer.UdpClient.Receive(ref Listened));
|
try {
|
||||||
} catch (SocketException e) {
|
Buffer = new ByteBuffer(Peer.UdpClient.Receive(ref Listened));
|
||||||
if (Array.Exists(CONN_LOST_CODES, x => x == e.ErrorCode)) {
|
} catch (SocketException e) {
|
||||||
if (LastSentConnection != null) {
|
if (Array.Exists(CONN_LOST_CODES, x => x == e.ErrorCode)) {
|
||||||
LastSentConnection.Status = ConnectionStatus.Lost;
|
if (LastSentConnection != null) {
|
||||||
Peer.MessageListener.Message($"Connection lost to {LastSentConnection.Endpoint}: {e.ToString()}");
|
LastSentConnection.Status = ConnectionStatus.Lost;
|
||||||
|
Peer.MessageListener.Message($"Connection lost to {LastSentConnection.Endpoint}: {e.ToString()}");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Peer.MessageListener.Message($"Listener error: {e.ToString()}");
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
Peer.MessageListener.Message($"Listener error: {e.ToString()}");
|
if (Buffer.ReadFingerprint(Peer.Fingerprint)) {
|
||||||
|
Peer.ConnectionManager.Handle(Listened, Buffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (Buffer.ReadFingerprint(Peer.Fingerprint)) {
|
|
||||||
Peer.ConnectionManager.Handle(Listened, Buffer);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (ThreadAbortException e) {
|
} catch (ThreadAbortException) {
|
||||||
Debug.Log("Listener Thread stopped");
|
Debug.Log("Listener Thread stopped");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -129,6 +129,7 @@ PlayerSettings:
|
|||||||
preloadedAssets:
|
preloadedAssets:
|
||||||
- {fileID: 0}
|
- {fileID: 0}
|
||||||
- {fileID: 0}
|
- {fileID: 0}
|
||||||
|
- {fileID: 0}
|
||||||
metroInputSource: 0
|
metroInputSource: 0
|
||||||
wsaTransparentSwapchain: 0
|
wsaTransparentSwapchain: 0
|
||||||
m_HolographicPauseOnTrackingLoss: 1
|
m_HolographicPauseOnTrackingLoss: 1
|
||||||
|
Loading…
Reference in New Issue
Block a user