From: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Date: Thu, 30 Nov 2023 13:24:48 +0000 (+1100) Subject: Add a debug command for global audio (#22018) X-Git-Url: https://git.smokeofanarchy.ru/gitweb.cgi?a=commitdiff_plain;h=8e5f53a0b798bc0207555075ef2ce9efdb33b99b;p=space-station-14.git Add a debug command for global audio (#22018) --- diff --git a/Content.Server/Administration/Commands/PlayGlobalSoundCommand.cs b/Content.Server/Administration/Commands/PlayGlobalSoundCommand.cs index fdf067181d..e282c1d7da 100644 --- a/Content.Server/Administration/Commands/PlayGlobalSoundCommand.cs +++ b/Content.Server/Administration/Commands/PlayGlobalSoundCommand.cs @@ -1,6 +1,8 @@ +using System.IO; using System.Linq; using Content.Server.Audio; using Content.Shared.Administration; +using Robust.Server.Audio; using Robust.Server.Player; using Robust.Shared.Audio; using Robust.Shared.Console; @@ -10,6 +12,50 @@ using Robust.Shared.Prototypes; namespace Content.Server.Administration.Commands; +// This is for debugging nothing more. +[AdminCommand(AdminFlags.Debug)] +public sealed class PlayGlobalAudioCommand : IConsoleCommand +{ + public string Command => "playaudio"; + public string Description => "Plays audio globally for debugging"; + public string Help => $"{Command}"; + public void Execute(IConsoleShell shell, string argStr, string[] args) + { + var entManager = IoCManager.Resolve(); + var protoManager = IoCManager.Resolve(); + var resourceManager = IoCManager.Resolve(); + var audioSystem = entManager.System(); + var fileName = args[0]; + + shell.WriteLine($"Checking {fileName} global audio"); + + var audioLength = audioSystem.GetAudioLength(fileName); + + shell.WriteLine($"Cached audio length is: {audioLength}"); + + // Copied code to get the actual length determination + // Check shipped metadata from packaging. + if (protoManager.TryIndex(fileName, out AudioMetadataPrototype? metadata)) + { + shell.WriteLine($"Used prototype, length is: {metadata.Length}"); + } + else if (!resourceManager.TryContentFileRead(fileName, out var stream)) + { + throw new FileNotFoundException($"Unable to find metadata for audio file {fileName}"); + } + else + { + shell.WriteLine("Looks like audio stream used and cached."); + } + + var broadcastFilter = Filter.Broadcast(); + + shell.WriteLine($"Playing filter to {broadcastFilter.Count} players"); + + audioSystem.PlayGlobal(fileName, broadcastFilter, true); + } +} + [AdminCommand(AdminFlags.Fun)] public sealed class PlayGlobalSoundCommand : IConsoleCommand {