Validate client input for pointing (#13115)

This commit is contained in:
Leon Friedrich
2022-12-21 11:29:38 +13:00
committed by GitHub
parent f560245ca2
commit c3d2e93051

View File

@@ -98,9 +98,15 @@ namespace Content.Server.Pointing.EntitySystems
public bool TryPoint(ICommonSession? session, EntityCoordinates coords, EntityUid pointed)
{
var mapCoords = coords.ToMap(EntityManager);
if ((session as IPlayerSession)?.ContentData()?.Mind?.CurrentEntity is not { } player)
if (session?.AttachedEntity is not { } player)
{
Logger.Warning($"Player {session} attempted to point without any attached entity");
return false;
}
if (!coords.IsValid(EntityManager))
{
Logger.Warning($"Player {ToPrettyString(player)} attempted to point at invalid coordinates: {coords}");
return false;
}
@@ -134,6 +140,8 @@ namespace Content.Server.Pointing.EntitySystems
return false;
}
var mapCoords = coords.ToMap(EntityManager);
_rotateToFaceSystem.TryFaceCoordinates(player, mapCoords.Position);
var arrow = EntityManager.SpawnEntity("PointingArrow", mapCoords);
@@ -238,7 +246,10 @@ namespace Content.Server.Pointing.EntitySystems
private void OnPointAttempt(PointingAttemptEvent ev, EntitySessionEventArgs args)
{
TryPoint(args.SenderSession, Transform(ev.Target).Coordinates, ev.Target);
if (TryComp(ev.Target, out TransformComponent? xform))
TryPoint(args.SenderSession, xform.Coordinates, ev.Target);
else
Logger.Warning($"User {args.SenderSession} attempted to point at a non-existent entity uid: {ev.Target}");
}
public override void Shutdown()