Dragonfly full support #199

Merged
Sirherobrine23 merged 4 commits from Dragonfly_Sirherobrine23 into main 2021-09-28 02:32:17 +00:00
12 changed files with 386 additions and 320 deletions

View File

@ -21,7 +21,8 @@
],
"java": [],
"pocketmine": [],
"spigot": []
"spigot": [],
"dragonfly": []
},
"StartedServer": {
"bedrock": {
@ -39,12 +40,22 @@
"spigot": {
"value": null,
"regex": false
},
"dragonfly": {
"value": null,
"regex": false
}
},
"Servers": {
"bedrock": {
"stop": "stop",
"op": "op \"{{Player}}\"",
"stop": {
"value": "stop",
"type": "command"
},
"op": {
"value": "op \"{{}}\"",
"type": "command"
},
"deop": "op \"{{Player}}\"",
"ban": "tp \"{{Player}}\" ~ ~99999 ~",
"kick": "kick \"{{Player}}\" \"{{Text}}\"",
@ -61,13 +72,64 @@
"say": "say {{Text}}"
},
"pocketmine": {
"stop": "stop",
"op": "op {{Player}}",
"deop": "op {{Player}}",
"ban": "ban {{Player}}",
"kick": "kick {{Player}}",
"tp": "tp \"{{Player}}\" {{X}} {{Y}} {{X}}",
"say": "say {{Text}}"
"stop": {
"value": "stop",
"type": "command"
},
"op": {
"value": "op {{Player}}",
"type": "command"
},
"deop": {
"value": "deop {{Player}}",
"type": "command"
},
"ban": {
"value": "ban {{Player}}",
"type": "command"
},
"kick": {
"value": "kick {{Player}}",
"type": "command"
},
"tp": {
"value": "tp {{Player}} {{X}} {{Y}} {{X}}",
"type": "command"
},
"say": {
"value": "say {{Text}}",
"type": "command"
}
},
"dragonfly": {
"stop": {
"value": "SIGNKILL",
"type": "process"
},
"op": {
"value": null,
"type": null
},
"deop": {
"value": null,
"type": null
},
"ban": {
"value": null,
"type": null
},
"kick": {
"value": null,
"type": null
},
"tp": {
"value": null,
"type": null
},
"say": {
"value": null,
"type": null
}
}
},
"contributors": [

View File

@ -82,5 +82,4 @@ async function Command() {
}
module.exports.Command = Command;
module.exports.TpMenu = TpMenu;
TpMenu();
module.exports.TpMenu = TpMenu;

View File

@ -14,7 +14,8 @@ const ProcessArgs = require("minimist")(process.argv.slice(2));
const BdsCore = require("../index");
const BdsReq = require("../lib/Requests");
const BdsExtraInfo = require("../BdsManegerInfo.json");
const commandExits = require("../lib/commandExist")
const commandExits = require("../lib/commandExist");
const BdsMenus = require("./bds_maneger/menus");
// Async functiona
async function Runner() {
@ -100,16 +101,16 @@ async function Runner() {
serverline.setPrompt("Command > ");
serverline.on("line", async function(line) {
if (/^@/.test(line)) {
console.log("🤪It's not working yet!");
// const command = (await inquirer.prompt([
// {
// type: "list",
// name: "command",
// message: "Select the command to run",
// choices: ["tp", "stop", "restart", "update", "info", "download"]
// }
// ])).command;
serverline.close();
if (/^@stop/.test(line)) {
BdsCoreStart.stop();
return;
} else if (/^@tp/.test(line)) {
await BdsMenus.TpMenu();
}
return serverline.init();
} else BdsCoreStart.command(line);
});
if (!(ProcessArgs["no-api"])) BdsCore.api()
}
Runner();

View File

@ -2,6 +2,7 @@ const { join, resolve, basename } = require("path");
const { existsSync, writeFileSync, mkdirSync, readFileSync } = require("fs");
const { homedir } = require("os");
const yaml = require("js-yaml");
const deepmerge = require("deepmerge");
// PATHs
const home = homedir();
@ -37,6 +38,7 @@ var Config = {
java: null,
pocketmine: null,
spigot: null,
dragonfly: null
},
Settings: {
java: {
@ -105,7 +107,7 @@ const ConfigPath = join(resolve(homedir(), "bds_core"), "BdsConfig.yaml")
const SaveConfig = () => writeFileSync(ConfigPath, yaml.dump(Config));
process.on("exit", () => SaveConfig());
if (existsSync(ConfigPath)) Config = yaml.load(readFileSync(ConfigPath, "utf8"));
if (existsSync(ConfigPath)) Config = deepmerge(Config, yaml.load(readFileSync(ConfigPath, "utf8")));
else writeFileSync(ConfigPath, yaml.dump(Config))
// Paths

View File

@ -3,6 +3,7 @@ const { readdirSync } = require("fs");
const { execSync } = require("child_process");
const commadExist = require("./commandExist");
const Request = require("./Requests");
const bds = require("../index");
async function CheckSystemAsync() {
const
@ -14,12 +15,15 @@ async function CheckSystemAsync() {
bedrock: true,
pocketmine: true,
java: commadExist("java"),
dragonfly: commadExist("go"),
dragonfly: true
};
// check php bin
if ((PHPBin[process.platform] || {})[arch]) valid_platform["pocketmine"] = true;
else valid_platform["pocketmine"] = false;
else valid_platform["pocketmine"] = false;
//
if (!(Servers.dragonfly[Servers.latest.dragonfly][process.platform][bds.arch])) valid_platform["dragonfly"] = false;
// SoSystem X
if (process.platform == "win32") {

25
package-lock.json generated
View File

@ -16,11 +16,13 @@
],
"dependencies": {
"@azure/storage-blob": "^12.6.0",
"@iarna/toml": "^2.2.5",
"adm-zip": "^0.5.1",
"body-parser": "^1.19.0",
"cli-color": "^2.0.0",
"cors": "^2.8.5",
"cron": "^1.8.2",
"deepmerge": "^4.2.2",
"express": "^4.17.1",
"express-fileupload": "^1.2.1",
"express-prettify": "^0.1.1",
@ -395,6 +397,11 @@
"integrity": "sha512-wdppn25U8z/2yiaT6YGquE6X8sSv7hNMWSXYSSU1jGv/yd6XqjXgTDJ8KP4NgjTXfJ3GbRjeeb8RTV7a/VpM+w==",
"dev": true
},
"node_modules/@iarna/toml": {
"version": "2.2.5",
"resolved": "https://registry.npmjs.org/@iarna/toml/-/toml-2.2.5.tgz",
"integrity": "sha512-trnsAYxU3xnS1gPHPyU961coFyLkh4gAD/0zQ5mymY4yOZ+CYvsPqUbOFSw0aDM4y0tV7tiFxL/1XfXPNC6IPg=="
},
"node_modules/@opentelemetry/api": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/@opentelemetry/api/-/api-1.0.3.tgz",
@ -1350,6 +1357,14 @@
"integrity": "sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ==",
"dev": true
},
"node_modules/deepmerge": {
"version": "4.2.2",
"resolved": "https://registry.npmjs.org/deepmerge/-/deepmerge-4.2.2.tgz",
"integrity": "sha512-FJ3UgI4gIl+PHZm53knsuSFpE+nESMr7M4v9QcgB7S63Kj/6WqMiFQJpBBYz1Pt+66bZpP3Q7Lye0Oo9MPKEdg==",
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/defaults": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/defaults/-/defaults-1.0.3.tgz",
@ -5983,6 +5998,11 @@
"integrity": "sha512-wdppn25U8z/2yiaT6YGquE6X8sSv7hNMWSXYSSU1jGv/yd6XqjXgTDJ8KP4NgjTXfJ3GbRjeeb8RTV7a/VpM+w==",
"dev": true
},
"@iarna/toml": {
"version": "2.2.5",
"resolved": "https://registry.npmjs.org/@iarna/toml/-/toml-2.2.5.tgz",
"integrity": "sha512-trnsAYxU3xnS1gPHPyU961coFyLkh4gAD/0zQ5mymY4yOZ+CYvsPqUbOFSw0aDM4y0tV7tiFxL/1XfXPNC6IPg=="
},
"@opentelemetry/api": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/@opentelemetry/api/-/api-1.0.3.tgz",
@ -6714,6 +6734,11 @@
"integrity": "sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ==",
"dev": true
},
"deepmerge": {
"version": "4.2.2",
"resolved": "https://registry.npmjs.org/deepmerge/-/deepmerge-4.2.2.tgz",
"integrity": "sha512-FJ3UgI4gIl+PHZm53knsuSFpE+nESMr7M4v9QcgB7S63Kj/6WqMiFQJpBBYz1Pt+66bZpP3Q7Lye0Oo9MPKEdg=="
},
"defaults": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/defaults/-/defaults-1.0.3.tgz",

View File

@ -54,11 +54,13 @@
],
"dependencies": {
"@azure/storage-blob": "^12.6.0",
"@iarna/toml": "^2.2.5",
"adm-zip": "^0.5.1",
"body-parser": "^1.19.0",
"cli-color": "^2.0.0",
"cors": "^2.8.5",
"cron": "^1.8.2",
"deepmerge": "^4.2.2",
"express": "^4.17.1",
"express-fileupload": "^1.2.1",
"express-prettify": "^0.1.1",

View File

@ -12,6 +12,7 @@ function Backup() {
java: GetServerPaths("java"),
pocketmine: GetServerPaths("pocketmine"),
spigot: GetServerPaths("spigot"),
dragonfly: GetServerPaths("dragonfly"),
}
const CurrentDate = new Date();
const ZipName = `Bds_Maneger_Core_Backups_${CurrentDate.getDate()}-${CurrentDate.getMonth()}-${CurrentDate.getFullYear()}.zip`
@ -35,6 +36,20 @@ function Backup() {
for (let index of ["pocketmine.yml", "server.properties", "white-list.txt", "ops.txt", "banned-players.txt", "banned-ips.txt"]) if (fs.existsSync(join(Paths.pocketmine, index))) zip.addLocalFile(join(Paths.pocketmine, index), "pocketmine");
} else console.info("Skipping the pocketmine as it was not installed");
// Spigot
if (fs.existsSync(join(Paths.spigot, "spigot.jar"))) {
if (fs.existsSync(join(Paths.spigot, "worlds"))) zip.addLocalFolder(join(Paths.spigot, "worlds"), join("Servers", "spigot", "worlds"));
for (let index of ["spigot.yml", "server.properties", "white-list.txt", "ops.txt", "banned-players.txt", "banned-ips.txt"]) if (fs.existsSync(join(Paths.spigot, index))) zip.addLocalFile(join(Paths.spigot, index), "spigot");
} else console.info("Skipping the spigot as it was not installed");
// Dragonfly
if (fs.existsSync(join(Paths.dragonfly, "config.toml"))) {
for (let index of fs.readdirSync(Paths.dragonfly).map(value => join(Paths.dragonfly, value))) {
if (fs.lstatSync(index).isDirectory()) zip.addLocalFolder(index, join("Servers", "dragonfly"));
else if (fs.lstatSync(index).isFile()) zip.addLocalFile(index, join("Servers", "dragonfly"));
}
} else console.info("Skipping the dragonfly as it was not installed");
// The Bds Maneger Core Backup
for (let index of ["BdsConfig.yaml", "bds_tokens.json"]) if (fs.existsSync(join(bds_dir, index))) zip.addLocalFile(join(bds_dir, index));

View File

@ -9,15 +9,14 @@ const commandExists = require("../lib/commandExist");
const BdsDetect = require("./CheckKill").Detect;
const bds = require("../index");
const { GetServerPaths, GetPaths, GetServerSettings, GetPlatform, GetCronBackup } = require("../lib/BdsSettings");
const BdsInfo = require("../BdsManegerInfo.json");
const { Backup } = require("./BdsBackup");
// Set bdsexec functions
global.BdsExecs = {};
function start() {
if (BdsDetect()){let ErrorReturn = "You already have a server running"; console.warn(ErrorReturn); throw new Error(ErrorReturn);}
if (BdsDetect()) throw new Error("You already have a server running");
const CurrentBdsPlatform = GetPlatform();
const SetupCommands = {
command: String,
args: [],
@ -28,7 +27,7 @@ function start() {
}
// Minecraft Bedrock Oficial
if (GetPlatform() === "bedrock"){
if (CurrentBdsPlatform === "bedrock"){
// Check Darwin Platform
if (process.platform === "darwin") throw new Error("Use a imagem Docker");
@ -57,7 +56,7 @@ function start() {
}
// Minecraft Java Oficial
else if (GetPlatform() === "java") {
else if (CurrentBdsPlatform === "java") {
const JavaConfig = GetServerSettings("java")
// Checking if java is installed on the device
@ -68,8 +67,30 @@ function start() {
} else {require("open")(bds.package_json.docs_base + "Java-Download#windows"); throw new Error(`Open: ${bds.package_json.docs_base + "Java-Download#windows"}`)}
}
// Spigot
else if (CurrentBdsPlatform === "spigot") {
const JavaConfig = GetServerSettings("java")
// Checking if java is installed on the device
if (commandExists("java")) {
SetupCommands.cwd = GetServerPaths("spigot");
SetupCommands.command = "java";
SetupCommands.args.push("-jar", `-Xms${JavaConfig.ram_mb}M`, `-Xmx${JavaConfig.ram_mb}M`, "spigot.jar", "nogui");
} else {require("open")(bds.package_json.docs_base + "Java-Download#windows"); throw new Error(`Open: ${bds.package_json.docs_base + "Java-Download#windows"}`)}
}
// Dragonfly
else if (CurrentBdsPlatform === "dragonfly") {
SetupCommands.cwd = GetServerPaths("dragonfly");
if (process.platform === "win32") {
SetupCommands.command = "Dragonfly.exe";
} else {
SetupCommands.command = "./Dragonfly";
child_process.execFileSync("chmod", ["a+x", SetupCommands.command], {cwd: SetupCommands.cwd});
}
}
// Minecraft Bedrock (Pocketmine-MP)
else if (GetPlatform() === "pocketmine") {
else if (CurrentBdsPlatform === "pocketmine") {
// Start PocketMine-MP
SetupCommands.command = path.join(path.resolve(GetServerPaths("pocketmine"), "bin", "php7", "bin"), "php");
if (process.platform === "win32") SetupCommands.command = path.join(path.resolve(GetServerPaths("pocketmine"), "bin/php"), "php.exe");
@ -109,22 +130,7 @@ function start() {
ServerExec.stdout.on("data", data => {if (global.bds_log_string) global.bds_log_string = data; else global.bds_log_string += data});
// sets bds core commands
const command = async function (command = "list", callback = function (){}) {
return new Promise((resolve) => {
ServerExec.stdin.write(`${command}\n`);
if (typeof callback === "function") {
const TempLog = []
const ControlTempHost = data => {TempLog.push(data); return data;}
ServerExec.stdout.on("data", data => ControlTempHost(data));
ServerExec.stderr.on("data", data => ControlTempHost(data));
setTimeout(() => {
callback(TempLog.join("\n"));
resolve(TempLog.join("\n"));
}, 2500);
}
});
};
const log = function (logCallback = data => process.stdout.write(data)){
const log = function (logCallback){
if (typeof logCallback !== "function") throw new Error("Log Callback is not a function");
ServerExec.stdout.on("data", data => logCallback(data));
ServerExec.stderr.on("data", data => logCallback(data));
@ -134,7 +140,7 @@ function start() {
};
const on = function(action = String, callback = Function) {
if (!(action === "all" || action === "connect" || action === "disconnect")) throw new Error("Use some valid action: all, connect, disconnect");
// Functions
const data = data => Player_Json(data, function (array_status){
array_status.filter(On => {if ("all" === action || On.Action === action) return true; else return false;}).forEach(_player => callback(_player))
@ -142,39 +148,130 @@ function start() {
ServerExec.stdout.on("data", data);
ServerExec.stderr.on("data", data);
};
const command = function (command = "list") {
ServerExec.stdin.write(`${command}\n`);
return command;
};
const stop = function (){
ServerExec.stdin.write(BdsInfo.Servers[GetPlatform()].stop+"\n");
return BdsInfo.Servers[GetPlatform()].stop;
if (CurrentBdsPlatform === "bedrock") {
ServerExec.stdin.write("stop\n");
return "stop";
} else if (CurrentBdsPlatform === "dragonfly") {
ServerExec.kill("SIGKILL");
return "process";
} else if (CurrentBdsPlatform === "java") {
ServerExec.stdin.write("stop\n");
return "stop";
} else if (CurrentBdsPlatform === "pocketmine") {
ServerExec.stdin.write("stop\n");
return "stop";
} else if (CurrentBdsPlatform === "spigot") {
ServerExec.stdin.write("stop\n");
return "stop";
} else throw new Error("Bds Core Bad Config Error");
};
const op = function (player = "Steve") {
let command = BdsInfo.Servers[GetPlatform()].op.replace("{{Player}}", player);
ServerExec.stdin.write(command+"\n");
return command;
if (CurrentBdsPlatform === "bedrock") {
ServerExec.stdin.write(`op "${player}"\n`);
return "op";
} else if (CurrentBdsPlatform === "dragonfly") {
throw new Error("Dragonfly does not support commands");
} else if (CurrentBdsPlatform === "java") {
ServerExec.stdin.write(`op ${player}\n`);
return "op";
} else if (CurrentBdsPlatform === "pocketmine") {
ServerExec.stdin.write(`op ${player}\n`);
return "op";
} else if (CurrentBdsPlatform === "spigot") {
ServerExec.stdin.write(`op ${player}\n`);
return "op";
} else throw new Error("Bds Core Bad Config Error");
};
const deop = function (player = "Steve") {
let command = BdsInfo.Servers[GetPlatform()].deop.replace("{{Player}}", player);
ServerExec.stdin.write(command+"\n");
return command;
if (CurrentBdsPlatform === "bedrock") {
ServerExec.stdin.write(`deop "${player}"\n`);
return "deop";
} else if (CurrentBdsPlatform === "dragonfly") {
throw new Error("Dragonfly does not support commands");
} else if (CurrentBdsPlatform === "java") {
ServerExec.stdin.write(`deop ${player}\n`);
return "deop";
} else if (CurrentBdsPlatform === "pocketmine") {
ServerExec.stdin.write(`deop ${player}\n`);
return "deop";
} else if (CurrentBdsPlatform === "spigot") {
ServerExec.stdin.write(`deop ${player}\n`);
return "deop";
} else throw new Error("Bds Core Bad Config Error");
};
const ban = function (player = "Steve") {
let command = BdsInfo.Servers[GetPlatform()].ban.replace("{{Player}}", player);
ServerExec.stdin.write(command+"\n");
return command;
if (CurrentBdsPlatform === "bedrock") {
ServerExec.stdin.write(`kick "${player}"\n`);
return "kick";
} else if (CurrentBdsPlatform === "dragonfly") {
throw new Error("Dragonfly does not support commands");
} else if (CurrentBdsPlatform === "java") {
ServerExec.stdin.write(`ban ${player}\n`);
return "ban";
} else if (CurrentBdsPlatform === "pocketmine") {
ServerExec.stdin.write(`ban ${player}\n`);
return "ban";
} else if (CurrentBdsPlatform === "spigot") {
ServerExec.stdin.write(`ban ${player}\n`);
return "ban";
} else throw new Error("Bds Core Bad Config Error");
};
const kick = function (player = "Steve", text = "you got kicked") {
let command = BdsInfo.Servers[GetPlatform()].kick.replace("{{Player}}", player).replace("{{Text}}", text);
ServerExec.stdin.write(command+"\n");
return command;
if (CurrentBdsPlatform === "bedrock") {
ServerExec.stdin.write(`kick "${player}" ${text}\n`);
return "kick";
} else if (CurrentBdsPlatform === "dragonfly") {
throw new Error("Dragonfly does not support commands");
} else if (CurrentBdsPlatform === "java") {
ServerExec.stdin.write(`kick ${player} ${text}\n`);
return "kick";
} else if (CurrentBdsPlatform === "pocketmine") {
ServerExec.stdin.write(`kick ${player} ${text}\n`);
return "kick";
} else if (CurrentBdsPlatform === "spigot") {
ServerExec.stdin.write(`kick ${player} ${text}\n`);
return "kick";
} else throw new Error("Bds Core Bad Config Error");
};
const tp = function (player = "Steve", cord = {x: 0, y: 128, z: 0}) {
let command = BdsInfo.Servers[GetPlatform()].tp.replace("{{Player}}", player);
if (cord.x) command = command.replace("{{X}}", cord.x); else command = command.replace("{{X}}", 0);
if (cord.y) command = command.replace("{{Y}}", cord.y); else command = command.replace("{{Y}}", 128);
if (cord.y) command = command.replace("{{Z}}", cord.y); else command = command.replace("{{Z}}", 0);
ServerExec.stdin.write(command+"\n");
return command;
if (CurrentBdsPlatform === "bedrock") {
ServerExec.stdin.write(`tp ${player} ${cord.x} ${cord.y} ${cord.z}\n`);
return "tp";
} else if (CurrentBdsPlatform === "dragonfly") {
throw new Error("Dragonfly does not support commands");
} else if (CurrentBdsPlatform === "java") {
ServerExec.stdin.write(`tp ${player} ${cord.x} ${cord.y} ${cord.z}\n`);
return "tp";
} else if (CurrentBdsPlatform === "pocketmine") {
ServerExec.stdin.write(`tp ${player} ${cord.x} ${cord.y} ${cord.z}\n`);
return "tp";
} else if (CurrentBdsPlatform === "spigot") {
ServerExec.stdin.write(`tp ${player} ${cord.x} ${cord.y} ${cord.z}\n`);
return "tp";
} else throw new Error("Bds Core Bad Config Error");
};
const say = (text = "") => ServerExec.stdin.write(BdsInfo.Servers.bedrock.say.replace("{{Text}}", text));
function say(text = ""){
if (CurrentBdsPlatform === "bedrock") {
ServerExec.stdin.write(`say ${text}\n`);
return "say";
} else if (CurrentBdsPlatform === "dragonfly") {
throw new Error("Dragonfly does not support commands");
} else if (CurrentBdsPlatform === "java") {
ServerExec.stdin.write(`say ${text}\n`);
return "say";
} else if (CurrentBdsPlatform === "pocketmine") {
ServerExec.stdin.write(`say ${text}\n`);
return "say";
} else if (CurrentBdsPlatform === "spigot") {
ServerExec.stdin.write(`say ${text}\n`);
return "say";
} else throw new Error("Bds Core Bad Config Error");
}
// Mount commands to Return
const returnFuntion = {

View File

@ -4,215 +4,52 @@ const { writeFileSync, existsSync, readFileSync, readdirSync, rmSync } = fs;
const { join, resolve } = path;
var AdmZip = require("adm-zip");
const BdsInfo = require("../lib/BdsSystemInfo");
const { GetServerPaths, GetServerVersion, UpdateServerVersion, GetPlatform } = require("../lib/BdsSettings");
const { GetServerPaths, GetPlatform } = require("../lib/BdsSettings");
const Extra = require("../BdsManegerInfo.json");
const bds = require("../index");
const { execSync } = require("child_process");
const Request = require("../lib/Requests");
module.exports = function (version = true, force_install = false, callback = (err) => {if (err) console.log("Download Error")}) {
return new Promise(async (promise_resolve, promise_reject) => {
BdsInfo().then(info => info.valid_platform).then(valid_platform => {
Request.JSON(Extra.Fetchs.servers).then(Servers => {
try {
// Server Paths
const bds_dir_bedrock = GetServerPaths("bedrock"),
bds_dir_java = GetServerPaths("java"),
bds_dir_pocketmine = GetServerPaths("pocketmine"),
bds_dir_spigot = GetServerPaths("spigot"),
bds_dir_dragonfly = GetServerPaths("dragonfly");
// Php download and install
async function php_download() {
const bds_dir_pocketmine = GetServerPaths("pocketmine");
const PHPBin = (await (await fetch(Extra.Fetchs.php)).json());
const phpFolder = resolve(bds_dir_pocketmine, "bin");
const phpExtensiosnsDir = resolve(bds_dir_pocketmine, "bin/php7/lib/php/extensions");
// Check Php Binary
let urlPHPBin = PHPBin[process.platform]
if (!(urlPHPBin)) throw new Error("unsupported system")
urlPHPBin = urlPHPBin[bds.arch];
if (!(urlPHPBin)) throw new Error("unsupported arch")
// JSON Configs and others
const ServerVersion = GetServerVersion();
const CurrentPlatform = GetPlatform();
if (typeof version === "boolean" || /true|latest/gi.test(`${version}`.toLocaleLowerCase())) version = Servers.latest[CurrentPlatform];
// Remove Old php Binary if it exists
if (existsSync(phpFolder)) {
rmSync(phpFolder, { recursive: true });
}
const ZipBuffer = Buffer.from((await (await fetch(urlPHPBin)).arrayBuffer()));
const zipExtractBin = new AdmZip(ZipBuffer);
zipExtractBin.extractAllTo(bds_dir_pocketmine, false)
// Donwload
console.log(`Installing version ${version}`);
// Bedrock Installer Script
if (CurrentPlatform === "bedrock") {
if (valid_platform.bedrock === true){
if (!(force_install === true) && ServerVersion.bedrock === version) {
console.warn("Jumping, installed version")
if (typeof callback === "function") callback(undefined, true);
promise_resolve(true);
} else {
// Get Server Version
const BedrockUrlDownload = (Servers.bedrock[version][bds.arch] || Servers.bedrock[version]["x64"])[process.platform];
if (!(BedrockUrlDownload)) return promise_reject(new Error("Error in find url version"));
if (Servers.bedrock[version].data) console.log(`Server data publish: ${Servers.bedrock[version].data}`);
if (process.platform === "win32") return resolve();
// Copy Config files
var server_configs, permissions, whitelist;
if (existsSync(join(bds_dir_bedrock, "server.properties"))) server_configs = readFileSync(join(bds_dir_bedrock, "server.properties"), "utf8");
if (existsSync(join(bds_dir_bedrock, "permissions.json"))) permissions = readFileSync(join(bds_dir_bedrock, "permissions.json"), "utf8");
if (existsSync(join(bds_dir_bedrock, "whitelist.json"))) whitelist = readFileSync(join(bds_dir_bedrock, "whitelist.json"), "utf8");
// Download and Add to Adm_Zip
Request.BUFFER(BedrockUrlDownload).then(ResBuffer => {
// Extract Zip
const zip = new AdmZip(ResBuffer);
console.log("Download Sucess")
zip.extractAllTo(bds_dir_bedrock, true)
console.log("Extract Sucess")
// Reeplace Server Configs
if (server_configs) writeFileSync(join(bds_dir_bedrock, "server.properties"), server_configs);
if (permissions) writeFileSync(join(bds_dir_bedrock, "permissions.json"), permissions);
if (whitelist) writeFileSync(join(bds_dir_bedrock, "whitelist.json"), whitelist);
// Update Server Version
UpdateServerVersion(version);
let phpConfigInit = readFileSync(join(phpFolder, "php7", "bin", "php.ini"), "utf8");
if (!(existsSync(phpExtensiosnsDir))) return true;
// Resolve
promise_resolve();
if (typeof callback === "function") callback(undefined);
}).catch(error => {promise_reject(error); if (typeof callback === "function") callback(error);});
}
} else {
const BedrcokError = Error("Bedrock Not suported");
promise_reject(BedrcokError);
if (typeof callback === "function") callback(BedrcokError);
}
}
const phpExtensiosns = readdirSync(phpExtensiosnsDir).map(FileFolder => {
if (!(FileFolder.includes("debug-zts"))) return false;
return resolve(phpExtensiosnsDir, FileFolder);
}).filter(a=>a);
// Java
else if (CurrentPlatform === "java") {
if (valid_platform.java === true){
if (version === "latest") version = Servers.latest.java
if (!(force_install === true) && version === ServerVersion.java) {
console.warn("Jumping, installed version")
promise_resolve(true);
if (typeof callback === "function") callback(undefined, true);
} else {
const JavaDownloadUrl = Servers.java[version].url
console.log(`Server data publish: ${Servers.java[version].data}`)
Request.BUFFER(JavaDownloadUrl).then(ResBuffer => {
// Save Jar file
writeFileSync(join(bds_dir_java, "MinecraftServerJava.jar"), ResBuffer, "binary")
console.log("Success when downloading and saving Minecraft Server java");
// Update Server Version
UpdateServerVersion(version);
// Resolve
promise_resolve();
if (typeof callback === "function") callback(undefined);
}).catch(error => {
promise_reject(error);
if (typeof callback === "function") callback(error);
});
}
} else {
const JavaError = Error("Java is not supported or required software is not installed");
promise_reject(JavaError);
if (typeof callback === "function") callback(JavaError);
}
}
// Pocketmine-MP
else if (CurrentPlatform === "pocketmine") {
if (valid_platform.pocketmine === true) {
if (version === "latest") version = Servers.latest.pocketmine
if (!(force_install === true) && version === ServerVersion.pocketmine) {
console.warn("Jumping, installed version")
promise_resolve();
if (typeof callback === "function") callback(undefined);
} else {
const PocketMineJson = Servers.pocketmine[version]
console.log(`Server data publish: ${PocketMineJson.data}`);
Request.BUFFER(PocketMineJson.url).then(ResBuffer => {
writeFileSync(join(bds_dir_pocketmine, "PocketMine-MP.phar"), ResBuffer, "binary")
console.log("Success downloading and saving PocketMine-MP php");
php_download().then(() => {
// Update server Version
UpdateServerVersion(version)
// Callback
promise_resolve(true);
if (typeof callback === "function") callback(undefined, true);
}).catch(error => {
promise_reject(error);
if (typeof callback === "function") callback(error);
});
}).catch(error => {
promise_reject(error);
if (typeof callback === "function") callback(error);
});
}
} else {
const PocketMineError = Error("Pocketmine not suported");
promise_reject(PocketMineError);
if (typeof callback === "function") callback(PocketMineError);
}
}
// Spigot
else if (CurrentPlatform === "spigot") {
if (valid_platform.java) {
if (version === "latest") version = Servers.latest.spigot;
if (!(force_install === true) && version === ServerVersion.spigot) {
console.warn("Jumping, installed version")
if (typeof callback === "function") callback(undefined, true);
promise_resolve(true)
} else {
const SpigotArray = Servers.spigot[version];
if (SpigotArray.data) console.log(`Server data publish: ${SpigotArray.data}`);
Request.BUFFER(SpigotArray.url).then(ResBuffer => {
writeFileSync(join(bds_dir_spigot, "spigot.jar"), ResBuffer, "binary");
console.log("Success when downloading and saving Spigot");
UpdateServerVersion(version);
promise_resolve();
if (typeof callback === "function") callback(undefined);
});
}
} else {
const JavaError = Error("Java is not supported or required software is not installed");
promise_reject(JavaError);
if (typeof callback === "function") callback(JavaError);
}
}
// dragonfly
else if (CurrentPlatform === "dragonfly") {
if (valid_platform.dragonfly) {
console.info("Dragonfly does not support versions");
execSync("git clone https://github.com/df-mc/dragonfly ./", {
cwd: bds_dir_dragonfly
});
promise_resolve(true);
if (typeof callback === "function") callback(undefined);
} else {
const DragonFlyError = Error("Dragonfly not suported");
promise_reject(DragonFlyError);
if (typeof callback === "function") callback(DragonFlyError);
}
}
// Unidentified platform
else {
const Err = Error("Bds maneger Config file error");
promise_reject(Err);
if (typeof callback === "function") callback(Err);
}
} catch (err) {
promise_reject(err);
if (typeof callback === "function") callback(err);
}
}).catch(err => {
promise_reject(err);
if (typeof callback === "function") callback(err);
});
}).catch(err => {
promise_reject(err);
if (typeof callback === "function") callback(err);
});
});
if (phpConfigInit.includes("extension_dir")) console.log("Skipping php.ini configuration");
else {
phpConfigInit = (`extension_dir="${phpExtensiosns.join()}"\n${phpConfigInit}`);
writeFileSync(join(phpFolder, "php7", "bin", "php.ini"), phpConfigInit);
}
return true;
}
// New Download Method
module.exports.v2 = async (version = true) => {
async function BdsDownloadV2(version = "latest") {
const CurrentPlatform = GetPlatform();
const valid_platform = (await BdsInfo()).valid_platform;
const LocalServersVersions = bds.BdsSettigs.GetServerVersion();
@ -222,11 +59,11 @@ module.exports.v2 = async (version = true) => {
const ServerDownloadJSON = await Request.json(Extra.Fetchs.servers);
// Check is latest version options or boolean
if (typeof version === "boolean" || /true|false|latest/.test(`${version}`.toLocaleLowerCase())) version = ServerDownloadJSON.latest[CurrentPlatform];
if (typeof version === "boolean" || /true|false|null|undefined|latest/.test(`${version}`.toLocaleLowerCase())) version = ServerDownloadJSON.latest[CurrentPlatform];
if (!version) throw Error("No version found");
const ReturnObject = {
version: version,
version,
platform: CurrentPlatform,
url: "",
data: "",
@ -304,7 +141,7 @@ module.exports.v2 = async (version = true) => {
if (valid_platform.spigot) {
if (LocalServersVersions.spigot !== version) {
// Add info to ReturnObject
const FindedSpigot = ServerDownloadJSON.spigot.findOne(spigot => spigot.version === version);
const FindedSpigot = ServerDownloadJSON.spigot.find(spigot => spigot.version === version);
ReturnObject.url = FindedSpigot.url;
ReturnObject.data = FindedSpigot.data;
@ -376,41 +213,6 @@ module.exports.v2 = async (version = true) => {
return ReturnObject;
}
// Php download and install
async function php_download() {
const bds_dir_pocketmine = GetServerPaths("pocketmine");
const PHPBin = (await (await fetch(Extra.Fetchs.php)).json());
const phpFolder = resolve(bds_dir_pocketmine, "bin");
const phpExtensiosnsDir = resolve(bds_dir_pocketmine, "bin/php7/lib/php/extensions");
// Check Php Binary
let urlPHPBin = PHPBin[process.platform]
if (!(urlPHPBin)) throw new Error("unsupported system")
urlPHPBin = urlPHPBin[bds.arch];
if (!(urlPHPBin)) throw new Error("unsupported arch")
// Remove Old php Binary if it exists
if (existsSync(phpFolder)) {
rmSync(phpFolder, { recursive: true });
}
const ZipBuffer = Buffer.from((await (await fetch(urlPHPBin)).arrayBuffer()));
const zipExtractBin = new AdmZip(ZipBuffer);
zipExtractBin.extractAllTo(bds_dir_pocketmine, false)
if (process.platform === "win32") return resolve();
let phpConfigInit = readFileSync(join(phpFolder, "php7", "bin", "php.ini"), "utf8");
if (!(existsSync(phpExtensiosnsDir))) return true;
const phpExtensiosns = readdirSync(phpExtensiosnsDir).map(FileFolder => {
if (!(FileFolder.includes("debug-zts"))) return false;
return resolve(phpExtensiosnsDir, FileFolder);
}).filter(a=>a);
if (phpConfigInit.includes("extension_dir")) console.log("Skipping php.ini configuration");
else {
phpConfigInit = (`extension_dir="${phpExtensiosns.join()}"\n${phpConfigInit}`);
writeFileSync(join(phpFolder, "php7", "bin", "php.ini"), phpConfigInit);
}
return true;
}
// Export
module.exports = BdsDownloadV2;
module.exports.v2 = BdsDownloadV2;

View File

@ -54,8 +54,10 @@ function Detect(){
const CurrentProcess = getProcess();
for (let check of CurrentProcess) {
if (/MinecraftServerJava.jar/.test(check.command)) return true;
if (/spigot.jar/.test(check.command)) return true;
if (/bedrock_server/.test(check.command)) return true;
if (/PocketMine-MP.phar/.test(check.command)) return true;
if (/Dragonfly/.test(check.command)) return true;
}
return false
}
@ -68,6 +70,10 @@ function Kill(){
console.log("Killing Minecraft Server Java");
killWithPid(check.pid);
}
if (/spigot.jar/.test(check.command)) {
console.log("Killing Spigot");
killWithPid(check.pid);
}
if (/bedrock_server/.test(check.command)) {
console.log("Killing Minecraft Bedrock Server");
killWithPid(check.pid);
@ -76,6 +82,10 @@ function Kill(){
console.log("Killing Pocketmine-MP");
killWithPid(check.pid);
}
if (/Dragonfly/.test(check.command)) {
console.log("Killing Dragonfly");
killWithPid(check.pid);
}
}
return true
}

View File

@ -3,15 +3,18 @@ const path = require("path");
const propertiesToJSON = require("properties-to-json");
const BdsInfo = require("../lib/BdsSystemInfo");
const { GetServerPaths, GetPlatform } = require("../lib/BdsSettings");
const TOML = require("@iarna/toml");
const ConfigFilePath = {
bedrock: path.join(GetServerPaths("bedrock"), "server.properties"),
java: path.join(GetServerPaths("java"), "server.properties"),
pocketmine: path.join(GetServerPaths("pocketmine"), "server.properties")
pocketmine: path.join(GetServerPaths("pocketmine"), "server.properties"),
dragonfly: path.join(GetServerPaths("dragonfly"), "config.toml"),
}
// Set Config
function bds_config(NewConfig = {world: "Bds Maneger", description: "The Bds Maneger", gamemode: "creative", difficulty: "normal", players: 10, commands: true, account: true, whitelist: true, port: 19132, portv6: 19133, seed: ""}){
const BdsPlatform = GetPlatform();
const JsonConfig = {
world: "Bds Maneger",
description: "The Bds Maneger",
@ -44,7 +47,7 @@ function bds_config(NewConfig = {world: "Bds Maneger", description: "The Bds Man
if (typeof NewConfig.portv6 === "number" && NewConfig.portv6) JsonConfig.portv6 = NewConfig.portv6
const Config = [];
if (GetPlatform() === "bedrock") {
if (BdsPlatform === "bedrock") {
const bedrockCPUThread = BdsInfo.GetCpuCoreCount();
var tickDistance; if (!(bedrockCPUThread % 2)) tickDistance = bedrockCPUThread; else tickDistance = 1;
Config.push(
@ -77,7 +80,7 @@ function bds_config(NewConfig = {world: "Bds Maneger", description: "The Bds Man
"correct-player-movement=false",
"server-authoritative-block-breaking=false",
);
} else if (GetPlatform() === "java") {
} else if (BdsPlatform === "java") {
Config.push(
"# By The Bds Maneger project",
`# Date: ${Date.now()}`,
@ -133,7 +136,35 @@ function bds_config(NewConfig = {world: "Bds Maneger", description: "The Bds Man
"spawn-protection=16",
"max-world-size=29999984",
);
} else if (GetPlatform() === "pocketmine") {
} else if (BdsPlatform === "dragonfly") {
Config.push(
"",
"[Network]",
` Address = ":${JsonConfig.port}"`,
"",
"[Players]",
" Folder = \"players\"",
" MaxCount = 0",
" MaximumChunkRadius = 32",
" SaveData = true",
"",
"[Resources]",
" Folder = \"resources\"",
"",
"[Server]",
" AuthEnabled = true",
" JoinMessage = \"%v has joined the game\"",
` Name = "${JsonConfig.description}"`,
" QuitMessage = \"%v has left the game\"",
" ShutdownMessage = \"Server closed.\"",
"",
"[World]",
" Folder = \"world\"",
` Name = "${JsonConfig.world}"`,
" SimulationDistance = 8",
""
);
} else if (BdsPlatform === "pocketmine") {
// Whitelist
if (JsonConfig.whitelist === true) JsonConfig.whitelist = "on";
else JsonConfig.whitelist = "off";
@ -178,12 +209,13 @@ function bds_config(NewConfig = {world: "Bds Maneger", description: "The Bds Man
"auto-save=on",
);
}
fs.writeFileSync(ConfigFilePath[GetPlatform()], Config.join("\n"))
fs.writeFileSync(ConfigFilePath[BdsPlatform], Config.join("\n"))
return Config.join("\n");
}
// Get Config
function bds_get_config(){
const BdsPlatform = GetPlatform();
var config;
const JsonConfig = {
world: "",
@ -196,8 +228,8 @@ function bds_get_config(){
portv6: 0,
};
if (GetPlatform() === "bedrock") {
if (fs.existsSync(ConfigFilePath[GetPlatform()])) {
if (BdsPlatform === "bedrock") {
if (fs.existsSync(ConfigFilePath[BdsPlatform])) {
config = propertiesToJSON(fs.readFileSync(ConfigFilePath["bedrock"], "utf8"));
// Players
@ -217,8 +249,8 @@ function bds_get_config(){
// JsonConfig.worldtype = "default";
}
}
else if (GetPlatform() === "java") {
if (fs.existsSync(ConfigFilePath[GetPlatform()])) {
else if (BdsPlatform === "java") {
if (fs.existsSync(ConfigFilePath[BdsPlatform])) {
config = propertiesToJSON(fs.readFileSync(path.join(ConfigFilePath["java"], "server.properties"), "utf8"));
// Players
@ -238,8 +270,8 @@ function bds_get_config(){
// JsonConfig.worldtype = config["level-type"];
}
}
else if (GetPlatform() === "pocketmine") {
if (fs.existsSync(ConfigFilePath[GetPlatform()])) {
else if (BdsPlatform === "pocketmine") {
if (fs.existsSync(ConfigFilePath[BdsPlatform])) {
config = propertiesToJSON(fs.readFileSync(path.join(ConfigFilePath["pocketmine"], "server.properties"), "utf8"));
// Players
@ -258,6 +290,21 @@ function bds_get_config(){
JsonConfig.commands = false;
// JsonConfig.worldtype = config["level-type"];
}
} else if (BdsPlatform === "dragonfly") {
if (fs.existsSync(ConfigFilePath[BdsPlatform])) {
const ConfigFile = TOML.parse(fs.readFileSync(ConfigFilePath[BdsPlatform], "utf8"));
JsonConfig.world = ConfigFile.World.Name;
JsonConfig.description = ConfigFile.Server.Name;
JsonConfig.gamemode = "creative";
JsonConfig.difficulty = null;
JsonConfig.players = parseInt(ConfigFile.Players.MaxCount || 0);
JsonConfig.account = false;
JsonConfig.whitelist = null;
JsonConfig.portv4 = parseInt(ConfigFile.Network.Address.replace(":", ""));
JsonConfig.portv6 = parseInt(ConfigFile.Network.Address.replace(":", ""));
JsonConfig.seed = null;
JsonConfig.commands = false;
}
} else throw new Error("Platform no exists, check config file");
return JsonConfig;
}
@ -265,7 +312,7 @@ function bds_get_config(){
// Get Withelist
function bds_get_whitelist(){
const BdsPlatform = GetPlatform();
const ToReturn = [];
const ToReturn = [];
// Bedrock
if (BdsPlatform === "bedrock") {
@ -300,4 +347,4 @@ function bds_get_whitelist(){
// Export modules
module.exports.config = bds_config
module.exports.get_config = bds_get_config
module.exports.get_whitelist = bds_get_whitelist
module.exports.get_whitelist = bds_get_whitelist