mirror of
https://github.com/artegoser/pimi-launcher-core.git
synced 2024-11-22 20:26:22 +03:00
small but major changes again. Pretty much done now
Removed: close restart. setting options in constructor. Added: getPid and new gif Reformatted: options now go back into the launch function. `authorization` still accepts either an json object or a promise. Better docs v2
This commit is contained in:
parent
845fac3767
commit
62d02dccba
4 changed files with 33 additions and 44 deletions
34
README.md
34
README.md
|
@ -19,6 +19,7 @@ const { Client, Authenticator } = require('minecraft-launcher-core');
|
||||||
|
|
||||||
let opts = {
|
let opts = {
|
||||||
clientPackage: null,
|
clientPackage: null,
|
||||||
|
authorization: Authenticator.getAuth("username", "password"),
|
||||||
root: "./minecraft",
|
root: "./minecraft",
|
||||||
os: "windows",
|
os: "windows",
|
||||||
version: {
|
version: {
|
||||||
|
@ -31,16 +32,23 @@ let opts = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const launcher = new Client(opts);
|
const launcher = new Client();
|
||||||
launcher.launch(Authenticator.getAuth(username, password));
|
launcher.launch(opts);
|
||||||
|
|
||||||
launcher.on('debug', (e) => console.log(e));
|
launcher.on('debug', (e) => console.log(e));
|
||||||
launcher.on('data', (e) => console.log(e));
|
launcher.on('data', (e) => console.log(e));
|
||||||
launcher.on('error', (e) => console.log(e));
|
launcher.on('error', (e) => console.log(e));
|
||||||
```
|
```
|
||||||
### Usage
|
### Documentation
|
||||||
|
|
||||||
##### Client Options
|
#### Client Functions
|
||||||
|
|
||||||
|
| Function | Type | Description |
|
||||||
|
|----------|---------|-----------------------------------------------------------------------------------------|
|
||||||
|
| `launch` | Promise | Launches the client with the specified `options` as a parameter |
|
||||||
|
| `getPid` | Integer | Returns the Minecraft client's PID |
|
||||||
|
|
||||||
|
##### launch
|
||||||
|
|
||||||
| Parameter | Type | Description | Required |
|
| Parameter | Type | Description | Required |
|
||||||
|--------------------------|----------|-------------------------------------------------------------------------------------------|----------|
|
|--------------------------|----------|-------------------------------------------------------------------------------------------|----------|
|
||||||
|
@ -52,6 +60,7 @@ launcher.on('error', (e) => console.log(e));
|
||||||
| `options.memory.max` | String | Max amount of memory being used by Minectaft. | True |
|
| `options.memory.max` | String | Max amount of memory being used by Minectaft. | True |
|
||||||
| `options.memory.min` | String | Min amount of memory being used by Minectaft. | True |
|
| `options.memory.min` | String | Min amount of memory being used by Minectaft. | True |
|
||||||
| `options.forge` | String | Path to Universal Forge Jar. | False |
|
| `options.forge` | String | Path to Universal Forge Jar. | False |
|
||||||
|
| `options.javaPath` | String | Path to the JRE executable file, will default to `java` if not entered. | False |
|
||||||
| `options.server.host` | String | Host url to the server, don't include the port. | 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.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.host` | String | Host url to the proxy, don't include the port. | False |
|
||||||
|
@ -66,19 +75,6 @@ launcher.on('error', (e) => console.log(e));
|
||||||
If you are loading up a client outside of vanilla Minecraft or Forge (Optifine and for an example), you'll need to download the needed files yourself
|
If you are loading up a client outside of vanilla Minecraft or Forge (Optifine and for an example), you'll need to download the needed files yourself
|
||||||
if you don't provide downloads url downloads like Forge and Fabric. Still need to provide the version jar.
|
if you don't provide downloads url downloads like Forge and Fabric. Still need to provide the version jar.
|
||||||
|
|
||||||
#### Client Functions
|
|
||||||
|
|
||||||
| Function | Type | Description |
|
|
||||||
|----------|---------|-----------------------------------------------------------------------------------------|
|
|
||||||
| `launch` | Promise | Launches the client with the specified `options` |
|
|
||||||
| `close` | Promise | Closes current client |
|
|
||||||
| `restart`| Promise | Restarts by closing the current client then relaunching it with the specified `options` |
|
|
||||||
|
|
||||||
##### launch
|
|
||||||
| Parameter | Type | Description | Required |
|
|
||||||
|-----------|--------|--------------------------------------------------------------|----------|
|
|
||||||
| `authentication` | Object | Result from `getAuth` or the getAuth function itself. | True |
|
|
||||||
|
|
||||||
#### Authenticator Functions
|
#### Authenticator Functions
|
||||||
|
|
||||||
##### getAuth
|
##### getAuth
|
||||||
|
@ -131,5 +127,5 @@ if you don't provide downloads url downloads like Forge and Fabric. Still need t
|
||||||
|
|
||||||
|
|
||||||
#### What should it look like running from console?
|
#### What should it look like running from console?
|
||||||
|
Showing the emitted information from debug and data, also using `getPid` after the process has been created.
|
||||||
![gif](https://pierce.is-serious.business/7d91a7.gif)
|
![gif](https://pierce.is-serious.business/3N3PMC4.gif)
|
||||||
|
|
|
@ -301,7 +301,7 @@ class Handler {
|
||||||
}
|
}
|
||||||
|
|
||||||
getLaunchOptions(modification) {
|
getLaunchOptions(modification) {
|
||||||
return new Promise(resolve => {
|
return new Promise(async resolve => {
|
||||||
let type = modification || this.version;
|
let type = modification || this.version;
|
||||||
|
|
||||||
let args = type.minecraftArguments ? type.minecraftArguments.split(' ') : type.arguments.game;
|
let args = type.minecraftArguments ? type.minecraftArguments.split(' ') : type.arguments.game;
|
||||||
|
@ -309,6 +309,10 @@ class Handler {
|
||||||
|
|
||||||
if(args.length < 5) args = args.concat(this.version.minecraftArguments ? this.version.minecraftArguments.split(' ') : this.version.arguments.game);
|
if(args.length < 5) args = args.concat(this.version.minecraftArguments ? this.version.minecraftArguments.split(' ') : this.version.arguments.game);
|
||||||
|
|
||||||
|
if({}.toString.call(this.options.authorization) === "[object Promise]") {
|
||||||
|
this.options.authorization = await this.options.authorization;
|
||||||
|
}
|
||||||
|
|
||||||
const fields = {
|
const fields = {
|
||||||
'${auth_access_token}': this.options.authorization.access_token,
|
'${auth_access_token}': this.options.authorization.access_token,
|
||||||
'${auth_session}': this.options.authorization.access_token,
|
'${auth_session}': this.options.authorization.access_token,
|
||||||
|
|
|
@ -6,24 +6,17 @@ const fs = require('fs');
|
||||||
const EventEmitter = require('events').EventEmitter;
|
const EventEmitter = require('events').EventEmitter;
|
||||||
|
|
||||||
class MCLCore extends EventEmitter {
|
class MCLCore extends EventEmitter {
|
||||||
constructor(options) {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.options = options;
|
|
||||||
this.handler = new handler(this);
|
|
||||||
this.pid = null;
|
this.pid = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
async launch(authorization) {
|
async launch(options) {
|
||||||
if(!authorization) throw Error('No authorization to launch the client with!');
|
this.options = options;
|
||||||
|
|
||||||
if({}.toString.call(authorization) === "[object Promise]") {
|
|
||||||
this.options.authorization = await authorization;
|
|
||||||
} else {
|
|
||||||
this.options.authorization = authorization
|
|
||||||
}
|
|
||||||
|
|
||||||
this.options.root = path.resolve(this.options.root);
|
this.options.root = path.resolve(this.options.root);
|
||||||
|
this.handler = new handler(this);
|
||||||
|
|
||||||
if(!fs.existsSync(this.options.root)) {
|
if(!fs.existsSync(this.options.root)) {
|
||||||
this.emit('debug', '[MCLC]: Attempting to create root folder');
|
this.emit('debug', '[MCLC]: Attempting to create root folder');
|
||||||
fs.mkdirSync(this.options.root);
|
fs.mkdirSync(this.options.root);
|
||||||
|
@ -109,13 +102,8 @@ class MCLCore extends EventEmitter {
|
||||||
this.pid = minecraft.pid;
|
this.pid = minecraft.pid;
|
||||||
}
|
}
|
||||||
|
|
||||||
async close() {
|
getPid() {
|
||||||
child.exec(`taskkill /PID ${this.pid}`, (err, out, error) => {return {err, out, error}})
|
return this.pid;
|
||||||
}
|
|
||||||
|
|
||||||
async restart() {
|
|
||||||
await this.close();
|
|
||||||
await this.launch()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "minecraft-launcher-core",
|
"name": "minecraft-launcher-core",
|
||||||
"version": "3.3.1",
|
"version": "3.4.0",
|
||||||
"description": "Module that downloads Minecraft assets and runs Minecraft. Also Supports Forge",
|
"description": "Lightweight module that downloads and runs Minecraft using javascript / NodeJS",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"adm-zip": "^0.4.13",
|
"adm-zip": "^0.4.13",
|
||||||
|
@ -20,7 +20,8 @@
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"minecraft",
|
"minecraft",
|
||||||
"minecraft-launcher-node"
|
"minecraft-launcher-node",
|
||||||
|
"minecraft-launcher"
|
||||||
],
|
],
|
||||||
"author": "Pierce Harriz",
|
"author": "Pierce Harriz",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
|
Loading…
Add table
Reference in a new issue