From 2908cd994c03478558de2df8a4a304a663188f77 Mon Sep 17 00:00:00 2001 From: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com> Date: Wed, 14 Sep 2022 21:40:05 +1200 Subject: [PATCH] Content changes for session specific entity states (#11235) --- Content.Server/Actions/ActionsSystem.cs | 27 ------------------- Content.Server/Flash/FlashSystem.cs | 26 ------------------ .../Shuttles/Systems/ShuttleConsoleSystem.cs | 7 ----- Content.Server/Vehicle/VehicleSystem.Rider.cs | 26 ------------------ Content.Shared/Actions/ActionsComponent.cs | 2 ++ Content.Shared/Actions/SharedActionsSystem.cs | 7 ----- Content.Shared/Alert/AlertsComponent.cs | 2 ++ Content.Shared/Alert/AlertsSystem.cs | 17 ------------ Content.Shared/Flash/SharedFlashSystem.cs | 8 ------ .../Flash/SharedFlashableComponent.cs | 2 ++ .../Shuttles/Components/PilotComponent.cs | 2 ++ .../Vehicle/Components/RiderComponent.cs | 2 ++ 12 files changed, 10 insertions(+), 118 deletions(-) diff --git a/Content.Server/Actions/ActionsSystem.cs b/Content.Server/Actions/ActionsSystem.cs index 98a800b99b..8d042be79a 100644 --- a/Content.Server/Actions/ActionsSystem.cs +++ b/Content.Server/Actions/ActionsSystem.cs @@ -16,33 +16,6 @@ namespace Content.Server.Actions public override void Initialize() { base.Initialize(); - - SubscribeLocalEvent(OnPlayerAttached); - SubscribeLocalEvent(OnStartup); - SubscribeLocalEvent(OnShutdown); - SubscribeLocalEvent(OnMetaFlagRemoval); - } - - private void OnMetaFlagRemoval(EntityUid uid, ActionsComponent component, ref MetaFlagRemoveAttemptEvent args) - { - if (component.LifeStage == ComponentLifeStage.Running) - args.ToRemove &= ~MetaDataFlags.EntitySpecific; - } - - private void OnStartup(EntityUid uid, ActionsComponent component, ComponentStartup args) - { - _metaSystem.AddFlag(uid, MetaDataFlags.EntitySpecific); - } - - private void OnShutdown(EntityUid uid, ActionsComponent component, ComponentShutdown args) - { - _metaSystem.RemoveFlag(uid, MetaDataFlags.EntitySpecific); - } - - private void OnPlayerAttached(EntityUid uid, ActionsComponent component, PlayerAttachedEvent args) - { - // need to send state to new player. - Dirty(component); } protected override bool PerformBasicActions(EntityUid user, ActionType action) diff --git a/Content.Server/Flash/FlashSystem.cs b/Content.Server/Flash/FlashSystem.cs index c5784f2b94..d93234a51c 100644 --- a/Content.Server/Flash/FlashSystem.cs +++ b/Content.Server/Flash/FlashSystem.cs @@ -39,32 +39,6 @@ namespace Content.Server.Flash SubscribeLocalEvent(OnInventoryFlashAttempt); SubscribeLocalEvent(OnFlashImmunityFlashAttempt); - - SubscribeLocalEvent(OnFlashableStartup); - SubscribeLocalEvent(OnFlashableShutdown); - SubscribeLocalEvent(OnMetaFlagRemoval); - SubscribeLocalEvent(OnPlayerAttached); - } - - private void OnPlayerAttached(EntityUid uid, FlashableComponent component, PlayerAttachedEvent args) - { - Dirty(component); - } - - private void OnMetaFlagRemoval(EntityUid uid, FlashableComponent component, ref MetaFlagRemoveAttemptEvent args) - { - if (component.LifeStage == ComponentLifeStage.Running) - args.ToRemove &= ~MetaDataFlags.EntitySpecific; - } - - private void OnFlashableStartup(EntityUid uid, FlashableComponent component, ComponentStartup args) - { - _metaSystem.AddFlag(uid, MetaDataFlags.EntitySpecific); - } - - private void OnFlashableShutdown(EntityUid uid, FlashableComponent component, ComponentShutdown args) - { - _metaSystem.RemoveFlag(uid, MetaDataFlags.EntitySpecific); } private void OnFlashMeleeHit(EntityUid uid, FlashComponent comp, MeleeHitEvent args) diff --git a/Content.Server/Shuttles/Systems/ShuttleConsoleSystem.cs b/Content.Server/Shuttles/Systems/ShuttleConsoleSystem.cs index 9ea7fad4fa..7acaa0e430 100644 --- a/Content.Server/Shuttles/Systems/ShuttleConsoleSystem.cs +++ b/Content.Server/Shuttles/Systems/ShuttleConsoleSystem.cs @@ -46,13 +46,6 @@ namespace Content.Server.Shuttles.Systems SubscribeLocalEvent(HandlePilotMove); SubscribeLocalEvent(OnGetState); - SubscribeLocalEvent(OnGetStateAttempt); - } - - private void OnGetStateAttempt(EntityUid uid, PilotComponent component, ref ComponentGetStateAttemptEvent args) - { - if (args.Cancelled || !TryComp(uid, out var actor) || actor.PlayerSession != args.Player) - args.Cancelled = true; } private void OnDestinationMessage(EntityUid uid, ShuttleConsoleComponent component, ShuttleConsoleDestinationMessage args) diff --git a/Content.Server/Vehicle/VehicleSystem.Rider.cs b/Content.Server/Vehicle/VehicleSystem.Rider.cs index 76f9cc4ebc..3f9c0e1d6d 100644 --- a/Content.Server/Vehicle/VehicleSystem.Rider.cs +++ b/Content.Server/Vehicle/VehicleSystem.Rider.cs @@ -11,38 +11,12 @@ namespace Content.Server.Vehicle { private void InitializeRider() { - SubscribeLocalEvent(OnRiderStartup); - SubscribeLocalEvent(OnRiderShutdown); - SubscribeLocalEvent(OnRiderRemoval); SubscribeLocalEvent(OnRiderGetState); - SubscribeLocalEvent(OnRiderGetStateAttempt); SubscribeLocalEvent(OnVirtualItemDeleted); SubscribeLocalEvent(OnFallDown); SubscribeLocalEvent(OnMobStateChanged); } - private void OnRiderRemoval(EntityUid uid, RiderComponent component, ref MetaFlagRemoveAttemptEvent args) - { - if ((args.ToRemove & MetaDataFlags.EntitySpecific) != 0x0) - args.ToRemove = MetaDataFlags.None; - } - - private void OnRiderStartup(EntityUid uid, RiderComponent component, ComponentStartup args) - { - _metadata.AddFlag(uid, MetaDataFlags.EntitySpecific); - } - - private void OnRiderShutdown(EntityUid uid, RiderComponent component, ComponentShutdown args) - { - _metadata.RemoveFlag(uid, MetaDataFlags.EntitySpecific); - } - - private void OnRiderGetStateAttempt(EntityUid uid, RiderComponent component, ref ComponentGetStateAttemptEvent args) - { - if (uid != args.Player.AttachedEntity) - args.Cancelled = true; - } - private void OnRiderGetState(EntityUid uid, RiderComponent component, ref ComponentGetState args) { args.State = new RiderComponentState() diff --git a/Content.Shared/Actions/ActionsComponent.cs b/Content.Shared/Actions/ActionsComponent.cs index 350951b470..646dac9d73 100644 --- a/Content.Shared/Actions/ActionsComponent.cs +++ b/Content.Shared/Actions/ActionsComponent.cs @@ -12,6 +12,8 @@ public sealed class ActionsComponent : Component [ViewVariables] [Access(typeof(SharedActionsSystem), Other = AccessPermissions.ReadExecute)] // FIXME Friends public SortedSet Actions = new(); + + public override bool SendOnlyToOwner => true; } [Serializable, NetSerializable] diff --git a/Content.Shared/Actions/SharedActionsSystem.cs b/Content.Shared/Actions/SharedActionsSystem.cs index b45e3890e2..d8aec2ec4d 100644 --- a/Content.Shared/Actions/SharedActionsSystem.cs +++ b/Content.Shared/Actions/SharedActionsSystem.cs @@ -37,7 +37,6 @@ public abstract class SharedActionsSystem : EntitySystem SubscribeLocalEvent(OnHandUnequipped); SubscribeLocalEvent(GetState); - SubscribeLocalEvent(OnCanGetState); SubscribeAllEvent(OnActionRequest); } @@ -89,12 +88,6 @@ public abstract class SharedActionsSystem : EntitySystem args.State = new ActionsComponentState(component.Actions.ToList()); } - private void OnCanGetState(EntityUid uid, ActionsComponent component, ref ComponentGetStateAttemptEvent args) - { - // Only send action state data to the relevant player. - if (args.Player.AttachedEntity != uid) - args.Cancelled = true; - } #endregion #region Execution diff --git a/Content.Shared/Alert/AlertsComponent.cs b/Content.Shared/Alert/AlertsComponent.cs index f1d5d01b9e..cc63efd29f 100644 --- a/Content.Shared/Alert/AlertsComponent.cs +++ b/Content.Shared/Alert/AlertsComponent.cs @@ -11,4 +11,6 @@ namespace Content.Shared.Alert; public sealed class AlertsComponent : Component { [ViewVariables] public Dictionary Alerts = new(); + + public override bool SendOnlyToOwner => true; } diff --git a/Content.Shared/Alert/AlertsSystem.cs b/Content.Shared/Alert/AlertsSystem.cs index 60a609538e..c5f920aebf 100644 --- a/Content.Shared/Alert/AlertsSystem.cs +++ b/Content.Shared/Alert/AlertsSystem.cs @@ -158,38 +158,21 @@ public abstract class AlertsSystem : EntitySystem SubscribeLocalEvent(HandleComponentStartup); SubscribeLocalEvent(HandleComponentShutdown); - SubscribeLocalEvent(OnMetaFlagRemoval); SubscribeLocalEvent(ClientAlertsGetState); - SubscribeLocalEvent(OnCanGetState); SubscribeNetworkEvent(HandleClickAlert); LoadPrototypes(); _prototypeManager.PrototypesReloaded += HandlePrototypesReloaded; } - private void OnMetaFlagRemoval(EntityUid uid, AlertsComponent component, ref MetaFlagRemoveAttemptEvent args) - { - if (component.LifeStage == ComponentLifeStage.Running) - args.ToRemove &= ~MetaDataFlags.EntitySpecific; - } - - private void OnCanGetState(EntityUid uid, AlertsComponent component, ref ComponentGetStateAttemptEvent args) - { - // Only send alert state data to the relevant player. - if (args.Player.AttachedEntity != uid) - args.Cancelled = true; - } - protected virtual void HandleComponentShutdown(EntityUid uid, AlertsComponent component, ComponentShutdown args) { RaiseLocalEvent(uid, new AlertSyncEvent(uid), true); - _metaSystem.RemoveFlag(uid, MetaDataFlags.EntitySpecific); } private void HandleComponentStartup(EntityUid uid, AlertsComponent component, ComponentStartup args) { RaiseLocalEvent(uid, new AlertSyncEvent(uid), true); - _metaSystem.AddFlag(uid, MetaDataFlags.EntitySpecific); } public override void Shutdown() diff --git a/Content.Shared/Flash/SharedFlashSystem.cs b/Content.Shared/Flash/SharedFlashSystem.cs index 8712a52474..672ac17b6b 100644 --- a/Content.Shared/Flash/SharedFlashSystem.cs +++ b/Content.Shared/Flash/SharedFlashSystem.cs @@ -9,14 +9,6 @@ namespace Content.Shared.Flash base.Initialize(); SubscribeLocalEvent(OnFlashableGetState); - SubscribeLocalEvent(OnGetStateAttempt); - } - - private static void OnGetStateAttempt(EntityUid uid, SharedFlashableComponent component, ref ComponentGetStateAttemptEvent args) - { - // Only send state to the player attached to the entity. - if (args.Player.AttachedEntity != uid) - args.Cancelled = true; } private static void OnFlashableGetState(EntityUid uid, SharedFlashableComponent component, ref ComponentGetState args) diff --git a/Content.Shared/Flash/SharedFlashableComponent.cs b/Content.Shared/Flash/SharedFlashableComponent.cs index 25b7c41394..4f30fb83b5 100644 --- a/Content.Shared/Flash/SharedFlashableComponent.cs +++ b/Content.Shared/Flash/SharedFlashableComponent.cs @@ -8,6 +8,8 @@ namespace Content.Shared.Flash { public float Duration { get; set; } public TimeSpan LastFlash { get; set; } + + public override bool SendOnlyToOwner => true; } [Serializable, NetSerializable] diff --git a/Content.Shared/Shuttles/Components/PilotComponent.cs b/Content.Shared/Shuttles/Components/PilotComponent.cs index 972abf91ef..f98723f4e9 100644 --- a/Content.Shared/Shuttles/Components/PilotComponent.cs +++ b/Content.Shared/Shuttles/Components/PilotComponent.cs @@ -29,5 +29,7 @@ namespace Content.Shared.Shuttles.Components [ViewVariables] public ShuttleButtons HeldButtons = ShuttleButtons.None; + + public override bool SendOnlyToOwner => true; } } diff --git a/Content.Shared/Vehicle/Components/RiderComponent.cs b/Content.Shared/Vehicle/Components/RiderComponent.cs index a08d1ca987..3fd559e2d6 100644 --- a/Content.Shared/Vehicle/Components/RiderComponent.cs +++ b/Content.Shared/Vehicle/Components/RiderComponent.cs @@ -13,5 +13,7 @@ namespace Content.Shared.Vehicle.Components /// The vehicle this rider is currently riding. /// [ViewVariables] public EntityUid? Vehicle; + + public override bool SendOnlyToOwner => true; } }