봇 중계 권한 (앱 유저의 디스코드 아이디 기준) - 서버 목록 · watch: 그 유저가 가입한 서버만. 아니면 watch_denied (명령 등록 · 멤버 목록도 거절) - 채널 · 음성 상태: 그 유저가 볼 수 있는(ViewChannel) 채널만. 볼 수 없는 채널로 옮기면 "나감"으로 가린다 - 음성 참여 op 4: 그 유저가 들어갈 수 있는(ViewChannel + Connect) 음성채널만 - /녹음시작 은 그 음성채널에 들어갈 수 있는 유저의 PC 로만, 다른 PC 로 가는 명령에는 볼 수 없는 채널 이름을 넣지 않는다 인증서 - 사이트 서버 https/wss(로그인 · 기기 등록 · 봇 중계 · 기기 중계)는 Node 내장 Mozilla 루트만 믿고 검증을 항상 켠다 (core/util/secure-http.ts) NODE_TLS_REJECT_UNAUTHORIZED=0 · 시스템 인증서 저장소의 가짜 루트로 엿볼 수 없다 - 시작할 때 NODE_TLS_REJECT_UNAUTHORIZED 를 지운다 (Electron main · 헤드리스 코어). fuses 로 막히지 않는 변수 - win smoke: 내장 루트만으로 실서버 https 가 검증되는지 확인 (siteTls) 테스트: 봇 중계 권한 1건(가입하지 않은 서버 · 비공개 채널 · 연결 권한 없는 채널 · 명령), 자체 서명 서버 + 검증 끄기 변수 1건(대조군 포함) login-e2e 친구 계정을 실제 F&L 멤버(테스트봇)로 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
317 lines
9.5 KiB
TypeScript
317 lines
9.5 KiB
TypeScript
// 앱 코어 · 사이트 서버 · 사이트 프런트엔드가 같이 쓰는 타입. docs/dev/ARCHITECTURE.md 4~6장.
|
|
|
|
export type GameType = 'valorant' | 'lol';
|
|
|
|
export interface TimeLabel {
|
|
/** 발로란트 "R7 · 0:42" / 롤 "21:14" / 경기 밖 "21:08:44" */
|
|
primary: string;
|
|
/** 발로란트 경기 경과 시간 "12:18" */
|
|
secondary?: string;
|
|
/** 현실 시각 (unix ms) */
|
|
real: number;
|
|
}
|
|
|
|
export interface Word {
|
|
w: string;
|
|
/** 발화 시작 기준 초 */
|
|
s: number;
|
|
e: number;
|
|
p?: number;
|
|
}
|
|
|
|
export interface User {
|
|
id: string;
|
|
name: string;
|
|
color: string;
|
|
avatar: string | null;
|
|
excluded: boolean;
|
|
riot: { puuid: string; riotId: string }[];
|
|
}
|
|
|
|
export type UtteranceStatus = 'pending' | 'realtime' | 'precise' | 'failed';
|
|
|
|
export interface UtteranceItem {
|
|
kind: 'utterance';
|
|
id: string;
|
|
ts: number;
|
|
endTs: number;
|
|
userId: string;
|
|
text: string | null;
|
|
words: Word[];
|
|
noise: boolean;
|
|
status: UtteranceStatus;
|
|
corrected: boolean;
|
|
confidence: number | null;
|
|
model: string | null;
|
|
audio: { url: string; durationMs: number; gainDb: number } | null;
|
|
game: { type: GameType; matchId: string; round?: number } | null;
|
|
time: TimeLabel;
|
|
}
|
|
|
|
export type EventType =
|
|
| 'kill'
|
|
| 'chat'
|
|
| 'object'
|
|
| 'spike'
|
|
| 'round_end'
|
|
| 'match_start'
|
|
| 'match_end'
|
|
| 'multikill'
|
|
| 'ace';
|
|
|
|
export interface PlayerRef {
|
|
puuid?: string;
|
|
name: string;
|
|
team?: string;
|
|
/** 발로란트 요원 / 롤 챔피언 */
|
|
character?: { id: string; name: string; icon: string | null };
|
|
userId?: string;
|
|
}
|
|
|
|
export interface KillData {
|
|
killer: PlayerRef | null;
|
|
victim: PlayerRef;
|
|
assists: PlayerRef[];
|
|
weapon: { id: string; name: string; icon: string | null } | null;
|
|
headshot?: boolean;
|
|
location?: { x: number; y: number } | null;
|
|
ally?: boolean;
|
|
}
|
|
export interface ChatData {
|
|
sender: PlayerRef;
|
|
channel: 'team' | 'all' | 'party' | 'system';
|
|
text: string;
|
|
source: 'api' | 'ocr' | 'lcu' | 'log';
|
|
}
|
|
export interface ObjectData {
|
|
object: 'dragon' | 'baron' | 'herald' | 'grub' | 'tower' | 'inhibitor' | 'atakhan';
|
|
subtype?: string;
|
|
team?: string;
|
|
killer?: PlayerRef | null;
|
|
ally?: boolean;
|
|
}
|
|
export interface RoundEndData {
|
|
round: number;
|
|
win: boolean;
|
|
result: string;
|
|
score: { ally: number; enemy: number };
|
|
}
|
|
|
|
export interface EventItem {
|
|
kind: 'event';
|
|
id: string;
|
|
ts: number;
|
|
game: GameType;
|
|
matchId: string;
|
|
type: EventType;
|
|
data: any;
|
|
time: TimeLabel;
|
|
userId?: string;
|
|
}
|
|
|
|
export type TimelineItem = UtteranceItem | EventItem;
|
|
|
|
export interface TimelinePage {
|
|
items: TimelineItem[];
|
|
next: string | null;
|
|
}
|
|
|
|
export interface MatchSummary {
|
|
id: string;
|
|
game: GameType;
|
|
startedAt: number;
|
|
endedAt: number | null;
|
|
map: { id: string; name: string; image: string | null };
|
|
mode: string;
|
|
win: boolean | null;
|
|
score: { ally: number; enemy: number } | null;
|
|
status: 'live' | 'pending_detail' | 'complete';
|
|
participants: string[];
|
|
}
|
|
|
|
export interface MatchPlayer {
|
|
puuid: string;
|
|
name: string;
|
|
tag?: string;
|
|
team: string;
|
|
ally: boolean;
|
|
character: { id: string; name: string; icon: string | null };
|
|
kills: number;
|
|
deaths: number;
|
|
assists: number;
|
|
score?: number;
|
|
cs?: number;
|
|
gold?: number;
|
|
level?: number;
|
|
items?: { id: number; name: string; icon: string | null }[];
|
|
rank?: string | null;
|
|
userId?: string;
|
|
}
|
|
|
|
export interface MatchRound {
|
|
num: number;
|
|
startedAt: number;
|
|
endedAt: number;
|
|
win: boolean;
|
|
result: string;
|
|
score: { ally: number; enemy: number };
|
|
economy?: Record<string, { spent: number; remaining: number; weapon?: string }>;
|
|
}
|
|
|
|
export interface MatchDetail extends MatchSummary {
|
|
players: MatchPlayer[];
|
|
rounds?: MatchRound[];
|
|
goldDiff?: { t: number; diff: number }[];
|
|
events: EventItem[];
|
|
utterances: UtteranceItem[];
|
|
mapTransform:
|
|
| { valorant: { xMultiplier: number; yMultiplier: number; xScalarToAdd: number; yScalarToAdd: number } }
|
|
| { lol: { minX: number; minY: number; maxX: number; maxY: number } }
|
|
| null;
|
|
}
|
|
|
|
export interface Overview {
|
|
guild: { id: string; name: string; icon: string | null } | null;
|
|
recording: { active: boolean; channel: string | null; since: number | null; participants: string[] };
|
|
users: User[];
|
|
games: { valorant: { connected: boolean; inMatch: boolean }; lol: { connected: boolean; inMatch: boolean } };
|
|
counts: { utterances: number; matches: number };
|
|
version: string;
|
|
}
|
|
|
|
export interface UserProfile {
|
|
user: User;
|
|
stats: { talkMs: number; count: number; topWords: { w: string; n: number }[] };
|
|
matches: MatchSummary[];
|
|
}
|
|
|
|
export type LiveEvent =
|
|
| { type: 'utterance.created' | 'utterance.updated'; data: UtteranceItem }
|
|
| { type: 'event.created'; data: EventItem }
|
|
| { type: 'match.updated'; data: MatchSummary }
|
|
| { type: 'recording.state'; data: Overview['recording'] }
|
|
| { type: 'users.updated'; data: User[] };
|
|
|
|
export interface DeviceStatus {
|
|
registered: boolean;
|
|
online: boolean;
|
|
name: string | null;
|
|
lastSeen: number | null;
|
|
version: string | null;
|
|
}
|
|
|
|
export type BrowserMessage = { type: 'status'; data: { device: DeviceStatus } } | LiveEvent;
|
|
|
|
// 사이트 서버 ↔ 앱 WebSocket
|
|
export type RelayToDevice =
|
|
| {
|
|
t: 'req';
|
|
id: string;
|
|
method: string;
|
|
path: string;
|
|
headers: Record<string, string>;
|
|
user: { id: string; name: string; avatar: string | null } | null;
|
|
body: string | null;
|
|
}
|
|
| { t: 'cancel'; id: string }
|
|
| { t: 'pong'; ts: number }
|
|
| { t: 'welcome'; deviceId: string };
|
|
|
|
export type RelayFromDevice =
|
|
| { t: 'hello'; name: string; version: string; guildId?: string | null }
|
|
| { t: 'ping'; ts: number }
|
|
| { t: 'res'; id: string; status: number; headers: Record<string, string>; body: string | null }
|
|
| { t: 'res_head'; id: string; status: number; headers: Record<string, string> }
|
|
| { t: 'res_end'; id: string }
|
|
| { t: 'event'; event: LiveEvent };
|
|
|
|
// 앱(exe) 로그인 · 유저 등록 (사이트 서버 /auth/app/*, /app/*)
|
|
/** superadmin = 최고 관리자(서버에 고정), admin = 관리자, user = 일반 유저 */
|
|
export type AppRole = 'superadmin' | 'admin' | 'user';
|
|
|
|
export interface AppUserInfo {
|
|
id: string;
|
|
name: string;
|
|
avatar: string | null;
|
|
}
|
|
|
|
/** POST /auth/app/begin → 브라우저로 열 주소와 결과를 받아 갈 비밀값 */
|
|
export interface AppLoginBegin {
|
|
id: string;
|
|
secret: string;
|
|
url: string;
|
|
expiresAt: number;
|
|
}
|
|
|
|
/** POST /auth/app/poll 응답 */
|
|
export type AppLoginPoll =
|
|
| { state: 'pending' }
|
|
| { state: 'ok'; token: string; user: AppUserInfo; role: AppRole }
|
|
| { state: 'not_registered'; user: AppUserInfo }
|
|
| { state: 'error'; error: string };
|
|
|
|
/** GET /app/me 응답 (등록된 유저만). 겜녹이 봇 토큰은 내려주지 않는다 (봇은 서버가 대신 연결, 아래 BotGw*) */
|
|
export interface AppMe {
|
|
user: AppUserInfo;
|
|
role: AppRole;
|
|
serverTime: number;
|
|
}
|
|
|
|
/** 관리자 화면의 등록 유저 한 줄 */
|
|
export interface AppUserRow {
|
|
id: string;
|
|
name: string;
|
|
avatar: string | null;
|
|
role: AppRole;
|
|
/** 서버에 고정된 최고 관리자 (지우거나 역할을 바꿀 수 없음) */
|
|
fixed: boolean;
|
|
addedBy: string | null;
|
|
addedAt: number | null;
|
|
lastSeenAt: number | null;
|
|
lastVersion: string | null;
|
|
}
|
|
|
|
// 겜녹이 봇 중계 (사이트 서버 WebSocket /app/bot/ws, Authorization: Bearer <앱 토큰>)
|
|
// 권한: 앱 유저가 가입한 디스코드 서버만, 그 유저가 볼 수 있는 채널만 보이고, 들어갈 수 있는(보기 + 연결) 음성채널에만 봇을 부를 수 있다
|
|
// 봇 토큰은 서버에만 있다. 서버가 디스코드 게이트웨이에 붙어 있고, 앱은 필요한 정보만 받는다.
|
|
// 음성채널에 들어갈 때는 앱의 @discordjs/voice 가 보낸 op 4 를 서버가 대신 보내고,
|
|
// 디스코드가 준 일회용 음성 접속 정보(VOICE_STATE/SERVER_UPDATE)를 앱에 넘긴다. 음성은 앱 ↔ 디스코드로 바로 간다.
|
|
export interface BotGwMember {
|
|
id: string;
|
|
name: string;
|
|
avatar: string | null;
|
|
bot: boolean;
|
|
}
|
|
export interface BotGwGuild {
|
|
id: string;
|
|
name: string;
|
|
icon: string | null;
|
|
}
|
|
export interface BotGwChannel {
|
|
id: string;
|
|
name: string;
|
|
}
|
|
|
|
export type BotGwToApp =
|
|
| { t: 'ready'; me: BotGwMember; guilds: BotGwGuild[] }
|
|
| { t: 'guilds'; guilds: BotGwGuild[] }
|
|
/** watch 응답: 그 서버에서 이 유저가 볼 수 있는 음성채널 · 그 채널에 있는 사람 */
|
|
| { t: 'guild'; guild: BotGwGuild; channels: BotGwChannel[]; voice: { member: BotGwMember; channelId: string }[] }
|
|
/** watch 거절: 이 유저가 가입하지 않은 서버 */
|
|
| { t: 'watch_denied'; guildId: string }
|
|
| { t: 'voiceState'; guildId: string; member: BotGwMember; oldChannelId: string | null; newChannelId: string | null; channel: BotGwChannel | null }
|
|
| { t: 'cmd'; id: string; name: string; guildId: string; user: BotGwMember; voiceChannel: BotGwChannel | null }
|
|
/** 음성 접속 정보 (디스코드 VOICE_SERVER_UPDATE / 봇 자신의 VOICE_STATE_UPDATE 원문) */
|
|
| { t: 'vserver'; guildId: string; data: any }
|
|
| { t: 'vstate'; guildId: string; data: any }
|
|
/** 다른 PC 가 이 서버에서 봇을 데려갔다 → 녹음을 멈춘다 */
|
|
| { t: 'taken'; guildId: string }
|
|
| { t: 'res'; id: string; ok: boolean; data?: any; error?: string };
|
|
|
|
export type BotGwFromApp =
|
|
| { t: 'watch'; guildId: string; commands: boolean }
|
|
/** @discordjs/voice 어댑터가 보낸 게이트웨이 op 4 (음성채널 참여 · 나가기) */
|
|
| { t: 'voice'; guildId: string; payload: any }
|
|
| { t: 'cmd_res'; id: string; content: string }
|
|
| { t: 'req'; id: string; op: 'members'; guildId: string };
|