diff --git a/README.md b/README.md index 7dac5dd..8be1d0a 100755 --- a/README.md +++ b/README.md @@ -21,6 +21,8 @@ _This is an early WIP with a few hours gone in to both the extension and the gam | Show File Push Notifications | `bitburner.showPushSuccessNotification` | If true, this will show a notification/toast when a file has been successfully pushed to the game. Errors will always show. | `false` | | Show File Watcher Enabled Notifications | `bitburner.showFileWatcherEnabledNotification` | If true, this will show a notification/toast whenever the File Watcher is enabled and/or the extension configuration scriptRoot has changed. Errors will always show. | `false` | | Game Authentication Token | `bitburner.authToken` | The auth token that the game generates, needed for you to be able to push files in to your game client. See [#authentication](#authentication) section below. | (No Default) | +| Game remote host | `bitburner.hostname` | Specify the host name of the game. | `localhost` | +| Game remote port | `bitburner.port` | Specify the port of the game. | `9990` | ## Pushing Files @@ -40,6 +42,10 @@ The token will ultimately end up in the workspace configuration (See your worksp - Use the command palette (CTRL/CMD + SHIFT + P) and select `Bitburner: Add Auth Token`. - Paste the Auth Token copied via the games context menu in to the input box. +#### Allow remote connections: + +By default, the game listens only on *localhost*. To allow connections from remote host or from a WSL container, you have to edit the `config.json` file and define the `host` parameter to `0.0.0.0`. + ### Push through the context menu - Right Click in the VSCode Editor (Your source code) and choose 'Bitburner: Push file to game' diff --git a/package.json b/package.json index 1280f89..3354e9d 100755 --- a/package.json +++ b/package.json @@ -110,6 +110,16 @@ "bitburner.authToken": { "type": "string", "description": "Token generated by the game client to allow file pushes." + }, + "bitburner.hostname": { + "type": "string", + "default": "localhost", + "description": "The hostname of the game client." + }, + "bitburner.port": { + "type": "number", + "default": "9990", + "description": "The port of the game client." } } } diff --git a/src/extension.js b/src/extension.js index bb0a004..c586636 100755 --- a/src/extension.js +++ b/src/extension.js @@ -22,7 +22,7 @@ let fwEnabled; // TODO: Refactor this user config to combined 'extension/user config' with better internal API/structure /** - * @type {{ scriptRoot: string, fwEnabled: boolean, showPushSuccessNotification: boolean, showFileWatcherEnabledNotification: boolean, authToken: string }} + * @type {{ scriptRoot: string, fwEnabled: boolean, showPushSuccessNotification: boolean, showFileWatcherEnabledNotification: boolean, authToken: string, hostname: string, port: number }} */ let sanitizedUserConfig; @@ -271,8 +271,8 @@ const doPostRequestToBBGame = (payload) => { const stringPayload = JSON.stringify(cleanPayload); const options = { - hostname: BB_GAME_CONFIG.url, - port: BB_GAME_CONFIG.port, + hostname: sanitizedUserConfig.hostname, + port: sanitizedUserConfig.port, path: BB_GAME_CONFIG.filePostURI, method: `POST`, headers: { @@ -333,6 +333,8 @@ const sanitizeUserConfig = () => { .get(`authToken`) .replace(/^bearer/i, ``) .trim(), + hostname: userConfig.get(`hostname`), + port: userConfig.get(`port`), }; }; @@ -353,7 +355,7 @@ const showToast = (message, toastType = `information`, opts = { forceShow: false if (!Object.keys(ToastTypes).includes(toastType)) { return; } - if (!sanitizedUserConfig.showPushSuccessNotification && !opts.forceShow && toastType !== `error`) { + if ((!sanitizedUserConfig || !sanitizedUserConfig.showPushSuccessNotification) && !opts.forceShow && toastType !== `error`) { return; }