Allow zoom command to ignore zoom limits (#19419)

This commit is contained in:
Leon Friedrich
2023-08-22 21:27:41 +12:00
committed by GitHub
parent cf38f16d36
commit 4d845caa07
7 changed files with 62 additions and 36 deletions

View File

@@ -4,6 +4,7 @@ using Robust.Client.Console;
using Robust.Client.Player; using Robust.Client.Player;
using Robust.Shared.ContentPack; using Robust.Shared.ContentPack;
using Robust.Shared.Network; using Robust.Shared.Network;
using Robust.Shared.Players;
using Robust.Shared.Utility; using Robust.Shared.Utility;
namespace Content.Client.Administration.Managers namespace Content.Client.Administration.Managers
@@ -121,5 +122,13 @@ namespace Content.Client.Administration.Managers
? _adminData ? _adminData
: null; : null;
} }
public AdminData? GetAdminData(ICommonSession session, bool includeDeAdmin = false)
{
if (_player.LocalPlayer?.UserId == session.UserId)
return _adminData;
return null;
}
} }
} }

View File

@@ -64,7 +64,7 @@ public sealed class ZoomCommand : IConsoleCommand
if (_entManager.TryGetComponent<ContentEyeComponent>(player, out var content)) if (_entManager.TryGetComponent<ContentEyeComponent>(player, out var content))
{ {
_entManager.System<ContentEyeSystem>().RequestZoom(player.Value, zoom, content); _entManager.System<ContentEyeSystem>().RequestZoom(player.Value, zoom, true, content);
return; return;
} }

View File

@@ -10,7 +10,7 @@ public sealed class ContentEyeSystem : SharedContentEyeSystem
{ {
[Dependency] private readonly IPlayerManager _player = default!; [Dependency] private readonly IPlayerManager _player = default!;
public void RequestZoom(EntityUid uid, Vector2 zoom, ContentEyeComponent? content = null) public void RequestZoom(EntityUid uid, Vector2 zoom, bool ignoreLimit, ContentEyeComponent? content = null)
{ {
if (!Resolve(uid, ref content, false)) if (!Resolve(uid, ref content, false))
return; return;
@@ -18,6 +18,7 @@ public sealed class ContentEyeSystem : SharedContentEyeSystem
RaisePredictiveEvent(new RequestTargetZoomEvent() RaisePredictiveEvent(new RequestTargetZoomEvent()
{ {
TargetZoom = zoom, TargetZoom = zoom,
IgnoreLimit = ignoreLimit,
}); });
} }

View File

@@ -49,14 +49,14 @@ namespace Content.Server.Administration.Managers
private readonly AdminCommandPermissions _commandPermissions = new(); private readonly AdminCommandPermissions _commandPermissions = new();
private readonly AdminCommandPermissions _toolshedCommandPermissions = new(); private readonly AdminCommandPermissions _toolshedCommandPermissions = new();
public bool IsAdmin(IPlayerSession session, bool includeDeAdmin = false) public bool IsAdmin(ICommonSession session, bool includeDeAdmin = false)
{ {
return GetAdminData(session, includeDeAdmin) != null; return GetAdminData(session, includeDeAdmin) != null;
} }
public AdminData? GetAdminData(IPlayerSession session, bool includeDeAdmin = false) public AdminData? GetAdminData(ICommonSession session, bool includeDeAdmin = false)
{ {
if (_admins.TryGetValue(session, out var reg) && (reg.Data.Active || includeDeAdmin)) if (_admins.TryGetValue((IPlayerSession)session, out var reg) && (reg.Data.Active || includeDeAdmin))
{ {
return reg.Data; return reg.Data;
} }

View File

@@ -29,36 +29,6 @@ namespace Content.Server.Administration.Managers
/// </summary> /// </summary>
IEnumerable<IPlayerSession> AllAdmins { get; } IEnumerable<IPlayerSession> AllAdmins { get; }
/// <summary>
/// Checks if a player is an admin.
/// </summary>
/// <param name="session">The player to check.</param>
/// <param name="includeDeAdmin">
/// Whether to return admin data for admins that are current de-adminned.
/// </param>
/// <returns>true if the player is an admin, false otherwise.</returns>
bool IsAdmin(IPlayerSession session, bool includeDeAdmin = false);
/// <summary>
/// Gets the admin data for a player, if they are an admin.
/// </summary>
/// <param name="session">The player to get admin data for.</param>
/// <param name="includeDeAdmin">
/// Whether to return admin data for admins that are current de-adminned.
/// </param>
/// <returns><see langword="null" /> if the player is not an admin.</returns>
AdminData? GetAdminData(IPlayerSession session, bool includeDeAdmin = false);
/// <summary>
/// See if a player has an admin flag.
/// </summary>
/// <returns>True if the player is and admin and has the specified flags.</returns>
bool HasAdminFlag(IPlayerSession player, AdminFlags flag)
{
var data = GetAdminData(player);
return data != null && data.HasFlag(flag);
}
/// <summary> /// <summary>
/// De-admins an admin temporarily so they are effectively a normal player. /// De-admins an admin temporarily so they are effectively a normal player.
/// </summary> /// </summary>

View File

@@ -1,3 +1,5 @@
using Robust.Shared.Players;
namespace Content.Shared.Administration.Managers; namespace Content.Shared.Administration.Managers;
/// <summary> /// <summary>
@@ -16,6 +18,18 @@ public interface ISharedAdminManager
/// </param> /// </param>
/// <returns><see langword="null" /> if the player is not an admin.</returns> /// <returns><see langword="null" /> if the player is not an admin.</returns>
AdminData? GetAdminData(EntityUid uid, bool includeDeAdmin = false); AdminData? GetAdminData(EntityUid uid, bool includeDeAdmin = false);
/// <summary>
/// Gets the admin data for a player, if they are an admin.
/// </summary>
/// <remarks>
/// When used by the client, this only returns accurate results for the player's own session.
/// </remarks>
/// <param name="includeDeAdmin">
/// Whether to return admin data for admins that are current de-adminned.
/// </param>
/// <returns><see langword="null" /> if the player is not an admin.</returns>
AdminData? GetAdminData(ICommonSession session, bool includeDeAdmin = false);
/// <summary> /// <summary>
/// See if a player has an admin flag. /// See if a player has an admin flag.
@@ -29,6 +43,19 @@ public interface ISharedAdminManager
var data = GetAdminData(player); var data = GetAdminData(player);
return data != null && data.HasFlag(flag); return data != null && data.HasFlag(flag);
} }
/// <summary>
/// See if a player has an admin flag.
/// </summary>
/// <remarks>
/// When used by the client, this only returns accurate results for the player's own session.
/// </remarks>
/// <returns>True if the player is and admin and has the specified flags.</returns>
bool HasAdminFlag(ICommonSession player, AdminFlags flag)
{
var data = GetAdminData(player);
return data != null && data.HasFlag(flag);
}
/// <summary> /// <summary>
/// Checks if a player is an admin. /// Checks if a player is an admin.
@@ -44,4 +71,19 @@ public interface ISharedAdminManager
{ {
return GetAdminData(uid, includeDeAdmin) != null; return GetAdminData(uid, includeDeAdmin) != null;
} }
/// <summary>
/// Checks if a player is an admin.
/// </summary>
/// <remarks>
/// When used by the client, this only returns accurate results for the player's own session.
/// </remarks>
/// <param name="includeDeAdmin">
/// Whether to return admin data for admins that are current de-adminned.
/// </param>
/// <returns>true if the player is an admin, false otherwise.</returns>
bool IsAdmin(ICommonSession session, bool includeDeAdmin = false)
{
return GetAdminData(session, includeDeAdmin) != null;
}
} }

