|
| 1 | +using Content.Server._DV.Administration.Components; |
| 2 | +using Content.Server.Administration; |
| 3 | +using Content.Server.Administration.Logs; |
| 4 | +using Content.Server.Chat.Managers; |
| 5 | +using Content.Shared.Administration; |
| 6 | +using Content.Shared.Database; |
| 7 | +using Content.Shared.Players; |
| 8 | +using Robust.Server.Player; |
| 9 | +using Robust.Shared.Console; |
| 10 | + |
| 11 | +namespace Content.Server._DV.Administration.Commands; |
| 12 | + |
| 13 | +/// <summary> |
| 14 | +/// Command for muting/unmuting specific players in specific OOC channels. |
| 15 | +/// Mutes are not persisted to storage. |
| 16 | +/// </summary> |
| 17 | +/// |
| 18 | +/// After adding/removing a channel in <see cref="Execute"/>, don't forget to: |
| 19 | +/// - Update <see cref="CHANNEL_COMPLETION_OPTIONS"/> |
| 20 | +/// - Document behavior in "cmd-mute-help" in Resources/Locale/en-US/_DV/administration/commands/mute.ftl |
| 21 | + |
| 22 | +[AdminCommand(AdminFlags.Ban)] |
| 23 | +public sealed class MuteCommand : LocalizedEntityCommands |
| 24 | +{ |
| 25 | + [Dependency] private readonly IPlayerManager _player = default!; |
| 26 | + [Dependency] private readonly IChatManager _chat = default!; |
| 27 | + [Dependency] private readonly IAdminLogManager _adminLogs = default!; |
| 28 | + |
| 29 | + private static readonly string[] ChannelCompletionOptions = ["OOC", "LOOC", "DEADCHAT"]; |
| 30 | + private static readonly string ChannelListText = string.Join(", ", ChannelCompletionOptions); |
| 31 | + |
| 32 | + public override string Command => "mute"; |
| 33 | + public override string Help => Loc.GetString("cmd-mute-help", ("channels", ChannelListText), ("command", Command)); |
| 34 | + |
| 35 | + public override void Execute(IConsoleShell shell, string argStr, string[] args) |
| 36 | + { |
| 37 | + if (args.Length != 2) |
| 38 | + { |
| 39 | + shell.WriteLine(Help); |
| 40 | + return; |
| 41 | + } |
| 42 | + |
| 43 | + if (!_player.TryGetSessionByUsername(args[1], out var session)) |
| 44 | + { |
| 45 | + shell.WriteLine(Loc.GetString("shell-target-player-does-not-exist")); |
| 46 | + return; |
| 47 | + } |
| 48 | + |
| 49 | + bool isMuted; |
| 50 | + switch (args[0].ToLower()) |
| 51 | + { |
| 52 | + case "deadchat": |
| 53 | + { |
| 54 | + if (session.GetMind() is not { } mind) |
| 55 | + { |
| 56 | + shell.WriteLine(Loc.GetString("cmd-mute-err-missing-mind")); |
| 57 | + return; |
| 58 | + } |
| 59 | + |
| 60 | + var mute = EntityManager.EnsureComponent<InGameOocMutedComponent>(mind); |
| 61 | + mute.MuteDeadchat = !mute.MuteDeadchat; |
| 62 | + isMuted = mute.MuteDeadchat; |
| 63 | + } |
| 64 | + break; |
| 65 | + |
| 66 | + case "looc": |
| 67 | + { |
| 68 | + if (session.GetMind() is not { } mind) |
| 69 | + { |
| 70 | + shell.WriteLine(Loc.GetString("cmd-mute-err-missing-mind")); |
| 71 | + return; |
| 72 | + } |
| 73 | + |
| 74 | + var mute = EntityManager.EnsureComponent<InGameOocMutedComponent>(mind); |
| 75 | + mute.MuteLooc = !mute.MuteLooc; |
| 76 | + isMuted = mute.MuteLooc; |
| 77 | + } |
| 78 | + break; |
| 79 | + |
| 80 | + case "ooc": |
| 81 | + if (session.ContentData() is not { } playerData) |
| 82 | + { |
| 83 | + shell.WriteLine(Loc.GetString("cmd-mute-err-no-data")); |
| 84 | + return; |
| 85 | + } |
| 86 | + |
| 87 | + playerData.OocMuted = !playerData.OocMuted; |
| 88 | + isMuted = playerData.OocMuted; |
| 89 | + break; |
| 90 | + |
| 91 | + default: |
| 92 | + shell.WriteLine(Loc.GetString("cmd-mute-err-unknown-channel", ("channels", ChannelListText))); |
| 93 | + return; |
| 94 | + } |
| 95 | + |
| 96 | + var channelName = args[0].ToUpper(); |
| 97 | + _adminLogs.Add(LogType.AdminCommands, |
| 98 | + LogImpact.Extreme, |
| 99 | + $"{session:player} has been {(isMuted ? "muted" : "unmuted")} in {channelName} by {shell.Player?.Name ?? "<UNKNOWN>"}"); |
| 100 | + |
| 101 | + var locArgs = ("chat", channelName); |
| 102 | + _chat.DispatchServerMessage(session, |
| 103 | + isMuted |
| 104 | + ? Loc.GetString("cmd-mute-player-notif-muted", locArgs) |
| 105 | + : Loc.GetString("cmd-mute-player-notif-unmuted", locArgs), |
| 106 | + true); |
| 107 | + |
| 108 | + shell.WriteLine(Loc.GetString("shell-command-success")); |
| 109 | + } |
| 110 | + |
| 111 | + public override CompletionResult GetCompletion(IConsoleShell shell, string[] args) |
| 112 | + { |
| 113 | + switch (args.Length) |
| 114 | + { |
| 115 | + case 1: |
| 116 | + return CompletionResult.FromHintOptions(ChannelCompletionOptions, "channel"); |
| 117 | + case 2: |
| 118 | + return CompletionResult.FromOptions(CompletionHelper.SessionNames()); |
| 119 | + default: |
| 120 | + return CompletionResult.Empty; |
| 121 | + } |
| 122 | + } |
| 123 | +} |
0 commit comments