Update NLog, change init order, fix block delete in UI, change config to JSON
This commit is contained in:
@@ -30,5 +30,10 @@ namespace Torch.API.Managers
|
|||||||
/// Disposes all loaded plugins.
|
/// Disposes all loaded plugins.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
void DisposePlugins();
|
void DisposePlugins();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Load plugins.
|
||||||
|
/// </summary>
|
||||||
|
void LoadPlugins();
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -56,6 +56,8 @@ namespace Torch.Server.Managers
|
|||||||
Directory.CreateDirectory(savesPath);
|
Directory.CreateDirectory(savesPath);
|
||||||
var modsPath = Path.Combine(path, "Mods");
|
var modsPath = Path.Combine(path, "Mods");
|
||||||
Directory.CreateDirectory(modsPath);
|
Directory.CreateDirectory(modsPath);
|
||||||
|
var configPath = Path.Combine(path, "SpaceEngineers-Dedicated.cfg");
|
||||||
|
new MyConfigDedicated<MyObjectBuilder_SessionSettings>(configPath).Save();
|
||||||
LoadInstance(path);
|
LoadInstance(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -23,6 +23,7 @@ using Torch.Server.Views;
|
|||||||
using VRage.Game.ModAPI;
|
using VRage.Game.ModAPI;
|
||||||
using System.IO.Compression;
|
using System.IO.Compression;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
using System.Security.Policy;
|
||||||
using Torch.Server.Managers;
|
using Torch.Server.Managers;
|
||||||
using VRage.FileSystem;
|
using VRage.FileSystem;
|
||||||
using VRageRender;
|
using VRageRender;
|
||||||
@@ -61,37 +62,22 @@ namespace Torch.Server
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var configName = "TorchConfig.xml";
|
//CommandLine reflection triggers assembly loading, so DS update must be completely separated.
|
||||||
var configPath = Path.Combine(Directory.GetCurrentDirectory(), configName);
|
if (!args.Contains("-noupdate"))
|
||||||
if (File.Exists(configName))
|
|
||||||
{
|
{
|
||||||
_log.Info($"Loading config {configPath}");
|
if (!Directory.Exists("DedicatedServer64"))
|
||||||
_config = TorchConfig.LoadFrom(configPath);
|
{
|
||||||
|
_log.Error("Game libraries not found. Press the Enter key to install the dedicated server.");
|
||||||
|
Console.ReadLine();
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
_log.Info($"Generating default config at {configPath}");
|
|
||||||
_config = new TorchConfig {InstancePath = Path.GetFullPath("Instance")};
|
|
||||||
|
|
||||||
_log.Warn("Would you like to enable automatic updates? (Y/n):");
|
|
||||||
|
|
||||||
var input = Console.ReadLine() ?? "";
|
|
||||||
var autoUpdate = string.IsNullOrEmpty(input) || input.Equals("y", StringComparison.InvariantCultureIgnoreCase);
|
|
||||||
_config.GetTorchUpdates = _config.GetPluginUpdates = autoUpdate;
|
|
||||||
if (autoUpdate)
|
|
||||||
{
|
|
||||||
_log.Info("Automatic updates enabled.");
|
|
||||||
RunSteamCmd();
|
RunSteamCmd();
|
||||||
}
|
}
|
||||||
|
|
||||||
_config.Save(configPath);
|
InitConfig();
|
||||||
}
|
|
||||||
|
|
||||||
if (!_config.Parse(args))
|
if (!_config.Parse(args))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
_log.Debug(_config.ToString());
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(_config.WaitForPID))
|
if (!string.IsNullOrEmpty(_config.WaitForPID))
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@@ -110,14 +96,26 @@ namespace Torch.Server
|
|||||||
}
|
}
|
||||||
|
|
||||||
_restartOnCrash = _config.RestartOnCrash;
|
_restartOnCrash = _config.RestartOnCrash;
|
||||||
|
|
||||||
if (_config.GetTorchUpdates || _config.Update)
|
|
||||||
{
|
|
||||||
RunSteamCmd();
|
|
||||||
}
|
|
||||||
RunServer(_config);
|
RunServer(_config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void InitConfig()
|
||||||
|
{
|
||||||
|
var configName = "Torch.cfg";
|
||||||
|
var configPath = Path.Combine(Directory.GetCurrentDirectory(), configName);
|
||||||
|
if (File.Exists(configName))
|
||||||
|
{
|
||||||
|
_log.Info($"Loading config {configPath}");
|
||||||
|
_config = TorchConfig.LoadFrom(configPath);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_log.Info($"Generating default config at {configPath}");
|
||||||
|
_config = new TorchConfig { InstancePath = Path.GetFullPath("Instance") };
|
||||||
|
_config.Save(configPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private const string STEAMCMD_DIR = "steamcmd";
|
private const string STEAMCMD_DIR = "steamcmd";
|
||||||
private const string STEAMCMD_ZIP = "temp.zip";
|
private const string STEAMCMD_ZIP = "temp.zip";
|
||||||
private static readonly string STEAMCMD_PATH = $"{STEAMCMD_DIR}\\steamcmd.exe";
|
private static readonly string STEAMCMD_PATH = $"{STEAMCMD_DIR}\\steamcmd.exe";
|
||||||
|
@@ -59,9 +59,11 @@
|
|||||||
<HintPath>..\GameBinaries\Microsoft.CodeAnalysis.CSharp.dll</HintPath>
|
<HintPath>..\GameBinaries\Microsoft.CodeAnalysis.CSharp.dll</HintPath>
|
||||||
<Private>False</Private>
|
<Private>False</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
|
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\NLog.4.4.1\lib\net45\NLog.dll</HintPath>
|
<HintPath>..\packages\NLog.4.4.11\lib\net45\NLog.dll</HintPath>
|
||||||
<Private>True</Private>
|
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="Sandbox.Common, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
<Reference Include="Sandbox.Common, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||||
<SpecificVersion>False</SpecificVersion>
|
<SpecificVersion>False</SpecificVersion>
|
||||||
|
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Xml.Serialization;
|
using System.Xml.Serialization;
|
||||||
|
using Newtonsoft.Json;
|
||||||
using NLog;
|
using NLog;
|
||||||
|
|
||||||
namespace Torch.Server
|
namespace Torch.Server
|
||||||
@@ -16,11 +17,11 @@ namespace Torch.Server
|
|||||||
public string InstancePath { get; set; }
|
public string InstancePath { get; set; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
[XmlIgnore, Arg("noupdate", "Disable automatically downloading game and plugin updates.")]
|
[JsonIgnore, Arg("noupdate", "Disable automatically downloading game and plugin updates.")]
|
||||||
public bool NoUpdate { get => false; set => GetTorchUpdates = GetPluginUpdates = !value; }
|
public bool NoUpdate { get => false; set => GetTorchUpdates = GetPluginUpdates = !value; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
[XmlIgnore, Arg("update", "Manually check for and install updates.")]
|
[JsonIgnore, Arg("update", "Manually check for and install updates.")]
|
||||||
public bool Update { get; set; }
|
public bool Update { get; set; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
@@ -36,7 +37,7 @@ namespace Torch.Server
|
|||||||
public bool NoGui { get; set; }
|
public bool NoGui { get; set; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
[XmlIgnore, Arg("waitforpid", "Makes Torch wait for another process to exit.")]
|
[JsonIgnore, Arg("waitforpid", "Makes Torch wait for another process to exit.")]
|
||||||
public string WaitForPID { get; set; }
|
public string WaitForPID { get; set; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
@@ -53,33 +54,26 @@ namespace Torch.Server
|
|||||||
public int TickTimeout { get; set; } = 60;
|
public int TickTimeout { get; set; } = 60;
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public List<string> Plugins { get; set; } = new List<string>();
|
public List<string> Plugins { get; set; } = new List<string> {"TorchAPI/Concealment", "TorchAPI/Essentials"};
|
||||||
|
|
||||||
internal Point WindowSize { get; set; } = new Point(800, 600);
|
internal Point WindowSize { get; set; } = new Point(800, 600);
|
||||||
internal Point WindowPosition { get; set; } = new Point();
|
internal Point WindowPosition { get; set; } = new Point();
|
||||||
[NonSerialized]
|
[JsonIgnore]
|
||||||
private string _path;
|
private string _path;
|
||||||
|
|
||||||
public TorchConfig() : this("Torch") { }
|
public TorchConfig() : this("Torch") { }
|
||||||
|
|
||||||
public TorchConfig(string instanceName = "Torch", string instancePath = null, int autosaveInterval = 5, bool autoRestart = false)
|
public TorchConfig(string instanceName = "Torch", string instancePath = null)
|
||||||
{
|
{
|
||||||
InstanceName = instanceName;
|
InstanceName = instanceName;
|
||||||
InstancePath = instancePath ?? Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "SpaceEngineersDedicated");
|
InstancePath = instancePath ?? Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "SpaceEngineersDedicated");
|
||||||
//Autosave = autosaveInterval;
|
|
||||||
//AutoRestart = autoRestart;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TorchConfig LoadFrom(string path)
|
public static TorchConfig LoadFrom(string path)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var serializer = new XmlSerializer(typeof(TorchConfig));
|
var config = JsonConvert.DeserializeObject<TorchConfig>(File.ReadAllText(path));
|
||||||
TorchConfig config;
|
|
||||||
using (var f = File.OpenRead(path))
|
|
||||||
{
|
|
||||||
config = (TorchConfig)serializer.Deserialize(f);
|
|
||||||
}
|
|
||||||
config._path = path;
|
config._path = path;
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
@@ -99,11 +93,8 @@ namespace Torch.Server
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var serializer = new XmlSerializer(typeof(TorchConfig));
|
var str = JsonConvert.SerializeObject(this);
|
||||||
using (var f = File.Create(path))
|
File.WriteAllText(path, str);
|
||||||
{
|
|
||||||
serializer.Serialize(f, this);
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
@@ -18,6 +18,7 @@ using Sandbox.ModAPI;
|
|||||||
using SteamSDK;
|
using SteamSDK;
|
||||||
using Torch.API;
|
using Torch.API;
|
||||||
using Torch.Managers;
|
using Torch.Managers;
|
||||||
|
using Torch.Server.Managers;
|
||||||
using VRage.Dedicated;
|
using VRage.Dedicated;
|
||||||
using VRage.FileSystem;
|
using VRage.FileSystem;
|
||||||
using VRage.Game;
|
using VRage.Game;
|
||||||
@@ -55,6 +56,7 @@ namespace Torch.Server
|
|||||||
|
|
||||||
public TorchServer(TorchConfig config = null)
|
public TorchServer(TorchConfig config = null)
|
||||||
{
|
{
|
||||||
|
AddManager(new ConfigManager(this));
|
||||||
Config = config ?? new TorchConfig();
|
Config = config ?? new TorchConfig();
|
||||||
MyFakes.ENABLE_INFINARIO = false;
|
MyFakes.ENABLE_INFINARIO = false;
|
||||||
}
|
}
|
||||||
@@ -85,7 +87,11 @@ namespace Torch.Server
|
|||||||
MyPlugins.RegisterSandboxGameAssemblyFile(MyPerGameSettings.SandboxGameAssembly);
|
MyPlugins.RegisterSandboxGameAssemblyFile(MyPerGameSettings.SandboxGameAssembly);
|
||||||
MyPlugins.Load();
|
MyPlugins.Load();
|
||||||
MyGlobalTypeMetadata.Static.Init();
|
MyGlobalTypeMetadata.Static.Init();
|
||||||
RuntimeHelpers.RunClassConstructor(typeof(MyObjectBuilder_Base).TypeHandle);
|
|
||||||
|
if (!Directory.Exists(Config.InstancePath))
|
||||||
|
GetManager<ConfigManager>().CreateInstance(Config.InstancePath);
|
||||||
|
|
||||||
|
Plugins.LoadPlugins();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void InvokeBeforeRun()
|
private void InvokeBeforeRun()
|
||||||
|
@@ -50,6 +50,12 @@ namespace Torch.Server.ViewModels.Blocks
|
|||||||
|
|
||||||
public override bool CanStop => false;
|
public override bool CanStop => false;
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override void Delete()
|
||||||
|
{
|
||||||
|
Block.CubeGrid.RazeBlock(Block.Position);
|
||||||
|
}
|
||||||
|
|
||||||
public BlockViewModel(IMyTerminalBlock block, EntityTreeViewModel tree) : base(block, tree)
|
public BlockViewModel(IMyTerminalBlock block, EntityTreeViewModel tree) : base(block, tree)
|
||||||
{
|
{
|
||||||
Block = block;
|
Block = block;
|
||||||
|
@@ -37,6 +37,11 @@ namespace Torch.Server.ViewModels.Entities
|
|||||||
|
|
||||||
public virtual bool CanDelete => !(Entity is IMyCharacter);
|
public virtual bool CanDelete => !(Entity is IMyCharacter);
|
||||||
|
|
||||||
|
public virtual void Delete()
|
||||||
|
{
|
||||||
|
Entity.Close();
|
||||||
|
}
|
||||||
|
|
||||||
public EntityViewModel(IMyEntity entity, EntityTreeViewModel tree)
|
public EntityViewModel(IMyEntity entity, EntityTreeViewModel tree)
|
||||||
{
|
{
|
||||||
Entity = entity;
|
Entity = entity;
|
||||||
|
@@ -60,7 +60,7 @@ namespace Torch.Server.Views
|
|||||||
{
|
{
|
||||||
if (Entities.CurrentEntity?.Entity is IMyCharacter)
|
if (Entities.CurrentEntity?.Entity is IMyCharacter)
|
||||||
return;
|
return;
|
||||||
TorchBase.Instance.Invoke(() => Entities.CurrentEntity?.Entity.Close());
|
TorchBase.Instance.Invoke(() => Entities.CurrentEntity?.Delete());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Stop_OnClick(object sender, RoutedEventArgs e)
|
private void Stop_OnClick(object sender, RoutedEventArgs e)
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<packages>
|
<packages>
|
||||||
<package id="Extended.Wpf.Toolkit" version="2.9" targetFramework="net461" />
|
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net461" />
|
||||||
<package id="NLog" version="4.4.1" targetFramework="net461" />
|
<package id="NLog" version="4.4.11" targetFramework="net461" />
|
||||||
</packages>
|
</packages>
|
@@ -1,6 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
@@ -14,7 +13,7 @@ namespace Torch
|
|||||||
private readonly string _argPrefix;
|
private readonly string _argPrefix;
|
||||||
private readonly Dictionary<ArgAttribute, PropertyInfo> _args = new Dictionary<ArgAttribute, PropertyInfo>();
|
private readonly Dictionary<ArgAttribute, PropertyInfo> _args = new Dictionary<ArgAttribute, PropertyInfo>();
|
||||||
|
|
||||||
public CommandLine(string argPrefix = "-")
|
protected CommandLine(string argPrefix = "-")
|
||||||
{
|
{
|
||||||
_argPrefix = argPrefix;
|
_argPrefix = argPrefix;
|
||||||
foreach (var prop in GetType().GetProperties())
|
foreach (var prop in GetType().GetProperties())
|
||||||
|
@@ -85,7 +85,7 @@ namespace Torch.Managers
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override void Init()
|
public void LoadPlugins()
|
||||||
{
|
{
|
||||||
_updateManager = Torch.GetManager<UpdateManager>();
|
_updateManager = Torch.GetManager<UpdateManager>();
|
||||||
var commands = Torch.GetManager<CommandManager>();
|
var commands = Torch.GetManager<CommandManager>();
|
||||||
|
@@ -226,16 +226,6 @@ namespace Torch
|
|||||||
SpaceEngineersGame.SetupBasicGameInfo();
|
SpaceEngineersGame.SetupBasicGameInfo();
|
||||||
SpaceEngineersGame.SetupPerGameSettings();
|
SpaceEngineersGame.SetupPerGameSettings();
|
||||||
|
|
||||||
/*
|
|
||||||
if (Directory.Exists("DedicatedServer64"))
|
|
||||||
{
|
|
||||||
Log.Debug("Inserting DedicatedServer64 before MyPerGameSettings assembly paths");
|
|
||||||
MyPerGameSettings.GameModAssembly = $"DedicatedServer64\\{MyPerGameSettings.GameModAssembly}";
|
|
||||||
MyPerGameSettings.GameModObjBuildersAssembly = $"DedicatedServer64\\{MyPerGameSettings.GameModObjBuildersAssembly}";
|
|
||||||
MyPerGameSettings.SandboxAssembly = $"DedicatedServer64\\{MyPerGameSettings.SandboxAssembly}";
|
|
||||||
MyPerGameSettings.SandboxGameAssembly = $"DedicatedServer64\\{MyPerGameSettings.SandboxGameAssembly}";
|
|
||||||
}*/
|
|
||||||
|
|
||||||
TorchVersion = Assembly.GetEntryAssembly().GetName().Version;
|
TorchVersion = Assembly.GetEntryAssembly().GetName().Version;
|
||||||
GameVersion = new Version(new MyVersion(MyPerGameSettings.BasicGameInfo.GameVersion.Value).FormattedText.ToString().Replace("_", "."));
|
GameVersion = new Version(new MyVersion(MyPerGameSettings.BasicGameInfo.GameVersion.Value).FormattedText.ToString().Replace("_", "."));
|
||||||
var verInfo = $"Torch {TorchVersion}, SE {GameVersion}";
|
var verInfo = $"Torch {TorchVersion}, SE {GameVersion}";
|
||||||
|
Reference in New Issue
Block a user