mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-02-22 03:40:54 +00:00
Client.cs: add OnReceivedError stuff
This commit is contained in:
parent
2253210489
commit
38f653ef3c
@ -19,7 +19,7 @@ namespace EpicTransport {
|
||||
private event Action OnConnected;
|
||||
public event Action OnDisconnected;
|
||||
// CHANGED
|
||||
private Action<string> SetTransportError;
|
||||
private event Action<TransportError, string> OnReceivedError;
|
||||
|
||||
private TimeSpan ConnectionTimeout;
|
||||
|
||||
@ -43,7 +43,7 @@ namespace EpicTransport {
|
||||
c.OnDisconnected += () => transport.OnClientDisconnected.Invoke();
|
||||
c.OnReceivedData += (data, channel) => transport.OnClientDataReceived.Invoke(new ArraySegment<byte>(data), channel);
|
||||
// CHANGED
|
||||
c.SetTransportError = transport.SetTransportError;
|
||||
c.OnReceivedError += (error, reason) => transport.OnClientError?.Invoke(error, reason);
|
||||
|
||||
return c;
|
||||
}
|
||||
@ -64,7 +64,7 @@ namespace EpicTransport {
|
||||
|
||||
if (await Task.WhenAny(connectedCompleteTask, Task.Delay(ConnectionTimeout/*, cancelToken.Token*/)) != connectedCompleteTask) {
|
||||
// CHANGED
|
||||
SetTransportError($"Connection to {host} timed out.");
|
||||
OnReceivedError?.Invoke(TransportError.Timeout, "Connection to {host} timed out.");
|
||||
Debug.LogError($"Connection to {host} timed out.");
|
||||
OnConnected -= SetConnectedComplete;
|
||||
OnConnectionFailed(hostProductId);
|
||||
@ -73,13 +73,13 @@ namespace EpicTransport {
|
||||
OnConnected -= SetConnectedComplete;
|
||||
} catch (FormatException) {
|
||||
// CHANGED
|
||||
SetTransportError("Connection string was not in the right format. Did you enter a ProductId?");
|
||||
OnReceivedError?.Invoke(TransportError.DnsResolve, "Connection string was not in the right format. Did you enter a ProductId?");
|
||||
Debug.LogError($"Connection string was not in the right format. Did you enter a ProductId?");
|
||||
Error = true;
|
||||
OnConnectionFailed(hostProductId);
|
||||
} catch (Exception ex) {
|
||||
// CHANGED
|
||||
SetTransportError(ex.Message);
|
||||
OnReceivedError?.Invoke(TransportError.Unexpected, ex.Message);
|
||||
Debug.LogError(ex.Message);
|
||||
Error = true;
|
||||
OnConnectionFailed(hostProductId);
|
||||
@ -158,7 +158,7 @@ namespace EpicTransport {
|
||||
break;
|
||||
case InternalMessages.DISCONNECT:
|
||||
// CHANGED
|
||||
SetTransportError("host disconnected");
|
||||
OnReceivedError?.Invoke(TransportError.ConnectionClosed, "host disconnected");
|
||||
Connected = false;
|
||||
Debug.Log("Disconnected.");
|
||||
|
||||
|
@ -93,7 +93,7 @@ namespace EpicTransport {
|
||||
Debug.Log($"Client with Product User ID {clientUserId} disconnected.");
|
||||
} else {
|
||||
// CHANGED
|
||||
OnReceivedError.Invoke(-1, TransportError.InvalidReceive, "ERROR Unknown Product User ID");
|
||||
OnReceivedError?.Invoke(-1, TransportError.InvalidReceive, "ERROR Unknown Product User ID");
|
||||
}
|
||||
|
||||
break;
|
||||
@ -109,7 +109,7 @@ namespace EpicTransport {
|
||||
}
|
||||
|
||||
if (epicToMirrorIds.TryGetValue(clientUserId, out int connectionId)) {
|
||||
OnReceivedData.Invoke(connectionId, data, channel);
|
||||
OnReceivedData?.Invoke(connectionId, data, channel);
|
||||
} else {
|
||||
SocketId socketId;
|
||||
epicToSocketIds.TryGetValue(clientUserId, out socketId);
|
||||
@ -120,7 +120,7 @@ namespace EpicTransport {
|
||||
|
||||
Debug.LogError("Data received from epic client thats not known " + productId);
|
||||
// CHANGED
|
||||
OnReceivedError.Invoke(-1, TransportError.InvalidReceive, "ERROR Unknown product ID");
|
||||
OnReceivedError?.Invoke(-1, TransportError.InvalidReceive, "ERROR Unknown product ID");
|
||||
}
|
||||
}
|
||||
|
||||
@ -158,7 +158,7 @@ namespace EpicTransport {
|
||||
} else {
|
||||
Debug.LogError("Trying to send on unknown connection: " + connectionId);
|
||||
// CHANGED
|
||||
OnReceivedError.Invoke(connectionId, TransportError.InvalidSend, "ERROR Unknown Connection");
|
||||
OnReceivedError?.Invoke(connectionId, TransportError.InvalidSend, "ERROR Unknown Connection");
|
||||
}
|
||||
|
||||
}
|
||||
@ -171,7 +171,7 @@ namespace EpicTransport {
|
||||
} else {
|
||||
Debug.LogError("Trying to get info on unknown connection: " + connectionId);
|
||||
// CHANGED
|
||||
OnReceivedError.Invoke(connectionId, TransportError.Unexpected, "ERROR Unknown Connection");
|
||||
OnReceivedError?.Invoke(connectionId, TransportError.Unexpected, "ERROR Unknown Connection");
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user