-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Fix bugs from code audit (server respawn, leaks, hardening) #4427
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
Draft
evanpelle
wants to merge
1
commit into
main
Choose a base branch
from
fix/code-audit-bugs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
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
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,45 @@ | ||
| import { SpawnExecution } from "../src/core/execution/SpawnExecution"; | ||
| import { Game, PlayerInfo, PlayerType } from "../src/core/game/Game"; | ||
| import { TileRef } from "../src/core/game/GameMap"; | ||
| import { GameID } from "../src/core/Schemas"; | ||
| import { setup } from "./util/Setup"; | ||
|
|
||
| const GAME_ID: GameID = "game_id"; | ||
| const PLAYER_ID = "p_id"; | ||
|
|
||
| async function spawnWith( | ||
| randomSpawn: boolean, | ||
| x: number, | ||
| y: number, | ||
| ): Promise<{ game: Game; injected: TileRef; spawnTile: TileRef | undefined }> { | ||
| const game = await setup("plains", { randomSpawn }); | ||
| game.addPlayer(new PlayerInfo("p", PlayerType.Human, null, PLAYER_ID)); | ||
| const injected = game.map().ref(x, y); | ||
| game.addExecution( | ||
| new SpawnExecution(GAME_ID, game.player(PLAYER_ID).info(), injected), | ||
| ); | ||
| game.executeNextTick(); // init the execution | ||
| game.executeNextTick(); // run the execution | ||
| return { game, injected, spawnTile: game.player(PLAYER_ID).spawnTile() }; | ||
| } | ||
|
|
||
| describe("Random spawn cannot be overridden by a client-supplied tile", () => { | ||
| test("non-random mode honors the requested tile", async () => { | ||
| const { injected, spawnTile } = await spawnWith(false, 50, 50); | ||
| expect(spawnTile).toBe(injected); | ||
| }); | ||
|
|
||
| test("random mode ignores the injected tile", async () => { | ||
| const a = await spawnWith(true, 50, 50); | ||
| const b = await spawnWith(true, 60, 60); | ||
|
|
||
| // The player still spawns on a valid land tile. | ||
| expect(a.spawnTile).toBeDefined(); | ||
| expect(a.game.isLand(a.spawnTile!)).toBe(true); | ||
|
|
||
| // If the injected tile were honored, the two runs would spawn at the two | ||
| // distinct injected tiles. Because random spawn ignores it and uses the | ||
| // deterministic per-player seed instead, both runs land on the same tile. | ||
| expect(a.spawnTile).toBe(b.spawnTile); | ||
| }); | ||
| }); |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
Mirror the websocket-set cleanup in this race path.
Line 723 removes the client from
activeClients, but this branch still leavesclient.wsinsidethis.websockets. If the socket was already closed beforeaddListeners()ran,end()keeps iterating a dead entry and the set can grow with abandoned sockets. Add the same delete used in the normal"close"handler.Proposed fix
if (client.ws.readyState >= 2) { this.log.info("client WebSocket already closing/closed, removing", { clientID: client.clientID, readyState: client.ws.readyState, }); + this.websockets.delete(client.ws); this.activeClients = this.activeClients.filter( (c) => c.clientID !== client.clientID, ); // Remove persistentId if the game has not started to prevent going over max players if (!this._hasStarted) {📝 Committable suggestion
🤖 Prompt for AI Agents