2021-02-07 06:36:34 +01:00
|
|
|
// ReSharper disable once RedundantUsingDirective
|
|
|
|
|
// Used to warn the player in big red letters in debug mode
|
2021-06-09 22:19:39 +02:00
|
|
|
|
2021-02-01 16:49:43 -08:00
|
|
|
using System.Linq;
|
2020-12-03 03:40:47 +01:00
|
|
|
using Content.Server.Administration;
|
|
|
|
|
using Content.Shared.Administration;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Server.Player;
|
2021-02-01 16:49:43 -08:00
|
|
|
using Robust.Shared.Console;
|
2021-12-03 11:13:58 +01:00
|
|
|
using Robust.Shared.GameObjects;
|
2020-12-03 03:40:47 +01:00
|
|
|
using Robust.Shared.IoC;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Shared.Map;
|
2021-12-03 11:13:58 +01:00
|
|
|
using Robust.Shared.Prototypes;
|
2021-02-18 20:45:45 -08:00
|
|
|
using Robust.Shared.Timing;
|
2020-12-03 03:40:47 +01:00
|
|
|
using Robust.Shared.Utility;
|
|
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Server.GameTicking.Commands
|
2020-12-03 03:40:47 +01:00
|
|
|
{
|
|
|
|
|
[AdminCommand(AdminFlags.Server | AdminFlags.Mapping)]
|
2021-02-01 16:49:43 -08:00
|
|
|
class MappingCommand : IConsoleCommand
|
2020-12-03 03:40:47 +01:00
|
|
|
{
|
2021-12-05 21:02:04 +01:00
|
|
|
[Dependency] private readonly IEntityManager _entities = default!;
|
|
|
|
|
|
2020-12-03 03:40:47 +01:00
|
|
|
public string Command => "mapping";
|
|
|
|
|
public string Description => "Creates and teleports you to a new uninitialized map for mapping.";
|
|
|
|
|
public string Help => $"Usage: {Command} <mapname> / {Command} <id> <mapname>";
|
|
|
|
|
|
2021-02-01 16:49:43 -08:00
|
|
|
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
2020-12-03 03:40:47 +01:00
|
|
|
{
|
2021-02-01 16:49:43 -08:00
|
|
|
var player = shell.Player as IPlayerSession;
|
2020-12-03 03:40:47 +01:00
|
|
|
if (player == null)
|
|
|
|
|
{
|
2021-02-01 16:49:43 -08:00
|
|
|
shell.WriteLine("Only players can use this command");
|
2020-12-03 03:40:47 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-07 06:36:34 +01:00
|
|
|
#if DEBUG
|
2021-02-07 14:56:08 +01:00
|
|
|
shell.WriteError("WARNING: The server is using a debug build. You are risking losing your changes.");
|
2021-02-07 06:36:34 +01:00
|
|
|
#endif
|
|
|
|
|
|
2020-12-03 03:40:47 +01:00
|
|
|
var mapManager = IoCManager.Resolve<IMapManager>();
|
|
|
|
|
int mapId;
|
|
|
|
|
string mapName;
|
|
|
|
|
|
|
|
|
|
switch (args.Length)
|
|
|
|
|
{
|
|
|
|
|
case 1:
|
|
|
|
|
if (player.AttachedEntity == null)
|
|
|
|
|
{
|
2021-11-23 06:31:21 +11:00
|
|
|
shell.WriteError("The map name argument cannot be omitted if you have no entity.");
|
2020-12-03 03:40:47 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mapId = (int) mapManager.NextMapId();
|
|
|
|
|
mapName = args[0];
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
if (!int.TryParse(args[0], out var id))
|
|
|
|
|
{
|
2021-11-23 06:31:21 +11:00
|
|
|
shell.WriteError($"{args[0]} is not a valid integer.");
|
2020-12-03 03:40:47 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mapId = id;
|
|
|
|
|
mapName = args[1];
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2021-02-01 16:49:43 -08:00
|
|
|
shell.WriteLine(Help);
|
2020-12-03 03:40:47 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-11 17:51:52 +11:00
|
|
|
// loadmap checks for this on its own but we want to avoid running our other commands.
|
2021-12-02 20:25:50 -08:00
|
|
|
if (mapManager.MapExists(new MapId(mapId)))
|
|
|
|
|
{
|
2022-01-11 17:51:52 +11:00
|
|
|
shell.WriteError($"Map {mapId} already exists");
|
2021-12-02 20:25:50 -08:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-27 16:22:20 +00:00
|
|
|
shell.ExecuteCommand("sudo cvar events.enabled false");
|
2022-01-11 17:51:52 +11:00
|
|
|
shell.ExecuteCommand($"loadmap {mapId} \"{CommandParsing.Escape(mapName)}\" true");
|
2021-11-23 06:31:21 +11:00
|
|
|
|
2021-12-05 21:02:04 +01:00
|
|
|
if (player.AttachedEntity is {Valid: true} playerEntity &&
|
|
|
|
|
_entities.GetComponent<MetaDataComponent>(playerEntity).EntityPrototype?.ID != "AdminObserver")
|
|
|
|
|
{
|
2021-11-23 06:31:21 +11:00
|
|
|
shell.ExecuteCommand("aghost");
|
2021-12-05 21:02:04 +01:00
|
|
|
}
|
2021-11-23 06:31:21 +11:00
|
|
|
|
2021-02-01 16:49:43 -08:00
|
|
|
shell.ExecuteCommand($"tp 0 0 {mapId}");
|
2021-11-25 18:36:57 -04:00
|
|
|
shell.RemoteExecuteCommand("showmarkers");
|
2020-12-03 03:40:47 +01:00
|
|
|
|
2021-01-17 15:51:44 +01:00
|
|
|
var newGrid = mapManager.GetAllGrids().OrderByDescending(g => (int) g.Index).First();
|
2020-12-14 06:16:40 +01:00
|
|
|
var pauseManager = IoCManager.Resolve<IPauseManager>();
|
2020-12-03 03:40:47 +01:00
|
|
|
|
2020-12-14 06:16:40 +01:00
|
|
|
pauseManager.SetMapPaused(newGrid.ParentMapId, true);
|
|
|
|
|
|
2021-02-01 16:49:43 -08:00
|
|
|
shell.WriteLine($"Created unloaded map from file {mapName} with id {mapId}. Use \"savebp {newGrid.Index} foo.yml\" to save the new grid as a map.");
|
2020-12-03 03:40:47 +01:00
|
|
|
}
|
|
|
|
|
}
|
2020-12-14 06:16:40 +01:00
|
|
|
}
|