2023-12-17 03:55:19 +00:00
|
|
|
using Content.Shared.Administration;
|
|
|
|
|
using Content.Shared.CCVar;
|
|
|
|
|
using Robust.Shared.Configuration;
|
|
|
|
|
using Robust.Shared.Console;
|
|
|
|
|
using Robust.Shared.Map;
|
2024-12-22 15:13:10 +13:00
|
|
|
using Robust.Shared.EntitySerialization.Systems;
|
2024-12-24 18:57:52 +13:00
|
|
|
using Robust.Shared.Utility;
|
2023-12-17 03:55:19 +00:00
|
|
|
|
|
|
|
|
namespace Content.Server.Administration.Commands;
|
|
|
|
|
|
|
|
|
|
[AdminCommand(AdminFlags.Server)]
|
2025-05-26 12:45:55 -04:00
|
|
|
public sealed class PersistenceSave : LocalizedEntityCommands
|
2023-12-17 03:55:19 +00:00
|
|
|
{
|
|
|
|
|
[Dependency] private readonly IConfigurationManager _config = default!;
|
2025-05-26 12:45:55 -04:00
|
|
|
[Dependency] private readonly SharedMapSystem _map = default!;
|
2025-06-08 20:09:42 -04:00
|
|
|
[Dependency] private readonly MapLoaderSystem _mapLoader = default!;
|
2023-12-17 03:55:19 +00:00
|
|
|
|
2025-05-26 12:45:55 -04:00
|
|
|
public override string Command => "persistencesave";
|
2023-12-17 03:55:19 +00:00
|
|
|
|
2025-05-26 12:45:55 -04:00
|
|
|
public override void Execute(IConsoleShell shell, string argStr, string[] args)
|
2023-12-17 03:55:19 +00:00
|
|
|
{
|
|
|
|
|
if (args.Length < 1 || args.Length > 2)
|
|
|
|
|
{
|
|
|
|
|
shell.WriteError(Loc.GetString("shell-wrong-arguments-number"));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!int.TryParse(args[0], out var intMapId))
|
|
|
|
|
{
|
|
|
|
|
shell.WriteError(Loc.GetString("cmd-parse-failure-integer", ("arg", args[0])));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var mapId = new MapId(intMapId);
|
|
|
|
|
if (!_map.MapExists(mapId))
|
|
|
|
|
{
|
|
|
|
|
shell.WriteError(Loc.GetString("cmd-savemap-not-exist"));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var saveFilePath = (args.Length > 1 ? args[1] : null) ?? _config.GetCVar(CCVars.GameMap);
|
|
|
|
|
if (string.IsNullOrWhiteSpace(saveFilePath))
|
|
|
|
|
{
|
|
|
|
|
shell.WriteError(Loc.GetString("cmd-persistencesave-no-path", ("cvar", nameof(CCVars.GameMap))));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-08 20:09:42 -04:00
|
|
|
_mapLoader.TrySaveMap(mapId, new ResPath(saveFilePath));
|
2023-12-17 03:55:19 +00:00
|
|
|
shell.WriteLine(Loc.GetString("cmd-savemap-success"));
|
|
|
|
|
}
|
|
|
|
|
}
|