View File

@@ -1,4 +1,5 @@
using System.Numerics; using System.Numerics;
using Content.Shared.Administration;
using Content.Shared.Administration.Managers; using Content.Shared.Administration.Managers;
using Content.Shared.Ghost; using Content.Shared.Ghost;
using Content.Shared.Input; using Content.Shared.Input;
@@ -82,8 +83,10 @@ public abstract class SharedContentEyeSystem : EntitySystem
private void OnContentZoomRequest(RequestTargetZoomEvent msg, EntitySessionEventArgs args) private void OnContentZoomRequest(RequestTargetZoomEvent msg, EntitySessionEventArgs args)
{ {
var ignoreLimit = msg.IgnoreLimit && _admin.HasAdminFlag(args.SenderSession, AdminFlags.Debug);
if (TryComp<ContentEyeComponent>(args.SenderSession.AttachedEntity, out var content)) if (TryComp<ContentEyeComponent>(args.SenderSession.AttachedEntity, out var content))
SetZoom(args.SenderSession.AttachedEntity.Value, msg.TargetZoom, eye: content); SetZoom(args.SenderSession.AttachedEntity.Value, msg.TargetZoom, ignoreLimit, eye: content);
} }
private void OnRequestFov(RequestFovEvent msg, EntitySessionEventArgs args) private void OnRequestFov(RequestFovEvent msg, EntitySessionEventArgs args)
@@ -149,6 +152,7 @@ public abstract class SharedContentEyeSystem : EntitySystem
public sealed class RequestTargetZoomEvent : EntityEventArgs public sealed class RequestTargetZoomEvent : EntityEventArgs
{ {
public Vector2 TargetZoom; public Vector2 TargetZoom;
public bool IgnoreLimit;
} }
/// <summary> /// <summary>