Skip to content

Commit 03a2285

Browse files
committed
Save Torch config on server start, remove concealment code (moved to plugin)
1 parent 32f5147 commit 03a2285

8 files changed

Lines changed: 23 additions & 379 deletions

File tree

‎Torch.Server/Program.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public static void Main(string[] args)
5252
{
5353
_log.Info($"Generating default config at {configPath}");
5454
options = new TorchConfig();
55-
options.SaveTo(configPath);
55+
options.Save(configPath);
5656
}
5757

5858
/*

‎Torch.Server/TorchConfig.cs‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
using System.Threading.Tasks;
77
using System.Xml.Serialization;
88
using NLog;
9-
using VRage.Dedicated;
9+
using Sandbox.ModAPI.Ingame;
1010

11-
namespace Torch.Server
11+
namespace Torch
1212
{
1313
public class TorchConfig
1414
{
@@ -19,13 +19,15 @@ public class TorchConfig
1919
public int Autosave { get; set; }
2020
public bool AutoRestart { get; set; }
2121
public bool LogChat { get; set; }
22+
[NonSerialized]
23+
private string _path;
2224

2325
public TorchConfig() : this("Torch") { }
2426

2527
public TorchConfig(string instanceName = "Torch", string instancePath = null, int autosaveInterval = 5, bool autoRestart = false)
2628
{
2729
InstanceName = instanceName;
28-
InstancePath = instancePath ?? Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "SpaceEngineersDedicated", InstanceName);
30+
InstancePath = instancePath ?? Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Torch", InstanceName);
2931
Autosave = autosaveInterval;
3032
AutoRestart = autoRestart;
3133
}
@@ -40,6 +42,7 @@ public static TorchConfig LoadFrom(string path)
4042
{
4143
config = (TorchConfig)serializer.Deserialize(f);
4244
}
45+
config._path = path;
4346
return config;
4447
}
4548
catch (Exception e)
@@ -49,8 +52,13 @@ public static TorchConfig LoadFrom(string path)
4952
}
5053
}
5154

52-
public bool SaveTo(string path)
55+
public bool Save(string path = null)
5356
{
57+
if (path == null)
58+
path = _path;
59+
else
60+
_path = path;
61+
5462
try
5563
{
5664
var serializer = new XmlSerializer(typeof(TorchConfig));

‎Torch.Server/TorchServer.cs‎

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,22 @@ public class TorchServer : TorchBase, ITorchServer
3434
{
3535
public Thread GameThread { get; private set; }
3636
public bool IsRunning { get; private set; }
37-
public string InstancePath { get; private set; }
38-
public string InstanceName { get; private set; }
37+
public TorchConfig Config { get; }
38+
public string InstanceName => Config?.InstanceName;
39+
public string InstancePath => Config?.InstancePath;
3940

4041
private readonly AutoResetEvent _stopHandle = new AutoResetEvent(false);
4142

42-
public TorchServer(TorchConfig options = null)
43+
public TorchServer(TorchConfig config = null)
4344
{
44-
var opt = options ?? new TorchConfig();
45-
46-
InstanceName = opt.InstanceName;
47-
InstancePath = opt.InstancePath;
45+
Config = config ?? new TorchConfig();
4846
}
4947

5048
public override void Init()
5149
{
5250
base.Init();
5351

54-
Log.Info($"Init server instance '{InstanceName}' at path '{InstancePath}'");
52+
Log.Info($"Init server instance '{Config.InstanceName}' at path '{Config.InstancePath}'");
5553

5654
MyFakes.ENABLE_INFINARIO = false;
5755
MyPerGameSettings.SendLogToKeen = false;
@@ -73,14 +71,6 @@ public void SetConfig(IMyConfigDedicated config)
7371
MySandboxGame.ConfigDedicated = config;
7472
}
7573

76-
public void SetInstance(string path = null, string name = null)
77-
{
78-
if (path != null)
79-
InstancePath = path;
80-
if (name != null)
81-
InstanceName = name;
82-
}
83-
8474
public void Start(IMyConfigDedicated config)
8575
{
8676
SetConfig(config);
@@ -95,14 +85,15 @@ public override void Start()
9585
if (IsRunning)
9686
throw new InvalidOperationException("Server is already running.");
9787

88+
Config.Save();
9889
IsRunning = true;
9990
Log.Info("Starting server.");
10091

10192
MySandboxGame.IsDedicated = true;
10293
Environment.SetEnvironmentVariable("SteamAppId", MyPerServerSettings.AppId.ToString());
10394

10495
Log.Trace("Invoking RunMain");
105-
try { Reflection.InvokeStaticMethod(typeof(DedicatedServer), "RunMain", InstanceName, InstancePath, false, true); }
96+
try { Reflection.InvokeStaticMethod(typeof(DedicatedServer), "RunMain", Config.InstanceName, Config.InstancePath, false, true); }
10697
catch (Exception e)
10798
{
10899
Log.Error("Error running server.");

‎Torch.Server/TorchService.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ protected override void OnStart(string[] args)
3737
if (File.Exists(configName))
3838
options = TorchConfig.LoadFrom(configName);
3939
else
40-
options.SaveTo(configName);
40+
options.Save(configName);
4141

4242
_server = new TorchServer(options);
4343
_server.Init();

‎Torch.Server/Views/TorchUI.xaml.cs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public partial class TorchUI : Window
3838

3939
public TorchUI(TorchServer server)
4040
{
41-
_config = new TorchConfig();
41+
_config = server.Config;
4242
_server = server;
4343
InitializeComponent();
4444
_startTime = DateTime.Now;
@@ -113,7 +113,6 @@ private void InstancePathBox_OnTextChanged(object sender, TextChangedEventArgs e
113113
{
114114
var name = (sender as TextBox).Text;
115115

116-
_server.SetInstance(null, name);
117116
_config.InstancePath = name;
118117

119118
LoadConfig(_config);

0 commit comments

Comments
 (0)