diff --git a/Content.Client/Maps/GridDraggingSystem.cs b/Content.Client/Maps/GridDraggingSystem.cs index 556cd12992..843f7bf5c5 100644 --- a/Content.Client/Maps/GridDraggingSystem.cs +++ b/Content.Client/Maps/GridDraggingSystem.cs @@ -1,4 +1,3 @@ -using Content.Client.Administration.Managers; using Content.Shared.Maps; using Robust.Client.GameObjects; using Robust.Client.Graphics; @@ -24,6 +23,23 @@ public sealed class GridDraggingSystem : SharedGridDraggingSystem private Vector2 _localPosition; private MapCoordinates? _lastMousePosition; + public override void Initialize() + { + base.Initialize(); + SubscribeNetworkEvent(OnToggleMessage); + } + + private void OnToggleMessage(GridDragToggleMessage ev) + { + if (Enabled == ev.Enabled) + return; + + Enabled = ev.Enabled; + + if (!Enabled) + StopDragging(); + } + private void StartDragging(EntityUid grid, Vector2 localPosition) { _dragging = grid; diff --git a/Content.Client/Weapons/Ranged/Systems/TetherGunSystem.cs b/Content.Client/Weapons/Ranged/Systems/TetherGunSystem.cs index 5a6117d0b1..02e06617a1 100644 --- a/Content.Client/Weapons/Ranged/Systems/TetherGunSystem.cs +++ b/Content.Client/Weapons/Ranged/Systems/TetherGunSystem.cs @@ -31,6 +31,12 @@ public sealed class TetherGunSystem : SharedTetherGunSystem { base.Initialize(); SubscribeNetworkEvent(OnPredictTether); + SubscribeNetworkEvent(OnTetherGun); + } + + private void OnTetherGun(TetherGunToggleMessage ev) + { + Enabled = ev.Enabled; } private void OnPredictTether(PredictTetherEvent ev) diff --git a/Content.Client/Maps/GridDraggingCommand.cs b/Content.Server/Maps/GridDraggingCommand.cs similarity index 67% rename from Content.Client/Maps/GridDraggingCommand.cs rename to Content.Server/Maps/GridDraggingCommand.cs index daea5674dc..897b9c08ef 100644 --- a/Content.Client/Maps/GridDraggingCommand.cs +++ b/Content.Server/Maps/GridDraggingCommand.cs @@ -1,11 +1,14 @@ +using Content.Server.Administration; +using Content.Shared.Administration; using Content.Shared.Maps; using Robust.Shared.Console; -namespace Content.Client.Maps; +namespace Content.Server.Maps; /// /// Toggles GridDragging on the system. /// +[AdminCommand(AdminFlags.Fun)] public sealed class GridDraggingCommand : IConsoleCommand { public string Command => SharedGridDraggingSystem.CommandName; @@ -13,10 +16,16 @@ public sealed class GridDraggingCommand : IConsoleCommand public string Help => $"{Command}"; public void Execute(IConsoleShell shell, string argStr, string[] args) { - var system = IoCManager.Resolve().GetEntitySystem(); - system.Enabled ^= true; + if (shell.Player == null) + { + shell.WriteError("shell-server-cannot"); + return; + } - if (system.Enabled) + var system = IoCManager.Resolve().GetEntitySystem(); + system.Toggle(shell.Player); + + if (system.IsEnabled(shell.Player)) shell.WriteLine("Grid dragging toggled on"); else shell.WriteLine("Grid dragging toggled off"); diff --git a/Content.Server/Maps/GridDraggingSystem.cs b/Content.Server/Maps/GridDraggingSystem.cs index 2bfd0c8dac..3c6ebf005e 100644 --- a/Content.Server/Maps/GridDraggingSystem.cs +++ b/Content.Server/Maps/GridDraggingSystem.cs @@ -1,6 +1,8 @@ using Content.Shared.Maps; using Robust.Server.Console; using Robust.Server.Player; +using Robust.Shared.Players; +using Robust.Shared.Utility; namespace Content.Server.Maps; @@ -9,6 +11,8 @@ public sealed class GridDraggingSystem : SharedGridDraggingSystem { [Dependency] private readonly IConGroupController _admin = default!; + private readonly HashSet _draggers = new(); + public override void Initialize() { base.Initialize(); @@ -16,6 +20,31 @@ public sealed class GridDraggingSystem : SharedGridDraggingSystem SubscribeNetworkEvent(OnRequestVelocity); } + public bool IsEnabled(ICommonSession session) => _draggers.Contains(session); + + public void Toggle(ICommonSession session) + { + if (session is not IPlayerSession pSession) + return; + + DebugTools.Assert(_admin.CanCommand(pSession, CommandName)); + + // Weird but it's a toggle + if (_draggers.Add(session)) + { + + } + else + { + _draggers.Remove(session); + } + + RaiseNetworkEvent(new GridDragToggleMessage() + { + Enabled = _draggers.Contains(session), + }, session.ConnectedClient); + } + private void OnRequestVelocity(GridDragVelocityRequest ev, EntitySessionEventArgs args) { if (args.SenderSession is not IPlayerSession playerSession || diff --git a/Content.Server/Weapon/Ranged/Systems/TetherGunSystem.cs b/Content.Server/Weapon/Ranged/Systems/TetherGunSystem.cs index e1fc7edda6..79283137c5 100644 --- a/Content.Server/Weapon/Ranged/Systems/TetherGunSystem.cs +++ b/Content.Server/Weapon/Ranged/Systems/TetherGunSystem.cs @@ -1,3 +1,4 @@ +using System.Linq; using Content.Server.Ghost.Components; using Content.Shared.Administration; using Content.Shared.Weapons.Ranged.Systems; @@ -20,7 +21,8 @@ public sealed class TetherGunSystem : SharedTetherGunSystem [Dependency] private readonly SharedContainerSystem _container = default!; [Dependency] private readonly SharedJointSystem _joints = default!; - private Dictionary _tethered = new(); + private readonly Dictionary _tethered = new(); + private readonly HashSet _draggers = new(); private const string JointId = "tether-joint"; @@ -46,6 +48,35 @@ public sealed class TetherGunSystem : SharedTetherGunSystem _playerManager.PlayerStatusChanged -= OnStatusChange; } + public void Toggle(ICommonSession? session) + { + if (session == null) + return; + + if (_draggers.Add(session)) + { + RaiseNetworkEvent(new TetherGunToggleMessage() + { + Enabled = true, + }, session.ConnectedClient); + return; + } + + _draggers.Remove(session); + RaiseNetworkEvent(new TetherGunToggleMessage() + { + Enabled = false, + }, session.ConnectedClient); + } + + public bool IsEnabled(ICommonSession? session) + { + if (session == null) + return false; + + return _draggers.Contains(session); + } + private void OnStartTether(StartTetherEvent msg, EntitySessionEventArgs args) { if (args.SenderSession is not IPlayerSession playerSession || diff --git a/Content.Client/Weapons/Ranged/Commands/TetherGunCommand.cs b/Content.Server/Weapons/Ranged/Commands/TetherGunCommand.cs similarity index 57% rename from Content.Client/Weapons/Ranged/Commands/TetherGunCommand.cs rename to Content.Server/Weapons/Ranged/Commands/TetherGunCommand.cs index f932eeb8a0..436a2224f5 100644 --- a/Content.Client/Weapons/Ranged/Commands/TetherGunCommand.cs +++ b/Content.Server/Weapons/Ranged/Commands/TetherGunCommand.cs @@ -1,19 +1,23 @@ -using Content.Client.Weapons.Ranged.Systems; +using Content.Server.Administration; +using Content.Server.Weapon.Ranged.Systems; +using Content.Shared.Administration; +using Content.Shared.Weapons.Ranged.Systems; using Robust.Shared.Console; -namespace Content.Client.Weapons.Ranged; +namespace Content.Server.Weapons.Ranged.Commands; +[AdminCommand(AdminFlags.Fun)] public sealed class TetherGunCommand : IConsoleCommand { - public string Command => "tethergun"; + public string Command => SharedTetherGunSystem.CommandName; public string Description => "Allows you to drag mobs around with your mouse."; public string Help => $"{Command}"; public void Execute(IConsoleShell shell, string argStr, string[] args) { var system = IoCManager.Resolve().GetEntitySystem(); - system.Enabled ^= true; + system.Toggle(shell.Player); - if (system.Enabled) + if (system.IsEnabled(shell.Player)) shell.WriteLine("Tether gun toggled on"); else shell.WriteLine("Tether gun toggled off"); diff --git a/Content.Shared/Maps/SharedGridDraggingSystem.cs b/Content.Shared/Maps/SharedGridDraggingSystem.cs index 02ff95751d..b53f64c65b 100644 --- a/Content.Shared/Maps/SharedGridDraggingSystem.cs +++ b/Content.Shared/Maps/SharedGridDraggingSystem.cs @@ -3,7 +3,7 @@ using Robust.Shared.Serialization; namespace Content.Shared.Maps; /// -/// Helper system to allow you to move grids with a mouse. +/// Helper system to allow you to move entities with a mouse. /// public abstract class SharedGridDraggingSystem : EntitySystem { @@ -11,6 +11,15 @@ public abstract class SharedGridDraggingSystem : EntitySystem } +/// +/// Sent from server to client if grid dragging is toggled on. +/// +[Serializable, NetSerializable] +public sealed class GridDragToggleMessage : EntityEventArgs +{ + public bool Enabled; +} + /// /// Raised on the client to request a grid move to a specific position. /// diff --git a/Content.Shared/Weapons/Ranged/Systems/SharedTetherGunSystem.cs b/Content.Shared/Weapons/Ranged/Systems/SharedTetherGunSystem.cs index 15c3205f36..8b0ed07162 100644 --- a/Content.Shared/Weapons/Ranged/Systems/SharedTetherGunSystem.cs +++ b/Content.Shared/Weapons/Ranged/Systems/SharedTetherGunSystem.cs @@ -5,7 +5,16 @@ namespace Content.Shared.Weapons.Ranged.Systems; public abstract class SharedTetherGunSystem : EntitySystem { - protected const string CommandName = "tethergun"; + public const string CommandName = "tethergun"; +} + +/// +/// Sent from server to client if tether gun is toggled on. +/// +[Serializable, NetSerializable] +public sealed class TetherGunToggleMessage : EntityEventArgs +{ + public bool Enabled; } [Serializable, NetSerializable] diff --git a/Resources/clientCommandPerms.yml b/Resources/clientCommandPerms.yml index 4d01cd7d4c..c62e81abf0 100644 --- a/Resources/clientCommandPerms.yml +++ b/Resources/clientCommandPerms.yml @@ -57,11 +57,6 @@ - nodevis - nodevisfilter -- Flags: FUN - Commands: - - tethergun - - griddrag - - Flags: ADMIN Commands: - togglehealthoverlay