Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
117ea7df91 | |||
6ec355f931 | |||
![]() |
343420f1d8 |
@@ -14,6 +14,9 @@ namespace Torch.API.Managers
|
||||
/// <summary>
|
||||
/// Fired when plugins are loaded.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Fired when plugins are loaded and immediately if subscribed after the plugins are loaded.
|
||||
/// </remarks>
|
||||
event Action<IReadOnlyCollection<ITorchPlugin>> PluginsLoaded;
|
||||
|
||||
/// <summary>
|
||||
|
@@ -58,7 +58,9 @@ namespace Torch.Server
|
||||
AddManager(new EntityControlManager(this));
|
||||
AddManager(new RemoteAPIManager(this));
|
||||
|
||||
|
||||
var sessionManager = Managers.GetManager<ITorchSessionManager>();
|
||||
sessionManager.AddFactory(_ => new MultiplayerManagerDedicated(this));
|
||||
sessionManager.SessionStateChanged += OnSessionStateChanged;
|
||||
|
||||
// Needs to be done at some point after MyVRageWindows.Init
|
||||
// where the debug listeners are registered
|
||||
@@ -119,7 +121,38 @@ namespace Torch.Server
|
||||
/// <inheritdoc />
|
||||
public ServerState State { get; private set; }
|
||||
|
||||
public event Action<ITorchServer> Initialized;
|
||||
private Action<ITorchServer> _initializedEvent;
|
||||
|
||||
public event Action<ITorchServer> Initialized
|
||||
{
|
||||
add
|
||||
{
|
||||
var action = _initializedEvent;
|
||||
Action<ITorchServer> action2;
|
||||
do
|
||||
{
|
||||
action2 = action;
|
||||
var action3 = (Action<ITorchServer>)Delegate.Combine(action2, value);
|
||||
action = Interlocked.CompareExchange(ref _initializedEvent, action3, action2);
|
||||
}
|
||||
while (action != action2);
|
||||
|
||||
if (GetManager<InstanceManager>().DedicatedConfig != null)
|
||||
value(this); //if already initialized
|
||||
}
|
||||
remove
|
||||
{
|
||||
var action = _initializedEvent;
|
||||
Action<ITorchServer> action2;
|
||||
do
|
||||
{
|
||||
action2 = action;
|
||||
var action3 = (Action<ITorchServer>)Delegate.Remove(action2, value);
|
||||
action = Interlocked.CompareExchange(ref _initializedEvent, action3, action2);
|
||||
}
|
||||
while (action != action2);
|
||||
}
|
||||
}
|
||||
|
||||
public int OnlinePlayers { get; private set; }
|
||||
|
||||
@@ -128,13 +161,9 @@ namespace Torch.Server
|
||||
{
|
||||
Log.Info("Initializing server");
|
||||
base.Init();
|
||||
var sessionManager = Managers.GetManager<ITorchSessionManager>();
|
||||
sessionManager.AddFactory(x => new MultiplayerManagerDedicated(this));
|
||||
sessionManager.SessionStateChanged += OnSessionStateChanged;
|
||||
|
||||
GetManager<InstanceManager>().LoadInstance(InstancePath);
|
||||
CanRun = true;
|
||||
Initialized?.Invoke(this);
|
||||
_initializedEvent?.Invoke(this);
|
||||
Log.Info($"Initialized server '{InstanceName}' at '{InstancePath}'");
|
||||
}
|
||||
|
||||
|
@@ -52,7 +52,39 @@ namespace Torch.Managers
|
||||
/// <inheritdoc />
|
||||
public IReadOnlyDictionary<Guid, ITorchPlugin> Plugins => _plugins.AsReadOnlyObservable();
|
||||
|
||||
public event Action<IReadOnlyCollection<ITorchPlugin>> PluginsLoaded;
|
||||
private Action<IReadOnlyCollection<ITorchPlugin>> _pluginsLoaded;
|
||||
private bool _loaded;
|
||||
|
||||
public event Action<IReadOnlyCollection<ITorchPlugin>> PluginsLoaded
|
||||
{
|
||||
add
|
||||
{
|
||||
var action = _pluginsLoaded;
|
||||
Action<IReadOnlyCollection<ITorchPlugin>> action2;
|
||||
do
|
||||
{
|
||||
action2 = action;
|
||||
var action3 = (Action<IReadOnlyCollection<ITorchPlugin>>)Delegate.Combine(action2, value);
|
||||
action = Interlocked.CompareExchange(ref _pluginsLoaded, action3, action2);
|
||||
}
|
||||
while (action != action2);
|
||||
|
||||
if (_loaded)
|
||||
value(_plugins.Values.AsReadOnly());
|
||||
}
|
||||
remove
|
||||
{
|
||||
var action = _pluginsLoaded;
|
||||
Action<IReadOnlyCollection<ITorchPlugin>> action2;
|
||||
do
|
||||
{
|
||||
action2 = action;
|
||||
var action3 = (Action<IReadOnlyCollection<ITorchPlugin>>)Delegate.Remove(action2, value);
|
||||
action = Interlocked.CompareExchange(ref _pluginsLoaded, action3, action2);
|
||||
}
|
||||
while (action != action2);
|
||||
}
|
||||
}
|
||||
|
||||
public PluginManager(ITorchBase torchInstance) : base(torchInstance)
|
||||
{
|
||||
@@ -145,7 +177,8 @@ namespace Torch.Managers
|
||||
plugin.Init(Torch);
|
||||
}
|
||||
_log.Info($"Loaded {_plugins.Count} plugins.");
|
||||
PluginsLoaded?.Invoke(_plugins.Values.AsReadOnly());
|
||||
_loaded = true;
|
||||
_pluginsLoaded?.Invoke(_plugins.Values.AsReadOnly());
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -220,7 +253,8 @@ namespace Torch.Managers
|
||||
plugin.Init(Torch);
|
||||
}
|
||||
_log.Info($"Loaded {_plugins.Count} plugins.");
|
||||
PluginsLoaded?.Invoke(_plugins.Values.AsReadOnly());
|
||||
_loaded = true;
|
||||
_pluginsLoaded?.Invoke(_plugins.Values.AsReadOnly());
|
||||
}
|
||||
|
||||
//debug flag is set when the user asks us to run with a specific plugin for plugin development debug
|
||||
|
@@ -49,8 +49,6 @@ namespace Torch.Session
|
||||
public TorchSessionManager(ITorchBase torchInstance) : base(torchInstance)
|
||||
{
|
||||
_overrideMods = new Dictionary<ulong, MyObjectBuilder_Checkpoint.ModItem>();
|
||||
if (Torch.Config.UgcServiceType == UGCServiceType.Steam)
|
||||
_overrideMods.Add(ModCommunication.MOD_ID, ModItemUtils.Create(ModCommunication.MOD_ID));
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
@@ -74,7 +72,9 @@ namespace Torch.Session
|
||||
{
|
||||
if (_overrideMods.ContainsKey(modId))
|
||||
return false;
|
||||
var item = ModItemUtils.Create(modId);
|
||||
#pragma warning disable CS0618
|
||||
var item = ModItemUtils.Create(modId, TorchBase.Instance.Config.UgcServiceType.ToString());
|
||||
#pragma warning restore CS0618
|
||||
_overrideMods.Add(modId, item);
|
||||
|
||||
OverrideModsChanged?.Invoke(new CollectionChangeEventArgs(CollectionChangeAction.Add, item));
|
||||
@@ -193,6 +193,8 @@ namespace Torch.Session
|
||||
MySession.AfterLoading += SessionLoaded;
|
||||
MySession.OnUnloading += SessionUnloading;
|
||||
MySession.OnUnloaded += SessionUnloaded;
|
||||
if (Torch.Config.UgcServiceType == UGCServiceType.Steam)
|
||||
_overrideMods.Add(ModCommunication.MOD_ID, ModItemUtils.Create(ModCommunication.MOD_ID));
|
||||
}
|
||||
|
||||
|
||||
|
@@ -116,6 +116,12 @@ namespace Torch
|
||||
Plugins = new PluginManager(this);
|
||||
#pragma warning restore CS0618
|
||||
|
||||
var sessionManager = new TorchSessionManager(this);
|
||||
sessionManager.AddFactory(_ => Sync.IsServer ? new ChatManagerServer(this) : new ChatManagerClient(this));
|
||||
sessionManager.AddFactory(_ => Sync.IsServer ? new CommandManager(this) : null);
|
||||
sessionManager.AddFactory(_ => new EntityManager(this));
|
||||
|
||||
Managers.AddManager(sessionManager);
|
||||
Managers.AddManager(new PatchManager(this));
|
||||
Managers.AddManager(new FilesystemManager(this));
|
||||
Managers.AddManager(new UpdateManager(this));
|
||||
@@ -283,15 +289,6 @@ namespace Torch
|
||||
Game = new VRageGame(this, TweakGameSettings, SteamAppName, SteamAppId, InstancePath, RunArgs);
|
||||
if (!Game.WaitFor(VRageGame.GameState.Stopped))
|
||||
Log.Warn("Failed to wait for game to be initialized");
|
||||
|
||||
var sessionManager = new TorchSessionManager(this);
|
||||
sessionManager.AddFactory((x) => Sync.IsServer ? new ChatManagerServer(this) : new ChatManagerClient(this));
|
||||
sessionManager.AddFactory((x) => Sync.IsServer ? new CommandManager(this) : null);
|
||||
sessionManager.AddFactory((x) => new EntityManager(this));
|
||||
|
||||
Managers.AddManager(sessionManager);
|
||||
|
||||
|
||||
Managers.Attach();
|
||||
_init = true;
|
||||
|
||||
|
Reference in New Issue
Block a user