2020-12-03 03:40:47 +01:00
|
|
|
using Content.Server.Administration;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Server.Commands;
|
2020-12-03 03:40:47 +01:00
|
|
|
using Content.Shared.Administration;
|
|
|
|
|
using Content.Shared.Alert;
|
2021-02-01 16:49:43 -08:00
|
|
|
using Robust.Shared.Console;
|
2020-12-03 03:40:47 +01:00
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Server.Alert.Commands
|
2020-12-03 03:40:47 +01:00
|
|
|
{
|
|
|
|
|
[AdminCommand(AdminFlags.Debug)]
|
2021-02-01 16:49:43 -08:00
|
|
|
public sealed class ShowAlert : IConsoleCommand
|
2020-12-03 03:40:47 +01:00
|
|
|
{
|
2024-05-12 17:34:52 -07:00
|
|
|
[Dependency] private readonly IEntityManager _e = default!;
|
|
|
|
|
|
2020-12-03 03:40:47 +01:00
|
|
|
public string Command => "showalert";
|
|
|
|
|
public string Description => "Shows an alert for a player, defaulting to current player";
|
|
|
|
|
public string Help => "showalert <alertType> <severity, -1 if no severity> <name or userID, omit for current player>";
|
|
|
|
|
|
2021-02-01 16:49:43 -08:00
|
|
|
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
2020-12-03 03:40:47 +01:00
|
|
|
{
|
2023-10-28 09:59:53 +11:00
|
|
|
var player = shell.Player;
|
2021-12-06 15:34:46 +01:00
|
|
|
if (player?.AttachedEntity == null)
|
2020-12-03 03:40:47 +01:00
|
|
|
{
|
2021-12-06 15:34:46 +01:00
|
|
|
shell.WriteLine("You cannot run this from the server or without an attached entity.");
|
2020-12-03 03:40:47 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-06 15:34:46 +01:00
|
|
|
var attachedEntity = player.AttachedEntity.Value;
|
2020-12-03 03:40:47 +01:00
|
|
|
|
|
|
|
|
if (args.Length > 2)
|
|
|
|
|
{
|
|
|
|
|
var target = args[2];
|
|
|
|
|
if (!CommandUtils.TryGetAttachedEntityByUsernameOrId(shell, target, player, out attachedEntity)) return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-12 17:34:52 -07:00
|
|
|
if (!_e.TryGetComponent(attachedEntity, out AlertsComponent? alertsComponent))
|
2020-12-03 03:40:47 +01:00
|
|
|
{
|
2021-02-01 16:49:43 -08:00
|
|
|
shell.WriteLine("user has no alerts component");
|
2020-12-03 03:40:47 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var alertType = args[0];
|
|
|
|
|
var severity = args[1];
|
2024-05-12 17:34:52 -07:00
|
|
|
var alertsSystem = _e.System<AlertsSystem>();
|
2024-05-23 22:43:04 -04:00
|
|
|
if (!alertsSystem.TryGet(alertType, out var alert))
|
2020-12-03 03:40:47 +01:00
|
|
|
{
|
2021-02-01 16:49:43 -08:00
|
|
|
shell.WriteLine("unrecognized alertType " + alertType);
|
2020-12-03 03:40:47 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!short.TryParse(severity, out var sevint))
|
|
|
|
|
{
|
2021-02-01 16:49:43 -08:00
|
|
|
shell.WriteLine("invalid severity " + sevint);
|
2020-12-03 03:40:47 +01:00
|
|
|
return;
|
|
|
|
|
}
|
2022-01-05 00:19:23 -08:00
|
|
|
|
|
|
|
|
short? severity1 = sevint == -1 ? null : sevint;
|
2024-05-23 22:43:04 -04:00
|
|
|
alertsSystem.ShowAlert(attachedEntity, alert.ID, severity1, null);
|
2020-12-03 03:40:47 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|