diff --git a/src/client/components/leaderboard/LeaderboardPlayerList.ts b/src/client/components/leaderboard/LeaderboardPlayerList.ts index 1ed4822cb..04beae8ea 100644 --- a/src/client/components/leaderboard/LeaderboardPlayerList.ts +++ b/src/client/components/leaderboard/LeaderboardPlayerList.ts @@ -2,6 +2,7 @@ import { virtualize } from "@lit-labs/virtualizer/virtualize.js"; import { html, LitElement } from "lit"; import { customElement, query, state } from "lit/decorators.js"; import { PlayerLeaderboardEntry } from "../../../core/ApiSchemas"; +import { RankedType } from "../../../core/game/Game"; import { fetchPlayerLeaderboard, getUserMe } from "../../Api"; import { translateText } from "../../Utils"; @@ -68,19 +69,19 @@ export class LeaderboardPlayerList extends LitElement { return; } - const nextPlayers: PlayerLeaderboardEntry[] = result["1v1"].map( - (entry) => ({ - rank: entry.rank, - playerId: entry.public_id, - username: entry.username, - clanTag: entry.clanTag ?? undefined, - elo: entry.elo, - games: entry.total, - wins: entry.wins, - losses: entry.losses, - winRate: entry.total > 0 ? entry.wins / entry.total : 0, - }), - ); + const nextPlayers: PlayerLeaderboardEntry[] = result[ + RankedType.OneVOne + ].map((entry) => ({ + rank: entry.rank, + playerId: entry.public_id, + username: entry.username, + clanTag: entry.clanTag ?? undefined, + elo: entry.elo, + games: entry.total, + wins: entry.wins, + losses: entry.losses, + winRate: entry.total > 0 ? entry.wins / entry.total : 0, + })); const receivedCount = nextPlayers.length; if (reset) { diff --git a/src/core/ApiSchemas.ts b/src/core/ApiSchemas.ts index 0e7bd5639..c3ab186e7 100644 --- a/src/core/ApiSchemas.ts +++ b/src/core/ApiSchemas.ts @@ -1,7 +1,13 @@ import { z } from "zod"; import { base64urlToUuid } from "./Base64"; import { BigIntStringSchema, PlayerStatsSchema } from "./StatsSchemas"; -import { Difficulty, GameMapType, GameMode, GameType } from "./game/Game"; +import { + Difficulty, + GameMapType, + GameMode, + GameType, + RankedType, +} from "./game/Game"; export const RefreshResponseSchema = z.object({ token: z.string(), @@ -176,7 +182,7 @@ export type RankedLeaderboardEntry = z.infer< >; export const RankedLeaderboardResponseSchema = z.object({ - "1v1": RankedLeaderboardEntrySchema.array(), + [RankedType.OneVOne]: RankedLeaderboardEntrySchema.array(), }); export type RankedLeaderboardResponse = z.infer< typeof RankedLeaderboardResponseSchema diff --git a/src/core/Util.ts b/src/core/Util.ts index a79dda1a8..1c8a07088 100644 --- a/src/core/Util.ts +++ b/src/core/Util.ts @@ -1,6 +1,6 @@ import DOMPurify from "dompurify"; import { customAlphabet } from "nanoid"; -import { Cell, Unit } from "./game/Game"; +import { Cell, PlayerType, Unit } from "./game/Game"; import { GameMap, TileRef } from "./game/GameMap"; import { GameConfig, @@ -291,10 +291,10 @@ export function withinInt(num: bigint, min: bigint, max: bigint): bigint { export function createRandomName( name: string, - playerType: string, + playerType: PlayerType, ): string | null { let randomName: string | null = null; - if (playerType === "HUMAN") { + if (playerType === PlayerType.Human) { const hash = simpleHash(name); const prefixIndex = hash % BOT_NAME_PREFIXES.length; const suffixIndex = diff --git a/src/server/Worker.ts b/src/server/Worker.ts index f20b8986b..f3a5455e8 100644 --- a/src/server/Worker.ts +++ b/src/server/Worker.ts @@ -185,7 +185,7 @@ export async function startWorker() { const game = gm.createGame(id, gc, creatorPersistentID); log.info( - `Worker ${workerId}: IP ${ipAnonymize(clientIP)} creating ${game.isPublic() ? "Public" : "Private"}${gc?.gameMode ? ` ${gc.gameMode}` : ""} game with id ${id}${creatorPersistentID ? `, creator: ${creatorPersistentID.substring(0, 8)}...` : ""}`, + `Worker ${workerId}: IP ${ipAnonymize(clientIP)} creating ${game.isPublic() ? GameType.Public : GameType.Private}${gc?.gameMode ? ` ${gc.gameMode}` : ""} game with id ${id}${creatorPersistentID ? `, creator: ${creatorPersistentID.substring(0, 8)}...` : ""}`, ); res.json(game.gameInfo()); });