From 1e96f285c6c3a25638ac91d9c2fb67b5d42d584c Mon Sep 17 00:00:00 2001 From: starfish <50672801+starfi5h@users.noreply.github.com> Date: Mon, 28 Nov 2022 01:09:42 +0800 Subject: [PATCH] Update disconnection reason --- NebulaNetwork/Client.cs | 23 ++++++++++++++--------- NebulaNetwork/Server.cs | 1 + 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/NebulaNetwork/Client.cs b/NebulaNetwork/Client.cs index 5b59dbb6e..a5d623671 100644 --- a/NebulaNetwork/Client.cs +++ b/NebulaNetwork/Client.cs @@ -315,6 +315,16 @@ private void ClientSocket_OnClose(object sender, CloseEventArgs e) return; } + if (e.Code == (ushort)DisconnectionReason.HostStillLoading) + { + InGamePopup.ShowWarning( + "Server Busy", + "Server is not ready to join. Please try again later.", + "OK".Translate(), + Multiplayer.LeaveGame); + return; + } + if (Multiplayer.Session.IsGameLoaded || Multiplayer.Session.IsInLobby) { InGamePopup.ShowWarning( @@ -331,6 +341,7 @@ private void ClientSocket_OnClose(object sender, CloseEventArgs e) } else { + Log.Warn("Disconnect code: " + e.Code + ", reason:" + e.Reason); InGamePopup.ShowWarning( "Server Unavailable", $"Could not reach the server, please try again later.", @@ -349,17 +360,11 @@ private static void DisableNagleAlgorithm(WebSocket socket) } } + private readonly AccessTools.FieldRef fragmentsBufferRef = AccessTools.FieldRefAccess("_fragmentsBuffer"); private int GetFragmentBufferLength() { - MemoryStream buffer = (MemoryStream)AccessTools.Field(typeof(WebSocket), "_fragmentsBuffer").GetValue(clientSocket); - if (buffer != null) - { - return (int)buffer.Length; - } - else - { - return 0; - } + MemoryStream fragmentsBuffer = fragmentsBufferRef(clientSocket); + return (int)(fragmentsBuffer?.Length ?? 0); } } } diff --git a/NebulaNetwork/Server.cs b/NebulaNetwork/Server.cs index c65080112..87311cbf3 100644 --- a/NebulaNetwork/Server.cs +++ b/NebulaNetwork/Server.cs @@ -130,6 +130,7 @@ public override void Start() { InGamePopup.ShowError("Error", "An error occurred while hosting the game: " + e.Message, "Close"); Stop(); + Multiplayer.LeaveGame(); return; }