Files
kickkingsapi/helpers.ts
T
2026-02-15 11:45:50 +05:30

26 lines
772 B
TypeScript

import { spawn } from 'child_process';
export function GetRandomPort(min: number, max: number): number {
return randomIntFromInterval(min, max);
}
export function OpenGameInstance(path: string, port: number): void {
const args = ["-port", port.toString()];
const child = spawn(path, args);
child.stdout.on('data', (data: Buffer) => {
// console.log('stdout: ' + data);
});
child.stderr.on('data', (data: Buffer) => {
console.log('stderr: ' + data);
});
child.on('close', (code: number) => {
console.log('Game instance with port ' + port + " exited with code " + code);
});
}
function randomIntFromInterval(min: number, max: number): number {
return Math.floor(Math.random() * (max - min + 1) + min);
}