// DEMO-ADAPTER: Es wird KEIN echter CS2-Server gestartet. // Er simuliert nur Startdauer und Konfiguration, damit der Ablauf ohne Hosting getestet werden kann. // Das Flag simulated=true sorgt dafür, dass das Frontend den Server ausdrücklich als Simulation kennzeichnet. import { backupPrefix, parseBackupFiles } from '../rounds.js'; const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms)); export class DemoServerAdapter { constructor({ startSeconds = 20, failFirstConfigure = false } = {}) { this.name = 'demo'; this.simulated = true; this.startMs = startSeconds * 1000; this.failFirstConfigure = failFirstConfigure; this.configureCalls = new Map(); } async start({ matchId }) { return { handle: { demo: true, matchId, startedAt: Date.now() }, host: 'demo.invalid', port: 27015, tvPort: 27020, }; } async status(handle) { if (handle.stopped) return { state: 'stopped', message: 'Simulation beendet' }; const elapsed = Date.now() - handle.startedAt; if (elapsed < this.startMs) { return { state: 'starting', message: `Simulierter Start (${Math.ceil((this.startMs - elapsed) / 1000)} s)` }; } return { state: 'running', message: 'Simulation – kein echter Server', playerCount: null }; } async configure(handle, plan) { await sleep(1500); const calls = (this.configureCalls.get(handle.matchId) ?? 0) + 1; this.configureCalls.set(handle.matchId, calls); if (this.failFirstConfigure && calls === 1) { throw new Error('Simulierter Konfigurationsfehler (DEMO_FAIL_FIRST_CONFIGURE) – bitte erneut versuchen'); } handle.map = plan.map; } // Simulierte Sicherungen: eine Datei je Runde der aktuellen Map, damit die Oberfläche testbar ist async listRoundBackups(handle, matchId, map = 'de_demo') { const files = [1, 2, 3].map((r) => `${backupPrefix(matchId)}_01_01_${map}_round${r}_score_${r}_0.txt`); return parseBackupFiles(files.join('\n'), matchId); } async loadRoundBackup() {} async sendCommands(handle, commands) { return commands.map(() => '(Demo – nicht ausgeführt)'); } async stop(handle) { handle.stopped = true; } }