1
0

ForceMapCommand.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using System.Linq;
  2. using Content.Server.Administration;
  3. using Content.Server.Maps;
  4. using Content.Shared.Administration;
  5. using Content.Shared.CCVar;
  6. using Robust.Shared.Configuration;
  7. using Robust.Shared.Console;
  8. using Robust.Shared.Prototypes;
  9. namespace Content.Server.GameTicking.Commands
  10. {
  11. [AdminCommand(AdminFlags.Round)]
  12. sealed class ForceMapCommand : IConsoleCommand
  13. {
  14. [Dependency] private readonly IConfigurationManager _configurationManager = default!;
  15. public string Command => "forcemap";
  16. public string Description => Loc.GetString("forcemap-command-description");
  17. public string Help => Loc.GetString("forcemap-command-help");
  18. public void Execute(IConsoleShell shell, string argStr, string[] args)
  19. {
  20. if (args.Length != 1)
  21. {
  22. shell.WriteLine(Loc.GetString("forcemap-command-need-one-argument"));
  23. return;
  24. }
  25. var gameMap = IoCManager.Resolve<IGameMapManager>();
  26. var name = args[0];
  27. // An empty string clears the forced map
  28. if (!string.IsNullOrEmpty(name) && !gameMap.CheckMapExists(name))
  29. {
  30. shell.WriteLine(Loc.GetString("forcemap-command-map-not-found", ("map", name)));
  31. return;
  32. }
  33. _configurationManager.SetCVar(CCVars.GameMap, name);
  34. if (string.IsNullOrEmpty(name))
  35. shell.WriteLine(Loc.GetString("forcemap-command-cleared"));
  36. else
  37. shell.WriteLine(Loc.GetString("forcemap-command-success", ("map", name)));
  38. }
  39. public CompletionResult GetCompletion(IConsoleShell shell, string[] args)
  40. {
  41. if (args.Length == 1)
  42. {
  43. var options = IoCManager.Resolve<IPrototypeManager>()
  44. .EnumeratePrototypes<GameMapPrototype>()
  45. .Select(p => new CompletionOption(p.ID, p.MapName))
  46. .OrderBy(p => p.Value);
  47. return CompletionResult.FromHintOptions(options, Loc.GetString("forcemap-command-arg-map"));
  48. }
  49. return CompletionResult.Empty;
  50. }
  51. }
  52. }