import { z } from 'zod'; import { APP_ERROR_CODES } from '../errors.ts'; const GameExitSchema = z.object({ code: z.number().int().nullable(), signal: z.string().nullable(), logFolder: z.string(), }); export type GameExit = z.output; /** Append the unsigned 32-bit hex form for Windows NTSTATUS/HRESULT exit codes. */ export function formatExitCode(code: number): string { if (code >= 0 && code <= 0xffff) return String(code); return `${code} (0x${(code >>> 0).toString(16).toUpperCase().padStart(8, '0')})`; } export const LaunchStateSchema = z.object({ phase: z.enum([ 'ready', 'checking', 'building', 'starting-server', 'starting-game', 'running', 'server-running', 'game-exited', 'stopping', 'port-busy', 'version-changed', 'server-exited', 'failed', ]), copyId: z.uuid().optional(), port: z.number().int().min(1).max(65535).optional(), filesWritten: z.number().int().nonnegative().optional(), filesTotal: z.number().int().nonnegative().optional(), file: z.string().optional(), actualVersion: z.string().nullable().optional(), gameExit: GameExitSchema.optional(), error: z.enum(APP_ERROR_CODES).optional(), }); export type LaunchState = z.output; export const LabInfoSchema = z.object({ copyPath: z.string(), port: z.number().int().min(1).max(65535), });