From 3f0ceae5b6ccf4bbbb0bcc9c8350f6445ee42bfe Mon Sep 17 00:00:00 2001 From: Pierce Date: Thu, 23 May 2019 20:40:44 -0400 Subject: [PATCH] Change how authentication gets passed I was making a launcher of my own, and I found it very hard to juggle with having the auth in the options since I needed to set the client events before I actaully had the users login. This will fix the issue i was running into! --- README.md | 9 ++++++--- components/launcher.js | 10 +++++++++- package.json | 2 +- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 61787bc..4241115 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,6 @@ https://discord.gg/8uYVbXP const { Client, Authenticator } = require('minecraft-launcher-core'); let opts = { - authorization: async () => { return await Authenticator.getAuth(username, password) }, clientPackage: null, root: "./minecraft", os: "windows", @@ -33,7 +32,7 @@ let opts = { } const launcher = new Client(opts); -launcher.launch(); +launcher.launch(Authenticator.getAuth(username, password)); launcher.on('debug', (e) => console.log(e)); launcher.on('data', (e) => console.log(e)); @@ -45,7 +44,6 @@ launcher.on('error', (e) => console.log(e)); | Parameter | Type | Description | Required | |--------------------------|----------|-------------------------------------------------------------------------------------------|----------| -| `options.authorization` | Object | The result from `getAuth` function, allows the client to login in online or offline mode. | True | | `options.clientPackage` | String | Path to the client package zip file. | False | | `options.root` | String | Path where you want the launcher to work in. like `C:/Users/user/AppData/Roaming/.mc`, | True | | `options.os` | String | windows, osx or linux, | True | @@ -73,6 +71,11 @@ if you don't provide downloads url downloads like Forge and Fabric. Still need t | `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 ##### getAuth diff --git a/components/launcher.js b/components/launcher.js index 013922c..00fb2b5 100644 --- a/components/launcher.js +++ b/components/launcher.js @@ -14,7 +14,15 @@ class MCLCore extends EventEmitter { this.pid = null; } - async launch() { + async launch(authorization) { + if(!authorization) throw Error('No authorization to launch the client with!'); + + if({}.toString.call(authorization) === "[object Promise]") { + this.options.authorization = await authorization; + } else { + this.options.authorization = authorization + } + this.options.root = path.resolve(this.options.root); if(!fs.existsSync(this.options.root)) { this.emit('debug', '[MCLC]: Attempting to create root folder'); diff --git a/package.json b/package.json index 2af8b98..27d2e8c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "minecraft-launcher-core", - "version": "3.0.2", + "version": "3.1.0", "description": "Module that downloads Minecraft assets and runs Minecraft. Also Supports Forge", "main": "index.js", "dependencies": {