// 가짜 Riot 서버 (발로란트 로컬 API · glz · pd, 롤 게임 클라이언트 API · LCU). 응답 구조는 실제 API 와 같게 맞췄다. // 테스트와 M0 시연용. 실제 게임 PC 검증은 진단 화면(M0)으로 한다. import { execFileSync } from 'node:child_process'; import fs from 'node:fs'; import https from 'node:https'; import path from 'node:path'; import { makeValDetails, SELF, ASCENT } from '../fixtures/make-val-details.ts'; export interface MockState { valState: 'MENUS' | 'PREGAME' | 'INGAME'; ally: number; enemy: number; valMessages: any[]; valMatchId: string; valStart: number; lolLive: any | null; lolPhase: string; lolGameId: number; lolHistoryReady: boolean; lolStart: number; } export async function startMockRiot(dir: string) { fs.mkdirSync(dir, { recursive: true }); const key = path.join(dir, 'key.pem'); const cert = path.join(dir, 'cert.pem'); if (!fs.existsSync(cert)) execFileSync('openssl', ['req', '-x509', '-newkey', 'rsa:2048', '-nodes', '-keyout', key, '-out', cert, '-days', '2', '-subj', '/CN=127.0.0.1'], { stdio: 'ignore' }); const st: MockState = { valState: 'MENUS', ally: 0, enemy: 0, valMessages: [], valMatchId: 'm-0001', valStart: 0, lolLive: null, lolPhase: 'None', lolGameId: 7001, lolHistoryReady: false, lolStart: 0, }; const password = 'pw-test'; const presence = () => { const priv = { isValid: true, sessionLoopState: st.valState, matchMap: ASCENT, partyOwnerMatchScoreAllyTeam: st.ally, partyOwnerMatchScoreEnemyTeam: st.enemy, provisioningFlow: 'Matchmaking', queueId: 'competitive', }; return Buffer.from(JSON.stringify(priv)).toString('base64'); }; const routes: [RegExp, (m: RegExpMatchArray, auth: string) => [number, any]][] = [ // ---- Riot Client local [/^\/entitlements\/v1\/token$/, () => [200, { accessToken: 'acc-token', token: 'ent-token', subject: SELF, issuer: 'x' }]], [ /^\/product-session\/v1\/external-sessions$/, () => [200, { 'host_app': { productId: 'valorant', version: 'release-11.08-shipping-1-3765', launchConfiguration: { arguments: ['-ares-deployment=kr', '-config-endpoint=https://shared.kr.a.pvp.net'] } } }], ], [/^\/chat\/v4\/presences$/, () => [200, { presences: [{ puuid: SELF, product: 'valorant', private: presence() }] }]], [/^\/chat\/v6\/messages$/, () => [200, { messages: st.valMessages }]], [/^\/chat\/v1\/session$/, () => [200, { game_name: '하늘', game_tag: 'KR1', puuid: SELF }]], // ---- glz [/^\/core-game\/v1\/players\/(.+)$/, () => (st.valState === 'INGAME' ? [200, { Subject: SELF, MatchID: st.valMatchId }] : [404, { errorCode: 'RESOURCE_NOT_FOUND' }])], [ /^\/core-game\/v1\/matches\/(.+)$/, () => [200, { MatchID: st.valMatchId, MapID: ASCENT, Players: [{ Subject: SELF, TeamID: 'Blue', CharacterID: 'add6443a-41bd-e414-f6ad-e58d267f4e95' }] }], ], // ---- pd [/^\/match-details\/v1\/matches\/(.+)$/, (_m, auth) => (auth.startsWith('Bearer ') && st.valState !== 'INGAME' ? [200, makeValDetails(st.valStart)] : [404, {}])], // ---- LoL Live Client Data [/^\/liveclientdata\/allgamedata$/, () => (st.lolLive ? [200, st.lolLive] : [404, {}])], // ---- LCU [/^\/lol-gameflow\/v1\/gameflow-phase$/, () => [200, st.lolPhase]], [/^\/lol-gameflow\/v1\/session$/, () => [200, { phase: st.lolPhase, gameData: { gameId: st.lolGameId, queue: { description: '솔로 랭크', id: 420 } } }]], [/^\/lol-summoner\/v1\/current-summoner$/, () => [200, { puuid: 'lol-self', gameName: '하늘', tagLine: 'KR1' }]], [/^\/lol-chat\/v1\/conversations$/, () => [200, st.lolPhase === 'ChampSelect' ? [{ id: 'cs1@champ-select.kr', type: 'championSelect' }] : []]], [/^\/lol-chat\/v1\/conversations\/(.+)\/messages$/, () => [200, [{ id: 'msg1', body: '정글 갱 갈게요', fromSummonerId: 11, timestamp: new Date(Date.now() - 5000).toISOString(), type: 'groupchat' }]]], [/^\/lol-summoner\/v1\/summoners\/(\d+)$/, () => [200, { gameName: '민수' }]], [/^\/lol-match-history\/v1\/games\/(\d+)$/, () => (st.lolHistoryReady ? [200, lolHistory()] : [404, {}])], [/^\/lol-match-history\/v1\/game-timelines\/(\d+)$/, () => (st.lolHistoryReady ? [200, lolTimeline()] : [404, {}])], ]; const server = https.createServer({ key: fs.readFileSync(key), cert: fs.readFileSync(cert) }, (req, res) => { const url = new URL(req.url || '/', 'https://x'); for (const [re, fn] of routes) { const m = url.pathname.match(re); if (!m) continue; const [code, body] = fn(m, String(req.headers.authorization || '')); res.writeHead(code, { 'content-type': 'application/json' }); res.end(JSON.stringify(body)); return; } res.writeHead(404); res.end('{}'); }); await new Promise((r) => server.listen(0, '127.0.0.1', () => r())); const port = (server.address() as any).port as number; const lockfile = path.join(dir, 'lockfile'); fs.writeFileSync(lockfile, `Riot Client:1234:${port}:${password}:https`); return { st, port, lockfile, base: `https://127.0.0.1:${port}`, close: () => new Promise((r) => server.close(() => r())) }; } export function lolLiveData(gameTime: number, events: any[]) { const player = (name: string, raw: string, ko: string, team: string, k: number) => ({ riotId: `${name}#KR1`, riotIdGameName: name, riotIdTagLine: 'KR1', summonerName: name, rawChampionName: `game_character_displayname_${raw}`, championName: ko, team, level: 9, scores: { kills: k, deaths: 1, assists: 2, creepScore: 80 }, items: [{ itemID: 3031, displayName: '무한의 대검', count: 1 }], }); return { activePlayer: { riotId: '하늘#KR1', summonerName: '하늘', currentGold: 500 }, allPlayers: [player('하늘', 'Ahri', '아리', 'ORDER', 3), player('민수', 'LeeSin', '리 신', 'ORDER', 1), player('적1', 'Garen', '가렌', 'CHAOS', 2)], events: { Events: events }, gameData: { gameMode: 'CLASSIC', gameTime, mapName: 'Map11', mapNumber: 11 }, }; } function lolHistory() { return { gameId: 7001, gameDuration: 1500, queueId: 420, participants: [ { participantId: 1, championId: 103, teamId: 100, stats: { kills: 5, deaths: 2, assists: 7, totalMinionsKilled: 180, neutralMinionsKilled: 10, goldEarned: 11000, item0: 3031, win: true, champLevel: 16 } }, { participantId: 2, championId: 64, teamId: 100, stats: { kills: 3, deaths: 4, assists: 9, totalMinionsKilled: 30, neutralMinionsKilled: 140, goldEarned: 9000, win: true } }, { participantId: 6, championId: 86, teamId: 200, stats: { kills: 4, deaths: 6, assists: 2, totalMinionsKilled: 170, neutralMinionsKilled: 0, goldEarned: 8500, win: false } }, ], participantIdentities: [ { participantId: 1, player: { puuid: 'lol-self', gameName: '하늘', tagLine: 'KR1' } }, { participantId: 2, player: { puuid: 'lol-2', gameName: '민수', tagLine: 'KR1' } }, { participantId: 6, player: { puuid: 'lol-6', gameName: '적1', tagLine: 'KR9' } }, ], teams: [ { teamId: 100, win: 'Win' }, { teamId: 200, win: 'Fail' }, ], }; } function lolTimeline() { return { frames: [ { timestamp: 0, participantFrames: { '1': { totalGold: 500 }, '2': { totalGold: 500 }, '6': { totalGold: 500 } }, events: [] }, { timestamp: 60000, participantFrames: { '1': { totalGold: 1500 }, '2': { totalGold: 1200 }, '6': { totalGold: 1000 } }, events: [ { type: 'CHAMPION_KILL', timestamp: 75000, killerId: 1, victimId: 6, assistingParticipantIds: [2], position: { x: 7000, y: 7200 } }, { type: 'ELITE_MONSTER_KILL', timestamp: 90000, killerId: 2, monsterType: 'DRAGON', monsterSubType: 'FIRE_DRAGON', position: { x: 9866, y: 4414 } }, { type: 'BUILDING_KILL', timestamp: 95000, killerId: 1, teamId: 200, buildingType: 'TOWER_BUILDING', position: { x: 8955, y: 8510 } }, ], }, ], }; }