Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forcemap can be cleared with empty string again #29472

Merged
merged 1 commit into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions Content.IntegrationTests/Tests/Commands/ForceMapTest.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Content.Server.Maps;
using Content.Shared.CCVar;
using Robust.Shared.Configuration;
using Robust.Shared.Console;
Expand Down Expand Up @@ -49,27 +50,34 @@ public async Task TestForceMapCommand()
var entMan = server.EntMan;
var configManager = server.ResolveDependency<IConfigurationManager>();
var consoleHost = server.ResolveDependency<IConsoleHost>();
var gameMapMan = server.ResolveDependency<IGameMapManager>();

await server.WaitAssertion(() =>
{
// Make sure we're set to the default map
Assert.That(configManager.GetCVar(CCVars.GameMap), Is.EqualTo(DefaultMapName),
Assert.That(gameMapMan.GetSelectedMap()?.ID, Is.EqualTo(DefaultMapName),
$"Test didn't start on expected map ({DefaultMapName})!");

// Try changing to a map that doesn't exist
consoleHost.ExecuteCommand($"forcemap {BadMapName}");
Assert.That(configManager.GetCVar(CCVars.GameMap), Is.EqualTo(DefaultMapName),
Assert.That(gameMapMan.GetSelectedMap()?.ID, Is.EqualTo(DefaultMapName),
$"Forcemap succeeded with a map that does not exist ({BadMapName})!");

// Try changing to a valid map
consoleHost.ExecuteCommand($"forcemap {TestMapEligibleName}");
Assert.That(configManager.GetCVar(CCVars.GameMap), Is.EqualTo(TestMapEligibleName),
Assert.That(gameMapMan.GetSelectedMap()?.ID, Is.EqualTo(TestMapEligibleName),
$"Forcemap failed with a valid map ({TestMapEligibleName})");

// Try changing to a map that exists but is ineligible
consoleHost.ExecuteCommand($"forcemap {TestMapIneligibleName}");
Assert.That(configManager.GetCVar(CCVars.GameMap), Is.EqualTo(TestMapIneligibleName),
Assert.That(gameMapMan.GetSelectedMap()?.ID, Is.EqualTo(TestMapIneligibleName),
$"Forcemap failed with valid but ineligible map ({TestMapIneligibleName})!");

// Try clearing the force-selected map
consoleHost.ExecuteCommand("forcemap \"\"");
Assert.That(gameMapMan.GetSelectedMap(), Is.Null,
$"Running 'forcemap \"\"' did not clear the forced map!");

});

// Cleanup
Expand Down
9 changes: 7 additions & 2 deletions Content.Server/GameTicking/Commands/ForceMapCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,19 @@ public void Execute(IConsoleShell shell, string argStr, string[] args)
var gameMap = IoCManager.Resolve<IGameMapManager>();
var name = args[0];

if (!gameMap.CheckMapExists(name))
// An empty string clears the forced map
if (!string.IsNullOrEmpty(name) && !gameMap.CheckMapExists(name))
{
shell.WriteLine(Loc.GetString("forcemap-command-map-not-found", ("map", name)));
return;
}

_configurationManager.SetCVar(CCVars.GameMap, name);
shell.WriteLine(Loc.GetString("forcemap-command-success", ("map", name)));

if (string.IsNullOrEmpty(name))
shell.WriteLine(Loc.GetString("forcemap-command-cleared"));
else
shell.WriteLine(Loc.GetString("forcemap-command-success", ("map", name)));
}

public CompletionResult GetCompletion(IConsoleShell shell, string[] args)
Expand Down
1 change: 1 addition & 0 deletions Resources/Locale/en-US/game-ticking/forcemap-command.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ forcemap-command-help = forcemap <map ID>
forcemap-command-need-one-argument = forcemap takes one argument, the path to the map file.
forcemap-command-map-not-found = No eligible map exists with name { $map }.
forcemap-command-success = Forced the game to start with map { $map } next round.
forcemap-command-cleared = Cleared the forced map setting.
forcemap-command-arg-map = <map ID>
Loading