From 38f653ef3ce003cd286049a1e7a53641ddd41ad8 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Sun, 7 May 2023 17:46:50 -0700 Subject: [PATCH] Client.cs: add OnReceivedError stuff --- EpicOnlineTransport/Client.cs | 12 ++++++------ EpicOnlineTransport/Server.cs | 10 +++++----- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/EpicOnlineTransport/Client.cs b/EpicOnlineTransport/Client.cs index 4ee1616b..a6a68dd9 100644 --- a/EpicOnlineTransport/Client.cs +++ b/EpicOnlineTransport/Client.cs @@ -19,7 +19,7 @@ namespace EpicTransport { private event Action OnConnected; public event Action OnDisconnected; // CHANGED - private Action SetTransportError; + private event Action OnReceivedError; private TimeSpan ConnectionTimeout; @@ -43,7 +43,7 @@ namespace EpicTransport { c.OnDisconnected += () => transport.OnClientDisconnected.Invoke(); c.OnReceivedData += (data, channel) => transport.OnClientDataReceived.Invoke(new ArraySegment(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."); diff --git a/EpicOnlineTransport/Server.cs b/EpicOnlineTransport/Server.cs index f12bf8a1..8f1c441e 100644 --- a/EpicOnlineTransport/Server.cs +++ b/EpicOnlineTransport/Server.cs @@ -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; } }