-
Notifications
You must be signed in to change notification settings - Fork 1k
fix(core,server): resolve critical security, stability, and logic issues #3796
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
Closed
+245
−17
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b97858d
fix(core,server): resolve critical security, stability, and logic issues
berkelmali 7ee9712
fix: address CodeRabbit review feedback and Prettier formatting
berkelmali af4040c
fix: address all CodeRabbit review feedback
berkelmali 2f5d071
fix: address remaining CodeRabbit nitpicks
berkelmali 0d8f233
fix: restore babyboucher's hostCheats fix (e0cc50d)
berkelmali File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| import { AttackExecution } from "../src/core/execution/AttackExecution"; | ||
| import { RetreatExecution } from "../src/core/execution/RetreatExecution"; | ||
| import { SpawnExecution } from "../src/core/execution/SpawnExecution"; | ||
| import { Game, Player, PlayerInfo, PlayerType } from "../src/core/game/Game"; | ||
| import { GameID } from "../src/core/Schemas"; | ||
| import { setup } from "./util/Setup"; | ||
|
|
||
| let game: Game; | ||
| const gameID: GameID = "game_id"; | ||
| let player1: Player; | ||
| let player2: Player; | ||
|
|
||
| describe("AttackRetreatStats", () => { | ||
| beforeEach(async () => { | ||
| game = await setup("plains", {}, [ | ||
| new PlayerInfo("player1", PlayerType.Human, "player1", "player1"), | ||
| new PlayerInfo("player2", PlayerType.Human, "player2", "player2"), | ||
| ]); | ||
|
|
||
| player1 = game.player("player1"); | ||
| player2 = game.player("player2"); | ||
|
|
||
| game.addExecution( | ||
| new SpawnExecution(gameID, player1.info(), game.ref(50, 50)), | ||
| ); | ||
| game.addExecution( | ||
| new SpawnExecution(gameID, player2.info(), game.ref(50, 55)), | ||
| ); | ||
|
|
||
| while (game.inSpawnPhase()) { | ||
| game.executeNextTick(); | ||
| } | ||
| }); | ||
|
|
||
| test("should call attackCancel when attack is retreated", () => { | ||
| // Attack terraNullius so the attack doesn't end quickly from troop loss | ||
| const attackCancelSpy = vi.spyOn(game.stats(), "attackCancel"); | ||
|
|
||
| game.addExecution( | ||
| new AttackExecution(player1.troops(), player1, game.terraNullius().id()), | ||
| ); | ||
|
|
||
| // Execute one tick so the attack is initialized | ||
| game.executeNextTick(); | ||
|
|
||
| const attacks = player1.outgoingAttacks(); | ||
| expect(attacks.length).toBeGreaterThan(0); | ||
| const attackId = attacks[0].id(); | ||
|
|
||
| // Add retreat execution immediately | ||
| game.addExecution(new RetreatExecution(player1, attackId)); | ||
|
|
||
| // Execute ticks until the attack finishes retreating (cancelDelay=20 + a few more) | ||
| for (let i = 0; i < 50; i++) { | ||
| game.executeNextTick(); | ||
| } | ||
|
|
||
| // Verify attackCancel was called (retreat stats recorded) | ||
| expect(attackCancelSpy).toHaveBeenCalled(); | ||
| expect(attackCancelSpy).toHaveBeenCalledWith( | ||
| player1, | ||
| expect.anything(), | ||
| expect.any(Number), | ||
| ); | ||
| }); | ||
|
|
||
| test("should NOT call attackCancel when attack completes without retreat", () => { | ||
| expect(player1.sharesBorderWith(player2)).toBeTruthy(); | ||
|
|
||
| const attackCancelSpy = vi.spyOn(game.stats(), "attackCancel"); | ||
|
|
||
| // Start a full-troop attack against the other player (no retreat) | ||
| game.addExecution( | ||
| new AttackExecution(player1.troops(), player1, player2.id()), | ||
| ); | ||
|
|
||
| // Execute until attack completes | ||
| let maxTicks = 5000; | ||
| while (player1.outgoingAttacks().length > 0 && maxTicks > 0) { | ||
| game.executeNextTick(); | ||
| maxTicks--; | ||
| } | ||
| // Make sure the loop ended because the attack finished, not because we ran out of ticks. | ||
| expect(player1.outgoingAttacks().length).toBe(0); | ||
|
|
||
| // Verify attackCancel was NOT called | ||
| expect(attackCancelSpy).not.toHaveBeenCalled(); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.