]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix forcemap not bypassing requirements (#29426)
authorTayrtahn <tayrtahn@gmail.com>
Mon, 24 Jun 2024 22:29:44 +0000 (18:29 -0400)
committerGitHub <noreply@github.com>
Mon, 24 Jun 2024 22:29:44 +0000 (18:29 -0400)
* Fix forcemap not bypassing requirements

* Add integration test for forcemap

Content.IntegrationTests/Tests/Commands/ForceMapTest.cs [new file with mode: 0644]
Content.Server/GameTicking/Commands/ForceMapCommand.cs
Resources/Locale/en-US/game-ticking/forcemap-command.ftl

diff --git a/Content.IntegrationTests/Tests/Commands/ForceMapTest.cs b/Content.IntegrationTests/Tests/Commands/ForceMapTest.cs
new file mode 100644 (file)
index 0000000..5115996
--- /dev/null
@@ -0,0 +1,80 @@
+using Content.Shared.CCVar;
+using Robust.Shared.Configuration;
+using Robust.Shared.Console;
+
+namespace Content.IntegrationTests.Tests.Commands;
+
+[TestFixture]
+public sealed class ForceMapTest
+{
+    private const string DefaultMapName = "Empty";
+    private const string BadMapName = "asdf_asd-fa__sdfAsd_f"; // Hopefully no one ever names a map this...
+    private const string TestMapEligibleName = "ForceMapTestEligible";
+    private const string TestMapIneligibleName = "ForceMapTestIneligible";
+
+    [TestPrototypes]
+    private static readonly string TestMaps = @$"
+- type: gameMap
+  id: {TestMapIneligibleName}
+  mapName: {TestMapIneligibleName}
+  mapPath: /Maps/Test/empty.yml
+  minPlayers: 20
+  maxPlayers: 80
+  stations:
+    Empty:
+      stationProto: StandardNanotrasenStation
+      components:
+        - type: StationNameSetup
+          mapNameTemplate: ""Empty""
+
+- type: gameMap
+  id: {TestMapEligibleName}
+  mapName: {TestMapEligibleName}
+  mapPath: /Maps/Test/empty.yml
+  minPlayers: 0
+  stations:
+    Empty:
+      stationProto: StandardNanotrasenStation
+      components:
+        - type: StationNameSetup
+          mapNameTemplate: ""Empty""
+";
+
+    [Test]
+    public async Task TestForceMapCommand()
+    {
+        await using var pair = await PoolManager.GetServerClient();
+        var server = pair.Server;
+
+        var entMan = server.EntMan;
+        var configManager = server.ResolveDependency<IConfigurationManager>();
+        var consoleHost = server.ResolveDependency<IConsoleHost>();
+
+        await server.WaitAssertion(() =>
+        {
+            // Make sure we're set to the default map
+            Assert.That(configManager.GetCVar(CCVars.GameMap), 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),
+                $"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),
+                $"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),
+                $"Forcemap failed with valid but ineligible map ({TestMapIneligibleName})!");
+        });
+
+        // Cleanup
+        configManager.SetCVar(CCVars.GameMap, DefaultMapName);
+
+        await pair.CleanReturnAsync();
+    }
+}
index 5677ff4b8ff7b36ad971cfe5306d702e4425f292..76777623a2bca747dfbc824b40dfb70db392c375 100644 (file)
@@ -29,9 +29,9 @@ namespace Content.Server.GameTicking.Commands
             var gameMap = IoCManager.Resolve<IGameMapManager>();
             var name = args[0];
 
-            if (!gameMap.TrySelectMapIfEligible(name))
+            if (!gameMap.CheckMapExists(name))
             {
-                shell.WriteLine($"No eligible map exists with name {name}.");
+                shell.WriteLine(Loc.GetString("forcemap-command-map-not-found", ("map", name)));
                 return;
             }
 
index df2ca687867623a2c1b6bd9f336c010bcc02f619..6a4399cdcfef61e61c6cb68ce501371ddfb5814a 100644 (file)
@@ -3,5 +3,6 @@
 forcemap-command-description = Forces the game to start with a given map next round.
 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-arg-map = <map ID>