import { spawn } from 'child_process'; import { logGameExit, logGameStderr } from './server_log'; export function GetRandomPort(min: number, max: number): number { return randomIntFromInterval(min, max); } export function OpenGameInstance(path: string, port: number, matchId?: number): void { const args = ["-port", port.toString()]; if (matchId != null && Number.isFinite(matchId)) { args.push("-matchId", String(Math.trunc(matchId))); } const child = spawn(path, args); child.stdout.on('data', (data: Buffer) => { // console.log('stdout: ' + data); }); child.stderr.on('data', (data: Buffer) => { logGameStderr(port, data); }); child.on('close', (code: number | null) => { logGameExit(port, code); }); } function randomIntFromInterval(min: number, max: number): number { return Math.floor(Math.random() * (max - min + 1) + min); }