Tweak plugin init, fix issue in mod config

This commit is contained in:
John Gross
2017-06-17 13:06:21 -07:00
parent 2723973673
commit e36f54a55b
10 changed files with 48 additions and 31 deletions

View File

@@ -9,18 +9,29 @@ namespace Torch.API.Plugins
{ {
public interface ITorchPlugin : IDisposable public interface ITorchPlugin : IDisposable
{ {
/// <summary>
/// A unique ID for the plugin.
/// </summary>
Guid Id { get; } Guid Id { get; }
/// <summary>
/// The version of the plugin.
/// </summary>
Version Version { get; } Version Version { get; }
/// <summary>
/// The name of the plugin.
/// </summary>
string Name { get; } string Name { get; }
/// <summary> /// <summary>
/// Called when the game is initialized. /// This is called before the game loop is started.
/// </summary> /// </summary>
/// <param name="torchBase"></param> /// <param name="torchBase">Torch instance</param>
void Init(ITorchBase torchBase); void Init(ITorchBase torchBase);
/// <summary> /// <summary>
/// Called after each game tick. Not thread safe, use invocation methods in <see cref="ITorchBase"/>. /// This is called on the game thread after each tick.
/// </summary> /// </summary>
void Update(); void Update();
} }

View File

@@ -11,7 +11,7 @@ namespace Torch.API.Plugins
{ {
/// <summary> /// <summary>
/// Used by the server's WPF interface to load custom plugin controls. /// Used by the server's WPF interface to load custom plugin controls.
/// Do not instantiate your plugin control outside of this method! It will throw an exception. /// You must instantiate your plugin's control object here, otherwise it will not be owned by the correct thread for WPF.
/// </summary> /// </summary>
UserControl GetControl(); UserControl GetControl();
} }

View File

@@ -1,4 +1,4 @@
using System.Reflection; using System.Reflection;
[assembly: AssemblyVersion("1.0.167.670")] [assembly: AssemblyVersion("1.0.168.389")]
[assembly: AssemblyFileVersion("1.0.167.670")] [assembly: AssemblyFileVersion("1.0.168.389")]

View File

@@ -1,4 +1,4 @@
using System.Reflection; using System.Reflection;
[assembly: AssemblyVersion("1.0.167.670")] [assembly: AssemblyVersion("1.0.168.389")]
[assembly: AssemblyFileVersion("1.0.167.670")] [assembly: AssemblyFileVersion("1.0.168.389")]

View File

@@ -113,7 +113,7 @@ namespace Torch.Server
MySandboxGame.Log.WriteLine("Environment.CurrentDirectory: " + Environment.CurrentDirectory); MySandboxGame.Log.WriteLine("Environment.CurrentDirectory: " + Environment.CurrentDirectory);
MySandboxGame.Log.WriteLine("MainAssembly.ProcessorArchitecture: " + Assembly.GetExecutingAssembly().GetArchitecture()); MySandboxGame.Log.WriteLine("MainAssembly.ProcessorArchitecture: " + Assembly.GetExecutingAssembly().GetArchitecture());
MySandboxGame.Log.WriteLine("ExecutingAssembly.ProcessorArchitecture: " + MyFileSystem.MainAssembly.GetArchitecture()); MySandboxGame.Log.WriteLine("ExecutingAssembly.ProcessorArchitecture: " + MyFileSystem.MainAssembly.GetArchitecture());
MySandboxGame.Log.WriteLine("IntPtr.Size: " + IntPtr.Size.ToString()); MySandboxGame.Log.WriteLine("IntPtr.Size: " + IntPtr.Size);
MySandboxGame.Log.WriteLine("Default Culture: " + CultureInfo.CurrentCulture.Name); MySandboxGame.Log.WriteLine("Default Culture: " + CultureInfo.CurrentCulture.Name);
MySandboxGame.Log.WriteLine("Default UI Culture: " + CultureInfo.CurrentUICulture.Name); MySandboxGame.Log.WriteLine("Default UI Culture: " + CultureInfo.CurrentUICulture.Name);
MySandboxGame.Log.WriteLine("IsAdmin: " + new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator)); MySandboxGame.Log.WriteLine("IsAdmin: " + new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator));
@@ -150,6 +150,7 @@ namespace Torch.Server
VRage.Service.ExitListenerSTA.OnExit += delegate { MySandboxGame.Static?.Exit(); }; VRage.Service.ExitListenerSTA.OnExit += delegate { MySandboxGame.Static?.Exit(); };
base.Start();
runInternal.Invoke(null, null); runInternal.Invoke(null, null);
MySandboxGame.Log.Close(); MySandboxGame.Log.Close();

View File

