Added Proxy and Server launch options. Reformted stuff

This commit is contained in:
Pierce 2019-03-10 20:18:49 -04:00
parent 2652654c18
commit a2e166dfe1
5 changed files with 84 additions and 38 deletions

View file

@ -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"
}
});
});

View file

@ -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);

View file

@ -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);
});
};

View file

@ -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);

View file

@ -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": {