From 5f6500f60a01b4a3ad56deb923bc5ce7e80021f4 Mon Sep 17 00:00:00 2001 From: admon84 Date: Sat, 27 Jul 2024 20:44:34 -0600 Subject: [PATCH] chore: update readme --- README.md | 10 +++++++--- src/clientApp.ts | 22 +++++++++++++--------- src/utils/clientUtils.ts | 8 ++++---- 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index f172d07..c49f690 100644 --- a/README.md +++ b/README.md @@ -2,11 +2,12 @@ ### Overview -The Screepers Steamless Client is a web proxy that allows you to run [Screeps: World](https://store.steampowered.com/app/464350/Screeps/), a game purchased via Steam, directly in your browser. It overcomes compatibility issues with the official Screeps client on many macOS devices. This client uses the Screeps files installed with Steam and enables gameplay on official and private servers across macOS, Linux, and Windows using the browser of your choice. +The Screepers Steamless Client is a web proxy for the [Screeps World](https://store.steampowered.com/app/464350/Screeps/) game client. It allows you to run Screeps in your web browser and works with macOS, Linux and Windows setups. ## Requirements -Node.js v20+ +- Node.js v20+ +- Screeps World (installed using Steam) ## Installation @@ -27,7 +28,7 @@ screepers-steamless-client View the server list page at http://localhost:8080/. This address can be changed with the `--host` and `--port` arguments. -Different servers can be accessed from the server list page, or using the url format `http://localhost:8080/(SERVER_ADDRESS)/` +Different servers can be accessed from the server list page, or using the url format `http://localhost:8080/(BACKEND_ADDRESS)/` - For the official server: http://localhost:8080/(https://screeps.com)/ @@ -48,6 +49,9 @@ All of the command line arguments are optional. - `--internal_backend` — Used to configure an internal backend url. If provided, the client app uses this address to reference the internal server endpoint. - `--server_list` — Used to set the path to a custom server list json config file. - `--beautify` — Formats .js files loaded in the client for debugging. +- `--debug` — Display verbose errors for development. +- `-v` , `--version` — Display the version number. +- `-h` , `--help` — Display the help message. ## Argument Examples diff --git a/src/clientApp.ts b/src/clientApp.ts index 9424406..987827a 100644 --- a/src/clientApp.ts +++ b/src/clientApp.ts @@ -36,19 +36,20 @@ const rootDir = path.join(__dirname, '..'); const packageJsonPath = path.resolve(rootDir, 'package.json'); const packageJson = JSON.parse(await fs.readFile(packageJsonPath, 'utf8')); const version = packageJson.version || '1.0.0'; +const arrow = '\u2192'; // Parse program arguments const argv = (() => { const parser = new ArgumentParser(); - parser.add_argument('--version', '-v', { action: 'version', version: `v${version}` }); + parser.add_argument('-v', '--version', { action: 'version', version: `v${version}` }); parser.add_argument('--package', { nargs: '?', type: 'str' }); parser.add_argument('--host', { nargs: '?', type: 'str' }); parser.add_argument('--port', { nargs: '?', type: 'int' }); parser.add_argument('--backend', { nargs: '?', type: 'str' }); parser.add_argument('--internal_backend', { nargs: '?', type: 'str' }); parser.add_argument('--server_list', { nargs: '?', type: 'str' }); - parser.add_argument('--beautify', { action: 'store_false', default: false }); - parser.add_argument('--debug', { action: 'store_false', default: false }); + parser.add_argument('--beautify', { action: 'store_true', default: false }); + parser.add_argument('--debug', { action: 'store_true', default: false }); return parser.parse_args(); })(); @@ -57,11 +58,14 @@ console.log('🧩', chalk.yellowBright(`Screepers Steamless Client v${version}`) // Create proxy const proxy = httpProxy.createProxyServer({ changeOrigin: true }); -proxy.on('error', (err, _req, res) => handleProxyError(err, res as ServerResponse)); +proxy.on('error', (err, _req, res) => handleProxyError(err, res as ServerResponse, argv.debug)); const exitOnPackageError = () => { - logError('Could not find the Screeps "package.nw".'); - logError('Use the "--package" argument to specify the path to the "package.nw" file.'); + if (argv.package) { + logError(`Could not find the Screeps "package.nw" at the path provided.`); + } else { + logError('Use the "--package" argument to specify the path to the Screeps "package.nw" file.'); + } process.exit(1); }; @@ -69,7 +73,7 @@ const exitOnPackageError = () => { const readPackageData = async () => { const pkgPath = argv.package ?? (await getScreepsPath()); if (!pkgPath || !existsSync(pkgPath)) exitOnPackageError(); - console.log('📦', chalk.dim('Package >'), chalk.gray(pkgPath)); + console.log('📦', chalk.dim('Package', arrow), chalk.gray(pkgPath)); return Promise.all([fs.readFile(pkgPath), fs.stat(pkgPath)]).catch(exitOnPackageError); }; @@ -87,8 +91,8 @@ const koa = new Koa(); const port = argv.port ?? 8080; const host = argv.host ?? 'localhost'; const server = koa.listen(port, host); -server.on('error', handleServerError); -server.on('listening', () => console.log('🌐', chalk.dim('Ready >'), chalk.white(`http://${host}:${port}/`))); +server.on('error', (err) => handleServerError(err, argv.debug)); +server.on('listening', () => console.log('🌐', chalk.dim('Ready', arrow), chalk.white(`http://${host}:${port}/`))); // Get system path for public files dir const indexFile = 'index.ejs'; diff --git a/src/utils/clientUtils.ts b/src/utils/clientUtils.ts index 1cf6d9d..7d9e054 100644 --- a/src/utils/clientUtils.ts +++ b/src/utils/clientUtils.ts @@ -41,10 +41,10 @@ const serverErrors: Record = { /** * Log proxy errors to the console with error styling. */ -export function handleProxyError(err: ServerError, res: ServerResponse) { +export function handleProxyError(err: ServerError, res: ServerResponse, debug?: boolean) { const message = serverErrors[err.code!] ?? 'An unknown error occurred.'; const target = `${err.address ?? ''}${err.port ? `:${err.port}` : ''}`; - logError(message, chalk.dim(target)); + logError(message, chalk.dim(target), ...(debug ? ['\n', err] : [])); // Return a plain text response instead of json so the client will stop loading. res.writeHead(500, { 'Content-Type': 'plain/text' }); @@ -54,10 +54,10 @@ export function handleProxyError(err: ServerError, res: ServerResponse) { /** * Log server errors to the console with error styling. */ -export function handleServerError(err: ServerError) { +export function handleServerError(err: ServerError, debug?: boolean) { const message = serverErrors[err.code!] ?? err.code ?? 'An unknown error occurred.'; const target = `${err.address ?? ''}${err.port ? `:${err.port}` : ''}`; - logError(message, chalk.dim(target)); + logError(message, chalk.dim(target), ...(debug ? ['\n', err] : [])); } /**