Modifications #241
@ -4,6 +4,10 @@ process.env.IS_BDS_CLI = process.env.IS_BIN_BDS = true;
|
|||||||
// Internal Modules
|
// Internal Modules
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
|
const readline = require("readline");
|
||||||
|
|
||||||
|
// Import Bds Core
|
||||||
|
const BdsCore = require("../index");
|
||||||
|
|
||||||
// External Modules
|
// External Modules
|
||||||
const cli_color = require("cli-color");
|
const cli_color = require("cli-color");
|
||||||
@ -12,14 +16,6 @@ const inquirer = require("inquirer");
|
|||||||
// Bin Args
|
// Bin Args
|
||||||
const ProcessArgs = require("minimist")(process.argv.slice(2));
|
const ProcessArgs = require("minimist")(process.argv.slice(2));
|
||||||
|
|
||||||
// Import Bds Core
|
|
||||||
const BdsCore = require("../index");
|
|
||||||
const BdsNetwork = require("../src/BdsNetwork");
|
|
||||||
const commandExits = require("../lib/commandExist");
|
|
||||||
const readline = require("readline");
|
|
||||||
const { PlatformVersionsV2 } = require("../src/BdsServersDownload");
|
|
||||||
const { GetPlatform } = require("../lib/BdsSettings");
|
|
||||||
|
|
||||||
// Load Bds Maneger CLI Plugins
|
// Load Bds Maneger CLI Plugins
|
||||||
const MoreHelp = [];
|
const MoreHelp = [];
|
||||||
const BeforeRun = [];
|
const BeforeRun = [];
|
||||||
@ -50,7 +46,7 @@ fs.readdirSync(path.join(__dirname, "plugins")).map(file => path.resolve(__dirna
|
|||||||
|
|
||||||
async function DownloadServer() {
|
async function DownloadServer() {
|
||||||
const ora = (await import("ora")).default;
|
const ora = (await import("ora")).default;
|
||||||
const PlatformVersion = await PlatformVersionsV2()
|
const PlatformVersion = await BdsCore.BdsDownload.PlatformVersionsV2();
|
||||||
const waitUserSelectVersion = (await inquirer.prompt({
|
const waitUserSelectVersion = (await inquirer.prompt({
|
||||||
type: "list",
|
type: "list",
|
||||||
name: "version",
|
name: "version",
|
||||||
@ -59,7 +55,7 @@ async function DownloadServer() {
|
|||||||
})).version;
|
})).version;
|
||||||
const RunSpinner = ora("Downloading...").start();
|
const RunSpinner = ora("Downloading...").start();
|
||||||
try {
|
try {
|
||||||
const DownloadRes = await BdsCore.download(waitUserSelectVersion);
|
const DownloadRes = await BdsCore.BdsDownload(waitUserSelectVersion);
|
||||||
RunSpinner.succeed(`Downloaded ${DownloadRes.version}, Published in ${DownloadRes.data.getDate()}/${DownloadRes.data.getMonth()}/${DownloadRes.data.getFullYear()}`);
|
RunSpinner.succeed(`Downloaded ${DownloadRes.version}, Published in ${DownloadRes.data.getDate()}/${DownloadRes.data.getMonth()}/${DownloadRes.data.getFullYear()}`);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
RunSpinner.fail(String(err));
|
RunSpinner.fail(String(err));
|
||||||
@ -68,22 +64,23 @@ async function DownloadServer() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function info() {
|
async function info() {
|
||||||
const { valid_platform } = await (require("../lib/BdsSystemInfo"))();
|
const { valid_platform } = await (require("../src/lib/BdsSystemInfo"))();
|
||||||
var checkothearch = "";
|
var checkothearch = "";
|
||||||
if (process.platform === "linux" && BdsCore.arch !== "x64"){checkothearch = `qemu-x86_64-static is installed to emulate an x64 system: ${commandExits("qemu-x86_64-static")}\n`}
|
if (process.platform === "linux" && BdsCore.BdsSystemInfo.arch !== "x64"){checkothearch = `qemu-x86_64-static is installed to emulate an x64 system: ${commandExits("qemu-x86_64-static")}\n`}
|
||||||
if (process.platform === "android" && BdsCore.arch !== "x64"){checkothearch = `qemu-x86_64 is installed to emulate an x64 system: ${commandExits("qemu-x86_64")}\n`}
|
if (process.platform === "android" && BdsCore.BdsSystemInfo.arch !== "x64"){checkothearch = `qemu-x86_64 is installed to emulate an x64 system: ${commandExits("qemu-x86_64")}\n`}
|
||||||
const info = [
|
const info = [
|
||||||
`Bds Maneger Core And Bds Maneger CLI version: ${cli_color.magentaBright(BdsCore.package_json.version)}`,
|
"",
|
||||||
`System: ${cli_color.yellow(process.platform)}, architecture: ${cli_color.blue(BdsCore.arch)}`,
|
`Bds Maneger Core And Bds Maneger CLI version: ${cli_color.magentaBright(BdsCore.version)}`,
|
||||||
checkothearch,
|
`System: ${cli_color.yellow(process.platform)}, architecture: ${cli_color.blue(BdsCore.BdsSystemInfo.arch)}`,
|
||||||
"**************************************************************",
|
checkothearch,
|
||||||
"* Servers currently available:",
|
"**************************************************************",
|
||||||
`* - Bedrock: ${valid_platform.bedrock}`,
|
"* Servers currently available:",
|
||||||
`* - Java and Spigot: ${valid_platform.java ? cli_color.green("Available") : cli_color.red("Needs Java installed https://upstream.bdsmaneger.com/docs/Java?Installer=info")}`,
|
`* - Bedrock: ${valid_platform.bedrock ? cli_color.greenBright("Avaible") : cli_color.redBright("Not Avaible")}`,
|
||||||
`* - Dragonfly: ${valid_platform.dragonfly}`,
|
`* - Java and Spigot: ${valid_platform.java ? cli_color.greenBright("Avaible") : cli_color.redBright("Not Avaible")}`,
|
||||||
`* - Pocketmine-MP: ${valid_platform.pocketmine}`,
|
`* - Dragonfly: ${valid_platform.dragonfly ? cli_color.greenBright("Avaible") : cli_color.redBright("Not Avaible")}`,
|
||||||
"*",
|
`* - Pocketmine-MP: ${valid_platform.pocketmine ? cli_color.greenBright("Avaible") : cli_color.redBright("Not Avaible")}`,
|
||||||
"**************************************************************"
|
"*",
|
||||||
|
"**************************************************************"
|
||||||
];
|
];
|
||||||
console.log(cli_color.whiteBright(info.join("\n").replace(/true/gi, cli_color.greenBright("true")).replace(/false/gi, cli_color.redBright("false")).replace(/undefined/gi, cli_color.red("undefined"))));
|
console.log(cli_color.whiteBright(info.join("\n").replace(/true/gi, cli_color.greenBright("true")).replace(/false/gi, cli_color.redBright("false")).replace(/undefined/gi, cli_color.red("undefined"))));
|
||||||
// End
|
// End
|
||||||
@ -92,8 +89,8 @@ async function info() {
|
|||||||
|
|
||||||
async function help() {
|
async function help() {
|
||||||
const help = [
|
const help = [
|
||||||
`Bds Maneger CLI version: ${cli_color.magentaBright(BdsCore.package_json.version)}`,
|
`Bds Maneger CLI version: ${cli_color.magentaBright(BdsCore.version)}`,
|
||||||
`System: ${cli_color.yellow(process.platform)}, architecture: ${cli_color.blue(BdsCore.arch)}`,
|
`System: ${cli_color.yellow(process.platform)}, architecture: ${cli_color.blue(BdsCore.BdsSystemInfo.arch)}`,
|
||||||
"",
|
"",
|
||||||
" Usage: bds-maneger-cli [options]",
|
" Usage: bds-maneger-cli [options]",
|
||||||
"",
|
"",
|
||||||
@ -132,7 +129,7 @@ async function Runner() {
|
|||||||
if (ProcessArgs.platform || ProcessArgs.p) {
|
if (ProcessArgs.platform || ProcessArgs.p) {
|
||||||
const UpdatePla = ora("Updating Bds Platform").start();
|
const UpdatePla = ora("Updating Bds Platform").start();
|
||||||
try {
|
try {
|
||||||
BdsCore.platform_update(ProcessArgs.platform || ProcessArgs.p);
|
BdsCore.BdsSettings.UpdatePlatform(ProcessArgs.platform || ProcessArgs.p);
|
||||||
UpdatePla.succeed(`Now the platform is the ${ProcessArgs.platform || ProcessArgs.p}`);
|
UpdatePla.succeed(`Now the platform is the ${ProcessArgs.platform || ProcessArgs.p}`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
UpdatePla.fail(`Unable to update platform to ${ProcessArgs.platform || ProcessArgs.p}`);
|
UpdatePla.fail(`Unable to update platform to ${ProcessArgs.platform || ProcessArgs.p}`);
|
||||||
@ -155,13 +152,19 @@ async function Runner() {
|
|||||||
// Download
|
// Download
|
||||||
if (ProcessArgs.download || ProcessArgs.d) await DownloadServer();
|
if (ProcessArgs.download || ProcessArgs.d) await DownloadServer();
|
||||||
|
|
||||||
|
|
||||||
|
// Load Plugins
|
||||||
|
for (let Plugin of BeforeRun) {
|
||||||
|
if (!(ProcessArgs[Plugin.arg])) Plugin.main(ProcessArgs[Plugin.arg], ProcessArgs).catch(err => console.log("Plugin Crash:", "\n\n", err));
|
||||||
|
}
|
||||||
|
|
||||||
// Start Server
|
// Start Server
|
||||||
if (!(ProcessArgs.start || ProcessArgs.s)) return;
|
if (!(ProcessArgs.start || ProcessArgs.s)) return;
|
||||||
|
|
||||||
// Get Temporary External Domain
|
// Get Temporary External Domain
|
||||||
if (ProcessArgs.get_domain) {
|
if (ProcessArgs.get_domain) {
|
||||||
try {
|
try {
|
||||||
const HostInfo = await BdsNetwork.GetHost();
|
const HostInfo = await BdsCore.BdsNetwork.GetHost();
|
||||||
console.log("Domain:", HostInfo.host);
|
console.log("Domain:", HostInfo.host);
|
||||||
process.on("exit", async () => {
|
process.on("exit", async () => {
|
||||||
await HostInfo.delete_host();
|
await HostInfo.delete_host();
|
||||||
@ -172,12 +175,7 @@ async function Runner() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load Plugins
|
const BdsManegerServer = BdsCore.BdsManegerServer.StartServer();
|
||||||
for (let Plugin of BeforeRun) {
|
|
||||||
if (!(ProcessArgs[Plugin.arg])) Plugin.main(ProcessArgs[Plugin.arg], ProcessArgs).catch(err => console.log("Plugin Crash:", "\n\n", err));
|
|
||||||
}
|
|
||||||
|
|
||||||
const BdsManegerServer = BdsCore.start();
|
|
||||||
BdsManegerServer.log(data => console.log(cli_color.blueBright(data.replace(/\n$/gi, ""))));
|
BdsManegerServer.log(data => console.log(cli_color.blueBright(data.replace(/\n$/gi, ""))));
|
||||||
BdsManegerServer.exit(code => {
|
BdsManegerServer.exit(code => {
|
||||||
console.log(cli_color.redBright(`Bds Core Exit with code ${code}, Uptimed: ${BdsManegerServer.uptime}`));
|
console.log(cli_color.redBright(`Bds Core Exit with code ${code}, Uptimed: ${BdsManegerServer.uptime}`));
|
||||||
|
185
bin/Docker.js
185
bin/Docker.js
@ -1,126 +1,95 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
process.env.BDS_DOCKER_IMAGE = true;
|
process.env.BDS_DOCKER_IMAGE = true;
|
||||||
const path = require("path");
|
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
|
|
||||||
const BdsCore = require("../index");
|
const BdsCore = require("../index");
|
||||||
const { GetPlatform, bds_dir } = require("../lib/BdsSettings");
|
const { GetPlatform, bds_dir } = require("../src/lib/BdsSettings");
|
||||||
const { CronJob } = require("cron");
|
const { CronJob } = require("cron");
|
||||||
const BdsInfo = require("../BdsManegerInfo.json");
|
|
||||||
const { PlatformVersionsV2 } = require("../src/BdsServersDownload");
|
const { PlatformVersionsV2 } = require("../src/BdsServersDownload");
|
||||||
|
|
||||||
// Get Current Tokens and Show in the console
|
// Get Current Tokens and Show in the console
|
||||||
function ShowToken() {
|
function ShowToken() {
|
||||||
const TokenFilePath = path.join(bds_dir, "bds_tokens.json");
|
const TokenFilePath = BdsCore.BdsManegerAPI.TokensFilePath;
|
||||||
let Tokens = 1
|
let Tokens = 1
|
||||||
if (fs.existsSync(TokenFilePath)) {
|
if (fs.existsSync(TokenFilePath)) {
|
||||||
[...JSON.parse(fs.readFileSync(TokenFilePath, "utf8"))].slice(0, 5).forEach(token => {console.log(Tokens+":", "Bds API Token:", token.token); Tokens++});
|
[...JSON.parse(fs.readFileSync(TokenFilePath, "utf8"))].slice(0, 5).forEach(token => {console.log(Tokens+":", "Bds API Token:", token.token); Tokens++});
|
||||||
} else {
|
} else {
|
||||||
console.log("No Tokens Found");
|
console.log(Tokens+":", "Bds API Token:", BdsCore.BdsManegerAPI.token_register());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function StartServer(){
|
async function CheckAndUpdateServer() {
|
||||||
console.log("The entire log can be accessed via the api and/or the docker log");
|
const LatestVersion = (await BdsCore.BdsDownload.PlatformVersionsV2()).latest;
|
||||||
const ServerStarted = BdsCore.start();
|
const LocalVersion = BdsCore.BdsSettings.GetServerVersion()[GetPlatform()];
|
||||||
ServerStarted.log(a => process.stdout.write(a));
|
if (!LocalVersion) {
|
||||||
ServerStarted.exit(code => process.exit(code));
|
console.log("Server is not installed, starting server implementation");
|
||||||
BdsCore.api();
|
const __InitInstall = await BdsCore.BdsDownload(true);
|
||||||
if (process.env.PULL_REQUEST === "true") {
|
console.log("Installed Version:", __InitInstall.version, `Release Version: ${__InitInstall.data.getDate()}/${__InitInstall.data.getMonth()}/${__InitInstall.data.getFullYear()}`);
|
||||||
console.log((require("cli-color")).red("Pull Request Actived 1 Min to exit"));
|
} else if (LocalVersion !== LatestVersion) {
|
||||||
setTimeout(() => {
|
console.log("Server is out of date, starting server implementation");
|
||||||
ServerStarted.stop();
|
const __UpdateInstall = await BdsCore.BdsDownload(true);
|
||||||
}, 1 * 60 * 1000)
|
console.log("Updated Version:", __UpdateInstall.version, `Release Version: ${__UpdateInstall.data.getDate()}/${__UpdateInstall.data.getMonth()}/${__UpdateInstall.data.getFullYear()}`);
|
||||||
}
|
}
|
||||||
ShowToken();
|
new CronJob("0 */1 * * *", async () => {
|
||||||
if (process.env.UPDATE_SERVER === "true") {
|
try {
|
||||||
new CronJob("0 */1 * * *", async () => {
|
const CurrentLocalVersion = BdsCore.BdsSettings.GetServerVersion()[GetPlatform()],
|
||||||
try {
|
CurrentRemoteVersion = (await PlatformVersionsV2(GetPlatform())).latest;
|
||||||
const CurrentLocalVersion = BdsCore.getBdsConfig().server.versions[GetPlatform()],
|
if (CurrentLocalVersion !== CurrentRemoteVersion) {
|
||||||
CurrentRemoteVersion = (await PlatformVersionsV2(GetPlatform())).latest;
|
let currenttime = `Hello we are starting the server upgrade from version ${CurrentLocalVersion} to version ${CurrentRemoteVersion}, you have 20 seconds to exit the server`
|
||||||
if (CurrentLocalVersion !== CurrentRemoteVersion) {
|
console.log("Update Server:", currenttime);
|
||||||
let currenttime = `Hello we are starting the server upgrade from version ${CurrentLocalVersion} to version ${CurrentRemoteVersion}, you have 20 seconds to exit the server`
|
ServerStarted.say(currenttime);
|
||||||
console.log("Update Server:", currenttime);
|
let countdown = 20;
|
||||||
ServerStarted.say(currenttime);
|
while (countdown > 1) {
|
||||||
let countdown = 20;
|
currenttime = `${countdown} seconds remaining to stop Server!`;
|
||||||
while (countdown > 1) {
|
console.log(currenttime);
|
||||||
currenttime = `${countdown} seconds remaining to stop Server!`;
|
ServerStarted.say(currenttime);
|
||||||
console.log(currenttime);
|
countdown--;
|
||||||
ServerStarted.say(currenttime);
|
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||||
countdown--;
|
}
|
||||||
await new Promise(resolve => setTimeout(resolve, 1000));
|
currenttime = "Stopping the server"
|
||||||
}
|
console.log(currenttime);
|
||||||
currenttime = "Stopping the server"
|
ServerStarted.say(currenttime);
|
||||||
console.log(currenttime);
|
await new Promise(resolve => setTimeout(resolve, 600));
|
||||||
ServerStarted.say(currenttime);
|
ServerStarted.stop();
|
||||||
await new Promise(resolve => setTimeout(resolve, 600));
|
}
|
||||||
ServerStarted.stop();
|
} catch (err) {
|
||||||
}
|
console.log(err);
|
||||||
} catch (err) {
|
|
||||||
console.log(err);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function StartServer(){
|
||||||
|
ShowToken();
|
||||||
|
console.log("The entire log can be accessed via the api and/or the docker log");
|
||||||
|
const ServerStarted = BdsCore.BdsManegerServer.StartServer();
|
||||||
|
ServerStarted.log(a => process.stdout.write(a));
|
||||||
|
ServerStarted.exit(code => process.exit(code));
|
||||||
|
BdsCore.BdsManegerAPI.api();
|
||||||
|
if (process.env.PULL_REQUEST === "true") {
|
||||||
|
console.log((require("cli-color")).red("Pull Request Actived 1 Min to exit"));
|
||||||
|
setTimeout(() => {
|
||||||
|
ServerStarted.stop();
|
||||||
|
}, 1 * 60 * 1000)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function RenderCLI(){
|
async function RenderCLI(){
|
||||||
// Check Installed Server
|
await CheckAndUpdateServer();
|
||||||
const AllVersions = BdsCore.BdsSettigs.GetJsonConfig().server.versions;
|
const { DESCRIPTION, WORLD_NAME, GAMEMODE, DIFFICULTY, ACCOUNT, PLAYERS, SERVER, ENABLE_COMMANDS } = process.env;
|
||||||
if (Object.getOwnPropertyNames(AllVersions).filter(platform => AllVersions[platform]).length >= 1) {
|
BdsCore.BdsSettings.UpdatePlatform(SERVER || "bedrock");
|
||||||
if (process.env.UPDATE_SERVER === "true") {
|
const ServerConfig = {
|
||||||
try {
|
world: WORLD_NAME,
|
||||||
await BdsCore.download(true, true);
|
description: DESCRIPTION,
|
||||||
StartServer();
|
gamemode: GAMEMODE,
|
||||||
} catch (err) {
|
difficulty: DIFFICULTY,
|
||||||
console.log(err);
|
players: parseInt(PLAYERS),
|
||||||
process.exit(1);
|
commands: ENABLE_COMMANDS === "true",
|
||||||
}
|
account: ACCOUNT === "true",
|
||||||
} else {
|
whitelist: false,
|
||||||
// Check for Update
|
port: 19132,
|
||||||
if (AllVersions[GetPlatform()] === Object.getOwnPropertyNames((await (await fetch(BdsInfo.Fetchs.servers)).json())[GetPlatform()])[0]) {
|
portv6: 19133,
|
||||||
console.log("The entire log can be accessed via the api and/or the docker log");
|
}
|
||||||
const ServerStarted = BdsCore.start();
|
BdsCore.BdsServerSettings.config(ServerConfig);
|
||||||
ServerStarted.log(a => process.stdout.write(a));
|
await StartServer();
|
||||||
ServerStarted.exit(process.exit);
|
|
||||||
BdsCore.api();
|
|
||||||
} else {
|
|
||||||
BdsCore.download(true, true, (err) => {
|
|
||||||
if (err) {
|
|
||||||
console.log(err);
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
StartServer();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
console.log("Server is not installed, starting server implementation");
|
|
||||||
// Import ENV to Settings Server
|
|
||||||
const { DESCRIPTION, WORLD_NAME, GAMEMODE, DIFFICULTY, ACCOUNT, PLAYERS, SERVER, ENABLE_COMMANDS } = process.env;
|
|
||||||
// Update Platform
|
|
||||||
BdsCore.change_platform(SERVER || "bedrock");
|
|
||||||
try {
|
|
||||||
await BdsCore.download(true, true);
|
|
||||||
// Create JSON Config
|
|
||||||
const ServerConfig = {
|
|
||||||
world: WORLD_NAME,
|
|
||||||
description: DESCRIPTION,
|
|
||||||
gamemode: GAMEMODE,
|
|
||||||
difficulty: DIFFICULTY,
|
|
||||||
players: parseInt(PLAYERS),
|
|
||||||
commands: ENABLE_COMMANDS === "true",
|
|
||||||
account: ACCOUNT === "true",
|
|
||||||
whitelist: false,
|
|
||||||
port: 19132,
|
|
||||||
portv6: 19133,
|
|
||||||
}
|
|
||||||
BdsCore.bds_maneger_token_register(["admin"]);
|
|
||||||
BdsCore.set_config(ServerConfig);
|
|
||||||
StartServer();
|
|
||||||
} catch (err) {
|
|
||||||
console.log(`${err}`);
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
RenderCLI();
|
RenderCLI();
|
@ -1,8 +1,8 @@
|
|||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const { Telegraf, Markup } = require("telegraf");
|
const { Telegraf, Markup } = require("telegraf");
|
||||||
const bds = require("../../index");
|
const bds = require("../../index");
|
||||||
const { GetPlatform, GetPaths, GetTelegramToken, UpdateTelegramToken } = require("../../lib/BdsSettings");
|
const { GetPlatform, GetPaths, GetTelegramToken, UpdateTelegramToken } = require("../../src/lib/BdsSettings");
|
||||||
const { GetKernel, arch, system } = require("../../lib/BdsSystemInfo");
|
const { GetKernel, arch, system } = require("../../src/lib/BdsSystemInfo");
|
||||||
const { Detect } = require("../../src/CheckKill");
|
const { Detect } = require("../../src/CheckKill");
|
||||||
const { CheckTelegramUser } = require("../../src/UsersAndtokenChecks");
|
const { CheckTelegramUser } = require("../../src/UsersAndtokenChecks");
|
||||||
const BdsInfo = require("../../BdsManegerInfo.json");
|
const BdsInfo = require("../../BdsManegerInfo.json");
|
||||||
|
@ -1,10 +1,14 @@
|
|||||||
version: "2.1"
|
version: "3.9"
|
||||||
|
volumes:
|
||||||
|
BdsManegerData:
|
||||||
services:
|
services:
|
||||||
bdscore:
|
bdscore:
|
||||||
build:
|
build:
|
||||||
context: .
|
context: .
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
container_name: bds_maneger_core
|
container_name: bds_maneger_core
|
||||||
|
volumes:
|
||||||
|
- BdsManegerData:/root/bds_core
|
||||||
environment:
|
environment:
|
||||||
DESCRIPTION: "Docker Test"
|
DESCRIPTION: "Docker Test"
|
||||||
WORLD_NAME: "Docker Run Test"
|
WORLD_NAME: "Docker Run Test"
|
||||||
@ -16,6 +20,4 @@ services:
|
|||||||
SERVER: "bedrock"
|
SERVER: "bedrock"
|
||||||
ports:
|
ports:
|
||||||
- 1932:1932/tcp
|
- 1932:1932/tcp
|
||||||
- 19132:19132/udp
|
- 19132:19132/udp
|
||||||
volumes:
|
|
||||||
- ./Test:/root/bds_core
|
|
139
index.js
139
index.js
@ -1,113 +1,48 @@
|
|||||||
/* eslint-disable no-irregular-whitespace */
|
/* eslint-disable no-irregular-whitespace */
|
||||||
const path = require("path")
|
// process.env.ShowLoadTime = true;
|
||||||
const fs = require("fs");
|
// Load Root JSON
|
||||||
const { randomUUID } = require("crypto");
|
const BdsManegerCoreJSONs = {
|
||||||
const BdsSettings = require("./lib/BdsSettings");
|
Package: require("./package.json"),
|
||||||
|
Extra: require("./BdsManegerInfo.json")
|
||||||
|
};
|
||||||
|
|
||||||
// Bds Maneger Core Package JSON File
|
// Bds Maneger Core Version
|
||||||
module.exports.package_path = path.resolve(__dirname, "package.json");
|
module.exports.version = BdsManegerCoreJSONs.Package.version;
|
||||||
module.exports.package_json = require("./package.json");
|
module.exports.ExtraJSON = BdsManegerCoreJSONs;
|
||||||
module.exports.extra_json = require("./BdsManegerInfo.json");
|
|
||||||
module.exports.BdsCoreVersion = module.exports.package_json.version;
|
|
||||||
|
|
||||||
// Inport and Export Arch
|
if (process.env.ShowLoadTime) console.time("Bds Maneger Core: Settings");
|
||||||
const { arch } = require("./lib/BdsSystemInfo");
|
module.exports.BdsSettings = require("./src/lib/BdsSettings");
|
||||||
module.exports.arch = arch
|
if (process.env.ShowLoadTime) console.timeEnd("Bds Maneger Core: Settings");
|
||||||
|
|
||||||
// Core Settings
|
if (process.env.ShowLoadTime) console.time("Bds Maneger Core: System Info");
|
||||||
module.exports.getBdsConfig = BdsSettings.GetJsonConfig;
|
module.exports.BdsSystemInfo = require("./src/lib/BdsSystemInfo");
|
||||||
module.exports.change_platform = BdsSettings.UpdatePlatform;
|
if (process.env.ShowLoadTime) console.timeEnd("Bds Maneger Core: System Info");
|
||||||
module.exports.platform_update = BdsSettings.UpdatePlatform;
|
|
||||||
module.exports.telegram_token_save = BdsSettings.UpdateTelegramToken;
|
|
||||||
|
|
||||||
// Platforms Checkers
|
if (process.env.ShowLoadTime) console.time("Bds Maneger Core: Network");
|
||||||
const { CheckSystemAsync, GetKernel } = require("./lib/BdsSystemInfo");
|
module.exports.BdsNetwork = require("./src/BdsNetwork")
|
||||||
module.exports.CheckSystem = CheckSystemAsync;
|
if (process.env.ShowLoadTime) console.timeEnd("Bds Maneger Core: Network");
|
||||||
module.exports.GetKernel = GetKernel;
|
|
||||||
|
|
||||||
// Bds Maneger Core Network
|
if (process.env.ShowLoadTime) console.time("Bds Maneger Core: Backups");
|
||||||
const BdsNetwork = require("./src/BdsNetwork")
|
module.exports.BdsBackup = require("./src/BdsBackup");
|
||||||
module.exports.internal_ip = BdsNetwork.LocalInterfaces;
|
if (process.env.ShowLoadTime) console.timeEnd("Bds Maneger Core: Backups");
|
||||||
module.exports.external_ip = BdsNetwork.GetExternalPublicAddress;
|
|
||||||
|
|
||||||
// Bds Maneger Core API
|
if (process.env.ShowLoadTime) console.time("Bds Maneger Core: Server Settings");
|
||||||
const BdsManegerAPI = require("./src/api");
|
module.exports.BdsServerSettings = require("./src/ServerSettings");
|
||||||
module.exports.api = BdsManegerAPI;
|
if (process.env.ShowLoadTime) console.timeEnd("Bds Maneger Core: Server Settings");
|
||||||
module.exports.BdsManegerAPI = BdsManegerAPI;
|
|
||||||
|
|
||||||
// Bds Maneger Core API token Register
|
if (process.env.ShowLoadTime) console.time("Bds Maneger Core: Download Server");
|
||||||
const path_tokens = path.join(BdsSettings.bds_dir, "bds_tokens.json");
|
module.exports.BdsDownload = require("./src/BdsServersDownload");
|
||||||
function token_register(Admin_Scoper = ["web_admin", "admin"]) {
|
if (process.env.ShowLoadTime) console.timeEnd("Bds Maneger Core: Download Server");
|
||||||
Admin_Scoper = Array.from(Admin_Scoper).filter(scoper => /admin/.test(scoper));
|
|
||||||
let tokens = [];
|
|
||||||
if (fs.existsSync(path_tokens)) tokens = JSON.parse(fs.readFileSync(path_tokens, "utf8"));
|
|
||||||
// Get UUID
|
|
||||||
const getBdsUUId = randomUUID().split("-");
|
|
||||||
const bdsuid = "bds_" + (getBdsUUId[0]+getBdsUUId[2].slice(0, 15));
|
|
||||||
// Save BdsUUID
|
|
||||||
tokens.push({
|
|
||||||
token: bdsuid,
|
|
||||||
date: new Date(),
|
|
||||||
scopers: Admin_Scoper
|
|
||||||
});
|
|
||||||
fs.writeFileSync(path_tokens, JSON.stringify(tokens, null, 4), "utf8");
|
|
||||||
return bdsuid;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Bds Maneger Core API Delet token
|
if (process.env.ShowLoadTime) console.time("Bds Maneger Core: Check And Kill");
|
||||||
function delete_token(Token = "") {
|
module.exports.BdsCkeckKill = require("./src/CheckKill");
|
||||||
if (!Token) return false;
|
if (process.env.ShowLoadTime) console.timeEnd("Bds Maneger Core: Check And Kill");
|
||||||
if (typeof Token !== "string") return false;
|
|
||||||
let tokens = [];
|
|
||||||
if (fs.existsSync(path_tokens)) tokens = JSON.parse(fs.readFileSync(path_tokens, "utf8"));
|
|
||||||
if (tokens.filter(token => token.token === Token).length > 0) {
|
|
||||||
fs.writeFileSync(path_tokens, JSON.stringify(tokens, null, 4), "utf8");
|
|
||||||
return true;
|
|
||||||
} else return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check Exists Tokens Files
|
if (process.env.ShowLoadTime) console.time("Bds Maneger Core: API");
|
||||||
if (!(fs.existsSync(path_tokens))) token_register();
|
module.exports.BdsManegerAPI = require("./src/api");
|
||||||
|
if (process.env.ShowLoadTime) console.timeEnd("Bds Maneger Core: API");
|
||||||
|
|
||||||
// Server Settings
|
if (process.env.ShowLoadTime) console.time("Bds Maneger Core: Server Maneger");
|
||||||
module.exports.token_register = token_register;
|
module.exports.BdsManegerServer = require("./src/BdsManegerServer");
|
||||||
module.exports.bds_maneger_token_register = token_register;
|
if (process.env.ShowLoadTime) console.timeEnd("Bds Maneger Core: Server Maneger");
|
||||||
module.exports.delete_token = delete_token;
|
if (process.env.ShowLoadTime) console.log("Bds Maneger Core: Complete");
|
||||||
module.exports.bds_maneger_delete_token = delete_token;
|
|
||||||
|
|
||||||
// Bds Maneger Settings
|
|
||||||
module.exports.BdsSettigs = require("./lib/BdsSettings");
|
|
||||||
|
|
||||||
// Bds Maneger Core Backups
|
|
||||||
const { World_BAckup } = require("./src/BdsBackup");
|
|
||||||
module.exports.backup = World_BAckup;
|
|
||||||
module.exports.core_backup = World_BAckup;
|
|
||||||
|
|
||||||
// Server Settings
|
|
||||||
const { config, get_config } = require("./src/ServerSettings");
|
|
||||||
module.exports.set_config = config;
|
|
||||||
module.exports.update_config = config;
|
|
||||||
module.exports.get_config = get_config;
|
|
||||||
module.exports.server_config = get_config;
|
|
||||||
module.exports.get_server_config = get_config;
|
|
||||||
|
|
||||||
// Dowloand Server
|
|
||||||
const download = require("./src/BdsServersDownload");
|
|
||||||
module.exports.download = download;
|
|
||||||
module.exports.download_server = download;
|
|
||||||
|
|
||||||
// Bds Maneger Core Server
|
|
||||||
const { start, stop, BdsCommand } = require("./src/BdsManegerServer")
|
|
||||||
module.exports.command = BdsCommand;
|
|
||||||
module.exports.server_command = BdsCommand;
|
|
||||||
module.exports.start = start;
|
|
||||||
module.exports.stop = stop;
|
|
||||||
|
|
||||||
// Process Manager Kill and Detect Server
|
|
||||||
const { Kill, Detect } = require("./src/CheckKill")
|
|
||||||
module.exports.detect = Detect;
|
|
||||||
module.exports.bds_detect = Detect;
|
|
||||||
module.exports.detect_server = Detect;
|
|
||||||
module.exports.kill = Kill;
|
|
||||||
|
|
||||||
setInterval(() => {} , 1000);
|
|
@ -1,293 +0,0 @@
|
|||||||
const { join, resolve, basename } = require("path");
|
|
||||||
const { existsSync, writeFileSync, mkdirSync, readFileSync } = require("fs");
|
|
||||||
const { homedir } = require("os");
|
|
||||||
const yaml = require("js-yaml");
|
|
||||||
const deepmerge = require("deepmerge");
|
|
||||||
|
|
||||||
// PATHs
|
|
||||||
const home = homedir();
|
|
||||||
const bds_dir = join(home, "bds_core");
|
|
||||||
if (!(existsSync(bds_dir))) mkdirSync(bds_dir, {recursive: true})
|
|
||||||
|
|
||||||
|
|
||||||
// Config Base to Bds Maneger Core and others Projects
|
|
||||||
var Config = {
|
|
||||||
paths: {
|
|
||||||
servers: join(bds_dir, "Servers"),
|
|
||||||
backups: join(bds_dir, "Backups"),
|
|
||||||
log: join(bds_dir, "Logs"),
|
|
||||||
player: join(bds_dir, "Players.json")
|
|
||||||
},
|
|
||||||
bds: {
|
|
||||||
enable_tmp_host: false
|
|
||||||
},
|
|
||||||
server: {
|
|
||||||
platform: "bedrock",
|
|
||||||
BackupCron: [
|
|
||||||
{
|
|
||||||
enabled: false,
|
|
||||||
cron: "0 1 * * */3",
|
|
||||||
Azure: false,
|
|
||||||
Oracle: false,
|
|
||||||
Google: false,
|
|
||||||
Driver: false
|
|
||||||
}
|
|
||||||
],
|
|
||||||
versions: {
|
|
||||||
bedrock: null,
|
|
||||||
java: null,
|
|
||||||
pocketmine: null,
|
|
||||||
spigot: null,
|
|
||||||
dragonfly: null
|
|
||||||
},
|
|
||||||
Settings: {
|
|
||||||
java: {
|
|
||||||
ram_mb: 1024
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
cloud: {
|
|
||||||
Azure: {
|
|
||||||
Account: null,
|
|
||||||
AccountKey: null,
|
|
||||||
Container: null
|
|
||||||
},
|
|
||||||
Oracle: {
|
|
||||||
Bucket: null
|
|
||||||
},
|
|
||||||
Google: {},
|
|
||||||
Driver: {
|
|
||||||
RootID: null
|
|
||||||
}
|
|
||||||
},
|
|
||||||
ban: [
|
|
||||||
{
|
|
||||||
username: "Steve",
|
|
||||||
bedrock: true,
|
|
||||||
java: true,
|
|
||||||
pocketmine: true,
|
|
||||||
jsprismarine: true,
|
|
||||||
spigot: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
username: "Alex",
|
|
||||||
bedrock: true,
|
|
||||||
java: true,
|
|
||||||
pocketmine: true,
|
|
||||||
jsprismarine: true,
|
|
||||||
spigot: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
username: "steve",
|
|
||||||
bedrock: true,
|
|
||||||
java: true,
|
|
||||||
pocketmine: true,
|
|
||||||
jsprismarine: true,
|
|
||||||
spigot: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
username: "alex",
|
|
||||||
bedrock: true,
|
|
||||||
java: true,
|
|
||||||
pocketmine: true,
|
|
||||||
jsprismarine: true,
|
|
||||||
spigot: true,
|
|
||||||
}
|
|
||||||
],
|
|
||||||
telegram: {
|
|
||||||
admins: ["all_users"],
|
|
||||||
ban: ["Steve_mine_mine"],
|
|
||||||
token: null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Config
|
|
||||||
const ConfigPath = join(bds_dir, "BdsConfig.yaml")
|
|
||||||
|
|
||||||
const SaveConfig = () => writeFileSync(ConfigPath, yaml.dump(Config));
|
|
||||||
process.on("exit", () => SaveConfig());
|
|
||||||
|
|
||||||
if (existsSync(ConfigPath)) {
|
|
||||||
Config.ban = [];
|
|
||||||
Config.server.BackupCron = [];
|
|
||||||
Config.telegram.admins = [];
|
|
||||||
Config.telegram.ban = [];
|
|
||||||
Config = deepmerge(Config, yaml.load(readFileSync(ConfigPath, "utf8")));
|
|
||||||
} else writeFileSync(ConfigPath, yaml.dump(Config))
|
|
||||||
|
|
||||||
// Paths
|
|
||||||
if (!(existsSync(Config.paths["backups"]))) mkdirSync(Config.paths["backups"], {recursive: true})
|
|
||||||
if (!(existsSync(Config.paths["log"]))) mkdirSync(Config.paths["log"], {recursive: true})
|
|
||||||
if (!(existsSync(Config.paths["servers"]))) mkdirSync(Config.paths["servers"], {recursive: true})
|
|
||||||
|
|
||||||
// Server Paths
|
|
||||||
const ServersPaths = {
|
|
||||||
bedrock: join(Config.paths.servers, "Bedrock"),
|
|
||||||
java: join(Config.paths.servers, "Java"),
|
|
||||||
pocketmine: join(Config.paths.servers, "Pocketmine-MP"),
|
|
||||||
dragonfly: join(Config.paths.servers, "Dragonfly_go"),
|
|
||||||
spigot: join(Config.paths.servers, "Spigot")
|
|
||||||
}
|
|
||||||
|
|
||||||
Object.getOwnPropertyNames(ServersPaths).map(Servers => ServersPaths[Servers]).forEach(Servers => {
|
|
||||||
if (!(existsSync(Servers))) {
|
|
||||||
console.log(`Creating the ${basename(Servers)} Folder`);
|
|
||||||
mkdirSync(Servers, {recursive: true})
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// get the path from the settings and return by function
|
|
||||||
function GetPaths(path = null){
|
|
||||||
if (!(path)) throw new Error("Set path to get");
|
|
||||||
if (!(path === "all" || Config.paths[path])) throw new Error("Put a valid path: " + Object.getOwnPropertyNames(Config.paths).join(", "));
|
|
||||||
if (path === "all") return Config.paths
|
|
||||||
return Config.paths[path]
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the server paths if you don't send a throw
|
|
||||||
function GetServerPaths(path = null){
|
|
||||||
if (!(path)) throw new Error("Set path to get");
|
|
||||||
if (!(ServersPaths[path])) throw new Error("Put a valid path: " + Object.getOwnPropertyNames(ServersPaths).join(", "));
|
|
||||||
if (path === "all") return ServersPaths
|
|
||||||
return ServersPaths[path]
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update the settings and save at the same time so as not to lose any information from the Bds Maneger settings
|
|
||||||
function UpdateServerVersion(version = null, platform = Config.server.platform){
|
|
||||||
if (Config.server.versions[platform] || Config.server.versions[platform] === null) {
|
|
||||||
Config.server.versions[platform] = version;
|
|
||||||
SaveConfig()
|
|
||||||
return Config.server.versions[platform]
|
|
||||||
} else throw new Error("Platform invalid")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update the entire Bds Manager Core platform
|
|
||||||
function UpdatePlatform(platform = "null"){
|
|
||||||
platform = platform.toLocaleLowerCase();
|
|
||||||
if (/bedrock/.test(platform)) {
|
|
||||||
Config.server.platform = "bedrock";
|
|
||||||
} else if (/java/.test(platform)) {
|
|
||||||
Config.server.platform = "java";
|
|
||||||
} else if (/pocketmine/.test(platform)) {
|
|
||||||
Config.server.platform = "pocketmine";
|
|
||||||
} else if (/spigot/.test(platform)) {
|
|
||||||
Config.server.platform = "spigot";
|
|
||||||
} else if (/dragonfly/.test(platform)) {
|
|
||||||
Config.server.platform = "dragonfly";
|
|
||||||
} else throw new Error("platform no exists");
|
|
||||||
SaveConfig();
|
|
||||||
return platform
|
|
||||||
}
|
|
||||||
|
|
||||||
// Telegram
|
|
||||||
function UpdateTelegramToken(token = null){
|
|
||||||
if (!(token)) throw new Error("Telegram Token invalid")
|
|
||||||
Config.telegram.token = token
|
|
||||||
SaveConfig()
|
|
||||||
return token
|
|
||||||
}
|
|
||||||
|
|
||||||
const GetJsonConfig = () => Config;
|
|
||||||
|
|
||||||
const GetCronBackup = () => Config.server.BackupCron;
|
|
||||||
const GetPlatform = () => Config.server.platform;
|
|
||||||
|
|
||||||
const GetServerBan = () => Config.ban;
|
|
||||||
const GetServerVersion = () => Config.server.versions;
|
|
||||||
const GetServerSettings = (platform = Config.server.platform) => Config.server.Settings[platform];
|
|
||||||
|
|
||||||
const GetTelegramToken = () => Config.telegram.token;
|
|
||||||
const GetTelegramAdmins = () => Config.telegram.admins;
|
|
||||||
|
|
||||||
// Get a temporary host to connect to the server.
|
|
||||||
const GetTempHost = () => Config.bds.enable_tmp_host
|
|
||||||
|
|
||||||
// Enable and/or disable pick up temporary host.
|
|
||||||
function UpdateTempHost(enable = false){
|
|
||||||
// Check Boolean
|
|
||||||
if (typeof enable !== "boolean") {console.log("Use Boolean, default false"); enable = false;}
|
|
||||||
|
|
||||||
// Save
|
|
||||||
Config.bds.enable_tmp_host = enable
|
|
||||||
SaveConfig();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the server settings
|
|
||||||
function GetCloudConfig(cloud = null){
|
|
||||||
if (!(cloud) || !(Config.cloud[cloud])) throw new Error("Cloud no exists");
|
|
||||||
return Config.cloud[cloud]
|
|
||||||
}
|
|
||||||
|
|
||||||
// Settings Cloud
|
|
||||||
// Azure
|
|
||||||
function Azure_Settings(account = null, key = null, container = null){
|
|
||||||
if (!(account)) throw new Error("Set Azure Blob Account")
|
|
||||||
if (!(key)) throw new Error("Set Azure Blob Key")
|
|
||||||
if (!(container)) throw new Error("Set Azure Container")
|
|
||||||
Config.cloud.Azure.Account = account
|
|
||||||
Config.cloud.Azure.AccountKey = key
|
|
||||||
Config.cloud.Azure.Container = container
|
|
||||||
SaveConfig()
|
|
||||||
return {
|
|
||||||
Account: Config.cloud.Azure.Account,
|
|
||||||
Key: Config.cloud.Azure.AccountKey,
|
|
||||||
Container: Config.cloud.Azure.Container
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Oracle
|
|
||||||
function Oracle_Settings(bucket = null){
|
|
||||||
if (!(bucket)) throw new Error("Set Oracle Bucket name")
|
|
||||||
Config.cloud.Oracle.Bucket = bucket
|
|
||||||
return {
|
|
||||||
Bucket: bucket
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Google Drive
|
|
||||||
function Google_Driver_Settings(rootid = null){
|
|
||||||
if (!(rootid)) {rootid = null; console.log("No Backup folder id added for Google Driver");}
|
|
||||||
Config.cloud.Driver.RootID = rootid
|
|
||||||
SaveConfig()
|
|
||||||
return {
|
|
||||||
RootID: rootid
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create Player JSON
|
|
||||||
if (!(existsSync(GetPaths("player")))) {
|
|
||||||
const PlayerBase = {}
|
|
||||||
for (let ServerPlat of Object.getOwnPropertyNames(Config.server.versions)) PlayerBase[ServerPlat] = [];
|
|
||||||
writeFileSync(GetPaths("player"), JSON.stringify(PlayerBase, null, 2));
|
|
||||||
} else {
|
|
||||||
const PlayerBase = JSON.parse(readFileSync(GetPaths("player"), "utf8"));
|
|
||||||
for (let ServerPlat of Object.getOwnPropertyNames(Config.server.versions)) if (!(PlayerBase[ServerPlat])) PlayerBase[ServerPlat] = [];
|
|
||||||
writeFileSync(GetPaths("player"), JSON.stringify(PlayerBase, null, 2));
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
bds_dir: bds_dir,
|
|
||||||
ServersPaths: ServersPaths,
|
|
||||||
GetJsonConfig,
|
|
||||||
GetPaths,
|
|
||||||
GetServerPaths,
|
|
||||||
GetServerSettings,
|
|
||||||
UpdateServerVersion,
|
|
||||||
GetServerVersion,
|
|
||||||
GetServerBan,
|
|
||||||
GetCronBackup,
|
|
||||||
UpdatePlatform,
|
|
||||||
GetPlatform,
|
|
||||||
UpdateTelegramToken,
|
|
||||||
GetTelegramToken,
|
|
||||||
GetTelegramAdmins,
|
|
||||||
GetTempHost,
|
|
||||||
UpdateTempHost,
|
|
||||||
GetCloudConfig,
|
|
||||||
CloudConfig: {
|
|
||||||
Azure: Azure_Settings,
|
|
||||||
Oracle: Oracle_Settings,
|
|
||||||
Driver: Google_Driver_Settings
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,125 +0,0 @@
|
|||||||
const { release } = require("os");
|
|
||||||
const { readdirSync } = require("fs");
|
|
||||||
const { execSync } = require("child_process");
|
|
||||||
const commadExist = require("./commandExist");
|
|
||||||
const Request = require("./Requests");
|
|
||||||
const bds = require("../index");
|
|
||||||
const { PlatformVersionsV2 } = require("../src/BdsServersDownload");
|
|
||||||
|
|
||||||
async function CheckSystemAsync() {
|
|
||||||
const
|
|
||||||
PHPBin = await Request.JSON("https://raw.githubusercontent.com/The-Bds-Maneger/Php_Static_Binary/main/binarys.json"),
|
|
||||||
Servers = {
|
|
||||||
bedrock: await PlatformVersionsV2("bedrock"),
|
|
||||||
spigot: await PlatformVersionsV2("spigot"),
|
|
||||||
dragonfly: await PlatformVersionsV2("dragonfly"),
|
|
||||||
}
|
|
||||||
|
|
||||||
let system, require_qemu = false;
|
|
||||||
const valid_platform = {
|
|
||||||
bedrock: true,
|
|
||||||
pocketmine: true,
|
|
||||||
java: commadExist("java"),
|
|
||||||
dragonfly: true
|
|
||||||
};
|
|
||||||
|
|
||||||
// check php bin
|
|
||||||
if ((PHPBin[process.platform] || {})[arch]) valid_platform["pocketmine"] = true;
|
|
||||||
else valid_platform["pocketmine"] = false;
|
|
||||||
|
|
||||||
// Check for Dragonfly
|
|
||||||
if (!(Servers.dragonfly.versions[Servers.dragonfly.latest][process.platform][bds.arch])) valid_platform["dragonfly"] = false;
|
|
||||||
|
|
||||||
// SoSystem X
|
|
||||||
if (process.platform == "win32") {
|
|
||||||
system = "Windows";
|
|
||||||
} else if (process.platform == "linux") {
|
|
||||||
system = "Linux";
|
|
||||||
|
|
||||||
// Bedrock Check
|
|
||||||
if (Servers.bedrock.versions[Servers.bedrock.latest][process.platform]) {
|
|
||||||
if (Servers.bedrock.versions[Servers.bedrock.latest][process.platform][arch]) 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (process.platform == "darwin") {
|
|
||||||
system = "MacOS";
|
|
||||||
} else if (process.platform === "android") {
|
|
||||||
system = "Android";
|
|
||||||
if (valid_platform["bedrock"]) valid_platform["bedrock"] = false;
|
|
||||||
} else {
|
|
||||||
throw new Error(`The Bds Maneger Core does not support ${process.platform} systems, as no tests have been done.`);
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
system: system,
|
|
||||||
require_qemu: require_qemu,
|
|
||||||
valid_platform: valid_platform,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = CheckSystemAsync;
|
|
||||||
module.exports.CheckSystemAsync = 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());
|
|
||||||
if (kernelVersion <= 6.1) return "Windows 7";
|
|
||||||
else if (kernelVersion <= 6.2) return "Windows 8";
|
|
||||||
else if (kernelVersion <= 6.3) return "Windows 8.1";
|
|
||||||
else if (kernelVersion <= 10.0) return "Windows 10 or Windows 11";
|
|
||||||
else return "Other Windows";
|
|
||||||
} else if (process.platform === "android") return `Android: ${release()}, CPU Core ${readdirSync("/sys/devices/system/cpu/").filter(data => /cpu[0-9]/.test(data)).length}`;
|
|
||||||
else if (commadExist("uname")) {
|
|
||||||
const str = execSync("uname -rv").toString("ascii");
|
|
||||||
// Amazon web services
|
|
||||||
if (/aws/.test(str)) {
|
|
||||||
if (/arm64|aarch64/.test(process.arch)) return "Amazon AWS Cloud arm64: AWS Graviton Serie";
|
|
||||||
else return `Amazon AWS Cloud ${process.arch}: ${require("os").cpus()[0].model}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Windows subsystem for Linux
|
|
||||||
else if (/WSL2|microsft/.test(str)) return "Microsoft WSL";
|
|
||||||
|
|
||||||
// Azure Virtual Machinime (VM)
|
|
||||||
else if (/[aA]zure/.test(str)) return "Microsoft Azure";
|
|
||||||
|
|
||||||
// Google Cloud Virtual Machinime (VM)
|
|
||||||
else if (/[gG]cp/.test(str)) return "Google Cloud Platform";
|
|
||||||
|
|
||||||
// Oracle cloud Virtual Machinime (VM)
|
|
||||||
else if (/[oO]racle/.test(str)) return "Oracle Cloud infrastructure";
|
|
||||||
|
|
||||||
// Darwin
|
|
||||||
else if (/[dD]arwin/.test(str)) return "Apple MacOS";
|
|
||||||
|
|
||||||
// Others Kernels
|
|
||||||
else return str.replace(/\n|\t|\r/gi, "");
|
|
||||||
} else return "Not identified";
|
|
||||||
}
|
|
||||||
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;
|
|
@ -1,45 +0,0 @@
|
|||||||
const { resolve, join } = require("path");
|
|
||||||
const { existsSync, readFileSync, mkdirSync } = require("fs");
|
|
||||||
|
|
||||||
function getAppDate(){
|
|
||||||
if (process.platform === "win32") return resolve(process.env.USERPROFILE, "AppData", "Roaming");
|
|
||||||
else if (process.platform === "darwin") return resolve(process.env.HOME, "Library", "Application Support");
|
|
||||||
else if (process.platform === "linux" || process.platform === "android") return resolve(process.env.HOME, ".local", "share");
|
|
||||||
}
|
|
||||||
|
|
||||||
var LinuxXDGJson = {};
|
|
||||||
if (process.platform === "linux") {
|
|
||||||
var XDG_File = join(process.env.HOME, ".config", "user-dirs.dirs");
|
|
||||||
if (existsSync(XDG_File)){
|
|
||||||
const lines = readFileSync(XDG_File, "utf8").replace(/\$([A-Za-z\-_]+)|\$\{([^{^}]+)\}/g, process.env.HOME).split(/\n/g);
|
|
||||||
for(let line of lines){
|
|
||||||
if (!(line.startsWith("#")||line === "")) {
|
|
||||||
line = line.split("=");
|
|
||||||
if (line.length === 2) LinuxXDGJson[line[0]] = JSON.parse(line[1]); else console.log(line);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function getDesktopFolder(){
|
|
||||||
if (process.platform === "win32") return resolve(process.env.USERPROFILE, "Desktop");
|
|
||||||
else if (process.platform === "darwin") return resolve(process.env.HOME, "Desktop");
|
|
||||||
else if (process.platform === "android") return resolve(process.env.TMPDIR);
|
|
||||||
else if (process.platform === "linux") {
|
|
||||||
var desktop;
|
|
||||||
if (LinuxXDGJson["XDG_DESKTOP_DIR"]) desktop = LinuxXDGJson["XDG_DESKTOP_DIR"];
|
|
||||||
// Check Desktop string
|
|
||||||
if (desktop === undefined) {
|
|
||||||
console.log("Using a temporary Desktop directory");
|
|
||||||
desktop = resolve((process.env.TMPDIR||"/tmp"), "desktop", )
|
|
||||||
if (!(existsSync(desktop))) mkdirSync(desktop)
|
|
||||||
}
|
|
||||||
return desktop
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
getConfigHome: getAppDate,
|
|
||||||
getAppDate: getAppDate,
|
|
||||||
getDesktopFolder: getDesktopFolder
|
|
||||||
}
|
|
@ -1,27 +0,0 @@
|
|||||||
if (typeof fetch === "undefined") {
|
|
||||||
global.fetch = (...args) => import("node-fetch").then(mod => mod.default(...args));
|
|
||||||
import("node-fetch").then(mod => global.fetch = mod.default);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Request Json
|
|
||||||
const ReqJson = async (url = "", options) => await (await fetch(url, options)).json()
|
|
||||||
|
|
||||||
// Request Text
|
|
||||||
const ReqText = async (url = "", options) => `${await (await fetch(url, options)).text()}`
|
|
||||||
|
|
||||||
const ReqBuffer = async (url = "", options) => Buffer.from(await (await fetch(url, options)).arrayBuffer())
|
|
||||||
|
|
||||||
// Export Bds Request
|
|
||||||
module.exports = {
|
|
||||||
// JSON
|
|
||||||
JSON: ReqJson,
|
|
||||||
json: ReqJson,
|
|
||||||
|
|
||||||
// Raw Text
|
|
||||||
TEXT: ReqText,
|
|
||||||
text: ReqText,
|
|
||||||
|
|
||||||
// Buffer
|
|
||||||
BUFFER: ReqBuffer,
|
|
||||||
buffer: ReqBuffer
|
|
||||||
}
|
|
@ -1,29 +0,0 @@
|
|||||||
const { execSync } = require("child_process");
|
|
||||||
const { readdirSync, existsSync } = require("fs");
|
|
||||||
|
|
||||||
function commdExist(command){
|
|
||||||
if (process.platform === "linux" || process.platform === "darwin" || process.platform === "android") {try {execSync(`command -v ${command}`);return true} catch (error) {return false}}
|
|
||||||
else if (process.platform === "win32") {try {execSync(`where ${command} > nul 2> nul`);return true} catch (error) {return false}}
|
|
||||||
else {
|
|
||||||
var PATHs;
|
|
||||||
const bin = []
|
|
||||||
if (process.platform === "win32") PATHs = process.env.PATH.split(/;/g);else PATHs = process.env.PATH.split(/:/g);
|
|
||||||
|
|
||||||
for (let path of PATHs)
|
|
||||||
if (existsSync(path))
|
|
||||||
for (let binS of readdirSync(path)) bin.push(binS);
|
|
||||||
for (let index of bin) {
|
|
||||||
if (process.platform === "linux") {if (index === command) return true}
|
|
||||||
else if (process.platform === "win32") {
|
|
||||||
if (!command.includes(".exe", ".cmd", ".bat", ".EXE", ".CMD", ".BAT")) {
|
|
||||||
for (let test of [".exe", ".cmd", ".bat", ".EXE", ".CMD", ".BAT"])
|
|
||||||
if (index === `${command}${test}`) return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = commdExist
|
|
||||||
module.exports.sync = commdExist
|
|
@ -1,36 +0,0 @@
|
|||||||
const { execSync, execFileSync } = require("child_process")
|
|
||||||
const commandExists = require("./commandExist").sync
|
|
||||||
const { existsSync } = require("fs");
|
|
||||||
const { resolve, join } = require("path")
|
|
||||||
|
|
||||||
if (!(commandExists("git"))) throw new Error("Install git")
|
|
||||||
|
|
||||||
//-----------------------------------------------------------
|
|
||||||
function GitClone(url, path = resolve(process.cwd(), Math.random().toString().replace(/[01]\./, "GitClone")), depth = 1) {
|
|
||||||
// Check exist dir
|
|
||||||
if (existsSync(join(path, ".git"))) return GitPull(path)
|
|
||||||
else {
|
|
||||||
// const command = `git clone "${url}" ${depth} ${resolve(path)}`
|
|
||||||
if (typeof depth !== "number") depth = 1;
|
|
||||||
console.log("git", ["clone", url, "--depth", depth, path]);
|
|
||||||
execFileSync("git", ["clone", url, "--depth", depth, path]).toString("ascii")
|
|
||||||
return execSync("git log -1 --pretty=format:%H", {cwd: path}).toString("ascii").split("\n").filter(d=>{if(d)return true;return false}).join("");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Pull changes from git repository and return git sha
|
|
||||||
*
|
|
||||||
* @param {string} [path="./"]
|
|
||||||
* @return {string} git sha
|
|
||||||
*/
|
|
||||||
function GitPull(path = "./"){
|
|
||||||
execSync("git pull --recurse-submodules=on-demand", {
|
|
||||||
cwd: resolve(path)
|
|
||||||
})
|
|
||||||
return execSync("git log -1 --pretty=format:%H", {cwd: path}).toString("ascii").split("\n").filter(d=>{if(d)return true;return false}).join("");
|
|
||||||
}
|
|
||||||
module.exports = {
|
|
||||||
GitClone,
|
|
||||||
GitPull
|
|
||||||
}
|
|
@ -1,7 +1,7 @@
|
|||||||
const { join, resolve } = require("path");
|
const { join, resolve } = require("path");
|
||||||
const fs = 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("../src/lib/BdsSettings");
|
||||||
|
|
||||||
function Backup() {
|
function Backup() {
|
||||||
const zip = new AdmZip();
|
const zip = new AdmZip();
|
||||||
|
@ -1,22 +1,19 @@
|
|||||||
const child_process = require("child_process");
|
const child_process = require("child_process");
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
const randomUUID = require("uuid").v4;
|
const { randomUUID } = require("crypto");
|
||||||
const { CronJob } = require("cron");
|
|
||||||
|
|
||||||
// Bds Maneger Inports
|
|
||||||
const commandExists = require("../lib/commandExist");
|
|
||||||
const BdsDetect = require("./CheckKill").Detect;
|
|
||||||
const bds = require("../index");
|
|
||||||
const { GetServerPaths, GetPaths, GetServerSettings, GetPlatform, GetCronBackup } = require("../lib/BdsSettings");
|
|
||||||
const { Backup } = require("./BdsBackup");
|
const { Backup } = require("./BdsBackup");
|
||||||
|
const { CronJob } = require("cron");
|
||||||
|
const BdsSettings = require("../src/lib/BdsSettings");
|
||||||
|
|
||||||
// Set bdsexec functions
|
const ServerSessions = {};
|
||||||
global.BdsExecs = {};
|
module.exports.GetSessions = () => ServerSessions;
|
||||||
|
|
||||||
function start() {
|
module.exports.StartServer = function start() {
|
||||||
|
const commandExists = require("../src/lib/commandExist");
|
||||||
|
const BdsDetect = require("./CheckKill").Detect;
|
||||||
if (BdsDetect()) throw new Error("You already have a server running");
|
if (BdsDetect()) throw new Error("You already have a server running");
|
||||||
const CurrentBdsPlatform = GetPlatform();
|
const CurrentBdsPlatform = BdsSettings.GetPlatform();
|
||||||
const SetupCommands = {
|
const SetupCommands = {
|
||||||
command: String,
|
command: String,
|
||||||
args: [],
|
args: [],
|
||||||
@ -34,17 +31,17 @@ function start() {
|
|||||||
// Windows Platform
|
// Windows Platform
|
||||||
else if (process.platform === "win32") {
|
else if (process.platform === "win32") {
|
||||||
SetupCommands.command = "bedrock_server.exe";
|
SetupCommands.command = "bedrock_server.exe";
|
||||||
SetupCommands.cwd = GetServerPaths("bedrock")
|
SetupCommands.cwd = BdsSettings.GetServerPaths("bedrock")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Linux Platform
|
// Linux Platform
|
||||||
else if (process.platform === "linux"){
|
else if (process.platform === "linux"){
|
||||||
// Set Executable file
|
// Set Executable file
|
||||||
try {child_process.execSync("chmod 777 bedrock_server", {cwd: GetServerPaths("bedrock")});} catch (error) {console.log(error);}
|
try {child_process.execSync("chmod 777 bedrock_server", {cwd: BdsSettings.GetServerPaths("bedrock")});} catch (error) {console.log(error);}
|
||||||
|
|
||||||
// Set Env and Cwd
|
// Set Env and Cwd
|
||||||
SetupCommands.cwd = GetServerPaths("bedrock");
|
SetupCommands.cwd = BdsSettings.GetServerPaths("bedrock");
|
||||||
SetupCommands.env.LD_LIBRARY_PATH = GetServerPaths("bedrock");
|
SetupCommands.env.LD_LIBRARY_PATH = BdsSettings.GetServerPaths("bedrock");
|
||||||
|
|
||||||
// In case the cpu is different from x64, the command will use qemu static to run the server
|
// In case the cpu is different from x64, the command will use qemu static to run the server
|
||||||
if (process.arch !== "x64") {
|
if (process.arch !== "x64") {
|
||||||
@ -57,30 +54,30 @@ function start() {
|
|||||||
|
|
||||||
// Minecraft Java Oficial
|
// Minecraft Java Oficial
|
||||||
else if (CurrentBdsPlatform === "java") {
|
else if (CurrentBdsPlatform === "java") {
|
||||||
const JavaConfig = GetServerSettings("java")
|
const JavaConfig = BdsSettings.GetServerSettings("java")
|
||||||
|
|
||||||
// Checking if java is installed on the device
|
// Checking if java is installed on the device
|
||||||
if (commandExists("java")) {
|
if (commandExists("java")) {
|
||||||
SetupCommands.cwd = GetServerPaths("java");
|
SetupCommands.cwd = BdsSettings.GetServerPaths("java");
|
||||||
SetupCommands.command = "java";
|
SetupCommands.command = "java";
|
||||||
SetupCommands.args.push("-jar", `-Xms${JavaConfig.ram_mb}M`, `-Xmx${JavaConfig.ram_mb}M`, "MinecraftServerJava.jar", "nogui");
|
SetupCommands.args.push("-jar", `-Xms${JavaConfig.ram_mb}M`, `-Xmx${JavaConfig.ram_mb}M`, "MinecraftServerJava.jar", "nogui");
|
||||||
} else {require("open")(bds.package_json.docs_base + "Java-Download#windows"); throw new Error(`Open: ${bds.package_json.docs_base + "Java-Download#windows"}`)}
|
} else throw new Error("Install Java")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Spigot
|
// Spigot
|
||||||
else if (CurrentBdsPlatform === "spigot") {
|
else if (CurrentBdsPlatform === "spigot") {
|
||||||
const JavaConfig = GetServerSettings("java")
|
const JavaConfig = BdsSettings.GetServerSettings("java")
|
||||||
// Checking if java is installed on the device
|
// Checking if java is installed on the device
|
||||||
if (commandExists("java")) {
|
if (commandExists("java")) {
|
||||||
SetupCommands.cwd = GetServerPaths("spigot");
|
SetupCommands.cwd = BdsSettings.GetServerPaths("spigot");
|
||||||
SetupCommands.command = "java";
|
SetupCommands.command = "java";
|
||||||
SetupCommands.args.push("-jar", `-Xms${JavaConfig.ram_mb}M`, `-Xmx${JavaConfig.ram_mb}M`, "spigot.jar", "nogui");
|
SetupCommands.args.push("-jar", `-Xms${JavaConfig.ram_mb}M`, `-Xmx${JavaConfig.ram_mb}M`, "spigot.jar", "nogui");
|
||||||
} else {require("open")(bds.package_json.docs_base + "Java-Download#windows"); throw new Error(`Open: ${bds.package_json.docs_base + "Java-Download#windows"}`)}
|
} else {require("open")(PackageJson.docs_base + "Java-Download#windows"); throw new Error(`Open: ${PackageJson.docs_base + "Java-Download#windows"}`)}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dragonfly
|
// Dragonfly
|
||||||
else if (CurrentBdsPlatform === "dragonfly") {
|
else if (CurrentBdsPlatform === "dragonfly") {
|
||||||
SetupCommands.cwd = GetServerPaths("dragonfly");
|
SetupCommands.cwd = BdsSettings.GetServerPaths("dragonfly");
|
||||||
if (process.platform === "win32") {
|
if (process.platform === "win32") {
|
||||||
SetupCommands.command = "Dragonfly.exe";
|
SetupCommands.command = "Dragonfly.exe";
|
||||||
} else {
|
} else {
|
||||||
@ -92,10 +89,10 @@ function start() {
|
|||||||
// Minecraft Bedrock (Pocketmine-MP)
|
// Minecraft Bedrock (Pocketmine-MP)
|
||||||
else if (CurrentBdsPlatform === "pocketmine") {
|
else if (CurrentBdsPlatform === "pocketmine") {
|
||||||
// Start PocketMine-MP
|
// Start PocketMine-MP
|
||||||
SetupCommands.command = path.join(path.resolve(GetServerPaths("pocketmine"), "bin", "php7", "bin"), "php");
|
SetupCommands.command = path.join(path.resolve(BdsSettings.GetServerPaths("pocketmine"), "bin", "php7", "bin"), "php");
|
||||||
if (process.platform === "win32") SetupCommands.command = path.join(path.resolve(GetServerPaths("pocketmine"), "bin/php"), "php.exe");
|
if (process.platform === "win32") SetupCommands.command = path.join(path.resolve(BdsSettings.GetServerPaths("pocketmine"), "bin/php"), "php.exe");
|
||||||
SetupCommands.args.push("./PocketMine-MP.phar");
|
SetupCommands.args.push("./PocketMine-MP.phar");
|
||||||
SetupCommands.cwd = GetServerPaths("pocketmine");
|
SetupCommands.cwd = BdsSettings.GetServerPaths("pocketmine");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show Error platform
|
// Show Error platform
|
||||||
@ -108,8 +105,8 @@ function start() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Log file
|
// Log file
|
||||||
const LogFile = path.join(GetPaths("log"), `${GetPlatform()}_${new Date().toString().replace(/:|\(|\)/g, "_")}_Bds_log.log`);
|
const LogFile = path.join(BdsSettings.GetPaths("log"), `${BdsSettings.GetPlatform()}_${new Date().toString().replace(/:|\(|\)/g, "_")}_Bds_log.log`);
|
||||||
const LatestLog_Path = path.join(GetPaths("log"), "latest.log");
|
const LatestLog_Path = path.join(BdsSettings.GetPaths("log"), "latest.log");
|
||||||
const LogSaveFunction = data => {
|
const LogSaveFunction = data => {
|
||||||
fs.appendFileSync(LogFile, data);
|
fs.appendFileSync(LogFile, data);
|
||||||
fs.appendFileSync(LatestLog_Path, data);
|
fs.appendFileSync(LatestLog_Path, data);
|
||||||
@ -285,18 +282,18 @@ function start() {
|
|||||||
// Uptime Server
|
// Uptime Server
|
||||||
const OnStop = setInterval(() => returnFuntion.uptime = (new Date().getTime() - returnFuntion.StartTime.getTime()) / 1000, 1000);
|
const OnStop = setInterval(() => returnFuntion.uptime = (new Date().getTime() - returnFuntion.StartTime.getTime()) / 1000, 1000);
|
||||||
ServerExec.on("exit", () => {
|
ServerExec.on("exit", () => {
|
||||||
delete global.BdsExecs[returnFuntion.uuid]
|
delete ServerSessions[returnFuntion.uuid]
|
||||||
clearInterval(OnStop);
|
clearInterval(OnStop);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Return
|
// Return
|
||||||
global.BdsExecs[returnFuntion.uuid] = returnFuntion;
|
ServerSessions[returnFuntion.uuid] = returnFuntion;
|
||||||
module.exports.BdsRun = returnFuntion;
|
module.exports.BdsRun = returnFuntion;
|
||||||
return returnFuntion;
|
return returnFuntion;
|
||||||
}
|
}
|
||||||
|
|
||||||
function Player_Json(data = "aaaaaa\n\n\naa", callback = () => {}){
|
function Player_Json(data = "", callback = () => {}){
|
||||||
const Current_platorm = GetPlatform();
|
const Current_platorm = BdsSettings.GetPlatform();
|
||||||
// Bedrock
|
// Bedrock
|
||||||
if (Current_platorm === "bedrock") {
|
if (Current_platorm === "bedrock") {
|
||||||
// "[INFO] Player connected: Sirherobrine, xuid: 2535413418839840",
|
// "[INFO] Player connected: Sirherobrine, xuid: 2535413418839840",
|
||||||
@ -352,8 +349,8 @@ function Player_Json(data = "aaaaaa\n\n\naa", callback = () => {}){
|
|||||||
}
|
}
|
||||||
|
|
||||||
const UpdateUserJSON = function (New_Object = []){
|
const UpdateUserJSON = function (New_Object = []){
|
||||||
const Player_Json_path = GetPaths("player");
|
const Player_Json_path = BdsSettings.GetPaths("player");
|
||||||
const Current_platorm = GetPlatform();
|
const Current_platorm = BdsSettings.GetPlatform();
|
||||||
let Players_Json = {
|
let Players_Json = {
|
||||||
bedrock: [],
|
bedrock: [],
|
||||||
java: [],
|
java: [],
|
||||||
@ -370,8 +367,8 @@ const UpdateUserJSON = function (New_Object = []){
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Search player in JSON
|
// Search player in JSON
|
||||||
function Player_Search(player = "dontSteve") {
|
module.exports.Player_Search = function Player_Search(player = "dontSteve") {
|
||||||
const Player_Json_path = GetPaths("player"), Current_platorm = GetPlatform();
|
const Player_Json_path = BdsSettings.GetPaths("player"), Current_platorm = BdsSettings.GetPlatform();
|
||||||
const Players_Json = JSON.parse(fs.readFileSync(Player_Json_path, "utf8"))[Current_platorm]
|
const Players_Json = JSON.parse(fs.readFileSync(Player_Json_path, "utf8"))[Current_platorm]
|
||||||
for (let Player of Players_Json) {
|
for (let Player of Players_Json) {
|
||||||
if (Player.Player === player.trim()) return Player;
|
if (Player.Player === player.trim()) return Player;
|
||||||
@ -379,42 +376,19 @@ function Player_Search(player = "dontSteve") {
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
function GetSessions(){
|
module.exports.GetFistSession = function GetFistSession(){
|
||||||
const ArraySessions = Object.getOwnPropertyNames(global.BdsExecs)
|
const ArraySessions = Object.getOwnPropertyNames(ServerSessions)
|
||||||
if (ArraySessions.length === 0) throw "Start Server";
|
if (ArraySessions.length === 0) throw "Start Server";
|
||||||
if (ArraySessions.length >= 2) throw "Select a session manually:" + ArraySessions.join(", ")
|
return ServerSessions[0]
|
||||||
return global.BdsExecs[0]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function BdsCommand(command = "list", SessionID = null) {
|
module.exports.CronBackups = BdsSettings.GetCronBackup().map(Crron => {
|
||||||
if (!(command)) return false;
|
const Cloud_Backup = {
|
||||||
try {
|
Azure: require("./clouds/Azure").Uploadbackups,
|
||||||
var Session = {}
|
Driver: require("./clouds/GoogleDriver").Uploadbackups,
|
||||||
if (!(SessionID)) Session = GetSessions(); else Session = global.BdsExecs[SessionID]
|
Oracle: require("./clouds/OracleCI").Uploadbackups,
|
||||||
Session.command(command);
|
|
||||||
return true
|
|
||||||
} catch (error) {
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
}
|
//
|
||||||
|
|
||||||
function stop(SessionID = null) {
|
|
||||||
try {
|
|
||||||
var Session = {}
|
|
||||||
if (!(SessionID)) Session = GetSessions(); else Session = global.BdsExecs[SessionID]
|
|
||||||
Session.stop()
|
|
||||||
return true
|
|
||||||
} catch (error) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const Cloud_Backup = {
|
|
||||||
Azure: require("./clouds/Azure").Uploadbackups,
|
|
||||||
Driver: require("./clouds/GoogleDriver").Uploadbackups,
|
|
||||||
Oracle: require("./clouds/OracleCI").Uploadbackups,
|
|
||||||
}
|
|
||||||
const CurrentBackups = GetCronBackup().map(Crron => {
|
|
||||||
return {
|
return {
|
||||||
CronFunction: new CronJob(Crron.cron, async () => {
|
CronFunction: new CronJob(Crron.cron, async () => {
|
||||||
console.log("Starting Server and World Backup");
|
console.log("Starting Server and World Backup");
|
||||||
@ -432,13 +406,4 @@ const CurrentBackups = GetCronBackup().map(Crron => {
|
|||||||
else console.info("Oracle Bucket Backup Disabled");
|
else console.info("Oracle Bucket Backup Disabled");
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
start,
|
|
||||||
BdsCommand,
|
|
||||||
stop,
|
|
||||||
GetSessions,
|
|
||||||
CronBackups: CurrentBackups,
|
|
||||||
Player_Search,
|
|
||||||
}
|
|
@ -1,5 +1,5 @@
|
|||||||
// External User ip
|
// External User ip
|
||||||
const Request = require("../lib/Requests");
|
const Request = require("../src/lib/Requests");
|
||||||
const os = require("os");
|
const os = require("os");
|
||||||
|
|
||||||
function LocalInterfaces() {
|
function LocalInterfaces() {
|
||||||
@ -19,7 +19,7 @@ function LocalInterfaces() {
|
|||||||
netmask: "",
|
netmask: "",
|
||||||
cidr: ""
|
cidr: ""
|
||||||
},
|
},
|
||||||
}
|
};
|
||||||
for (let iface of interfaces[name]) {
|
for (let iface of interfaces[name]) {
|
||||||
if (!Inter.mac && iface.mac) Inter.mac = iface.mac;
|
if (!Inter.mac && iface.mac) Inter.mac = iface.mac;
|
||||||
if (iface.family === "IPv4") {
|
if (iface.family === "IPv4") {
|
||||||
|
@ -3,10 +3,10 @@ const path = require("path");
|
|||||||
const { writeFileSync, existsSync, readFileSync, readdirSync, rmSync } = fs;
|
const { writeFileSync, existsSync, readFileSync, readdirSync, rmSync } = fs;
|
||||||
const { join, resolve } = path;
|
const { join, resolve } = path;
|
||||||
var AdmZip = require("adm-zip");
|
var AdmZip = require("adm-zip");
|
||||||
const { GetServerPaths, GetPlatform } = require("../lib/BdsSettings");
|
const { GetServerPaths, GetPlatform } = require("../src/lib/BdsSettings");
|
||||||
const Extra = require("../BdsManegerInfo.json");
|
const Extra = require("../BdsManegerInfo.json");
|
||||||
const bds = require("../index");
|
const bds = require("../index");
|
||||||
const Request = require("../lib/Requests");
|
const Request = require("../src/lib/Requests");
|
||||||
|
|
||||||
// Get Platform Object Versions
|
// Get Platform Object Versions
|
||||||
async function PlatformVersionsV2(SelectPlatform = "") {
|
async function PlatformVersionsV2(SelectPlatform = "") {
|
||||||
@ -53,7 +53,7 @@ async function php_download() {
|
|||||||
// Check Php Binary
|
// Check Php Binary
|
||||||
let urlPHPBin = PHPBin[process.platform]
|
let urlPHPBin = PHPBin[process.platform]
|
||||||
if (!(urlPHPBin)) throw new Error("unsupported system")
|
if (!(urlPHPBin)) throw new Error("unsupported system")
|
||||||
urlPHPBin = urlPHPBin[bds.arch];
|
urlPHPBin = urlPHPBin[bds.BdsSystemInfo.arch];
|
||||||
if (!(urlPHPBin)) throw new Error("unsupported arch")
|
if (!(urlPHPBin)) throw new Error("unsupported arch")
|
||||||
|
|
||||||
// Remove Old php Binary if it exists
|
// Remove Old php Binary if it exists
|
||||||
@ -85,26 +85,30 @@ async function php_download() {
|
|||||||
// New Download Method
|
// New Download Method
|
||||||
async function BdsDownloadV2(version = "latest") {
|
async function BdsDownloadV2(version = "latest") {
|
||||||
const CurrentPlatform = GetPlatform();
|
const CurrentPlatform = GetPlatform();
|
||||||
const { valid_platform, require_qemu } = await (require("../lib/BdsSystemInfo")).CheckSystemAsync();
|
const { valid_platform, require_qemu } = await (require("../src/lib/BdsSystemInfo")).CheckSystemAsync();
|
||||||
const LocalServersVersions = bds.BdsSettigs.GetServerVersion();
|
const LocalServersVersions = bds.BdsSettings.GetServerVersion();
|
||||||
const { ServersPaths } = bds.BdsSettigs;
|
const { ServersPaths } = bds.BdsSettings;
|
||||||
|
|
||||||
const ReturnObject = {
|
const ReturnObject = {
|
||||||
version,
|
version: version,
|
||||||
platform: CurrentPlatform,
|
platform: CurrentPlatform,
|
||||||
url: "",
|
url: "",
|
||||||
data: new Date(),
|
data: new Date(),
|
||||||
skip: false
|
skip: false
|
||||||
}
|
};
|
||||||
|
|
||||||
// Bedrock
|
// Bedrock
|
||||||
if (CurrentPlatform === "bedrock") {
|
if (CurrentPlatform === "bedrock") {
|
||||||
const BedrockVersions = await PlatformVersionsV2("bedrock");
|
const BedrockVersions = await PlatformVersionsV2("bedrock");
|
||||||
if (typeof version === "boolean" || /true|false|null|undefined|latest/.test(`${version}`.toLocaleLowerCase())) version = BedrockVersions.latest;
|
if (/true|false|null|undefined|latest/.test(`${version}`.toLocaleLowerCase())) {
|
||||||
|
version = BedrockVersions.latest;
|
||||||
|
ReturnObject.version = version;
|
||||||
|
}
|
||||||
if (valid_platform.bedrock) {
|
if (valid_platform.bedrock) {
|
||||||
if (LocalServersVersions.bedrock !== version) {
|
if (LocalServersVersions.bedrock !== version) {
|
||||||
// Add info to ReturnObject
|
// Add info to ReturnObject
|
||||||
if (require_qemu) ReturnObject.url = BedrockVersions.versions[version][process.platform]["x64"]; else ReturnObject.url = BedrockVersions.versions[version][process.platform][bds.arch];
|
if (require_qemu) ReturnObject.url = BedrockVersions.versions[version][process.platform]["x64"];
|
||||||
|
else ReturnObject.url = BedrockVersions.versions[version][process.platform][bds.BdsSystemInfo.arch];
|
||||||
ReturnObject.data = BedrockVersions.versions[version].data ? new Date(BedrockVersions.versions[version].data) : null;
|
ReturnObject.data = BedrockVersions.versions[version].data ? new Date(BedrockVersions.versions[version].data) : null;
|
||||||
|
|
||||||
// Download and Add buffer to AdmZip
|
// Download and Add buffer to AdmZip
|
||||||
@ -115,7 +119,7 @@ async function BdsDownloadV2(version = "latest") {
|
|||||||
proprieties: "",
|
proprieties: "",
|
||||||
whitelist: "",
|
whitelist: "",
|
||||||
permissions: "",
|
permissions: "",
|
||||||
}
|
};
|
||||||
|
|
||||||
// Get Bedrock Config Files
|
// Get Bedrock Config Files
|
||||||
if (fs.existsSync(path.join(ServersPaths.bedrock, "bedrock_server.properties"))) BedrockConfigFiles.proprieties = fs.readFileSync(path.join(ServersPaths.bedrock, "bedrock_server.properties"), "utf8");
|
if (fs.existsSync(path.join(ServersPaths.bedrock, "bedrock_server.properties"))) BedrockConfigFiles.proprieties = fs.readFileSync(path.join(ServersPaths.bedrock, "bedrock_server.properties"), "utf8");
|
||||||
@ -131,7 +135,7 @@ async function BdsDownloadV2(version = "latest") {
|
|||||||
if (BedrockConfigFiles.permissions) fs.writeFileSync(path.join(ServersPaths.bedrock, "permissions.json"), BedrockConfigFiles.permissions, "utf8");
|
if (BedrockConfigFiles.permissions) fs.writeFileSync(path.join(ServersPaths.bedrock, "permissions.json"), BedrockConfigFiles.permissions, "utf8");
|
||||||
|
|
||||||
// Update Server Version
|
// Update Server Version
|
||||||
bds.BdsSettigs.UpdateServerVersion(version, CurrentPlatform);
|
bds.BdsSettings.UpdateServerVersion(version, CurrentPlatform);
|
||||||
} else {
|
} else {
|
||||||
ReturnObject.skip = true;
|
ReturnObject.skip = true;
|
||||||
}
|
}
|
||||||
@ -197,7 +201,7 @@ async function BdsDownloadV2(version = "latest") {
|
|||||||
if (valid_platform.dragonfly) {
|
if (valid_platform.dragonfly) {
|
||||||
if (LocalServersVersions.dragonfly !== version) {
|
if (LocalServersVersions.dragonfly !== version) {
|
||||||
// Add info to ReturnObject
|
// Add info to ReturnObject
|
||||||
ReturnObject.url = DragonflyVersions.versions[version][process.platform][bds.arch]
|
ReturnObject.url = DragonflyVersions.versions[version][process.platform][bds.BdsSystemInfo.arch];
|
||||||
ReturnObject.data = DragonflyVersions.versions[version].data;
|
ReturnObject.data = DragonflyVersions.versions[version].data;
|
||||||
|
|
||||||
// Download
|
// Download
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
const bds = require("../index")
|
const bds = require("../index")
|
||||||
const { CheckBan } = require("./UsersAndtokenChecks");
|
const { CheckBan } = require("./UsersAndtokenChecks");
|
||||||
const { GetPlatform, GetPaths } = require("../lib/BdsSettings");
|
const { GetPlatform, GetPaths } = require("../src/lib/BdsSettings");
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
|
|
||||||
function MytypeKill(player) {
|
function MytypeKill(player) {
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
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 BdsInfo = require("../lib/BdsSystemInfo");
|
const BdsInfo = require("../src/lib/BdsSystemInfo");
|
||||||
const { GetServerPaths, GetPlatform } = require("../lib/BdsSettings");
|
const { GetServerPaths, GetPlatform } = require("../src/lib/BdsSettings");
|
||||||
const TOML = require("@iarna/toml");
|
const TOML = require("@iarna/toml");
|
||||||
|
|
||||||
const ConfigFilePath = {
|
const ConfigFilePath = {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
const { bds_dir, GetServerBan, GetTelegramAdmins, GetPlatform, GetPaths } = require("../lib/BdsSettings");
|
const { bds_dir, GetServerBan, GetTelegramAdmins, GetPlatform, GetPaths } = require("../src/lib/BdsSettings");
|
||||||
const { existsSync, readFileSync } = require("fs")
|
const { existsSync, readFileSync } = require("fs")
|
||||||
const { join } = require("path")
|
const { join } = require("path")
|
||||||
|
|
||||||
|
45
src/api.js
45
src/api.js
@ -1,12 +1,13 @@
|
|||||||
// Node Modules
|
// Node Modules
|
||||||
const os = require("os");
|
const os = require("os");
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
|
const path = require("path");
|
||||||
|
const { randomUUID } = require("crypto")
|
||||||
// Bds Maneger Core
|
// Bds Maneger Core
|
||||||
const BdsManegerCore = require("../index");
|
const BdsManegerCore = require("../index");
|
||||||
const BdsSystemInfo = require("../lib/BdsSystemInfo");
|
const BdsSystemInfo = require("../src/lib/BdsSystemInfo");
|
||||||
const BdsChecks = require("./UsersAndtokenChecks");
|
const BdsChecks = require("./UsersAndtokenChecks");
|
||||||
const BdsSettings = require("../lib/BdsSettings");
|
const BdsSettings = require("../src/lib/BdsSettings");
|
||||||
|
|
||||||
// Init Express
|
// Init Express
|
||||||
const express = require("express");
|
const express = require("express");
|
||||||
@ -429,7 +430,43 @@ function MainAPI(apiConfig = {api_port: 1932}, callback = function (port){consol
|
|||||||
return API(port_rest, callback);
|
return API(port_rest, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Bds Maneger Core API token Register
|
||||||
|
const path_tokens = path.join(BdsSettings.bds_dir, "bds_tokens.json");
|
||||||
|
function token_register(Admin_Scoper = ["web_admin", "admin"]) {
|
||||||
|
Admin_Scoper = Array.from(Admin_Scoper).filter(scoper => /admin/.test(scoper));
|
||||||
|
let tokens = [];
|
||||||
|
if (fs.existsSync(path_tokens)) tokens = JSON.parse(fs.readFileSync(path_tokens, "utf8"));
|
||||||
|
// Get UUID
|
||||||
|
const getBdsUUId = randomUUID().split("-");
|
||||||
|
const bdsuid = "bds_" + (getBdsUUId[0]+getBdsUUId[2].slice(0, 15));
|
||||||
|
// Save BdsUUID
|
||||||
|
tokens.push({
|
||||||
|
token: bdsuid,
|
||||||
|
date: new Date(),
|
||||||
|
scopers: Admin_Scoper
|
||||||
|
});
|
||||||
|
fs.writeFileSync(path_tokens, JSON.stringify(tokens, null, 4), "utf8");
|
||||||
|
return bdsuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bds Maneger Core API Delet token
|
||||||
|
function delete_token(Token = "") {
|
||||||
|
if (!Token) return false;
|
||||||
|
if (typeof Token !== "string") return false;
|
||||||
|
let tokens = [];
|
||||||
|
if (fs.existsSync(path_tokens)) tokens = JSON.parse(fs.readFileSync(path_tokens, "utf8"));
|
||||||
|
if (tokens.filter(token => token.token === Token).length > 0) {
|
||||||
|
fs.writeFileSync(path_tokens, JSON.stringify(tokens, null, 4), "utf8");
|
||||||
|
return true;
|
||||||
|
} else return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check Exists Tokens Files
|
||||||
|
if (!(fs.existsSync(path_tokens))) token_register();
|
||||||
|
|
||||||
module.exports = MainAPI;
|
module.exports = MainAPI;
|
||||||
module.exports.api = API;
|
module.exports.api = API;
|
||||||
module.exports.BdsRoutes = app;
|
module.exports.BdsRoutes = app;
|
||||||
|
module.exports.token_register = token_register;
|
||||||
|
module.exports.delete_token = delete_token;
|
||||||
|
module.exports.TokensFilePath = path_tokens;
|
@ -5,7 +5,7 @@ const express = require("express");
|
|||||||
const { google } = require("googleapis");
|
const { google } = require("googleapis");
|
||||||
|
|
||||||
const ip_andress = require("../../BdsNetwork");
|
const ip_andress = require("../../BdsNetwork");
|
||||||
const { bds_dir } = require("../../../lib/BdsSettings");
|
const { bds_dir } = require("../../../src/lib/BdsSettings");
|
||||||
|
|
||||||
const PathToToken = join(bds_dir, "google_user_token.json");
|
const PathToToken = join(bds_dir, "google_user_token.json");
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
const path = require("path");
|
const path = require("path");
|
||||||
const { BlobServiceClient, StorageSharedKeyCredential } = require("@azure/storage-blob");
|
const { BlobServiceClient, StorageSharedKeyCredential } = require("@azure/storage-blob");
|
||||||
const NewBdsSettings = require("../../lib/BdsSettings");
|
const NewBdsSettings = require("../../src/lib/BdsSettings");
|
||||||
|
|
||||||
// Upload Function
|
// Upload Function
|
||||||
async function Uploadbackups(object = "Backup.zip", fileLocation = "Backup.zip", callback = function (){}) {
|
async function Uploadbackups(object = "Backup.zip", fileLocation = "Backup.zip", callback = function (){}) {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const { google } = require("googleapis");
|
const { google } = require("googleapis");
|
||||||
const { authorize } = require("./Auth/Google");
|
const { authorize } = require("./Auth/Google");
|
||||||
const { GetCloudConfig } = require("../../lib/BdsSettings");
|
const { GetCloudConfig } = require("../../src/lib/BdsSettings");
|
||||||
|
|
||||||
module.exports.Uploadbackups = async function (file_name = "Backup.zip", fileLocation = "Backup.zip", BackupCallback){
|
module.exports.Uploadbackups = async function (file_name = "Backup.zip", fileLocation = "Backup.zip", BackupCallback){
|
||||||
return new Promise(async function (resolve, reject){
|
return new Promise(async function (resolve, reject){
|
||||||
|
@ -2,7 +2,7 @@ const oci_storage = require("oci-objectstorage");
|
|||||||
const oci_common = require("oci-common");
|
const oci_common = require("oci-common");
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const { resolve } = require("path");
|
const { resolve } = require("path");
|
||||||
const { CloudConfig } = require("../../lib/BdsSettings");
|
const { CloudConfig } = require("../../src/lib/BdsSettings");
|
||||||
|
|
||||||
async function Uploadbackups(object = "Backup.zip", fileLocation = resolve(__dirname, "../Backup.zip"), callback = function (data){console.log(data)}){
|
async function Uploadbackups(object = "Backup.zip", fileLocation = resolve(__dirname, "../Backup.zip"), callback = function (data){console.log(data)}){
|
||||||
return new Promise(async function (resolve, reject){
|
return new Promise(async function (resolve, reject){
|
||||||
|
292
src/lib/BdsSettings.js
Normal file
292
src/lib/BdsSettings.js
Normal file
@ -0,0 +1,292 @@
|
|||||||
|
const { join, basename } = require("path");
|
||||||
|
const { existsSync, writeFileSync, mkdirSync, readFileSync } = require("fs");
|
||||||
|
const { homedir } = require("os");
|
||||||
|
const yaml = require("js-yaml");
|
||||||
|
const deepmerge = require("deepmerge");
|
||||||
|
|
||||||
|
// PATHs
|
||||||
|
const home = homedir();
|
||||||
|
const bds_dir = join(home, "bds_core");
|
||||||
|
if (!(existsSync(bds_dir))) mkdirSync(bds_dir, {recursive: true})
|
||||||
|
|
||||||
|
// Config Base to Bds Maneger Core and others Projects
|
||||||
|
var Config = {
|
||||||
|
paths: {
|
||||||
|
servers: join(bds_dir, "Servers"),
|
||||||
|
backups: join(bds_dir, "Backups"),
|
||||||
|
log: join(bds_dir, "Logs"),
|
||||||
|
player: join(bds_dir, "Players.json")
|
||||||
|
},
|
||||||
|
bds: {
|
||||||
|
enable_tmp_host: false
|
||||||
|
},
|
||||||
|
server: {
|
||||||
|
platform: "bedrock",
|
||||||
|
BackupCron: [
|
||||||
|
{
|
||||||
|
enabled: false,
|
||||||
|
cron: "0 1 * * */3",
|
||||||
|
Azure: false,
|
||||||
|
Oracle: false,
|
||||||
|
Google: false,
|
||||||
|
Driver: false
|
||||||
|
}
|
||||||
|
],
|
||||||
|
versions: {
|
||||||
|
bedrock: null,
|
||||||
|
java: null,
|
||||||
|
pocketmine: null,
|
||||||
|
spigot: null,
|
||||||
|
dragonfly: null
|
||||||
|
},
|
||||||
|
Settings: {
|
||||||
|
java: {
|
||||||
|
ram_mb: 1024
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
cloud: {
|
||||||
|
Azure: {
|
||||||
|
Account: null,
|
||||||
|
AccountKey: null,
|
||||||
|
Container: null
|
||||||
|
},
|
||||||
|
Oracle: {
|
||||||
|
Bucket: null
|
||||||
|
},
|
||||||
|
Google: {},
|
||||||
|
Driver: {
|
||||||
|
RootID: null
|
||||||
|
}
|
||||||
|
},
|
||||||
|
ban: [
|
||||||
|
{
|
||||||
|
username: "Steve",
|
||||||
|
bedrock: true,
|
||||||
|
java: true,
|
||||||
|
pocketmine: true,
|
||||||
|
jsprismarine: true,
|
||||||
|
spigot: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
username: "Alex",
|
||||||
|
bedrock: true,
|
||||||
|
java: true,
|
||||||
|
pocketmine: true,
|
||||||
|
jsprismarine: true,
|
||||||
|
spigot: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
username: "steve",
|
||||||
|
bedrock: true,
|
||||||
|
java: true,
|
||||||
|
pocketmine: true,
|
||||||
|
jsprismarine: true,
|
||||||
|
spigot: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
username: "alex",
|
||||||
|
bedrock: true,
|
||||||
|
java: true,
|
||||||
|
pocketmine: true,
|
||||||
|
jsprismarine: true,
|
||||||
|
spigot: true,
|
||||||
|
}
|
||||||
|
],
|
||||||
|
telegram: {
|
||||||
|
admins: ["all_users"],
|
||||||
|
ban: ["Steve_mine_mine"],
|
||||||
|
token: null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Config
|
||||||
|
const ConfigPath = join(bds_dir, "BdsConfig.yaml")
|
||||||
|
|
||||||
|
const SaveConfig = () => writeFileSync(ConfigPath, yaml.dump(Config));
|
||||||
|
process.on("exit", () => SaveConfig());
|
||||||
|
|
||||||
|
if (existsSync(ConfigPath)) {
|
||||||
|
Config.ban = [];
|
||||||
|
Config.server.BackupCron = [];
|
||||||
|
Config.telegram.admins = [];
|
||||||
|
Config.telegram.ban = [];
|
||||||
|
Config = deepmerge(Config, yaml.load(readFileSync(ConfigPath, "utf8")));
|
||||||
|
} else writeFileSync(ConfigPath, yaml.dump(Config))
|
||||||
|
|
||||||
|
// Paths
|
||||||
|
if (!(existsSync(Config.paths["backups"]))) mkdirSync(Config.paths["backups"], {recursive: true})
|
||||||
|
if (!(existsSync(Config.paths["log"]))) mkdirSync(Config.paths["log"], {recursive: true})
|
||||||
|
if (!(existsSync(Config.paths["servers"]))) mkdirSync(Config.paths["servers"], {recursive: true})
|
||||||
|
|
||||||
|
// Server Paths
|
||||||
|
const ServersPaths = {
|
||||||
|
bedrock: join(Config.paths.servers, "Bedrock"),
|
||||||
|
java: join(Config.paths.servers, "Java"),
|
||||||
|
pocketmine: join(Config.paths.servers, "Pocketmine-MP"),
|
||||||
|
dragonfly: join(Config.paths.servers, "Dragonfly_go"),
|
||||||
|
spigot: join(Config.paths.servers, "Spigot")
|
||||||
|
}
|
||||||
|
|
||||||
|
Object.getOwnPropertyNames(ServersPaths).map(Servers => ServersPaths[Servers]).forEach(Servers => {
|
||||||
|
if (!(existsSync(Servers))) {
|
||||||
|
console.log(`Creating the ${basename(Servers)} Folder`);
|
||||||
|
mkdirSync(Servers, {recursive: true})
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// get the path from the settings and return by function
|
||||||
|
function GetPaths(path = null){
|
||||||
|
if (!(path)) throw new Error("Set path to get");
|
||||||
|
if (!(path === "all" || Config.paths[path])) throw new Error("Put a valid path: " + Object.getOwnPropertyNames(Config.paths).join(", "));
|
||||||
|
if (path === "all") return Config.paths
|
||||||
|
return Config.paths[path]
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the server paths if you don't send a throw
|
||||||
|
function GetServerPaths(path = null){
|
||||||
|
if (!(path)) throw new Error("Set path to get");
|
||||||
|
if (!(ServersPaths[path])) throw new Error("Put a valid path: " + Object.getOwnPropertyNames(ServersPaths).join(", "));
|
||||||
|
if (path === "all") return ServersPaths
|
||||||
|
return ServersPaths[path]
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update the settings and save at the same time so as not to lose any information from the Bds Maneger settings
|
||||||
|
function UpdateServerVersion(version = null, platform = Config.server.platform){
|
||||||
|
if (Config.server.versions[platform] || Config.server.versions[platform] === null) {
|
||||||
|
Config.server.versions[platform] = version;
|
||||||
|
SaveConfig()
|
||||||
|
return Config.server.versions[platform]
|
||||||
|
} else throw new Error("Platform invalid")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update the entire Bds Manager Core platform
|
||||||
|
function UpdatePlatform(platform = "null"){
|
||||||
|
platform = platform.toLocaleLowerCase();
|
||||||
|
if (/bedrock/.test(platform)) {
|
||||||
|
Config.server.platform = "bedrock";
|
||||||
|
} else if (/java/.test(platform)) {
|
||||||
|
Config.server.platform = "java";
|
||||||
|
} else if (/pocketmine/.test(platform)) {
|
||||||
|
Config.server.platform = "pocketmine";
|
||||||
|
} else if (/spigot/.test(platform)) {
|
||||||
|
Config.server.platform = "spigot";
|
||||||
|
} else if (/dragonfly/.test(platform)) {
|
||||||
|
Config.server.platform = "dragonfly";
|
||||||
|
} else throw new Error("platform no exists");
|
||||||
|
SaveConfig();
|
||||||
|
return platform
|
||||||
|
}
|
||||||
|
|
||||||
|
// Telegram
|
||||||
|
function UpdateTelegramToken(token = null){
|
||||||
|
if (!(token)) throw new Error("Telegram Token invalid")
|
||||||
|
Config.telegram.token = token
|
||||||
|
SaveConfig()
|
||||||
|
return token
|
||||||
|
}
|
||||||
|
|
||||||
|
const GetJsonConfig = () => Config;
|
||||||
|
|
||||||
|
const GetCronBackup = () => Config.server.BackupCron;
|
||||||
|
const GetPlatform = () => Config.server.platform;
|
||||||
|
|
||||||
|
const GetServerBan = () => Config.ban;
|
||||||
|
const GetServerVersion = () => Config.server.versions;
|
||||||
|
const GetServerSettings = (platform = Config.server.platform) => Config.server.Settings[platform];
|
||||||
|
|
||||||
|
const GetTelegramToken = () => Config.telegram.token;
|
||||||
|
const GetTelegramAdmins = () => Config.telegram.admins;
|
||||||
|
|
||||||
|
// Get a temporary host to connect to the server.
|
||||||
|
const GetTempHost = () => Config.bds.enable_tmp_host
|
||||||
|
|
||||||
|
// Enable and/or disable pick up temporary host.
|
||||||
|
function UpdateTempHost(enable = false){
|
||||||
|
// Check Boolean
|
||||||
|
if (typeof enable !== "boolean") {console.log("Use Boolean, default false"); enable = false;}
|
||||||
|
|
||||||
|
// Save
|
||||||
|
Config.bds.enable_tmp_host = enable
|
||||||
|
SaveConfig();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the server settings
|
||||||
|
function GetCloudConfig(cloud = null){
|
||||||
|
if (!(cloud) || !(Config.cloud[cloud])) throw new Error("Cloud no exists");
|
||||||
|
return Config.cloud[cloud]
|
||||||
|
}
|
||||||
|
|
||||||
|
// Settings Cloud
|
||||||
|
// Azure
|
||||||
|
function Azure_Settings(account = null, key = null, container = null){
|
||||||
|
if (!(account)) throw new Error("Set Azure Blob Account")
|
||||||
|
if (!(key)) throw new Error("Set Azure Blob Key")
|
||||||
|
if (!(container)) throw new Error("Set Azure Container")
|
||||||
|
Config.cloud.Azure.Account = account
|
||||||
|
Config.cloud.Azure.AccountKey = key
|
||||||
|
Config.cloud.Azure.Container = container
|
||||||
|
SaveConfig()
|
||||||
|
return {
|
||||||
|
Account: Config.cloud.Azure.Account,
|
||||||
|
Key: Config.cloud.Azure.AccountKey,
|
||||||
|
Container: Config.cloud.Azure.Container
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Oracle
|
||||||
|
function Oracle_Settings(bucket = null){
|
||||||
|
if (!(bucket)) throw new Error("Set Oracle Bucket name")
|
||||||
|
Config.cloud.Oracle.Bucket = bucket
|
||||||
|
return {
|
||||||
|
Bucket: bucket
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Google Drive
|
||||||
|
function Google_Driver_Settings(rootid = null){
|
||||||
|
if (!(rootid)) {rootid = null; console.log("No Backup folder id added for Google Driver");}
|
||||||
|
Config.cloud.Driver.RootID = rootid
|
||||||
|
SaveConfig()
|
||||||
|
return {
|
||||||
|
RootID: rootid
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create Player JSON
|
||||||
|
if (!(existsSync(GetPaths("player")))) {
|
||||||
|
const PlayerBase = {}
|
||||||
|
for (let ServerPlat of Object.getOwnPropertyNames(Config.server.versions)) PlayerBase[ServerPlat] = [];
|
||||||
|
writeFileSync(GetPaths("player"), JSON.stringify(PlayerBase, null, 2));
|
||||||
|
} else {
|
||||||
|
const PlayerBase = JSON.parse(readFileSync(GetPaths("player"), "utf8"));
|
||||||
|
for (let ServerPlat of Object.getOwnPropertyNames(Config.server.versions)) if (!(PlayerBase[ServerPlat])) PlayerBase[ServerPlat] = [];
|
||||||
|
writeFileSync(GetPaths("player"), JSON.stringify(PlayerBase, null, 2));
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
bds_dir: bds_dir,
|
||||||
|
ServersPaths: ServersPaths,
|
||||||
|
GetJsonConfig,
|
||||||
|
GetPaths,
|
||||||
|
GetServerPaths,
|
||||||
|
GetServerSettings,
|
||||||
|
UpdateServerVersion,
|
||||||
|
GetServerVersion,
|
||||||
|
GetServerBan,
|
||||||
|
GetCronBackup,
|
||||||
|
UpdatePlatform,
|
||||||
|
GetPlatform,
|
||||||
|
UpdateTelegramToken,
|
||||||
|
GetTelegramToken,
|
||||||
|
GetTelegramAdmins,
|
||||||
|
GetTempHost,
|
||||||
|
UpdateTempHost,
|
||||||
|
GetCloudConfig,
|
||||||
|
CloudConfig: {
|
||||||
|
Azure: Azure_Settings,
|
||||||
|
Oracle: Oracle_Settings,
|
||||||
|
Driver: Google_Driver_Settings
|
||||||
|
}
|
||||||
|
}
|
113
src/lib/BdsSystemInfo.js
Normal file
113
src/lib/BdsSystemInfo.js
Normal file
@ -0,0 +1,113 @@
|
|||||||
|
const { release } = require("os");
|
||||||
|
const { readdirSync } = require("fs");
|
||||||
|
const { execSync } = require("child_process");
|
||||||
|
const commadExist = require("./commandExist");
|
||||||
|
const Request = require("./Requests");
|
||||||
|
const { PlatformVersionsV2 } = require("../BdsServersDownload");
|
||||||
|
|
||||||
|
// System Architect (x64, aarch64 and others)
|
||||||
|
let arch;
|
||||||
|
if (process.arch === "arm64") arch = "aarch64";
|
||||||
|
else arch = process.arch
|
||||||
|
|
||||||
|
// Get System Basic Info
|
||||||
|
async function CheckSystemAsync() {
|
||||||
|
const
|
||||||
|
PHPBin = await Request.JSON("https://raw.githubusercontent.com/The-Bds-Maneger/Php_Static_Binary/main/binarys.json"),
|
||||||
|
Servers = {
|
||||||
|
bedrock: await PlatformVersionsV2("bedrock"),
|
||||||
|
spigot: await PlatformVersionsV2("spigot"),
|
||||||
|
dragonfly: await PlatformVersionsV2("dragonfly"),
|
||||||
|
}
|
||||||
|
const BasicConfigJSON = {
|
||||||
|
require_qemu: false,
|
||||||
|
valid_platform: {
|
||||||
|
bedrock: true,
|
||||||
|
pocketmine: true,
|
||||||
|
java: commadExist("java"),
|
||||||
|
dragonfly: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check php bin
|
||||||
|
if ((PHPBin[process.platform] || {})[arch]) BasicConfigJSON.valid_platform["pocketmine"] = true;
|
||||||
|
else BasicConfigJSON.valid_platform["pocketmine"] = false;
|
||||||
|
|
||||||
|
// Check for Dragonfly
|
||||||
|
if (!(Servers.dragonfly.versions[Servers.dragonfly.latest][process.platform][arch])) BasicConfigJSON.valid_platform["dragonfly"] = false;
|
||||||
|
|
||||||
|
// SoSystem X
|
||||||
|
if (process.platform == "linux") {
|
||||||
|
// Bedrock Check
|
||||||
|
if (Servers.bedrock.versions[Servers.bedrock.latest][process.platform]) {
|
||||||
|
if (Servers.bedrock.versions[Servers.bedrock.latest][process.platform][arch]) BasicConfigJSON.valid_platform["bedrock"] = true;
|
||||||
|
else BasicConfigJSON.valid_platform["bedrock"] = false;
|
||||||
|
} else BasicConfigJSON.valid_platform["bedrock"] = false;
|
||||||
|
|
||||||
|
if (BasicConfigJSON.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'");;
|
||||||
|
BasicConfigJSON.valid_platform["bedrock"] = true
|
||||||
|
BasicConfigJSON.require_qemu = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (process.platform === "android") {
|
||||||
|
if (BasicConfigJSON.valid_platform["bedrock"]) BasicConfigJSON.valid_platform["bedrock"] = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return BasicConfigJSON;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Platforms valid from deferents systems
|
||||||
|
*/
|
||||||
|
function GetKernel() {
|
||||||
|
if (process.platform === "win32") {
|
||||||
|
const kernelVersion = parseFloat(release());
|
||||||
|
if (kernelVersion <= 6.1) return "Windows 7";
|
||||||
|
else if (kernelVersion <= 6.2) return "Windows 8";
|
||||||
|
else if (kernelVersion <= 6.3) return "Windows 8.1";
|
||||||
|
else if (kernelVersion <= 10.0) return "Windows 10 or Windows 11";
|
||||||
|
else return "Other Windows";
|
||||||
|
} else if (process.platform === "android") return `Android: ${release()}, CPU Core ${readdirSync("/sys/devices/system/cpu/").filter(data => /cpu[0-9]/.test(data)).length}`;
|
||||||
|
else if (commadExist("uname")) {
|
||||||
|
const str = execSync("uname -rv").toString("ascii");
|
||||||
|
// Amazon web services
|
||||||
|
if (/aws/.test(str)) {
|
||||||
|
if (/arm64|aarch64/.test(process.arch)) return "Amazon AWS Cloud arm64: AWS Graviton Serie";
|
||||||
|
else return `Amazon AWS Cloud ${process.arch}: ${require("os").cpus()[0].model}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Windows subsystem for Linux
|
||||||
|
else if (/WSL2|microsft/.test(str)) return "Microsoft WSL";
|
||||||
|
|
||||||
|
// Azure Virtual Machinime (VM)
|
||||||
|
else if (/[aA]zure/.test(str)) return "Microsoft Azure";
|
||||||
|
|
||||||
|
// Google Cloud Virtual Machinime (VM)
|
||||||
|
else if (/[gG]cp/.test(str)) return "Google Cloud Platform";
|
||||||
|
|
||||||
|
// Oracle cloud Virtual Machinime (VM)
|
||||||
|
else if (/[oO]racle/.test(str)) return "Oracle Cloud infrastructure";
|
||||||
|
|
||||||
|
// Darwin
|
||||||
|
else if (/[dD]arwin/.test(str)) return "Apple MacOS";
|
||||||
|
|
||||||
|
// Others Kernels
|
||||||
|
else return str.replace(/\n|\t|\r/gi, "");
|
||||||
|
} else return "Not identified";
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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 = CheckSystemAsync;
|
||||||
|
module.exports.arch = arch
|
||||||
|
module.exports.GetKernel = GetKernel;
|
||||||
|
module.exports.CheckSystemAsync = CheckSystemAsync;
|
||||||
|
module.exports.GetCpuCoreCount = GetCpuCoreCount;
|
40
src/lib/Requests.js
Normal file
40
src/lib/Requests.js
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
if (typeof global.fetch !== "function") {
|
||||||
|
global.fetch = (...args) => import("node-fetch").then(m => m.default(...args));
|
||||||
|
import("node-fetch").then(m => global.fetch = m.default);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function BufferHTTP(url = "", args = {}) {
|
||||||
|
const res = await fetch(url, {
|
||||||
|
mode: "cors",
|
||||||
|
...args
|
||||||
|
});
|
||||||
|
if (res.ok) return Buffer.from(await res.arrayBuffer());
|
||||||
|
else throw {
|
||||||
|
Error: await res.text(),
|
||||||
|
status: res.status
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function JsonHTTP(url = "", args = {}) {
|
||||||
|
const res = await BufferHTTP(url, args);
|
||||||
|
return JSON.parse(res.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
async function TextHTTP(url = "", args = {}) {
|
||||||
|
return (await BufferHTTP(url, args)).toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Export Bds Request
|
||||||
|
module.exports = {
|
||||||
|
// JSON
|
||||||
|
JSON: JsonHTTP,
|
||||||
|
json: JsonHTTP,
|
||||||
|
|
||||||
|
// Raw Text
|
||||||
|
TEXT: TextHTTP,
|
||||||
|
text: TextHTTP,
|
||||||
|
|
||||||
|
// Buffer
|
||||||
|
BUFFER: BufferHTTP,
|
||||||
|
buffer: BufferHTTP
|
||||||
|
}
|
11
src/lib/commandExist.js
Normal file
11
src/lib/commandExist.js
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
const { execSync } = require("child_process");
|
||||||
|
const { readdirSync, existsSync } = require("fs");
|
||||||
|
|
||||||
|
function commdExist(command){
|
||||||
|
if (process.platform === "linux" || process.platform === "darwin" || process.platform === "android") {try {execSync(`command -v ${command}`);return true} catch (error) {return false}}
|
||||||
|
else if (process.platform === "win32") {try {execSync(`where ${command} > nul 2> nul`);return true} catch (error) {return false}}
|
||||||
|
throw new Error(`Platform ${process.platform} not supported`);
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = commdExist
|
||||||
|
module.exports.sync = commdExist
|
Reference in New Issue
Block a user