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
|
|
|
|
2022-09-03 06:39:28 -07:00
|
|
|
using System.Linq;
|
2020-12-03 03:40:47 +01:00
|
|
|
using Content.Server.Administration;
|
2023-11-20 20:27:37 -08:00
|
|
|
using Content.Server.GameTicking;
|
2020-12-03 03:40:47 +01:00
|
|
|
using Content.Shared.Administration;
|
2022-09-03 06:39:28 -07:00
|
|
|
using Content.Shared.CCVar;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Server.Player;
|
2022-09-03 06:39:28 -07:00
|
|
|
using Robust.Shared.Configuration;
|
2021-02-01 16:49:43 -08:00
|
|
|
using Robust.Shared.Console;
|
2022-09-03 06:39:28 -07:00
|
|
|
using Robust.Shared.ContentPack;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Shared.Map;
|
2020-12-03 03:40:47 +01:00
|
|
|
using Robust.Shared.Utility;
|
|
|
|
|
|
2022-09-03 06:39:28 -07:00
|
|
|
namespace Content.Server.Mapping
|
2020-12-03 03:40:47 +01:00
|
|
|
{
|
|
|
|
|
[AdminCommand(AdminFlags.Server | AdminFlags.Mapping)]
|
2022-02-16 00:23:23 -07:00
|
|
|
sealed 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";
|
2022-06-09 14:38:31 +12:00
|
|
|
public string Description => Loc.GetString("cmd-mapping-desc");
|
|
|
|
|
public string Help => Loc.GetString("cmd-mapping-help");
|
|
|
|
|
|
|
|
|
|
public CompletionResult GetCompletion(IConsoleShell shell, string[] args)
|
|
|
|
|
{
|
|
|
|
|
switch (args.Length)
|
|
|
|
|
{
|
|
|
|
|
case 1:
|
|
|
|
|
return CompletionResult.FromHint(Loc.GetString("cmd-hint-mapping-id"));
|
|
|
|
|
case 2:
|
|
|
|
|
var res = IoCManager.Resolve<IResourceManager>();
|
|
|
|
|
var opts = CompletionHelper.UserFilePath(args[1], res.UserData)
|
|
|
|
|
.Concat(CompletionHelper.ContentFilePath(args[1], res));
|
|
|
|
|
return CompletionResult.FromHintOptions(opts, Loc.GetString("cmd-hint-mapping-path"));
|
|
|
|
|
}
|
|
|
|
|
return CompletionResult.Empty;
|
|
|
|
|
}
|
2020-12-03 03:40:47 +01:00
|
|
|
|
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
|
|
|
{
|
2023-10-28 09:59:53 +11:00
|
|
|
if (shell.Player is not { } player)
|
2020-12-03 03:40:47 +01:00
|
|
|
{
|
2022-06-09 14:38:31 +12:00
|
|
|
shell.WriteError(Loc.GetString("cmd-savemap-server"));
|
2020-12-03 03:40:47 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-28 14:21:15 +13:00
|
|
|
if (args.Length > 2)
|
|
|
|
|
{
|
|
|
|
|
shell.WriteLine(Help);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-07 06:36:34 +01:00
|
|
|
#if DEBUG
|
2022-06-09 14:38:31 +12:00
|
|
|
shell.WriteError(Loc.GetString("cmd-mapping-warning"));
|
2021-02-07 06:36:34 +01:00
|
|
|
#endif
|
|
|
|
|
|
2020-12-03 03:40:47 +01:00
|
|
|
var mapManager = IoCManager.Resolve<IMapManager>();
|
2022-02-28 14:21:15 +13:00
|
|
|
MapId mapId;
|
2020-12-03 03:40:47 +01:00
|
|
|
|
2022-02-28 14:21:15 +13:00
|
|
|
// Get the map ID to use
|
2022-03-01 21:11:22 +11:00
|
|
|
if (args.Length is 1 or 2)
|
2020-12-03 03:40:47 +01:00
|
|
|
{
|
2022-06-09 14:38:31 +12:00
|
|
|
|
|
|
|
|
if (!int.TryParse(args[0], out var intMapId))
|
2022-02-28 14:21:15 +13:00
|
|
|
{
|
2022-06-09 14:38:31 +12:00
|
|
|
shell.WriteError(Loc.GetString("cmd-mapping-failure-integer", ("arg", args[0])));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mapId = new MapId(intMapId);
|
|
|
|
|
|
|
|
|
|
// no loading null space
|
|
|
|
|
if (mapId == MapId.Nullspace)
|
|
|
|
|
{
|
|
|
|
|
shell.WriteError(Loc.GetString("cmd-mapping-nullspace"));
|
2022-02-28 14:21:15 +13:00
|
|
|
return;
|
|
|
|
|
}
|
2020-12-03 03:40:47 +01:00
|
|
|
|
2022-02-28 14:21:15 +13:00
|
|
|
if (mapManager.MapExists(mapId))
|
|
|
|
|
{
|
2022-06-09 14:38:31 +12:00
|
|
|
shell.WriteError(Loc.GetString("cmd-mapping-exists", ("mapId", mapId)));
|
2020-12-03 03:40:47 +01:00
|
|
|
return;
|
2022-02-28 14:21:15 +13:00
|
|
|
}
|
2022-06-09 14:38:31 +12:00
|
|
|
|
2022-02-28 14:21:15 +13:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
mapId = mapManager.NextMapId();
|
2020-12-03 03:40:47 +01:00
|
|
|
}
|
|
|
|
|
|
2022-09-03 06:39:28 -07:00
|
|
|
string? toLoad = null;
|
2022-02-28 14:21:15 +13:00
|
|
|
// either load a map or create a new one.
|
2022-03-01 21:11:22 +11:00
|
|
|
if (args.Length <= 1)
|
2022-09-03 06:39:28 -07:00
|
|
|
{
|
2022-02-28 16:38:33 +11:00
|
|
|
shell.ExecuteCommand($"addmap {mapId} false");
|
2022-09-03 06:39:28 -07:00
|
|
|
}
|
2022-02-28 14:21:15 +13:00
|
|
|
else
|
2022-09-03 06:39:28 -07:00
|
|
|
{
|
|
|
|
|
toLoad = CommandParsing.Escape(args[1]);
|
|
|
|
|
shell.ExecuteCommand($"loadmap {mapId} \"{toLoad}\" 0 0 0 true");
|
|
|
|
|
}
|
2022-02-28 14:21:15 +13:00
|
|
|
|
|
|
|
|
// was the map actually created?
|
|
|
|
|
if (!mapManager.MapExists(mapId))
|
2021-12-02 20:25:50 -08:00
|
|
|
{
|
2022-06-09 14:38:31 +12:00
|
|
|
shell.WriteError(Loc.GetString("cmd-mapping-error"));
|
2021-12-02 20:25:50 -08:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-28 14:21:15 +13:00
|
|
|
// map successfully created. run misc helpful mapping commands
|
|
|
|
|
if (player.AttachedEntity is { Valid: true } playerEntity &&
|
2023-11-20 20:27:37 -08:00
|
|
|
_entities.GetComponent<MetaDataComponent>(playerEntity).EntityPrototype?.ID != GameTicker.AdminObserverPrototypeName)
|
2021-12-05 21:02:04 +01:00
|
|
|
{
|
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
|
|
|
|
2022-09-03 06:39:28 -07:00
|
|
|
var cfg = IoCManager.Resolve<IConfigurationManager>();
|
|
|
|
|
|
2022-11-17 15:14:44 -08:00
|
|
|
// don't interrupt mapping with events or auto-shuttle
|
2022-02-28 14:21:15 +13:00
|
|
|
shell.ExecuteCommand("sudo cvar events.enabled false");
|
2022-11-17 15:14:44 -08:00
|
|
|
shell.ExecuteCommand("sudo cvar shuttle.auto_call_time 0");
|
|
|
|
|
|
2022-09-03 06:39:28 -07:00
|
|
|
if (cfg.GetCVar(CCVars.AutosaveEnabled))
|
|
|
|
|
shell.ExecuteCommand($"toggleautosave {mapId} {toLoad ?? "NEWMAP"}");
|
2021-02-01 16:49:43 -08:00
|
|
|
shell.ExecuteCommand($"tp 0 0 {mapId}");
|
2022-05-04 04:19:15 +01:00
|
|
|
shell.RemoteExecuteCommand("mappingclientsidesetup");
|
2022-02-28 14:21:15 +13:00
|
|
|
mapManager.SetMapPaused(mapId, true);
|
|
|
|
|
|
2022-03-01 21:11:22 +11:00
|
|
|
if (args.Length == 2)
|
2022-06-09 14:38:31 +12:00
|
|
|
shell.WriteLine(Loc.GetString("cmd-mapping-success-load",("mapId",mapId),("path", args[1])));
|
2022-02-28 14:21:15 +13:00
|
|
|
else
|
2022-06-09 14:38:31 +12:00
|
|
|
shell.WriteLine(Loc.GetString("cmd-mapping-success", ("mapId", mapId)));
|
2020-12-03 03:40:47 +01:00
|
|
|
}
|
|
|
|
|
}
|
2020-12-14 06:16:40 +01:00
|
|
|
}
|