feat(launcher): implement gated standard launch
Build the selected copy for its port, wait for the local server, and manage the game and server lifecycles. Keep standard launch disabled pending isolation verification. Verified both type checks, the launcher build, and the launch lifecycle against a temporary copy and a stand-in executable.
This commit is contained in:
1 parent
2a97b0d46c
commit
c1dea23955
19 files changed
+522
-105
No files matched your search
@@ -40,16 +40,22 @@ export const APP_ERROR_CODES = [
|
||||
'copy_location_in_use',
|
||||
'launch_no_copy',
|
||||
'launch_busy',
|
||||
'launch_failed',
|
||||
'launch_disabled',
|
||||
'launch_lab_required',
|
||||
'launch_lab_missing',
|
||||
'launch_lab_version',
|
||||
'launch_lab_failed',
|
||||
'launch_game_running',
|
||||
'launch_copy_in_steam',
|
||||
'launch_location',
|
||||
'launch_stock_version',
|
||||
'launch_build_failed',
|
||||
'launch_build_unavailable',
|
||||
'launch_port_busy',
|
||||
'launch_server_failed',
|
||||
'launch_server_exited',
|
||||
'launch_game_failed',
|
||||
/** A folder the player chose does not exist or cannot be read (params: path). */
|
||||
'folder_unreadable',
|
||||
/** The chosen folder lacks the files of a War Thunder installation (params: path). */
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
/** Split the launch setting into Windows arguments without going through a command shell. */
|
||||
export function parseLaunchArguments(text: string): string[] | null {
|
||||
if (/[\0\r\n]/.test(text)) return null;
|
||||
const args: string[] = [];
|
||||
let argument = '';
|
||||
let quoted = false;
|
||||
let started = false;
|
||||
let backslashes = 0;
|
||||
|
||||
for (const character of text) {
|
||||
if (character === '\\') {
|
||||
backslashes++;
|
||||
started = true;
|
||||
continue;
|
||||
}
|
||||
if (character === '"') {
|
||||
argument += '\\'.repeat(Math.floor(backslashes / 2));
|
||||
if (backslashes % 2 === 1) argument += '"';
|
||||
else quoted = !quoted;
|
||||
backslashes = 0;
|
||||
started = true;
|
||||
continue;
|
||||
}
|
||||
argument += '\\'.repeat(backslashes);
|
||||
backslashes = 0;
|
||||
if (!quoted && (character === ' ' || character === '\t')) {
|
||||
if (started) args.push(argument);
|
||||
argument = '';
|
||||
started = false;
|
||||
continue;
|
||||
}
|
||||
argument += character;
|
||||
started = true;
|
||||
}
|
||||
|
||||
if (quoted) return null;
|
||||
if (started) args.push(argument + '\\'.repeat(backslashes));
|
||||
return args;
|
||||
}
|
||||
@@ -1,10 +1,13 @@
|
||||
import { z } from 'zod';
|
||||
import { APP_ERROR_CODES } from '../errors.ts';
|
||||
|
||||
// Enable only after isolation has been verified and the maintainer approves the change.
|
||||
export const ORDINARY_LAUNCH_ENABLED = false;
|
||||
|
||||
export const LaunchStateSchema = z.object({
|
||||
phase: z.enum([
|
||||
'ready', 'checking', 'building', 'starting-server', 'starting-game', 'running',
|
||||
'stopping', 'port-busy', 'version-changed', 'server-exited', 'failed',
|
||||
'server-running', 'stopping', 'port-busy', 'version-changed', 'server-exited', 'failed',
|
||||
]),
|
||||
copyId: z.uuid().optional(),
|
||||
port: z.number().int().min(1).max(65535).optional(),
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
import { z } from 'zod';
|
||||
import { LANGUAGE_CHOICES } from '../languages.ts';
|
||||
import { parseLaunchArguments } from '../launch-arguments.ts';
|
||||
import { BACKGROUND_RANDOM, BackgroundChoiceSchema } from './background.ts';
|
||||
|
||||
const LanguageChoiceSchema = z.enum(LANGUAGE_CHOICES);
|
||||
const WindowCloseSchema = z.enum(['quit', 'tray']);
|
||||
const AfterGameStartsSchema = z.enum(['minimize', 'keep']);
|
||||
const LabPathSchema = z.string().min(1).nullable();
|
||||
const PortModeSchema = z.enum(['auto', 'fixed']);
|
||||
const PortSchema = z.number().int().min(1).max(65535);
|
||||
export const LAUNCH_ARGUMENTS_LIMIT = 4000;
|
||||
const LaunchArgumentsSchema = z.string().max(LAUNCH_ARGUMENTS_LIMIT).refine((value) => parseLaunchArguments(value) !== null);
|
||||
|
||||
/** The launcher's own settings (not the game's, not the local service's tuning). */
|
||||
export const SettingsSchema = z.object({
|
||||
@@ -19,6 +24,10 @@ export const SettingsSchema = z.object({
|
||||
windowClose: WindowCloseSchema.default('quit'),
|
||||
afterGameStarts: AfterGameStartsSchema.default('minimize'),
|
||||
autoSaveBackups: z.boolean().default(true),
|
||||
launchPortMode: PortModeSchema.default('auto'),
|
||||
launchPort: PortSchema.default(27015),
|
||||
closeServerOnGameExit: z.boolean().default(true),
|
||||
launchArguments: LaunchArgumentsSchema.default(''),
|
||||
developerMode: z.boolean().default(true),
|
||||
labStockPath: LabPathSchema.default(null),
|
||||
labDataPath: LabPathSchema.default(null),
|
||||
@@ -35,6 +44,10 @@ export const SettingsPatchSchema = z.object({
|
||||
windowClose: WindowCloseSchema.optional(),
|
||||
afterGameStarts: AfterGameStartsSchema.optional(),
|
||||
autoSaveBackups: z.boolean().optional(),
|
||||
launchPortMode: PortModeSchema.optional(),
|
||||
launchPort: PortSchema.optional(),
|
||||
closeServerOnGameExit: z.boolean().optional(),
|
||||
launchArguments: LaunchArgumentsSchema.optional(),
|
||||
developerMode: z.boolean().optional(),
|
||||
labStockPath: LabPathSchema.optional(),
|
||||
labDataPath: LabPathSchema.optional(),
|
||||
|
||||
Reference in new issue
Block a user