diff --git a/Torch.API/Managers/IPluginManager.cs b/Torch.API/Managers/IPluginManager.cs
index 2a0d729..fa8c911 100644
--- a/Torch.API/Managers/IPluginManager.cs
+++ b/Torch.API/Managers/IPluginManager.cs
@@ -30,5 +30,10 @@ namespace Torch.API.Managers
/// Disposes all loaded plugins.
///
void DisposePlugins();
+
+ ///
+ /// Load plugins.
+ ///
+ void LoadPlugins();
}
}
\ No newline at end of file
diff --git a/Torch.Server/Managers/ConfigManager.cs b/Torch.Server/Managers/ConfigManager.cs
index b655391..98515bc 100644
--- a/Torch.Server/Managers/ConfigManager.cs
+++ b/Torch.Server/Managers/ConfigManager.cs
@@ -56,6 +56,8 @@ namespace Torch.Server.Managers
Directory.CreateDirectory(savesPath);
var modsPath = Path.Combine(path, "Mods");
Directory.CreateDirectory(modsPath);
+ var configPath = Path.Combine(path, "SpaceEngineers-Dedicated.cfg");
+ new MyConfigDedicated(configPath).Save();
LoadInstance(path);
}
}
diff --git a/Torch.Server/Program.cs b/Torch.Server/Program.cs
index 17fb1e0..e445998 100644
--- a/Torch.Server/Program.cs
+++ b/Torch.Server/Program.cs
@@ -23,6 +23,7 @@ using Torch.Server.Views;
using VRage.Game.ModAPI;
using System.IO.Compression;
using System.Net;
+using System.Security.Policy;
using Torch.Server.Managers;
using VRage.FileSystem;
using VRageRender;
@@ -61,37 +62,22 @@ namespace Torch.Server
return;
}
- var configName = "TorchConfig.xml";
- var configPath = Path.Combine(Directory.GetCurrentDirectory(), configName);
- if (File.Exists(configName))
+ //CommandLine reflection triggers assembly loading, so DS update must be completely separated.
+ if (!args.Contains("-noupdate"))
{
- _log.Info($"Loading config {configPath}");
- _config = TorchConfig.LoadFrom(configPath);
- }
- 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)
+ if (!Directory.Exists("DedicatedServer64"))
{
- _log.Info("Automatic updates enabled.");
- RunSteamCmd();
+ _log.Error("Game libraries not found. Press the Enter key to install the dedicated server.");
+ Console.ReadLine();
}
-
- _config.Save(configPath);
+ RunSteamCmd();
}
+ InitConfig();
+
if (!_config.Parse(args))
return;
- _log.Debug(_config.ToString());
-
if (!string.IsNullOrEmpty(_config.WaitForPID))
{
try
@@ -110,14 +96,26 @@ namespace Torch.Server
}
_restartOnCrash = _config.RestartOnCrash;
-
- if (_config.GetTorchUpdates || _config.Update)
- {
- RunSteamCmd();
- }
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_ZIP = "temp.zip";
private static readonly string STEAMCMD_PATH = $"{STEAMCMD_DIR}\\steamcmd.exe";
diff --git a/Torch.Server/Torch.Server.csproj b/Torch.Server/Torch.Server.csproj
index df199ad..fd2018f 100644
--- a/Torch.Server/Torch.Server.csproj
+++ b/Torch.Server/Torch.Server.csproj
@@ -59,9 +59,11 @@
..\GameBinaries\Microsoft.CodeAnalysis.CSharp.dll
False
+
+ ..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll
+
- ..\packages\NLog.4.4.1\lib\net45\NLog.dll
- True
+ ..\packages\NLog.4.4.11\lib\net45\NLog.dll
False
diff --git a/Torch.Server/TorchConfig.cs b/Torch.Server/TorchConfig.cs
index e3268d4..7f504b3 100644
--- a/Torch.Server/TorchConfig.cs
+++ b/Torch.Server/TorchConfig.cs
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.IO;
using System.Windows;
using System.Xml.Serialization;
+using Newtonsoft.Json;
using NLog;
namespace Torch.Server
@@ -16,11 +17,11 @@ namespace Torch.Server
public string InstancePath { get; set; }
///
- [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; }
///
- [XmlIgnore, Arg("update", "Manually check for and install updates.")]
+ [JsonIgnore, Arg("update", "Manually check for and install updates.")]
public bool Update { get; set; }
///
@@ -36,7 +37,7 @@ namespace Torch.Server
public bool NoGui { get; set; }
///
- [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; }
///
@@ -53,33 +54,26 @@ namespace Torch.Server
public int TickTimeout { get; set; } = 60;
///
- public List Plugins { get; set; } = new List();
+ public List Plugins { get; set; } = new List {"TorchAPI/Concealment", "TorchAPI/Essentials"};
internal Point WindowSize { get; set; } = new Point(800, 600);
internal Point WindowPosition { get; set; } = new Point();
- [NonSerialized]
+ [JsonIgnore]
private string _path;
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;
InstancePath = instancePath ?? Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "SpaceEngineersDedicated");
- //Autosave = autosaveInterval;
- //AutoRestart = autoRestart;
}
public static TorchConfig LoadFrom(string path)
{
try
{
- var serializer = new XmlSerializer(typeof(TorchConfig));
- TorchConfig config;
- using (var f = File.OpenRead(path))
- {
- config = (TorchConfig)serializer.Deserialize(f);
- }
+ var config = JsonConvert.DeserializeObject(File.ReadAllText(path));
config._path = path;
return config;
}
@@ -99,11 +93,8 @@ namespace Torch.Server
try
{
- var serializer = new XmlSerializer(typeof(TorchConfig));
- using (var f = File.Create(path))
- {
- serializer.Serialize(f, this);
- }
+ var str = JsonConvert.SerializeObject(this);
+ File.WriteAllText(path, str);
return true;
}
catch (Exception e)
diff --git a/Torch.Server/TorchServer.cs b/Torch.Server/TorchServer.cs
index 3cd8298..bb2c761 100644
--- a/Torch.Server/TorchServer.cs
+++ b/Torch.Server/TorchServer.cs
@@ -18,6 +18,7 @@ using Sandbox.ModAPI;
using SteamSDK;
using Torch.API;
using Torch.Managers;
+using Torch.Server.Managers;
using VRage.Dedicated;
using VRage.FileSystem;
using VRage.Game;
@@ -55,6 +56,7 @@ namespace Torch.Server
public TorchServer(TorchConfig config = null)
{
+ AddManager(new ConfigManager(this));
Config = config ?? new TorchConfig();
MyFakes.ENABLE_INFINARIO = false;
}
@@ -85,7 +87,11 @@ namespace Torch.Server
MyPlugins.RegisterSandboxGameAssemblyFile(MyPerGameSettings.SandboxGameAssembly);
MyPlugins.Load();
MyGlobalTypeMetadata.Static.Init();
- RuntimeHelpers.RunClassConstructor(typeof(MyObjectBuilder_Base).TypeHandle);
+
+ if (!Directory.Exists(Config.InstancePath))
+ GetManager().CreateInstance(Config.InstancePath);
+
+ Plugins.LoadPlugins();
}
private void InvokeBeforeRun()
diff --git a/Torch.Server/ViewModels/Entities/Blocks/BlockViewModel.cs b/Torch.Server/ViewModels/Entities/Blocks/BlockViewModel.cs
index e3cbe76..1b90cdb 100644
--- a/Torch.Server/ViewModels/Entities/Blocks/BlockViewModel.cs
+++ b/Torch.Server/ViewModels/Entities/Blocks/BlockViewModel.cs
@@ -50,6 +50,12 @@ namespace Torch.Server.ViewModels.Blocks
public override bool CanStop => false;
+ ///
+ public override void Delete()
+ {
+ Block.CubeGrid.RazeBlock(Block.Position);
+ }
+
public BlockViewModel(IMyTerminalBlock block, EntityTreeViewModel tree) : base(block, tree)
{
Block = block;
diff --git a/Torch.Server/ViewModels/Entities/EntityViewModel.cs b/Torch.Server/ViewModels/Entities/EntityViewModel.cs
index 80cae76..08ad9ae 100644
--- a/Torch.Server/ViewModels/Entities/EntityViewModel.cs
+++ b/Torch.Server/ViewModels/Entities/EntityViewModel.cs
@@ -37,6 +37,11 @@ namespace Torch.Server.ViewModels.Entities
public virtual bool CanDelete => !(Entity is IMyCharacter);
+ public virtual void Delete()
+ {
+ Entity.Close();
+ }
+
public EntityViewModel(IMyEntity entity, EntityTreeViewModel tree)
{
Entity = entity;
diff --git a/Torch.Server/Views/EntitiesControl.xaml.cs b/Torch.Server/Views/EntitiesControl.xaml.cs
index 0dc992a..1ba3541 100644
--- a/Torch.Server/Views/EntitiesControl.xaml.cs
+++ b/Torch.Server/Views/EntitiesControl.xaml.cs
@@ -60,7 +60,7 @@ namespace Torch.Server.Views
{
if (Entities.CurrentEntity?.Entity is IMyCharacter)
return;
- TorchBase.Instance.Invoke(() => Entities.CurrentEntity?.Entity.Close());
+ TorchBase.Instance.Invoke(() => Entities.CurrentEntity?.Delete());
}
private void Stop_OnClick(object sender, RoutedEventArgs e)
diff --git a/Torch.Server/packages.config b/Torch.Server/packages.config
index 38604b6..cd583f4 100644
--- a/Torch.Server/packages.config
+++ b/Torch.Server/packages.config
@@ -1,5 +1,5 @@
-
-
+
+
\ No newline at end of file
diff --git a/Torch/CommandLine.cs b/Torch/CommandLine.cs
index 4ca10a4..505f235 100644
--- a/Torch/CommandLine.cs
+++ b/Torch/CommandLine.cs
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
-using System.Linq;
using System.Reflection;
using System.Text;
@@ -14,7 +13,7 @@ namespace Torch
private readonly string _argPrefix;
private readonly Dictionary _args = new Dictionary();
- public CommandLine(string argPrefix = "-")
+ protected CommandLine(string argPrefix = "-")
{
_argPrefix = argPrefix;
foreach (var prop in GetType().GetProperties())
diff --git a/Torch/Managers/PluginManager.cs b/Torch/Managers/PluginManager.cs
index c39a5c0..cdd719e 100644
--- a/Torch/Managers/PluginManager.cs
+++ b/Torch/Managers/PluginManager.cs
@@ -85,7 +85,7 @@ namespace Torch.Managers
}
///
- public override void Init()
+ public void LoadPlugins()
{
_updateManager = Torch.GetManager();
var commands = Torch.GetManager();
diff --git a/Torch/TorchBase.cs b/Torch/TorchBase.cs
index da54215..95dc087 100644
--- a/Torch/TorchBase.cs
+++ b/Torch/TorchBase.cs
@@ -226,16 +226,6 @@ namespace Torch
SpaceEngineersGame.SetupBasicGameInfo();
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;
GameVersion = new Version(new MyVersion(MyPerGameSettings.BasicGameInfo.GameVersion.Value).FormattedText.ToString().Replace("_", "."));
var verInfo = $"Torch {TorchVersion}, SE {GameVersion}";