Pocketmine init #79

Merged
Sirherobrine23 merged 10 commits from pocketMine into main 2021-04-10 03:23:21 +00:00
6 changed files with 123 additions and 14 deletions
Showing only changes of commit 51c20a5879 - Show all commits

View File

@ -5,6 +5,7 @@ const { resolve } = require("path");
const { error } = console;
const shell = require("shelljs");
const {getDesktopFolder, getConfigHome} = require("platform-folders")
const { execSync } = require("child_process");
const bds_core_package = resolve(__dirname, "package.json")
const bds_maneger_version = require(bds_core_package).version
@ -40,9 +41,10 @@ module.exports.package_path = bds_core_package
if (process.platform == "win32") {
home = process.env.USERPROFILE;
tmp = process.env.TMP
system = "windows";
system = "Windows";
valid_platform = {
"bedrock": true,
"pocketmine": true,
"java": true
}
} else if (process.platform == "linux") {
@ -50,9 +52,10 @@ if (process.platform == "win32") {
if (process.env.BDS_DOCKER_IMAGE) desktop = "/home/bds/"
else desktop = "/tmp"
tmp = "/tmp";
system = "linux";
system = "Linux";
valid_platform = {
"bedrock": true,
"pocketmine": true,
"java": true
}
} else if (process.platform == "darwin") {
@ -60,9 +63,10 @@ if (process.platform == "win32") {
else require("open")("https://github.com/The-Bds-Maneger/core/wiki/system_support#macos-with-intel-processors");
home = process.env.HOME;
tmp = "/tmp";
system = "macOS";
system = "MacOS";
valid_platform = {
"bedrock": false,
"pocketmine": true,
"java": true
}
} else {
@ -165,6 +169,15 @@ if (!(fs.existsSync(bds_dir_bedrock))){
}
module.exports.bds_dir_bedrock = bds_dir_bedrock
/* PocketMine Path */
const bds_dir_pocketmine = path.join(bds_dir, "pocketmine");
if (!(fs.existsSync(bds_dir_pocketmine))){
console.log("Creating the bds directory to Pocketmine")
fs.mkdirSync(bds_dir_pocketmine)
if (!(fs.existsSync(bds_dir_pocketmine))) shell.mkdir("-p", bds_dir_pocketmine);
}
module.exports.bds_dir_pocketmine = bds_dir_pocketmine
// Create backup folder
if (!(fs.existsSync(bds_dir_backup))){
fs.mkdirSync(bds_dir_backup)
@ -192,6 +205,18 @@ if (!(fs.existsSync(log_dir))){
if (typeof fetch === "undefined") global.fetch = require("node-fetch");
if (typeof localStorage === "undefined") global.localStorage = new require("node-localstorage").LocalStorage(path.join(LocalStorageFolder, "Local_Storage"));
/* Minecraft Servers URLs and depedencies */
// urls
const SERVER_URLs = JSON.parse(execSync("curl -sS \"https://raw.githubusercontent.com/Bds-Maneger/Raw_files/main/Server.json\"").toString())
module.exports.SERVER_URLs = SERVER_URLs
// PHP Bins
const PHPbinsUrl = JSON.parse(execSync("curl -sS \"https://raw.githubusercontent.com/The-Bds-Maneger/Raw_files/main/php_bin.json\"").toString())
module.exports.PHPbinsUrls = PHPbinsUrl
console.log(PHPbinsUrl);
const PHPurlNames = Object.getOwnPropertyNames(PHPbinsUrl)
module.exports.PHPurlNames = PHPurlNames
/* ---------------------------------------------------------------------------- Variables ---------------------------------------------------------------------------- */
// Configs
var bds_config, bds_config_file = path.join(bds_dir, "bds_config.json");
@ -376,7 +401,7 @@ if (require("fs").existsSync(path.join(bds_dir, "telegram_token.txt"))){
throw new error("It was not possible to move the old telegram token file to the new bds maneger api file")
}
}
const getSize = require("get-folder-size")
const getSize = require("get-folder-size");
getSize(bds_dir_backup, function(err, info) {
if (err) throw err
function toGB(x) {return (x / (1024 * 1024 * 1024)).toFixed(1);}

5
package-lock.json generated
View File

@ -1,12 +1,13 @@
{
"name": "@the-bds-maneger/core",
"version": "1.8.5.4",
"version": "1.8.6",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "@the-bds-maneger/core",
"version": "1.8.5.4",
"version": "1.8.6",
"hasInstallScript": true,
"license": "AGPL-3.0-or-later",
"dependencies": {
"adm-zip": "^0.5.1",

View File

@ -3,7 +3,7 @@
"publishConfig": {
"access": "public"
},
"version": "1.8.5.5",
"version": "1.8.6",
"description": "scripts to manage minecraft bedrock server",
"private": false,
"main": "index.js",
@ -12,7 +12,8 @@
"eslint": "eslint .",
"eslint:fix": "eslint --fix .",
"start": "node bin/bds_maneger.js",
"debug": "node bin/debug.js"
"debug": "node bin/debug.js",
"postinstall": "node ./postinstall/curlCheck.js"
},
"bin": {
"bds_maneger": "./bin/bds_maneger.js"

28
postinstall/curlCheck.js Normal file
View File

@ -0,0 +1,28 @@
const { existsSync, mkdirSync, writeFileSync, chmodSync } = require("fs")
const { resolve, join } = require("path")
const binFolder = resolve((process.env.USERPROFILE||process.env.HOME), "bds_core", "bin")
if (typeof fetch === "undefined") {var fetch = require("node-fetch")}
(function (){
if (require("command-exists").sync("curl")) {console.log("Curl is already installed.");process.exit(0)}
else {
if (!(existsSync(binFolder))) mkdirSync(binFolder)
if (process.platform === "linux"){
fetch("https://api.github.com/repos/moparisthebest/static-curl/releases").then(response => response.json()).then(function (res){
var arch = process.arch
if (arch === "x64") arch = "amd64"
let url = `https://github.com/moparisthebest/static-curl/releases/download/${res[0].tag_name}/curl-${arch}`
console.log(url);
fetch(url).then(response => response.arrayBuffer()).then(response => Buffer.from(response)).then(response => {
writeFileSync(join(binFolder, "curl"), response, "binary")
chmodSync(join(binFolder, "curl"), 7777)
process.exit(0)
}).catch(function (err){if (err) {console.log(err);process.exit(1)}})
})
} else if (process.platform === "darwin") throw Error("You will have to install cURL manually, download page: https://curl.se/download.html");
else if (process.platform === "win32") {
if (Math.trunc(require("os").release()) === "10") throw Error("Please make sure you are on the latest version of Windows 10");
else throw Error(`Please manually install curl for Windows ${Math.trunc(require("os").release())}, download page: https://curl.se/download.html`)
} else throw Error("Please install curl manually, download page: https://curl.se/download.html")
}
})()

View File

@ -3,7 +3,8 @@ const Storage = localStorage;
const {exec, execSync} = require("child_process");
const fs = require("fs")
const path = require("path")
const {CheckBan} = require("./check")
const {CheckBan} = require("./check");
const { resolve } = require("path");
module.exports.start = () => {
function KickPlayer(player){
@ -41,7 +42,7 @@ module.exports.start = () => {
}, cwd: bds.bds_dir_bedrock});
} else if (process.platform === "darwin") throw Error("We don't have MacOS support yet")
else process.exit(210)
} else {
} else if (plat === "java") {
if (require("command-exists").sync("java")) start_server = exec(`java -Xmx${bds.bds_config.java_config.max}M -Xms${bds.bds_config.java_config.max}M -jar server.jar nogui`, {cwd: bds.bds_dir_java});
else {
if (bds.system == "windows"){
@ -55,7 +56,11 @@ module.exports.start = () => {
console.log("http://docs.sirherobrine23.com/scripts/_java")
}
}
}
} else if (plat === "pocketmine") {
start_server = exec(`${resolve(bds.bds_dir_pocketmine, "bin/php7/bin/php")} ${resolve(bds.bds_dir_pocketmine, "PocketMine-MP.phar")}`, {env: {
...process.env,
}, cwd: bds.bds_dir_pocketmine});
} else throw Error("")
Storage.setItem("old_log_file", bds.log_file)
start_server.stdout.on("data", function(data){
if (data.includes("agree", "EULA")){

View File

@ -2,9 +2,11 @@ var AdmZip = require("adm-zip");
const { warn } = require("console");
const {writeFileSync, existsSync, readFileSync} = require("fs");
const { join } = require("path");
const {bds_config, bds_dir_bedrock, bds_dir_java, platform_version_update, valid_platform} = require("../index")
const {bds_config, bds_dir_bedrock, bds_dir_java, platform_version_update, valid_platform, PHPurlNames, bds_dir_pocketmine, PHPbinsUrls} = require("../index")
const bdsSystem = require("../index").system
const response = require("../index").SERVER_URLs
module.exports = function (version, force_install) {
return fetch("https://raw.githubusercontent.com/Bds-Maneger/Raw_files/main/Server.json").then(response => response.json()).then(response => {
try {
if (version === "") version="latest"
if (version === undefined) version="latest"
const server_platform = bds_config.bds_platform
@ -61,6 +63,53 @@ module.exports = function (version, force_install) {
if (process.env.BDS_DOCKER_IMAGE === "true") process.exit(0);
}
} else throw Error("Java not suported")
} else if (server_platform === "pocketmine") {
if (valid_platform.pocketmine === true) {
if (version === "latest") version = response.PocketMine_latest
url = response.PocketMine[version].url
console.log(`Server data publish: ${response.PocketMine[version].data}`)
console.log(bds_dir_pocketmine);
fetch(url).then(response => response.arrayBuffer()).then(response => Buffer.from(response)).then(response => {
writeFileSync(join(bds_dir_pocketmine, "PocketMine-MP.phar"), response, "binary")
console.log("PocketMine-MP.phar saved");
platform_version_update(version)
const binFolder = join(bds_dir_pocketmine, "bin")
if (!(existsSync(binFolder))) {
var urlPHPBin;
for (let index in PHPurlNames){
const nameFile = PHPurlNames[index]
var archS;
if (process.platform === "linux") if (process.arch === "x64") archS = "x86_64";
if (process.platform === "darwin") if (process.arch === "x64") archS = "x86_64";
if (process.platform === "win32") if (process.arch === "x64") archS = "x64";
var arch = false, system = false;
if (nameFile.includes(bdsSystem)) system = true
if (nameFile.includes(archS)) arch = true
// -*-*-*-*-
console.log({
arch,
system
});
if (arch === true && system === true){
urlPHPBin = PHPbinsUrls[nameFile]
}
}
if (urlPHPBin === undefined) throw Error("File not found")
else {
console.log(urlPHPBin);
fetch(urlPHPBin).then(response => response.arrayBuffer()).then(response => Buffer.from(response)).then(response => {
console.log("Download Sucess")
var zipExtractBin = new AdmZip(response);
zipExtractBin.extractAllTo(bds_dir_pocketmine, true)
console.log("Extract Sucess")
if (process.env.BDS_DOCKER_IMAGE === "true") process.exit(0);
})
}
} else if (process.env.BDS_DOCKER_IMAGE === "true") process.exit(0);
})
} else throw Error("Pocketmine not suported")
} else throw Error("Bds maneger Config file error")
}).catch(function (err){if (err) throw err;})
} catch (error) {
console.error(error);
}
}