Turn SandboxManager into a system (#6867)
This commit is contained in:
@@ -1,17 +1,12 @@
|
||||
using System.IO;
|
||||
using Content.Client.Administration.Managers;
|
||||
using Content.Client.Decals.UI;
|
||||
using Content.Client.Sandbox;
|
||||
using Content.Shared.Administration;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.Placement;
|
||||
using Robust.Client.ResourceManagement;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Client.Administration.UI.Tabs.AdminbusTab
|
||||
@@ -19,10 +14,6 @@ namespace Content.Client.Administration.UI.Tabs.AdminbusTab
|
||||
[GenerateTypedNameReferences]
|
||||
public sealed partial class AdminbusTab : Control
|
||||
{
|
||||
private EntitySpawnWindow? _entitySpawnWindow;
|
||||
private TileSpawnWindow? _tileSpawnWindow;
|
||||
private DecalPlacerWindow? _decalPlacerWindow;
|
||||
|
||||
public AdminbusTab()
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
@@ -53,38 +44,17 @@ namespace Content.Client.Administration.UI.Tabs.AdminbusTab
|
||||
|
||||
private void SpawnEntitiesButtonOnOnPressed(BaseButton.ButtonEventArgs obj)
|
||||
{
|
||||
//FIXME: WE SHOULDN'T NEED TO CHECK FOR DISPOSED
|
||||
if (_entitySpawnWindow == null || _entitySpawnWindow.Disposed)
|
||||
{
|
||||
_entitySpawnWindow = new EntitySpawnWindow(IoCManager.Resolve<IPlacementManager>(),
|
||||
IoCManager.Resolve<IPrototypeManager>(),
|
||||
IoCManager.Resolve<IResourceCache>());
|
||||
}
|
||||
|
||||
EntitySystem.Get<AdminSystem>().OpenCommand(_entitySpawnWindow);
|
||||
EntitySystem.Get<SandboxSystem>().ToggleEntitySpawnWindow();
|
||||
}
|
||||
|
||||
private void SpawnTilesButtonOnOnPressed(BaseButton.ButtonEventArgs obj)
|
||||
{
|
||||
//FIXME: WE SHOULDN'T NEED TO CHECK FOR DISPOSED
|
||||
if (_tileSpawnWindow == null || _tileSpawnWindow.Disposed)
|
||||
{
|
||||
_tileSpawnWindow = new TileSpawnWindow(IoCManager.Resolve<ITileDefinitionManager>(),
|
||||
IoCManager.Resolve<IPlacementManager>(),
|
||||
IoCManager.Resolve<IResourceCache>());
|
||||
}
|
||||
|
||||
EntitySystem.Get<AdminSystem>().OpenCommand(_tileSpawnWindow);
|
||||
EntitySystem.Get<SandboxSystem>().ToggleTilesWindow();
|
||||
}
|
||||
|
||||
private void SpawnDecalsButtonOnPressed(BaseButton.ButtonEventArgs obj)
|
||||
{
|
||||
if (_decalPlacerWindow == null || _decalPlacerWindow.Disposed)
|
||||
{
|
||||
_decalPlacerWindow = new DecalPlacerWindow(IoCManager.Resolve<IPrototypeManager>());
|
||||
}
|
||||
|
||||
EntitySystem.Get<AdminSystem>().OpenCommand(_decalPlacerWindow);
|
||||
EntitySystem.Get<SandboxSystem>().ToggleDecalsWindow();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -186,7 +186,6 @@ namespace Content.Client.Entry
|
||||
overlayMgr.AddOverlay(new RadiationPulseOverlay());
|
||||
|
||||
IoCManager.Resolve<IChatManager>().Initialize();
|
||||
IoCManager.Resolve<ISandboxManager>().Initialize();
|
||||
IoCManager.Resolve<IClientPreferencesManager>().Initialize();
|
||||
IoCManager.Resolve<IStationEventManager>().Initialize();
|
||||
IoCManager.Resolve<EuiManager>().Initialize();
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using Content.Client.Administration;
|
||||
using Content.Client.Administration.Managers;
|
||||
using Content.Client.Administration.Managers;
|
||||
using Content.Client.Changelog;
|
||||
using Content.Client.Chat.Managers;
|
||||
using Content.Client.Clickable;
|
||||
@@ -11,7 +10,6 @@ using Content.Client.Items.Managers;
|
||||
using Content.Client.Module;
|
||||
using Content.Client.Parallax.Managers;
|
||||
using Content.Client.Preferences;
|
||||
using Content.Client.Sandbox;
|
||||
using Content.Client.Screenshot;
|
||||
using Content.Client.StationEvents.Managers;
|
||||
using Content.Client.Stylesheets;
|
||||
@@ -20,7 +18,6 @@ using Content.Client.Voting;
|
||||
using Content.Shared.Actions;
|
||||
using Content.Shared.Administration;
|
||||
using Content.Shared.Module;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
namespace Content.Client.IoC
|
||||
{
|
||||
@@ -32,7 +29,6 @@ namespace Content.Client.IoC
|
||||
IoCManager.Register<IParallaxManager, ParallaxManager>();
|
||||
IoCManager.Register<IChatManager, ChatManager>();
|
||||
IoCManager.Register<IEscapeMenuOwner, EscapeMenuOwner>();
|
||||
IoCManager.Register<ISandboxManager, SandboxManager>();
|
||||
IoCManager.Register<IModuleManager, ClientModuleManager>();
|
||||
IoCManager.Register<IClientPreferencesManager, ClientPreferencesManager>();
|
||||
IoCManager.Register<IItemSlotManager, ItemSlotManager>();
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace Content.Client.Sandbox
|
||||
{
|
||||
public interface ISandboxManager
|
||||
{
|
||||
void Initialize();
|
||||
bool SandboxAllowed { get; }
|
||||
event Action<bool> AllowedChanged;
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,12 @@
|
||||
using System;
|
||||
using Content.Client.Administration.Managers;
|
||||
using Content.Client.Decals.UI;
|
||||
using Content.Client.HUD;
|
||||
using Content.Client.Markers;
|
||||
using Content.Client.SubFloor;
|
||||
using Content.Shared.Administration;
|
||||
using Content.Shared.GameTicking;
|
||||
using Content.Shared.Input;
|
||||
using Content.Shared.Sandbox;
|
||||
using Content.Shared.SubFloor;
|
||||
using Robust.Client.Console;
|
||||
using Robust.Client.Debugging;
|
||||
using Robust.Client.Graphics;
|
||||
@@ -14,13 +15,9 @@ using Robust.Client.Placement;
|
||||
using Robust.Client.ResourceManagement;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Input.Binding;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Network;
|
||||
using Robust.Shared.Prototypes;
|
||||
using static Robust.Client.UserInterface.Controls.BoxContainer;
|
||||
|
||||
namespace Content.Client.Sandbox
|
||||
@@ -116,41 +113,33 @@ namespace Content.Client.Sandbox
|
||||
|
||||
}
|
||||
|
||||
internal sealed class SandboxManager : SharedSandboxManager, ISandboxManager
|
||||
public sealed class SandboxSystem : SharedSandboxSystem
|
||||
{
|
||||
[Dependency] private readonly IClientConsoleHost _consoleHost = default!;
|
||||
[Dependency] private readonly IGameHud _gameHud = default!;
|
||||
[Dependency] private readonly IClientNetManager _netManager = default!;
|
||||
[Dependency] private readonly IPlacementManager _placementManager = default!;
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
[Dependency] private readonly IResourceCache _resourceCache = default!;
|
||||
[Dependency] private readonly ITileDefinitionManager _tileDefinitionManager = default!;
|
||||
[Dependency] private readonly IInputManager _inputManager = default!;
|
||||
[Dependency] private readonly IClientAdminManager _adminManager = default!;
|
||||
|
||||
public bool SandboxAllowed { get; private set; }
|
||||
|
||||
public event Action<bool>? AllowedChanged;
|
||||
|
||||
private SandboxWindow? _window;
|
||||
private SandboxWindow? _sandboxWindow;
|
||||
private EntitySpawnWindow? _spawnWindow;
|
||||
private TileSpawnWindow? _tilesSpawnWindow;
|
||||
private DecalPlacerWindow? _decalSpawnWindow;
|
||||
private bool _sandboxWindowToggled;
|
||||
|
||||
public void Initialize()
|
||||
public override void Initialize()
|
||||
{
|
||||
_netManager.RegisterNetMessage<MsgSandboxStatus>(message => SetAllowed(message.SandboxAllowed));
|
||||
|
||||
_netManager.RegisterNetMessage<MsgSandboxGiveAccess>();
|
||||
|
||||
_netManager.RegisterNetMessage<MsgSandboxRespawn>();
|
||||
|
||||
_netManager.RegisterNetMessage<MsgSandboxGiveAghost>();
|
||||
|
||||
_netManager.RegisterNetMessage<MsgSandboxSuicide>();
|
||||
base.Initialize();
|
||||
SubscribeNetworkEvent<MsgSandboxStatus>(OnSandboxStatus);
|
||||
SubscribeNetworkEvent<RoundRestartCleanupEvent>(OnRoundRestart);
|
||||
|
||||
_adminManager.AdminStatusUpdated += OnAdminStatus;
|
||||
_gameHud.SandboxButtonToggled += SandboxButtonPressed;
|
||||
|
||||
// Do these need cleanup?
|
||||
_inputManager.SetInputCommand(ContentKeyFunctions.OpenEntitySpawnWindow,
|
||||
InputCmdHandler.FromDelegate(session => ToggleEntitySpawnWindow()));
|
||||
_inputManager.SetInputCommand(ContentKeyFunctions.OpenSandboxWindow,
|
||||
@@ -161,83 +150,129 @@ namespace Content.Client.Sandbox
|
||||
InputCmdHandler.FromDelegate(session => ToggleDecalsWindow()));
|
||||
}
|
||||
|
||||
private void OnAdminStatus()
|
||||
{
|
||||
if (CanSandbox())
|
||||
Enable();
|
||||
else
|
||||
Disable();
|
||||
}
|
||||
|
||||
private bool CanSandbox()
|
||||
{
|
||||
return SandboxAllowed || _adminManager.IsActive();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Run when sandbox is disabled
|
||||
/// </summary>
|
||||
private void Disable()
|
||||
{
|
||||
_gameHud.SandboxButtonVisible = false;
|
||||
_sandboxWindow?.Close();
|
||||
_sandboxWindow = null;
|
||||
_spawnWindow?.Close();
|
||||
_tilesSpawnWindow?.Close();
|
||||
_decalSpawnWindow?.Close();
|
||||
}
|
||||
|
||||
private void Enable()
|
||||
{
|
||||
_gameHud.SandboxButtonVisible = true;
|
||||
}
|
||||
|
||||
private void OnRoundRestart(RoundRestartCleanupEvent ev)
|
||||
{
|
||||
// Go through and cleanup windows (even if they remain adminned better to just shut them).
|
||||
Disable();
|
||||
|
||||
if (CanSandbox())
|
||||
Enable();
|
||||
}
|
||||
|
||||
public override void Shutdown()
|
||||
{
|
||||
base.Shutdown();
|
||||
// TODO: Gamehud moment
|
||||
_gameHud.SandboxButtonToggled -= SandboxButtonPressed;
|
||||
_adminManager.AdminStatusUpdated -= OnAdminStatus;
|
||||
}
|
||||
|
||||
private void OnSandboxStatus(MsgSandboxStatus ev)
|
||||
{
|
||||
SetAllowed(ev.SandboxAllowed);
|
||||
}
|
||||
|
||||
private void SandboxButtonPressed(bool newValue)
|
||||
{
|
||||
_sandboxWindowToggled = newValue;
|
||||
UpdateSandboxWindowVisibility();
|
||||
}
|
||||
|
||||
private void ToggleSandboxWindow()
|
||||
{
|
||||
_sandboxWindowToggled = !_sandboxWindowToggled;
|
||||
UpdateSandboxWindowVisibility();
|
||||
}
|
||||
|
||||
private void UpdateSandboxWindowVisibility()
|
||||
{
|
||||
if (_sandboxWindowToggled && SandboxAllowed)
|
||||
OpenWindow();
|
||||
if (CanSandbox() && _sandboxWindow?.IsOpen != true)
|
||||
OpenSandboxWindow();
|
||||
else
|
||||
_window?.Close();
|
||||
_sandboxWindow?.Close();
|
||||
}
|
||||
|
||||
private void SetAllowed(bool newAllowed)
|
||||
{
|
||||
if (newAllowed == SandboxAllowed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
SandboxAllowed = newAllowed;
|
||||
_gameHud.SandboxButtonVisible = newAllowed;
|
||||
_gameHud.SandboxButtonVisible = CanSandbox();
|
||||
|
||||
if (!newAllowed)
|
||||
{
|
||||
// Sandbox permission revoked, close window.
|
||||
_window?.Close();
|
||||
}
|
||||
|
||||
AllowedChanged?.Invoke(newAllowed);
|
||||
if (!CanSandbox())
|
||||
Disable();
|
||||
}
|
||||
|
||||
private void OpenWindow()
|
||||
private void OpenSandboxWindow()
|
||||
{
|
||||
if (_window != null)
|
||||
if (_sandboxWindow != null)
|
||||
{
|
||||
if (!_sandboxWindow.IsOpen)
|
||||
_sandboxWindow.Open();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
_window = new SandboxWindow();
|
||||
_sandboxWindow = new SandboxWindow();
|
||||
|
||||
_window.OnClose += WindowOnOnClose;
|
||||
_sandboxWindow.OnClose += SandboxWindowOnClose;
|
||||
|
||||
_window.RespawnButton.OnPressed += OnRespawnButtonOnOnPressed;
|
||||
_window.SpawnTilesButton.OnPressed += OnSpawnTilesButtonClicked;
|
||||
_window.SpawnEntitiesButton.OnPressed += OnSpawnEntitiesButtonClicked;
|
||||
_window.SpawnDecalsButton.OnPressed += OnSpawnDecalsButtonClicked;
|
||||
_window.GiveFullAccessButton.OnPressed += OnGiveAdminAccessButtonClicked;
|
||||
_window.GiveAghostButton.OnPressed += OnGiveAghostButtonClicked;
|
||||
_window.ToggleLightButton.OnToggled += OnToggleLightButtonClicked;
|
||||
_window.ToggleFovButton.OnToggled += OnToggleFovButtonClicked;
|
||||
_window.ToggleShadowsButton.OnToggled += OnToggleShadowsButtonClicked;
|
||||
_window.SuicideButton.OnPressed += OnSuicideButtonClicked;
|
||||
_window.ToggleSubfloorButton.OnPressed += OnToggleSubfloorButtonClicked;
|
||||
_window.ShowMarkersButton.OnPressed += OnShowMarkersButtonClicked;
|
||||
_window.ShowBbButton.OnPressed += OnShowBbButtonClicked;
|
||||
_window.MachineLinkingButton.OnPressed += OnMachineLinkingButtonClicked;
|
||||
_sandboxWindow.RespawnButton.OnPressed += OnRespawnButtonOnOnPressed;
|
||||
_sandboxWindow.SpawnTilesButton.OnPressed += OnSpawnTilesButtonClicked;
|
||||
_sandboxWindow.SpawnEntitiesButton.OnPressed += OnSpawnEntitiesButtonClicked;
|
||||
_sandboxWindow.SpawnDecalsButton.OnPressed += OnSpawnDecalsButtonClicked;
|
||||
_sandboxWindow.GiveFullAccessButton.OnPressed += OnGiveAdminAccessButtonClicked;
|
||||
_sandboxWindow.GiveAghostButton.OnPressed += OnGiveAghostButtonClicked;
|
||||
_sandboxWindow.ToggleLightButton.OnToggled += OnToggleLightButtonClicked;
|
||||
_sandboxWindow.ToggleFovButton.OnToggled += OnToggleFovButtonClicked;
|
||||
_sandboxWindow.ToggleShadowsButton.OnToggled += OnToggleShadowsButtonClicked;
|
||||
_sandboxWindow.SuicideButton.OnPressed += OnSuicideButtonClicked;
|
||||
_sandboxWindow.ToggleSubfloorButton.OnPressed += OnToggleSubfloorButtonClicked;
|
||||
_sandboxWindow.ShowMarkersButton.OnPressed += OnShowMarkersButtonClicked;
|
||||
_sandboxWindow.ShowBbButton.OnPressed += OnShowBbButtonClicked;
|
||||
_sandboxWindow.MachineLinkingButton.OnPressed += OnMachineLinkingButtonClicked;
|
||||
|
||||
_window.OpenCentered();
|
||||
_sandboxWindow.OpenCentered();
|
||||
}
|
||||
|
||||
private void WindowOnOnClose()
|
||||
private void SandboxWindowOnClose()
|
||||
{
|
||||
_window = null;
|
||||
_sandboxWindowToggled = false;
|
||||
_sandboxWindow = null;
|
||||
}
|
||||
|
||||
private void OnRespawnButtonOnOnPressed(BaseButton.ButtonEventArgs args)
|
||||
{
|
||||
_netManager.ClientSendMessage(_netManager.CreateNetMessage<MsgSandboxRespawn>());
|
||||
RaiseNetworkEvent(new MsgSandboxRespawn());
|
||||
}
|
||||
|
||||
private void OnSpawnEntitiesButtonClicked(BaseButton.ButtonEventArgs args)
|
||||
@@ -291,24 +326,27 @@ namespace Content.Client.Sandbox
|
||||
|
||||
private void OnGiveAdminAccessButtonClicked(BaseButton.ButtonEventArgs args)
|
||||
{
|
||||
_netManager.ClientSendMessage(_netManager.CreateNetMessage<MsgSandboxGiveAccess>());
|
||||
RaiseNetworkEvent(new MsgSandboxGiveAccess());
|
||||
}
|
||||
|
||||
private void OnGiveAghostButtonClicked(BaseButton.ButtonEventArgs args)
|
||||
{
|
||||
_netManager.ClientSendMessage(_netManager.CreateNetMessage<MsgSandboxGiveAghost>());
|
||||
RaiseNetworkEvent(new MsgSandboxGiveAghost());
|
||||
}
|
||||
|
||||
private void OnSuicideButtonClicked(BaseButton.ButtonEventArgs args)
|
||||
{
|
||||
_netManager.ClientSendMessage(_netManager.CreateNetMessage<MsgSandboxSuicide>());
|
||||
RaiseNetworkEvent(new MsgSandboxSuicide());
|
||||
}
|
||||
|
||||
private void ToggleEntitySpawnWindow()
|
||||
// TODO: These should check for command perms + be reset if the round is over.
|
||||
public void ToggleEntitySpawnWindow()
|
||||
{
|
||||
if (_spawnWindow == null)
|
||||
{
|
||||
_spawnWindow = new EntitySpawnWindow(_placementManager, _prototypeManager, _resourceCache);
|
||||
if (!CanSandbox()) return;
|
||||
|
||||
_spawnWindow = new EntitySpawnWindow(_placementManager, PrototypeManager, _resourceCache);
|
||||
_spawnWindow.OpenToLeft();
|
||||
return;
|
||||
}
|
||||
@@ -323,10 +361,12 @@ namespace Content.Client.Sandbox
|
||||
}
|
||||
}
|
||||
|
||||
private void ToggleTilesWindow()
|
||||
public void ToggleTilesWindow()
|
||||
{
|
||||
if (_tilesSpawnWindow == null)
|
||||
{
|
||||
if (!CanSandbox()) return;
|
||||
|
||||
_tilesSpawnWindow = new TileSpawnWindow(_tileDefinitionManager, _placementManager, _resourceCache);
|
||||
_tilesSpawnWindow.OpenToLeft();
|
||||
return;
|
||||
@@ -342,11 +382,13 @@ namespace Content.Client.Sandbox
|
||||
}
|
||||
}
|
||||
|
||||
private void ToggleDecalsWindow()
|
||||
public void ToggleDecalsWindow()
|
||||
{
|
||||
if (_decalSpawnWindow == null)
|
||||
{
|
||||
_decalSpawnWindow = new DecalPlacerWindow(_prototypeManager);
|
||||
if (!CanSandbox()) return;
|
||||
|
||||
_decalSpawnWindow = new DecalPlacerWindow(PrototypeManager);
|
||||
_decalSpawnWindow.OpenToLeft();
|
||||
return;
|
||||
}
|
||||
@@ -361,6 +403,7 @@ namespace Content.Client.Sandbox
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: need to cleanup these
|
||||
private void ToggleLight()
|
||||
{
|
||||
_consoleHost.ExecuteCommand("togglelight");
|
||||
@@ -112,7 +112,6 @@ namespace Content.Server.Entry
|
||||
}
|
||||
else
|
||||
{
|
||||
IoCManager.Resolve<ISandboxManager>().Initialize();
|
||||
IoCManager.Resolve<RecipeManager>().Initialize();
|
||||
IoCManager.Resolve<ActionManager>().Initialize();
|
||||
IoCManager.Resolve<BlackboardManager>().Initialize();
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
using Content.Server.Sandbox;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
namespace Content.Server.GameTicking.Rules;
|
||||
|
||||
public sealed class SandboxRuleSystem : GameRuleSystem
|
||||
{
|
||||
[Dependency] private readonly ISandboxManager _sandbox = default!;
|
||||
[Dependency] private readonly SandboxSystem _sandbox = default!;
|
||||
|
||||
public override string Prototype => "Sandbox";
|
||||
|
||||
|
||||
@@ -16,13 +16,11 @@ using Content.Server.NodeContainer.NodeGroups;
|
||||
using Content.Server.Objectives;
|
||||
using Content.Server.Objectives.Interfaces;
|
||||
using Content.Server.Preferences.Managers;
|
||||
using Content.Server.Sandbox;
|
||||
using Content.Server.Voting.Managers;
|
||||
using Content.Shared.Actions;
|
||||
using Content.Shared.Administration;
|
||||
using Content.Shared.Kitchen;
|
||||
using Content.Shared.Module;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
namespace Content.Server.IoC
|
||||
{
|
||||
@@ -33,7 +31,6 @@ namespace Content.Server.IoC
|
||||
IoCManager.Register<IChatManager, ChatManager>();
|
||||
IoCManager.Register<IChatSanitizationManager, ChatSanitizationManager>();
|
||||
IoCManager.Register<IMoMMILink, MoMMILink>();
|
||||
IoCManager.Register<ISandboxManager, SandboxManager>();
|
||||
IoCManager.Register<IModuleManager, ServerModuleManager>();
|
||||
IoCManager.Register<IServerPreferencesManager, ServerPreferencesManager>();
|
||||
IoCManager.Register<IServerDbManager, ServerDbManager>();
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace Content.Server.Sandbox.Commands
|
||||
|
||||
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
var sandboxManager = IoCManager.Resolve<ISandboxManager>();
|
||||
var sandboxManager = EntitySystem.Get<SandboxSystem>();
|
||||
var adminManager = IoCManager.Resolve<IAdminManager>();
|
||||
if (shell.IsClient && (!sandboxManager.IsSandboxEnabled && !adminManager.HasAdminFlag((IPlayerSession)shell.Player!, AdminFlags.Mapping)))
|
||||
{
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
namespace Content.Server.Sandbox
|
||||
{
|
||||
public interface ISandboxManager
|
||||
{
|
||||
bool IsSandboxEnabled { get; set; }
|
||||
void Initialize();
|
||||
}
|
||||
}
|
||||
@@ -22,14 +22,16 @@ using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Server.Sandbox
|
||||
{
|
||||
internal sealed class SandboxManager : SharedSandboxManager, ISandboxManager, IEntityEventSubscriber
|
||||
public sealed class SandboxSystem : SharedSandboxSystem
|
||||
{
|
||||
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
||||
[Dependency] private readonly IServerNetManager _netManager = default!;
|
||||
[Dependency] private readonly IPlacementManager _placementManager = default!;
|
||||
[Dependency] private readonly IConGroupController _conGroupController = default!;
|
||||
[Dependency] private readonly IEntityManager _entityManager = default!;
|
||||
[Dependency] private readonly IServerConsoleHost _host = default!;
|
||||
[Dependency] private readonly AccessSystem _access = default!;
|
||||
[Dependency] private readonly InventorySystem _inventory = default!;
|
||||
[Dependency] private readonly ItemSlotsSystem _slots = default!;
|
||||
[Dependency] private readonly GameTicker _ticker = default!;
|
||||
|
||||
private bool _isSandboxEnabled;
|
||||
|
||||
@@ -44,16 +46,17 @@ namespace Content.Server.Sandbox
|
||||
}
|
||||
}
|
||||
|
||||
public void Initialize()
|
||||
public override void Initialize()
|
||||
{
|
||||
_netManager.RegisterNetMessage<MsgSandboxStatus>();
|
||||
_netManager.RegisterNetMessage<MsgSandboxRespawn>(SandboxRespawnReceived);
|
||||
_netManager.RegisterNetMessage<MsgSandboxGiveAccess>(SandboxGiveAccessReceived);
|
||||
_netManager.RegisterNetMessage<MsgSandboxGiveAghost>(SandboxGiveAghostReceived);
|
||||
_netManager.RegisterNetMessage<MsgSandboxSuicide>(SandboxSuicideReceived);
|
||||
base.Initialize();
|
||||
SubscribeNetworkEvent<MsgSandboxRespawn>(SandboxRespawnReceived);
|
||||
SubscribeNetworkEvent<MsgSandboxGiveAccess>(SandboxGiveAccessReceived);
|
||||
SubscribeNetworkEvent<MsgSandboxGiveAghost>(SandboxGiveAghostReceived);
|
||||
SubscribeNetworkEvent<MsgSandboxSuicide>(SandboxSuicideReceived);
|
||||
|
||||
SubscribeLocalEvent<GameRunLevelChangedEvent>(GameTickerOnOnRunLevelChanged);
|
||||
|
||||
_playerManager.PlayerStatusChanged += OnPlayerStatusChanged;
|
||||
_entityManager.EventBus.SubscribeEvent<GameRunLevelChangedEvent>(EventSource.Local, this, GameTickerOnOnRunLevelChanged);
|
||||
|
||||
_placementManager.AllowPlacementFunc = placement =>
|
||||
{
|
||||
@@ -74,6 +77,13 @@ namespace Content.Server.Sandbox
|
||||
};
|
||||
}
|
||||
|
||||
public override void Shutdown()
|
||||
{
|
||||
base.Shutdown();
|
||||
_placementManager.AllowPlacementFunc = null;
|
||||
_playerManager.PlayerStatusChanged -= OnPlayerStatusChanged;
|
||||
}
|
||||
|
||||
private void GameTickerOnOnRunLevelChanged(GameRunLevelChangedEvent obj)
|
||||
{
|
||||
// Automatically clear sandbox state when round resets.
|
||||
@@ -86,60 +96,51 @@ namespace Content.Server.Sandbox
|
||||
private void OnPlayerStatusChanged(object? sender, SessionStatusEventArgs e)
|
||||
{
|
||||
if (e.NewStatus != SessionStatus.Connected || e.OldStatus != SessionStatus.Connecting)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var msg = _netManager.CreateNetMessage<MsgSandboxStatus>();
|
||||
msg.SandboxAllowed = IsSandboxEnabled;
|
||||
_netManager.ServerSendMessage(msg, e.Session.ConnectedClient);
|
||||
RaiseNetworkEvent(new MsgSandboxStatus {SandboxAllowed = IsSandboxEnabled}, e.Session.ConnectedClient);
|
||||
}
|
||||
|
||||
private void SandboxRespawnReceived(MsgSandboxRespawn message)
|
||||
private void SandboxRespawnReceived(MsgSandboxRespawn message, EntitySessionEventArgs args)
|
||||
{
|
||||
if (!IsSandboxEnabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var player = _playerManager.GetSessionByChannel(message.MsgChannel);
|
||||
EntitySystem.Get<GameTicker>().Respawn(player);
|
||||
var player = _playerManager.GetSessionByChannel(args.SenderSession.ConnectedClient);
|
||||
if (player.AttachedEntity == null) return;
|
||||
|
||||
_ticker.Respawn(player);
|
||||
}
|
||||
|
||||
private void SandboxGiveAccessReceived(MsgSandboxGiveAccess message)
|
||||
private void SandboxGiveAccessReceived(MsgSandboxGiveAccess message, EntitySessionEventArgs args)
|
||||
{
|
||||
if (!IsSandboxEnabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var player = _playerManager.GetSessionByChannel(message.MsgChannel);
|
||||
var player = _playerManager.GetSessionByChannel(args.SenderSession.ConnectedClient);
|
||||
if (player.AttachedEntity is not {} attached)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var allAccess = IoCManager.Resolve<IPrototypeManager>()
|
||||
var allAccess = PrototypeManager
|
||||
.EnumeratePrototypes<AccessLevelPrototype>()
|
||||
.Select(p => p.ID).ToArray();
|
||||
|
||||
var invSystem = EntitySystem.Get<InventorySystem>();
|
||||
|
||||
if (invSystem.TryGetSlotEntity(attached, "id", out var slotEntity))
|
||||
if (_inventory.TryGetSlotEntity(attached, "id", out var slotEntity))
|
||||
{
|
||||
if (_entityManager.HasComponent<AccessComponent>(slotEntity))
|
||||
if (HasComp<AccessComponent>(slotEntity))
|
||||
{
|
||||
UpgradeId(slotEntity.Value);
|
||||
}
|
||||
else if (_entityManager.TryGetComponent(slotEntity, out PDAComponent? pda))
|
||||
else if (TryComp<PDAComponent>(slotEntity, out var pda))
|
||||
{
|
||||
if (pda.ContainedID == null)
|
||||
{
|
||||
var newID = CreateFreshId();
|
||||
if (_entityManager.TryGetComponent(pda.Owner, out ItemSlotsComponent? itemSlots))
|
||||
if (TryComp<ItemSlotsComponent>(pda.Owner, out var itemSlots))
|
||||
{
|
||||
_entityManager.EntitySysManager.GetEntitySystem<ItemSlotsSystem>().
|
||||
TryInsert(slotEntity.Value, pda.IdSlot, newID, null);
|
||||
_slots.TryInsert(slotEntity.Value, pda.IdSlot, newID, null);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -148,21 +149,20 @@ namespace Content.Server.Sandbox
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (_entityManager.TryGetComponent<HandsComponent?>(attached, out var hands))
|
||||
else if (TryComp<HandsComponent>(attached, out var hands))
|
||||
{
|
||||
var card = CreateFreshId();
|
||||
if (!invSystem.TryEquip(attached, card, "id", true, true))
|
||||
if (!_inventory.TryEquip(attached, card, "id", true, true))
|
||||
{
|
||||
hands.PutInHandOrDrop(_entityManager.GetComponent<SharedItemComponent>(card));
|
||||
hands.PutInHandOrDrop(Comp<SharedItemComponent>(card));
|
||||
}
|
||||
}
|
||||
|
||||
void UpgradeId(EntityUid id)
|
||||
{
|
||||
var accessSystem = EntitySystem.Get<AccessSystem>();
|
||||
accessSystem.TrySetTags(id, allAccess);
|
||||
_access.TrySetTags(id, allAccess);
|
||||
|
||||
if (_entityManager.TryGetComponent(id, out SpriteComponent? sprite))
|
||||
if (TryComp<SpriteComponent>(id, out var sprite))
|
||||
{
|
||||
sprite.LayerSetState(0, "gold");
|
||||
}
|
||||
@@ -170,42 +170,36 @@ namespace Content.Server.Sandbox
|
||||
|
||||
EntityUid CreateFreshId()
|
||||
{
|
||||
var card = _entityManager.SpawnEntity("CaptainIDCard", _entityManager.GetComponent<TransformComponent>(attached).Coordinates);
|
||||
var card = Spawn("CaptainIDCard", Transform(attached).Coordinates);
|
||||
UpgradeId(card);
|
||||
|
||||
_entityManager.GetComponent<IdCardComponent>(card).FullName = _entityManager.GetComponent<MetaDataComponent>(attached).EntityName;
|
||||
Comp<IdCardComponent>(card).FullName = MetaData(attached).EntityName;
|
||||
return card;
|
||||
}
|
||||
}
|
||||
|
||||
private void SandboxGiveAghostReceived(MsgSandboxGiveAghost message)
|
||||
private void SandboxGiveAghostReceived(MsgSandboxGiveAghost message, EntitySessionEventArgs args)
|
||||
{
|
||||
if (!IsSandboxEnabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var player = _playerManager.GetSessionByChannel(message.MsgChannel);
|
||||
var player = _playerManager.GetSessionByChannel(args.SenderSession.ConnectedClient);
|
||||
|
||||
_host.ExecuteCommand(player, _conGroupController.CanCommand(player, "aghost") ? "aghost" : "ghost");
|
||||
}
|
||||
|
||||
private void SandboxSuicideReceived(MsgSandboxSuicide message)
|
||||
private void SandboxSuicideReceived(MsgSandboxSuicide message, EntitySessionEventArgs args)
|
||||
{
|
||||
if (!IsSandboxEnabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var player = _playerManager.GetSessionByChannel(message.MsgChannel);
|
||||
var player = _playerManager.GetSessionByChannel(args.SenderSession.ConnectedClient);
|
||||
_host.ExecuteCommand(player, "suicide");
|
||||
}
|
||||
|
||||
private void UpdateSandboxStatusForAll()
|
||||
{
|
||||
var msg = _netManager.CreateNetMessage<MsgSandboxStatus>();
|
||||
msg.SandboxAllowed = IsSandboxEnabled;
|
||||
_netManager.ServerSendToAll(msg);
|
||||
RaiseNetworkEvent(new MsgSandboxStatus {SandboxAllowed = IsSandboxEnabled});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
using Lidgren.Network;
|
||||
using Robust.Shared.Network;
|
||||
|
||||
namespace Content.Shared.Sandbox
|
||||
{
|
||||
public abstract class SharedSandboxManager
|
||||
{
|
||||
protected sealed class MsgSandboxStatus : NetMessage
|
||||
{
|
||||
public override MsgGroups MsgGroup => MsgGroups.Command;
|
||||
|
||||
public bool SandboxAllowed { get; set; }
|
||||
|
||||
public override void ReadFromBuffer(NetIncomingMessage buffer)
|
||||
{
|
||||
SandboxAllowed = buffer.ReadBoolean();
|
||||
}
|
||||
|
||||
public override void WriteToBuffer(NetOutgoingMessage buffer)
|
||||
{
|
||||
buffer.Write(SandboxAllowed);
|
||||
}
|
||||
}
|
||||
|
||||
protected sealed class MsgSandboxRespawn : NetMessage
|
||||
{
|
||||
public override MsgGroups MsgGroup => MsgGroups.Command;
|
||||
|
||||
public override void ReadFromBuffer(NetIncomingMessage buffer)
|
||||
{
|
||||
}
|
||||
|
||||
public override void WriteToBuffer(NetOutgoingMessage buffer)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
protected sealed class MsgSandboxGiveAccess : NetMessage
|
||||
{
|
||||
public override MsgGroups MsgGroup => MsgGroups.Command;
|
||||
|
||||
public override void ReadFromBuffer(NetIncomingMessage buffer)
|
||||
{
|
||||
}
|
||||
|
||||
public override void WriteToBuffer(NetOutgoingMessage buffer)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected sealed class MsgSandboxGiveAghost : NetMessage
|
||||
{
|
||||
public override MsgGroups MsgGroup => MsgGroups.Command;
|
||||
|
||||
public override void ReadFromBuffer(NetIncomingMessage buffer)
|
||||
{
|
||||
}
|
||||
|
||||
public override void WriteToBuffer(NetOutgoingMessage buffer)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected sealed class MsgSandboxSuicide : NetMessage
|
||||
{
|
||||
public override MsgGroups MsgGroup => MsgGroups.Command;
|
||||
|
||||
public override void ReadFromBuffer(NetIncomingMessage buffer)
|
||||
{
|
||||
}
|
||||
|
||||
public override void WriteToBuffer(NetOutgoingMessage buffer)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
28
Content.Shared/Sandbox/SharedSandboxSystem.cs
Normal file
28
Content.Shared/Sandbox/SharedSandboxSystem.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.Sandbox
|
||||
{
|
||||
public abstract class SharedSandboxSystem : EntitySystem
|
||||
{
|
||||
[Dependency] protected readonly IPrototypeManager PrototypeManager = default!;
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
protected sealed class MsgSandboxStatus : EntityEventArgs
|
||||
{
|
||||
public bool SandboxAllowed { get; set; }
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
protected sealed class MsgSandboxRespawn : EntityEventArgs {}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
protected sealed class MsgSandboxGiveAccess : EntityEventArgs {}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
protected sealed class MsgSandboxGiveAghost : EntityEventArgs {}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
protected sealed class MsgSandboxSuicide : EntityEventArgs {}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user