mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 15:10:43 +00:00
bugfix: SpawnExecution couldn't find existing player because Game.Players() only returns alive players. This caused SpawnExecution to respawn each human player.
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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":
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user