Skip to content
Merged
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
6 changes: 6 additions & 0 deletions src/core/Util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
GameRecord,
PartialGameRecord,
PlayerRecord,
Tribe,
Turn,
Winner,
} from "./Schemas";
Expand Down Expand Up @@ -264,6 +265,10 @@ export function createPartialGameRecord(
lobbyCreatedAt?: number,
// Time the lobby became visible to players (ms).
visibleAt?: number,
// Purchased bot tribe names in use this game (public games only). Infra
// ingest reads them from the record for owner appearance stats, and
// replays rebuild GameStartInfo from the record so the same names spawn.
tribes?: Tribe[],
): PartialGameRecord {
const duration = Math.floor((end - start) / 1000);
const num_turns = allTurns.length;
Expand Down Expand Up @@ -291,6 +296,7 @@ export function createPartialGameRecord(
duration,
num_turns,
winner,
tribes,
},
version: "v0.0.2",
turns,
Expand Down
1 change: 1 addition & 0 deletions src/server/GameServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1804,6 +1804,7 @@ export class GameServer {
this.winner?.winner,
this.createdAt,
this.visibleAt,
this.gameStartInfo.tribes,
),
),
);
Expand Down
41 changes: 41 additions & 0 deletions tests/server/ArchivePlayerRecord.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,45 @@ describe("archiveGame player records", () => {
isLobbyCreator: false,
});
});

it("carries custom tribe names into the archived record for infra ingest and replays", () => {
const game = new GameServer("test-game", mockLogger, Date.now(), {
gameType: GameType.Public,
} as any);

(game as any).gameStartInfo = {
gameID: "test-game",
lobbyCreatedAt: 0,
config: { gameType: GameType.Public },
players: [],
tribes: [{ name: "Dragon Riders" }, { name: "Night Wolves" }],
};

(game as any).archiveGame();

expect(archive).toHaveBeenCalledTimes(1);
const record = vi.mocked(archive).mock.calls[0][0] as any;
expect(record.info.tribes).toEqual([
{ name: "Dragon Riders" },
{ name: "Night Wolves" },
]);
});

it("omits tribes from the archived record when none were fetched", () => {
const game = new GameServer("test-game", mockLogger, Date.now(), {
gameType: GameType.Public,
} as any);

(game as any).gameStartInfo = {
gameID: "test-game",
lobbyCreatedAt: 0,
config: { gameType: GameType.Public },
players: [],
};

(game as any).archiveGame();

const record = vi.mocked(archive).mock.calls[0][0] as any;
expect(record.info.tribes).toBeUndefined();
});
});
Loading