My New Year's resolution is to stop making commits like these
This commit is contained in:
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.ServiceProcess;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@@ -15,38 +16,23 @@ namespace Torch.Server
|
||||
{
|
||||
public static class Program
|
||||
{
|
||||
private static readonly ITorchServer _server = new TorchServer();
|
||||
private static TorchUI _ui;
|
||||
private static ITorchServer _server;
|
||||
|
||||
[STAThread]
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
_server.Init();
|
||||
_server.RunArgs = new[] { "-console" };
|
||||
_ui = new TorchUI(_server);
|
||||
|
||||
if (args.Contains("-nogui"))
|
||||
_server.Start();
|
||||
if (!Environment.UserInteractive)
|
||||
{
|
||||
using (var service = new TorchService())
|
||||
{
|
||||
ServiceBase.Run(service);
|
||||
}
|
||||
}
|
||||
else
|
||||
StartUI();
|
||||
|
||||
if (args.Contains("-autostart") && !_server.IsRunning)
|
||||
new Thread(() => _server.Start()).Start();
|
||||
|
||||
Dispatcher.Run();
|
||||
}
|
||||
|
||||
public static void StartUI()
|
||||
{
|
||||
Thread.CurrentThread.Name = "UI Thread";
|
||||
_ui.Show();
|
||||
}
|
||||
|
||||
public static void FullRestart()
|
||||
{
|
||||
_server.Stop();
|
||||
Process.Start("TorchServer.exe", "-autostart");
|
||||
Environment.Exit(1);
|
||||
{
|
||||
_server = new TorchServer();
|
||||
_server.Init();
|
||||
_server.Start();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -67,8 +67,10 @@
|
||||
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\SteamSDK.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Configuration.Install" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.ServiceProcess" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
@@ -104,6 +106,12 @@
|
||||
<Reference Include="PresentationFramework" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="TorchService.cs">
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
<Compile Include="TorchServiceInstaller.cs">
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
<Compile Include="ViewModels\ConfigDedicatedViewModel.cs" />
|
||||
<Compile Include="Views\AddWorkshopItemsDialog.xaml.cs">
|
||||
<DependentUpon>AddWorkshopItemsDialog.xaml</DependentUpon>
|
||||
|
@@ -33,11 +33,12 @@ namespace Torch.Server
|
||||
internal TorchServer()
|
||||
{
|
||||
MySession.OnLoading += OnSessionLoading;
|
||||
Plugins = new PluginManager();
|
||||
}
|
||||
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
|
||||
SpaceEngineersGame.SetupBasicGameInfo();
|
||||
SpaceEngineersGame.SetupPerGameSettings();
|
||||
MyPerGameSettings.SendLogToKeen = false;
|
||||
@@ -78,7 +79,7 @@ namespace Torch.Server
|
||||
throw new InvalidOperationException("Server is already running.");
|
||||
|
||||
IsRunning = true;
|
||||
Logger.Write("Starting server.");
|
||||
Log.Write("Starting server.");
|
||||
|
||||
if (MySandboxGame.Log.LogEnabled)
|
||||
MySandboxGame.Log.Close();
|
||||
@@ -93,13 +94,13 @@ namespace Torch.Server
|
||||
{
|
||||
if (Thread.CurrentThread.ManagedThreadId != ServerThread?.ManagedThreadId)
|
||||
{
|
||||
Logger.Write("Requesting server stop.");
|
||||
Log.Write("Requesting server stop.");
|
||||
MySandboxGame.Static.Invoke(Stop);
|
||||
_stopHandle.WaitOne();
|
||||
return;
|
||||
}
|
||||
|
||||
Logger.Write("Stopping server.");
|
||||
Log.Write("Stopping server.");
|
||||
MySession.Static.Save();
|
||||
MySession.Static.Unload();
|
||||
MySandboxGame.Static.Exit();
|
||||
@@ -111,7 +112,7 @@ namespace Torch.Server
|
||||
VRage.Input.MyInput.UnloadData();
|
||||
CleanupProfilers();
|
||||
|
||||
Logger.Write("Server stopped.");
|
||||
Log.Write("Server stopped.");
|
||||
_stopHandle.Set();
|
||||
IsRunning = false;
|
||||
}
|
||||
|
54
Torch.Server/TorchService.cs
Normal file
54
Torch.Server/TorchService.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.ServiceProcess;
|
||||
using Torch.API;
|
||||
|
||||
namespace Torch.Server
|
||||
{
|
||||
class TorchService : ServiceBase
|
||||
{
|
||||
public const string Name = "Torch (SEDS)";
|
||||
private readonly ITorchServer _server = new TorchServer();
|
||||
|
||||
public TorchService()
|
||||
{
|
||||
ServiceName = Name;
|
||||
EventLog.Log = "Application";
|
||||
|
||||
CanHandlePowerEvent = true;
|
||||
CanHandleSessionChangeEvent = false;
|
||||
CanPauseAndContinue = false;
|
||||
CanStop = true;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnStart(string[] args)
|
||||
{
|
||||
base.OnStart(args);
|
||||
_server.Init();
|
||||
_server.Start();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnStop()
|
||||
{
|
||||
_server.Stop();
|
||||
base.OnStop();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnShutdown()
|
||||
{
|
||||
base.OnShutdown();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override bool OnPowerEvent(PowerBroadcastStatus powerStatus)
|
||||
{
|
||||
return base.OnPowerEvent(powerStatus);
|
||||
}
|
||||
}
|
||||
}
|
61
Torch.Server/TorchServiceInstaller.cs
Normal file
61
Torch.Server/TorchServiceInstaller.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Configuration.Install;
|
||||
using System.Linq;
|
||||
using System.ServiceProcess;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Torch.Server
|
||||
{
|
||||
[RunInstaller(true)]
|
||||
class TorchServiceInstaller : Installer
|
||||
{
|
||||
private ServiceInstaller _serviceInstaller;
|
||||
|
||||
public TorchServiceInstaller()
|
||||
{
|
||||
var serviceProcessInstaller = new ServiceProcessInstaller();
|
||||
_serviceInstaller = new ServiceInstaller();
|
||||
|
||||
serviceProcessInstaller.Account = ServiceAccount.LocalSystem;
|
||||
serviceProcessInstaller.Username = null;
|
||||
serviceProcessInstaller.Password = null;
|
||||
|
||||
_serviceInstaller.DisplayName = "Torch (SEDS)";
|
||||
_serviceInstaller.Description = "Service for Torch (SE Dedicated Server)";
|
||||
_serviceInstaller.StartType = ServiceStartMode.Manual;
|
||||
|
||||
_serviceInstaller.ServiceName = TorchService.Name;
|
||||
|
||||
Installers.Add(serviceProcessInstaller);
|
||||
Installers.Add(_serviceInstaller);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Install(IDictionary stateSaver)
|
||||
{
|
||||
GetServiceName();
|
||||
base.Install(stateSaver);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Uninstall(IDictionary savedState)
|
||||
{
|
||||
GetServiceName();
|
||||
base.Uninstall(savedState);
|
||||
}
|
||||
|
||||
private void GetServiceName()
|
||||
{
|
||||
var name = Context.Parameters["name"];
|
||||
if (string.IsNullOrEmpty(name))
|
||||
return;
|
||||
|
||||
_serviceInstaller.DisplayName = name;
|
||||
_serviceInstaller.ServiceName = name;
|
||||
}
|
||||
}
|
||||
}
|
@@ -88,7 +88,7 @@ namespace Torch.Server
|
||||
|
||||
private void BtnRestart_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Program.FullRestart();
|
||||
//Program.FullRestart();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user