Merge branch 'master' into Patron

This commit is contained in:
John Gross
2019-09-19 11:34:09 -07:00
7 changed files with 111 additions and 14 deletions

View File

@@ -254,6 +254,7 @@ quit";
private void HandleException(object sender, UnhandledExceptionEventArgs e)
{
_server.FatalException = true;
var ex = (Exception)e.ExceptionObject;
LogException(ex);
if (MyFakes.ENABLE_MINIDUMP_SENDING)

View File

@@ -63,7 +63,7 @@ namespace Torch.Server
// Breaks on Windows Server 2019
if (!new ComputerInfo().OSFullName.Contains("Server 2019") && !Environment.UserInteractive)
{
using (var service = new TorchService())
using (var service = new TorchService(args))
ServiceBase.Run(service);
return;
}

View File

@@ -49,6 +49,8 @@ namespace Torch.Server
private Timer _watchdog;
private int _players;
private MultiplayerManagerDedicated _multiplayerManagerDedicated;
internal bool FatalException { get; set; }
/// <inheritdoc />
public TorchServer(TorchConfig config = null)
@@ -232,10 +234,16 @@ namespace Torch.Server
private static void CheckServerResponding(object state)
{
var server = (TorchServer)state;
var mre = new ManualResetEvent(false);
((TorchServer)state).Invoke(() => mre.Set());
server.Invoke(() => mre.Set());
if (!mre.WaitOne(TimeSpan.FromSeconds(Instance.Config.TickTimeout)))
{
if (server.FatalException)
{
server._watchdog.Dispose();
return;
}
#if DEBUG
Log.Error(
$"Server watchdog detected that the server was frozen for at least {((TorchServer) state).Config.TickTimeout} seconds.");

View File

@@ -1,10 +1,12 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ServiceProcess;
using System.Threading;
using NLog;
using Torch.API;
@@ -12,12 +14,14 @@ namespace Torch.Server
{
class TorchService : ServiceBase
{
private static readonly Logger Log = LogManager.GetCurrentClassLogger();
public const string Name = "Torch (SEDS)";
private TorchServer _server;
private Initializer _initializer;
private string[] _args;
public TorchService()
public TorchService(string[] args)
{
_args = args;
var workingDir = new FileInfo(typeof(TorchService).Assembly.Location).Directory.ToString();
Directory.SetCurrentDirectory(workingDir);
_initializer = new Initializer(workingDir);
@@ -29,19 +33,21 @@ namespace Torch.Server
}
/// <inheritdoc />
protected override void OnStart(string[] args)
protected override void OnStart(string[] _)
{
base.OnStart(args);
base.OnStart(_args);
_initializer.Initialize(args);
_initializer.Initialize(_args);
_initializer.Run();
}
/// <inheritdoc />
protected override void OnStop()
{
_server.Stop();
base.OnStop();
var mre = new ManualResetEvent(false);
Task.Run(() => _initializer.Server.Stop());
if (!mre.WaitOne(TimeSpan.FromMinutes(1)))
Process.GetCurrentProcess().Kill();
}
}
}