Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/client/graphics/layers/TeamStats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) + "%";
}
5 changes: 4 additions & 1 deletion src/core/execution/FakeHumanExecution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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()),
);
}
}

Expand Down
7 changes: 7 additions & 0 deletions src/core/game/PlayerImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
13 changes: 9 additions & 4 deletions src/server/Privilege.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Cosmetics } from "../core/CosmeticSchemas";
import { decodePatternData } from "../core/PatternDecoder";
import {
FlagSchema,
PlayerColor,
PlayerCosmeticRefs,
PlayerCosmetics,
Expand Down Expand Up @@ -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 };
Expand Down