From 3ea2d5d9e615b6d5cf2f42a9b92ff32701fdb7e4 Mon Sep 17 00:00:00 2001 From: James Frowen Date: Tue, 9 Jul 2024 18:27:26 +0100 Subject: [PATCH] fix: disconnecting player if send buffer is full Full send buffer will throw, This will cause issues when sending to multiple clients if just one of their send buffers is full --- Assets/Mirage/Runtime/NetworkPlayer.cs | 40 ++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/Assets/Mirage/Runtime/NetworkPlayer.cs b/Assets/Mirage/Runtime/NetworkPlayer.cs index 620ea77306..ba78a2597b 100644 --- a/Assets/Mirage/Runtime/NetworkPlayer.cs +++ b/Assets/Mirage/Runtime/NetworkPlayer.cs @@ -203,15 +203,29 @@ public void Send(T message, Channel channelId = Channel.Reliable) /// public void Send(ArraySegment segment, Channel channelId = Channel.Reliable) { - if (_isDisconnected) { return; } + if (_isDisconnected) + return; - if (channelId == Channel.Reliable) + try { - _connection.SendReliable(segment); + if (channelId == Channel.Reliable) + { + _connection.SendReliable(segment); + } + else + { + _connection.SendUnreliable(segment); + } } - else + catch (BufferFullException e) { - _connection.SendUnreliable(segment); + logger.LogError($"Disconnecting player because send buffer was full. {e}"); + Disconnect(); + } + catch (NoConnectionException e) + { + logger.LogError($"Inner connection was disconnected, but disconnected flag not yet. {e}"); + Disconnect(); } } @@ -233,7 +247,21 @@ public void Send(T message, INotifyCallBack callBacks) var segment = writer.ToArraySegment(); NetworkDiagnostics.OnSend(message, segment.Count, 1); if (logger.LogEnabled()) logger.Log($"Sending {typeof(T)} to {this} channel:Notify"); - _connection.SendNotify(segment, callBacks); + + try + { + _connection.SendNotify(segment, callBacks); + } + catch (BufferFullException e) + { + logger.LogError($"Disconnecting player because send buffer was full. {e}"); + Disconnect(); + } + catch (NoConnectionException e) + { + logger.LogError($"Inner connection was disconnected, but disconnected flag not yet. {e}"); + Disconnect(); + } } }