From a9c89e4f15f1cb21051676d78b4cba085bd02455 Mon Sep 17 00:00:00 2001 From: Mattia Migliorini Date: Sun, 1 Mar 2026 12:20:19 +0100 Subject: [PATCH] Fix: Nations reject alliance requests during spawn phase (#3312) ## Description: This PR fixes an exploit that allows the player to request alliances to Nations, mostly in impossible mode, during spawn phase, with high chances for it to be accepted due to troop count parity. Nations now reject alliance requests during the spawn phase. ## Please complete the following: - [x] I have added screenshots for all UI updates - [x] I process any text displayed to the user through translateText() and I've added it to the en.json file - [x] I have added relevant tests to the test directory - [x] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced ## Please put your Discord username so you can be contacted if a bug or regression is found: deshack_82603 --- .../execution/nation/NationAllianceBehavior.ts | 5 +++++ tests/NationAllianceBehavior.test.ts | 14 ++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/core/execution/nation/NationAllianceBehavior.ts b/src/core/execution/nation/NationAllianceBehavior.ts index 186a3b556..410e1a63e 100644 --- a/src/core/execution/nation/NationAllianceBehavior.ts +++ b/src/core/execution/nation/NationAllianceBehavior.ts @@ -76,6 +76,11 @@ export class NationAllianceBehavior { otherPlayer: Player, isResponse: boolean, ): boolean { + // Reject alliance requests during the spawn phase + if (this.game.inSpawnPhase()) { + return false; + } + // Easy (dumb) nations sometimes get confused and accept/reject randomly (Just like dumb humans do) if (this.isConfused()) { return this.random.chance(2); diff --git a/tests/NationAllianceBehavior.test.ts b/tests/NationAllianceBehavior.test.ts index ea2c74077..2849ac75b 100644 --- a/tests/NationAllianceBehavior.test.ts +++ b/tests/NationAllianceBehavior.test.ts @@ -51,6 +51,10 @@ describe("AllianceBehavior.handleAllianceRequests", () => { player, new NationEmojiBehavior(random, game, player), ); + + while (game.inSpawnPhase()) { + game.executeNextTick(); + } }); function setupAllianceRequest({ @@ -92,6 +96,16 @@ describe("AllianceBehavior.handleAllianceRequests", () => { return mockRequest; } + test("should reject alliance during spawn phase", () => { + vi.spyOn(game, "inSpawnPhase").mockReturnValue(true); + const request = setupAllianceRequest({}); + + allianceBehavior.handleAllianceRequests(); + + expect(request.accept).not.toHaveBeenCalled(); + expect(request.reject).toHaveBeenCalled(); + }); + test("should accept alliance when all conditions are met", () => { const request = setupAllianceRequest({});