ForgeWrapper & Auth changes

This commit is contained in:
Pierce 2021-08-08 13:05:50 -07:00
parent 3e276479cd
commit 6af7b10f86
7 changed files with 36 additions and 2143 deletions

View file

@ -111,7 +111,14 @@ let opts = {
defaultRepoForge: "https://libraries.minecraft.net/", // for Forge only, you need to redefine the library url defaultRepoForge: "https://libraries.minecraft.net/", // for Forge only, you need to redefine the library url
// in the version json. // in the version json.
fallbackMaven: "https://search.maven.org/remotecontent?filepath=" fallbackMaven: "https://search.maven.org/remotecontent?filepath="
} },
// The following is options for which version of ForgeWrapper MCLC uses. This allows us to launch modern Forge.
fw: {
baseUrl: 'https://github.com/ZekerZhayard/ForgeWrapper/releases/download/',
version: '1.5.1',
sh1: '90104e9aaa8fbedf6c3d1f6d0b90cabce080b5a9',
size: 29892,
}
} }
} }
``` ```
@ -130,6 +137,7 @@ This runs an executable with specified launch arguments. Was used to support For
|-----------|--------|--------------------------------------------------------------|----------| |-----------|--------|--------------------------------------------------------------|----------|
| `username`| String | Email or username | True | | `username`| String | Email or username | True |
| `password`| String | Password for the Mojang account being used if online mode. | False | | `password`| String | Password for the Mojang account being used if online mode. | False |
| `client_token`| String | Client token that will be used. If one is not specified, one will be generated | False |
##### validate ##### validate
@ -144,7 +152,6 @@ This runs an executable with specified launch arguments. Was used to support For
|--------------------|--------|-------------------------------------------------------------------------------------|----------| |--------------------|--------|-------------------------------------------------------------------------------------|----------|
| `access_token` | String | Token being checked if it can be used to login with (online mode). | True | | `access_token` | String | Token being checked if it can be used to login with (online mode). | True |
| `client_token` | String | Token being checked if it's the same client that the access_token was created from. | True | | `client_token` | String | Token being checked if it's the same client that the access_token was created from. | True |
| `selected_profile` | Object | Json Object that was returned from Mojang's auth api. | True |
##### invalidate ##### invalidate

View file

