Async functions #169
@ -46,11 +46,13 @@ case "$(apt search openjdk)" in
|
|||||||
esac
|
esac
|
||||||
|
|
||||||
# Setup non root user
|
# Setup non root user
|
||||||
|
setup_user() {
|
||||||
useradd -m -p "$(perl -e 'print crypt($ARGV[0], "password")' "LucaA1113ba21")" "thebds"
|
useradd -m -p "$(perl -e 'print crypt($ARGV[0], "password")' "LucaA1113ba21")" "thebds"
|
||||||
addgroup thebds sudo
|
addgroup thebds sudo
|
||||||
addgroup thebds root
|
addgroup thebds root
|
||||||
usermod --shell /usr/bin/zsh thebds;
|
usermod --shell /usr/bin/zsh thebds;
|
||||||
echo "thebds ALL=(ALL:ALL) NOPASSWD: ALL" >> /etc/sudoers
|
echo "thebds ALL=(ALL:ALL) NOPASSWD: ALL" >> /etc/sudoers
|
||||||
|
}
|
||||||
|
|
||||||
# Remove Unnecessary Packages
|
# Remove Unnecessary Packages
|
||||||
apt autoremove -y
|
apt autoremove -y
|
||||||
|
@ -10,10 +10,8 @@
|
|||||||
console.log("Start:", bds.start());
|
console.log("Start:", bds.start());
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
console.log("Kill Server:", bds.kill());
|
console.log("Kill Server:", bds.kill());
|
||||||
|
setTimeout(() => process.exit(0), 1000);
|
||||||
}, 1 * 30 * 1000);
|
}, 1 * 30 * 1000);
|
||||||
setTimeout(() => {
|
|
||||||
process.exit(0);
|
|
||||||
}, 1 * 60 * 1000);
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log("Detect Error:", err);
|
console.log("Detect Error:", err);
|
||||||
process.exit(1)
|
process.exit(1)
|
||||||
|
0
bin/Docker.js
Normal file → Executable file
0
bin/Docker.js
Normal file → Executable file
@ -89,7 +89,7 @@ async function StartServer(){
|
|||||||
process.exit(2)
|
process.exit(2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
(async () => {
|
||||||
// Bds Maneger CLI Help
|
// Bds Maneger CLI Help
|
||||||
if (help) {
|
if (help) {
|
||||||
let help = [
|
let help = [
|
||||||
@ -129,6 +129,7 @@ if (version) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (SystemCheck) {
|
if (SystemCheck) {
|
||||||
|
const { valid_platform } = await SystemInfo();
|
||||||
var checkothearch = "";
|
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 === "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`}
|
if (process.platform === "android" && bds.arch !== "x64"){checkothearch = `qemu-x86_64 is installed to emulate an x64 system: ${commandExits("qemu-x86_64")}\n`}
|
||||||
@ -150,11 +151,11 @@ if (SystemCheck) {
|
|||||||
"*",
|
"*",
|
||||||
"**************************************************************",
|
"**************************************************************",
|
||||||
"* Servers currently available:",
|
"* Servers currently available:",
|
||||||
`* - Bedrock: ${SystemInfo.valid_platform.bedrock}`,
|
`* - Bedrock: ${valid_platform.bedrock}`,
|
||||||
`* - Pocketmine-MP: ${SystemInfo.valid_platform.pocketmine}`,
|
`* - Pocketmine-MP: ${valid_platform.pocketmine}`,
|
||||||
`* - Dragonfly: ${SystemInfo.valid_platform.dragonfly}`,
|
`* - Dragonfly: ${valid_platform.dragonfly}`,
|
||||||
`* - Java: ${SystemInfo.valid_platform.java}`,
|
`* - Java: ${valid_platform.java}`,
|
||||||
`* - Spigot: ${SystemInfo.valid_platform.java}`,
|
`* - Spigot: ${valid_platform.java}`,
|
||||||
"*",
|
"*",
|
||||||
"**************************************************************"
|
"**************************************************************"
|
||||||
];
|
];
|
||||||
@ -206,3 +207,5 @@ if (bds_version){
|
|||||||
|
|
||||||
// Start server
|
// Start server
|
||||||
if (start && !(server || version || SystemCheck || bds_version || help)) StartServer();
|
if (start && !(server || version || SystemCheck || bds_version || help)) StartServer();
|
||||||
|
|
||||||
|
})()
|
@ -23,7 +23,7 @@ const HelpAndStart = [
|
|||||||
" /download",
|
" /download",
|
||||||
" Version",
|
" Version",
|
||||||
" ",
|
" ",
|
||||||
]
|
];
|
||||||
|
|
||||||
// Set Telegram Bot
|
// Set Telegram Bot
|
||||||
const bot = new Telegraf(GetTelegramToken());
|
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
|
* @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"]) {
|
function token_register(Admin_Scoper = ["web_admin", "admin"]) {
|
||||||
Admin_Scoper = Array.from(Admin_Scoper).filter(scoper => /admin/.test(scoper));
|
Admin_Scoper = Array.from(Admin_Scoper).filter(scoper => /admin/.test(scoper));
|
||||||
const bds_token_path = path.join(bds_dir, "bds_tokens.json");
|
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"));
|
if (fs.existsSync(bds_token_path)) tokens = JSON.parse(fs.readFileSync(bds_token_path, "utf8"));
|
||||||
|
|
||||||
// Get UUID
|
// Get UUID
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
const { join, resolve, basename } = require("path");
|
const { join, resolve, basename } = require("path");
|
||||||
const { existsSync, writeFileSync, mkdirSync, readFileSync } = require("fs");
|
const { existsSync, writeFileSync, mkdirSync, readFileSync } = require("fs");
|
||||||
const { homedir } = require("os");
|
const { homedir } = require("os");
|
||||||
const { valid_platform } = require("./BdsSystemInfo");
|
const BdsInfo = require("./BdsSystemInfo");
|
||||||
const yaml = require("js-yaml");
|
const yaml = require("js-yaml");
|
||||||
|
|
||||||
// PATHs
|
// PATHs
|
||||||
@ -9,12 +9,19 @@ const home = homedir();
|
|||||||
const bds_dir = join(home, "bds_core");
|
const bds_dir = join(home, "bds_core");
|
||||||
if (!(existsSync(bds_dir))) mkdirSync(bds_dir, {recursive: true})
|
if (!(existsSync(bds_dir))) mkdirSync(bds_dir, {recursive: true})
|
||||||
|
|
||||||
|
BdsInfo().then(validation => {
|
||||||
|
const { valid_platform } = validation;
|
||||||
// Set default platform for bds maneger
|
// Set default platform for bds maneger
|
||||||
var default_platformConfig;
|
var default_platformConfig;
|
||||||
if (valid_platform["bedrock"]) default_platformConfig = "bedrock";
|
if (valid_platform["bedrock"]) default_platformConfig = "bedrock";
|
||||||
else if (valid_platform["java"]) default_platformConfig = "java";
|
else if (valid_platform["java"]) default_platformConfig = "java";
|
||||||
else if (valid_platform["pocketmine"]) default_platformConfig = "pocketmine";
|
else if (valid_platform["pocketmine"]) default_platformConfig = "pocketmine";
|
||||||
else throw new Error("We cannot run any platforms on this system/device");
|
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
|
// Config Base to Bds Maneger Core and others Projects
|
||||||
var Config = {
|
var Config = {
|
||||||
@ -28,7 +35,7 @@ var Config = {
|
|||||||
enable_tmp_host: false
|
enable_tmp_host: false
|
||||||
},
|
},
|
||||||
server: {
|
server: {
|
||||||
platform: default_platformConfig,
|
platform: "bedrock",
|
||||||
BackupCron: [
|
BackupCron: [
|
||||||
{
|
{
|
||||||
enabled: false,
|
enabled: false,
|
||||||
|
@ -1,27 +1,21 @@
|
|||||||
const { execSync } = require("child_process");
|
|
||||||
const { release } = require("os");
|
const { release } = require("os");
|
||||||
const { readdirSync } = require("fs");
|
const { readdirSync } = require("fs");
|
||||||
|
const { execSync } = require("child_process");
|
||||||
const commadExist = require("./commandExist");
|
const commadExist = require("./commandExist");
|
||||||
const fetchSync = require("@the-bds-maneger/fetchsync");
|
const Request = require("./Requests");
|
||||||
|
|
||||||
// Load JSON for Server and PHP Zip files
|
async function CheckSystemAsync() {
|
||||||
const PHPBin = fetchSync("https://raw.githubusercontent.com/The-Bds-Maneger/Php_Static_Binary/main/binarys.json").json(),
|
const
|
||||||
Servers = fetchSync("https://raw.githubusercontent.com/The-Bds-Maneger/external_files/main/Server.json").json();
|
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");
|
||||||
|
|
||||||
// System Architect (x64, aarch64 and others)
|
let system, require_qemu = false;
|
||||||
var arch;
|
const valid_platform = {
|
||||||
if (process.arch === "arm64") arch = "aarch64";
|
|
||||||
else arch = process.arch
|
|
||||||
module.exports.arch = arch
|
|
||||||
|
|
||||||
var system,
|
|
||||||
require_qemu = false,
|
|
||||||
valid_platform = {
|
|
||||||
bedrock: true,
|
bedrock: true,
|
||||||
pocketmine: true,
|
pocketmine: true,
|
||||||
java: commadExist("java"),
|
java: commadExist("java"),
|
||||||
dragonfly: commadExist("go"),
|
dragonfly: commadExist("go"),
|
||||||
}
|
};
|
||||||
|
|
||||||
// check php bin
|
// check php bin
|
||||||
if ((PHPBin[process.platform] || {})[arch]) valid_platform["pocketmine"] = true;
|
if ((PHPBin[process.platform] || {})[arch]) valid_platform["pocketmine"] = true;
|
||||||
@ -53,10 +47,27 @@ if (process.platform == "win32") {
|
|||||||
system = "Android";
|
system = "Android";
|
||||||
valid_platform["bedrock"] = false
|
valid_platform["bedrock"] = false
|
||||||
} else {
|
} else {
|
||||||
console.log(`The Bds Maneger Core does not support ${process.platform} systems, as no tests have been done.`);
|
throw new Error(`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() {
|
function GetKernel() {
|
||||||
if (process.platform === "win32") {
|
if (process.platform === "win32") {
|
||||||
const kernelVersion = parseFloat(release());
|
const kernelVersion = parseFloat(release());
|
||||||
@ -93,11 +104,13 @@ function GetKernel() {
|
|||||||
else return str.replace(/\n|\t|\r/gi, "");
|
else return str.replace(/\n|\t|\r/gi, "");
|
||||||
} else return "Not identified";
|
} 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;
|
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 { join, resolve } = require("path");
|
||||||
const { readdirSync, existsSync, readFileSync, statSync } = require("fs")
|
const fs = require("fs");
|
||||||
const AdmZip = require("adm-zip");
|
const AdmZip = require("adm-zip");
|
||||||
const { GetServerPaths, GetPaths, bds_dir } = require("../lib/BdsSettings")
|
const { GetServerPaths, GetPaths, bds_dir } = require("../lib/BdsSettings");
|
||||||
|
|
||||||
function Backup() {
|
function Backup() {
|
||||||
const zip = new AdmZip();
|
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
|
// Names And Path"s
|
||||||
const Paths = {
|
const Paths = {
|
||||||
bedrock: GetServerPaths("bedrock"),
|
bedrock: GetServerPaths("bedrock"),
|
||||||
@ -14,43 +14,47 @@ function Backup() {
|
|||||||
spigot: GetServerPaths("spigot"),
|
spigot: GetServerPaths("spigot"),
|
||||||
}
|
}
|
||||||
const CurrentDate = new Date();
|
const CurrentDate = new Date();
|
||||||
const name = `Bds_Maneger_Core_Backups_${CurrentDate.getDate()}-${CurrentDate.getMonth()}-${CurrentDate.getFullYear()}.zip`
|
const ZipName = `Bds_Maneger_Core_Backups_${CurrentDate.getDate()}-${CurrentDate.getMonth()}-${CurrentDate.getFullYear()}.zip`
|
||||||
const PathBackup = join(GetPaths("backups"), name);
|
const PathBackup = join(GetPaths("backups"), ZipName);
|
||||||
|
|
||||||
// Bedrock
|
// 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"));
|
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");
|
} else console.info("Skipping the bedrock as it was not installed");
|
||||||
|
|
||||||
// Java
|
// Java
|
||||||
if (existsSync(join(Paths.java, "MinecraftServerJava.jar"))) {
|
if (fs.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 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 (existsSync(join(Paths.java, index))) zip.addLocalFile(join(Paths.java, index), join("Servers", "Java"))}
|
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");
|
} else console.info("Skipping the java as it was not installed");
|
||||||
|
|
||||||
// PocketMine
|
// PocketMine
|
||||||
if (existsSync(join(Paths.pocketmine, "PocketMine-MP.phar"))) {
|
if (fs.existsSync(join(Paths.pocketmine, "PocketMine-MP.phar"))) {
|
||||||
if (existsSync(join(Paths.pocketmine, "worlds"))) zip.addLocalFolder(join(Paths.pocketmine, "worlds"), join("Servers", "pocketmine", "worlds"));
|
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 (existsSync(join(Paths.pocketmine, index))) zip.addLocalFile(join(Paths.pocketmine, index), "pocketmine");
|
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");
|
} else console.info("Skipping the pocketmine as it was not installed");
|
||||||
|
|
||||||
// The Bds Maneger Core Backup
|
// 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))) {
|
for (let index of Object.getOwnPropertyNames(GetPaths("all")).filter(path => !/servers|backups/.test(path)).map(name => GetPaths(name))) {
|
||||||
if (existsSync(index)) {
|
if (fs.existsSync(index)) {
|
||||||
const _S = statSync(resolve(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, "")));
|
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.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 {
|
return {
|
||||||
file_path: PathBackup,
|
file_path: PathBackup,
|
||||||
file_name: name,
|
Buffer: ZipBuffer,
|
||||||
Buffer: readFileSync(PathBackup)
|
file_name: ZipName,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,14 +1,17 @@
|
|||||||
const { writeFileSync, existsSync, readFileSync, readdirSync, rmSync } = require("fs");
|
const { writeFileSync, existsSync, readFileSync, readdirSync, rmSync } = require("fs");
|
||||||
const { join, resolve, basename } = require("path");
|
const { join, resolve, basename } = require("path");
|
||||||
var AdmZip = require("adm-zip");
|
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 { GetServerPaths, GetServerVersion, UpdateServerVersion, GetPlatform } = require("../lib/BdsSettings");
|
||||||
const Extra = require("../BdsManegerInfo.json");
|
const Extra = require("../BdsManegerInfo.json");
|
||||||
const bds = require("../index");
|
const bds = require("../index");
|
||||||
const { execSync } = require("child_process");
|
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) => {
|
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 {
|
try {
|
||||||
// Server Paths
|
// Server Paths
|
||||||
const bds_dir_bedrock = GetServerPaths("bedrock"),
|
const bds_dir_bedrock = GetServerPaths("bedrock"),
|
||||||
@ -18,12 +21,11 @@ module.exports = async function (version, force_install, callback) {
|
|||||||
bds_dir_dragonfly = GetServerPaths("dragonfly");
|
bds_dir_dragonfly = GetServerPaths("dragonfly");
|
||||||
|
|
||||||
// JSON Configs and others
|
// JSON Configs and others
|
||||||
const Servers = (await (await fetch(Extra.Fetchs.servers)).json());
|
|
||||||
const ServerVersion = GetServerVersion();
|
const ServerVersion = GetServerVersion();
|
||||||
const CurrentPlatform = GetPlatform();
|
const CurrentPlatform = GetPlatform();
|
||||||
if (!(version) || version === true || version === "true" || version === "latest") version = Servers.latest[CurrentPlatform]
|
if (typeof version === "boolean" || /true|latest/gi.test(version)) version = Servers.latest[CurrentPlatform]
|
||||||
var url;
|
|
||||||
|
|
||||||
|
// Donwload
|
||||||
console.log(`Installing version ${version}`);
|
console.log(`Installing version ${version}`);
|
||||||
// Bedrock Installer Script
|
// Bedrock Installer Script
|
||||||
if (CurrentPlatform === "bedrock") {
|
if (CurrentPlatform === "bedrock") {
|
||||||
@ -31,28 +33,39 @@ module.exports = async function (version, force_install, callback) {
|
|||||||
if (version === "latest") version = Servers.latest.bedrock
|
if (version === "latest") version = Servers.latest.bedrock
|
||||||
if (!(force_install === true) && ServerVersion.bedrock === version) {
|
if (!(force_install === true) && ServerVersion.bedrock === version) {
|
||||||
console.warn("Jumping, installed version")
|
console.warn("Jumping, installed version")
|
||||||
if (typeof callback === "function") await callback(undefined, true);
|
if (typeof callback === "function") callback(undefined, true);
|
||||||
promise_resolve(true);
|
promise_resolve(true);
|
||||||
} else {
|
} else {
|
||||||
|
// Get Server Version
|
||||||
if (Servers.bedrock[version].data) console.log(`Server data publish: ${Servers.bedrock[version].data}`)
|
if (Servers.bedrock[version].data) console.log(`Server data publish: ${Servers.bedrock[version].data}`)
|
||||||
url = Servers.bedrock[version][bds.arch][process.platform]
|
const BedrockUrlDownload = Servers.bedrock[version][bds.arch][process.platform]
|
||||||
|
|
||||||
|
// Copy Config files
|
||||||
var server_configs, permissions, whitelist;
|
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, "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, "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");
|
if (existsSync(join(bds_dir_bedrock, "whitelist.json"))) whitelist = readFileSync(join(bds_dir_bedrock, "whitelist.json"), "utf8");
|
||||||
|
|
||||||
// Download and Add to Adm_Zip
|
// Download and Add to Adm_Zip
|
||||||
const zip = new AdmZip(Buffer.from((await (await fetch(url)).arrayBuffer())))
|
Request.BUFFER(BedrockUrlDownload).then(Buffer => {
|
||||||
|
// Extract Zip
|
||||||
|
const zip = new AdmZip(Buffer);
|
||||||
console.log("Download Sucess")
|
console.log("Download Sucess")
|
||||||
|
|
||||||
zip.extractAllTo(bds_dir_bedrock, true)
|
zip.extractAllTo(bds_dir_bedrock, true)
|
||||||
console.log("Extract Sucess")
|
console.log("Extract Sucess")
|
||||||
|
|
||||||
|
// Reeplace Server Configs
|
||||||
if (server_configs) writeFileSync(join(bds_dir_bedrock, "server.properties"), 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 (permissions) writeFileSync(join(bds_dir_bedrock, "permissions.json"), permissions);
|
||||||
if (whitelist) writeFileSync(join(bds_dir_bedrock, "whitelist.json"), whitelist)
|
if (whitelist) writeFileSync(join(bds_dir_bedrock, "whitelist.json"), whitelist);
|
||||||
|
|
||||||
|
// Update Server Version
|
||||||
UpdateServerVersion(version);
|
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")
|
||||||
}
|
}
|
||||||
@ -63,17 +76,23 @@ module.exports = async function (version, force_install, callback) {
|
|||||||
if (version === "latest") version = Servers.latest.java
|
if (version === "latest") version = Servers.latest.java
|
||||||
if (!(force_install === true) && version === ServerVersion.java) {
|
if (!(force_install === true) && version === ServerVersion.java) {
|
||||||
console.warn("Jumping, installed version")
|
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);
|
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")
|
||||||
}
|
}
|
||||||
@ -84,22 +103,23 @@ module.exports = async function (version, force_install, callback) {
|
|||||||
if (version === "latest") version = Servers.latest.pocketmine
|
if (version === "latest") version = Servers.latest.pocketmine
|
||||||
if (!(force_install === true) && version === ServerVersion.pocketmine) {
|
if (!(force_install === true) && version === ServerVersion.pocketmine) {
|
||||||
console.warn("Jumping, installed version")
|
console.warn("Jumping, installed version")
|
||||||
if (typeof callback === "function") await callback(undefined, true);
|
promise_resolve();
|
||||||
promise_resolve(true)
|
if (typeof callback === "function") callback(undefined);
|
||||||
} else {
|
} else {
|
||||||
const PocketMineJson = Servers.pocketmine[version]
|
const PocketMineJson = Servers.pocketmine[version]
|
||||||
console.log(`Server data publish: ${PocketMineJson.data}`);
|
console.log(`Server data publish: ${PocketMineJson.data}`);
|
||||||
|
|
||||||
writeFileSync(join(bds_dir_pocketmine, "PocketMine-MP.phar"), Buffer.from((await (await fetch(PocketMineJson.url)).arrayBuffer())), "binary")
|
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");
|
console.log("Success downloading and saving PocketMine-MP php");
|
||||||
|
php_download().then(() => {
|
||||||
await php_download();
|
|
||||||
|
|
||||||
// Update server Version
|
// Update server Version
|
||||||
UpdateServerVersion(version)
|
UpdateServerVersion(version)
|
||||||
// Callback
|
// Callback
|
||||||
if (typeof callback === "function") await callback(undefined, true);
|
|
||||||
promise_resolve(true);
|
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")
|
||||||
}
|
}
|
||||||
@ -110,16 +130,18 @@ module.exports = async function (version, force_install, callback) {
|
|||||||
if (version === "latest") version = Servers.latest.spigot;
|
if (version === "latest") version = Servers.latest.spigot;
|
||||||
if (!(force_install === true) && version === ServerVersion.spigot) {
|
if (!(force_install === true) && version === ServerVersion.spigot) {
|
||||||
console.warn("Jumping, installed version")
|
console.warn("Jumping, installed version")
|
||||||
if (typeof callback === "function") await callback(undefined, true);
|
if (typeof callback === "function") callback(undefined, true);
|
||||||
promise_resolve(true)
|
promise_resolve(true)
|
||||||
} else {
|
} else {
|
||||||
const SpigotURL = Servers.spigot[version].url;
|
const SpigotArray = Servers.spigot[version];
|
||||||
if (Servers.spigot[version].data) console.log(`Server data publish: ${Servers.spigot[version].data}`);
|
if (SpigotArray.data) console.log(`Server data publish: ${SpigotArray.data}`);
|
||||||
writeFileSync(join(bds_dir_spigot, "spigot.jar"), Buffer.from((await (await fetch(SpigotURL)).arrayBuffer())), "binary");
|
Request.BUFFER(SpigotArray.url).then(Buffer => {
|
||||||
|
writeFileSync(join(bds_dir_spigot, "spigot.jar"), Buffer, "binary");
|
||||||
console.log("Success when downloading and saving Spigot");
|
console.log("Success when downloading and saving Spigot");
|
||||||
UpdateServerVersion(version);
|
UpdateServerVersion(version);
|
||||||
if (typeof callback === "function") await callback(undefined, true);
|
promise_resolve();
|
||||||
promise_resolve(true);
|
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")
|
||||||
}
|
}
|
||||||
@ -131,17 +153,19 @@ module.exports = async function (version, force_install, callback) {
|
|||||||
execSync("git clone https://github.com/df-mc/dragonfly ./", {
|
execSync("git clone https://github.com/df-mc/dragonfly ./", {
|
||||||
cwd: bds_dir_dragonfly
|
cwd: bds_dir_dragonfly
|
||||||
});
|
});
|
||||||
if (typeof callback === "function") await callback(undefined, true);
|
|
||||||
promise_resolve(true);
|
promise_resolve(true);
|
||||||
|
if (typeof callback === "function") callback(undefined);
|
||||||
} else throw Error("Dragonfly not suported")
|
} else throw Error("Dragonfly not suported")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unidentified platform
|
// Unidentified platform
|
||||||
else throw Error("Bds maneger Config file error")
|
else throw Error("Bds maneger Config file error")
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (typeof callback === "function") await callback(err, false);
|
promise_reject(err);
|
||||||
return 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");
|
var fs = require("fs");
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
const propertiesToJSON = require("properties-to-json");
|
const propertiesToJSON = require("properties-to-json");
|
||||||
const { join } = require("path");
|
const BdsInfo = require("../lib/BdsSystemInfo");
|
||||||
const { GetServerPaths, GetPlatform } = require("../lib/BdsSettings");
|
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(
|
const ConfigFilePath = {
|
||||||
NewConfig = {
|
bedrock: path.join(GetServerPaths("bedrock"), "server.properties"),
|
||||||
world: "Bds Maneger",
|
java: path.join(GetServerPaths("java"), "server.properties"),
|
||||||
description: "The Bds Maneger",
|
pocketmine: path.join(GetServerPaths("pocketmine"), "server.properties")
|
||||||
gamemode: "creative",
|
|
||||||
difficulty: "normal",
|
|
||||||
players: 10,
|
|
||||||
commands: true,
|
|
||||||
account: true,
|
|
||||||
whitelist: true,
|
|
||||||
port: 19132,
|
|
||||||
portv6: 19133,
|
|
||||||
seed: ""
|
|
||||||
}
|
}
|
||||||
){
|
|
||||||
let JsonConfig = {
|
// 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",
|
world: "Bds Maneger",
|
||||||
description: "The Bds Maneger",
|
description: "The Bds Maneger",
|
||||||
gamemode: "creative",
|
gamemode: "creative",
|
||||||
@ -35,31 +26,31 @@ function bds_config(
|
|||||||
seed: ""
|
seed: ""
|
||||||
};
|
};
|
||||||
|
|
||||||
if (NewConfig.world) JsonConfig.world = NewConfig.world
|
// Strings
|
||||||
if (NewConfig.description) JsonConfig.description = NewConfig.description
|
if (typeof NewConfig.world === "string" && NewConfig.world) JsonConfig.world = NewConfig.world
|
||||||
if (NewConfig.gamemode) JsonConfig.gamemode = NewConfig.gamemode
|
if (typeof NewConfig.description === "string" && NewConfig.description) JsonConfig.description = NewConfig.description
|
||||||
if (NewConfig.difficulty) JsonConfig.difficulty = NewConfig.difficulty
|
if (typeof NewConfig.gamemode === "string" && NewConfig.gamemode) JsonConfig.gamemode = NewConfig.gamemode
|
||||||
if (NewConfig.players) JsonConfig.players = NewConfig.players
|
if (typeof NewConfig.difficulty === "string" && NewConfig.difficulty) JsonConfig.difficulty = NewConfig.difficulty
|
||||||
if (NewConfig.commands || NewConfig.commands === false) JsonConfig.commands = NewConfig.commands
|
if ((typeof NewConfig.seed === "string" || typeof NewConfig.seed === "number") && NewConfig.seed) JsonConfig.seed = NewConfig.seed
|
||||||
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;
|
// 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") {
|
if (GetPlatform() === "bedrock") {
|
||||||
var tickDistance;
|
const bedrockCPUThread = BdsInfo.GetCpuCoreCount();
|
||||||
if (bedrockCPUThread >= 12) tickDistance = 12;
|
var tickDistance; if (!(bedrockCPUThread % 2)) tickDistance = bedrockCPUThread; else tickDistance = 1;
|
||||||
else if (bedrockCPUThread >= 10) tickDistance = 10;
|
Config.push(
|
||||||
else if (bedrockCPUThread >= 8) tickDistance = 8;
|
"# By The Bds Maneger project",
|
||||||
else if (bedrockCPUThread >= 6) tickDistance = 6;
|
`# Date: ${Date.now()}`,
|
||||||
else if (bedrockCPUThread >= 4) tickDistance = 4;
|
"",
|
||||||
else if (bedrockCPUThread >= 2) tickDistance = 2;
|
|
||||||
else tickDistance = 1;
|
|
||||||
|
|
||||||
ConfigFile = join(bds_dir_bedrock, "server.properties");
|
|
||||||
Config = [
|
|
||||||
`level-name=${JsonConfig.world}`,
|
`level-name=${JsonConfig.world}`,
|
||||||
`server-name=${JsonConfig.description}`,
|
`server-name=${JsonConfig.description}`,
|
||||||
`gamemode=${JsonConfig.gamemode}`,
|
`gamemode=${JsonConfig.gamemode}`,
|
||||||
@ -84,11 +75,13 @@ function bds_config(
|
|||||||
"player-movement-distance-threshold=0.3",
|
"player-movement-distance-threshold=0.3",
|
||||||
"player-movement-duration-threshold-in-ms=500",
|
"player-movement-duration-threshold-in-ms=500",
|
||||||
"correct-player-movement=false",
|
"correct-player-movement=false",
|
||||||
"server-authoritative-block-breaking=false"
|
"server-authoritative-block-breaking=false",
|
||||||
]
|
);
|
||||||
} else if (GetPlatform() === "java") {
|
} else if (GetPlatform() === "java") {
|
||||||
ConfigFile = join(bds_dir_java, "server.properties");
|
Config.push(
|
||||||
Config = [
|
"# By The Bds Maneger project",
|
||||||
|
`# Date: ${Date.now()}`,
|
||||||
|
"",
|
||||||
`level-name=${JsonConfig.world}`,
|
`level-name=${JsonConfig.world}`,
|
||||||
`motd=${JsonConfig.description}`,
|
`motd=${JsonConfig.description}`,
|
||||||
`gamemode=${JsonConfig.gamemode}`,
|
`gamemode=${JsonConfig.gamemode}`,
|
||||||
@ -138,20 +131,38 @@ function bds_config(
|
|||||||
"enforce-whitelist=false",
|
"enforce-whitelist=false",
|
||||||
"resource-pack-sha1=",
|
"resource-pack-sha1=",
|
||||||
"spawn-protection=16",
|
"spawn-protection=16",
|
||||||
"max-world-size=29999984"
|
"max-world-size=29999984",
|
||||||
]
|
);
|
||||||
} else if (GetPlatform() === "pocketmine") {
|
} else if (GetPlatform() === "pocketmine") {
|
||||||
ConfigFile = join(bds_dir_pocketmine, "server.properties");
|
// Whitelist
|
||||||
Config = [
|
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",
|
"language=eng",
|
||||||
`level-name=${JsonConfig.world}`,
|
`level-name=${JsonConfig.world}`,
|
||||||
`motd=${JsonConfig.description}`,
|
`motd=${JsonConfig.description}`,
|
||||||
`server-port=${JsonConfig.port}`,
|
`server-port=${JsonConfig.port}`,
|
||||||
`white-list=${(()=>{if (JsonConfig.whitelist === true) return "on";else return "off";})()}`,
|
`white-list=${JsonConfig.whitelist}`,
|
||||||
`max-players=${JsonConfig.players}`,
|
`max-players=${JsonConfig.players}`,
|
||||||
`gamemode=${JsonConfig.gamemode}`,
|
`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");})()}`,
|
`difficulty=${JsonConfig.difficulty}`,
|
||||||
`xbox-auth=${(()=>{if (JsonConfig.account === true) return "on";else return "off";})()}`,
|
`xbox-auth=${JsonConfig.account}`,
|
||||||
`level-seed=${JsonConfig.seed}`,
|
`level-seed=${JsonConfig.seed}`,
|
||||||
"view-distance=32",
|
"view-distance=32",
|
||||||
"hardcore=0",
|
"hardcore=0",
|
||||||
@ -164,31 +175,30 @@ function bds_config(
|
|||||||
"enable-query=on",
|
"enable-query=on",
|
||||||
"enable-rcon=off",
|
"enable-rcon=off",
|
||||||
"rcon.password=F/deZ5kefY",
|
"rcon.password=F/deZ5kefY",
|
||||||
"auto-save=on"
|
"auto-save=on",
|
||||||
]
|
);
|
||||||
|
}
|
||||||
|
fs.writeFileSync(ConfigFilePath[GetPlatform()], Config.join("\n"))
|
||||||
|
return Config.join("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
Config.push("")
|
// Get Config
|
||||||
Config.push("")
|
|
||||||
Config.push("# By The Bds Maneger project")
|
|
||||||
fs.writeFileSync(ConfigFile, Config.join("\n"))
|
|
||||||
return Config;
|
|
||||||
}
|
|
||||||
function bds_get_config(){
|
function bds_get_config(){
|
||||||
var config;
|
var config;
|
||||||
const JsonConfig = {
|
const JsonConfig = {
|
||||||
world: null,
|
world: "",
|
||||||
description: null,
|
description: "",
|
||||||
gamemode: null,
|
gamemode: "",
|
||||||
difficulty: null,
|
difficulty: "",
|
||||||
players: null,
|
players: "",
|
||||||
whitelist: null,
|
whitelist: null,
|
||||||
portv4: null,
|
portv4: 0,
|
||||||
portv6: null,
|
portv6: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (GetPlatform() === "bedrock") {
|
if (GetPlatform() === "bedrock") {
|
||||||
config = propertiesToJSON(fs.readFileSync(path.join(bds_dir_bedrock, "server.properties"), "utf8"));
|
if (fs.existsSync(ConfigFilePath[GetPlatform()])) {
|
||||||
|
config = propertiesToJSON(fs.readFileSync(ConfigFilePath["bedrock"], "utf8"));
|
||||||
|
|
||||||
// Players
|
// Players
|
||||||
JsonConfig.world = config["level-name"];
|
JsonConfig.world = config["level-name"];
|
||||||
@ -206,8 +216,10 @@ function bds_get_config(){
|
|||||||
JsonConfig.commands = (config["allow-cheats"] === "true");
|
JsonConfig.commands = (config["allow-cheats"] === "true");
|
||||||
// JsonConfig.worldtype = "default";
|
// JsonConfig.worldtype = "default";
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else if (GetPlatform() === "java") {
|
else if (GetPlatform() === "java") {
|
||||||
config = propertiesToJSON(fs.readFileSync(path.join(bds_dir_java, "server.properties"), "utf8"));
|
if (fs.existsSync(ConfigFilePath[GetPlatform()])) {
|
||||||
|
config = propertiesToJSON(fs.readFileSync(path.join(ConfigFilePath["java"], "server.properties"), "utf8"));
|
||||||
|
|
||||||
// Players
|
// Players
|
||||||
JsonConfig.world = config["level-name"];
|
JsonConfig.world = config["level-name"];
|
||||||
@ -225,8 +237,10 @@ function bds_get_config(){
|
|||||||
JsonConfig.commands = (config["enable-command-block"] === "true");
|
JsonConfig.commands = (config["enable-command-block"] === "true");
|
||||||
// JsonConfig.worldtype = config["level-type"];
|
// JsonConfig.worldtype = config["level-type"];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else if (GetPlatform() === "pocketmine") {
|
else if (GetPlatform() === "pocketmine") {
|
||||||
config = propertiesToJSON(fs.readFileSync(path.join(bds_dir_pocketmine, "server.properties"), "utf8"));
|
if (fs.existsSync(ConfigFilePath[GetPlatform()])) {
|
||||||
|
config = propertiesToJSON(fs.readFileSync(path.join(ConfigFilePath["pocketmine"], "server.properties"), "utf8"));
|
||||||
|
|
||||||
// Players
|
// Players
|
||||||
JsonConfig.world = config["level-name"];
|
JsonConfig.world = config["level-name"];
|
||||||
@ -243,10 +257,12 @@ function bds_get_config(){
|
|||||||
JsonConfig.seed = config["level-seed"];
|
JsonConfig.seed = config["level-seed"];
|
||||||
JsonConfig.commands = false;
|
JsonConfig.commands = false;
|
||||||
// JsonConfig.worldtype = config["level-type"];
|
// JsonConfig.worldtype = config["level-type"];
|
||||||
} else if (GetPlatform() === "jsprismarine") throw "Platform not fully supported";
|
}
|
||||||
else throw new Error("Platform no exists, check config file");
|
} else throw new Error("Platform no exists, check config file");
|
||||||
return JsonConfig;
|
return JsonConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// To remove
|
||||||
function config_example(){
|
function config_example(){
|
||||||
return {
|
return {
|
||||||
name: "Bedrock our Java",
|
name: "Bedrock our Java",
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
const express = require("express");
|
const express = require("express");
|
||||||
const app = express.Router();
|
const app = express.Router();
|
||||||
const { GetPlatform, GetPaths } = require("../../../lib/BdsSettings")
|
const { GetPlatform, GetPaths } = require("../../../lib/BdsSettings")
|
||||||
const bds = require("../../../index");
|
|
||||||
const { token_verify, CheckPlayer } = require("../../UsersAndtokenChecks");
|
const { token_verify, CheckPlayer } = require("../../UsersAndtokenChecks");
|
||||||
const { readFileSync } = require("fs");
|
const { readFileSync } = require("fs");
|
||||||
const docs = require("../../../BdsManegerInfo.json").docs;
|
const docs = require("../../../BdsManegerInfo.json").docs;
|
Reference in New Issue
Block a user