Skip to content

Commit

Permalink
chore: update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
admon84 committed Jul 28, 2024
1 parent ac933a2 commit 5f6500f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 16 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)/

Expand All @@ -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

Expand Down
22 changes: 13 additions & 9 deletions src/clientApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
})();

Expand All @@ -57,19 +58,22 @@ 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);
};

// Locate and read `package.nw`
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);
};

Expand All @@ -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';
Expand Down
8 changes: 4 additions & 4 deletions src/utils/clientUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ const serverErrors: Record<PropertyKey, string> = {
/**
* 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' });
Expand All @@ -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] : []));
}

/**
Expand Down

0 comments on commit 5f6500f

Please sign in to comment.