From 9fa3691c5c985f79512841bd28e143093607e429 Mon Sep 17 00:00:00 2001 From: Evan Date: Thu, 3 Apr 2025 19:31:42 -0700 Subject: [PATCH] bugfix: SpawnExecution couldn't find existing player because Game.Players() only returns alive players. This caused SpawnExecution to respawn each human player. --- src/core/GameRunner.ts | 6 +++++- src/core/execution/ExecutionManager.ts | 14 ++------------ src/core/execution/SpawnExecution.ts | 6 ++---- src/core/game/PlayerImpl.ts | 2 +- 4 files changed, 10 insertions(+), 18 deletions(-) diff --git a/src/core/GameRunner.ts b/src/core/GameRunner.ts index cc7e24b2a..13d8fcc10 100644 --- a/src/core/GameRunner.ts +++ b/src/core/GameRunner.ts @@ -25,6 +25,8 @@ import { } from "./game/GameUpdates"; import { loadTerrainMap as loadGameMap } from "./game/TerrainMapLoader"; import { ClientID, GameStartInfo, Turn } from "./Schemas"; +import { sanitize } from "./Util"; +import { fixProfaneUsername } from "./validations/username"; export async function createGameRunner( gameStart: GameStartInfo, @@ -38,7 +40,9 @@ export async function createGameRunner( (p) => new PlayerInfo( p.flag, - p.username, + p.clientID == clientID + ? sanitize(p.username) + : fixProfaneUsername(sanitize(p.username)), PlayerType.Human, p.clientID, p.playerID, diff --git a/src/core/execution/ExecutionManager.ts b/src/core/execution/ExecutionManager.ts index ad6e95d4d..968455cc1 100644 --- a/src/core/execution/ExecutionManager.ts +++ b/src/core/execution/ExecutionManager.ts @@ -1,8 +1,7 @@ import { Execution, Game, PlayerInfo, PlayerType } from "../game/Game"; import { PseudoRandom } from "../PseudoRandom"; import { ClientID, GameID, Intent, Turn } from "../Schemas"; -import { sanitize, simpleHash } from "../Util"; -import { fixProfaneUsername } from "../validations/username"; +import { simpleHash } from "../Util"; import { AllianceRequestExecution } from "./alliance/AllianceRequestExecution"; import { AllianceRequestReplyExecution } from "./alliance/AllianceRequestReplyExecution"; import { BreakAllianceExecution } from "./alliance/BreakAllianceExecution"; @@ -62,16 +61,7 @@ export class Executor { return new MoveWarshipExecution(intent.unitId, intent.tile); case "spawn": return new SpawnExecution( - new PlayerInfo( - intent.flag, - // Players see their original name, others see a sanitized version - intent.clientID == this.clientID - ? sanitize(intent.name) - : fixProfaneUsername(sanitize(intent.name)), - PlayerType.Human, - intent.clientID, - playerID, - ), + player.info(), this.mg.ref(intent.x, intent.y), ); case "boat": diff --git a/src/core/execution/SpawnExecution.ts b/src/core/execution/SpawnExecution.ts index d315a0a53..27b036eb1 100644 --- a/src/core/execution/SpawnExecution.ts +++ b/src/core/execution/SpawnExecution.ts @@ -25,10 +25,8 @@ export class SpawnExecution implements Execution { return; } - const existing = this.mg - .players() - .find((p) => p.id() == this.playerInfo.id); - if (existing) { + if (this.mg.hasPlayer(this.playerInfo.id)) { + const existing = this.mg.player(this.playerInfo.id); existing.tiles().forEach((t) => existing.relinquish(t)); getSpawnTiles(this.mg, this.tile).forEach((t) => { existing.conquer(t); diff --git a/src/core/game/PlayerImpl.ts b/src/core/game/PlayerImpl.ts index 9606e205b..7bdf19edc 100644 --- a/src/core/game/PlayerImpl.ts +++ b/src/core/game/PlayerImpl.ts @@ -99,7 +99,7 @@ export class PlayerImpl implements Player { private _smallID: number, private readonly playerInfo: PlayerInfo, startTroops: number, - private _team: Team | null, + private readonly _team: Team | null, ) { this._flag = playerInfo.flag; this._name = sanitizeUsername(playerInfo.name);