From a2e166dfe11e37a5f85e7c635123c15bad6bd1ea Mon Sep 17 00:00:00 2001 From: Pierce Date: Sun, 10 Mar 2019 20:18:49 -0400 Subject: [PATCH] Added Proxy and Server launch options. Reformted stuff --- README.md | 88 +++++++++++++++++++++++++++---------- components/authenticator.js | 2 +- components/handler.js | 21 ++++++--- components/launcher.js | 9 ++-- package.json | 2 +- 5 files changed, 84 insertions(+), 38 deletions(-) diff --git a/README.md b/README.md index 71bd047..bc665ae 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,39 @@ Basically a core for your Electron or script based launchers. `npm i minecraft-launcher-core` +### Standard Example +```javascript +const launcher = require('minecraft-launcher-core'); + +launcher.authenticator.getAuth("email", "password").then(auth => { + // Save the auth to a file so it can be used later on! + launcher.core({ + authorization: auth, + clientPackage: null, + forge: null, + root: "C:/Users/user/AppData/Roaming/.mc", + os: "windows", + version: { + number: "1.13.2", + type: "release" + }, + memory: { + max: "3000", + min: "1000" + }, + server: { + host: "server.url", + port: "25565" + }, + proxy: { + host: "proxy.url", + port: "8080", + username: "username", + password: "password" + } + }); +}); +``` ### Usage ##### launcher.core Options @@ -22,6 +55,12 @@ Basically a core for your Electron or script based launchers. | `options.version.type` | String | Any string. The actual Minecraft launcher uses `release` and `snapshot`. | True | | `options.memory.max` | String | Max amount of memory being used by Minectaft | True | | `options.forge.path` | String | Path to Universal Forge Jar | False | +| `options.server.host` | String | Host url to the server, don't include the port | False | +| `options.server.port` | String | Port of the host url, will default to `25565` if not entered. | False | +| `options.proxy.host` | String | Host url to the proxy, don't include the port | False | +| `options.proxy.port` | String | Port of the host proxy, will default to `8080` if not entered. | False | +| `options.proxy.username` | String | Username for the proxy. | False | +| `options.proxy.password` | String | Password for the proxy. | False | #### launcher.authenticator Functions @@ -69,28 +108,7 @@ this function is in the `handler` component. | `versions` | Array | Array of the versions being downloaded and being made into a package. | True | | `os` | String | OS that the package will be loaded on. OS specific natives need this. | True | -### Examples -```javascript -const launcher = require('minecraft-launcher-core'); - -launcher.authenticator.getAuth("email", "password").then(auth => { - // Save the auth to a file so it can be used later on! - launcher.core({ - authorization: auth, - clientPackage: null, - forge: null, - root: "C:/Users/user/AppData/Roaming/.mc", - os: "windows", - version: { - number: "1.13.2", - type: "MCC-Launcher" - }, - memory: { - max: "500" - } - }); -}); -``` +### Other Examples ##### Using Validate and Refresh @@ -111,7 +129,18 @@ launcher.core({ type: "MCC-Launcher" }, memory: { - max: "500" + max: "500", + min: "100" + }, + server: { + host: "server.url", + port: "25565" + }, + proxy: { + host: "proxy.url", + port: "8080", + username: "username", + password: "password" } }); ``` @@ -133,7 +162,18 @@ launcher.authenticator.getAuth("email", "password").then(auth => { type: "MCC-Launcher" }, memory: { - max: "500" + max: "500", + min: "100" + }, + server: { + host: "server.url", + port: "25565" + }, + proxy: { + host: "proxy.url", + port: "8080", + username: "username", + password: "password" } }); }); diff --git a/components/authenticator.js b/components/authenticator.js index fe52e59..9eda93a 100644 --- a/components/authenticator.js +++ b/components/authenticator.js @@ -43,7 +43,7 @@ function getAuth(username, password) { uuid: body.selectedProfile.id, name: body.selectedProfile.name, selected_profile: body.selectedProfile, - user_properties: JSON.stringify((body.user || {}).properties || {}) + user_properties: JSON.stringify(body.user.properties || {}) }; resolve(userProfile); diff --git a/components/handler.js b/components/handler.js index a3ab515..eb5a28a 100644 --- a/components/handler.js +++ b/components/handler.js @@ -217,12 +217,9 @@ module.exports.getClasses = function (root, version) { module.exports.getLaunchOptions = function (version, forge, options) { return new Promise(resolve => { - let arguments; - if(forge) { - arguments = forge.minecraftArguments ? forge.minecraftArguments.split(' ') : forge.arguments.game; - } else { - arguments = version.minecraftArguments ? version.minecraftArguments.split(' ') : version.arguments.game; - } + let type = forge || version; + let arguments = type.minecraftArguments ? type.minecraftArguments.split(' ') : type.arguments.game; + const fields = { '${auth_access_token}': options.authorization.access_token, '${auth_session}': options.authorization.access_token, @@ -243,6 +240,18 @@ module.exports.getLaunchOptions = function (version, forge, options) { } } + if(options.server) arguments.push('--server', options.server.host, '--port', options.server.port || "25565"); + if(options.proxy) arguments.push( + '--proxyHost', + options.proxy.host, + '--proxyPort', + options.proxy.port || "8080", + '--proxyUser', + options.proxy.username, + '--proxyPass', + options.proxy.password + ); + resolve(arguments); }); }; diff --git a/components/launcher.js b/components/launcher.js index a68c8ba..2b8f590 100644 --- a/components/launcher.js +++ b/components/launcher.js @@ -37,6 +37,7 @@ module.exports = async function (options) { '-Dfml.ignoreInvalidMinecraftCertificates=true', `-Djava.library.path=${nativePath}`, `-Xmx${options.memory.max}M`, + `-Xms${options.memory.min}M`, '-Xincgc' ]; jvm.push(await handler.getJVM(versionFile, options)); @@ -55,13 +56,9 @@ module.exports = async function (options) { // Download version's assets await handler.getAssets(options.root, versionFile); - // Launch options + // Launch options. Thank you Lyrus for the reformat <3 let launchOptions; - if(forge) { - launchOptions = await handler.getLaunchOptions(versionFile, forge.forge, options); - } else { - launchOptions = await handler.getLaunchOptions(versionFile, null, options); - } + launchOptions = await handler.getLaunchOptions(versionFile, forge ? forge.forge : null, options); const launchArguments = args.concat(jvm, classPaths, launchOptions); diff --git a/package.json b/package.json index 92a84c0..034cd56 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "minecraft-launcher-core", - "version": "2.2.0", + "version": "2.3.0", "description": "Module that downloads Minecraft assets and runs Minecraft. Also Supports Forge", "main": "index.js", "dependencies": {