mineflayer-viaproxy 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +112 -0
- package/dist/constants.d.ts +3 -0
- package/dist/constants.js +8 -0
- package/dist/constants.js.map +1 -0
- package/dist/convNmp.d.ts +6 -0
- package/dist/convNmp.js +312 -0
- package/dist/convNmp.js.map +1 -0
- package/dist/func.d.ts +4 -0
- package/dist/func.js +255 -0
- package/dist/func.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/openAuthMod.d.ts +2 -0
- package/dist/openAuthMod.js +31 -0
- package/dist/openAuthMod.js.map +1 -0
- package/dist/types/accountsV3.d.ts +109 -0
- package/dist/types/accountsV3.js +3 -0
- package/dist/types/accountsV3.js.map +1 -0
- package/dist/types/accountsV4.d.ts +124 -0
- package/dist/types/accountsV4.js +3 -0
- package/dist/types/accountsV4.js.map +1 -0
- package/dist/types/config.d.ts +20 -0
- package/dist/types/config.js +39 -0
- package/dist/types/config.js.map +1 -0
- package/dist/types/index.d.ts +22 -0
- package/dist/types/index.js +10 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types.d.ts +21 -0
- package/dist/types.js +10 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +20 -0
- package/dist/utils.js +544 -0
- package/dist/utils.js.map +1 -0
- package/eclcc.log +1 -0
- package/package.json +32 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export declare enum AuthType {
|
|
2
|
+
NONE = "NONE",
|
|
3
|
+
OPENAUTHMOD = "OPENAUTHMOD",
|
|
4
|
+
ACCOUNT = "ACCOUNT"
|
|
5
|
+
}
|
|
6
|
+
export interface ViaProxyOpts {
|
|
7
|
+
forceViaProxy?: boolean;
|
|
8
|
+
javaPath?: string;
|
|
9
|
+
localPort?: number;
|
|
10
|
+
localAuth?: AuthType;
|
|
11
|
+
viaProxyLocation?: string;
|
|
12
|
+
viaProxyWorkingDir?: string;
|
|
13
|
+
autoUpdate?: boolean;
|
|
14
|
+
viaProxyConfig?: Partial<ViaProxyConfig>;
|
|
15
|
+
viaProxyStdoutCb?: (data: any) => void;
|
|
16
|
+
viaProxyStderrCb?: (data: any) => void;
|
|
17
|
+
}
|
|
18
|
+
export interface ViaProxyConfig {
|
|
19
|
+
backendProxyUrl: string;
|
|
20
|
+
[key: string]: string | number | boolean;
|
|
21
|
+
}
|
|
22
|
+
export { ViaProxySettings } from './config';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AuthType = void 0;
|
|
4
|
+
var AuthType;
|
|
5
|
+
(function (AuthType) {
|
|
6
|
+
AuthType["NONE"] = "NONE";
|
|
7
|
+
AuthType["OPENAUTHMOD"] = "OPENAUTHMOD";
|
|
8
|
+
AuthType["ACCOUNT"] = "ACCOUNT";
|
|
9
|
+
})(AuthType || (exports.AuthType = AuthType = {}));
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";;;AAAA,IAAY,QAIX;AAJD,WAAY,QAAQ;IAChB,yBAAa,CAAA;IACb,uCAA2B,CAAA;IAC3B,+BAAmB,CAAA;AACvB,CAAC,EAJW,QAAQ,wBAAR,QAAQ,QAInB"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare enum AuthType {
|
|
2
|
+
NONE = "NONE",
|
|
3
|
+
OPENAUTHMOD = "OPENAUTHMOD",
|
|
4
|
+
ACCOUNT = "ACCOUNT"
|
|
5
|
+
}
|
|
6
|
+
export interface ViaProxyOpts {
|
|
7
|
+
forceViaProxy?: boolean;
|
|
8
|
+
javaPath?: string;
|
|
9
|
+
localPort?: number;
|
|
10
|
+
localAuth?: AuthType;
|
|
11
|
+
viaProxyLocation?: string;
|
|
12
|
+
viaProxyWorkingDir?: string;
|
|
13
|
+
autoUpdate?: boolean;
|
|
14
|
+
viaProxyConfig?: Partial<ViaProxyConfig>;
|
|
15
|
+
viaProxyStdoutCb?: (data: any) => void;
|
|
16
|
+
viaProxyStderrCb?: (data: any) => void;
|
|
17
|
+
}
|
|
18
|
+
export interface ViaProxyConfig {
|
|
19
|
+
backendProxyUrl: string;
|
|
20
|
+
[key: string]: string | number | boolean;
|
|
21
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AuthType = void 0;
|
|
4
|
+
var AuthType;
|
|
5
|
+
(function (AuthType) {
|
|
6
|
+
AuthType["NONE"] = "NONE";
|
|
7
|
+
AuthType["OPENAUTHMOD"] = "OPENAUTHMOD";
|
|
8
|
+
AuthType["ACCOUNT"] = "ACCOUNT";
|
|
9
|
+
})(AuthType || (exports.AuthType = AuthType = {}));
|
|
10
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAAA,IAAY,QAIX;AAJD,WAAY,QAAQ;IAChB,yBAAa,CAAA;IACb,uCAA2B,CAAA;IAC3B,+BAAmB,CAAA;AACvB,CAAC,EAJW,QAAQ,wBAAR,QAAQ,QAInB"}
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Bot } from "mineflayer";
|
|
2
|
+
import { ClientOptions } from "minecraft-protocol";
|
|
3
|
+
import { ViaProxySettings } from "./types";
|
|
4
|
+
import { ViaProxyV3Config } from "./types/config";
|
|
5
|
+
export declare function validateOptions(options: ClientOptions): ClientOptions & {
|
|
6
|
+
profilesFolder: string;
|
|
7
|
+
};
|
|
8
|
+
export declare function openAuthLogin(bot: Bot): Promise<void>;
|
|
9
|
+
export declare function findOpenPort(): Promise<number>;
|
|
10
|
+
export declare function getSupportedMCVersions(javaLoc: string, cwd: string, filename: string): Promise<string[]>;
|
|
11
|
+
export declare function fetchViaProxyJar(path: string, version: string, filename: string): Promise<string | void>;
|
|
12
|
+
export declare function fetchGeyserJar(pluginDir: string, verAndBuild: string, filename: string): Promise<string | void>;
|
|
13
|
+
export declare function verifyViaProxyLoc(cwd: string, autoUpdate: boolean | undefined, javaLoc: string, location?: string): Promise<string>;
|
|
14
|
+
export declare function verifyGeyserLoc(pluginDir: string, autoUpdate?: boolean, location?: string): Promise<string>;
|
|
15
|
+
export declare function checkJavaVersion(javaLoc: string): Promise<number>;
|
|
16
|
+
export declare function openViaProxyGUI(javaLoc: string, fullpath: string, cwd: string): Promise<void>;
|
|
17
|
+
export declare function loadProxySaves(cwd: string, javaLoc: string, location: string): Promise<ViaProxySettings>;
|
|
18
|
+
export declare function modifyProxySaves(cwd: string, javaLoc: string, location: string, data: ViaProxyV3Config): Promise<void>;
|
|
19
|
+
export declare function identifyAccount(username: string, bedrock: boolean, javaLoc: string, location: string, wantedCwd: string, depth?: number, open?: boolean): Promise<number>;
|
|
20
|
+
export declare function configureGeyserConfig(pluginDir: string, localPort: number): void;
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,544 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.validateOptions = validateOptions;
|
|
16
|
+
exports.openAuthLogin = openAuthLogin;
|
|
17
|
+
exports.findOpenPort = findOpenPort;
|
|
18
|
+
exports.getSupportedMCVersions = getSupportedMCVersions;
|
|
19
|
+
exports.fetchViaProxyJar = fetchViaProxyJar;
|
|
20
|
+
exports.fetchGeyserJar = fetchGeyserJar;
|
|
21
|
+
exports.verifyViaProxyLoc = verifyViaProxyLoc;
|
|
22
|
+
exports.verifyGeyserLoc = verifyGeyserLoc;
|
|
23
|
+
exports.checkJavaVersion = checkJavaVersion;
|
|
24
|
+
exports.openViaProxyGUI = openViaProxyGUI;
|
|
25
|
+
exports.loadProxySaves = loadProxySaves;
|
|
26
|
+
exports.modifyProxySaves = modifyProxySaves;
|
|
27
|
+
exports.identifyAccount = identifyAccount;
|
|
28
|
+
exports.configureGeyserConfig = configureGeyserConfig;
|
|
29
|
+
const fs_1 = require("fs");
|
|
30
|
+
const path_1 = require("path");
|
|
31
|
+
const constants_1 = require("./constants");
|
|
32
|
+
const child_process_1 = require("child_process");
|
|
33
|
+
const js_yaml_1 = __importDefault(require("js-yaml"));
|
|
34
|
+
const path_2 = __importDefault(require("path"));
|
|
35
|
+
const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
|
36
|
+
const convNmp_1 = require("./convNmp");
|
|
37
|
+
const debug = require("debug")("mineflayer-viaproxy");
|
|
38
|
+
const minecraftFolderPath = require("minecraft-folder-path");
|
|
39
|
+
function validateOptions(options) {
|
|
40
|
+
if (options.profilesFolder == null) {
|
|
41
|
+
options.profilesFolder = path_2.default.join(minecraftFolderPath, "nmp-cache");
|
|
42
|
+
}
|
|
43
|
+
return options;
|
|
44
|
+
}
|
|
45
|
+
function openAuthLogin(bot) {
|
|
46
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
47
|
+
const listener = (packet) => {
|
|
48
|
+
const channel = packet.channel;
|
|
49
|
+
if (channel !== "oam:join")
|
|
50
|
+
return;
|
|
51
|
+
bot._client.write("login_plugin_response", {
|
|
52
|
+
messageId: packet.messageId,
|
|
53
|
+
data: Buffer.from([1]),
|
|
54
|
+
});
|
|
55
|
+
bot._client.removeListener("login_plugin_request", listener);
|
|
56
|
+
};
|
|
57
|
+
bot._client.removeAllListeners("login_plugin_request");
|
|
58
|
+
bot._client.on("login_plugin_request", listener);
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
function findOpenPort() {
|
|
62
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
63
|
+
const net = require("net");
|
|
64
|
+
const server = net.createServer();
|
|
65
|
+
return new Promise((resolve, reject) => {
|
|
66
|
+
server.listen(0, () => {
|
|
67
|
+
const port = server.address().port;
|
|
68
|
+
server.close(() => {
|
|
69
|
+
resolve(port);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
function viaProxyAvailable(cwd, use8) {
|
|
76
|
+
let regex;
|
|
77
|
+
if (use8) {
|
|
78
|
+
regex = /ViaProxy-\d+\.\d+\.\d+(-SNAPSHOT)?(-RELEASE)?\+java8\.jar/;
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
regex = /ViaProxy-\d+\.\d+\.\d+(-SNAPSHOT)?(-RELEASE)?\.jar/;
|
|
82
|
+
}
|
|
83
|
+
const valid = [];
|
|
84
|
+
const files = (0, fs_1.readdirSync)(cwd);
|
|
85
|
+
for (const file of files) {
|
|
86
|
+
if (regex.test(file))
|
|
87
|
+
valid.push(file);
|
|
88
|
+
}
|
|
89
|
+
if (valid.length === 0)
|
|
90
|
+
return null;
|
|
91
|
+
valid.sort(isGreaterThan);
|
|
92
|
+
return (0, path_1.join)(cwd, valid[0]);
|
|
93
|
+
}
|
|
94
|
+
function extractVersion(viaProxyPath) {
|
|
95
|
+
const filename = viaProxyPath.split("/").pop();
|
|
96
|
+
const version = filename.split("-")[1].split(".jar")[0];
|
|
97
|
+
return version;
|
|
98
|
+
}
|
|
99
|
+
function isGreaterThan(src, test) {
|
|
100
|
+
const srcArr = src.split(".").map((x) => parseInt(x));
|
|
101
|
+
const testArr = test.split(".").map((x) => parseInt(x));
|
|
102
|
+
for (let i = 0; i < srcArr.length; i++) {
|
|
103
|
+
if (srcArr[i] > testArr[i])
|
|
104
|
+
return 1;
|
|
105
|
+
if (srcArr[i] < testArr[i])
|
|
106
|
+
return -1;
|
|
107
|
+
}
|
|
108
|
+
return 0;
|
|
109
|
+
}
|
|
110
|
+
function geyserAvailable(cwd) {
|
|
111
|
+
const regex = /Geyser-\d+\.\d+\.\d+\.jar/;
|
|
112
|
+
const files = (0, fs_1.readdirSync)(cwd);
|
|
113
|
+
for (const file of files) {
|
|
114
|
+
if (regex.test(file))
|
|
115
|
+
return (0, path_1.join)(cwd, file);
|
|
116
|
+
}
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
function getViaProxyJarVersion() {
|
|
120
|
+
return __awaiter(this, arguments, void 0, function* (use8 = false) {
|
|
121
|
+
const req = yield fetch(constants_1.BASE_VIAPROXY_URL);
|
|
122
|
+
const html = yield req.text();
|
|
123
|
+
const versions = html.match(/ViaProxy-([0-9.]+)/);
|
|
124
|
+
if (versions == null) {
|
|
125
|
+
throw new Error("Failed to get ViaProxy version.");
|
|
126
|
+
}
|
|
127
|
+
const version = versions[1];
|
|
128
|
+
const snapshot = html.includes('SNAPSHOT');
|
|
129
|
+
let filename = 'ViaProxy-';
|
|
130
|
+
filename += version;
|
|
131
|
+
filename += snapshot ? '-SNAPSHOT' : '-RELEASE';
|
|
132
|
+
filename += use8 ? '+java8' : '';
|
|
133
|
+
filename += '.jar';
|
|
134
|
+
return { version, snapshot, filename };
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
function getSupportedMCVersions(javaLoc, cwd, filename) {
|
|
138
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
139
|
+
const test = (0, child_process_1.exec)(`${(0, constants_1.VIA_PROXY_CMD)(javaLoc, filename, true)} --list-versions`, { cwd: cwd });
|
|
140
|
+
let versions = [];
|
|
141
|
+
let seeStartVersions = false;
|
|
142
|
+
yield new Promise((resolve, reject) => {
|
|
143
|
+
let stdOutListener = (data) => {
|
|
144
|
+
var _a, _b;
|
|
145
|
+
const strData = data.toString();
|
|
146
|
+
if (!strData.includes("===") && !seeStartVersions)
|
|
147
|
+
return;
|
|
148
|
+
else if (strData.includes("===") && seeStartVersions) {
|
|
149
|
+
(_a = test.stdout) === null || _a === void 0 ? void 0 : _a.removeListener("data", stdOutListener);
|
|
150
|
+
(_b = test.stderr) === null || _b === void 0 ? void 0 : _b.removeListener("data", stdErrListener);
|
|
151
|
+
resolve();
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
if (strData.includes("===")) {
|
|
155
|
+
seeStartVersions = true;
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
const split = strData.split("\x1B[0m");
|
|
159
|
+
const version = split[split.length - 1].split('\n')[0];
|
|
160
|
+
versions.push(version);
|
|
161
|
+
};
|
|
162
|
+
let stdErrListener = (data) => {
|
|
163
|
+
var _a, _b;
|
|
164
|
+
console.error(data.toString());
|
|
165
|
+
(_a = test.stdout) === null || _a === void 0 ? void 0 : _a.removeListener("data", stdOutListener);
|
|
166
|
+
(_b = test.stderr) === null || _b === void 0 ? void 0 : _b.removeListener("data", stdErrListener);
|
|
167
|
+
reject();
|
|
168
|
+
return;
|
|
169
|
+
};
|
|
170
|
+
if (test.stdout != null) {
|
|
171
|
+
test.stdout.on("data", stdOutListener);
|
|
172
|
+
}
|
|
173
|
+
if (test.stderr != null) {
|
|
174
|
+
test.stderr.on("data", stdErrListener);
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
return versions;
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
function getGeyserJarVersion() {
|
|
181
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
182
|
+
const resp = yield fetch(`${constants_1.BASE_GEYSER_URL}/versions/latest/builds/latest`);
|
|
183
|
+
const version = resp.url.split("versions/")[1].split("/")[0];
|
|
184
|
+
const buildVer = resp.url.split("builds/")[1].split("/")[0];
|
|
185
|
+
const filename = `Geyser-${version}-${buildVer}.jar`;
|
|
186
|
+
return { version: `${version}-${buildVer}`, filename };
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
function fetchViaProxyJar(path, version, filename) {
|
|
190
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
191
|
+
const url = `${constants_1.BASE_VIAPROXY_URL}/artifact/build/libs/${filename}`;
|
|
192
|
+
const resp2 = yield fetch(url);
|
|
193
|
+
if (!resp2.ok) {
|
|
194
|
+
console.error(`Failed to download ViaProxy jar: ${resp2.statusText}`);
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
const filepath = (0, path_1.join)(path, filename);
|
|
198
|
+
const fileStream = (0, fs_1.createWriteStream)(filepath);
|
|
199
|
+
const stream = new WritableStream({
|
|
200
|
+
write(chunk) {
|
|
201
|
+
fileStream.write(chunk);
|
|
202
|
+
},
|
|
203
|
+
});
|
|
204
|
+
if (!resp2.body)
|
|
205
|
+
throw new Error("No body in response");
|
|
206
|
+
yield resp2.body.pipeTo(stream);
|
|
207
|
+
return filepath;
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
function fetchGeyserJar(pluginDir, verAndBuild, filename) {
|
|
211
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
212
|
+
const [version, build] = verAndBuild.split("-");
|
|
213
|
+
const url = `${constants_1.BASE_GEYSER_URL}/versions/${version}/builds/${build}/downloads/viaproxy`;
|
|
214
|
+
const resp2 = yield fetch(url);
|
|
215
|
+
if (!resp2.ok) {
|
|
216
|
+
console.error(`Failed to download Geyser jar: ${resp2.statusText}`);
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
const filepath = (0, path_1.join)(pluginDir, filename);
|
|
220
|
+
const fileStream = (0, fs_1.createWriteStream)(filepath);
|
|
221
|
+
const stream = new WritableStream({
|
|
222
|
+
write(chunk) {
|
|
223
|
+
fileStream.write(chunk);
|
|
224
|
+
},
|
|
225
|
+
});
|
|
226
|
+
if (!resp2.body)
|
|
227
|
+
throw new Error("No body in response");
|
|
228
|
+
yield resp2.body.pipeTo(stream);
|
|
229
|
+
return filepath;
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
function verifyViaProxyLoc(cwd_1) {
|
|
233
|
+
return __awaiter(this, arguments, void 0, function* (cwd, autoUpdate = true, javaLoc, location) {
|
|
234
|
+
if (!location || !(0, fs_1.existsSync)(location)) {
|
|
235
|
+
const javaVer = yield checkJavaVersion(javaLoc);
|
|
236
|
+
if (!autoUpdate) {
|
|
237
|
+
const viaProxy = viaProxyAvailable(cwd, javaVer < 17);
|
|
238
|
+
if (viaProxy) {
|
|
239
|
+
debug("Found ViaProxy jar in directory. Using that.");
|
|
240
|
+
return viaProxy;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
const { version, filename } = yield getViaProxyJarVersion(javaVer < 17);
|
|
244
|
+
if (autoUpdate) {
|
|
245
|
+
const testLoc = (0, path_1.join)(cwd, filename);
|
|
246
|
+
if ((0, fs_1.existsSync)(testLoc)) {
|
|
247
|
+
if (isGreaterThan(extractVersion(testLoc), version) >= 0) {
|
|
248
|
+
debug(`Found version ${extractVersion(testLoc)} of ViaProxy, which is good enough. Skipping download.`);
|
|
249
|
+
return testLoc;
|
|
250
|
+
}
|
|
251
|
+
else {
|
|
252
|
+
debug("Found older version of ViaProxy. Deleting.");
|
|
253
|
+
(0, fs_1.unlinkSync)(testLoc);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
else {
|
|
257
|
+
const available = viaProxyAvailable(cwd, javaVer < 17);
|
|
258
|
+
if (available) {
|
|
259
|
+
if (isGreaterThan(extractVersion(available), version) >= 0) {
|
|
260
|
+
debug(`Found version ${extractVersion(available)} of ViaProxy, which is good enough. Skipping download.`);
|
|
261
|
+
return available;
|
|
262
|
+
}
|
|
263
|
+
else {
|
|
264
|
+
debug(`Found older version of ViaProxy. Deleting and installing newer.`);
|
|
265
|
+
(0, fs_1.unlinkSync)(available);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
debug(`Fetching ViaProxy for java version ${version}.`);
|
|
271
|
+
const jar = yield fetchViaProxyJar(cwd, version, filename);
|
|
272
|
+
if (!jar)
|
|
273
|
+
throw new Error("Failed to fetch ViaProxy jar.");
|
|
274
|
+
return jar;
|
|
275
|
+
}
|
|
276
|
+
return location;
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
function verifyGeyserLoc(pluginDir_1) {
|
|
280
|
+
return __awaiter(this, arguments, void 0, function* (pluginDir, autoUpdate = true, location) {
|
|
281
|
+
if (!location || !(0, fs_1.existsSync)(location)) {
|
|
282
|
+
if (!autoUpdate) {
|
|
283
|
+
const geyser = geyserAvailable(pluginDir);
|
|
284
|
+
if (geyser) {
|
|
285
|
+
debug("Found Geyser jar in directory. Using that.");
|
|
286
|
+
return geyser;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
const { version, filename } = yield getGeyserJarVersion();
|
|
290
|
+
if (autoUpdate) {
|
|
291
|
+
const testLoc = (0, path_1.join)(pluginDir, filename);
|
|
292
|
+
if ((0, fs_1.existsSync)(testLoc)) {
|
|
293
|
+
debug("Geyser jar already exists, skipping download.");
|
|
294
|
+
return testLoc;
|
|
295
|
+
}
|
|
296
|
+
else {
|
|
297
|
+
const available = geyserAvailable(pluginDir);
|
|
298
|
+
if (available) {
|
|
299
|
+
(0, fs_1.unlinkSync)(available);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
debug(`Downloading Geyser jar at ${pluginDir}`);
|
|
304
|
+
const jar = yield fetchGeyserJar(pluginDir, version, filename);
|
|
305
|
+
if (!jar)
|
|
306
|
+
throw new Error("Failed to fetch Geyser jar.");
|
|
307
|
+
return jar;
|
|
308
|
+
}
|
|
309
|
+
return location;
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
function checkJavaVersion(javaLoc) {
|
|
313
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
314
|
+
const { stderr: stdout, exitCode } = yield (0, child_process_1.exec)(`${javaLoc} -version`);
|
|
315
|
+
if (exitCode != null && exitCode !== 0) {
|
|
316
|
+
throw new Error("Failed to check Java version. Most likely, java is not installed.");
|
|
317
|
+
}
|
|
318
|
+
return yield new Promise((resolve, reject) => {
|
|
319
|
+
if (stdout != null) {
|
|
320
|
+
stdout.on("data", (data) => {
|
|
321
|
+
const version = data.split(" ")[2].replace(/"/g, "");
|
|
322
|
+
const major = parseInt(version.split(".")[0]);
|
|
323
|
+
resolve(major);
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
});
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
function openViaProxyGUI(javaLoc, fullpath, cwd) {
|
|
330
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
331
|
+
console.log("opening ViaProxy. This is done to add your account.\nSimply close the window when you're done to allow the mineflayer code to continue.");
|
|
332
|
+
const test = (0, child_process_1.exec)((0, constants_1.VIA_PROXY_CMD)(javaLoc, fullpath, false), { cwd: cwd });
|
|
333
|
+
yield new Promise((resolve, reject) => {
|
|
334
|
+
test.on("close", (code) => {
|
|
335
|
+
resolve();
|
|
336
|
+
});
|
|
337
|
+
test.on("error", (err) => {
|
|
338
|
+
reject(err);
|
|
339
|
+
});
|
|
340
|
+
test.on("exit", (code) => {
|
|
341
|
+
resolve();
|
|
342
|
+
});
|
|
343
|
+
});
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
function loadProxySaves(cwd, javaLoc, location) {
|
|
347
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
348
|
+
const loc = (0, path_1.join)(cwd, "saves.json");
|
|
349
|
+
if (!(0, fs_1.existsSync)(loc)) {
|
|
350
|
+
debug("No saves.json found. Creating one by running ViaProxy CLI.");
|
|
351
|
+
debug(`Running command: ${(0, constants_1.VIA_PROXY_CMD)(javaLoc, location, true)}`);
|
|
352
|
+
const process = (0, child_process_1.exec)((0, constants_1.VIA_PROXY_CMD)(javaLoc, location, true), { cwd: cwd });
|
|
353
|
+
yield new Promise((resolve) => setTimeout(resolve, 3000));
|
|
354
|
+
process.kill();
|
|
355
|
+
yield new Promise((resolve) => setTimeout(() => resolve(), 2000));
|
|
356
|
+
const data = JSON.parse((0, fs_1.readFileSync)(loc, "utf-8"));
|
|
357
|
+
return data;
|
|
358
|
+
}
|
|
359
|
+
const data = JSON.parse((0, fs_1.readFileSync)(loc, "utf-8"));
|
|
360
|
+
debug("Loaded existing saves.json file for ViaProxy.");
|
|
361
|
+
return data;
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
function modifyProxySaves(cwd, javaLoc, location, data) {
|
|
365
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
366
|
+
const loc = (0, path_1.join)(cwd, "saves.json");
|
|
367
|
+
const saves = yield loadProxySaves(cwd, javaLoc, location);
|
|
368
|
+
const { newest, key } = latestAccountsKey(saves);
|
|
369
|
+
switch (newest) {
|
|
370
|
+
case 3:
|
|
371
|
+
const dataTyped = data;
|
|
372
|
+
const data1 = saves[key];
|
|
373
|
+
data1.push(...dataTyped.accountsV3);
|
|
374
|
+
break;
|
|
375
|
+
case 4:
|
|
376
|
+
const dataTyped4 = (0, convNmp_1.convToV4)(data);
|
|
377
|
+
const data4 = saves[key];
|
|
378
|
+
data4.push(...dataTyped4.accountsV4);
|
|
379
|
+
break;
|
|
380
|
+
default:
|
|
381
|
+
throw new Error(`Unsupported accounts version: ${newest}`);
|
|
382
|
+
}
|
|
383
|
+
(0, fs_1.writeFileSync)(loc, JSON.stringify(saves, null, 2), "utf-8");
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
function assertDepth(depth) {
|
|
387
|
+
if (depth < 0)
|
|
388
|
+
throw new Error("Invalid depth received (below zero). This should never be manually specified.");
|
|
389
|
+
}
|
|
390
|
+
function latestAccountsKey(saves) {
|
|
391
|
+
const versions = Object.keys(saves)
|
|
392
|
+
.filter((k) => k.startsWith("accountsV"))
|
|
393
|
+
.map((k) => Number(k.slice("accountsV".length)))
|
|
394
|
+
.filter((n) => Number.isFinite(n))
|
|
395
|
+
.sort((a, b) => a - b);
|
|
396
|
+
if (versions.length === 0)
|
|
397
|
+
throw new Error("No accountsV* keys found in saves.json.");
|
|
398
|
+
const newest = versions[versions.length - 1];
|
|
399
|
+
return { newest, key: `accountsV${newest}` };
|
|
400
|
+
}
|
|
401
|
+
function isBedrock(acc) {
|
|
402
|
+
var _a;
|
|
403
|
+
return (_a = acc.accountType) === null || _a === void 0 ? void 0 : _a.includes("Bedrock");
|
|
404
|
+
}
|
|
405
|
+
function isMicrosoft(acc) {
|
|
406
|
+
var _a;
|
|
407
|
+
return (_a = acc.accountType) === null || _a === void 0 ? void 0 : _a.includes("Microsoft");
|
|
408
|
+
}
|
|
409
|
+
function withSingleRetry(depth, open, onOpen, action) {
|
|
410
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
411
|
+
try {
|
|
412
|
+
return yield action();
|
|
413
|
+
}
|
|
414
|
+
catch (err) {
|
|
415
|
+
if (depth >= 1)
|
|
416
|
+
throw err;
|
|
417
|
+
if (!open)
|
|
418
|
+
throw err;
|
|
419
|
+
yield onOpen();
|
|
420
|
+
return yield action();
|
|
421
|
+
}
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
function getV3Names(accounts) {
|
|
425
|
+
var _a, _b, _c, _d;
|
|
426
|
+
const bedrockNames = [];
|
|
427
|
+
const javaNames = [];
|
|
428
|
+
for (const acc of accounts) {
|
|
429
|
+
if (isBedrock(acc))
|
|
430
|
+
bedrockNames.push((_b = (_a = acc.bedrockSession) === null || _a === void 0 ? void 0 : _a.mcChain) === null || _b === void 0 ? void 0 : _b.displayName);
|
|
431
|
+
else if (isMicrosoft(acc))
|
|
432
|
+
javaNames.push((_d = (_c = acc.javaSession) === null || _c === void 0 ? void 0 : _c.mcProfile) === null || _d === void 0 ? void 0 : _d.name);
|
|
433
|
+
}
|
|
434
|
+
return {
|
|
435
|
+
bedrockNames: bedrockNames.filter(Boolean),
|
|
436
|
+
javaNames: javaNames.filter(Boolean),
|
|
437
|
+
findBedrockIndex: (username) => accounts.findIndex((a) => { var _a, _b; return isBedrock(a) && ((_b = (_a = a.bedrockSession) === null || _a === void 0 ? void 0 : _a.mcChain) === null || _b === void 0 ? void 0 : _b.displayName) === username; }),
|
|
438
|
+
findJavaIndex: (username) => accounts.findIndex((a) => { var _a, _b; return isMicrosoft(a) && ((_b = (_a = a.javaSession) === null || _a === void 0 ? void 0 : _a.mcProfile) === null || _b === void 0 ? void 0 : _b.name) === username; }),
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
function getV4Names(accounts) {
|
|
442
|
+
var _a, _b, _c, _d;
|
|
443
|
+
const bedrockNames = [];
|
|
444
|
+
const javaNames = [];
|
|
445
|
+
for (const acc of accounts) {
|
|
446
|
+
if (isBedrock(acc)) {
|
|
447
|
+
const jwt1 = (_a = acc.minecraftCertificateChain) === null || _a === void 0 ? void 0 : _a.identityJwt;
|
|
448
|
+
if (!jwt1)
|
|
449
|
+
continue;
|
|
450
|
+
const decoded = jsonwebtoken_1.default.decode(jwt1, { complete: true });
|
|
451
|
+
const displayName = decoded ? (_c = (_b = decoded.payload) === null || _b === void 0 ? void 0 : _b.extraData) === null || _c === void 0 ? void 0 : _c.displayName : undefined;
|
|
452
|
+
if (displayName)
|
|
453
|
+
bedrockNames.push(displayName);
|
|
454
|
+
}
|
|
455
|
+
else if (isMicrosoft(acc)) {
|
|
456
|
+
const name = (_d = acc.minecraftProfile) === null || _d === void 0 ? void 0 : _d.name;
|
|
457
|
+
if (name)
|
|
458
|
+
javaNames.push(name);
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
return {
|
|
462
|
+
bedrockNames,
|
|
463
|
+
javaNames,
|
|
464
|
+
findBedrockIndex: (username) => accounts.findIndex((acc) => {
|
|
465
|
+
var _a, _b, _c;
|
|
466
|
+
if (!isBedrock(acc))
|
|
467
|
+
return false;
|
|
468
|
+
const jwt1 = (_a = acc.minecraftCertificateChain) === null || _a === void 0 ? void 0 : _a.identityJwt;
|
|
469
|
+
const decoded = jwt1 ? jsonwebtoken_1.default.decode(jwt1, { complete: true }) : null;
|
|
470
|
+
const dn = decoded ? (_c = (_b = decoded.payload) === null || _b === void 0 ? void 0 : _b.extraData) === null || _c === void 0 ? void 0 : _c.displayName : undefined;
|
|
471
|
+
return dn === username;
|
|
472
|
+
}),
|
|
473
|
+
findJavaIndex: (username) => accounts.findIndex((acc) => { var _a; return isMicrosoft(acc) && ((_a = acc.minecraftProfile) === null || _a === void 0 ? void 0 : _a.name) === username; }),
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
function identifyAccount(username_1, bedrock_1, javaLoc_1, location_1, wantedCwd_1) {
|
|
477
|
+
return __awaiter(this, arguments, void 0, function* (username, bedrock, javaLoc, location, wantedCwd, depth = 0, open = true) {
|
|
478
|
+
assertDepth(depth);
|
|
479
|
+
const onOpen = () => __awaiter(this, void 0, void 0, function* () {
|
|
480
|
+
debug(`Opening GUI.\nLocation: ${location}`);
|
|
481
|
+
yield openViaProxyGUI(javaLoc, location, wantedCwd);
|
|
482
|
+
});
|
|
483
|
+
const saves = yield withSingleRetry(depth, open, onOpen, () => __awaiter(this, void 0, void 0, function* () { return yield loadProxySaves(wantedCwd, javaLoc, location); })).catch((err) => __awaiter(this, void 0, void 0, function* () {
|
|
484
|
+
if (!open && depth === 0) {
|
|
485
|
+
debug(`Failed to load saves.json. Not opening GUI as 'open' is false.`);
|
|
486
|
+
return null;
|
|
487
|
+
}
|
|
488
|
+
throw err;
|
|
489
|
+
}));
|
|
490
|
+
if (saves == null)
|
|
491
|
+
return -1;
|
|
492
|
+
const { newest, key } = latestAccountsKey(saves);
|
|
493
|
+
const accounts = saves[key];
|
|
494
|
+
if (!Array.isArray(accounts) || accounts.length === 0) {
|
|
495
|
+
if (depth >= 1)
|
|
496
|
+
throw new Error("No accounts found.");
|
|
497
|
+
if (!open) {
|
|
498
|
+
debug(`No users in saves.json found. Not opening GUI as 'open' is false.`);
|
|
499
|
+
return -1;
|
|
500
|
+
}
|
|
501
|
+
debug(`No users in saves.json found. Opening GUI.`);
|
|
502
|
+
yield onOpen();
|
|
503
|
+
return identifyAccount(username, bedrock, javaLoc, location, wantedCwd, depth + 1, open);
|
|
504
|
+
}
|
|
505
|
+
const helper = newest === 3 ? getV3Names(accounts) :
|
|
506
|
+
newest === 4 ? getV4Names(accounts) :
|
|
507
|
+
null;
|
|
508
|
+
if (!helper)
|
|
509
|
+
throw new Error(`Unsupported account version: ${newest}.`);
|
|
510
|
+
debug(`Available Bedrock users: ${helper.bedrockNames.length ? helper.bedrockNames.join(", ") : "None"}`);
|
|
511
|
+
debug(`Available Java users: ${helper.javaNames.length ? helper.javaNames.join(", ") : "None"}`);
|
|
512
|
+
const names = bedrock ? helper.bedrockNames : helper.javaNames;
|
|
513
|
+
const label = bedrock ? "Bedrock" : "Microsoft";
|
|
514
|
+
const exists = names.includes(username);
|
|
515
|
+
if (!exists) {
|
|
516
|
+
if (depth >= 1) {
|
|
517
|
+
if (names.length === 0)
|
|
518
|
+
throw new Error(`No ${label} accounts found${bedrock ? " (even after opening GUI)" : ""}.`);
|
|
519
|
+
throw new Error(`No ${label} account saved with the account name ${username}.\nOptions: ${names.join(", ")}`);
|
|
520
|
+
}
|
|
521
|
+
if (!open) {
|
|
522
|
+
debug(`No ${label} account saved with the account name ${username}. Not opening GUI as 'open' is false.`);
|
|
523
|
+
return -1;
|
|
524
|
+
}
|
|
525
|
+
debug(`No ${label} account saved with the account name ${username}. Opening GUI.`);
|
|
526
|
+
yield onOpen();
|
|
527
|
+
return identifyAccount(username, bedrock, javaLoc, location, wantedCwd, depth + 1, open);
|
|
528
|
+
}
|
|
529
|
+
const idx = bedrock ? helper.findBedrockIndex(username) : helper.findJavaIndex(username);
|
|
530
|
+
return idx;
|
|
531
|
+
});
|
|
532
|
+
}
|
|
533
|
+
function configureGeyserConfig(pluginDir, localPort) {
|
|
534
|
+
const configPath = (0, path_1.join)(pluginDir, "Geyser/config.yml");
|
|
535
|
+
if (!(0, fs_1.existsSync)(configPath)) {
|
|
536
|
+
throw new Error("Geyser config not found.");
|
|
537
|
+
}
|
|
538
|
+
const config = (0, fs_1.readFileSync)(configPath, "utf-8");
|
|
539
|
+
const parsed = js_yaml_1.default.load(config);
|
|
540
|
+
parsed["bedrock"]["port"] = localPort;
|
|
541
|
+
const newConfig = js_yaml_1.default.dump(parsed);
|
|
542
|
+
(0, fs_1.writeFileSync)(configPath, newConfig);
|
|
543
|
+
}
|
|
544
|
+
//# sourceMappingURL=utils.js.map
|