Build 0.20.9.0
This commit is contained in:
@@ -1,12 +1,15 @@
|
||||
using System.Diagnostics;
|
||||
using System.IO.Pipes;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
|
||||
namespace Barotrauma.Networking
|
||||
{
|
||||
static partial class ChildServerRelay
|
||||
{
|
||||
public static Process Process;
|
||||
public static bool IsProcessAlive => Process is { HasExited: false };
|
||||
|
||||
private static bool localHandlesDisposed;
|
||||
private static AnonymousPipeServerStream writePipe;
|
||||
private static AnonymousPipeServerStream readPipe;
|
||||
@@ -44,18 +47,27 @@ namespace Barotrauma.Networking
|
||||
localHandlesDisposed = true;
|
||||
}
|
||||
|
||||
public static void ClosePipes()
|
||||
public static void AttemptGracefulShutDown(int maxAttempts = 20)
|
||||
{
|
||||
writePipe?.Dispose(); writePipe = null;
|
||||
readPipe?.Dispose(); readPipe = null;
|
||||
shutDown = true;
|
||||
status = StatusEnum.RequestedShutDown;
|
||||
writeManualResetEvent?.Set();
|
||||
int checks = 0;
|
||||
while (Process is { HasExited: false })
|
||||
{
|
||||
if (checks >= maxAttempts)
|
||||
{
|
||||
DebugConsole.AddWarning("Server could not be shut down gracefully");
|
||||
break;
|
||||
}
|
||||
Thread.Sleep(100);
|
||||
checks++;
|
||||
}
|
||||
ForceShutDown();
|
||||
}
|
||||
|
||||
public static void ShutDown()
|
||||
|
||||
public static void ForceShutDown()
|
||||
{
|
||||
Process?.Kill(); Process = null;
|
||||
writePipe = null; readPipe = null;
|
||||
|
||||
PrivateShutDown();
|
||||
}
|
||||
|
||||
|
||||
@@ -332,10 +332,27 @@ namespace Barotrauma.Networking
|
||||
};
|
||||
}
|
||||
|
||||
public void CreateServerCrashMessage()
|
||||
{
|
||||
// Close any message boxes that say "The server has crashed."
|
||||
var basicServerCrashMsg = TextManager.Get($"{nameof(DisconnectReason)}.{nameof(DisconnectReason.ServerCrashed)}");
|
||||
GUIMessageBox.MessageBoxes
|
||||
.OfType<GUIMessageBox>()
|
||||
.Where(mb => mb.Text?.Text == basicServerCrashMsg)
|
||||
.ToArray()
|
||||
.ForEach(mb => mb.Close());
|
||||
|
||||
// Open a new message box with the crash report path
|
||||
if (GUIMessageBox.MessageBoxes.All(
|
||||
mb => (mb as GUIMessageBox)?.Text?.Text != ChildServerRelay.CrashMessage))
|
||||
{
|
||||
var msgBox = new GUIMessageBox(TextManager.Get("ConnectionLost"), ChildServerRelay.CrashMessage);
|
||||
msgBox.Buttons[0].OnClicked += ReturnToPreviousMenu;
|
||||
}
|
||||
}
|
||||
|
||||
private bool ReturnToPreviousMenu(GUIButton button, object obj)
|
||||
{
|
||||
Quit();
|
||||
|
||||
Submarine.Unload();
|
||||
GameMain.Client = null;
|
||||
GameMain.GameSession = null;
|
||||
@@ -531,14 +548,10 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
if (GameMain.WindowActive)
|
||||
{
|
||||
if (ChildServerRelay.Process?.HasExited ?? true)
|
||||
if (!ChildServerRelay.IsProcessAlive)
|
||||
{
|
||||
Quit();
|
||||
if (!GUIMessageBox.MessageBoxes.Any(mb => (mb as GUIMessageBox)?.Text?.Text == ChildServerRelay.CrashMessage))
|
||||
{
|
||||
var msgBox = new GUIMessageBox(TextManager.Get("ConnectionLost"), ChildServerRelay.CrashMessage);
|
||||
msgBox.Buttons[0].OnClicked += ReturnToPreviousMenu;
|
||||
}
|
||||
CreateServerCrashMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -942,13 +955,6 @@ namespace Barotrauma.Networking
|
||||
|
||||
GUI.ClearCursorWait();
|
||||
|
||||
ChildServerRelay.ShutDown();
|
||||
|
||||
if (SteamManager.IsInitialized)
|
||||
{
|
||||
Steamworks.SteamFriends.ClearRichPresence();
|
||||
}
|
||||
|
||||
if (disconnectPacket.ShouldCreateAnalyticsEvent)
|
||||
{
|
||||
GameAnalyticsManager.AddErrorEventOnce(
|
||||
@@ -974,11 +980,43 @@ namespace Barotrauma.Networking
|
||||
}
|
||||
else
|
||||
{
|
||||
ReturnToPreviousMenu(null, null);
|
||||
new GUIMessageBox(TextManager.Get(wasConnected ? "ConnectionLost" : "CouldNotConnectToServer"), disconnectPacket.PopupMessage)
|
||||
if (ClientPeer is SteamP2PClientPeer or SteamP2POwnerPeer)
|
||||
{
|
||||
DisplayInLoadingScreens = true
|
||||
};
|
||||
SteamManager.LeaveLobby();
|
||||
}
|
||||
|
||||
GameMain.ModDownloadScreen.Reset();
|
||||
ContentPackageManager.EnabledPackages.Restore();
|
||||
|
||||
CampaignMode.StartRoundCancellationToken?.Cancel();
|
||||
|
||||
if (SteamManager.IsInitialized)
|
||||
{
|
||||
Steamworks.SteamFriends.ClearRichPresence();
|
||||
}
|
||||
foreach (var fileTransfer in FileReceiver.ActiveTransfers.ToArray())
|
||||
{
|
||||
FileReceiver.StopTransfer(fileTransfer, deleteFile: true);
|
||||
}
|
||||
|
||||
ChildServerRelay.AttemptGracefulShutDown();
|
||||
GUIMessageBox.MessageBoxes.RemoveAll(c => c?.UserData is RoundSummary);
|
||||
|
||||
characterInfo?.Remove();
|
||||
|
||||
VoipClient?.Dispose();
|
||||
VoipClient = null;
|
||||
GameMain.Client = null;
|
||||
GameMain.GameSession = null;
|
||||
|
||||
ReturnToPreviousMenu(null, null);
|
||||
if (disconnectPacket.DisconnectReason != DisconnectReason.Disconnected)
|
||||
{
|
||||
new GUIMessageBox(TextManager.Get(wasConnected ? "ConnectionLost" : "CouldNotConnectToServer"), disconnectPacket.PopupMessage)
|
||||
{
|
||||
DisplayInLoadingScreens = true
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2538,46 +2576,9 @@ namespace Barotrauma.Networking
|
||||
|
||||
public void Quit()
|
||||
{
|
||||
if (ClientPeer is SteamP2PClientPeer || ClientPeer is SteamP2POwnerPeer)
|
||||
{
|
||||
SteamManager.LeaveLobby();
|
||||
}
|
||||
|
||||
GameMain.ModDownloadScreen.Reset();
|
||||
ContentPackageManager.EnabledPackages.Restore();
|
||||
|
||||
CampaignMode.StartRoundCancellationToken?.Cancel();
|
||||
|
||||
ClientPeer?.Close(PeerDisconnectPacket.WithReason(DisconnectReason.Disconnected));
|
||||
ClientPeer = null;
|
||||
|
||||
foreach (var fileTransfer in FileReceiver.ActiveTransfers.ToArray())
|
||||
{
|
||||
FileReceiver.StopTransfer(fileTransfer, deleteFile: true);
|
||||
}
|
||||
|
||||
if (ChildServerRelay.Process != null)
|
||||
{
|
||||
int checks = 0;
|
||||
while (ChildServerRelay.Process is { HasExited: false })
|
||||
{
|
||||
if (checks > 10)
|
||||
{
|
||||
ChildServerRelay.ShutDown();
|
||||
}
|
||||
Thread.Sleep(100);
|
||||
checks++;
|
||||
}
|
||||
}
|
||||
ChildServerRelay.ShutDown();
|
||||
|
||||
GUIMessageBox.MessageBoxes.RemoveAll(c => c?.UserData is RoundSummary);
|
||||
|
||||
characterInfo?.Remove();
|
||||
|
||||
VoipClient?.Dispose();
|
||||
VoipClient = null;
|
||||
GameMain.Client = null;
|
||||
GameMain.GameSession = null;
|
||||
}
|
||||
|
||||
public void SendCharacterInfo(string newName = null)
|
||||
|
||||
+3
-7
@@ -91,15 +91,11 @@ namespace Barotrauma.Networking
|
||||
ToolBox.ThrowIfNull(netClient);
|
||||
ToolBox.ThrowIfNull(incomingLidgrenMessages);
|
||||
|
||||
if (isOwner && !(ChildServerRelay.Process is { HasExited: false }))
|
||||
if (isOwner && !ChildServerRelay.IsProcessAlive)
|
||||
{
|
||||
var gameClient = GameMain.Client;
|
||||
Close(PeerDisconnectPacket.WithReason(DisconnectReason.ServerCrashed));
|
||||
var msgBox = new GUIMessageBox(TextManager.Get("ConnectionLost"), ChildServerRelay.CrashMessage);
|
||||
msgBox.Buttons[0].OnClicked += (btn, obj) =>
|
||||
{
|
||||
GameMain.MainMenuScreen.Select();
|
||||
return false;
|
||||
};
|
||||
gameClient?.CreateServerCrashMessage();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
+3
-9
@@ -187,15 +187,11 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
if (!isActive) { return; }
|
||||
|
||||
if (ChildServerRelay.HasShutDown || !(ChildServerRelay.Process is { HasExited: false }))
|
||||
if (ChildServerRelay.HasShutDown || !ChildServerRelay.IsProcessAlive)
|
||||
{
|
||||
var gameClient = GameMain.Client;
|
||||
Close(PeerDisconnectPacket.WithReason(DisconnectReason.ServerCrashed));
|
||||
var msgBox = new GUIMessageBox(TextManager.Get("ConnectionLost"), ChildServerRelay.CrashMessage);
|
||||
msgBox.Buttons[0].OnClicked += (btn, obj) =>
|
||||
{
|
||||
GameMain.MainMenuScreen.Select();
|
||||
return false;
|
||||
};
|
||||
gameClient?.CreateServerCrashMessage();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -401,8 +397,6 @@ namespace Barotrauma.Networking
|
||||
ClosePeerSession(remotePeers[i]);
|
||||
}
|
||||
|
||||
ChildServerRelay.ClosePipes();
|
||||
|
||||
callbacks.OnDisconnect.Invoke(peerDisconnectPacket);
|
||||
|
||||
SteamManager.LeaveLobby();
|
||||
|
||||
@@ -17,9 +17,7 @@ namespace Barotrauma.Networking
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public static IReadOnlyList<string> CaptureDeviceNames =>
|
||||
Alc.GetStringList(IntPtr.Zero, OpenAL.Alc.CaptureDeviceSpecifier);
|
||||
|
||||
|
||||
private readonly IntPtr captureDevice;
|
||||
|
||||
@@ -169,6 +167,11 @@ namespace Barotrauma.Networking
|
||||
Create(GameSettings.CurrentConfig.Audio.VoiceCaptureDevice, storedBufferID);
|
||||
}
|
||||
|
||||
public static IReadOnlyList<string> GetCaptureDeviceNames()
|
||||
{
|
||||
return Alc.GetStringList(IntPtr.Zero, OpenAL.Alc.CaptureDeviceSpecifier);
|
||||
}
|
||||
|
||||
IntPtr nativeBuffer;
|
||||
readonly short[] uncompressedBuffer = new short[VoipConfig.BUFFER_SIZE];
|
||||
readonly short[] prevUncompressedBuffer = new short[VoipConfig.BUFFER_SIZE];
|
||||
|
||||
Reference in New Issue
Block a user