@@ -23,27 +23,26 @@ namespace Torch.Server.ViewModels
{ {
_config = configDedicated; _config = configDedicated;
SessionSettings = new SessionSettingsViewModel(_config.SessionSettings); SessionSettings = new SessionSettingsViewModel(_config.SessionSettings);
Administrators = string.Join("\r\n", _config.Administrators); Administrators = string.Join(Environment.NewLine, _config.Administrators);
Banned = string.Join("\r\n", _config.Banned); Banned = string.Join(Environment.NewLine, _config.Banned);
Mods = string.Join("\r\n", _config.Mods); Mods = string.Join(Environment.NewLine, _config.Mods);
} }
public void Save(string path = null) public void Save(string path = null)
{ {
var newline = new [] {Environment.NewLine};
_config.Administrators.Clear(); _config.Administrators.Clear();
foreach (var admin in Administrators.Split('\r', '\n')) foreach (var admin in Administrators.Split(newline, StringSplitOptions.RemoveEmptyEntries))
if (!string.IsNullOrEmpty(admin)) _config.Administrators.Add(admin);
_config.Administrators.Add(admin);
_config.Banned.Clear(); _config.Banned.Clear();
foreach (var banned in Banned.Split('\r', '\n')) foreach (var banned in Banned.Split(newline, StringSplitOptions.RemoveEmptyEntries))
if (!string.IsNullOrEmpty(banned)) _config.Banned.Add(ulong.Parse(banned));
_config.Banned.Add(ulong.Parse(banned));
_config.Mods.Clear(); _config.Mods.Clear();
foreach (var mod in Mods.Split('\r', '\n')) foreach (var mod in Mods.Split(newline, StringSplitOptions.RemoveEmptyEntries))
if (!string.IsNullOrEmpty(mod)) _config.Mods.Add(ulong.Parse(mod));
_config.Mods.Add(ulong.Parse(mod));
_config.Save(path); _config.Save(path);
} }

View File

@@ -52,13 +52,13 @@ namespace Torch.Server.Views
Log.Info("Saved DS config."); Log.Info("Saved DS config.");
try try
{ {
var checkpoint = MyLocalCache.LoadCheckpoint(_viewModel.LoadWorld, out _); var checkpoint = MyLocalCache.LoadCheckpoint(Config.LoadWorld, out _);
checkpoint.Settings = _viewModel.SessionSettings; checkpoint.Settings = Config.SessionSettings;
checkpoint.Mods.Clear(); checkpoint.Mods.Clear();
foreach (var modId in _viewModel.Mods) foreach (var modId in Config.Mods)
checkpoint.Mods.Add(new MyObjectBuilder_Checkpoint.ModItem(modId)); checkpoint.Mods.Add(new MyObjectBuilder_Checkpoint.ModItem(modId));
MyLocalCache.SaveCheckpoint(checkpoint, _viewModel.LoadWorld); MyLocalCache.SaveCheckpoint(checkpoint, Config.LoadWorld);
Log.Info("Saved world config."); Log.Info("Saved world config.");
} }
catch (Exception e) catch (Exception e)

View File

@@ -118,6 +118,9 @@ namespace Torch.Managers
{ {
if (type.GetInterfaces().Contains(typeof(ITorchPlugin))) if (type.GetInterfaces().Contains(typeof(ITorchPlugin)))
{ {
if (type.GetCustomAttribute<PluginAttribute>() == null)
continue;
try try
{ {
var plugin = (TorchPluginBase)Activator.CreateInstance(type); var plugin = (TorchPluginBase)Activator.CreateInstance(type);
@@ -130,10 +133,9 @@ namespace Torch.Managers
commands.RegisterPluginCommands(plugin); commands.RegisterPluginCommands(plugin);
} }
catch (Exception e) catch
{ {
_log.Error($"Error loading plugin '{type.FullName}'"); _log.Error($"Error loading plugin '{type.FullName}'");
_log.Error(e);
throw; throw;
} }
} }

View File

@@ -217,8 +217,12 @@ namespace Torch
pluginList.Add(this); pluginList.Add(this);
} }
public abstract void Start(); public virtual void Start()
public abstract void Stop(); {
Plugins.Init();
}
public virtual void Stop() { }
/// <inheritdoc /> /// <inheritdoc />
public virtual void Dispose() public virtual void Dispose()
@@ -231,7 +235,6 @@ namespace Torch
{ {
Network.Init(); Network.Init();
ChatManager.Instance.Init(); ChatManager.Instance.Init();
Plugins.Init();
} }
/// <inheritdoc /> /// <inheritdoc />

View File

@@ -47,6 +47,7 @@ namespace Torch
} }
public virtual void Update() { } public virtual void Update() { }
public abstract void Dispose();
public virtual void Dispose() { }
} }
} }