Async functions #169
@ -46,11 +46,13 @@ case "$(apt search openjdk)" in
|
||||
esac
|
||||
|
||||
# Setup non root user
|
||||
useradd -m -p "$(perl -e 'print crypt($ARGV[0], "password")' "LucaA1113ba21")" "thebds"
|
||||
addgroup thebds sudo
|
||||
addgroup thebds root
|
||||
usermod --shell /usr/bin/zsh thebds;
|
||||
echo "thebds ALL=(ALL:ALL) NOPASSWD: ALL" >> /etc/sudoers
|
||||
setup_user() {
|
||||
useradd -m -p "$(perl -e 'print crypt($ARGV[0], "password")' "LucaA1113ba21")" "thebds"
|
||||
addgroup thebds sudo
|
||||
addgroup thebds root
|
||||
usermod --shell /usr/bin/zsh thebds;
|
||||
echo "thebds ALL=(ALL:ALL) NOPASSWD: ALL" >> /etc/sudoers
|
||||
}
|
||||
|
||||
# Remove Unnecessary Packages
|
||||
apt autoremove -y
|
||||
|
@ -10,10 +10,8 @@
|
||||
console.log("Start:", bds.start());
|
||||
setTimeout(() => {
|
||||
console.log("Kill Server:", bds.kill());
|
||||
setTimeout(() => process.exit(0), 1000);
|
||||
}, 1 * 30 * 1000);
|
||||
setTimeout(() => {
|
||||
process.exit(0);
|
||||
}, 1 * 60 * 1000);
|
||||
} catch (err) {
|
||||
console.log("Detect Error:", err);
|
||||
process.exit(1)
|
||||
|
0
bin/Docker.js
Normal file → Executable file
0
bin/Docker.js
Normal file → Executable file
@ -89,120 +89,123 @@ async function StartServer(){
|
||||
process.exit(2)
|
||||
}
|
||||
}
|
||||
|
||||
// Bds Maneger CLI Help
|
||||
if (help) {
|
||||
let help = [
|
||||
"usage: bds_maneger [options]",
|
||||
"",
|
||||
"options:",
|
||||
" -s --start Start Server",
|
||||
" -k --kill Detect and kill bds servers",
|
||||
" -p --platform Select server platform",
|
||||
" -d --download server version to install, default \"latest\"",
|
||||
" --interactive Install the server interactively",
|
||||
" -S --system_info System info and test",
|
||||
" -h --help Print this list and exit.",
|
||||
" -v --version Print the version and exit."
|
||||
]
|
||||
console.log(cli_color.yellow(help.join("\n")));
|
||||
process.exit();
|
||||
}
|
||||
|
||||
// Get Bds Core Version
|
||||
if (version) {
|
||||
const Info = [
|
||||
`Bds Maneger Core version: ${bds.package_json.version}`,
|
||||
"",
|
||||
"****************** Bds Maneger Core contributors ******************",
|
||||
"",
|
||||
]
|
||||
for (let contri of bds.extra_json.contributors) {
|
||||
Info.push(`********* ${contri.name} *********`)
|
||||
if (contri.email) Info.push(`* ${contri.email}`)
|
||||
if (contri.url) Info.push(`* ${contri.url}`)
|
||||
Info.push("*")
|
||||
Info.push("*********")
|
||||
(async () => {
|
||||
// Bds Maneger CLI Help
|
||||
if (help) {
|
||||
let help = [
|
||||
"usage: bds_maneger [options]",
|
||||
"",
|
||||
"options:",
|
||||
" -s --start Start Server",
|
||||
" -k --kill Detect and kill bds servers",
|
||||
" -p --platform Select server platform",
|
||||
" -d --download server version to install, default \"latest\"",
|
||||
" --interactive Install the server interactively",
|
||||
" -S --system_info System info and test",
|
||||
" -h --help Print this list and exit.",
|
||||
" -v --version Print the version and exit."
|
||||
]
|
||||
console.log(cli_color.yellow(help.join("\n")));
|
||||
process.exit();
|
||||
}
|
||||
console.log(Info.join("\n"));
|
||||
process.exit();
|
||||
}
|
||||
|
||||
if (SystemCheck) {
|
||||
var checkothearch = "";
|
||||
if (process.platform === "linux" && bds.arch !== "x64"){checkothearch = `qemu-x86_64-static is installed to emulate an x64 system: ${commandExits("qemu-x86_64-static")}\n`}
|
||||
if (process.platform === "android" && bds.arch !== "x64"){checkothearch = `qemu-x86_64 is installed to emulate an x64 system: ${commandExits("qemu-x86_64")}\n`}
|
||||
const help = [
|
||||
`Bds Maneger Core And Bds Maneger CLI version: ${cli_color.magentaBright(bds.package_json.version)}`,
|
||||
`System: ${cli_color.yellow(process.platform)}, architecture: ${cli_color.blue(bds.arch)}`,
|
||||
checkothearch,
|
||||
"**************************************************************",
|
||||
"* Bds Maneger dirs:",
|
||||
`* - Config: ${cli_color.yellowBright(bds_dir)}`,
|
||||
`* - Players File: ${cli_color.yellowBright(GetPaths("player"))}`,
|
||||
"*",
|
||||
"* Bds Servers dirs:",
|
||||
`* - Bedrock Server: ${cli_color.yellowBright(GetServerPaths("bedrock"))}`,
|
||||
`* - Pocketmine-MP Server: ${cli_color.yellowBright(GetServerPaths("pocketmine"))}`,
|
||||
`* - Dragonfly: ${cli_color.yellowBright(GetServerPaths("dragonfly"))}`,
|
||||
`* - Java Server: ${cli_color.yellowBright(GetServerPaths("java"))}`,
|
||||
`* - Spigot Server: ${cli_color.yellowBright(GetServerPaths("spigot"))}`,
|
||||
"*",
|
||||
"**************************************************************",
|
||||
"* Servers currently available:",
|
||||
`* - Bedrock: ${SystemInfo.valid_platform.bedrock}`,
|
||||
`* - Pocketmine-MP: ${SystemInfo.valid_platform.pocketmine}`,
|
||||
`* - Dragonfly: ${SystemInfo.valid_platform.dragonfly}`,
|
||||
`* - Java: ${SystemInfo.valid_platform.java}`,
|
||||
`* - Spigot: ${SystemInfo.valid_platform.java}`,
|
||||
"*",
|
||||
"**************************************************************"
|
||||
];
|
||||
console.log(
|
||||
cli_color.whiteBright(help.join("\n")
|
||||
.replace(/true/gi, cli_color.greenBright("true"))
|
||||
.replace(/false/gi, cli_color.redBright("false"))
|
||||
.replace(/undefined/gi, cli_color.red("undefined"))
|
||||
));
|
||||
process.exit(0)
|
||||
}
|
||||
// Get Bds Core Version
|
||||
if (version) {
|
||||
const Info = [
|
||||
`Bds Maneger Core version: ${bds.package_json.version}`,
|
||||
"",
|
||||
"****************** Bds Maneger Core contributors ******************",
|
||||
"",
|
||||
]
|
||||
for (let contri of bds.extra_json.contributors) {
|
||||
Info.push(`********* ${contri.name} *********`)
|
||||
if (contri.email) Info.push(`* ${contri.email}`)
|
||||
if (contri.url) Info.push(`* ${contri.url}`)
|
||||
Info.push("*")
|
||||
Info.push("*********")
|
||||
}
|
||||
console.log(Info.join("\n"));
|
||||
process.exit();
|
||||
}
|
||||
|
||||
// Download server
|
||||
if (bds_version){
|
||||
(async () => {
|
||||
try {
|
||||
if (argv.interactive) {
|
||||
const LoadVersion = (await (await fetch(BdsConfigAndInfo.Fetchs.servers)).json())[GetPlatform()]
|
||||
const Version = Object.getOwnPropertyNames(LoadVersion)
|
||||
|
||||
const StartQuestion = (Readline) => {
|
||||
Readline.question("Select a version to download: ", input => {
|
||||
if (Version[parseInt(input) - 1]) {
|
||||
Readline.close();
|
||||
download(Version[parseInt(input) - 1], true, function(){
|
||||
if (start) return StartServer();
|
||||
console.log("Installation was successful, so start the server with the -s option");
|
||||
process.exit(0);
|
||||
})
|
||||
} else {
|
||||
console.log("Invalid Option");
|
||||
StartQuestion(Readline);
|
||||
}
|
||||
});
|
||||
if (SystemCheck) {
|
||||
const { valid_platform } = await SystemInfo();
|
||||
var checkothearch = "";
|
||||
if (process.platform === "linux" && bds.arch !== "x64"){checkothearch = `qemu-x86_64-static is installed to emulate an x64 system: ${commandExits("qemu-x86_64-static")}\n`}
|
||||
if (process.platform === "android" && bds.arch !== "x64"){checkothearch = `qemu-x86_64 is installed to emulate an x64 system: ${commandExits("qemu-x86_64")}\n`}
|
||||
const help = [
|
||||
`Bds Maneger Core And Bds Maneger CLI version: ${cli_color.magentaBright(bds.package_json.version)}`,
|
||||
`System: ${cli_color.yellow(process.platform)}, architecture: ${cli_color.blue(bds.arch)}`,
|
||||
checkothearch,
|
||||
"**************************************************************",
|
||||
"* Bds Maneger dirs:",
|
||||
`* - Config: ${cli_color.yellowBright(bds_dir)}`,
|
||||
`* - Players File: ${cli_color.yellowBright(GetPaths("player"))}`,
|
||||
"*",
|
||||
"* Bds Servers dirs:",
|
||||
`* - Bedrock Server: ${cli_color.yellowBright(GetServerPaths("bedrock"))}`,
|
||||
`* - Pocketmine-MP Server: ${cli_color.yellowBright(GetServerPaths("pocketmine"))}`,
|
||||
`* - Dragonfly: ${cli_color.yellowBright(GetServerPaths("dragonfly"))}`,
|
||||
`* - Java Server: ${cli_color.yellowBright(GetServerPaths("java"))}`,
|
||||
`* - Spigot Server: ${cli_color.yellowBright(GetServerPaths("spigot"))}`,
|
||||
"*",
|
||||
"**************************************************************",
|
||||
"* Servers currently available:",
|
||||
`* - Bedrock: ${valid_platform.bedrock}`,
|
||||
`* - Pocketmine-MP: ${valid_platform.pocketmine}`,
|
||||
`* - Dragonfly: ${valid_platform.dragonfly}`,
|
||||
`* - Java: ${valid_platform.java}`,
|
||||
`* - Spigot: ${valid_platform.java}`,
|
||||
"*",
|
||||
"**************************************************************"
|
||||
];
|
||||
console.log(
|
||||
cli_color.whiteBright(help.join("\n")
|
||||
.replace(/true/gi, cli_color.greenBright("true"))
|
||||
.replace(/false/gi, cli_color.redBright("false"))
|
||||
.replace(/undefined/gi, cli_color.red("undefined"))
|
||||
));
|
||||
process.exit(0)
|
||||
}
|
||||
|
||||
// Download server
|
||||
if (bds_version){
|
||||
(async () => {
|
||||
try {
|
||||
if (argv.interactive) {
|
||||
const LoadVersion = (await (await fetch(BdsConfigAndInfo.Fetchs.servers)).json())[GetPlatform()]
|
||||
const Version = Object.getOwnPropertyNames(LoadVersion)
|
||||
|
||||
const StartQuestion = (Readline) => {
|
||||
Readline.question("Select a version to download: ", input => {
|
||||
if (Version[parseInt(input) - 1]) {
|
||||
Readline.close();
|
||||
download(Version[parseInt(input) - 1], true, function(){
|
||||
if (start) return StartServer();
|
||||
console.log("Installation was successful, so start the server with the -s option");
|
||||
process.exit(0);
|
||||
})
|
||||
} else {
|
||||
console.log("Invalid Option");
|
||||
StartQuestion(Readline);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
console.log(`Selected platform: ${GetPlatform()}, Total available versions: ${Version.length}`);
|
||||
console.log(`${cli_color.red("Option")} ${cli_color.green("Version")}`);
|
||||
|
||||
for (let option in Version) console.log(`${cli_color.red(parseInt(option) + 1)}: ${cli_color.green(Version[option])}`);
|
||||
StartQuestion(readline.createInterface({input: process.stdin,output: process.stdout}));
|
||||
}
|
||||
|
||||
console.log(`Selected platform: ${GetPlatform()}, Total available versions: ${Version.length}`);
|
||||
console.log(`${cli_color.red("Option")} ${cli_color.green("Version")}`);
|
||||
|
||||
for (let option in Version) console.log(`${cli_color.red(parseInt(option) + 1)}: ${cli_color.green(Version[option])}`);
|
||||
StartQuestion(readline.createInterface({input: process.stdin,output: process.stdout}));
|
||||
}
|
||||
else bds.download(bds_version, true, function(){
|
||||
if (start) StartServer();
|
||||
})
|
||||
} catch (error) {console.error(error);process.exit(165);}
|
||||
})();
|
||||
}
|
||||
else bds.download(bds_version, true, function(){
|
||||
if (start) StartServer();
|
||||
})
|
||||
} catch (error) {console.error(error);process.exit(165);}
|
||||
})();
|
||||
}
|
||||
|
||||
// Start server
|
||||
if (start && !(server || version || SystemCheck || bds_version || help)) StartServer();
|
||||
// Start server
|
||||
if (start && !(server || version || SystemCheck || bds_version || help)) StartServer();
|
||||
|
||||
})()
|
@ -23,7 +23,7 @@ const HelpAndStart = [
|
||||
" /download",
|
||||
" Version",
|
||||
" ",
|
||||
]
|
||||
];
|
||||
|
||||
// Set Telegram Bot
|
||||
const bot = new Telegraf(GetTelegramToken());
|
||||
|
4
index.js
4
index.js
@ -47,12 +47,12 @@ module.exports.telegram_token_save = UpdateTelegramToken
|
||||
*
|
||||
* @param {function} callback - The callback function after start API
|
||||
*/
|
||||
module.exports.api = require("./src/rest/api");
|
||||
module.exports.api = require("./src/api/api");
|
||||
|
||||
function token_register(Admin_Scoper = ["web_admin", "admin"]) {
|
||||
Admin_Scoper = Array.from(Admin_Scoper).filter(scoper => /admin/.test(scoper));
|
||||
const bds_token_path = path.join(bds_dir, "bds_tokens.json");
|
||||
let tokens = []
|
||||
let tokens = [];
|
||||
if (fs.existsSync(bds_token_path)) tokens = JSON.parse(fs.readFileSync(bds_token_path, "utf8"));
|
||||
|
||||
// Get UUID
|
||||
|
@ -1,7 +1,7 @@
|
||||
const { join, resolve, basename } = require("path");
|
||||
const { existsSync, writeFileSync, mkdirSync, readFileSync } = require("fs");
|
||||
const { homedir } = require("os");
|
||||
const { valid_platform } = require("./BdsSystemInfo");
|
||||
const BdsInfo = require("./BdsSystemInfo");
|
||||
const yaml = require("js-yaml");
|
||||
|
||||
// PATHs
|
||||
@ -9,12 +9,19 @@ const home = homedir();
|
||||
const bds_dir = join(home, "bds_core");
|
||||
if (!(existsSync(bds_dir))) mkdirSync(bds_dir, {recursive: true})
|
||||
|
||||
// Set default platform for bds maneger
|
||||
var default_platformConfig;
|
||||
if (valid_platform["bedrock"]) default_platformConfig = "bedrock";
|
||||
else if (valid_platform["java"]) default_platformConfig = "java";
|
||||
else if (valid_platform["pocketmine"]) default_platformConfig = "pocketmine";
|
||||
else throw new Error("We cannot run any platforms on this system/device");
|
||||
BdsInfo().then(validation => {
|
||||
const { valid_platform } = validation;
|
||||
// Set default platform for bds maneger
|
||||
var default_platformConfig;
|
||||
if (valid_platform["bedrock"]) default_platformConfig = "bedrock";
|
||||
else if (valid_platform["java"]) default_platformConfig = "java";
|
||||
else if (valid_platform["pocketmine"]) default_platformConfig = "pocketmine";
|
||||
else throw new Error("We cannot run any platforms on this system/device");
|
||||
UpdatePlatform(default_platformConfig);
|
||||
}).catch(err => {
|
||||
console.log(err);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
// Config Base to Bds Maneger Core and others Projects
|
||||
var Config = {
|
||||
@ -28,7 +35,7 @@ var Config = {
|
||||
enable_tmp_host: false
|
||||
},
|
||||
server: {
|
||||
platform: default_platformConfig,
|
||||
platform: "bedrock",
|
||||
BackupCron: [
|
||||
{
|
||||
enabled: false,
|
||||
|
@ -1,62 +1,73 @@
|
||||
const { execSync } = require("child_process");
|
||||
const { release } = require("os");
|
||||
const { readdirSync } = require("fs");
|
||||
const { execSync } = require("child_process");
|
||||
const commadExist = require("./commandExist");
|
||||
const fetchSync = require("@the-bds-maneger/fetchsync");
|
||||
const Request = require("./Requests");
|
||||
|
||||
// Load JSON for Server and PHP Zip files
|
||||
const PHPBin = fetchSync("https://raw.githubusercontent.com/The-Bds-Maneger/Php_Static_Binary/main/binarys.json").json(),
|
||||
Servers = fetchSync("https://raw.githubusercontent.com/The-Bds-Maneger/external_files/main/Server.json").json();
|
||||
|
||||
// System Architect (x64, aarch64 and others)
|
||||
var arch;
|
||||
if (process.arch === "arm64") arch = "aarch64";
|
||||
else arch = process.arch
|
||||
module.exports.arch = arch
|
||||
|
||||
var system,
|
||||
require_qemu = false,
|
||||
valid_platform = {
|
||||
async function CheckSystemAsync() {
|
||||
const
|
||||
PHPBin = await Request.JSON("https://raw.githubusercontent.com/The-Bds-Maneger/Php_Static_Binary/main/binarys.json"),
|
||||
Servers = await Request.JSON("https://raw.githubusercontent.com/The-Bds-Maneger/external_files/main/Server.json");
|
||||
|
||||
let system, require_qemu = false;
|
||||
const valid_platform = {
|
||||
bedrock: true,
|
||||
pocketmine: true,
|
||||
java: commadExist("java"),
|
||||
dragonfly: commadExist("go"),
|
||||
}
|
||||
};
|
||||
|
||||
// check php bin
|
||||
if ((PHPBin[process.platform] || {})[arch]) valid_platform["pocketmine"] = true;
|
||||
else valid_platform["pocketmine"] = false;
|
||||
// check php bin
|
||||
if ((PHPBin[process.platform] || {})[arch]) valid_platform["pocketmine"] = true;
|
||||
else valid_platform["pocketmine"] = false;
|
||||
|
||||
// SoSystem X
|
||||
if (process.platform == "win32") {
|
||||
system = "Windows";
|
||||
} else if (process.platform == "linux") {
|
||||
system = "Linux";
|
||||
|
||||
// Bedrock Check
|
||||
if (Servers.bedrock[Servers.latest.bedrock][arch]) {
|
||||
if (Servers.bedrock[Servers.latest.bedrock][arch][process.platform]) valid_platform["bedrock"] = true;
|
||||
else valid_platform["bedrock"] = false;
|
||||
} else valid_platform["bedrock"] = false;
|
||||
// SoSystem X
|
||||
if (process.platform == "win32") {
|
||||
system = "Windows";
|
||||
} else if (process.platform == "linux") {
|
||||
system = "Linux";
|
||||
|
||||
// Bedrock Check
|
||||
if (Servers.bedrock[Servers.latest.bedrock][arch]) {
|
||||
if (Servers.bedrock[Servers.latest.bedrock][arch][process.platform]) valid_platform["bedrock"] = true;
|
||||
else valid_platform["bedrock"] = false;
|
||||
} else valid_platform["bedrock"] = false;
|
||||
|
||||
if (valid_platform["bedrock"] === false) {
|
||||
if (commadExist("qemu-x86_64-static")) {
|
||||
console.warn("The Minecraft Bedrock Server is only being validated because you can use 'qemu-x86_64-static'");
|
||||
valid_platform["bedrock"] = true
|
||||
require_qemu = true
|
||||
if (valid_platform["bedrock"] === false) {
|
||||
if (commadExist("qemu-x86_64-static")) {
|
||||
console.warn("The Minecraft Bedrock Server is only being validated because you can use 'qemu-x86_64-static'");
|
||||
valid_platform["bedrock"] = true
|
||||
require_qemu = true
|
||||
}
|
||||
}
|
||||
} else if (process.platform == "darwin") {
|
||||
system = "MacOS";
|
||||
valid_platform["bedrock"] = false
|
||||
} else if (process.platform === "android") {
|
||||
system = "Android";
|
||||
valid_platform["bedrock"] = false
|
||||
} else {
|
||||
throw new Error(`The Bds Maneger Core does not support ${process.platform} systems, as no tests have been done.`);
|
||||
}
|
||||
} else if (process.platform == "darwin") {
|
||||
system = "MacOS";
|
||||
valid_platform["bedrock"] = false
|
||||
} else if (process.platform === "android") {
|
||||
system = "Android";
|
||||
valid_platform["bedrock"] = false
|
||||
} else {
|
||||
console.log(`The Bds Maneger Core does not support ${process.platform} systems, as no tests have been done.`);
|
||||
process.exit(127);
|
||||
|
||||
return {
|
||||
system,
|
||||
require_qemu,
|
||||
valid_platform,
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = CheckSystemAsync;
|
||||
|
||||
// System Architect (x64, aarch64 and others)
|
||||
let arch;
|
||||
if (process.arch === "arm64") arch = "aarch64";
|
||||
else arch = process.arch
|
||||
module.exports.arch = arch
|
||||
|
||||
/**
|
||||
* Platforms valid from deferents systems
|
||||
*/
|
||||
function GetKernel() {
|
||||
if (process.platform === "win32") {
|
||||
const kernelVersion = parseFloat(release());
|
||||
@ -93,11 +104,13 @@ function GetKernel() {
|
||||
else return str.replace(/\n|\t|\r/gi, "");
|
||||
} else return "Not identified";
|
||||
}
|
||||
|
||||
/**
|
||||
* Platforms valid from deferents systems
|
||||
*/
|
||||
module.exports.valid_platform = valid_platform
|
||||
module.exports.require_qemu = require_qemu
|
||||
module.exports.system = system
|
||||
module.exports.GetKernel = GetKernel;
|
||||
|
||||
// Get CPU Core Count
|
||||
function GetCpuCoreCount() {
|
||||
if (process.platform === "win32") return require("os").cpus().length;
|
||||
else if (process.platform === "android" || process.platform === "linux") return readdirSync("/sys/devices/system/cpu/").filter(data => /cpu[0-9]/.test(data)).length;
|
||||
else if (process.platform === "darwin") return require("os").cpus().length;
|
||||
else return 1;
|
||||
}
|
||||
module.exports.GetCpuCoreCount = GetCpuCoreCount;
|
6
lib/Requests.js
Normal file
6
lib/Requests.js
Normal file
@ -0,0 +1,6 @@
|
||||
if (typeof fetch === "undefined") global.fetch = require("node-fetch");
|
||||
module.exports = {
|
||||
JSON: async (url = "", options) => await (await fetch(url, options)).json(),
|
||||
TEXT: async (url = "", options) => await (await fetch(url, options)).text(),
|
||||
BUFFER: async (url = "", options) => Buffer.from(await (await fetch(url, options)).arrayBuffer()),
|
||||
}
|
@ -1,11 +1,11 @@
|
||||
const { join, resolve } = require("path");
|
||||
const { readdirSync, existsSync, readFileSync, statSync } = require("fs")
|
||||
const fs = require("fs");
|
||||
const AdmZip = require("adm-zip");
|
||||
const { GetServerPaths, GetPaths, bds_dir } = require("../lib/BdsSettings")
|
||||
const { GetServerPaths, GetPaths, bds_dir } = require("../lib/BdsSettings");
|
||||
|
||||
function Backup() {
|
||||
const zip = new AdmZip();
|
||||
console.info("Please wait");
|
||||
console.info("Starting Bds Core Backup Along with the server maps, please wait");
|
||||
// Names And Path"s
|
||||
const Paths = {
|
||||
bedrock: GetServerPaths("bedrock"),
|
||||
@ -14,43 +14,47 @@ function Backup() {
|
||||
spigot: GetServerPaths("spigot"),
|
||||
}
|
||||
const CurrentDate = new Date();
|
||||
const name = `Bds_Maneger_Core_Backups_${CurrentDate.getDate()}-${CurrentDate.getMonth()}-${CurrentDate.getFullYear()}.zip`
|
||||
const PathBackup = join(GetPaths("backups"), name);
|
||||
const ZipName = `Bds_Maneger_Core_Backups_${CurrentDate.getDate()}-${CurrentDate.getMonth()}-${CurrentDate.getFullYear()}.zip`
|
||||
const PathBackup = join(GetPaths("backups"), ZipName);
|
||||
|
||||
// Bedrock
|
||||
if (readdirSync(Paths.bedrock).filter(a=>/worlds/.test(a)).length >= 1) {
|
||||
if (fs.readdirSync(Paths.bedrock).filter(a=>/worlds/.test(a)).length >= 1) {
|
||||
zip.addLocalFolder(join(Paths.bedrock, "worlds"), join("Servers", "Bedrock", "worlds"));
|
||||
for (let index of ["server.properties", "permissions.json", "whitelist.json"]) {if (existsSync(join(Paths.bedrock, index))) zip.addLocalFile(join(Paths.bedrock, index), join("Servers", "Bedrock"));}
|
||||
for (let index of ["server.properties", "permissions.json", "whitelist.json"]) {if (fs.existsSync(join(Paths.bedrock, index))) zip.addLocalFile(join(Paths.bedrock, index), join("Servers", "Bedrock"));}
|
||||
} else console.info("Skipping the bedrock as it was not installed");
|
||||
|
||||
// Java
|
||||
if (existsSync(join(Paths.java, "MinecraftServerJava.jar"))) {
|
||||
for (let index of readdirSync(Paths.java).filter(value => !/banned-ips.json|banned-players.json|eula.txt|logs|ops.json|server.jar|MinecraftServerJava.jar|server.properties|usercache.json|whitelist.json/.test(value))) zip.addLocalFolder(join(Paths.java, index), join("Servers", "Java", index));
|
||||
for (let index of ["banned-ips.json", "banned-players.json", "ops.json", "server.properties", "whitelist.json"]) {if (existsSync(join(Paths.java, index))) zip.addLocalFile(join(Paths.java, index), join("Servers", "Java"))}
|
||||
if (fs.existsSync(join(Paths.java, "MinecraftServerJava.jar"))) {
|
||||
for (let index of fs.readdirSync(Paths.java).filter(value => !/banned-ips.json|banned-players.json|eula.txt|logs|ops.json|server.jar|MinecraftServerJava.jar|server.properties|usercache.json|whitelist.json/.test(value))) zip.addLocalFolder(join(Paths.java, index), join("Servers", "Java", index));
|
||||
for (let index of ["banned-ips.json", "banned-players.json", "ops.json", "server.properties", "whitelist.json"]) {if (fs.existsSync(join(Paths.java, index))) zip.addLocalFile(join(Paths.java, index), join("Servers", "Java"))}
|
||||
} else console.info("Skipping the java as it was not installed");
|
||||
|
||||
// PocketMine
|
||||
if (existsSync(join(Paths.pocketmine, "PocketMine-MP.phar"))) {
|
||||
if (existsSync(join(Paths.pocketmine, "worlds"))) zip.addLocalFolder(join(Paths.pocketmine, "worlds"), join("Servers", "pocketmine", "worlds"));
|
||||
for (let index of ["pocketmine.yml", "server.properties", "white-list.txt", "ops.txt", "banned-players.txt", "banned-ips.txt"]) if (existsSync(join(Paths.pocketmine, index))) zip.addLocalFile(join(Paths.pocketmine, index), "pocketmine");
|
||||
if (fs.existsSync(join(Paths.pocketmine, "PocketMine-MP.phar"))) {
|
||||
if (fs.existsSync(join(Paths.pocketmine, "worlds"))) zip.addLocalFolder(join(Paths.pocketmine, "worlds"), join("Servers", "pocketmine", "worlds"));
|
||||
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");
|
||||
|
||||
// The Bds Maneger Core Backup
|
||||
for (let index of ["BdsConfig.yaml", "bds_tokens.json"]) if (existsSync(join(bds_dir, index))) zip.addLocalFile(join(bds_dir, index));
|
||||
for (let index of ["BdsConfig.yaml", "bds_tokens.json"]) if (fs.existsSync(join(bds_dir, index))) zip.addLocalFile(join(bds_dir, index));
|
||||
|
||||
for (let index of Object.getOwnPropertyNames(GetPaths("all")).filter(path => !/servers|backups/.test(path)).map(name => GetPaths(name))) {
|
||||
if (existsSync(index)) {
|
||||
const _S = statSync(resolve(index));
|
||||
if (fs.existsSync(index)) {
|
||||
const _S = fs.statSync(resolve(index));
|
||||
if (_S.isFile() || _S.isSymbolicLink()) zip.addLocalFile(index, "/BdsManegerCore"); else zip.addLocalFolder(index, join("/BdsManegerCore", index.replace(bds_dir, "")));
|
||||
}
|
||||
}
|
||||
|
||||
zip.addZipComment("Settings and World Backups, by The Bds Maneger Project©");
|
||||
zip.writeZip(PathBackup);
|
||||
|
||||
// Zip Buffer
|
||||
const ZipBuffer = zip.toBuffer();
|
||||
fs.writeFileSync(PathBackup, ZipBuffer, "binary");
|
||||
console.log("Backup Complete");
|
||||
return {
|
||||
file_path: PathBackup,
|
||||
file_name: name,
|
||||
Buffer: readFileSync(PathBackup)
|
||||
Buffer: ZipBuffer,
|
||||
file_name: ZipName,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,147 +1,171 @@
|
||||
const { writeFileSync, existsSync, readFileSync, readdirSync, rmSync } = require("fs");
|
||||
const { join, resolve, basename } = require("path");
|
||||
var AdmZip = require("adm-zip");
|
||||
const { valid_platform } = require("../lib/BdsSystemInfo");
|
||||
const BdsInfo = require("../lib/BdsSystemInfo");
|
||||
const { GetServerPaths, GetServerVersion, UpdateServerVersion, 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 = async function (version, force_install, callback) {
|
||||
module.exports = function (version = true, force_install = false, callback = (err) => {if (err) console.log("Download Error")}) {
|
||||
return new Promise(async (promise_resolve, promise_reject) => {
|
||||
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");
|
||||
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");
|
||||
|
||||
// JSON Configs and others
|
||||
const Servers = (await (await fetch(Extra.Fetchs.servers)).json());
|
||||
const ServerVersion = GetServerVersion();
|
||||
const CurrentPlatform = GetPlatform();
|
||||
if (!(version) || version === true || version === "true" || version === "latest") version = Servers.latest[CurrentPlatform]
|
||||
var url;
|
||||
// JSON Configs and others
|
||||
const ServerVersion = GetServerVersion();
|
||||
const CurrentPlatform = GetPlatform();
|
||||
if (typeof version === "boolean" || /true|latest/gi.test(version)) version = Servers.latest[CurrentPlatform]
|
||||
|
||||
console.log(`Installing version ${version}`);
|
||||
// Bedrock Installer Script
|
||||
if (CurrentPlatform === "bedrock") {
|
||||
if (valid_platform.bedrock === true){
|
||||
if (version === "latest") version = Servers.latest.bedrock
|
||||
if (!(force_install === true) && ServerVersion.bedrock === version) {
|
||||
console.warn("Jumping, installed version")
|
||||
if (typeof callback === "function") await callback(undefined, true);
|
||||
promise_resolve(true);
|
||||
} else {
|
||||
if (Servers.bedrock[version].data) console.log(`Server data publish: ${Servers.bedrock[version].data}`)
|
||||
url = Servers.bedrock[version][bds.arch][process.platform]
|
||||
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
|
||||
const zip = new AdmZip(Buffer.from((await (await fetch(url)).arrayBuffer())))
|
||||
console.log("Download Sucess")
|
||||
// Donwload
|
||||
console.log(`Installing version ${version}`);
|
||||
// Bedrock Installer Script
|
||||
if (CurrentPlatform === "bedrock") {
|
||||
if (valid_platform.bedrock === true){
|
||||
if (version === "latest") version = Servers.latest.bedrock
|
||||
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
|
||||
if (Servers.bedrock[version].data) console.log(`Server data publish: ${Servers.bedrock[version].data}`)
|
||||
const BedrockUrlDownload = Servers.bedrock[version][bds.arch][process.platform]
|
||||
|
||||
// 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(Buffer => {
|
||||
// Extract Zip
|
||||
const zip = new AdmZip(Buffer);
|
||||
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);
|
||||
|
||||
zip.extractAllTo(bds_dir_bedrock, true)
|
||||
console.log("Extract Sucess")
|
||||
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)
|
||||
UpdateServerVersion(version);
|
||||
if (typeof callback === "function") await callback(undefined, true);
|
||||
promise_resolve(true);
|
||||
// Resolve
|
||||
promise_resolve();
|
||||
if (typeof callback === "function") callback(undefined);
|
||||
}).catch(error => {promise_reject(error); if (typeof callback === "function") callback(error);});
|
||||
}
|
||||
} else throw Error("Bedrock Not suported")
|
||||
}
|
||||
} else throw Error("Bedrock Not suported")
|
||||
}
|
||||
|
||||
// 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")
|
||||
if (typeof callback === "function") await callback(undefined, true);
|
||||
promise_resolve(true)
|
||||
} else {
|
||||
url = Servers.java[version].url
|
||||
console.log(`Server data publish: ${Servers.java[version].data}`)
|
||||
|
||||
writeFileSync(join(bds_dir_java, "MinecraftServerJava.jar"), Buffer.from((await (await fetch(url)).arrayBuffer())), "binary")
|
||||
console.log("Success when downloading and saving Minecraft Server java");
|
||||
UpdateServerVersion(version);
|
||||
if (typeof callback === "function") await callback(undefined, true);
|
||||
promise_resolve(true);
|
||||
// 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(Buffer => {
|
||||
// Save Jar file
|
||||
writeFileSync(join(bds_dir_java, "MinecraftServerJava.jar"), Buffer, "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 throw Error("Java is not supported or required software is not installed")
|
||||
}
|
||||
} else throw Error("Java is not supported or required software is not installed")
|
||||
}
|
||||
|
||||
// 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")
|
||||
if (typeof callback === "function") await callback(undefined, true);
|
||||
promise_resolve(true)
|
||||
} else {
|
||||
const PocketMineJson = Servers.pocketmine[version]
|
||||
console.log(`Server data publish: ${PocketMineJson.data}`);
|
||||
|
||||
writeFileSync(join(bds_dir_pocketmine, "PocketMine-MP.phar"), Buffer.from((await (await fetch(PocketMineJson.url)).arrayBuffer())), "binary")
|
||||
console.log("Success downloading and saving PocketMine-MP php");
|
||||
|
||||
await php_download();
|
||||
|
||||
// Update server Version
|
||||
UpdateServerVersion(version)
|
||||
// Callback
|
||||
if (typeof callback === "function") await callback(undefined, true);
|
||||
promise_resolve(true);
|
||||
// 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(Buffer => {
|
||||
writeFileSync(join(bds_dir_pocketmine, "PocketMine-MP.phar"), Buffer, "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 throw Error("Pocketmine not suported")
|
||||
}
|
||||
} else throw Error("Pocketmine not suported")
|
||||
}
|
||||
|
||||
// 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") await callback(undefined, true);
|
||||
promise_resolve(true)
|
||||
} else {
|
||||
const SpigotURL = Servers.spigot[version].url;
|
||||
if (Servers.spigot[version].data) console.log(`Server data publish: ${Servers.spigot[version].data}`);
|
||||
writeFileSync(join(bds_dir_spigot, "spigot.jar"), Buffer.from((await (await fetch(SpigotURL)).arrayBuffer())), "binary");
|
||||
console.log("Success when downloading and saving Spigot");
|
||||
UpdateServerVersion(version);
|
||||
if (typeof callback === "function") await callback(undefined, true);
|
||||
promise_resolve(true);
|
||||
// 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(Buffer => {
|
||||
writeFileSync(join(bds_dir_spigot, "spigot.jar"), Buffer, "binary");
|
||||
console.log("Success when downloading and saving Spigot");
|
||||
UpdateServerVersion(version);
|
||||
promise_resolve();
|
||||
if (typeof callback === "function") callback(undefined);
|
||||
});
|
||||
}
|
||||
} else throw Error("Java is not supported or required software is not installed")
|
||||
}
|
||||
} else throw Error("Java is not supported or required software is not installed")
|
||||
}
|
||||
|
||||
// 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
|
||||
});
|
||||
if (typeof callback === "function") await callback(undefined, true);
|
||||
promise_resolve(true);
|
||||
} else throw Error("Dragonfly not suported")
|
||||
}
|
||||
// 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 throw Error("Dragonfly not suported")
|
||||
}
|
||||
|
||||
// Unidentified platform
|
||||
else throw Error("Bds maneger Config file error")
|
||||
} catch (err) {
|
||||
if (typeof callback === "function") await callback(err, false);
|
||||
return promise_reject(err);
|
||||
}
|
||||
// Unidentified platform
|
||||
else throw Error("Bds maneger Config file error")
|
||||
} 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);});
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1,27 +1,18 @@
|
||||
var fs = require("fs");
|
||||
const path = require("path");
|
||||
const propertiesToJSON = require("properties-to-json");
|
||||
const { join } = require("path");
|
||||
const BdsInfo = require("../lib/BdsSystemInfo");
|
||||
const { GetServerPaths, GetPlatform } = require("../lib/BdsSettings");
|
||||
const bds_dir_bedrock = GetServerPaths("bedrock"), bds_dir_java = GetServerPaths("java"), bds_dir_pocketmine = GetServerPaths("pocketmine");
|
||||
const bedrockCPUThread = require("os").cpus().length;
|
||||
|
||||
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: ""
|
||||
}
|
||||
){
|
||||
let JsonConfig = {
|
||||
const ConfigFilePath = {
|
||||
bedrock: path.join(GetServerPaths("bedrock"), "server.properties"),
|
||||
java: path.join(GetServerPaths("java"), "server.properties"),
|
||||
pocketmine: path.join(GetServerPaths("pocketmine"), "server.properties")
|
||||
}
|
||||
|
||||
// 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 JsonConfig = {
|
||||
world: "Bds Maneger",
|
||||
description: "The Bds Maneger",
|
||||
gamemode: "creative",
|
||||
@ -35,31 +26,31 @@ function bds_config(
|
||||
seed: ""
|
||||
};
|
||||
|
||||
if (NewConfig.world) JsonConfig.world = NewConfig.world
|
||||
if (NewConfig.description) JsonConfig.description = NewConfig.description
|
||||
if (NewConfig.gamemode) JsonConfig.gamemode = NewConfig.gamemode
|
||||
if (NewConfig.difficulty) JsonConfig.difficulty = NewConfig.difficulty
|
||||
if (NewConfig.players) JsonConfig.players = NewConfig.players
|
||||
if (NewConfig.commands || NewConfig.commands === false) JsonConfig.commands = NewConfig.commands
|
||||
if (NewConfig.account || NewConfig.account === false) JsonConfig.account = NewConfig.account
|
||||
if (NewConfig.whitelist || NewConfig.whitelist === false) JsonConfig.whitelist = NewConfig.whitelist
|
||||
if (NewConfig.port) JsonConfig.port = NewConfig.port
|
||||
if (NewConfig.portv6) JsonConfig.portv6 = NewConfig.portv6
|
||||
if (NewConfig.seed) JsonConfig.seed = NewConfig.seed
|
||||
|
||||
var Config, ConfigFile;
|
||||
// Strings
|
||||
if (typeof NewConfig.world === "string" && NewConfig.world) JsonConfig.world = NewConfig.world
|
||||
if (typeof NewConfig.description === "string" && NewConfig.description) JsonConfig.description = NewConfig.description
|
||||
if (typeof NewConfig.gamemode === "string" && NewConfig.gamemode) JsonConfig.gamemode = NewConfig.gamemode
|
||||
if (typeof NewConfig.difficulty === "string" && NewConfig.difficulty) JsonConfig.difficulty = NewConfig.difficulty
|
||||
if ((typeof NewConfig.seed === "string" || typeof NewConfig.seed === "number") && NewConfig.seed) JsonConfig.seed = NewConfig.seed
|
||||
|
||||
// Booleans
|
||||
if (typeof NewConfig.commands === "boolean" && (NewConfig.commands || NewConfig.commands === false)) JsonConfig.commands = NewConfig.commands
|
||||
if (typeof NewConfig.account === "boolean" && (NewConfig.account || NewConfig.account === false)) JsonConfig.account = NewConfig.account
|
||||
if (typeof NewConfig.whitelist === "boolean" && (NewConfig.whitelist || NewConfig.whitelist === false)) JsonConfig.whitelist = NewConfig.whitelist
|
||||
|
||||
// Numbers
|
||||
if (typeof NewConfig.port === "number" && NewConfig.port) JsonConfig.port = NewConfig.port
|
||||
if (typeof NewConfig.players === "number" && NewConfig.players) JsonConfig.players = NewConfig.players
|
||||
if (typeof NewConfig.portv6 === "number" && NewConfig.portv6) JsonConfig.portv6 = NewConfig.portv6
|
||||
|
||||
const Config = [];
|
||||
if (GetPlatform() === "bedrock") {
|
||||
var tickDistance;
|
||||
if (bedrockCPUThread >= 12) tickDistance = 12;
|
||||
else if (bedrockCPUThread >= 10) tickDistance = 10;
|
||||
else if (bedrockCPUThread >= 8) tickDistance = 8;
|
||||
else if (bedrockCPUThread >= 6) tickDistance = 6;
|
||||
else if (bedrockCPUThread >= 4) tickDistance = 4;
|
||||
else if (bedrockCPUThread >= 2) tickDistance = 2;
|
||||
else tickDistance = 1;
|
||||
|
||||
ConfigFile = join(bds_dir_bedrock, "server.properties");
|
||||
Config = [
|
||||
const bedrockCPUThread = BdsInfo.GetCpuCoreCount();
|
||||
var tickDistance; if (!(bedrockCPUThread % 2)) tickDistance = bedrockCPUThread; else tickDistance = 1;
|
||||
Config.push(
|
||||
"# By The Bds Maneger project",
|
||||
`# Date: ${Date.now()}`,
|
||||
"",
|
||||
`level-name=${JsonConfig.world}`,
|
||||
`server-name=${JsonConfig.description}`,
|
||||
`gamemode=${JsonConfig.gamemode}`,
|
||||
@ -84,11 +75,13 @@ function bds_config(
|
||||
"player-movement-distance-threshold=0.3",
|
||||
"player-movement-duration-threshold-in-ms=500",
|
||||
"correct-player-movement=false",
|
||||
"server-authoritative-block-breaking=false"
|
||||
]
|
||||
"server-authoritative-block-breaking=false",
|
||||
);
|
||||
} else if (GetPlatform() === "java") {
|
||||
ConfigFile = join(bds_dir_java, "server.properties");
|
||||
Config = [
|
||||
Config.push(
|
||||
"# By The Bds Maneger project",
|
||||
`# Date: ${Date.now()}`,
|
||||
"",
|
||||
`level-name=${JsonConfig.world}`,
|
||||
`motd=${JsonConfig.description}`,
|
||||
`gamemode=${JsonConfig.gamemode}`,
|
||||
@ -138,20 +131,38 @@ function bds_config(
|
||||
"enforce-whitelist=false",
|
||||
"resource-pack-sha1=",
|
||||
"spawn-protection=16",
|
||||
"max-world-size=29999984"
|
||||
]
|
||||
"max-world-size=29999984",
|
||||
);
|
||||
} else if (GetPlatform() === "pocketmine") {
|
||||
ConfigFile = join(bds_dir_pocketmine, "server.properties");
|
||||
Config = [
|
||||
// Whitelist
|
||||
if (JsonConfig.whitelist === true) JsonConfig.whitelist = "on";
|
||||
else JsonConfig.whitelist = "off";
|
||||
|
||||
// difficulty
|
||||
if (JsonConfig.difficulty === "easy") JsonConfig.difficulty = 0;
|
||||
else if (JsonConfig.difficulty === "peaceful") JsonConfig.difficulty = 1;
|
||||
else if (JsonConfig.difficulty === "normal") JsonConfig.difficulty = 2;
|
||||
else if (JsonConfig.difficulty === "hard") JsonConfig.difficulty = 3;
|
||||
else throw new Error("Difficulty error");
|
||||
|
||||
// Required Accoutn
|
||||
if (JsonConfig.account === true) JsonConfig.account = "on";
|
||||
else JsonConfig.account = "off";
|
||||
|
||||
// Config
|
||||
Config.push(
|
||||
"# By The Bds Maneger project",
|
||||
`# Date: ${Date.now()}`,
|
||||
"",
|
||||
"language=eng",
|
||||
`level-name=${JsonConfig.world}`,
|
||||
`motd=${JsonConfig.description}`,
|
||||
`server-port=${JsonConfig.port}`,
|
||||
`white-list=${(()=>{if (JsonConfig.whitelist === true) return "on";else return "off";})()}`,
|
||||
`white-list=${JsonConfig.whitelist}`,
|
||||
`max-players=${JsonConfig.players}`,
|
||||
`gamemode=${JsonConfig.gamemode}`,
|
||||
`difficulty=${(()=>{if (JsonConfig.difficulty === "easy") return 0;else if (JsonConfig.difficulty === "peaceful") return 1;else if (JsonConfig.difficulty === "normal") return 2;else if (JsonConfig.difficulty === "hard") return 3;else throw new Error("Difficulty error");})()}`,
|
||||
`xbox-auth=${(()=>{if (JsonConfig.account === true) return "on";else return "off";})()}`,
|
||||
`difficulty=${JsonConfig.difficulty}`,
|
||||
`xbox-auth=${JsonConfig.account}`,
|
||||
`level-seed=${JsonConfig.seed}`,
|
||||
"view-distance=32",
|
||||
"hardcore=0",
|
||||
@ -164,89 +175,94 @@ function bds_config(
|
||||
"enable-query=on",
|
||||
"enable-rcon=off",
|
||||
"rcon.password=F/deZ5kefY",
|
||||
"auto-save=on"
|
||||
]
|
||||
"auto-save=on",
|
||||
);
|
||||
}
|
||||
|
||||
Config.push("")
|
||||
Config.push("")
|
||||
Config.push("# By The Bds Maneger project")
|
||||
fs.writeFileSync(ConfigFile, Config.join("\n"))
|
||||
return Config;
|
||||
fs.writeFileSync(ConfigFilePath[GetPlatform()], Config.join("\n"))
|
||||
return Config.join("\n");
|
||||
}
|
||||
|
||||
// Get Config
|
||||
function bds_get_config(){
|
||||
var config;
|
||||
const JsonConfig = {
|
||||
world: null,
|
||||
description: null,
|
||||
gamemode: null,
|
||||
difficulty: null,
|
||||
players: null,
|
||||
world: "",
|
||||
description: "",
|
||||
gamemode: "",
|
||||
difficulty: "",
|
||||
players: "",
|
||||
whitelist: null,
|
||||
portv4: null,
|
||||
portv6: null,
|
||||
portv4: 0,
|
||||
portv6: 0,
|
||||
};
|
||||
|
||||
if (GetPlatform() === "bedrock") {
|
||||
config = propertiesToJSON(fs.readFileSync(path.join(bds_dir_bedrock, "server.properties"), "utf8"));
|
||||
|
||||
// Players
|
||||
JsonConfig.world = config["level-name"];
|
||||
JsonConfig.description = config["server-name"];
|
||||
JsonConfig.gamemode = config["gamemode"];
|
||||
JsonConfig.difficulty = config["difficulty"];
|
||||
JsonConfig.players = parseInt(config["max-players"]);
|
||||
JsonConfig.account = (config["online-mode"] === "true");
|
||||
JsonConfig.whitelist = (config["white-list"] === "true");
|
||||
|
||||
// Server/World
|
||||
JsonConfig.portv4 = parseInt(config["server-port"]);
|
||||
JsonConfig.portv6 = parseInt(config["server-portv6"]);
|
||||
JsonConfig.seed = config["level-seed"];
|
||||
JsonConfig.commands = (config["allow-cheats"] === "true");
|
||||
// JsonConfig.worldtype = "default";
|
||||
if (fs.existsSync(ConfigFilePath[GetPlatform()])) {
|
||||
config = propertiesToJSON(fs.readFileSync(ConfigFilePath["bedrock"], "utf8"));
|
||||
|
||||
// Players
|
||||
JsonConfig.world = config["level-name"];
|
||||
JsonConfig.description = config["server-name"];
|
||||
JsonConfig.gamemode = config["gamemode"];
|
||||
JsonConfig.difficulty = config["difficulty"];
|
||||
JsonConfig.players = parseInt(config["max-players"]);
|
||||
JsonConfig.account = (config["online-mode"] === "true");
|
||||
JsonConfig.whitelist = (config["white-list"] === "true");
|
||||
|
||||
// Server/World
|
||||
JsonConfig.portv4 = parseInt(config["server-port"]);
|
||||
JsonConfig.portv6 = parseInt(config["server-portv6"]);
|
||||
JsonConfig.seed = config["level-seed"];
|
||||
JsonConfig.commands = (config["allow-cheats"] === "true");
|
||||
// JsonConfig.worldtype = "default";
|
||||
}
|
||||
}
|
||||
else if (GetPlatform() === "java") {
|
||||
config = propertiesToJSON(fs.readFileSync(path.join(bds_dir_java, "server.properties"), "utf8"));
|
||||
|
||||
// Players
|
||||
JsonConfig.world = config["level-name"];
|
||||
JsonConfig.description = config["motd"];
|
||||
JsonConfig.gamemode = config["gamemode"];
|
||||
JsonConfig.difficulty = config["difficulty"];
|
||||
JsonConfig.players = parseInt(config["max-players"]);
|
||||
JsonConfig.account = (config["online-mode"] === "true");
|
||||
JsonConfig.whitelist = (config["white-list"] === "true");
|
||||
|
||||
// Server/World
|
||||
JsonConfig.portv4 = parseInt(config["server-port"]);
|
||||
JsonConfig.portv6 = parseInt(config["server-port"]);
|
||||
JsonConfig.seed = config["level-seed"];
|
||||
JsonConfig.commands = (config["enable-command-block"] === "true");
|
||||
// JsonConfig.worldtype = config["level-type"];
|
||||
if (fs.existsSync(ConfigFilePath[GetPlatform()])) {
|
||||
config = propertiesToJSON(fs.readFileSync(path.join(ConfigFilePath["java"], "server.properties"), "utf8"));
|
||||
|
||||
// Players
|
||||
JsonConfig.world = config["level-name"];
|
||||
JsonConfig.description = config["motd"];
|
||||
JsonConfig.gamemode = config["gamemode"];
|
||||
JsonConfig.difficulty = config["difficulty"];
|
||||
JsonConfig.players = parseInt(config["max-players"]);
|
||||
JsonConfig.account = (config["online-mode"] === "true");
|
||||
JsonConfig.whitelist = (config["white-list"] === "true");
|
||||
|
||||
// Server/World
|
||||
JsonConfig.portv4 = parseInt(config["server-port"]);
|
||||
JsonConfig.portv6 = parseInt(config["server-port"]);
|
||||
JsonConfig.seed = config["level-seed"];
|
||||
JsonConfig.commands = (config["enable-command-block"] === "true");
|
||||
// JsonConfig.worldtype = config["level-type"];
|
||||
}
|
||||
}
|
||||
else if (GetPlatform() === "pocketmine") {
|
||||
config = propertiesToJSON(fs.readFileSync(path.join(bds_dir_pocketmine, "server.properties"), "utf8"));
|
||||
|
||||
// Players
|
||||
JsonConfig.world = config["level-name"];
|
||||
JsonConfig.description = config["motd"];
|
||||
JsonConfig.gamemode = (()=>{let test = parseInt(config["gamemode"]);if (test === 0) return "survival";else if (test === 1) return "creative";else return undefined;})();
|
||||
JsonConfig.difficulty = (()=>{let test = parseInt(config["difficulty"]);if (test === 0) return "easy";else if (test === 1) return "peaceful";else if (test === 2) return "normal";else if (test === 3) return "hard";else return undefined;})();
|
||||
JsonConfig.players = parseInt(config["max-players"]);
|
||||
JsonConfig.account = (config["xbox-auth"] === "on");
|
||||
JsonConfig.whitelist = (config["white-list"] === "true");
|
||||
|
||||
// Server/World
|
||||
JsonConfig.portv4 = parseInt(config["server-port"]);
|
||||
JsonConfig.portv6 = parseInt(config["server-port"]);
|
||||
JsonConfig.seed = config["level-seed"];
|
||||
JsonConfig.commands = false;
|
||||
// JsonConfig.worldtype = config["level-type"];
|
||||
} else if (GetPlatform() === "jsprismarine") throw "Platform not fully supported";
|
||||
else throw new Error("Platform no exists, check config file");
|
||||
if (fs.existsSync(ConfigFilePath[GetPlatform()])) {
|
||||
config = propertiesToJSON(fs.readFileSync(path.join(ConfigFilePath["pocketmine"], "server.properties"), "utf8"));
|
||||
|
||||
// Players
|
||||
JsonConfig.world = config["level-name"];
|
||||
JsonConfig.description = config["motd"];
|
||||
JsonConfig.gamemode = (()=>{let test = parseInt(config["gamemode"]);if (test === 0) return "survival";else if (test === 1) return "creative";else return undefined;})();
|
||||
JsonConfig.difficulty = (()=>{let test = parseInt(config["difficulty"]);if (test === 0) return "easy";else if (test === 1) return "peaceful";else if (test === 2) return "normal";else if (test === 3) return "hard";else return undefined;})();
|
||||
JsonConfig.players = parseInt(config["max-players"]);
|
||||
JsonConfig.account = (config["xbox-auth"] === "on");
|
||||
JsonConfig.whitelist = (config["white-list"] === "true");
|
||||
|
||||
// Server/World
|
||||
JsonConfig.portv4 = parseInt(config["server-port"]);
|
||||
JsonConfig.portv6 = parseInt(config["server-port"]);
|
||||
JsonConfig.seed = config["level-seed"];
|
||||
JsonConfig.commands = false;
|
||||
// JsonConfig.worldtype = config["level-type"];
|
||||
}
|
||||
} else throw new Error("Platform no exists, check config file");
|
||||
return JsonConfig;
|
||||
}
|
||||
|
||||
// To remove
|
||||
function config_example(){
|
||||
return {
|
||||
name: "Bedrock our Java",
|
||||
|
@ -1,7 +1,6 @@
|
||||
const express = require("express");
|
||||
const app = express.Router();
|
||||
const { GetPlatform, GetPaths } = require("../../../lib/BdsSettings")
|
||||
const bds = require("../../../index");
|
||||
const { token_verify, CheckPlayer } = require("../../UsersAndtokenChecks");
|
||||
const { readFileSync } = require("fs");
|
||||
const docs = require("../../../BdsManegerInfo.json").docs;
|
Reference in New Issue
Block a user