From 5e6f8f5d9198621c5005071fed29fc0baf0b79d3 Mon Sep 17 00:00:00 2001 From: Evan Date: Tue, 18 Feb 2025 16:26:49 -0800 Subject: [PATCH] validate all intent input --- src/core/execution/AttackExecution.ts | 11 +++++++++++ src/core/execution/CityExecution.ts | 5 +++++ src/core/execution/ConstructionExecution.ts | 5 +++++ src/core/execution/DefensePostExecution.ts | 5 +++++ src/core/execution/DonateExecution.ts | 11 +++++++++++ src/core/execution/EmojiExecution.ts | 11 +++++++++++ src/core/execution/MIRVExecution.ts | 6 ++++++ src/core/execution/MissileSiloExecution.ts | 6 ++++++ src/core/execution/NukeExecution.ts | 6 ++++++ src/core/execution/PlayerExecution.ts | 5 +++++ src/core/execution/PortExecution.ts | 5 +++++ src/core/execution/SetTargetTroopRatioExecution.ts | 5 +++++ src/core/execution/SpawnExecution.ts | 1 + src/core/execution/TargetPlayerExecution.ts | 13 +++++++++++++ src/core/execution/TransportShipExecution.ts | 13 +++++++++++++ src/core/execution/WarshipExecution.ts | 5 +++++ 16 files changed, 113 insertions(+) diff --git a/src/core/execution/AttackExecution.ts b/src/core/execution/AttackExecution.ts index 6bff9b4b0..6453d4237 100644 --- a/src/core/execution/AttackExecution.ts +++ b/src/core/execution/AttackExecution.ts @@ -62,6 +62,17 @@ export class AttackExecution implements Execution { } this.mg = mg; + if (!mg.hasPlayer(this._ownerID)) { + console.warn(`player ${this._ownerID} not found`); + this.active = false; + return; + } + if (this._targetID != null && !mg.hasPlayer(this._targetID)) { + console.warn(`target ${this._targetID} not found`); + this.active = false; + return; + } + this._owner = mg.player(this._ownerID); this.target = this._targetID == this.mg.terraNullius().id() diff --git a/src/core/execution/CityExecution.ts b/src/core/execution/CityExecution.ts index 47270708e..d6cbaf2c6 100644 --- a/src/core/execution/CityExecution.ts +++ b/src/core/execution/CityExecution.ts @@ -22,6 +22,11 @@ export class CityExecution implements Execution { init(mg: Game, ticks: number): void { this.mg = mg; + if (!mg.hasPlayer(this.ownerId)) { + console.warn(`CityExecution: player ${this.ownerId} not found`); + this.active = false; + return; + } this.player = mg.player(this.ownerId); } diff --git a/src/core/execution/ConstructionExecution.ts b/src/core/execution/ConstructionExecution.ts index be86ad275..f6a545528 100644 --- a/src/core/execution/ConstructionExecution.ts +++ b/src/core/execution/ConstructionExecution.ts @@ -36,6 +36,11 @@ export class ConstructionExecution implements Execution { init(mg: Game, ticks: number): void { this.mg = mg; + if (!mg.hasPlayer(this.ownerId)) { + console.warn(`ConstructionExecution: owner ${this.ownerId} not found`); + this.active = false; + return; + } this.player = mg.player(this.ownerId); } diff --git a/src/core/execution/DefensePostExecution.ts b/src/core/execution/DefensePostExecution.ts index d298ebc1e..74001526b 100644 --- a/src/core/execution/DefensePostExecution.ts +++ b/src/core/execution/DefensePostExecution.ts @@ -23,6 +23,11 @@ export class DefensePostExecution implements Execution { init(mg: Game, ticks: number): void { this.mg = mg; + if (!mg.hasPlayer(this.ownerId)) { + console.warn(`DefensePostExectuion: owner ${this.ownerId} not found`); + this.active = false; + return; + } this.player = mg.player(this.ownerId); } diff --git a/src/core/execution/DonateExecution.ts b/src/core/execution/DonateExecution.ts index 0cbefa5da..70012b0e3 100644 --- a/src/core/execution/DonateExecution.ts +++ b/src/core/execution/DonateExecution.ts @@ -14,6 +14,17 @@ export class DonateExecution implements Execution { ) {} init(mg: Game, ticks: number): void { + if (!mg.hasPlayer(this.senderID)) { + console.warn(`DonateExecution: sender ${this.senderID} not found`); + this.active = false; + return; + } + if (!mg.hasPlayer(this.recipientID)) { + console.warn(`DonateExecution recipient ${this.recipientID} not found`); + this.active = false; + return; + } + this.sender = mg.player(this.senderID); this.recipient = mg.player(this.recipientID); if (this.troops == null) { diff --git a/src/core/execution/EmojiExecution.ts b/src/core/execution/EmojiExecution.ts index 4a7147469..1793ce7d2 100644 --- a/src/core/execution/EmojiExecution.ts +++ b/src/core/execution/EmojiExecution.ts @@ -22,6 +22,17 @@ export class EmojiExecution implements Execution { ) {} init(mg: Game, ticks: number): void { + if (!mg.hasPlayer(this.senderID)) { + console.warn(`EmojiExecution: sender ${this.senderID} not found`); + this.active = false; + return; + } + if (this.recipientID != AllPlayers && !mg.hasPlayer(this.recipientID)) { + console.warn(`EmojiExecution: recipient ${this.recipientID} not found`); + this.active = false; + return; + } + this.requestor = mg.player(this.senderID); this.recipient = this.recipientID == AllPlayers ? AllPlayers : mg.player(this.recipientID); diff --git a/src/core/execution/MIRVExecution.ts b/src/core/execution/MIRVExecution.ts index 430df2e59..f865eea75 100644 --- a/src/core/execution/MIRVExecution.ts +++ b/src/core/execution/MIRVExecution.ts @@ -43,6 +43,12 @@ export class MirvExecution implements Execution { ) {} init(mg: Game, ticks: number): void { + if (!this.mg.hasPlayer(this.senderID)) { + console.warn(`MIRVExecution: player ${this.senderID} not found`); + this.active = false; + return; + } + this.random = new PseudoRandom(mg.ticks() + simpleHash(this.senderID)); this.mg = mg; this.pathFinder = PathFinder.Mini(mg, 10_000, true); diff --git a/src/core/execution/MissileSiloExecution.ts b/src/core/execution/MissileSiloExecution.ts index dd3265262..3dc1a8714 100644 --- a/src/core/execution/MissileSiloExecution.ts +++ b/src/core/execution/MissileSiloExecution.ts @@ -22,6 +22,12 @@ export class MissileSiloExecution implements Execution { ) {} init(mg: Game, ticks: number): void { + if (!mg.hasPlayer(this._owner)) { + console.warn(`MissileSiloExecution: owner ${this._owner} not found`); + this.active = false; + return; + } + this.mg = mg; this.player = mg.player(this._owner); } diff --git a/src/core/execution/NukeExecution.ts b/src/core/execution/NukeExecution.ts index 38f80a933..2ce6200b5 100644 --- a/src/core/execution/NukeExecution.ts +++ b/src/core/execution/NukeExecution.ts @@ -33,6 +33,12 @@ export class NukeExecution implements Execution { ) {} init(mg: Game, ticks: number): void { + if (!mg.hasPlayer(this.senderID)) { + console.warn(`NukeExecution: sender ${this.senderID} not found`); + this.active = false; + return; + } + this.mg = mg; this.player = mg.player(this.senderID); this.random = new PseudoRandom(ticks); diff --git a/src/core/execution/PlayerExecution.ts b/src/core/execution/PlayerExecution.ts index 59a69386c..454bc03e4 100644 --- a/src/core/execution/PlayerExecution.ts +++ b/src/core/execution/PlayerExecution.ts @@ -28,6 +28,11 @@ export class PlayerExecution implements Execution { } init(mg: Game, ticks: number) { + if (!mg.hasPlayer(this.playerID)) { + console.warn(`PlayerExecution: player ${this.playerID} not found`); + this.active = false; + return; + } this.mg = mg; this.config = mg.config(); this.player = mg.player(this.playerID); diff --git a/src/core/execution/PortExecution.ts b/src/core/execution/PortExecution.ts index 0d0b99815..18053299a 100644 --- a/src/core/execution/PortExecution.ts +++ b/src/core/execution/PortExecution.ts @@ -31,6 +31,11 @@ export class PortExecution implements Execution { ) {} init(mg: Game, ticks: number): void { + if (!mg.hasPlayer(this._owner)) { + console.warn(`PortExecution: player ${this._owner} not found`); + this.active = false; + return; + } this.mg = mg; this.random = new PseudoRandom(mg.ticks()); } diff --git a/src/core/execution/SetTargetTroopRatioExecution.ts b/src/core/execution/SetTargetTroopRatioExecution.ts index 191e88f79..495c8ebe6 100644 --- a/src/core/execution/SetTargetTroopRatioExecution.ts +++ b/src/core/execution/SetTargetTroopRatioExecution.ts @@ -12,6 +12,11 @@ export class SetTargetTroopRatioExecution implements Execution { ) {} init(mg: Game, ticks: number): void { + if (!mg.hasPlayer(this.playerID)) { + console.warn( + `SetTargetTRoopRatioExecution: player ${this.playerID} not found`, + ); + } this.player = mg.player(this.playerID); } diff --git a/src/core/execution/SpawnExecution.ts b/src/core/execution/SpawnExecution.ts index 5ee3b0ebc..0c8cc5687 100644 --- a/src/core/execution/SpawnExecution.ts +++ b/src/core/execution/SpawnExecution.ts @@ -28,6 +28,7 @@ export class SpawnExecution implements Execution { this.active = false; if (!this.mg.inSpawnPhase()) { + this.active = false; return; } diff --git a/src/core/execution/TargetPlayerExecution.ts b/src/core/execution/TargetPlayerExecution.ts index f93989aee..ef738b774 100644 --- a/src/core/execution/TargetPlayerExecution.ts +++ b/src/core/execution/TargetPlayerExecution.ts @@ -12,6 +12,19 @@ export class TargetPlayerExecution implements Execution { ) {} init(mg: Game, ticks: number): void { + if (!mg.hasPlayer(this.requestorID)) { + console.warn( + `TargetPlayerExecution: requestor ${this.requestorID} not found`, + ); + this.active = false; + return; + } + if (!mg.hasPlayer(this.targetID)) { + console.warn(`TargetPlayerExecution: target ${this.targetID} not found`); + this.active = false; + return; + } + this.requestor = mg.player(this.requestorID); this.target = mg.player(this.targetID); } diff --git a/src/core/execution/TransportShipExecution.ts b/src/core/execution/TransportShipExecution.ts index fb4f7f4c0..7ec50437c 100644 --- a/src/core/execution/TransportShipExecution.ts +++ b/src/core/execution/TransportShipExecution.ts @@ -50,6 +50,19 @@ export class TransportShipExecution implements Execution { } init(mg: Game, ticks: number) { + if (!mg.hasPlayer(this.attackerID)) { + console.warn( + `TransportShipExecution: attacker ${this.attackerID} not found`, + ); + this.active = false; + return; + } + if (!mg.hasPlayer(this.targetID)) { + console.warn(`TransportShipExecution: target ${this.targetID} not found`); + this.active = false; + return; + } + this.lastMove = ticks; this.mg = mg; this.pathFinder = PathFinder.Mini(mg, 10_000, false, 2); diff --git a/src/core/execution/WarshipExecution.ts b/src/core/execution/WarshipExecution.ts index c84cc9823..09f806d8a 100644 --- a/src/core/execution/WarshipExecution.ts +++ b/src/core/execution/WarshipExecution.ts @@ -43,6 +43,11 @@ export class WarshipExecution implements Execution { ) {} init(mg: Game, ticks: number): void { + if (!mg.hasPlayer(this.playerID)) { + console.log(`WarshipExecution: player ${this.playerID} not found`); + this.active = false; + return; + } this.pathfinder = PathFinder.Mini(mg, 5000, false); this._owner = mg.player(this.playerID); this.mg = mg;