mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 11:40:42 +00:00
validate all intent input
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ export class SpawnExecution implements Execution {
|
||||
this.active = false;
|
||||
|
||||
if (!this.mg.inSpawnPhase()) {
|
||||
this.active = false;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user