Plugin system working, Windows service and command system in progress

This commit is contained in:
John Gross
2017-01-05 02:49:43 -08:00
parent e0a4ee9ce0
commit 4949982fa8
24 changed files with 352 additions and 132 deletions

View File

@@ -27,10 +27,11 @@ namespace Torch.Server
{
public Thread GameThread { get; private set; }
public bool IsRunning { get; private set; }
public bool IsService { get; set; }
public event Action SessionLoading;
private readonly ManualResetEvent _stopHandle = new ManualResetEvent(false);
private readonly AutoResetEvent _stopHandle = new AutoResetEvent(false);
internal TorchServer()
{
@@ -85,7 +86,15 @@ namespace Torch.Server
MySandboxGame.IsDedicated = true;
Environment.SetEnvironmentVariable("SteamAppId", MyPerServerSettings.AppId.ToString());
Reflection.InvokeStaticMethod(typeof(DedicatedServer), "RunMain", "Torch", null, true);
Log.Trace("Invoking RunMain");
try { Reflection.InvokeStaticMethod(typeof(DedicatedServer), "RunMain", "Torch", null, IsService, true); }
catch (Exception e)
{
Log.Error(e);
throw;
}
Log.Trace("RunMain completed");
IsRunning = false;
}
/// <summary>
@@ -93,11 +102,15 @@ namespace Torch.Server
/// </summary>
public override void Stop()
{
if (Thread.CurrentThread.ManagedThreadId != GameThread?.ManagedThreadId)
if (!IsRunning)
Log.Error("Server is already stopped");
if (Thread.CurrentThread.ManagedThreadId != GameThread?.ManagedThreadId && MySandboxGame.Static.IsRunning)
{
Log.Info("Requesting server stop.");
MySandboxGame.Static.Invoke(Stop);
_stopHandle.WaitOne();
_stopHandle.WaitOne(10000);
Log.Error("Server stop timed out.");
return;
}