diff --git a/OpenDreamRuntime/DreamManager.cs b/OpenDreamRuntime/DreamManager.cs index 46ee16f661..58ee95d465 100644 --- a/OpenDreamRuntime/DreamManager.cs +++ b/OpenDreamRuntime/DreamManager.cs @@ -1,6 +1,8 @@ using System.IO; using System.Linq; using System.Text.Json; +using System.Threading; + using DMCompiler.Bytecode; using DMCompiler.Json; using OpenDreamRuntime.Objects; @@ -33,6 +35,7 @@ public sealed partial class DreamManager { [Dependency] private readonly IEntitySystemManager _entitySystemManager = default!; [Dependency] private readonly IStatusHost _statusHost = default!; [Dependency] private readonly IDependencyCollection _dependencyCollection = default!; + [Dependency] private readonly IBaseServer _server = default!; private ServerAppearanceSystem? _appearanceSystem; @@ -59,6 +62,8 @@ public sealed partial class DreamManager { private ISawmill _sawmill = default!; + private string? _queuedShutdownReason; + //TODO This arg is awful and temporary until RT supports cvar overrides in unit tests public void PreInitialize(string? jsonPath) { _sawmill = Logger.GetSawmill("opendream"); @@ -99,6 +104,12 @@ public void Update() { return; _procScheduler.Process(); + var shutdownReason = Interlocked.Exchange(ref _queuedShutdownReason, null); + if (shutdownReason != null) { + _server.Shutdown(shutdownReason); + return; + } + UpdateStat(); _dreamMapManager.UpdateTiles(); DreamObjectSavefile.FlushAllUpdates(); @@ -340,6 +351,10 @@ public void HandleException(Exception e, string msg = "", string file = "", int WorldInstance.SpawnProc("Error", usr: null, new DreamValue(obj)); } + + public void QueueShutdown(string reason) { + _queuedShutdownReason = reason; + } } public enum RefType : uint { diff --git a/OpenDreamRuntime/Objects/Types/DreamObjectWorld.cs b/OpenDreamRuntime/Objects/Types/DreamObjectWorld.cs index 833bb60a94..e82ea2d7bb 100644 --- a/OpenDreamRuntime/Objects/Types/DreamObjectWorld.cs +++ b/OpenDreamRuntime/Objects/Types/DreamObjectWorld.cs @@ -4,7 +4,6 @@ using OpenDreamRuntime.Resources; using OpenDreamShared; using OpenDreamShared.Dream; -using Robust.Server; using Robust.Shared; using Robust.Shared.Configuration; using Robust.Shared.Network; @@ -15,7 +14,6 @@ namespace OpenDreamRuntime.Objects.Types; public sealed class DreamObjectWorld : DreamObject { public override bool ShouldCallNew => false; // Gets called manually later - [Dependency] private readonly IBaseServer _server = default!; [Dependency] private readonly IGameTiming _gameTiming = default!; [Dependency] private readonly INetManager _netManager = default!; [Dependency] private readonly IConfigurationManager _cfg = default!; @@ -88,7 +86,7 @@ public DreamObjectWorld(DreamObjectDefinition objectDefinition) : protected override void HandleDeletion() { base.HandleDeletion(); - _server.Shutdown("world was deleted"); + DreamManager.QueueShutdown("world was deleted"); } protected override bool TryGetVar(string varName, out DreamValue value) { diff --git a/OpenDreamRuntime/Procs/Native/DreamProcNativeWorld.cs b/OpenDreamRuntime/Procs/Native/DreamProcNativeWorld.cs index 6b190eefde..0a6f16107e 100644 --- a/OpenDreamRuntime/Procs/Native/DreamProcNativeWorld.cs +++ b/OpenDreamRuntime/Procs/Native/DreamProcNativeWorld.cs @@ -5,7 +5,6 @@ using Byond.TopicSender; using OpenDreamRuntime.Objects; using OpenDreamRuntime.Objects.Types; -using Robust.Server; namespace OpenDreamRuntime.Procs.Native; @@ -164,9 +163,7 @@ public static DreamValue NativeProc_Profile(NativeProc.Bundle bundle, DreamObjec [DreamProc("Reboot")] [DreamProcParameter("reason", Type = DreamValue.DreamValueTypeFlag.Float)] public static DreamValue NativeProc_Reboot(NativeProc.Bundle bundle, DreamObject? src, DreamObject? usr) { - var server = IoCManager.Resolve(); - - server.Shutdown("/world.Reboot() was called but restarting is very broken"); + bundle.DreamManager.QueueShutdown("/world.Reboot() was called but restarting is very broken"); return DreamValue.Null; }