Files
OldThink/Content.Server/Mapping/MappingCommand.cs

139 lines
4.7 KiB
C#
Raw Normal View History

// 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;
using Content.Server.Administration;
using Content.Server.GameTicking;
using Content.Shared.Administration;
2022-09-03 06:39:28 -07:00
using Content.Shared.CCVar;
using Robust.Server.Player;
2022-09-03 06:39:28 -07:00
using Robust.Shared.Configuration;
using Robust.Shared.Console;
2022-09-03 06:39:28 -07:00
using Robust.Shared.ContentPack;
using Robust.Shared.Map;
using Robust.Shared.Utility;
2022-09-03 06:39:28 -07:00
namespace Content.Server.Mapping
{
[AdminCommand(AdminFlags.Server | AdminFlags.Mapping)]
sealed class MappingCommand : IConsoleCommand
{
2021-12-05 21:02:04 +01:00
[Dependency] private readonly IEntityManager _entities = default!;
public string Command => "mapping";
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;
}
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (shell.Player is not { } player)
{
shell.WriteError(Loc.GetString("cmd-savemap-server"));
return;
}
2022-02-28 14:21:15 +13:00
if (args.Length > 2)
{
shell.WriteLine(Help);
return;
}
#if DEBUG
shell.WriteError(Loc.GetString("cmd-mapping-warning"));
#endif
var mapManager = IoCManager.Resolve<IMapManager>();
2022-02-28 14:21:15 +13:00
MapId mapId;
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)
{
if (!int.TryParse(args[0], out var intMapId))
2022-02-28 14:21:15 +13: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;
}
2022-02-28 14:21:15 +13:00
if (mapManager.MapExists(mapId))
{
shell.WriteError(Loc.GetString("cmd-mapping-exists", ("mapId", mapId)));
return;
2022-02-28 14:21:15 +13:00
}
2022-02-28 14:21:15 +13:00
}
else
{
mapId = mapManager.NextMapId();
}
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
{
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))
{
shell.WriteError(Loc.GetString("cmd-mapping-error"));
return;
}
2022-02-28 14:21:15 +13:00
// map successfully created. run misc helpful mapping commands
if (player.AttachedEntity is { Valid: true } playerEntity &&
_entities.GetComponent<MetaDataComponent>(playerEntity).EntityPrototype?.ID != GameTicker.AdminObserverPrototypeName)
2021-12-05 21:02:04 +01:00
{
shell.ExecuteCommand("aghost");
2021-12-05 21:02:04 +01:00
}
2022-09-03 06:39:28 -07:00
var cfg = IoCManager.Resolve<IConfigurationManager>();
// don't interrupt mapping with events or auto-shuttle
2022-02-28 14:21:15 +13:00
shell.ExecuteCommand("sudo cvar events.enabled false");
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"}");
shell.ExecuteCommand($"tp 0 0 {mapId}");
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)
shell.WriteLine(Loc.GetString("cmd-mapping-success-load",("mapId",mapId),("path", args[1])));
2022-02-28 14:21:15 +13:00
else
shell.WriteLine(Loc.GetString("cmd-mapping-success", ("mapId", mapId)));
}
}
}