diff --git a/Content.Client/GameObjects/Components/Observer/GhostComponent.cs b/Content.Client/GameObjects/Components/Observer/GhostComponent.cs index 75ffbf78ca..6321b8a63b 100644 --- a/Content.Client/GameObjects/Components/Observer/GhostComponent.cs +++ b/Content.Client/GameObjects/Components/Observer/GhostComponent.cs @@ -20,6 +20,7 @@ namespace Content.Client.GameObjects.Components.Observer [Dependency] private readonly IPlayerManager _playerManager = default!; [Dependency] private readonly IComponentManager _componentManager = default!; [Dependency] private readonly IChatManager _chatManager = default!; + public List WarpNames = new(); public Dictionary PlayerNames = new(); @@ -42,7 +43,6 @@ namespace Content.Client.GameObjects.Components.Observer } } - private void SetGhostVisibility(bool visibility) { foreach (var ghost in _componentManager.GetAllComponents(typeof(GhostComponent), true)) @@ -99,7 +99,9 @@ namespace Content.Client.GameObjects.Components.Observer public void SendReturnToBodyMessage() => SendNetworkMessage(new ReturnToBodyComponentMessage()); - public void SendGhostWarpRequestMessage(EntityUid target = default, string warpName = default!) => SendNetworkMessage(new GhostWarpRequestMessage(target, warpName)); + public void SendGhostWarpRequestMessage(string warpName) => SendNetworkMessage(new GhostWarpToLocationRequestMessage(warpName)); + + public void SendGhostWarpRequestMessage(EntityUid target) => SendNetworkMessage(new GhostWarpToTargetRequestMessage(target)); public void GhostRequestWarpPoint() => SendNetworkMessage(new GhostRequestWarpPointData()); diff --git a/Content.Client/UserInterface/GhostGui.cs b/Content.Client/UserInterface/GhostGui.cs index 99db855839..c9783999a5 100644 --- a/Content.Client/UserInterface/GhostGui.cs +++ b/Content.Client/UserInterface/GhostGui.cs @@ -17,7 +17,7 @@ namespace Content.Client.UserInterface private readonly Button _ghostRoles = new() {Text = Loc.GetString("Ghost Roles")}; private readonly GhostComponent _owner; - public GhostTargetWindow? TargetWindow { get; private set; } + public GhostTargetWindow? TargetWindow { get; } public GhostGui(GhostComponent owner) { @@ -29,8 +29,8 @@ namespace Content.Client.UserInterface MouseFilter = MouseFilterMode.Ignore; - _ghostWarp.OnPressed += args => TargetWindow.Populate(); - _returnToBody.OnPressed += args => owner.SendReturnToBodyMessage(); + _ghostWarp.OnPressed += _ => TargetWindow.Populate(); + _returnToBody.OnPressed += _ => owner.SendReturnToBodyMessage(); _ghostRoles.OnPressed += _ => IoCManager.Resolve().RemoteExecuteCommand(null, "ghostroles"); AddChild(new HBoxContainer @@ -114,7 +114,7 @@ namespace Content.Client.UserInterface ClipText = true, }; - currentButtonRef.OnPressed += (args) => + currentButtonRef.OnPressed += (_) => { _owner.SendGhostWarpRequestMessage(key); }; @@ -138,9 +138,9 @@ namespace Content.Client.UserInterface ClipText = true, }; - currentButtonRef.OnPressed += (args) => + currentButtonRef.OnPressed += (_) => { - _owner.SendGhostWarpRequestMessage(default,name); + _owner.SendGhostWarpRequestMessage(name); }; _buttonContainer.AddChild(currentButtonRef); diff --git a/Content.Server/GameObjects/Components/Observer/GhostComponent.cs b/Content.Server/GameObjects/Components/Observer/GhostComponent.cs index 6d636e30ff..e28df43a31 100644 --- a/Content.Server/GameObjects/Components/Observer/GhostComponent.cs +++ b/Content.Server/GameObjects/Components/Observer/GhostComponent.cs @@ -12,6 +12,7 @@ using Robust.Server.Player; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Localization; +using Robust.Shared.Log; using Robust.Shared.Network; using Robust.Shared.Players; using Robust.Shared.Timing; @@ -94,43 +95,51 @@ namespace Content.Server.GameObjects.Components.Observer Owner.EntityManager.EventBus.RaiseEvent(EventSource.Local, new GhostReturnMessage(mind.Mind)); } break; - case GhostWarpRequestMessage warp: + case GhostWarpToLocationRequestMessage warp: { if (session?.AttachedEntity != Owner) { break; } - if (warp.PlayerTarget != default) + foreach (var warpPoint in FindWaypoints()) { - if (!Owner.EntityManager.TryGetEntity(warp.PlayerTarget, out var entity)) + if (warp.Name == warpPoint.Location) { + Owner.Transform.Coordinates = warpPoint.Owner.Transform.Coordinates; break; } - - if (!entity.TryGetComponent(out IActorComponent? actor)) - { - break; - } - - if (!_playerManager.TryGetSessionByChannel(actor.playerSession.ConnectedClient, out var player) || - player.AttachedEntity != entity) - { - break; - } - - Owner.Transform.Coordinates = entity.Transform.Coordinates; - } - else - { - foreach (var warpPoint in FindWaypoints()) - { - if (warp.WarpName == warpPoint.Location) - { - Owner.Transform.Coordinates = warpPoint.Owner.Transform.Coordinates; - } - } } + + Logger.Warning($"User {session.Name} tried to warp to an invalid warp: {warp.Name}"); + + break; + } + case GhostWarpToTargetRequestMessage target: + { + if (session?.AttachedEntity != Owner) + { + break; + } + + if (!Owner.TryGetComponent(out IActorComponent? actor)) + { + break; + } + + if (!Owner.EntityManager.TryGetEntity(target.Target, out var entity)) + { + Logger.Warning($"User {session.Name} tried to warp to an invalid entity id: {target.Target}"); + break; + } + + if (!_playerManager.TryGetSessionByChannel(actor.playerSession.ConnectedClient, out var player) || + player.AttachedEntity != entity) + { + break; + } + + Owner.Transform.Coordinates = entity.Transform.Coordinates; break; } case GhostRequestPlayerNameData _: diff --git a/Content.Shared/GameObjects/Components/Observer/GhostWarpToLocationRequestMessage.cs b/Content.Shared/GameObjects/Components/Observer/GhostWarpToLocationRequestMessage.cs new file mode 100644 index 0000000000..43836c3881 --- /dev/null +++ b/Content.Shared/GameObjects/Components/Observer/GhostWarpToLocationRequestMessage.cs @@ -0,0 +1,18 @@ +using System; +using Robust.Shared.GameObjects; +using Robust.Shared.Serialization; + +namespace Content.Shared.GameObjects.Components.Observer +{ + [Serializable, NetSerializable] + public class GhostWarpToLocationRequestMessage : ComponentMessage + { + public string Name { get; } + + public GhostWarpToLocationRequestMessage(string name) + { + Name = name; + Directed = true; + } + } +} diff --git a/Content.Shared/GameObjects/Components/Observer/GhostWarpToTargetRequestMessage.cs b/Content.Shared/GameObjects/Components/Observer/GhostWarpToTargetRequestMessage.cs new file mode 100644 index 0000000000..d42dee0e4e --- /dev/null +++ b/Content.Shared/GameObjects/Components/Observer/GhostWarpToTargetRequestMessage.cs @@ -0,0 +1,18 @@ +using System; +using Robust.Shared.GameObjects; +using Robust.Shared.Serialization; + +namespace Content.Shared.GameObjects.Components.Observer +{ + [Serializable, NetSerializable] + public class GhostWarpToTargetRequestMessage : ComponentMessage + { + public EntityUid Target { get; } + + public GhostWarpToTargetRequestMessage(EntityUid target) + { + Target = target; + Directed = true; + } + } +} diff --git a/Content.Shared/GameObjects/Components/Observer/SharedGhostComponent.cs b/Content.Shared/GameObjects/Components/Observer/SharedGhostComponent.cs index 41cd9972f4..04a8801026 100644 --- a/Content.Shared/GameObjects/Components/Observer/SharedGhostComponent.cs +++ b/Content.Shared/GameObjects/Components/Observer/SharedGhostComponent.cs @@ -40,19 +40,6 @@ namespace Content.Shared.GameObjects.Components.Observer } } - [Serializable, NetSerializable] - public class GhostWarpRequestMessage : ComponentMessage - { - public EntityUid PlayerTarget; - public string WarpName; - public GhostWarpRequestMessage(EntityUid playerTarget = default, string warpTarget = default) - { - WarpName = warpTarget; - PlayerTarget = playerTarget; - Directed = true; - } - } - [Serializable, NetSerializable] public class GhostRequestWarpPointData : ComponentMessage {