Fix NRE in MyGameService static constructor

This commit is contained in:
2023-06-18 01:06:22 -04:00
parent d65c20a05d
commit e70e1ca4e6
2 changed files with 14 additions and 9 deletions

View File

@@ -56,9 +56,7 @@ namespace Torch.Server
AddManager(new EntityControlManager(this)); AddManager(new EntityControlManager(this));
AddManager(new RemoteAPIManager(this)); AddManager(new RemoteAPIManager(this));
var sessionManager = Managers.GetManager<ITorchSessionManager>();
sessionManager.AddFactory(x => new MultiplayerManagerDedicated(this));
sessionManager.SessionStateChanged += OnSessionStateChanged;
// Needs to be done at some point after MyVRageWindows.Init // Needs to be done at some point after MyVRageWindows.Init
// where the debug listeners are registered // where the debug listeners are registered
@@ -128,6 +126,10 @@ namespace Torch.Server
{ {
Log.Info("Initializing server"); Log.Info("Initializing server");
base.Init(); base.Init();
var sessionManager = Managers.GetManager<ITorchSessionManager>();
sessionManager.AddFactory(x => new MultiplayerManagerDedicated(this));
sessionManager.SessionStateChanged += OnSessionStateChanged;
GetManager<InstanceManager>().LoadInstance(InstancePath); GetManager<InstanceManager>().LoadInstance(InstancePath);
CanRun = true; CanRun = true;
Initialized?.Invoke(this); Initialized?.Invoke(this);

View File

@@ -113,12 +113,6 @@ namespace Torch
Plugins = new PluginManager(this); Plugins = new PluginManager(this);
#pragma warning restore CS0618 #pragma warning restore CS0618
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.AddManager(new PatchManager(this)); Managers.AddManager(new PatchManager(this));
Managers.AddManager(new FilesystemManager(this)); Managers.AddManager(new FilesystemManager(this));
Managers.AddManager(new UpdateManager(this)); Managers.AddManager(new UpdateManager(this));
@@ -286,6 +280,15 @@ namespace Torch
Game = new VRageGame(this, TweakGameSettings, SteamAppName, SteamAppId, InstancePath, RunArgs); Game = new VRageGame(this, TweakGameSettings, SteamAppName, SteamAppId, InstancePath, RunArgs);
if (!Game.WaitFor(VRageGame.GameState.Stopped)) if (!Game.WaitFor(VRageGame.GameState.Stopped))
Log.Warn("Failed to wait for game to be initialized"); 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(); Managers.Attach();
_init = true; _init = true;