Fix Hands Crash (#122)

* Fixed sprite issues with construction system (Thanks PJB!).

* Storage and Hands Systems now subscribe to Transform Parent changes, and will keep their containers in sync.

* Add check in Interaction System to prevent processing client-side entities on the server.
This commit is contained in:
Acruid
2018-11-11 11:32:05 -08:00
committed by Pieter-Jan Briers
parent 4720182cf4
commit 8038ebe37d
11 changed files with 108 additions and 38 deletions

View File

@@ -139,7 +139,13 @@ namespace Content.Server.GameObjects.EntitySystems
// client sanitization
if(!coords.IsValidLocation())
{
Logger.InfoS("interaction", $"Invalid Coordinates: client={session}, coords={coords}");
Logger.InfoS("system.interaction", $"Invalid Coordinates: client={session}, coords={coords}");
return;
}
if (uid.IsClientSide())
{
Logger.WarningS("system.interaction", $"Client sent interaction with client-side entity. Session={session}, Uid={uid}");
return;
}
@@ -169,8 +175,8 @@ namespace Content.Server.GameObjects.EntitySystems
{
return;
}
var item = hands.GetActiveHand?.Owner;
var item = hands.GetActiveHand?.Owner;
if (!MobCanInteract(player))
return;

View File

@@ -1,7 +1,7 @@
using System;
using Content.Server.GameObjects.Components;
using Content.Server.GameObjects.Components.Projectiles;
using Content.Server.GameObjects.Components.Stack;
using Content.Server.Interfaces.GameObjects;
using Content.Shared.Input;
using Content.Shared.Physics;
using SS14.Server.GameObjects;
@@ -11,7 +11,6 @@ using SS14.Shared.GameObjects;
using SS14.Shared.GameObjects.EntitySystemMessages;
using SS14.Shared.GameObjects.Systems;
using SS14.Shared.Input;
using SS14.Shared.Interfaces.GameObjects;
using SS14.Shared.Interfaces.GameObjects.Components;
using SS14.Shared.Interfaces.Timing;
using SS14.Shared.IoC;
@@ -61,11 +60,18 @@ namespace Content.Server.GameObjects.EntitySystems
{
var msg = (EntParentChangedMessage) args;
// entity is no longer a child of OldParent, therefore it cannot be in the hand of the parent
if (msg.OldParent != null && msg.OldParent.IsValid() && msg.OldParent.TryGetComponent(out IHandsComponent handsComp))
{
handsComp.RemoveHandEntity(msg.Entity);
}
// deleted entities will not pass this test
if (!msg.Entity.TryGetComponent(out ITransformComponent transform))
return;
// if item is in a container
if(transform.IsMapTransform)
if (transform.IsMapTransform)
return;
if(!msg.Entity.TryGetComponent(out PhysicsComponent physics))

View File

@@ -1,7 +1,9 @@
using System.Collections.Generic;
using SS14.Server.Interfaces.Player;
using SS14.Shared.GameObjects;
using SS14.Shared.GameObjects.EntitySystemMessages;
using SS14.Shared.GameObjects.Systems;
using SS14.Shared.Interfaces.GameObjects;
namespace Content.Server.GameObjects.EntitySystems
{
@@ -15,42 +17,72 @@ namespace Content.Server.GameObjects.EntitySystems
EntityQuery = new TypeEntityQuery(typeof(ServerStorageComponent));
}
/// <inheritdoc />
public override void SubscribeEvents()
{
base.SubscribeEvents();
SubscribeEvent<EntParentChangedMessage>(HandleParentChanged);
}
/// <inheritdoc />
public override void Update(float frameTime)
{
foreach (var entity in RelevantEntities)
{
var storageComp = entity.GetComponent<ServerStorageComponent>();
CheckSubscribedEntities(entity);
}
}
// We have to cache the set of sessions because Unsubscribe modifies the original.
_sessionCache.Clear();
_sessionCache.AddRange(storageComp.SubscribedSessions);
private static void HandleParentChanged(object sender, EntitySystemMessage message)
{
if(!(sender is IEntity childEntity))
return;
if (_sessionCache.Count == 0)
if(!(message is EntParentChangedMessage msg))
return;
var oldParentEntity = msg.OldParent;
if(oldParentEntity == null || !oldParentEntity.IsValid())
return;
if (oldParentEntity.TryGetComponent(out ServerStorageComponent storageComp))
{
storageComp.Remove(childEntity);
}
}
private void CheckSubscribedEntities(IEntity entity)
{
var storageComp = entity.GetComponent<ServerStorageComponent>();
// We have to cache the set of sessions because Unsubscribe modifies the original.
_sessionCache.Clear();
_sessionCache.AddRange(storageComp.SubscribedSessions);
if (_sessionCache.Count == 0)
return;
var storagePos = entity.Transform.WorldPosition;
var storageMap = entity.Transform.MapID;
foreach (var session in _sessionCache)
{
var attachedEntity = session.AttachedEntity;
// The component manages the set of sessions, so this invalid session should be removed soon.
if (attachedEntity == null || !attachedEntity.IsValid())
continue;
var storagePos = entity.Transform.WorldPosition;
var storageMap = entity.Transform.MapID;
if (storageMap != attachedEntity.Transform.MapID)
continue;
foreach (var session in _sessionCache)
var distanceSquared = (storagePos - attachedEntity.Transform.WorldPosition).LengthSquared;
if (distanceSquared > InteractionSystem.INTERACTION_RANGE_SQUARED)
{
var attachedEntity = session.AttachedEntity;
// The component manages the set of sessions, so this invalid session should be removed soon.
if (attachedEntity == null || !attachedEntity.IsValid())
continue;
if(storageMap != attachedEntity.Transform.MapID)
continue;
var distanceSquared = (storagePos - attachedEntity.Transform.WorldPosition).LengthSquared;
if (distanceSquared > InteractionSystem.INTERACTION_RANGE_SQUARED)
{
storageComp.UnsubscribeSession(session);
}
storageComp.UnsubscribeSession(session);
}
}
}
}