Skip to content

Commit

Permalink
Update disconnection reason
Browse files Browse the repository at this point in the history
  • Loading branch information
starfi5h committed Dec 7, 2022
1 parent 2b7ad6d commit 1e96f28
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
23 changes: 14 additions & 9 deletions NebulaNetwork/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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.",
Expand All @@ -349,17 +360,11 @@ private static void DisableNagleAlgorithm(WebSocket socket)
}
}

private readonly AccessTools.FieldRef<WebSocket, MemoryStream> fragmentsBufferRef = AccessTools.FieldRefAccess<WebSocket, MemoryStream>("_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);
}
}
}
1 change: 1 addition & 0 deletions NebulaNetwork/Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 1e96f28

Please sign in to comment.