Client.cs: add OnReceivedError stuff

This commit is contained in:
JohnCorby 2023-05-07 17:46:50 -07:00
parent 2253210489
commit 38f653ef3c
2 changed files with 11 additions and 11 deletions

View File

@ -19,7 +19,7 @@ namespace EpicTransport {
private event Action OnConnected; private event Action OnConnected;
public event Action OnDisconnected; public event Action OnDisconnected;
// CHANGED // CHANGED
private Action<string> SetTransportError; private event Action<TransportError, string> OnReceivedError;
private TimeSpan ConnectionTimeout; private TimeSpan ConnectionTimeout;
@ -43,7 +43,7 @@ namespace EpicTransport {
c.OnDisconnected += () => transport.OnClientDisconnected.Invoke(); c.OnDisconnected += () => transport.OnClientDisconnected.Invoke();
c.OnReceivedData += (data, channel) => transport.OnClientDataReceived.Invoke(new ArraySegment<byte>(data), channel); c.OnReceivedData += (data, channel) => transport.OnClientDataReceived.Invoke(new ArraySegment<byte>(data), channel);
// CHANGED // CHANGED
c.SetTransportError = transport.SetTransportError; c.OnReceivedError += (error, reason) => transport.OnClientError?.Invoke(error, reason);
return c; return c;
} }
@ -64,7 +64,7 @@ namespace EpicTransport {
if (await Task.WhenAny(connectedCompleteTask, Task.Delay(ConnectionTimeout/*, cancelToken.Token*/)) != connectedCompleteTask) { if (await Task.WhenAny(connectedCompleteTask, Task.Delay(ConnectionTimeout/*, cancelToken.Token*/)) != connectedCompleteTask) {
// CHANGED // CHANGED
SetTransportError($"Connection to {host} timed out."); OnReceivedError?.Invoke(TransportError.Timeout, "Connection to {host} timed out.");
Debug.LogError($"Connection to {host} timed out."); Debug.LogError($"Connection to {host} timed out.");
OnConnected -= SetConnectedComplete; OnConnected -= SetConnectedComplete;
OnConnectionFailed(hostProductId); OnConnectionFailed(hostProductId);
@ -73,13 +73,13 @@ namespace EpicTransport {
OnConnected -= SetConnectedComplete; OnConnected -= SetConnectedComplete;
} catch (FormatException) { } catch (FormatException) {
// CHANGED // 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?"); Debug.LogError($"Connection string was not in the right format. Did you enter a ProductId?");
Error = true; Error = true;
OnConnectionFailed(hostProductId); OnConnectionFailed(hostProductId);
} catch (Exception ex) { } catch (Exception ex) {
// CHANGED // CHANGED
SetTransportError(ex.Message); OnReceivedError?.Invoke(TransportError.Unexpected, ex.Message);
Debug.LogError(ex.Message); Debug.LogError(ex.Message);
Error = true; Error = true;
OnConnectionFailed(hostProductId); OnConnectionFailed(hostProductId);
@ -158,7 +158,7 @@ namespace EpicTransport {
break; break;
case InternalMessages.DISCONNECT: case InternalMessages.DISCONNECT:
// CHANGED // CHANGED
SetTransportError("host disconnected"); OnReceivedError?.Invoke(TransportError.ConnectionClosed, "host disconnected");
Connected = false; Connected = false;
Debug.Log("Disconnected."); Debug.Log("Disconnected.");

View File

@ -93,7 +93,7 @@ namespace EpicTransport {
Debug.Log($"Client with Product User ID {clientUserId} disconnected."); Debug.Log($"Client with Product User ID {clientUserId} disconnected.");
} else { } else {
// CHANGED // CHANGED
OnReceivedError.Invoke(-1, TransportError.InvalidReceive, "ERROR Unknown Product User ID"); OnReceivedError?.Invoke(-1, TransportError.InvalidReceive, "ERROR Unknown Product User ID");
} }
break; break;
@ -109,7 +109,7 @@ namespace EpicTransport {
} }
if (epicToMirrorIds.TryGetValue(clientUserId, out int connectionId)) { if (epicToMirrorIds.TryGetValue(clientUserId, out int connectionId)) {
OnReceivedData.Invoke(connectionId, data, channel); OnReceivedData?.Invoke(connectionId, data, channel);
} else { } else {
SocketId socketId; SocketId socketId;
epicToSocketIds.TryGetValue(clientUserId, out socketId); epicToSocketIds.TryGetValue(clientUserId, out socketId);
@ -120,7 +120,7 @@ namespace EpicTransport {
Debug.LogError("Data received from epic client thats not known " + productId); Debug.LogError("Data received from epic client thats not known " + productId);
// CHANGED // 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 { } else {
Debug.LogError("Trying to send on unknown connection: " + connectionId); Debug.LogError("Trying to send on unknown connection: " + connectionId);
// CHANGED // CHANGED
OnReceivedError.Invoke(connectionId, TransportError.InvalidSend, "ERROR Unknown Connection"); OnReceivedError?.Invoke(connectionId, TransportError.InvalidSend, "ERROR Unknown Connection");
} }
} }
@ -171,7 +171,7 @@ namespace EpicTransport {
} else { } else {
Debug.LogError("Trying to get info on unknown connection: " + connectionId); Debug.LogError("Trying to get info on unknown connection: " + connectionId);
// CHANGED // CHANGED
OnReceivedError.Invoke(connectionId, TransportError.Unexpected, "ERROR Unknown Connection"); OnReceivedError?.Invoke(connectionId, TransportError.Unexpected, "ERROR Unknown Connection");
return string.Empty; return string.Empty;
} }
} }