@ -1,13 +1,13 @@
const request = require('request') const request = require('request')
const uuid = require('uuid/v1') const uuid = require('uuid').v1
let api_url = 'https://authserver.mojang.com' let api_url = 'https://authserver.mojang.com'
module.exports.getAuth = function (username, password) { module.exports.getAuth = function (username, password, client_token = null) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if (!password) { if (!password) {
const user = { const user = {
access_token: uuid(), access_token: uuid(),
client_token: uuid(), client_token: client_token || uuid(),
uuid: uuid(), uuid: uuid(),
name: username, name: username,
user_properties: '{}' user_properties: '{}'
@ -69,14 +69,13 @@ module.exports.validate = function (access_token, client_token) {
}) })
} }
module.exports.refreshAuth = function (accessToken, clientToken, selectedProfile) { module.exports.refreshAuth = function (accessToken, clientToken) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const requestObject = { const requestObject = {
url: api_url + '/refresh', url: api_url + '/refresh',
json: { json: {
accessToken: accessToken, accessToken: accessToken,
clientToken: clientToken, clientToken: clientToken,
selectedProfile: selectedProfile,
requestUser: true requestUser: true
} }
} }

View file

@ -320,7 +320,7 @@ class Handler {
if (fs.existsSync(versionPath)) { if (fs.existsSync(versionPath)) {
try { try {
json = JSON.parse(fs.readFileSync(versionPath)) json = JSON.parse(fs.readFileSync(versionPath))
if (!json.forgeWrapperVersion || !(json.forgeWrapperVersion === this.options.fw.version)) { if (!json.forgeWrapperVersion || !(json.forgeWrapperVersion === this.options.overrides.fw.version)) {
this.client.emit('debug', '[MCLC]: Old ForgeWrapper has generated this version JSON, re-generating') this.client.emit('debug', '[MCLC]: Old ForgeWrapper has generated this version JSON, re-generating')
} else { } else {
// If forge is modern, add ForgeWrappers launch arguments and set forge to null so MCLC treats it as a custom json. // If forge is modern, add ForgeWrappers launch arguments and set forge to null so MCLC treats it as a custom json.
@ -362,16 +362,16 @@ class Handler {
// If forge is modern and above 1.12.2, we add ForgeWrapper to the libraries so MCLC includes it in the classpaths. // If forge is modern and above 1.12.2, we add ForgeWrapper to the libraries so MCLC includes it in the classpaths.
if (json.inheritsFrom !== '1.12.2') { if (json.inheritsFrom !== '1.12.2') {
this.fwAddArgs() this.fwAddArgs()
const fwName = `ForgeWrapper-${this.options.fw.version}.jar` const fwName = `ForgeWrapper-${this.options.overrides.fw.version}.jar`
const fwPathArr = ['io', 'github', 'zekerzhayard', 'ForgeWrapper', this.options.fw.version] const fwPathArr = ['io', 'github', 'zekerzhayard', 'ForgeWrapper', this.options.overrides.fw.version]
json.libraries.push({ json.libraries.push({
name: fwPathArr.join(':'), name: fwPathArr.join(':'),
downloads: { downloads: {
artifact: { artifact: {
path: [...fwPathArr, fwName].join('/'), path: [...fwPathArr, fwName].join('/'),
url: `${this.options.fw.baseUrl}${this.options.fw.version}/${fwName}`, url: `${this.options.overrides.fw.baseUrl}${this.options.overrides.fw.version}/${fwName}`,
sha1: this.options.fw.sh1, sha1: this.options.overrides.fw.sh1,
size: this.options.fw.size size: this.options.overrides.fw.size
} }
} }
}) })

View file

@ -20,14 +20,17 @@ class MCLCore extends EventEmitter {
...this.options.overrides ...this.options.overrides
? this.options.overrides.url ? this.options.overrides.url
: undefined : undefined
},
fw: {
baseUrl: 'https://github.com/ZekerZhayard/ForgeWrapper/releases/download/',
version: '1.5.1',
sh1: '90104e9aaa8fbedf6c3d1f6d0b90cabce080b5a9',
size: 29892,
...this.options.overrides
? this.options.overrides.fw
: undefined
} }
} }
this.options.fw = {
baseUrl: 'https://github.com/ZekerZhayard/ForgeWrapper/releases/download/',
version: '1.4.2',
sh1: '79ff9c1530e8743450c5c3ebc6e07b535437aa6e',
size: 22346
}
this.handler = new Handler(this) this.handler = new Handler(this)

7
index.d.ts vendored
View file

@ -22,6 +22,12 @@ declare module "minecraft-launcher-core" {
defaultRepoForge?: string; defaultRepoForge?: string;
fallbackMaven?: string; fallbackMaven?: string;
}; };
fw?: {
baseUrl?: string;
version?: string;
sh1?: string;
size?: number;
};
} }
interface ILauncherOptions { interface ILauncherOptions {
@ -185,7 +191,6 @@ declare module "minecraft-launcher-core" {
refreshAuth( refreshAuth(
access_token: string, access_token: string,
client_token: string, client_token: string,
selectedProfile: IProfile
): Promise<IUser>; ): Promise<IUser>;
/** /**
* *

2121
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -1,13 +1,13 @@
{ {
"name": "minecraft-launcher-core", "name": "minecraft-launcher-core",
"version": "3.16.4", "version": "3.16.5",
"description": "Lightweight module that downloads and runs Minecraft using javascript / NodeJS", "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",
"checksum": "^0.1.1", "checksum": "^0.1.1",
"request": "^2.88.0", "request": "^2.88.0",
"uuid": "^3.3.2" "uuid": "^8.3.2"
}, },
"devDependencies": { "devDependencies": {
"@types/node": "^14.0.27", "@types/node": "^14.0.27",