mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-22 10:10:27 +00:00
fix bad tile crash (#1237)
## Description: Sending invalid coords can cause game to crash. Make sure to validate tile ref. ## 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 - [x] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced - [x] I understand that submitting code with bugs that could have been caught through manual testing blocks releases and new features for all contributors ## Please put your Discord username so you can be contacted if a bug or regression is found: evan
This commit is contained in:
@@ -688,6 +688,9 @@ export class GameImpl implements Game {
|
||||
ref(x: number, y: number): TileRef {
|
||||
return this._map.ref(x, y);
|
||||
}
|
||||
isValidRef(ref: TileRef): boolean {
|
||||
return this._map.isValidRef(ref);
|
||||
}
|
||||
x(ref: TileRef): number {
|
||||
return this._map.x(ref);
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ export type TileUpdate = bigint;
|
||||
|
||||
export interface GameMap {
|
||||
ref(x: number, y: number): TileRef;
|
||||
|
||||
isValidRef(ref: TileRef): boolean;
|
||||
x(ref: TileRef): number;
|
||||
y(ref: TileRef): number;
|
||||
cell(ref: TileRef): Cell;
|
||||
@@ -117,6 +117,10 @@ export class GameMapImpl implements GameMap {
|
||||
return this.yToRef[y] + x;
|
||||
}
|
||||
|
||||
isValidRef(ref: TileRef): boolean {
|
||||
return this.isValidCoord(this.x(ref), this.y(ref));
|
||||
}
|
||||
|
||||
x(ref: TileRef): number {
|
||||
return this.refToX[ref];
|
||||
}
|
||||
|
||||
@@ -496,6 +496,9 @@ export class GameView implements GameMap {
|
||||
ref(x: number, y: number): TileRef {
|
||||
return this._map.ref(x, y);
|
||||
}
|
||||
isValidRef(ref: TileRef): boolean {
|
||||
return this._map.isValidRef(ref);
|
||||
}
|
||||
x(ref: TileRef): number {
|
||||
return this._map.x(ref);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user