Add the Sokko TCG collectible card mini-game

Add the server-backed card game: Discord login, recharging pack openings,
album, trades, gifts, stardust shop, campaign codes and its administration,
stored in SQLite and disabled in production until configured.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Shinuwa 2026-11-05 17:47:35 +01:00
parent 243465720f
commit 5ce35cd7ba
193 changed files with 12159 additions and 28 deletions

View file

@ -0,0 +1,18 @@
// Rôle : sauvegarde ou vérifie la base Sokko TCG depuis les tâches d'exploitation.
import { resolve } from "node:path";
import { backupCardsDatabase, restoreCardsDatabase, verifyCardsDatabase } from "../services/cards/backup.js";
const [mode, source, destination] = process.argv.slice(2);
if (mode === "backup" && source && destination) {
await backupCardsDatabase(resolve(source), resolve(destination));
console.log(`Sokko TCG backup written to ${resolve(destination)}`);
} else if (mode === "verify" && source) {
verifyCardsDatabase(resolve(source));
console.log(`Sokko TCG backup verified: ${resolve(source)}`);
} else if (mode === "restore" && source && destination) {
restoreCardsDatabase(resolve(source), resolve(destination));
console.log(`Sokko TCG database restored to ${resolve(destination)}`);
} else {
console.error("Usage: node scripts/backup-nebula-cards.mjs backup <database> <backup> | verify <backup> | restore <backup> <database>");
process.exitCode = 1;
}

View file

@ -0,0 +1,50 @@
// Rôle : démarre le build avec une base Sokko TCG temporaire pour les parcours Playwright.
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
const directory = mkdtempSync(join(tmpdir(), "sokkog-cards-e2e-"));
process.env.NODE_ENV = "production";
process.env.PORT = process.env.PORT || "4180";
process.env.CARDS_ENABLED = "true";
process.env.CARDS_DEV_AUTH = "true";
process.env.CARDS_DB_PATH = join(directory, "cards.sqlite");
process.env.CARDS_PUBLIC_ORIGIN = `http://127.0.0.1:${process.env.PORT}`;
// Rend le bouton Discord visible ; les parcours ne le suivent jamais jusqu'à Discord.
process.env.DISCORD_CLIENT_ID = "e2e-client";
process.env.DISCORD_CLIENT_SECRET = "e2e-secret";
// Un second joueur, avec des doublons et une session, pour les parcours d'échange et de don à deux comptes.
const [{ CardsDatabase }, { CardsService }, { loadCardsCatalog }] = await Promise.all([import("../services/cards/database.js"), import("../services/cards/service.js"), import("../services/cards/catalog.js")]);
const seedDatabase = new CardsDatabase(process.env.CARDS_DB_PATH);
const seedService = new CardsService({ database: seedDatabase, catalog: loadCardsCatalog(join(import.meta.dirname, "..", "website", "public", "data", "cards", "catalog.json")) });
const partner = seedService.upsertPlayer({ discordId: "e2e-partner", displayName: "Partenaire E2E" });
for (const editionId of ["aurora-wolf-standard", "aurora-wolf-standard", "aurora-wolf-standard", "aurora-wolf-standard", "starvoid-dragon-standard", "starvoid-dragon-standard", "starvoid-dragon-standard"]) seedService.addCard(partner.id, editionId);
seedDatabase.db.prepare("UPDATE players SET stardust = 500 WHERE id = ?").run(partner.id);
writeFileSync(join(tmpdir(), "sokkog-cards-e2e-partner.json"), JSON.stringify({ token: seedService.createSession(partner.id).token }));
// Une base neuve n'a aucune variation mythique : les parcours de jeu et d'administration en ont besoin.
const insertVariation = seedDatabase.db.prepare("INSERT INTO mythic_variations(edition_id, card_id, finish_id, status, updated_at, updated_by) VALUES (?, ?, ?, 'active', 0, NULL)");
for (const cardId of ["starvoid-dragon", "crimson-moon-kitsune", "milky-way-panda", "constellation-magpie", "solar-dawn-capybara", "aurora-wolf"]) {
for (const finishId of ["spectral-prism-aurora", "spectral-prism-cosmic"]) insertVariation.run(`${cardId}-${finishId}`, cardId, finishId);
}
insertVariation.run("mythic-card-pull-spectral-prism-solar", "mythic-card-pull", "spectral-prism-solar");
seedDatabase.close();
const { startServer } = await import("../server.mjs");
const draws = [0.999, 0, 0.999, 0.999, 0.999, 0];
let drawIndex = 0;
// Tous les parcours et leurs deux comptes partagent la même adresse IP : la limite par minute les ferait échouer au hasard.
const server = startServer({ cardsApiOptions: { apiRateLimit: 100_000, random: (max) => Math.min(max - 1, Math.floor(draws[drawIndex++ % draws.length] * max)) } });
let stopping = false;
function stop() {
if (stopping) return;
stopping = true;
server.close(() => {
rmSync(directory, { recursive: true, force: true });
process.exit(0);
});
}
process.on("SIGTERM", stop);
process.on("SIGINT", stop);