Validate spawn tile (#1512)

## Description:

Enforce valid tile during spawn, to prevent the game from crashing for
all players.

## 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
- [ ] I confirm I have thoroughly tested these changes and take full
responsibility for any bugs introduced
- [ ] I have read and accepted the CLA aggreement (only required once).
This commit is contained in:
Scott Anderson
2025-07-20 20:17:29 -07:00
committed by GitHub
parent e31495645f
commit 0489c63f4b
9 changed files with 27 additions and 57 deletions
+5 -14
View File
@@ -1,5 +1,4 @@
import {
Cell,
Execution,
Game,
Gold,
@@ -27,12 +26,11 @@ export class ConstructionExecution implements Execution {
private ticksUntilComplete: Tick;
private cost: Gold;
private tile: TileRef;
constructor(
private player: Player,
private constructionType: UnitType,
private tileOrCell: TileRef | Cell,
private tile: TileRef,
) {}
init(mg: Game, ticks: number): void {
@@ -46,17 +44,10 @@ export class ConstructionExecution implements Execution {
return;
}
if (this.tileOrCell instanceof Cell) {
if (!this.mg.isValidCoord(this.tileOrCell.x, this.tileOrCell.y)) {
console.warn(
`cannot build construction invalid coordinates ${this.tileOrCell.x}, ${this.tileOrCell.y}`,
);
this.active = false;
return;
}
this.tile = this.mg.ref(this.tileOrCell.x, this.tileOrCell.y);
} else {
this.tile = this.tileOrCell;
if (!this.mg.isValidRef(this.tile)) {
console.warn(`cannot build construction invalid tile ${this.tile}`);
this.active = false;
return;
}
}
+3 -10
View File
@@ -1,4 +1,4 @@
import { Cell, Execution, Game } from "../game/Game";
import { Execution, Game } from "../game/Game";
import { PseudoRandom } from "../PseudoRandom";
import { ClientID, GameID, Intent, Turn } from "../Schemas";
import { simpleHash } from "../Util";
@@ -67,10 +67,7 @@ export class Executor {
case "move_warship":
return new MoveWarshipExecution(player, intent.unitId, intent.tile);
case "spawn":
return new SpawnExecution(
player.info(),
this.mg.ref(intent.x, intent.y),
);
return new SpawnExecution(player.info(), intent.tile);
case "boat":
return new TransportShipExecution(
player,
@@ -106,11 +103,7 @@ export class Executor {
case "embargo":
return new EmbargoExecution(player, intent.targetID, intent.action);
case "build_unit":
return new ConstructionExecution(
player,
intent.unit,
new Cell(intent.x, intent.y),
);
return new ConstructionExecution(player, intent.unit, intent.tile);
case "allianceExtension": {
return new AllianceExtensionExecution(player, intent.recipient);
}
+5
View File
@@ -20,6 +20,11 @@ export class SpawnExecution implements Execution {
tick(ticks: number) {
this.active = false;
if (!this.mg.isValidRef(this.tile)) {
console.warn(`SpawnExecution: tile ${this.tile} not valid`);
return;
}
if (!this.mg.inSpawnPhase()) {
this.active = false;
return;