diff --git a/NLog.config b/NLog.config
index 078af4e..61d309a 100644
--- a/NLog.config
+++ b/NLog.config
@@ -3,7 +3,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
-
+
diff --git a/TestPlugin/Commands.cs b/TestPlugin/Commands.cs
index 7141749..6617b26 100644
--- a/TestPlugin/Commands.cs
+++ b/TestPlugin/Commands.cs
@@ -3,11 +3,15 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using Sandbox;
+using Sandbox.Game.Entities;
+using Sandbox.Game.World;
using Torch.Commands;
+using VRage.Game.Entity;
+using VRage.Game.ModAPI;
namespace TestPlugin
{
- [Category("admin", "tools")]
public class Commands : CommandModule
{
[Command("Ban", "Bans a player from the game")]
diff --git a/TestPlugin/Plugin.cs b/TestPlugin/Plugin.cs
index b276bce..6017a95 100644
--- a/TestPlugin/Plugin.cs
+++ b/TestPlugin/Plugin.cs
@@ -26,7 +26,7 @@ namespace TestPlugin
}
///
- public override void Unload()
+ public override void Dispose()
{
//Torch.Log.Write($"Plugin unload {Name}");
}
diff --git a/TestPlugin/TestPlugin.csproj b/TestPlugin/TestPlugin.csproj
index 24445bb..21772c3 100644
--- a/TestPlugin/TestPlugin.csproj
+++ b/TestPlugin/TestPlugin.csproj
@@ -31,6 +31,9 @@
MinimumRecommendedRules.ruleset
+
+ ..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\Sandbox.Game.dll
+
@@ -42,6 +45,11 @@
..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\VRage.dll
+
+ False
+ ..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\VRage.Game.dll
+
+
diff --git a/Torch.API/IPluginManager.cs b/Torch.API/IPluginManager.cs
index 42bf9b1..9e28193 100644
--- a/Torch.API/IPluginManager.cs
+++ b/Torch.API/IPluginManager.cs
@@ -9,6 +9,6 @@ namespace Torch.API
{
void UpdatePlugins();
void Init();
- void UnloadPlugins();
+ void DisposePlugins();
}
}
\ No newline at end of file
diff --git a/Torch.API/ITorchBase.cs b/Torch.API/ITorchBase.cs
index 5415ec3..981cd28 100644
--- a/Torch.API/ITorchBase.cs
+++ b/Torch.API/ITorchBase.cs
@@ -8,10 +8,13 @@ namespace Torch.API
{
public interface ITorchBase
{
+ event Action SessionLoading;
event Action SessionLoaded;
+ event Action SessionUnloading;
+ event Action SessionUnloaded;
IMultiplayer Multiplayer { get; }
IPluginManager Plugins { get; }
- Version Version { get; }
+ Version TorchVersion { get; }
void Invoke(Action action);
void InvokeBlocking(Action action);
Task InvokeAsync(Action action);
diff --git a/Torch.API/ITorchPlugin.cs b/Torch.API/ITorchPlugin.cs
index 3053170..d333196 100644
--- a/Torch.API/ITorchPlugin.cs
+++ b/Torch.API/ITorchPlugin.cs
@@ -7,7 +7,7 @@ using System.Threading.Tasks;
namespace Torch.API
{
- public interface ITorchPlugin
+ public interface ITorchPlugin : IDisposable
{
Guid Id { get; }
Version Version { get; }
@@ -23,10 +23,5 @@ namespace Torch.API
/// Called after each game tick. Not thread safe, use invocation methods in .
///
void Update();
-
- ///
- /// Called when the game exits.
- ///
- void Unload();
}
}
diff --git a/Torch.Client/Program.cs b/Torch.Client/Program.cs
index 68e8231..1bb555a 100644
--- a/Torch.Client/Program.cs
+++ b/Torch.Client/Program.cs
@@ -1,12 +1,17 @@
using System;
using System.Windows;
+using NLog;
namespace Torch.Client
{
public static class Program
{
+ private static Logger _log = LogManager.GetLogger("Torch");
+
public static void Main(string[] args)
{
+ AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
+
var client = new TorchClient();
try
@@ -15,11 +20,18 @@ namespace Torch.Client
}
catch (Exception e)
{
- MessageBox.Show($"Torch encountered an error trying to initialize the game.\n{e.Message}");
+ _log.Fatal("Torch encountered an error trying to initialize the game.");
+ _log.Fatal(e);
return;
}
client.Start();
}
+
+ private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
+ {
+ var ex = (Exception)e.ExceptionObject;
+ MessageBox.Show(ex.StackTrace, ex.Message);
+ }
}
}
\ No newline at end of file
diff --git a/Torch.Client/Properties/AssemblyInfo.cs b/Torch.Client/Properties/AssemblyInfo.cs
index 7b43e53..e1e6015 100644
--- a/Torch.Client/Properties/AssemblyInfo.cs
+++ b/Torch.Client/Properties/AssemblyInfo.cs
@@ -1,55 +1,16 @@
-using System.Reflection;
-using System.Resources;
-using System.Runtime.CompilerServices;
+
+using System.Reflection;
using System.Runtime.InteropServices;
-using System.Windows;
-// General Information about an assembly is controlled through the following
-// set of attributes. Change these attribute values to modify the information
-// associated with an assembly.
-[assembly: AssemblyTitle("PistonClient")]
+[assembly: AssemblyTitle("Torch Client")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
-[assembly: AssemblyProduct("PistonClient")]
-[assembly: AssemblyCopyright("Copyright © 2016")]
+[assembly: AssemblyProduct("Torch")]
+[assembly: AssemblyCopyright("Copyright © Torch API 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
-
-// Setting ComVisible to false makes the types in this assembly not visible
-// to COM components. If you need to access a type in this assembly from
-// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
-//In order to begin building localizable applications, set
-//CultureYouAreCodingWith in your .csproj file
-//inside a . For example, if you are using US english
-//in your source files, set the to en-US. Then uncomment
-//the NeutralResourceLanguage attribute below. Update the "en-US" in
-//the line below to match the UICulture setting in the project file.
-
-//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
-
-
-[assembly: ThemeInfo(
- ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
- //(used if a resource is not found in the page,
- // or application resource dictionaries)
- ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
- //(used if a resource is not found in the page,
- // app, or any theme specific resource dictionaries)
-)]
-
-
-// Version information for an assembly consists of the following four values:
-//
-// Major Version
-// Minor Version
-// Build Number
-// Revision
-//
-// You can specify all the values or you can default the Build and Revision Numbers
-// by using the '*' as shown below:
-// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.0.0.0")]
-[assembly: AssemblyFileVersion("1.0.0.0")]
+[assembly: AssemblyVersion("1.0.35.456")]
+[assembly: AssemblyFileVersion("1.0.35.456")]
\ No newline at end of file
diff --git a/Torch.Client/Properties/AssemblyInfo.tt b/Torch.Client/Properties/AssemblyInfo.tt
new file mode 100644
index 0000000..c1b48cf
--- /dev/null
+++ b/Torch.Client/Properties/AssemblyInfo.tt
@@ -0,0 +1,28 @@
+<#@ template debug="false" hostspecific="false" language="C#" #>
+<#@ assembly name="System.Core" #>
+<#@ import namespace="System.Linq" #>
+<#@ import namespace="System.Text" #>
+<#@ import namespace="System.Collections.Generic" #>
+<#@ output extension=".cs" #>
+
+using System.Reflection;
+using System.Runtime.InteropServices;
+
+[assembly: AssemblyTitle("Torch Client")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("Torch")]
+[assembly: AssemblyCopyright("Copyright © Torch API 2017")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+[assembly: ComVisible(false)]
+
+<# var dt = DateTime.Now;
+ int major = 1;
+ int minor = 0;
+ int build = dt.DayOfYear;
+ int rev = (int)dt.TimeOfDay.TotalMinutes / 2;
+#>
+[assembly: AssemblyVersion("<#= major #>.<#= minor #>.<#= build #>.<#= rev #>")]
+[assembly: AssemblyFileVersion("<#= major #>.<#= minor #>.<#= build #>.<#= rev #>")]
\ No newline at end of file
diff --git a/Torch.Client/Torch.Client.csproj b/Torch.Client/Torch.Client.csproj
index 27926f5..cafcd96 100644
--- a/Torch.Client/Torch.Client.csproj
+++ b/Torch.Client/Torch.Client.csproj
@@ -36,6 +36,9 @@
MinimumRecommendedRules.ruleset
true
+
+ torchicon.ico
+
..\packages\NLog.4.4.1\lib\net45\NLog.dll
@@ -100,14 +103,16 @@
+
+ AssemblyInfo.tt
+ True
+ True
+
-
- Code
-
True
True
@@ -141,6 +146,18 @@
True
+
+
+
+
+
+ TextTemplatingFileGenerator
+ AssemblyInfo.cs
+
+
+
+
+
copy "$(SolutionDir)NLog.config" "$(TargetDir)"
diff --git a/Torch.Client/TorchClient.cs b/Torch.Client/TorchClient.cs
index ea1c3bd..d164f31 100644
--- a/Torch.Client/TorchClient.cs
+++ b/Torch.Client/TorchClient.cs
@@ -7,6 +7,7 @@ using System.Threading.Tasks;
using System.Windows;
using Sandbox;
using Sandbox.Engine.Platform;
+using Sandbox.Engine.Utils;
using Sandbox.Game;
using SpaceEngineers.Game;
using Torch.API;
@@ -24,6 +25,7 @@ namespace Torch.Client
public override void Init()
{
+ Log.Info("Initializing Torch Client");
base.Init();
if (!File.Exists("steam_appid.txt"))
@@ -71,9 +73,8 @@ namespace Torch.Client
{
Persons = new List
{
- new MyCreditsPerson("JIMMACLE"),
- new MyCreditsPerson("REXXAR"),
- new MyCreditsPerson("PHOENIXTHESAGE")
+ new MyCreditsPerson("THE TORCH TEAM"),
+ new MyCreditsPerson("http://github.com/TorchSE"),
}
};
MyPerGameSettings.Credits.Departments.Insert(0, credits);
diff --git a/Torch.Client/torchicon.ico b/Torch.Client/torchicon.ico
new file mode 100644
index 0000000..4563964
Binary files /dev/null and b/Torch.Client/torchicon.ico differ
diff --git a/Torch.Server/Program.cs b/Torch.Server/Program.cs
index 3be41f6..0e6292c 100644
--- a/Torch.Server/Program.cs
+++ b/Torch.Server/Program.cs
@@ -12,9 +12,14 @@ using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Threading;
+using Microsoft.CodeAnalysis;
+using Microsoft.CodeAnalysis.CSharp;
using NLog;
+using Sandbox.Game.World;
+using Sandbox.ModAPI;
using Torch;
using Torch.API;
+using VRage.Game.ModAPI;
namespace Torch.Server
{
@@ -34,19 +39,49 @@ namespace Torch.Server
return;
}
- if (args.FirstOrDefault() == "-svcinstall")
+ string configName = args.Length > 0 ? args[0] : "TorchConfig.xml";
+ var configPath = Path.Combine(Directory.GetCurrentDirectory(), configName);
+ var options = new ServerConfig("Torch");
+ if (File.Exists(configName))
{
- /* Working on installing the service properly instead of with sc.exe
- _log.Info("Installing service");
- var installer = new TorchServiceInstaller();
- installer.Context = new InstallContext(Path.Combine(Directory.GetCurrentDirectory(), "svclog.log"), null);
- installer.Context.Parameters.Add("name", "Torch DS");
- installer.Install(new Hashtable
+ _log.Info($"Loading config {configPath}");
+ options = ServerConfig.LoadFrom(configPath);
+ }
+ else
+ {
+ _log.Info($"Generating default config at {configPath}");
+ options.SaveTo(configPath);
+ }
+
+ /*
+ if (!parser.ParseArguments(args, options))
+ {
+ _log.Error($"Parsing arguments failed: {string.Join(" ", args)}");
+ return;
+ }
+
+ if (!string.IsNullOrEmpty(options.Config) && File.Exists(options.Config))
+ {
+ options = ServerConfig.LoadFrom(options.Config);
+ parser.ParseArguments(args, options);
+ }*/
+
+ //RestartOnCrash autostart autosave=15
+ //gamepath ="C:\Program Files\Space Engineers DS" instance="Hydro Survival" instancepath="C:\ProgramData\SpaceEngineersDedicated\Hydro Survival"
+
+ /*
+ if (options.InstallService)
+ {
+ var serviceName = $"\"Torch - {options.InstanceName}\"";
+ // Working on installing the service properly instead of with sc.exe
+ _log.Info($"Installing service '{serviceName}");
+ var exePath = $"\"{Assembly.GetExecutingAssembly().Location}\"";
+ var createInfo = new ServiceCreateInfo
{
- {"name", "Torch DS"}
-
- });
- _log.Info("Service Installed");*/
+ Name = options.InstanceName,
+ BinaryPath = exePath,
+ };
+ _log.Info("Service Installed");
var runArgs = string.Join(" ", args.Skip(1));
_log.Info($"Installing Torch as a service with arguments '{runArgs}'");
@@ -63,7 +98,7 @@ namespace Torch.Server
return;
}
- if (args.FirstOrDefault() == "-svcuninstall")
+ if (options.UninstallService)
{
_log.Info("Uninstalling Torch service");
var startInfo = new ProcessStartInfo
@@ -77,9 +112,9 @@ namespace Torch.Server
Process.Start(startInfo).WaitForExit();
_log.Info("Torch service uninstalled");
return;
- }
+ }*/
- _server = new TorchServer();
+ _server = new TorchServer(options);
_server.Init();
_server.Start();
}
diff --git a/Torch.Server/Properties/AssemblyInfo.cs b/Torch.Server/Properties/AssemblyInfo.cs
index 8ff64c2..cdf7092 100644
--- a/Torch.Server/Properties/AssemblyInfo.cs
+++ b/Torch.Server/Properties/AssemblyInfo.cs
@@ -1,55 +1,16 @@
-using System.Reflection;
-using System.Resources;
-using System.Runtime.CompilerServices;
+
+using System.Reflection;
using System.Runtime.InteropServices;
-using System.Windows;
-// General Information about an assembly is controlled through the following
-// set of attributes. Change these attribute values to modify the information
-// associated with an assembly.
-[assembly: AssemblyTitle("TorchServer")]
+[assembly: AssemblyTitle("Torch Server")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
-[assembly: AssemblyProduct("TorchServer")]
-[assembly: AssemblyCopyright("Copyright © 2016")]
+[assembly: AssemblyProduct("Torch")]
+[assembly: AssemblyCopyright("Copyright © Torch API 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
-
-// Setting ComVisible to false makes the types in this assembly not visible
-// to COM components. If you need to access a type in this assembly from
-// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
-//In order to begin building localizable applications, set
-//CultureYouAreCodingWith in your .csproj file
-//inside a . For example, if you are using US english
-//in your source files, set the to en-US. Then uncomment
-//the NeutralResourceLanguage attribute below. Update the "en-US" in
-//the line below to match the UICulture setting in the project file.
-
-//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
-
-
-[assembly: ThemeInfo(
- ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
- //(used if a resource is not found in the page,
- // or application resource dictionaries)
- ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
- //(used if a resource is not found in the page,
- // app, or any theme specific resource dictionaries)
-)]
-
-
-// Version information for an assembly consists of the following four values:
-//
-// Major Version
-// Minor Version
-// Build Number
-// Revision
-//
-// You can specify all the values or you can default the Build and Revision Numbers
-// by using the '*' as shown below:
-// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.0.0.0")]
-[assembly: AssemblyFileVersion("1.0.0.0")]
+[assembly: AssemblyVersion("1.0.35.456")]
+[assembly: AssemblyFileVersion("1.0.35.456")]
\ No newline at end of file
diff --git a/Torch.Server/Properties/AssemblyInfo.tt b/Torch.Server/Properties/AssemblyInfo.tt
new file mode 100644
index 0000000..eee6580
--- /dev/null
+++ b/Torch.Server/Properties/AssemblyInfo.tt
@@ -0,0 +1,28 @@
+<#@ template debug="false" hostspecific="false" language="C#" #>
+<#@ assembly name="System.Core" #>
+<#@ import namespace="System.Linq" #>
+<#@ import namespace="System.Text" #>
+<#@ import namespace="System.Collections.Generic" #>
+<#@ output extension=".cs" #>
+
+using System.Reflection;
+using System.Runtime.InteropServices;
+
+[assembly: AssemblyTitle("Torch Server")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("Torch")]
+[assembly: AssemblyCopyright("Copyright © Torch API 2017")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+[assembly: ComVisible(false)]
+
+<# var dt = DateTime.Now;
+ int major = 1;
+ int minor = 0;
+ int build = dt.DayOfYear;
+ int rev = (int)dt.TimeOfDay.TotalMinutes / 2;
+#>
+[assembly: AssemblyVersion("<#= major #>.<#= minor #>.<#= build #>.<#= rev #>")]
+[assembly: AssemblyFileVersion("<#= major #>.<#= minor #>.<#= build #>.<#= rev #>")]
\ No newline at end of file
diff --git a/Torch.Server/ServerConfig.cs b/Torch.Server/ServerConfig.cs
new file mode 100644
index 0000000..d970309
--- /dev/null
+++ b/Torch.Server/ServerConfig.cs
@@ -0,0 +1,70 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Xml.Serialization;
+using NLog;
+using VRage.Dedicated;
+
+namespace Torch.Server
+{
+ public class ServerConfig
+ {
+ private static Logger _log = LogManager.GetLogger("Config");
+
+ public string InstancePath { get; set; }
+ public string InstanceName { get; set; }
+ //public string SaveName { get; set; }
+ public int Autosave { get; set; }
+ public bool AutoRestart { get; set; }
+
+ public ServerConfig(string instanceName = "Torch", string instancePath = null, int autosaveInterval = 5, bool autoRestart = false)
+ {
+ InstanceName = instanceName;
+ InstancePath = instancePath ?? Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Torch", InstanceName);
+ Autosave = autosaveInterval;
+ AutoRestart = autoRestart;
+ }
+
+ public static ServerConfig LoadFrom(string path)
+ {
+ _log.Info($"Loading config from '{path}'");
+ try
+ {
+ var serializer = new XmlSerializer(typeof(ServerConfig));
+ ServerConfig config;
+ using (var f = File.OpenRead(path))
+ {
+ config = (ServerConfig)serializer.Deserialize(f);
+ }
+ return config;
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine(e);
+ return null;
+ }
+ }
+
+ public bool SaveTo(string path)
+ {
+ _log.Info($"Saving config to '{path}'");
+ try
+ {
+ var serializer = new XmlSerializer(typeof(ServerConfig));
+ using (var f = File.OpenWrite(path))
+ {
+ serializer.Serialize(f, this);
+ }
+ return true;
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine(e);
+ return false;
+ }
+ }
+ }
+}
diff --git a/Torch.Server/SpaceEngineers.ico b/Torch.Server/SpaceEngineers.ico
deleted file mode 100644
index ea7041a..0000000
Binary files a/Torch.Server/SpaceEngineers.ico and /dev/null differ
diff --git a/Torch.Server/Torch.Server.csproj b/Torch.Server/Torch.Server.csproj
index e6f61d3..2269baa 100644
--- a/Torch.Server/Torch.Server.csproj
+++ b/Torch.Server/Torch.Server.csproj
@@ -40,7 +40,7 @@
Torch.Server.Program
- SpaceEngineers.ico
+ torchicon.ico
@@ -48,28 +48,38 @@
C:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\DedicatedServer64\HavokWrapper.dll
False
+
+ False
+ ..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\Microsoft.CodeAnalysis.dll
+
+
+ False
+ ..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\Microsoft.CodeAnalysis.CSharp.dll
+
..\packages\NLog.4.4.1\lib\net45\NLog.dll
True
-
- False
- C:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\DedicatedServer64\Sandbox.Common.dll
- False
+
+ ..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\Sandbox.Common.dll
-
- False
- C:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\DedicatedServer64\Sandbox.Game.dll
- False
+
+ ..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\Sandbox.Game.dll
-
+
False
- C:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\SpaceEngineers.Game.dll
- False
+ ..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\Sandbox.Graphics.dll
-
- C:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\DedicatedServer64\SpaceEngineersDedicated.exe
- False
+
+ ..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\SpaceEngineers.Game.dll
+
+
+ False
+ ..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\SpaceEngineers.ObjectBuilders.dll
+
+
+ False
+ ..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\SpaceEngineers.ObjectBuilders.XmlSerializers.dll
False
@@ -91,36 +101,63 @@
4.0
-
- False
- C:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\VRage.dll
- False
+
+ ..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\VRage.dll
-
+
False
- C:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\DedicatedServer64\VRage.Dedicated.dll
- False
+ ..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\VRage.Audio.dll
-
- False
- C:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\DedicatedServer64\VRage.Game.dll
- False
+
+ ..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\VRage.Dedicated.dll
-
- False
- C:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\VRage.Input.dll
- False
+
+ ..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\VRage.Game.dll
-
+
+ ..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\VRage.Game.XmlSerializers.dll
+
+
+ ..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\VRage.Input.dll
+
+
+ ..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\VRage.Library.dll
+
+
False
- C:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\VRage.Library.dll
- False
+ ..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\VRage.Math.dll
+
+
+ False
+ ..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\VRage.Native.dll
+
+
+ False
+ ..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\VRage.OpenVRWrapper.dll
+
+
+ False
+ ..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\VRage.Render.dll
+
+
+ False
+ ..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\VRage.Render11.dll
+
+
+ False
+ ..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\VRage.Scripting.dll
+
+ True
+ True
+ AssemblyInfo.tt
+
+
Component
@@ -150,9 +187,6 @@
-
- Code
-
True
True
@@ -213,7 +247,16 @@
-
+
+
+
+
+
+
+
+ TextTemplatingFileGenerator
+ AssemblyInfo.cs
+
diff --git a/Torch.Server/TorchServer.cs b/Torch.Server/TorchServer.cs
index 930c475..5d89b8e 100644
--- a/Torch.Server/TorchServer.cs
+++ b/Torch.Server/TorchServer.cs
@@ -8,9 +8,12 @@ using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
+using NLog;
using Torch;
using Sandbox;
+using Sandbox.Engine.Analytics;
using Sandbox.Engine.Multiplayer;
+using Sandbox.Engine.Utils;
using Sandbox.Game;
using Sandbox.Game.Gui;
using Sandbox.Game.World;
@@ -27,31 +30,24 @@ namespace Torch.Server
{
public Thread GameThread { get; private set; }
public bool IsRunning { get; private set; }
- public bool IsService { get; }
- public string InstancePath { get; private set; }
+ public string InstancePath { get; }
public string InstanceName { get; }
- public event Action SessionLoading;
-
private readonly AutoResetEvent _stopHandle = new AutoResetEvent(false);
- internal TorchServer(string instanceName = null)
+ internal TorchServer(ServerConfig options)
{
- if (instanceName != null)
- {
- IsService = true;
- InstanceName = instanceName;
- }
-
- MySession.OnLoading += OnSessionLoading;
+ InstanceName = options.InstanceName;
+ InstancePath = options.InstancePath;
}
public override void Init()
{
base.Init();
- SpaceEngineersGame.SetupBasicGameInfo();
- SpaceEngineersGame.SetupPerGameSettings();
+ Log.Info($"Server instance {InstanceName} at path {InstancePath}");
+
+ MyFakes.ENABLE_INFINARIO = false;
MyPerGameSettings.SendLogToKeen = false;
MyPerServerSettings.GameName = MyPerGameSettings.GameName;
MyPerServerSettings.GameNameSafe = MyPerGameSettings.GameNameSafe;
@@ -68,18 +64,7 @@ namespace Torch.Server
var gameVersion = MyPerGameSettings.BasicGameInfo.GameVersion;
MyFinalBuildConstants.APP_VERSION = gameVersion ?? 0;
- InstancePath = InstanceName != null ? GetInstancePath(true, InstanceName) : GetInstancePath();
- }
-
- private void OnSessionLoading()
- {
- SessionLoading?.Invoke();
- MySession.Static.OnReady += OnSessionReady;
- }
-
- private void OnSessionReady()
- {
- InvokeSessionLoaded();
+ //InstancePath = InstanceName != null ? GetInstancePath(true, InstanceName) : GetInstancePath();
}
///
@@ -100,6 +85,7 @@ namespace Torch.Server
try { Reflection.InvokeStaticMethod(typeof(DedicatedServer), "RunMain", InstanceName, InstancePath, false, true); }
catch (Exception e)
{
+ Log.Error("Error running server.");
Log.Error(e);
throw;
}
@@ -134,26 +120,28 @@ namespace Torch.Server
VRage.FileSystem.MyFileSystem.Reset();
VRage.Input.MyGuiGameControlsHelpers.Reset();
VRage.Input.MyInput.UnloadData();
- CleanupProfilers();
+ //CleanupProfilers();
Log.Info("Server stopped.");
_stopHandle.Set();
IsRunning = false;
}
+ /*
private string GetInstancePath(bool isService = false, string instanceName = "Torch")
{
if (isService)
return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), MyPerServerSettings.GameDSName, instanceName);
return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), MyPerServerSettings.GameDSName);
- }
+ }*/
+ /*
private void CleanupProfilers()
{
typeof(MyRenderProfiler).GetField("m_threadProfiler", BindingFlags.Static | BindingFlags.NonPublic).SetValue(null, null);
typeof(MyRenderProfiler).GetField("m_gpuProfiler", BindingFlags.Static | BindingFlags.NonPublic).SetValue(null, null);
(typeof(MyRenderProfiler).GetField("m_threadProfilers", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null) as List).Clear();
- }
+ }*/
}
}
diff --git a/Torch.Server/TorchService.cs b/Torch.Server/TorchService.cs
index 46839c3..a9ce339 100644
--- a/Torch.Server/TorchService.cs
+++ b/Torch.Server/TorchService.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -30,7 +31,15 @@ namespace Torch.Server
protected override void OnStart(string[] args)
{
base.OnStart(args);
- _server = new TorchServer("Torch");
+
+ string configName = args.Length > 0 ? args[0] : "TorchConfig.xml";
+ var options = new ServerConfig("Torch");
+ if (File.Exists(configName))
+ options = ServerConfig.LoadFrom(configName);
+ else
+ options.SaveTo(configName);
+
+ _server = new TorchServer(options);
_server.Init();
_server.RunArgs = args;
Task.Run(() => _server.Start());
diff --git a/Torch.Server/torchicon.ico b/Torch.Server/torchicon.ico
new file mode 100644
index 0000000..4563964
Binary files /dev/null and b/Torch.Server/torchicon.ico differ
diff --git a/Torch/Collections/KeyTree.cs b/Torch/Collections/KeyTree.cs
new file mode 100644
index 0000000..79add2e
--- /dev/null
+++ b/Torch/Collections/KeyTree.cs
@@ -0,0 +1,79 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Torch.Collections
+{
+ public class KeyTree
+ {
+ private Dictionary> _nodes = new Dictionary>();
+ }
+
+ public class KeyTreeNode
+ {
+ public TKey Key { get; }
+ public TValue Value { get; set; }
+ public KeyTreeNode Parent { get; private set; }
+ private readonly Dictionary> _children = new Dictionary>();
+
+ public IEnumerable> Children => _children.Values;
+
+ public KeyTreeNode(TKey key, TValue value)
+ {
+ Key = key;
+ Value = value;
+ }
+
+ public KeyTreeNode GetChild(TKey key)
+ {
+ if (_children.TryGetValue(key, out KeyTreeNode value))
+ return value;
+
+ return null;
+ }
+
+ public bool AddChild(TKey key, TValue value)
+ {
+ if (_children.ContainsKey(key))
+ return false;
+
+ var node = new KeyTreeNode(key, value) { Parent = this };
+ _children.Add(key, node);
+ return true;
+ }
+
+ public bool AddChild(KeyTreeNode node)
+ {
+ if (node.Parent != null || _children.ContainsKey(node.Key))
+ return false;
+
+ node.Parent = this;
+ _children.Add(node.Key, node);
+ return true;
+ }
+
+ public bool RemoveChild(TKey key)
+ {
+ if (!_children.TryGetValue(key, out KeyTreeNode value))
+ return false;
+
+ value.Parent = null;
+ _children.Remove(key);
+ return true;
+ }
+
+ public IEnumerable> Traverse()
+ {
+ foreach (var node in Children)
+ {
+ yield return node;
+ foreach (var child in node.Traverse())
+ {
+ yield return child;
+ }
+ }
+ }
+ }
+}
diff --git a/Torch/Commands/CommandContext.cs b/Torch/Commands/CommandContext.cs
index 7c38927..d85f52b 100644
--- a/Torch/Commands/CommandContext.cs
+++ b/Torch/Commands/CommandContext.cs
@@ -28,7 +28,7 @@ namespace Torch.Commands
public void Respond(string message, string sender = "Server", string font = MyFontEnum.Blue)
{
- Torch.Multiplayer.SendMessage(message, Player.PlayerID, sender, font);
+ Torch.Multiplayer.SendMessage(message, Player.IdentityId, sender, font);
}
}
}
\ No newline at end of file
diff --git a/Torch/Commands/TorchCommands.cs b/Torch/Commands/TorchCommands.cs
index e15ad2e..61a6726 100644
--- a/Torch/Commands/TorchCommands.cs
+++ b/Torch/Commands/TorchCommands.cs
@@ -9,13 +9,20 @@ namespace Torch.Commands
{
public class TorchCommands : CommandModule
{
+#if DEBUG
+ [Command("fixit")]
+ public void Fixit()
+ {
+ Environment.Exit(0);
+ }
+
[Command("dbgcmd")]
public void Dbgcmd()
{
var commandManager = ((PluginManager)Context.Torch.Plugins).Commands;
Console.WriteLine(commandManager.Commands.GetTreeString());
}
-
+#endif
[Command("help", "Displays help for a command")]
public void Help()
{
@@ -32,8 +39,7 @@ namespace Torch.Commands
if (command != null)
sb.AppendLine(command.HelpText);
- if (children.Any())
- sb.AppendLine($"Subcommands: {string.Join(", ", children)}");
+ sb.AppendLine($"Subcommands: {string.Join(", ", children)}");
Context.Respond(sb.ToString());
}
@@ -47,7 +53,7 @@ namespace Torch.Commands
[Command("ver", "Shows the running Torch version.")]
public void Version()
{
- var ver = Context.Torch.Version;
+ var ver = Context.Torch.TorchVersion;
Context.Respond($"Torch version: {ver}");
}
diff --git a/Torch/Managers/MultiplayerManager.cs b/Torch/Managers/MultiplayerManager.cs
index 378422c..b743c62 100644
--- a/Torch/Managers/MultiplayerManager.cs
+++ b/Torch/Managers/MultiplayerManager.cs
@@ -82,7 +82,7 @@ namespace Torch.Managers
///
/// Send a message in chat.
///
- public void SendMessage(string message, long playerId, string author = "Server", string font = MyFontEnum.Blue)
+ public void SendMessage(string message, long playerId, string author = "Server", string font = MyFontEnum.Red)
{
var msg = new ScriptedChatMsg {Author = author, Font = font, Target = playerId, Text = message};
MyMultiplayerBase.SendScriptedChatMessage(ref msg);
@@ -164,7 +164,7 @@ namespace Torch.Managers
private HashSet _waitingForGroup;
private HashSet _waitingForFriends;
private Dictionary _gameOwnerIds = new Dictionary();
- private IMultiplayer _multiplayerImplementation;
+ //private IMultiplayer _multiplayerImplementation;
///
/// Removes Keen's hooks into some Steam events so we have full control over client authentication
diff --git a/Torch/Managers/NetworkManager/NetworkManager.cs b/Torch/Managers/NetworkManager/NetworkManager.cs
index 2a735a3..e0c3ece 100644
--- a/Torch/Managers/NetworkManager/NetworkManager.cs
+++ b/Torch/Managers/NetworkManager/NetworkManager.cs
@@ -16,8 +16,16 @@ namespace Torch.Managers
{
private NetworkManager()
{
- if (ReflectionUnitTest())
- InitNetworkIntercept();
+ try
+ {
+ if (ReflectionUnitTest())
+ InitNetworkIntercept();
+ }
+ catch (Exception ex)
+ {
+ _log.Error("Error initializing network intercept");
+ _log.Error(ex);
+ }
}
private static Logger _log = LogManager.GetLogger(nameof(NetworkManager));
diff --git a/Torch/Managers/PluginManager.cs b/Torch/Managers/PluginManager.cs
index 25a925c..c669345 100644
--- a/Torch/Managers/PluginManager.cs
+++ b/Torch/Managers/PluginManager.cs
@@ -72,10 +72,10 @@ namespace Torch.Managers
///
/// Unloads all plugins.
///
- public void UnloadPlugins()
+ public void DisposePlugins()
{
foreach (var plugin in _plugins)
- plugin.Unload();
+ plugin.Dispose();
_plugins.Clear();
}
@@ -114,11 +114,14 @@ namespace Torch.Managers
catch (Exception e)
{
_log.Error($"Error loading plugin '{type.FullName}'");
+ _log.Error(e);
throw;
}
}
}
}
+
+ _plugins.ForEach(p => p.Init(_torch));
}
public IEnumerator GetEnumerator()
@@ -168,7 +171,7 @@ namespace Torch.Managers
public void Dispose()
{
- _manager.UnloadPlugins();
+ _manager.DisposePlugins();
}
}
}
diff --git a/Torch/Reflection.cs b/Torch/Reflection.cs
index 14f3e98..4f8b62d 100644
--- a/Torch/Reflection.cs
+++ b/Torch/Reflection.cs
@@ -48,7 +48,7 @@ namespace Torch
return true;
}
- catch (AmbiguousMatchException aex)
+ catch (AmbiguousMatchException)
{
return true;
}
@@ -95,7 +95,7 @@ namespace Torch
if (prop == null)
prop = type.GetProperty(propertyName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy);
if (prop == null)
- prop = type.BaseType.GetProperty(propertyName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy);
+ prop = type.BaseType?.GetProperty(propertyName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy);
if (prop == null)
{
Log.Error("Failed to find property '{0}' in type '{1}'", propertyName, type.FullName);
diff --git a/Torch/Torch.csproj b/Torch/Torch.csproj
index 690e454..e453fe7 100644
--- a/Torch/Torch.csproj
+++ b/Torch/Torch.csproj
@@ -145,6 +145,7 @@
+
diff --git a/Torch/TorchBase.cs b/Torch/TorchBase.cs
index 253cabf..15cc773 100644
--- a/Torch/TorchBase.cs
+++ b/Torch/TorchBase.cs
@@ -9,10 +9,14 @@ using System.Threading;
using System.Threading.Tasks;
using NLog;
using Sandbox;
+using Sandbox.Game;
+using Sandbox.Game.World;
using Sandbox.ModAPI;
+using SpaceEngineers.Game;
using Torch.API;
using Torch.Managers;
using VRage.Scripting;
+using VRage.Utils;
namespace Torch
{
@@ -24,20 +28,19 @@ namespace Torch
///
[Obsolete]
public static ITorchBase Instance { get; private set; }
- protected static Logger Log = LogManager.GetLogger("Torch");
- public Version Version { get; protected set; }
+ protected static Logger Log { get; } = LogManager.GetLogger("Torch");
+ public Version TorchVersion { get; protected set; }
+ public Version GameVersion { get; private set; }
public string[] RunArgs { get; set; }
public IPluginManager Plugins { get; protected set; }
public IMultiplayer Multiplayer { get; protected set; }
+ public event Action SessionLoading;
public event Action SessionLoaded;
+ public event Action SessionUnloading;
+ public event Action SessionUnloaded;
private bool _init;
- protected void InvokeSessionLoaded()
- {
- SessionLoaded?.Invoke();
- }
-
protected TorchBase()
{
if (Instance != null)
@@ -45,7 +48,7 @@ namespace Torch
Instance = this;
- Version = Assembly.GetExecutingAssembly().GetName().Version;
+ TorchVersion = Assembly.GetExecutingAssembly().GetName().Version;
RunArgs = new string[0];
Plugins = new PluginManager(this);
Multiplayer = new MultiplayerManager(this);
@@ -120,12 +123,34 @@ namespace Torch
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
+ SpaceEngineersGame.SetupBasicGameInfo();
+ SpaceEngineersGame.SetupPerGameSettings();
+ TorchVersion = Assembly.GetEntryAssembly().GetName().Version;
+ GameVersion = new Version(new MyVersion(MyPerGameSettings.BasicGameInfo.GameVersion.Value).FormattedText.ToString().Replace("_", "."));
+ var verInfo = $"Torch {TorchVersion}, SE {GameVersion}";
+ Console.Title = verInfo;
+#if DEBUG
+ Log.Info("DEBUG");
+#else
+ Log.Info("RELEASE");
+#endif
+ Log.Info(verInfo);
+ Log.Info($"Executing assembly: {Assembly.GetEntryAssembly().FullName}");
+ Log.Info($"Executing directory: {AppDomain.CurrentDomain.BaseDirectory}");
+
+ MySession.OnLoading += () => SessionLoading?.Invoke();
+ MySession.AfterLoading += () => SessionLoaded?.Invoke();
+ MySession.OnUnloading += () => SessionUnloading?.Invoke();
+ MySession.OnUnloaded += () => SessionUnloaded?.Invoke();
+
_init = true;
}
private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
Log.Fatal((Exception)e.ExceptionObject);
+ Console.ReadLine();
+ Environment.Exit(-1);
}
public abstract void Start();
diff --git a/Torch/TorchPluginBase.cs b/Torch/TorchPluginBase.cs
index fe7cb8f..5f5b456 100644
--- a/Torch/TorchPluginBase.cs
+++ b/Torch/TorchPluginBase.cs
@@ -18,7 +18,7 @@ namespace Torch
public Version Version { get; }
public string Name { get; }
public ITorchBase Torch { get; private set; }
- private static Logger _log = LogManager.GetCurrentClassLogger();
+ private static readonly Logger _log = LogManager.GetLogger(nameof(TorchPluginBase));
protected TorchPluginBase()
{
@@ -44,7 +44,7 @@ namespace Torch
Torch = torch;
}
- public abstract void Update();
- public abstract void Unload();
+ public virtual void Update() { }
+ public abstract void Dispose();
}
}
diff --git a/torchicon.ico b/torchicon.ico
new file mode 100644
index 0000000..4563964
Binary files /dev/null and b/torchicon.ico differ