diff --git a/Content.Server/Administration/Commands/BanListCommand.cs b/Content.Server/Administration/Commands/BanListCommand.cs index 2f7093ae1d..ea68788deb 100644 --- a/Content.Server/Administration/Commands/BanListCommand.cs +++ b/Content.Server/Administration/Commands/BanListCommand.cs @@ -14,9 +14,10 @@ namespace Content.Server.Administration.Commands; [AdminCommand(AdminFlags.Ban)] public sealed class BanListCommand : LocalizedCommands { + [Dependency] private readonly IPlayerLocator _locator = default!; + [Dependency] private readonly IPlayerManager _playerManager = default!; [Dependency] private readonly IServerDbManager _dbManager = default!; [Dependency] private readonly EuiManager _eui = default!; - [Dependency] private readonly IPlayerLocator _locator = default!; public override string Command => "banlist"; @@ -66,8 +67,7 @@ public sealed class BanListCommand : LocalizedCommands if (args.Length != 1) return CompletionResult.Empty; - var playerMgr = IoCManager.Resolve(); - var options = playerMgr.Sessions.Select(c => c.Name).OrderBy(c => c).ToArray(); + var options = _playerManager.Sessions.Select(c => c.Name).OrderBy(c => c).ToArray(); return CompletionResult.FromHintOptions(options, Loc.GetString("cmd-banlist-hint")); } } diff --git a/Content.Server/Administration/Commands/OpenAdminNotesCommand.cs b/Content.Server/Administration/Commands/OpenAdminNotesCommand.cs index cbe1e89e19..5577e13437 100644 --- a/Content.Server/Administration/Commands/OpenAdminNotesCommand.cs +++ b/Content.Server/Administration/Commands/OpenAdminNotesCommand.cs @@ -9,6 +9,9 @@ namespace Content.Server.Administration.Commands; [AdminCommand(AdminFlags.ViewNotes)] public sealed class OpenAdminNotesCommand : LocalizedCommands { + [Dependency] private readonly IAdminNotesManager _adminNotes = default!; + [Dependency] private readonly IPlayerLocator _locator = default!; + public const string CommandName = "adminnotes"; public override string Command => CommandName; @@ -28,8 +31,7 @@ public sealed class OpenAdminNotesCommand : LocalizedCommands case 1 when Guid.TryParse(args[0], out notedPlayer): break; case 1: - var locator = IoCManager.Resolve(); - var dbGuid = await locator.LookupIdByNameAsync(args[0]); + var dbGuid = await _locator.LookupIdByNameAsync(args[0]); if (dbGuid == null) { @@ -44,7 +46,7 @@ public sealed class OpenAdminNotesCommand : LocalizedCommands return; } - await IoCManager.Resolve().OpenEui(player, notedPlayer); + await _adminNotes.OpenEui(player, notedPlayer); } public override CompletionResult GetCompletion(IConsoleShell shell, string[] args) diff --git a/Content.Server/Administration/Commands/StealthminCommand.cs b/Content.Server/Administration/Commands/StealthminCommand.cs index 49d8363481..f28fd23f7e 100644 --- a/Content.Server/Administration/Commands/StealthminCommand.cs +++ b/Content.Server/Administration/Commands/StealthminCommand.cs @@ -1,39 +1,33 @@ using Content.Server.Administration.Managers; using Content.Shared.Administration; -using JetBrains.Annotations; using Robust.Shared.Console; using Robust.Shared.Utility; namespace Content.Server.Administration.Commands; -[UsedImplicitly] [AdminCommand(AdminFlags.Stealth)] public sealed class StealthminCommand : LocalizedCommands { + [Dependency] private readonly IAdminManager _adminManager = default!; + public override string Command => "stealthmin"; public override void Execute(IConsoleShell shell, string argStr, string[] args) { - var player = shell.Player; - if (player == null) - { - shell.WriteLine(Loc.GetString("cmd-stealthmin-no-console")); - return; - } + var player = shell.Player; + if (player == null) + { + shell.WriteLine(Loc.GetString("shell-cannot-run-command-from-server")); + return; + } - var mgr = IoCManager.Resolve(); + var adminData = _adminManager.GetAdminData(player); - var adminData = mgr.GetAdminData(player); + DebugTools.AssertNotNull(adminData); - DebugTools.AssertNotNull(adminData); - - if (!adminData!.Stealth) - { - mgr.Stealth(player); - } - else - { - mgr.UnStealth(player); - } + if (!adminData!.Stealth) + _adminManager.Stealth(player); + else + _adminManager.UnStealth(player); } } diff --git a/Content.Server/AlertLevel/Commands/SetAlertLevelCommand.cs b/Content.Server/AlertLevel/Commands/SetAlertLevelCommand.cs index 405500442f..2a8e02fadb 100644 --- a/Content.Server/AlertLevel/Commands/SetAlertLevelCommand.cs +++ b/Content.Server/AlertLevel/Commands/SetAlertLevelCommand.cs @@ -2,16 +2,15 @@ using Content.Server.Administration; using Content.Server.Station.Systems; using Content.Shared.Administration; -using JetBrains.Annotations; using Robust.Shared.Console; namespace Content.Server.AlertLevel.Commands { - [UsedImplicitly] [AdminCommand(AdminFlags.Fun)] - public sealed class SetAlertLevelCommand : LocalizedCommands + public sealed class SetAlertLevelCommand : LocalizedEntityCommands { - [Dependency] private readonly IEntitySystemManager _entitySystems = default!; + [Dependency] private readonly AlertLevelSystem _alertLevelSystem = default!; + [Dependency] private readonly StationSystem _stationSystem = default!; public override string Command => "setalertlevel"; @@ -21,11 +20,9 @@ namespace Content.Server.AlertLevel.Commands var player = shell.Player; if (player?.AttachedEntity != null) { - var stationUid = _entitySystems.GetEntitySystem().GetOwningStation(player.AttachedEntity.Value); + var stationUid = _stationSystem.GetOwningStation(player.AttachedEntity.Value); if (stationUid != null) - { levelNames = GetStationLevelNames(stationUid.Value); - } } return args.Length switch @@ -60,7 +57,7 @@ namespace Content.Server.AlertLevel.Commands return; } - var stationUid = _entitySystems.GetEntitySystem().GetOwningStation(player.AttachedEntity.Value); + var stationUid = _stationSystem.GetOwningStation(player.AttachedEntity.Value); if (stationUid == null) { shell.WriteLine(LocalizationManager.GetString("cmd-setalertlevel-invalid-grid")); @@ -75,13 +72,12 @@ namespace Content.Server.AlertLevel.Commands return; } - _entitySystems.GetEntitySystem().SetLevel(stationUid.Value, level, true, true, true, locked); + _alertLevelSystem.SetLevel(stationUid.Value, level, true, true, true, locked); } private string[] GetStationLevelNames(EntityUid station) { - var entityManager = IoCManager.Resolve(); - if (!entityManager.TryGetComponent(station, out var alertLevelComp)) + if (!EntityManager.TryGetComponent(station, out var alertLevelComp)) return new string[]{}; if (alertLevelComp.AlertLevels == null) diff --git a/Content.Server/Sandbox/Commands/ColorNetworkCommand.cs b/Content.Server/Sandbox/Commands/ColorNetworkCommand.cs index 9f4d617904..8237ccb2eb 100644 --- a/Content.Server/Sandbox/Commands/ColorNetworkCommand.cs +++ b/Content.Server/Sandbox/Commands/ColorNetworkCommand.cs @@ -1,8 +1,6 @@ using Content.Server.Administration.Managers; using Content.Server.Atmos.Piping.Components; using Content.Server.Atmos.Piping.EntitySystems; -using Content.Server.NodeContainer; -using Content.Server.NodeContainer.NodeGroups; using Content.Shared.Administration; using Content.Shared.NodeContainer; using Content.Shared.NodeContainer.NodeGroups; diff --git a/Content.Server/Whitelist/WhitelistCommands.cs b/Content.Server/Whitelist/WhitelistCommands.cs index 09df1d1419..6e24831fe4 100644 --- a/Content.Server/Whitelist/WhitelistCommands.cs +++ b/Content.Server/Whitelist/WhitelistCommands.cs @@ -12,6 +12,8 @@ namespace Content.Server.Whitelist; [AdminCommand(AdminFlags.Ban)] public sealed class AddWhitelistCommand : LocalizedCommands { + [Dependency] private readonly IPlayerLocator _locator = default!; + [Dependency] private readonly IServerDbManager _dbManager = default!; public override string Command => "whitelistadd"; public override async void Execute(IConsoleShell shell, string argStr, string[] args) @@ -23,23 +25,20 @@ public sealed class AddWhitelistCommand : LocalizedCommands return; } - var db = IoCManager.Resolve(); - var loc = IoCManager.Resolve(); - var name = string.Join(' ', args).Trim(); - var data = await loc.LookupIdByNameOrIdAsync(name); + var data = await _locator.LookupIdByNameOrIdAsync(name); if (data != null) { var guid = data.UserId; - var isWhitelisted = await db.GetWhitelistStatusAsync(guid); + var isWhitelisted = await _dbManager.GetWhitelistStatusAsync(guid); if (isWhitelisted) { shell.WriteLine(Loc.GetString("cmd-whitelistadd-existing", ("username", data.Username))); return; } - await db.AddToWhitelistAsync(guid); + await _dbManager.AddToWhitelistAsync(guid); shell.WriteLine(Loc.GetString("cmd-whitelistadd-added", ("username", data.Username))); return; } @@ -61,6 +60,9 @@ public sealed class AddWhitelistCommand : LocalizedCommands [AdminCommand(AdminFlags.Ban)] public sealed class RemoveWhitelistCommand : LocalizedCommands { + [Dependency] private readonly IPlayerLocator _locator = default!; + [Dependency] private readonly IServerDbManager _dbManager = default!; + public override string Command => "whitelistremove"; public override async void Execute(IConsoleShell shell, string argStr, string[] args) @@ -72,23 +74,20 @@ public sealed class RemoveWhitelistCommand : LocalizedCommands return; } - var db = IoCManager.Resolve(); - var loc = IoCManager.Resolve(); - var name = string.Join(' ', args).Trim(); - var data = await loc.LookupIdByNameOrIdAsync(name); + var data = await _locator.LookupIdByNameOrIdAsync(name); if (data != null) { var guid = data.UserId; - var isWhitelisted = await db.GetWhitelistStatusAsync(guid); + var isWhitelisted = await _dbManager.GetWhitelistStatusAsync(guid); if (!isWhitelisted) { shell.WriteLine(Loc.GetString("cmd-whitelistremove-existing", ("username", data.Username))); return; } - await db.RemoveFromWhitelistAsync(guid); + await _dbManager.RemoveFromWhitelistAsync(guid); shell.WriteLine(Loc.GetString("cmd-whitelistremove-removed", ("username", data.Username))); return; } @@ -110,6 +109,11 @@ public sealed class RemoveWhitelistCommand : LocalizedCommands [AdminCommand(AdminFlags.Ban)] public sealed class KickNonWhitelistedCommand : LocalizedCommands { + [Dependency] private readonly IConfigurationManager _configManager = default!; + [Dependency] private readonly IServerNetManager _netManager = default!; + [Dependency] private readonly IPlayerManager _playerManager = default!; + [Dependency] private readonly IServerDbManager _dbManager = default!; + public override string Command => "kicknonwhitelisted"; public override async void Execute(IConsoleShell shell, string argStr, string[] args) @@ -121,24 +125,16 @@ public sealed class KickNonWhitelistedCommand : LocalizedCommands return; } - var cfg = IoCManager.Resolve(); - - if (!cfg.GetCVar(CCVars.WhitelistEnabled)) + if (!_configManager.GetCVar(CCVars.WhitelistEnabled)) return; - var player = IoCManager.Resolve(); - var db = IoCManager.Resolve(); - var net = IoCManager.Resolve(); - - foreach (var session in player.NetworkedSessions) + foreach (var session in _playerManager.NetworkedSessions) { - if (await db.GetAdminDataForAsync(session.UserId) is not null) + if (await _dbManager.GetAdminDataForAsync(session.UserId) is not null) continue; - if (!await db.GetWhitelistStatusAsync(session.UserId)) - { - net.DisconnectChannel(session.Channel, Loc.GetString("whitelist-not-whitelisted")); - } + if (!await _dbManager.GetWhitelistStatusAsync(session.UserId)) + _netManager.DisconnectChannel(session.Channel, Loc.GetString("whitelist-not-whitelisted")); } } } diff --git a/Resources/Locale/en-US/administration/commands/stealthmin-command.ftl b/Resources/Locale/en-US/administration/commands/stealthmin-command.ftl index 4fb5e52105..895d102984 100644 --- a/Resources/Locale/en-US/administration/commands/stealthmin-command.ftl +++ b/Resources/Locale/en-US/administration/commands/stealthmin-command.ftl @@ -1,3 +1,2 @@ cmd-stealthmin-desc = Toggle whether others can see you in adminwho. cmd-stealthmin-help = Usage: stealthmin\nUse stealthmin to toggle whether you appear in the output of the adminwho command. -cmd-stealthmin-no-console = You cannot use this command from the server console.