2022-11-07 18:18:21 -08:00
|
|
|
using System.Linq;
|
2022-05-25 00:26:57 +02:00
|
|
|
using Content.Server.Administration;
|
2021-11-20 12:32:07 -06:00
|
|
|
using Content.Server.Maps;
|
2021-11-11 23:25:57 -07:00
|
|
|
using Content.Shared.Administration;
|
2022-11-07 18:18:21 -08:00
|
|
|
using Content.Shared.CCVar;
|
|
|
|
|
using Robust.Shared.Configuration;
|
2021-11-11 23:25:57 -07:00
|
|
|
using Robust.Shared.Console;
|
2022-05-25 00:26:57 +02:00
|
|
|
using Robust.Shared.Prototypes;
|
2021-11-11 23:25:57 -07:00
|
|
|
|
|
|
|
|
namespace Content.Server.GameTicking.Commands
|
|
|
|
|
{
|
2021-11-29 14:40:10 -06:00
|
|
|
[AdminCommand(AdminFlags.Round)]
|
2025-06-17 05:39:42 -04:00
|
|
|
public sealed class ForceMapCommand : LocalizedCommands
|
2021-11-11 23:25:57 -07:00
|
|
|
{
|
2022-11-07 18:18:21 -08:00
|
|
|
[Dependency] private readonly IConfigurationManager _configurationManager = default!;
|
2025-06-17 05:39:42 -04:00
|
|
|
[Dependency] private readonly IGameMapManager _gameMapManager = default!;
|
|
|
|
|
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
2022-11-07 18:18:21 -08:00
|
|
|
|
2025-06-17 05:39:42 -04:00
|
|
|
public override string Command => "forcemap";
|
2021-11-11 23:25:57 -07:00
|
|
|
|
2025-06-17 05:39:42 -04:00
|
|
|
public override void Execute(IConsoleShell shell, string argStr, string[] args)
|
2021-11-11 23:25:57 -07:00
|
|
|
{
|
|
|
|
|
if (args.Length != 1)
|
|
|
|
|
{
|
2025-06-17 05:39:42 -04:00
|
|
|
shell.WriteLine(Loc.GetString(Loc.GetString($"shell-need-exactly-one-argument")));
|
2021-11-11 23:25:57 -07:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var name = args[0];
|
|
|
|
|
|
2024-06-26 02:41:31 -04:00
|
|
|
// An empty string clears the forced map
|
2025-06-17 05:39:42 -04:00
|
|
|
if (!string.IsNullOrEmpty(name) && !_gameMapManager.CheckMapExists(name))
|
2024-06-24 06:56:21 -04:00
|
|
|
{
|
2025-06-17 05:39:42 -04:00
|
|
|
shell.WriteLine(Loc.GetString("cmd-forcemap-map-not-found", ("map", name)));
|
2024-06-24 06:56:21 -04:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-07 18:18:21 -08:00
|
|
|
_configurationManager.SetCVar(CCVars.GameMap, name);
|
2024-06-26 02:41:31 -04:00
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(name))
|
2025-06-17 05:39:42 -04:00
|
|
|
shell.WriteLine(Loc.GetString("cmd-forcemap-cleared"));
|
2024-06-26 02:41:31 -04:00
|
|
|
else
|
2025-06-17 05:39:42 -04:00
|
|
|
shell.WriteLine(Loc.GetString("cmd-forcemap-success", ("map", name)));
|
2021-11-11 23:25:57 -07:00
|
|
|
}
|
2022-05-25 00:26:57 +02:00
|
|
|
|
2025-06-17 05:39:42 -04:00
|
|
|
public override CompletionResult GetCompletion(IConsoleShell shell, string[] args)
|
2022-05-25 00:26:57 +02:00
|
|
|
{
|
|
|
|
|
if (args.Length == 1)
|
|
|
|
|
{
|
2025-06-17 05:39:42 -04:00
|
|
|
var options = _prototypeManager
|
2022-05-25 00:26:57 +02:00
|
|
|
.EnumeratePrototypes<GameMapPrototype>()
|
|
|
|
|
.Select(p => new CompletionOption(p.ID, p.MapName))
|
|
|
|
|
.OrderBy(p => p.Value);
|
|
|
|
|
|
2025-06-17 05:39:42 -04:00
|
|
|
return CompletionResult.FromHintOptions(options, Loc.GetString($"cmd-forcemap-hint"));
|
2022-05-25 00:26:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return CompletionResult.Empty;
|
|
|
|
|
}
|
2021-11-11 23:25:57 -07:00
|
|
|
}
|
|
|
|
|
}
|