Fix bedrock
This commit is contained in:
14
package-lock.json
generated
14
package-lock.json
generated
@ -9,7 +9,7 @@
|
||||
"version": "4.2.3",
|
||||
"license": "GPL-3.0",
|
||||
"dependencies": {
|
||||
"@the-bds-maneger/server_versions": "^4.0.1",
|
||||
"@the-bds-maneger/server_versions": "^4.1.2",
|
||||
"adm-zip": "^0.5.9",
|
||||
"axios": "^0.27.2",
|
||||
"cron": "^2.1.0",
|
||||
@ -91,9 +91,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@the-bds-maneger/server_versions": {
|
||||
"version": "4.1.1",
|
||||
"resolved": "https://registry.npmjs.org/@the-bds-maneger/server_versions/-/server_versions-4.1.1.tgz",
|
||||
"integrity": "sha512-WUQ50JrCFA9bSqNdLBrUu6bfH1OP4BsRioBK4Qr0+dcx0ajA7JRL1LgSxYpkTw9oioQrLoIAaHm4Pd/lTchprg==",
|
||||
"version": "4.1.2",
|
||||
"resolved": "https://registry.npmjs.org/@the-bds-maneger/server_versions/-/server_versions-4.1.2.tgz",
|
||||
"integrity": "sha512-SzQmDOKV+7Lwmqaew8QzeQYvSNpO0a87dZa8ddaXI0FFvH05rrjlJ6r5xNtuz/7rgYi53k/yteBUNi2JXQf/8Q==",
|
||||
"dependencies": {
|
||||
"axios": "^0.27.2",
|
||||
"cors": "^2.8.5",
|
||||
@ -3193,9 +3193,9 @@
|
||||
}
|
||||
},
|
||||
"@the-bds-maneger/server_versions": {
|
||||
"version": "4.1.1",
|
||||
"resolved": "https://registry.npmjs.org/@the-bds-maneger/server_versions/-/server_versions-4.1.1.tgz",
|
||||
"integrity": "sha512-WUQ50JrCFA9bSqNdLBrUu6bfH1OP4BsRioBK4Qr0+dcx0ajA7JRL1LgSxYpkTw9oioQrLoIAaHm4Pd/lTchprg==",
|
||||
"version": "4.1.2",
|
||||
"resolved": "https://registry.npmjs.org/@the-bds-maneger/server_versions/-/server_versions-4.1.2.tgz",
|
||||
"integrity": "sha512-SzQmDOKV+7Lwmqaew8QzeQYvSNpO0a87dZa8ddaXI0FFvH05rrjlJ6r5xNtuz/7rgYi53k/yteBUNi2JXQf/8Q==",
|
||||
"requires": {
|
||||
"axios": "^0.27.2",
|
||||
"cors": "^2.8.5",
|
||||
|
@ -31,7 +31,7 @@
|
||||
"node": ">=16.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@the-bds-maneger/server_versions": "^4.0.1",
|
||||
"@the-bds-maneger/server_versions": "^4.1.2",
|
||||
"adm-zip": "^0.5.9",
|
||||
"axios": "^0.27.2",
|
||||
"cron": "^2.1.0",
|
||||
|
60
src/plugin/bedrock.ts
Normal file
60
src/plugin/bedrock.ts
Normal file
@ -0,0 +1,60 @@
|
||||
import path from "node:path";
|
||||
import fs from "node:fs/promises";
|
||||
import admZip from "adm-zip";
|
||||
import { serverPath as pocketmineServerPath } from "../pocketmine";
|
||||
import { serverPath as powernukkittServerPath } from "../pwnuukit";
|
||||
import { existsSync } from "node:fs";
|
||||
import { saveFile } from "../httpRequest";
|
||||
const defaultFolder = path.join(__dirname, "plugins");
|
||||
|
||||
export type pluginPlatform = "pocketmine"|"powernukkit";
|
||||
export type pluginConfig = {
|
||||
name: string,
|
||||
fileName?: string,
|
||||
url: string,
|
||||
type?: "zip"|"jar",
|
||||
platforms: pluginPlatform[],
|
||||
dependes?: (string|pluginConfig)[]
|
||||
};
|
||||
|
||||
export default class plugin_maneger {
|
||||
#platform: pluginPlatform = "pocketmine";
|
||||
pluginList: pluginConfig[] = [];
|
||||
getPlatform() {return this.#platform};
|
||||
|
||||
async #addPlugin (file?: string): Promise<pluginConfig|void> {
|
||||
const config: pluginConfig = JSON.parse(await fs.readFile(path.join(defaultFolder, file), "utf8"));
|
||||
if (this.pluginList.some(plugin => plugin.name === config.name)) return config;
|
||||
if (!config.platforms.includes(this.#platform)) return;
|
||||
this.pluginList.push(config);
|
||||
if (config.dependes) {
|
||||
config.dependes = await Promise.all(config.dependes.filter(depend => typeof depend === "string"?depend.startsWith("./"):false).map((depend: string) => this.#addPlugin(depend.replace("./", "")))) as pluginConfig[];
|
||||
}
|
||||
};
|
||||
|
||||
async installPlugin(name: string) {
|
||||
const plugin = this.pluginList.find(plugin => plugin.name === name);
|
||||
if (!plugin) throw new Error(`${name} plugin not avaible to install`);
|
||||
console.log("Installing %s plugin", plugin.name);
|
||||
const pluginFolder = path.join(this.#platform === "pocketmine"?pocketmineServerPath:powernukkittServerPath, "plugins");
|
||||
if (!existsSync(pluginFolder)) await fs.mkdir(pluginFolder, {recursive: true});
|
||||
const saveOut = path.join(pluginFolder, plugin.fileName||`${plugin.name}.${path.extname(plugin.fileName||plugin.url)}`);
|
||||
await saveFile(plugin.url, {filePath: saveOut});
|
||||
if (plugin.type === "zip") {
|
||||
const zip = new admZip(saveOut);
|
||||
zip.extractAllTo(pluginFolder, true);
|
||||
await fs.rm(saveOut, {force: true});
|
||||
}
|
||||
if (plugin.dependes) await Promise.all(plugin.dependes.map((depend: pluginConfig) => this.installPlugin(depend.name)));
|
||||
}
|
||||
|
||||
async loadPlugins() {
|
||||
for (const file of await fs.readdir(defaultFolder)) await this.#addPlugin(file);
|
||||
return this;
|
||||
}
|
||||
|
||||
constructor(platform: pluginPlatform, autoLoad: boolean = true) {
|
||||
this.#platform = platform;
|
||||
if (autoLoad) this.loadPlugins();
|
||||
}
|
||||
};
|
8
src/plugin/plugins/MobPlugin.json
Normal file
8
src/plugin/plugins/MobPlugin.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"name": "MobPlugin",
|
||||
"url": "https://cloudburstmc.org/resources/mobplugin.3/download",
|
||||
"fileName": "MobPlugin.jar",
|
||||
"platforms": [
|
||||
"powernukkit"
|
||||
]
|
||||
}
|
@ -3,7 +3,7 @@ import * as fs from "node:fs/promises";
|
||||
import * as os from "node:os";
|
||||
import * as tar from "tar";
|
||||
import { existsSync as fsExistsSync } from "node:fs";
|
||||
import { platformManeger, versionURLs } from "@the-bds-maneger/server_versions";
|
||||
import { platformManeger } from "@the-bds-maneger/server_versions";
|
||||
import { execFileAsync } from './childPromisses';
|
||||
import { logRoot, serverRoot } from "./pathControl";
|
||||
import { getBuffer } from "./httpRequest";
|
||||
@ -53,18 +53,15 @@ async function buildPhp() {
|
||||
}
|
||||
|
||||
async function installPhp(): Promise<void> {
|
||||
const file = (await getBuffer(`${versionURLs[0]}/pocketmine/bin?os=${process.platform}&arch=${process.arch}`).then(res => JSON.parse(res.toString("utf8")) as {url: string, name: string}[]))[0];
|
||||
const file = await platformManeger.pocketmine.getPhp({});
|
||||
if (!file) return buildPhp();
|
||||
if (fsExistsSync(path.resolve(serverPath, "bin"))) await fs.rm(path.resolve(serverPath, "bin"), {recursive: true});
|
||||
await fs.mkdir(path.resolve(serverPath, "bin"), {recursive: true});
|
||||
// Tar.gz
|
||||
if (/tar\.gz/.test(file.name)) {
|
||||
await fs.writeFile(path.join(os.tmpdir(), file.name), await getBuffer(file.url));
|
||||
await fs.writeFile(path.join(os.tmpdir(), file.name), file.buffer);
|
||||
await tar.extract({file: path.join(os.tmpdir(), file.name), C: path.join(serverPath, "bin"), keep: true, p: true, noChmod: false});
|
||||
} else {
|
||||
const zip = new AdmZip(await getBuffer(file.url));
|
||||
await promisify(zip.extractAllToAsync)(serverPath, false, true);
|
||||
}
|
||||
} else await promisify((new AdmZip(file.buffer)).extractAllToAsync)(serverPath, false, true);
|
||||
if (process.platform === "linux"||process.platform === "android"||process.platform === "darwin") {
|
||||
const ztsFind = await Readdir(path.resolve(serverPath, "bin"), [/.*debug-zts.*/]);
|
||||
if (ztsFind.length > 0) {
|
||||
@ -76,7 +73,7 @@ async function installPhp(): Promise<void> {
|
||||
}
|
||||
}
|
||||
// test it's works php
|
||||
await fs.writeFile(path.join(os.tmpdir(), "test.php"), `<?php echo "Hello World";`);
|
||||
await fs.writeFile(path.join(os.tmpdir(), "bds_test.php"), `<?php echo "Hello World";`);
|
||||
await execFileAsync(phpBinPath, ["-f", path.join(os.tmpdir(), "test.php")]).catch(buildPhp);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user