]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Probably fix playglobalsound completion (#16297)
authormetalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Sat, 13 May 2023 15:54:02 +0000 (01:54 +1000)
committerGitHub <noreply@github.com>
Sat, 13 May 2023 15:54:02 +0000 (11:54 -0400)
Content.Client/Administration/Commands/PlayGlobalSoundCommand.cs [deleted file]
Content.Server/Administration/Commands/PlayGlobalSoundCommand.cs [new file with mode: 0644]
Content.Server/Audio/ServerGlobalSoundSystem.cs

diff --git a/Content.Client/Administration/Commands/PlayGlobalSoundCommand.cs b/Content.Client/Administration/Commands/PlayGlobalSoundCommand.cs
deleted file mode 100644 (file)
index e52bf2d..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-using System.Linq;
-using Robust.Client.Player;
-using Robust.Shared.Console;
-using Robust.Shared.ContentPack;
-
-namespace Content.Client.Administration.Commands;
-
-/// <summary>
-/// Proxy to server-side <c>playglobalsound</c> command. Implements completions.
-/// </summary>
-public sealed class PlayGlobalSoundCommand : IConsoleCommand
-{
-    public string Command => "playglobalsound";
-    public string Description => Loc.GetString("play-global-sound-command-description");
-    public string Help => Loc.GetString("play-global-sound-command-help");
-
-    public void Execute(IConsoleShell shell, string argStr, string[] args)
-    {
-        shell.RemoteExecuteCommand(argStr);
-    }
-
-    public CompletionResult GetCompletion(IConsoleShell shell, string[] args)
-    {
-        if (args.Length == 1)
-        {
-            var hint = Loc.GetString("play-global-sound-command-arg-path");
-            var res = IoCManager.Resolve<IResourceManager>();
-
-            var options = CompletionHelper.ContentFilePath(args[0], res);
-
-            return CompletionResult.FromHintOptions(options, hint);
-        }
-
-        if (args.Length == 2)
-            return CompletionResult.FromHint(Loc.GetString("play-global-sound-command-arg-volume"));
-
-        if (args.Length > 2)
-        {
-            var plyMgr = IoCManager.Resolve<IPlayerManager>();
-            var options = plyMgr.Sessions.Select(c => c.Name);
-            return CompletionResult.FromHintOptions(
-                options,
-                Loc.GetString("play-global-sound-command-arg-usern", ("user", args.Length - 2)));
-        }
-
-        return CompletionResult.Empty;
-    }
-}
diff --git a/Content.Server/Administration/Commands/PlayGlobalSoundCommand.cs b/Content.Server/Administration/Commands/PlayGlobalSoundCommand.cs
new file mode 100644 (file)
index 0000000..fdd3173
--- /dev/null
@@ -0,0 +1,119 @@
+using System.Linq;
+using Content.Server.Audio;
+using Content.Shared.Administration;
+using Robust.Server.Player;
+using Robust.Shared.Audio;
+using Robust.Shared.Console;
+using Robust.Shared.ContentPack;
+using Robust.Shared.Player;
+using Robust.Shared.Players;
+using Robust.Shared.Prototypes;
+
+namespace Content.Server.Administration.Commands;
+
+[AdminCommand(AdminFlags.Fun)]
+public sealed class PlayGlobalSoundCommand : IConsoleCommand
+{
+    [Dependency] private readonly IEntityManager _entManager = default!;
+    [Dependency] private readonly IPlayerManager _playerManager = default!;
+    [Dependency] private readonly IResourceManager _res = default!;
+
+    public string Command => "playglobalsound";
+    public string Description => Loc.GetString("play-global-sound-command-description");
+    public string Help => Loc.GetString("play-global-sound-command-help");
+
+    public void Execute(IConsoleShell shell, string argStr, string[] args)
+    {
+        Filter filter;
+        var audio = AudioParams.Default;
+
+        bool replay = true;
+
+        switch (args.Length)
+        {
+            // No arguments, show command help.
+            case 0:
+                shell.WriteLine(Loc.GetString("play-global-sound-command-help"));
+                return;
+
+            // No users, play sound for everyone.
+            case 1:
+                // Filter.Broadcast does resolves IPlayerManager, so use this instead.
+                filter = Filter.Empty().AddAllPlayers(_playerManager);
+                break;
+
+            // One or more users specified.
+            default:
+                var volumeOffset = 0;
+
+                // Try to specify a new volume to play it at.
+                if (int.TryParse(args[1], out var volume))
+                {
+                    audio = audio.WithVolume(volume);
+                    volumeOffset = 1;
+                }
+                else
+                {
+                    shell.WriteError(Loc.GetString("play-global-sound-command-volume-parse", ("volume", args[1])));
+                    return;
+                }
+
+                // No users specified so play for them all.
+                if (args.Length == 2)
+                {
+                    filter = Filter.Empty().AddAllPlayers(_playerManager);
+                }
+                else
+                {
+                    // TODO REPLAYS uhhh.. what to do with this?
+                    replay = false;
+
+                    filter = Filter.Empty();
+
+                    // Skip the first argument, which is the sound path.
+                    for (var i = 1 + volumeOffset; i < args.Length; i++)
+                    {
+                        var username = args[i];
+
+                        if (!_playerManager.TryGetSessionByUsername(username, out var session))
+                        {
+                            shell.WriteError(Loc.GetString("play-global-sound-command-player-not-found", ("username", username)));
+                            continue;
+                        }
+
+                        filter.AddPlayer(session);
+                    }
+                }
+
+                break;
+        }
+
+        audio = audio.AddVolume(-8);
+        _entManager.System<ServerGlobalSoundSystem>().PlayAdminGlobal(filter, args[0], audio, replay);
+    }
+
+    public CompletionResult GetCompletion(IConsoleShell shell, string[] args)
+    {
+        if (args.Length == 1)
+        {
+            var hint = Loc.GetString("play-global-sound-command-arg-path");
+
+            var options = CompletionHelper.ContentFilePath(args[0], _res);
+
+            return CompletionResult.FromHintOptions(options, hint);
+        }
+
+        if (args.Length == 2)
+            return CompletionResult.FromHint(Loc.GetString("play-global-sound-command-arg-volume"));
+
+        if (args.Length > 2)
+        {
+            var options = _playerManager.Sessions.Select<ICommonSession, string>(c => c.Name);
+            return CompletionResult.FromHintOptions(
+                options,
+                Loc.GetString("play-global-sound-command-arg-usern", ("user", args.Length - 2)));
+        }
+
+        return CompletionResult.Empty;
+    }
+}
index 714403fe83148ff1afe8f116cd65360be2424f77..df8771df8d866e593b352e61ff0ba9cb031db413 100644 (file)
@@ -1,9 +1,5 @@
-using Content.Server.Administration;
-using Content.Server.Station.Components;
-using Content.Server.Station.Systems;
-using Content.Shared.Administration;
+using Content.Server.Station.Systems;
 using Content.Shared.Audio;
-using Robust.Server.Player;
 using Robust.Shared.Audio;
 using Robust.Shared.Console;
 using Robust.Shared.Player;
@@ -13,22 +9,15 @@ namespace Content.Server.Audio;
 public sealed class ServerGlobalSoundSystem : SharedGlobalSoundSystem
 {
     [Dependency] private readonly IConsoleHost _conHost = default!;
-    [Dependency] private readonly IPlayerManager _playerManager = default!;
     [Dependency] private readonly StationSystem _stationSystem = default!;
 
-    public override void Initialize()
-    {
-        base.Initialize();
-        _conHost.RegisterCommand("playglobalsound", Loc.GetString("play-global-sound-command-description"), Loc.GetString("play-global-sound-command-help"), PlayGlobalSoundCommand);
-    }
-
     public override void Shutdown()
     {
         base.Shutdown();
         _conHost.UnregisterCommand("playglobalsound");
     }
 
-    private void PlayAdminGlobal(Filter playerFilter, string filename, AudioParams? audioParams = null, bool replay = true)
+    public void PlayAdminGlobal(Filter playerFilter, string filename, AudioParams? audioParams = null, bool replay = true)
     {
         var msg = new AdminSoundEvent(filename, audioParams);
         RaiseNetworkEvent(msg, playerFilter, recordReplay: replay);
@@ -68,78 +57,4 @@ public sealed class ServerGlobalSoundSystem : SharedGlobalSoundSystem
         var filter = GetStationAndPvs(source);
         RaiseNetworkEvent(msg, filter);
     }
-
-    /// <summary>
-    ///     Command that allows admins to play global sounds.
-    /// </summary>
-    [AdminCommand(AdminFlags.Fun)]
-    public void PlayGlobalSoundCommand(IConsoleShell shell, string argStr, string[] args)
-    {
-        Filter filter;
-        var audio = AudioParams.Default;
-
-        bool replay = true;
-
-        switch (args.Length)
-        {
-            // No arguments, show command help.
-            case 0:
-                shell.WriteLine(Loc.GetString("play-global-sound-command-help"));
-                return;
-
-            // No users, play sound for everyone.
-            case 1:
-                // Filter.Broadcast does resolves IPlayerManager, so use this instead.
-                filter = Filter.Empty().AddAllPlayers(_playerManager);
-                break;
-
-            // One or more users specified.
-            default:
-                var volumeOffset = 0;
-
-                // Try to specify a new volume to play it at.
-                if (int.TryParse(args[1], out var volume))
-                {
-                    audio = audio.WithVolume(volume);
-                    volumeOffset = 1;
-                }
-                else
-                {
-                    shell.WriteError(Loc.GetString("play-global-sound-command-volume-parse", ("volume", args[1])));
-                    return;
-                }
-
-                // No users specified so play for them all.
-                if (args.Length == 2)
-                {
-                    filter = Filter.Empty().AddAllPlayers(_playerManager);
-                }
-                else
-                {
-                    // TODO REPLAYS uhhh.. what to do with this?
-                    replay = false;
-
-                    filter = Filter.Empty();
-
-                    // Skip the first argument, which is the sound path.
-                    for (var i = 1 + volumeOffset; i < args.Length; i++)
-                    {
-                        var username = args[i];
-
-                        if (!_playerManager.TryGetSessionByUsername(username, out var session))
-                        {
-                            shell.WriteError(Loc.GetString("play-global-sound-command-player-not-found", ("username", username)));
-                            continue;
-                        }
-
-                        filter.AddPlayer(session);
-                    }
-                }
-
-                break;
-        }
-
-        audio = audio.AddVolume(-8);
-        PlayAdminGlobal(filter, args[0], audio, replay);
-    }
 }