diff --git a/src/client/graphics/layers/TeamStats.ts b/src/client/graphics/layers/TeamStats.ts index ba8e9dbe759..a8503c22984 100644 --- a/src/client/graphics/layers/TeamStats.ts +++ b/src/client/graphics/layers/TeamStats.ts @@ -221,5 +221,6 @@ export class TeamStats extends LitElement implements Layer { function formatPercentage(value: number): string { const perc = value * 100; if (Number.isNaN(perc)) return "0%"; + if (perc === 100) return "100%"; return perc.toPrecision(2) + "%"; } diff --git a/src/core/execution/FakeHumanExecution.ts b/src/core/execution/FakeHumanExecution.ts index edeab741763..3b8a7e94d81 100644 --- a/src/core/execution/FakeHumanExecution.ts +++ b/src/core/execution/FakeHumanExecution.ts @@ -17,6 +17,7 @@ import { TileRef, euclDistFN } from "../game/GameMap"; import { PseudoRandom } from "../PseudoRandom"; import { GameID } from "../Schemas"; import { boundingBoxTiles, calculateBoundingBox, simpleHash } from "../Util"; +import { AllianceRequestExecution } from "./alliance/AllianceRequestExecution"; import { ConstructionExecution } from "./ConstructionExecution"; import { EmojiExecution } from "./EmojiExecution"; import { structureSpawnTileValue } from "./nation/structureSpawnTileValue"; @@ -221,7 +222,9 @@ export class FakeHumanExecution implements Execution { if (this.random.chance(20)) { const toAlly = this.random.randElement(enemies); if (this.player.canSendAllianceRequest(toAlly)) { - this.player.createAllianceRequest(toAlly); + this.mg.addExecution( + new AllianceRequestExecution(this.player, toAlly.id()), + ); } } diff --git a/src/core/game/PlayerImpl.ts b/src/core/game/PlayerImpl.ts index d9ba8ba7c72..75a3afcf9f4 100644 --- a/src/core/game/PlayerImpl.ts +++ b/src/core/game/PlayerImpl.ts @@ -390,6 +390,13 @@ export class PlayerImpl implements Player { if (other === this) { return false; } + if (this.isDisconnected() || other.isDisconnected()) { + // Disconnected players are marked as not-friendly even if they are allies, + // so we need to return early if either player is disconnected. + // Otherise we could end up sending an alliance request to someone + // we are already allied with. + return false; + } if (this.isFriendly(other) || !this.isAlive()) { return false; } diff --git a/src/server/Privilege.ts b/src/server/Privilege.ts index 402b4c3c7bc..fece2849e0c 100644 --- a/src/server/Privilege.ts +++ b/src/server/Privilege.ts @@ -1,6 +1,7 @@ import { Cosmetics } from "../core/CosmeticSchemas"; import { decodePatternData } from "../core/PatternDecoder"; import { + FlagSchema, PlayerColor, PlayerCosmeticRefs, PlayerCosmetics, @@ -42,10 +43,14 @@ export class PrivilegeCheckerImpl implements PrivilegeChecker { } } if (refs.flag) { - cosmetics.flag = cosmetics.flag = refs.flag.replace( - /[^a-z0-9-_ ()]/gi, - "", - ); + const result = FlagSchema.safeParse(refs.flag); + if (!result.success) { + return { + type: "forbidden", + reason: "invalid flag: " + result.error.message, + }; + } + cosmetics.flag = result.data; } return { type: "allowed", cosmetics };