Publish stable mode IDs and matching responses in the stock format. Build the mission pools from the multiplayer mission data and provide required fields and localized names. Load datasets before listening and reuse cached results when the source file digests match. Preserve invalid UTF-8 bytes when round-tripping BLK strings and names. The game mode list appeared in the offline client.
42 lines
1.5 KiB
TypeScript
42 lines
1.5 KiB
TypeScript
/**
|
|
* Development entry point of the local service.
|
|
*
|
|
* node packages/local-service/src/cli.ts --game <game folder> --data <data folder> --port <n>
|
|
*
|
|
* The port must match the one the game copy was built with (packages/build). The launcher
|
|
* will start the service the same way. Stops on Ctrl+C.
|
|
*/
|
|
import { parseArgs } from 'node:util';
|
|
import { LOOPBACK, startLocalService } from './local-service.ts';
|
|
|
|
async function main(): Promise<number> {
|
|
const { values } = parseArgs({
|
|
options: {
|
|
game: { type: 'string' },
|
|
data: { type: 'string' },
|
|
port: { type: 'string' },
|
|
},
|
|
});
|
|
const port = Number(values.port);
|
|
if (!values.game || !values.data || !Number.isInteger(port) || port < 1 || port > 65535) {
|
|
console.error('usage: cli.ts --game <game folder> --data <data folder> --port <n>');
|
|
return 2;
|
|
}
|
|
let service;
|
|
try {
|
|
service = await startLocalService({ gameFolder: values.game, dataFolder: values.data, port, report: (line) => console.log(line) });
|
|
} catch (error) {
|
|
const code = (error as NodeJS.ErrnoException).code;
|
|
console.error(code === 'EADDRINUSE' ? `port ${port} is already in use; choose another port` : String(error));
|
|
return 1;
|
|
}
|
|
console.log(`local service listening on ${LOOPBACK}:${port}`);
|
|
console.log(`traffic log: ${service.logFolder}`);
|
|
const running = service;
|
|
await new Promise<void>((resolve) => process.once('SIGINT', resolve));
|
|
await running.close();
|
|
return 0;
|
|
}
|
|
|
|
process.exitCode = await main();
|