Modifications #241
3
.github/workflows/PullRequest.yml
vendored
3
.github/workflows/PullRequest.yml
vendored
@ -1,5 +1,8 @@
|
||||
name: Docker And Node Test
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
|
@ -1,32 +1,33 @@
|
||||
const chai = require("chai");
|
||||
const { assert } = chai;
|
||||
process.env.ShowLoadTime = true;
|
||||
const BdsCore = require("../index");
|
||||
|
||||
describe("Small functions", () => {
|
||||
it("Detect Server is running", function (done) {
|
||||
this.timeout(10000);
|
||||
assert.equal(BdsCore.detect(), false);
|
||||
assert.equal(BdsCore.BdsCkeckKill.Detect(), false);
|
||||
done();
|
||||
});
|
||||
it("List Platforms Avaible", async function() {
|
||||
this.timeout(10 * 1000);
|
||||
await BdsCore.CheckSystem();
|
||||
await BdsCore.BdsSystemInfo.SystemInfo();
|
||||
});
|
||||
it("Update Platform to Java", function(done) {
|
||||
BdsCore.platform_update("java");
|
||||
BdsCore.BdsSettings.UpdatePlatform("java");
|
||||
done();
|
||||
});
|
||||
it("Update Platform to dragonfly", function(done) {
|
||||
BdsCore.platform_update("dragonfly");
|
||||
BdsCore.BdsSettings.UpdatePlatform("dragonfly");
|
||||
done();
|
||||
});
|
||||
it("Register And Delete API Token", function (done) {
|
||||
const Token = BdsCore.token_register();
|
||||
BdsCore.delete_token(Token);
|
||||
const Token = BdsCore.BdsManegerAPI.token_register();
|
||||
BdsCore.BdsManegerAPI.delete_token(Token);
|
||||
done();
|
||||
});
|
||||
it("Get Server Config", function (done) {
|
||||
BdsCore.get_server_config();
|
||||
BdsCore.BdsServerSettings.get_config();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
@ -24,6 +24,7 @@ We have a separate repository for all Bds Maneger Project documentation, [link h
|
||||
[](https://lgtm.com/projects/g/Bds-Maneger/bds_maneger_api/alerts/)
|
||||
[](https://lgtm.com/projects/g/Bds-Maneger/bds_maneger_api/context:javascript)
|
||||
[](https://deepscan.io/dashboard#view=project&tid=13683&pid=16691&bid=363172)
|
||||
[](https://www.codacy.com/gh/The-Bds-Maneger/Bds-Maneger-Core/dashboard?utm_source=github.com&utm_medium=referral&utm_content=The-Bds-Maneger/Bds-Maneger-Core&utm_campaign=Badge_Grade)
|
||||
|
||||
## Start Bds Maneger Core with npx
|
||||
|
||||
|
@ -4,6 +4,10 @@ process.env.IS_BDS_CLI = process.env.IS_BIN_BDS = true;
|
||||
// Internal Modules
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const readline = require("readline");
|
||||
|
||||
// Import Bds Core
|
||||
const BdsCore = require("../index");
|
||||
|
||||
// External Modules
|
||||
const cli_color = require("cli-color");
|
||||
@ -12,14 +16,6 @@ const inquirer = require("inquirer");
|
||||
// Bin Args
|
||||
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
|
||||
const MoreHelp = [];
|
||||
const BeforeRun = [];
|
||||
@ -43,23 +39,23 @@ fs.readdirSync(path.join(__dirname, "plugins")).map(file => path.resolve(__dirna
|
||||
});
|
||||
MoreHelp.push(cli_color.redBright(`Plugin: ${path.basename(Plugin).replace(/\.js$/gi, "")} - ${__module.description}`), "", ...(__module.help || []), "");
|
||||
} catch (err) {
|
||||
console.log(cli_color.redBright(`Error loading plugin: ${Plugin}`));
|
||||
console.log(cli_color.redBright(`Error loading plugin: ${path.basename(Plugin).replace(/\.js$/gi, "")}`));
|
||||
console.log(cli_color.redBright(err));
|
||||
}
|
||||
});
|
||||
|
||||
async function DownloadServer() {
|
||||
const ora = (await import("ora")).default;
|
||||
const PlatformVersion = await PlatformVersionsV2()
|
||||
const PlatformVersion = await BdsCore.BdsDownload.PlatformVersionsV2();
|
||||
const waitUserSelectVersion = (await inquirer.prompt({
|
||||
type: "list",
|
||||
name: "version",
|
||||
message: `Select the version to download ${GetPlatform()}`,
|
||||
message: `Select the version to download ${BdsCore.BdsSettings.GetPlatform()}`,
|
||||
choices: Object.keys(PlatformVersion.versions).map(version => ({name: `v${version}`, value: version}))
|
||||
})).version;
|
||||
const RunSpinner = ora("Downloading...").start();
|
||||
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()}`);
|
||||
} catch (err) {
|
||||
RunSpinner.fail(String(err));
|
||||
@ -68,22 +64,28 @@ async function DownloadServer() {
|
||||
}
|
||||
|
||||
async function info() {
|
||||
const { valid_platform } = await (require("../lib/BdsSystemInfo"))();
|
||||
const commandExist = require("../src/lib/commandExist");
|
||||
const { valid_platform } = await (require("../src/lib/BdsSystemInfo"))();
|
||||
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 === "android" && BdsCore.arch !== "x64"){checkothearch = `qemu-x86_64 is installed to emulate an x64 system: ${commandExits("qemu-x86_64")}\n`}
|
||||
if (process.platform === "linux" && BdsCore.BdsSystemInfo.arch !== "x64"){
|
||||
checkothearch = `qemu-x86_64-static is installed to emulate an x64 system: ${commandExist("qemu-x86_64-static")}\n`
|
||||
}
|
||||
if (process.platform === "android" && BdsCore.BdsSystemInfo.arch !== "x64"){
|
||||
checkothearch = `qemu-x86_64 is installed to emulate an x64 system: ${commandExist("qemu-x86_64")}\n`
|
||||
}
|
||||
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)}`,
|
||||
checkothearch,
|
||||
"**************************************************************",
|
||||
"* Servers currently available:",
|
||||
`* - Bedrock: ${valid_platform.bedrock}`,
|
||||
`* - Java and Spigot: ${valid_platform.java ? cli_color.green("Available") : cli_color.red("Needs Java installed https://upstream.bdsmaneger.com/docs/Java?Installer=info")}`,
|
||||
`* - Dragonfly: ${valid_platform.dragonfly}`,
|
||||
`* - Pocketmine-MP: ${valid_platform.pocketmine}`,
|
||||
"*",
|
||||
"**************************************************************"
|
||||
"",
|
||||
`Bds Maneger Core And Bds Maneger CLI version: ${cli_color.magentaBright(BdsCore.version)}`,
|
||||
`System: ${cli_color.yellow(process.platform)}, architecture: ${cli_color.blue(BdsCore.BdsSystemInfo.arch)}`,
|
||||
checkothearch,
|
||||
"**************************************************************",
|
||||
"* Servers currently available:",
|
||||
`* - Bedrock: ${valid_platform.bedrock ? cli_color.greenBright("Avaible") : cli_color.redBright("Not Avaible")}`,
|
||||
`* - Java and Spigot: ${valid_platform.java ? cli_color.greenBright("Avaible") : cli_color.redBright("Not Avaible")}`,
|
||||
`* - 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"))));
|
||||
// End
|
||||
@ -92,8 +94,8 @@ async function info() {
|
||||
|
||||
async function help() {
|
||||
const help = [
|
||||
`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 CLI version: ${cli_color.magentaBright(BdsCore.version)}`,
|
||||
`System: ${cli_color.yellow(process.platform)}, architecture: ${cli_color.blue(BdsCore.BdsSystemInfo.arch)}`,
|
||||
"",
|
||||
" Usage: bds-maneger-cli [options]",
|
||||
"",
|
||||
@ -132,7 +134,7 @@ async function Runner() {
|
||||
if (ProcessArgs.platform || ProcessArgs.p) {
|
||||
const UpdatePla = ora("Updating Bds Platform").start();
|
||||
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}`);
|
||||
} catch (error) {
|
||||
UpdatePla.fail(`Unable to update platform to ${ProcessArgs.platform || ProcessArgs.p}`);
|
||||
@ -155,14 +157,29 @@ async function Runner() {
|
||||
// Download
|
||||
if (ProcessArgs.download || ProcessArgs.d) await DownloadServer();
|
||||
|
||||
// Kill
|
||||
if (ProcessArgs.kill || ProcessArgs.k) BdsCore.BdsCkeckKill.Kill();
|
||||
|
||||
// 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
|
||||
if (!(ProcessArgs.start || ProcessArgs.s)) return;
|
||||
|
||||
const BdsManegerServer = BdsCore.BdsManegerServer.StartServer();
|
||||
BdsManegerServer.log(data => process.stdout.write(cli_color.blueBright(data)));
|
||||
if (!(ProcessArgs["no-api"])) BdsCore.BdsManegerAPI.api();
|
||||
const __readline = readline.createInterface({input: process.stdin, output: process.stdout});
|
||||
__readline.on("line", data => BdsManegerServer.command(data));
|
||||
__readline.on("close", () => BdsManegerServer.stop());
|
||||
// Get Temporary External Domain
|
||||
if (ProcessArgs.get_domain) {
|
||||
try {
|
||||
const HostInfo = await BdsNetwork.GetHost();
|
||||
const HostInfo = await BdsCore.BdsNetwork.GetHost();
|
||||
console.log("Domain:", HostInfo.host);
|
||||
BdsManegerServer.exit(async () => await HostInfo.delete_host());
|
||||
process.on("exit", async () => {
|
||||
await HostInfo.delete_host();
|
||||
console.log("Sucess remove host");
|
||||
@ -171,20 +188,9 @@ async function Runner() {
|
||||
console.log("Cannot get domain");
|
||||
}
|
||||
}
|
||||
|
||||
// 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));
|
||||
}
|
||||
|
||||
const BdsManegerServer = BdsCore.start();
|
||||
BdsManegerServer.log(data => console.log(cli_color.blueBright(data.replace(/\n$/gi, ""))));
|
||||
BdsManegerServer.exit(code => {
|
||||
console.log(cli_color.redBright(`Bds Core Exit with code ${code}, Uptimed: ${BdsManegerServer.uptime}`));
|
||||
process.exit(code);
|
||||
console.log(cli_color.redBright(`Bds Core Exit with code ${code}, Uptimed: ${BdsManegerServer.uptime}`));
|
||||
process.exit(code);
|
||||
});
|
||||
if (!(ProcessArgs["no-api"])) BdsCore.api();
|
||||
const __readline = readline.createInterface({input: process.stdin, output: process.stdout});
|
||||
__readline.on("line", data => BdsManegerServer.command(data));
|
||||
}
|
||||
Runner();
|
||||
|
187
bin/Docker.js
187
bin/Docker.js
@ -1,126 +1,95 @@
|
||||
#!/usr/bin/env node
|
||||
process.env.BDS_DOCKER_IMAGE = true;
|
||||
const path = require("path");
|
||||
const fs = require("fs");
|
||||
|
||||
const BdsCore = require("../index");
|
||||
const { GetPlatform, bds_dir } = require("../lib/BdsSettings");
|
||||
const { GetPlatform } = require("../src/lib/BdsSettings");
|
||||
const { CronJob } = require("cron");
|
||||
const BdsInfo = require("../BdsManegerInfo.json");
|
||||
const { PlatformVersionsV2 } = require("../src/BdsServersDownload");
|
||||
|
||||
// Get Current Tokens and Show in the console
|
||||
function ShowToken() {
|
||||
const TokenFilePath = path.join(bds_dir, "bds_tokens.json");
|
||||
let Tokens = 1
|
||||
if (fs.existsSync(TokenFilePath)) {
|
||||
[...JSON.parse(fs.readFileSync(TokenFilePath, "utf8"))].slice(0, 5).forEach(token => {console.log(Tokens+":", "Bds API Token:", token.token); Tokens++});
|
||||
} else {
|
||||
console.log("No Tokens Found");
|
||||
}
|
||||
const TokenFilePath = BdsCore.BdsManegerAPI.TokensFilePath;
|
||||
let Tokens = 1
|
||||
if (fs.existsSync(TokenFilePath)) {
|
||||
[...JSON.parse(fs.readFileSync(TokenFilePath, "utf8"))].slice(0, 5).forEach(token => {console.log(Tokens+":", "Bds API Token:", token.token); Tokens++});
|
||||
} else {
|
||||
console.log(Tokens+":", "Bds API Token:", BdsCore.BdsManegerAPI.token_register());
|
||||
}
|
||||
}
|
||||
|
||||
function StartServer(){
|
||||
console.log("The entire log can be accessed via the api and/or the docker log");
|
||||
const ServerStarted = BdsCore.start();
|
||||
ServerStarted.log(a => process.stdout.write(a));
|
||||
ServerStarted.exit(code => process.exit(code));
|
||||
BdsCore.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)
|
||||
}
|
||||
ShowToken();
|
||||
if (process.env.UPDATE_SERVER === "true") {
|
||||
new CronJob("0 */1 * * *", async () => {
|
||||
try {
|
||||
const CurrentLocalVersion = BdsCore.getBdsConfig().server.versions[GetPlatform()],
|
||||
CurrentRemoteVersion = (await PlatformVersionsV2(GetPlatform())).latest;
|
||||
if (CurrentLocalVersion !== CurrentRemoteVersion) {
|
||||
let currenttime = `Hello we are starting the server upgrade from version ${CurrentLocalVersion} to version ${CurrentRemoteVersion}, you have 20 seconds to exit the server`
|
||||
console.log("Update Server:", currenttime);
|
||||
ServerStarted.say(currenttime);
|
||||
let countdown = 20;
|
||||
while (countdown > 1) {
|
||||
currenttime = `${countdown} seconds remaining to stop Server!`;
|
||||
console.log(currenttime);
|
||||
ServerStarted.say(currenttime);
|
||||
countdown--;
|
||||
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||
}
|
||||
currenttime = "Stopping the server"
|
||||
console.log(currenttime);
|
||||
ServerStarted.say(currenttime);
|
||||
await new Promise(resolve => setTimeout(resolve, 600));
|
||||
ServerStarted.stop();
|
||||
}
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
});
|
||||
async function CheckAndUpdateServer() {
|
||||
const LatestVersion = (await BdsCore.BdsDownload.PlatformVersionsV2()).latest;
|
||||
const LocalVersion = BdsCore.BdsSettings.GetServerVersion()[GetPlatform()];
|
||||
if (!LocalVersion) {
|
||||
console.log("Server is not installed, starting server implementation");
|
||||
const __InitInstall = await BdsCore.BdsDownload(true);
|
||||
console.log("Installed Version:", __InitInstall.version, `Release Version: ${__InitInstall.data.getDate()}/${__InitInstall.data.getMonth()}/${__InitInstall.data.getFullYear()}`);
|
||||
} else if (LocalVersion !== LatestVersion) {
|
||||
console.log("Server is out of date, starting server implementation");
|
||||
const __UpdateInstall = await BdsCore.BdsDownload(true);
|
||||
console.log("Updated Version:", __UpdateInstall.version, `Release Version: ${__UpdateInstall.data.getDate()}/${__UpdateInstall.data.getMonth()}/${__UpdateInstall.data.getFullYear()}`);
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
new CronJob("0 */1 * * *", async () => {
|
||||
try {
|
||||
const CurrentLocalVersion = BdsCore.BdsSettings.GetServerVersion()[GetPlatform()],
|
||||
CurrentRemoteVersion = (await PlatformVersionsV2(GetPlatform())).latest;
|
||||
if (CurrentLocalVersion !== CurrentRemoteVersion) {
|
||||
let currenttime = `Hello we are starting the server upgrade from version ${CurrentLocalVersion} to version ${CurrentRemoteVersion}, you have 20 seconds to exit the server`
|
||||
console.log("Update Server:", currenttime);
|
||||
ServerStarted.say(currenttime);
|
||||
let countdown = 20;
|
||||
while (countdown > 1) {
|
||||
currenttime = `${countdown} seconds remaining to stop Server!`;
|
||||
console.log(currenttime);
|
||||
ServerStarted.say(currenttime);
|
||||
countdown--;
|
||||
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||
}
|
||||
currenttime = "Stopping the server"
|
||||
console.log(currenttime);
|
||||
ServerStarted.say(currenttime);
|
||||
await new Promise(resolve => setTimeout(resolve, 600));
|
||||
ServerStarted.stop();
|
||||
}
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async function RenderCLI(){
|
||||
// Check Installed Server
|
||||
const AllVersions = BdsCore.BdsSettigs.GetJsonConfig().server.versions;
|
||||
if (Object.getOwnPropertyNames(AllVersions).filter(platform => AllVersions[platform]).length >= 1) {
|
||||
if (process.env.UPDATE_SERVER === "true") {
|
||||
try {
|
||||
await BdsCore.download(true, true);
|
||||
StartServer();
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
process.exit(1);
|
||||
}
|
||||
} else {
|
||||
// Check for Update
|
||||
if (AllVersions[GetPlatform()] === Object.getOwnPropertyNames((await (await fetch(BdsInfo.Fetchs.servers)).json())[GetPlatform()])[0]) {
|
||||
console.log("The entire log can be accessed via the api and/or the docker log");
|
||||
const ServerStarted = BdsCore.start();
|
||||
ServerStarted.log(a => process.stdout.write(a));
|
||||
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);
|
||||
}
|
||||
}
|
||||
await CheckAndUpdateServer();
|
||||
const { DESCRIPTION, WORLD_NAME, GAMEMODE, DIFFICULTY, ACCOUNT, PLAYERS, SERVER, ENABLE_COMMANDS } = process.env;
|
||||
BdsCore.BdsSettings.UpdatePlatform(SERVER || "bedrock");
|
||||
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.BdsServerSettings.config(ServerConfig);
|
||||
await StartServer();
|
||||
}
|
||||
RenderCLI();
|
||||
RenderCLI();
|
||||
|
@ -1,8 +1,8 @@
|
||||
const fs = require("fs");
|
||||
const { Telegraf, Markup } = require("telegraf");
|
||||
const bds = require("../../index");
|
||||
const { GetPlatform, GetPaths, GetTelegramToken, UpdateTelegramToken } = require("../../lib/BdsSettings");
|
||||
const { GetKernel, arch, system } = require("../../lib/BdsSystemInfo");
|
||||
const { GetPlatform, GetPaths, GetTelegramToken, UpdateTelegramToken } = require("../../src/lib/BdsSettings");
|
||||
const { GetKernel, arch, system } = require("../../src/lib/BdsSystemInfo");
|
||||
const { Detect } = require("../../src/CheckKill");
|
||||
const { CheckTelegramUser } = require("../../src/UsersAndtokenChecks");
|
||||
const BdsInfo = require("../../BdsManegerInfo.json");
|
||||
@ -25,7 +25,9 @@ const HelpAndStart = [
|
||||
];
|
||||
|
||||
// Set Telegram Bot
|
||||
const bot = new Telegraf(GetTelegramToken());
|
||||
const TelegramToken = GetTelegramToken();
|
||||
if (!TelegramToken) throw new Error("Add Telegram Token");
|
||||
const bot = new Telegraf(TelegramToken);
|
||||
|
||||
// Start and Help Command
|
||||
bot.start((ctx)=>ctx.reply(HelpAndStart.join("\n")));
|
||||
|
@ -1,10 +1,14 @@
|
||||
version: "2.1"
|
||||
version: "3.9"
|
||||
volumes:
|
||||
BdsManegerData:
|
||||
services:
|
||||
bdscore:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
container_name: bds_maneger_core
|
||||
volumes:
|
||||
- BdsManegerData:/root/bds_core
|
||||
environment:
|
||||
DESCRIPTION: "Docker Test"
|
||||
WORLD_NAME: "Docker Run Test"
|
||||
@ -16,6 +20,4 @@ services:
|
||||
SERVER: "bedrock"
|
||||
ports:
|
||||
- 1932:1932/tcp
|
||||
- 19132:19132/udp
|
||||
volumes:
|
||||
- ./Test:/root/bds_core
|
||||
- 19132:19132/udp
|
139
index.js
139
index.js
@ -1,113 +1,48 @@
|
||||
/* eslint-disable no-irregular-whitespace */
|
||||
const path = require("path")
|
||||
const fs = require("fs");
|
||||
const { randomUUID } = require("crypto");
|
||||
const BdsSettings = require("./lib/BdsSettings");
|
||||
// process.env.ShowLoadTime = true;
|
||||
// Load Root JSON
|
||||
const BdsManegerCoreJSONs = {
|
||||
Package: require("./package.json"),
|
||||
Extra: require("./BdsManegerInfo.json")
|
||||
};
|
||||
|
||||
// Bds Maneger Core Package JSON File
|
||||
module.exports.package_path = path.resolve(__dirname, "package.json");
|
||||
module.exports.package_json = require("./package.json");
|
||||
module.exports.extra_json = require("./BdsManegerInfo.json");
|
||||
module.exports.BdsCoreVersion = module.exports.package_json.version;
|
||||
// Bds Maneger Core Version
|
||||
module.exports.version = BdsManegerCoreJSONs.Package.version;
|
||||
module.exports.ExtraJSON = BdsManegerCoreJSONs;
|
||||
|
||||
// Inport and Export Arch
|
||||
const { arch } = require("./lib/BdsSystemInfo");
|
||||
module.exports.arch = arch
|
||||
if (process.env.ShowLoadTime) console.time("Bds Maneger Core: Settings");
|
||||
module.exports.BdsSettings = require("./src/lib/BdsSettings");
|
||||
if (process.env.ShowLoadTime) console.timeEnd("Bds Maneger Core: Settings");
|
||||
|
||||
// Core Settings
|
||||
module.exports.getBdsConfig = BdsSettings.GetJsonConfig;
|
||||
module.exports.change_platform = BdsSettings.UpdatePlatform;
|
||||
module.exports.platform_update = BdsSettings.UpdatePlatform;
|
||||
module.exports.telegram_token_save = BdsSettings.UpdateTelegramToken;
|
||||
if (process.env.ShowLoadTime) console.time("Bds Maneger Core: System Info");
|
||||
module.exports.BdsSystemInfo = require("./src/lib/BdsSystemInfo");
|
||||
if (process.env.ShowLoadTime) console.timeEnd("Bds Maneger Core: System Info");
|
||||
|
||||
// Platforms Checkers
|
||||
const { CheckSystemAsync, GetKernel } = require("./lib/BdsSystemInfo");
|
||||
module.exports.CheckSystem = CheckSystemAsync;
|
||||
module.exports.GetKernel = GetKernel;
|
||||
if (process.env.ShowLoadTime) console.time("Bds Maneger Core: Network");
|
||||
module.exports.BdsNetwork = require("./src/BdsNetwork")
|
||||
if (process.env.ShowLoadTime) console.timeEnd("Bds Maneger Core: Network");
|
||||
|
||||
// Bds Maneger Core Network
|
||||
const BdsNetwork = require("./src/BdsNetwork")
|
||||
module.exports.internal_ip = BdsNetwork.LocalInterfaces;
|
||||
module.exports.external_ip = BdsNetwork.GetExternalPublicAddress;
|
||||
if (process.env.ShowLoadTime) console.time("Bds Maneger Core: Backups");
|
||||
module.exports.BdsBackup = require("./src/BdsBackup");
|
||||
if (process.env.ShowLoadTime) console.timeEnd("Bds Maneger Core: Backups");
|
||||
|
||||
// Bds Maneger Core API
|
||||
const BdsManegerAPI = require("./src/api");
|
||||
module.exports.api = BdsManegerAPI;
|
||||
module.exports.BdsManegerAPI = BdsManegerAPI;
|
||||
if (process.env.ShowLoadTime) console.time("Bds Maneger Core: Server Settings");
|
||||
module.exports.BdsServerSettings = require("./src/ServerSettings");
|
||||
if (process.env.ShowLoadTime) console.timeEnd("Bds Maneger Core: Server Settings");
|
||||
|
||||
// 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;
|
||||
}
|
||||
if (process.env.ShowLoadTime) console.time("Bds Maneger Core: Download Server");
|
||||
module.exports.BdsDownload = require("./src/BdsServersDownload");
|
||||
if (process.env.ShowLoadTime) console.timeEnd("Bds Maneger Core: Download Server");
|
||||
|
||||
// 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;
|
||||
}
|
||||
if (process.env.ShowLoadTime) console.time("Bds Maneger Core: Check And Kill");
|
||||
module.exports.BdsCkeckKill = require("./src/CheckKill");
|
||||
if (process.env.ShowLoadTime) console.timeEnd("Bds Maneger Core: Check And Kill");
|
||||
|
||||
// Check Exists Tokens Files
|
||||
if (!(fs.existsSync(path_tokens))) token_register();
|
||||
if (process.env.ShowLoadTime) console.time("Bds Maneger Core: API");
|
||||
module.exports.BdsManegerAPI = require("./src/api");
|
||||
if (process.env.ShowLoadTime) console.timeEnd("Bds Maneger Core: API");
|
||||
|
||||
// Server Settings
|
||||
module.exports.token_register = token_register;
|
||||
module.exports.bds_maneger_token_register = token_register;
|
||||
module.exports.delete_token = delete_token;
|
||||
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);
|
||||
if (process.env.ShowLoadTime) console.time("Bds Maneger Core: Server Maneger");
|
||||
module.exports.BdsManegerServer = require("./src/BdsManegerServer");
|
||||
if (process.env.ShowLoadTime) console.timeEnd("Bds Maneger Core: Server Maneger");
|
||||
if (process.env.ShowLoadTime) console.log("Bds Maneger Core: Complete");
|
@ -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
|
||||
}
|
334
package-lock.json
generated
334
package-lock.json
generated
@ -26,7 +26,7 @@
|
||||
"express": "^4.17.1",
|
||||
"express-fileupload": "^1.2.1",
|
||||
"express-prettify": "^0.1.1",
|
||||
"express-rate-limit": "^5.2.3",
|
||||
"express-rate-limit": "^5.5.1",
|
||||
"googleapis": "^91.0.0",
|
||||
"inquirer": "^8.1.5",
|
||||
"js-yaml": "^4.1.0",
|
||||
@ -37,6 +37,7 @@
|
||||
"ora": "^6.0.1",
|
||||
"properties-to-json": "^0.2.1",
|
||||
"request-ip": "^2.1.3",
|
||||
"socket.io": "^4.3.2",
|
||||
"telegraf": "^4.0.0"
|
||||
},
|
||||
"bin": {
|
||||
@ -322,6 +323,21 @@
|
||||
"node": ">=6"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/component-emitter": {
|
||||
"version": "1.2.11",
|
||||
"resolved": "https://registry.npmjs.org/@types/component-emitter/-/component-emitter-1.2.11.tgz",
|
||||
"integrity": "sha512-SRXjM+tfsSlA9VuG8hGO2nft2p8zjXCK1VcC6N4NXbBbYbSia9kzCChYQajIjzIqOOOuh5Ock6MmV2oux4jDZQ=="
|
||||
},
|
||||
"node_modules/@types/cookie": {
|
||||
"version": "0.4.1",
|
||||
"resolved": "https://registry.npmjs.org/@types/cookie/-/cookie-0.4.1.tgz",
|
||||
"integrity": "sha512-XW/Aa8APYr6jSVVA1y/DEIZX0/GMKLEVekNG727R8cs56ahETkRAy/3DR7+fJyh7oUgGwNQaRfXCun0+KbWY7Q=="
|
||||
},
|
||||
"node_modules/@types/cors": {
|
||||
"version": "2.8.12",
|
||||
"resolved": "https://registry.npmjs.org/@types/cors/-/cors-2.8.12.tgz",
|
||||
"integrity": "sha512-vt+kDhq/M2ayberEtJcIN/hxXy1Pk+59g2FV/ZQceeaTyCtCucjL2Q7FXlFjtWn4n15KCr1NE2lNNFhp0lEThw=="
|
||||
},
|
||||
"node_modules/@types/isomorphic-fetch": {
|
||||
"version": "0.0.35",
|
||||
"resolved": "https://registry.npmjs.org/@types/isomorphic-fetch/-/isomorphic-fetch-0.0.35.tgz",
|
||||
@ -632,6 +648,14 @@
|
||||
"integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/base64-arraybuffer": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/base64-arraybuffer/-/base64-arraybuffer-1.0.1.tgz",
|
||||
"integrity": "sha512-vFIUq7FdLtjZMhATwDul5RZWv2jpXQ09Pd6jcVEOvIsqCWTRFD/ONHNfyOS8dA/Ippi5dsIgpyKWKZaAKZltbA==",
|
||||
"engines": {
|
||||
"node": ">= 0.6.0"
|
||||
}
|
||||
},
|
||||
"node_modules/base64-js": {
|
||||
"version": "1.5.1",
|
||||
"resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz",
|
||||
@ -651,6 +675,14 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"node_modules/base64id": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/base64id/-/base64id-2.0.0.tgz",
|
||||
"integrity": "sha512-lGe34o6EHj9y3Kts9R4ZYs/Gr+6N7MCaMlIFA3F1R2O5/m7K06AxfSeO5530PEERE6/WyEg3lsuyw4GHlPZHog==",
|
||||
"engines": {
|
||||
"node": "^4.5.0 || >= 5.9"
|
||||
}
|
||||
},
|
||||
"node_modules/bcrypt-pbkdf": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.2.tgz",
|
||||
@ -1075,6 +1107,11 @@
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/component-emitter": {
|
||||
"version": "1.3.0",
|
||||
"resolved": "https://registry.npmjs.org/component-emitter/-/component-emitter-1.3.0.tgz",
|
||||
"integrity": "sha512-Rd3se6QB+sO1TwqZjscQrurpEPIfO0/yYnSin6Q/rD3mOutHvUrCAhJub3r90uNb+SESBuE0QYoB90YdfatsRg=="
|
||||
},
|
||||
"node_modules/concat-map": {
|
||||
"version": "0.0.1",
|
||||
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
|
||||
@ -1402,6 +1439,66 @@
|
||||
"once": "^1.4.0"
|
||||
}
|
||||
},
|
||||
"node_modules/engine.io": {
|
||||
"version": "6.0.1",
|
||||
"resolved": "https://registry.npmjs.org/engine.io/-/engine.io-6.0.1.tgz",
|
||||
"integrity": "sha512-Y53UaciUh2Rmx5MiogtMxOQcfh7pnemday+Bb4QDg0Wjmnvo/VTvuEyNGQgYmh8L7VOe8Je1QuiqjLNDelMqLA==",
|
||||
"dependencies": {
|
||||
"@types/cookie": "^0.4.1",
|
||||
"@types/cors": "^2.8.12",
|
||||
"@types/node": ">=10.0.0",
|
||||
"accepts": "~1.3.4",
|
||||
"base64id": "2.0.0",
|
||||
"cookie": "~0.4.1",
|
||||
"cors": "~2.8.5",
|
||||
"debug": "~4.3.1",
|
||||
"engine.io-parser": "~5.0.0",
|
||||
"ws": "~8.2.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/engine.io-parser": {
|
||||
"version": "5.0.2",
|
||||
"resolved": "https://registry.npmjs.org/engine.io-parser/-/engine.io-parser-5.0.2.tgz",
|
||||
"integrity": "sha512-wuiO7qO/OEkPJSFueuATIXtrxF7/6GTbAO9QLv7nnbjwZ5tYhLm9zxvLwxstRs0dcT0KUlWTjtIOs1T86jt12g==",
|
||||
"dependencies": {
|
||||
"base64-arraybuffer": "~1.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/engine.io/node_modules/cookie": {
|
||||
"version": "0.4.1",
|
||||
"resolved": "https://registry.npmjs.org/cookie/-/cookie-0.4.1.tgz",
|
||||
"integrity": "sha512-ZwrFkGJxUR3EIoXtO+yVE69Eb7KlixbaeAWfBQB9vVsNn/o+Yw69gBWSSDK825hQNdN+wF8zELf3dFNl/kxkUA==",
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/engine.io/node_modules/debug": {
|
||||
"version": "4.3.2",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.2.tgz",
|
||||
"integrity": "sha512-mOp8wKcvj7XxC78zLgw/ZA+6TSgkoE2C/ienthhRD298T7UNwAg9diBpLRxC0mOezLl4B0xV7M0cCO6P/O0Xhw==",
|
||||
"dependencies": {
|
||||
"ms": "2.1.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6.0"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"supports-color": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/engine.io/node_modules/ms": {
|
||||
"version": "2.1.2",
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
|
||||
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
|
||||
},
|
||||
"node_modules/enquirer": {
|
||||
"version": "2.3.6",
|
||||
"resolved": "https://registry.npmjs.org/enquirer/-/enquirer-2.3.6.tgz",
|
||||
@ -5200,6 +5297,82 @@
|
||||
"resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.4.tgz",
|
||||
"integrity": "sha512-rqYhcAnZ6d/vTPGghdrw7iumdcbXpsk1b8IG/rz+VWV51DM0p7XCtMoJ3qhPLIbp3tvyt3pKRbaaEMZYpHto8Q=="
|
||||
},
|
||||
"node_modules/socket.io": {
|
||||
"version": "4.3.2",
|
||||
"resolved": "https://registry.npmjs.org/socket.io/-/socket.io-4.3.2.tgz",
|
||||
"integrity": "sha512-6S5tV4jcY6dbZ/lLzD6EkvNWI3s81JO6ABP/EpvOlK1NPOcIj3AS4khi6xXw6JlZCASq82HQV4SapfmVMMl2dg==",
|
||||
"dependencies": {
|
||||
"accepts": "~1.3.4",
|
||||
"base64id": "~2.0.0",
|
||||
"debug": "~4.3.2",
|
||||
"engine.io": "~6.0.0",
|
||||
"socket.io-adapter": "~2.3.2",
|
||||
"socket.io-parser": "~4.0.4"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/socket.io-adapter": {
|
||||
"version": "2.3.3",
|
||||
"resolved": "https://registry.npmjs.org/socket.io-adapter/-/socket.io-adapter-2.3.3.tgz",
|
||||
"integrity": "sha512-Qd/iwn3VskrpNO60BeRyCyr8ZWw9CPZyitW4AQwmRZ8zCiyDiL+znRnWX6tDHXnWn1sJrM1+b6Mn6wEDJJ4aYQ=="
|
||||
},
|
||||
"node_modules/socket.io-parser": {
|
||||
"version": "4.0.4",
|
||||
"resolved": "https://registry.npmjs.org/socket.io-parser/-/socket.io-parser-4.0.4.tgz",
|
||||
"integrity": "sha512-t+b0SS+IxG7Rxzda2EVvyBZbvFPBCjJoyHuE0P//7OAsN23GItzDRdWa6ALxZI/8R5ygK7jAR6t028/z+7295g==",
|
||||
"dependencies": {
|
||||
"@types/component-emitter": "^1.2.10",
|
||||
"component-emitter": "~1.3.0",
|
||||
"debug": "~4.3.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/socket.io-parser/node_modules/debug": {
|
||||
"version": "4.3.2",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.2.tgz",
|
||||
"integrity": "sha512-mOp8wKcvj7XxC78zLgw/ZA+6TSgkoE2C/ienthhRD298T7UNwAg9diBpLRxC0mOezLl4B0xV7M0cCO6P/O0Xhw==",
|
||||
"dependencies": {
|
||||
"ms": "2.1.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6.0"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"supports-color": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/socket.io-parser/node_modules/ms": {
|
||||
"version": "2.1.2",
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
|
||||
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
|
||||
},
|
||||
"node_modules/socket.io/node_modules/debug": {
|
||||
"version": "4.3.2",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.2.tgz",
|
||||
"integrity": "sha512-mOp8wKcvj7XxC78zLgw/ZA+6TSgkoE2C/ienthhRD298T7UNwAg9diBpLRxC0mOezLl4B0xV7M0cCO6P/O0Xhw==",
|
||||
"dependencies": {
|
||||
"ms": "2.1.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6.0"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"supports-color": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/socket.io/node_modules/ms": {
|
||||
"version": "2.1.2",
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
|
||||
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
|
||||
},
|
||||
"node_modules/sshpk": {
|
||||
"version": "1.16.1",
|
||||
"resolved": "https://registry.npmjs.org/sshpk/-/sshpk-1.16.1.tgz",
|
||||
@ -5804,6 +5977,26 @@
|
||||
"typedarray-to-buffer": "^3.1.5"
|
||||
}
|
||||
},
|
||||
"node_modules/ws": {
|
||||
"version": "8.2.3",
|
||||
"resolved": "https://registry.npmjs.org/ws/-/ws-8.2.3.tgz",
|
||||
"integrity": "sha512-wBuoj1BDpC6ZQ1B7DWQBYVLphPWkm8i9Y0/3YdHjHKHiohOJ1ws+3OccDWtH+PoC9DZD5WOTrJvNbWvjS6JWaA==",
|
||||
"engines": {
|
||||
"node": ">=10.0.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"bufferutil": "^4.0.1",
|
||||
"utf-8-validate": "^5.0.2"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"bufferutil": {
|
||||
"optional": true
|
||||
},
|
||||
"utf-8-validate": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/xdg-basedir": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/xdg-basedir/-/xdg-basedir-4.0.0.tgz",
|
||||
@ -6120,6 +6313,21 @@
|
||||
"defer-to-connect": "^1.0.1"
|
||||
}
|
||||
},
|
||||
"@types/component-emitter": {
|
||||
"version": "1.2.11",
|
||||
"resolved": "https://registry.npmjs.org/@types/component-emitter/-/component-emitter-1.2.11.tgz",
|
||||
"integrity": "sha512-SRXjM+tfsSlA9VuG8hGO2nft2p8zjXCK1VcC6N4NXbBbYbSia9kzCChYQajIjzIqOOOuh5Ock6MmV2oux4jDZQ=="
|
||||
},
|
||||
"@types/cookie": {
|
||||
"version": "0.4.1",
|
||||
"resolved": "https://registry.npmjs.org/@types/cookie/-/cookie-0.4.1.tgz",
|
||||
"integrity": "sha512-XW/Aa8APYr6jSVVA1y/DEIZX0/GMKLEVekNG727R8cs56ahETkRAy/3DR7+fJyh7oUgGwNQaRfXCun0+KbWY7Q=="
|
||||
},
|
||||
"@types/cors": {
|
||||
"version": "2.8.12",
|
||||
"resolved": "https://registry.npmjs.org/@types/cors/-/cors-2.8.12.tgz",
|
||||
"integrity": "sha512-vt+kDhq/M2ayberEtJcIN/hxXy1Pk+59g2FV/ZQceeaTyCtCucjL2Q7FXlFjtWn4n15KCr1NE2lNNFhp0lEThw=="
|
||||
},
|
||||
"@types/isomorphic-fetch": {
|
||||
"version": "0.0.35",
|
||||
"resolved": "https://registry.npmjs.org/@types/isomorphic-fetch/-/isomorphic-fetch-0.0.35.tgz",
|
||||
@ -6368,11 +6576,21 @@
|
||||
"integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==",
|
||||
"dev": true
|
||||
},
|
||||
"base64-arraybuffer": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/base64-arraybuffer/-/base64-arraybuffer-1.0.1.tgz",
|
||||
"integrity": "sha512-vFIUq7FdLtjZMhATwDul5RZWv2jpXQ09Pd6jcVEOvIsqCWTRFD/ONHNfyOS8dA/Ippi5dsIgpyKWKZaAKZltbA=="
|
||||
},
|
||||
"base64-js": {
|
||||
"version": "1.5.1",
|
||||
"resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz",
|
||||
"integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA=="
|
||||
},
|
||||
"base64id": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/base64id/-/base64id-2.0.0.tgz",
|
||||
"integrity": "sha512-lGe34o6EHj9y3Kts9R4ZYs/Gr+6N7MCaMlIFA3F1R2O5/m7K06AxfSeO5530PEERE6/WyEg3lsuyw4GHlPZHog=="
|
||||
},
|
||||
"bcrypt-pbkdf": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.2.tgz",
|
||||
@ -6695,6 +6913,11 @@
|
||||
"delayed-stream": "~1.0.0"
|
||||
}
|
||||
},
|
||||
"component-emitter": {
|
||||
"version": "1.3.0",
|
||||
"resolved": "https://registry.npmjs.org/component-emitter/-/component-emitter-1.3.0.tgz",
|
||||
"integrity": "sha512-Rd3se6QB+sO1TwqZjscQrurpEPIfO0/yYnSin6Q/rD3mOutHvUrCAhJub3r90uNb+SESBuE0QYoB90YdfatsRg=="
|
||||
},
|
||||
"concat-map": {
|
||||
"version": "0.0.1",
|
||||
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
|
||||
@ -6956,6 +7179,51 @@
|
||||
"once": "^1.4.0"
|
||||
}
|
||||
},
|
||||
"engine.io": {
|
||||
"version": "6.0.1",
|
||||
"resolved": "https://registry.npmjs.org/engine.io/-/engine.io-6.0.1.tgz",
|
||||
"integrity": "sha512-Y53UaciUh2Rmx5MiogtMxOQcfh7pnemday+Bb4QDg0Wjmnvo/VTvuEyNGQgYmh8L7VOe8Je1QuiqjLNDelMqLA==",
|
||||
"requires": {
|
||||
"@types/cookie": "^0.4.1",
|
||||
"@types/cors": "^2.8.12",
|
||||
"@types/node": ">=10.0.0",
|
||||
"accepts": "~1.3.4",
|
||||
"base64id": "2.0.0",
|
||||
"cookie": "~0.4.1",
|
||||
"cors": "~2.8.5",
|
||||
"debug": "~4.3.1",
|
||||
"engine.io-parser": "~5.0.0",
|
||||
"ws": "~8.2.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"cookie": {
|
||||
"version": "0.4.1",
|
||||
"resolved": "https://registry.npmjs.org/cookie/-/cookie-0.4.1.tgz",
|
||||
"integrity": "sha512-ZwrFkGJxUR3EIoXtO+yVE69Eb7KlixbaeAWfBQB9vVsNn/o+Yw69gBWSSDK825hQNdN+wF8zELf3dFNl/kxkUA=="
|
||||
},
|
||||
"debug": {
|
||||
"version": "4.3.2",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.2.tgz",
|
||||
"integrity": "sha512-mOp8wKcvj7XxC78zLgw/ZA+6TSgkoE2C/ienthhRD298T7UNwAg9diBpLRxC0mOezLl4B0xV7M0cCO6P/O0Xhw==",
|
||||
"requires": {
|
||||
"ms": "2.1.2"
|
||||
}
|
||||
},
|
||||
"ms": {
|
||||
"version": "2.1.2",
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
|
||||
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
|
||||
}
|
||||
}
|
||||
},
|
||||
"engine.io-parser": {
|
||||
"version": "5.0.2",
|
||||
"resolved": "https://registry.npmjs.org/engine.io-parser/-/engine.io-parser-5.0.2.tgz",
|
||||
"integrity": "sha512-wuiO7qO/OEkPJSFueuATIXtrxF7/6GTbAO9QLv7nnbjwZ5tYhLm9zxvLwxstRs0dcT0KUlWTjtIOs1T86jt12g==",
|
||||
"requires": {
|
||||
"base64-arraybuffer": "~1.0.1"
|
||||
}
|
||||
},
|
||||
"enquirer": {
|
||||
"version": "2.3.6",
|
||||
"resolved": "https://registry.npmjs.org/enquirer/-/enquirer-2.3.6.tgz",
|
||||
@ -10041,6 +10309,64 @@
|
||||
"resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.4.tgz",
|
||||
"integrity": "sha512-rqYhcAnZ6d/vTPGghdrw7iumdcbXpsk1b8IG/rz+VWV51DM0p7XCtMoJ3qhPLIbp3tvyt3pKRbaaEMZYpHto8Q=="
|
||||
},
|
||||
"socket.io": {
|
||||
"version": "4.3.2",
|
||||
"resolved": "https://registry.npmjs.org/socket.io/-/socket.io-4.3.2.tgz",
|
||||
"integrity": "sha512-6S5tV4jcY6dbZ/lLzD6EkvNWI3s81JO6ABP/EpvOlK1NPOcIj3AS4khi6xXw6JlZCASq82HQV4SapfmVMMl2dg==",
|
||||
"requires": {
|
||||
"accepts": "~1.3.4",
|
||||
"base64id": "~2.0.0",
|
||||
"debug": "~4.3.2",
|
||||
"engine.io": "~6.0.0",
|
||||
"socket.io-adapter": "~2.3.2",
|
||||
"socket.io-parser": "~4.0.4"
|
||||
},
|
||||
"dependencies": {
|
||||
"debug": {
|
||||
"version": "4.3.2",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.2.tgz",
|
||||
"integrity": "sha512-mOp8wKcvj7XxC78zLgw/ZA+6TSgkoE2C/ienthhRD298T7UNwAg9diBpLRxC0mOezLl4B0xV7M0cCO6P/O0Xhw==",
|
||||
"requires": {
|
||||
"ms": "2.1.2"
|
||||
}
|
||||
},
|
||||
"ms": {
|
||||
"version": "2.1.2",
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
|
||||
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
|
||||
}
|
||||
}
|
||||
},
|
||||
"socket.io-adapter": {
|
||||
"version": "2.3.3",
|
||||
"resolved": "https://registry.npmjs.org/socket.io-adapter/-/socket.io-adapter-2.3.3.tgz",
|
||||
"integrity": "sha512-Qd/iwn3VskrpNO60BeRyCyr8ZWw9CPZyitW4AQwmRZ8zCiyDiL+znRnWX6tDHXnWn1sJrM1+b6Mn6wEDJJ4aYQ=="
|
||||
},
|
||||
"socket.io-parser": {
|
||||
"version": "4.0.4",
|
||||
"resolved": "https://registry.npmjs.org/socket.io-parser/-/socket.io-parser-4.0.4.tgz",
|
||||
"integrity": "sha512-t+b0SS+IxG7Rxzda2EVvyBZbvFPBCjJoyHuE0P//7OAsN23GItzDRdWa6ALxZI/8R5ygK7jAR6t028/z+7295g==",
|
||||
"requires": {
|
||||
"@types/component-emitter": "^1.2.10",
|
||||
"component-emitter": "~1.3.0",
|
||||
"debug": "~4.3.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"debug": {
|
||||
"version": "4.3.2",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.2.tgz",
|
||||
"integrity": "sha512-mOp8wKcvj7XxC78zLgw/ZA+6TSgkoE2C/ienthhRD298T7UNwAg9diBpLRxC0mOezLl4B0xV7M0cCO6P/O0Xhw==",
|
||||
"requires": {
|
||||
"ms": "2.1.2"
|
||||
}
|
||||
},
|
||||
"ms": {
|
||||
"version": "2.1.2",
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
|
||||
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
|
||||
}
|
||||
}
|
||||
},
|
||||
"sshpk": {
|
||||
"version": "1.16.1",
|
||||
"resolved": "https://registry.npmjs.org/sshpk/-/sshpk-1.16.1.tgz",
|
||||
@ -10500,6 +10826,12 @@
|
||||
"typedarray-to-buffer": "^3.1.5"
|
||||
}
|
||||
},
|
||||
"ws": {
|
||||
"version": "8.2.3",
|
||||
"resolved": "https://registry.npmjs.org/ws/-/ws-8.2.3.tgz",
|
||||
"integrity": "sha512-wBuoj1BDpC6ZQ1B7DWQBYVLphPWkm8i9Y0/3YdHjHKHiohOJ1ws+3OccDWtH+PoC9DZD5WOTrJvNbWvjS6JWaA==",
|
||||
"requires": {}
|
||||
},
|
||||
"xdg-basedir": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/xdg-basedir/-/xdg-basedir-4.0.0.tgz",
|
||||
|
@ -63,7 +63,7 @@
|
||||
"express": "^4.17.1",
|
||||
"express-fileupload": "^1.2.1",
|
||||
"express-prettify": "^0.1.1",
|
||||
"express-rate-limit": "^5.2.3",
|
||||
"express-rate-limit": "^5.5.1",
|
||||
"googleapis": "^91.0.0",
|
||||
"inquirer": "^8.1.5",
|
||||
"js-yaml": "^4.1.0",
|
||||
@ -74,6 +74,7 @@
|
||||
"ora": "^6.0.1",
|
||||
"properties-to-json": "^0.2.1",
|
||||
"request-ip": "^2.1.3",
|
||||
"socket.io": "^4.3.2",
|
||||
"telegraf": "^4.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
@ -1,7 +1,7 @@
|
||||
const { join, resolve } = require("path");
|
||||
const fs = require("fs");
|
||||
const AdmZip = require("adm-zip");
|
||||
const { GetServerPaths, GetPaths, bds_dir } = require("../lib/BdsSettings");
|
||||
const { GetServerPaths, GetPaths, bds_dir } = require("../src/lib/BdsSettings");
|
||||
|
||||
function Backup() {
|
||||
const zip = new AdmZip();
|
||||
|
@ -1,23 +1,20 @@
|
||||
const child_process = require("child_process");
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const randomUUID = require("uuid").v4;
|
||||
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 { randomUUID } = require("crypto");
|
||||
const { Backup } = require("./BdsBackup");
|
||||
const { CronJob } = require("cron");
|
||||
const BdsSettings = require("../src/lib/BdsSettings");
|
||||
|
||||
// Set bdsexec functions
|
||||
global.BdsExecs = {};
|
||||
const ServerSessions = {};
|
||||
module.exports.GetSessions = () => ServerSessions;
|
||||
|
||||
function start() {
|
||||
if (BdsDetect()) throw new Error("You already have a server running");
|
||||
const CurrentBdsPlatform = GetPlatform();
|
||||
module.exports.StartServer = function start() {
|
||||
const commandExists = require("../src/lib/commandExist");
|
||||
const io = require("./api").SocketIO;
|
||||
const CurrentBdsPlatform = BdsSettings.GetPlatform();
|
||||
const SetupCommands = {
|
||||
RunInCroot: false,
|
||||
command: String,
|
||||
args: [],
|
||||
cwd: String,
|
||||
@ -34,17 +31,17 @@ function start() {
|
||||
// Windows Platform
|
||||
else if (process.platform === "win32") {
|
||||
SetupCommands.command = "bedrock_server.exe";
|
||||
SetupCommands.cwd = GetServerPaths("bedrock")
|
||||
SetupCommands.cwd = BdsSettings.GetServerPaths("bedrock")
|
||||
}
|
||||
|
||||
// Linux Platform
|
||||
else if (process.platform === "linux"){
|
||||
// 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
|
||||
SetupCommands.cwd = GetServerPaths("bedrock");
|
||||
SetupCommands.env.LD_LIBRARY_PATH = GetServerPaths("bedrock");
|
||||
SetupCommands.cwd = BdsSettings.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
|
||||
if (process.arch !== "x64") {
|
||||
@ -57,30 +54,30 @@ function start() {
|
||||
|
||||
// Minecraft Java Oficial
|
||||
else if (CurrentBdsPlatform === "java") {
|
||||
const JavaConfig = GetServerSettings("java")
|
||||
const JavaConfig = BdsSettings.GetServerSettings("java")
|
||||
|
||||
// Checking if java is installed on the device
|
||||
if (commandExists("java")) {
|
||||
SetupCommands.cwd = GetServerPaths("java");
|
||||
SetupCommands.cwd = BdsSettings.GetServerPaths("java");
|
||||
SetupCommands.command = "java";
|
||||
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
|
||||
else if (CurrentBdsPlatform === "spigot") {
|
||||
const JavaConfig = GetServerSettings("java")
|
||||
const JavaConfig = BdsSettings.GetServerSettings("java")
|
||||
// Checking if java is installed on the device
|
||||
if (commandExists("java")) {
|
||||
SetupCommands.cwd = GetServerPaths("spigot");
|
||||
SetupCommands.cwd = BdsSettings.GetServerPaths("spigot");
|
||||
SetupCommands.command = "java";
|
||||
SetupCommands.args.push("-jar", `-Xms${JavaConfig.ram_mb}M`, `-Xmx${JavaConfig.ram_mb}M`, "spigot.jar", "nogui");
|
||||
} else {require("open")(bds.package_json.docs_base + "Java-Download#windows"); throw new Error(`Open: ${bds.package_json.docs_base + "Java-Download#windows"}`)}
|
||||
} else throw new Error("Install Java");
|
||||
}
|
||||
|
||||
// Dragonfly
|
||||
else if (CurrentBdsPlatform === "dragonfly") {
|
||||
SetupCommands.cwd = GetServerPaths("dragonfly");
|
||||
SetupCommands.cwd = BdsSettings.GetServerPaths("dragonfly");
|
||||
if (process.platform === "win32") {
|
||||
SetupCommands.command = "Dragonfly.exe";
|
||||
} else {
|
||||
@ -92,24 +89,27 @@ function start() {
|
||||
// Minecraft Bedrock (Pocketmine-MP)
|
||||
else if (CurrentBdsPlatform === "pocketmine") {
|
||||
// Start PocketMine-MP
|
||||
SetupCommands.command = path.join(path.resolve(GetServerPaths("pocketmine"), "bin", "php7", "bin"), "php");
|
||||
if (process.platform === "win32") SetupCommands.command = path.join(path.resolve(GetServerPaths("pocketmine"), "bin/php"), "php.exe");
|
||||
SetupCommands.command = path.join(path.resolve(BdsSettings.GetServerPaths("pocketmine"), "bin", "php7", "bin"), "php");
|
||||
if (process.platform === "win32") SetupCommands.command = path.join(path.resolve(BdsSettings.GetServerPaths("pocketmine"), "bin/php"), "php.exe");
|
||||
SetupCommands.args.push("./PocketMine-MP.phar");
|
||||
SetupCommands.cwd = GetServerPaths("pocketmine");
|
||||
SetupCommands.cwd = BdsSettings.GetServerPaths("pocketmine");
|
||||
}
|
||||
|
||||
// Show Error platform
|
||||
else throw Error("Bds Config Error")
|
||||
|
||||
// Setup commands
|
||||
const ServerExec = child_process.execFile(SetupCommands.command, SetupCommands.args, {
|
||||
cwd: SetupCommands.cwd,
|
||||
let __ServerExec = child_process.exec("exit 0");
|
||||
if (SetupCommands.RunInCroot) throw new Error("RunInCroot is not supported yet");
|
||||
else __ServerExec = child_process.execFile(SetupCommands.command, SetupCommands.args, {
|
||||
cwd: SetupCommands.cwd,
|
||||
env: SetupCommands.env
|
||||
});
|
||||
const ServerExec = __ServerExec;
|
||||
|
||||
// Log file
|
||||
const LogFile = path.join(GetPaths("log"), `${GetPlatform()}_${new Date().toString().replace(/:|\(|\)/g, "_")}_Bds_log.log`);
|
||||
const LatestLog_Path = path.join(GetPaths("log"), "latest.log");
|
||||
const LogFile = path.join(BdsSettings.GetPaths("log"), `${BdsSettings.GetPlatform()}_${new Date().toString().replace(/:|\(|\)/g, "_")}_Bds_log.log`);
|
||||
const LatestLog_Path = path.join(BdsSettings.GetPaths("log"), "latest.log");
|
||||
const LogSaveFunction = data => {
|
||||
fs.appendFileSync(LogFile, data);
|
||||
fs.appendFileSync(LatestLog_Path, data);
|
||||
@ -285,18 +285,49 @@ function start() {
|
||||
// Uptime Server
|
||||
const OnStop = setInterval(() => returnFuntion.uptime = (new Date().getTime() - returnFuntion.StartTime.getTime()) / 1000, 1000);
|
||||
ServerExec.on("exit", () => {
|
||||
delete global.BdsExecs[returnFuntion.uuid]
|
||||
delete ServerSessions[returnFuntion.uuid]
|
||||
clearInterval(OnStop);
|
||||
});
|
||||
|
||||
// Socket.io
|
||||
io.on("connection", (socket) => {
|
||||
socket.on("ServerCommand", (data = "") => {
|
||||
if (typeof data === "string") return returnFuntion.command(data);
|
||||
else if (typeof data === "object") {
|
||||
if (typeof data.uuid === "string") {
|
||||
if (data.uuid === returnFuntion.uuid) return returnFuntion.command(data.command);
|
||||
}
|
||||
}
|
||||
return;
|
||||
});
|
||||
ServerExec.on("exit", code => socket.emit("ServerExit", {
|
||||
UUID: returnFuntion.uuid,
|
||||
exitCode: code
|
||||
}));
|
||||
ServerExec.stdout.on("data", (data = "") => {
|
||||
socket.emit("ServerLog", {
|
||||
UUID: returnFuntion.uuid,
|
||||
data: data,
|
||||
IsStderr: false
|
||||
});
|
||||
});
|
||||
ServerExec.stderr.on("data", (data = "") => {
|
||||
socket.emit("ServerLog", {
|
||||
UUID: returnFuntion.uuid,
|
||||
data: data,
|
||||
IsStderr: true
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// Return
|
||||
global.BdsExecs[returnFuntion.uuid] = returnFuntion;
|
||||
ServerSessions[returnFuntion.uuid] = returnFuntion;
|
||||
module.exports.BdsRun = returnFuntion;
|
||||
return returnFuntion;
|
||||
}
|
||||
|
||||
function Player_Json(data = "aaaaaa\n\n\naa", callback = () => {}){
|
||||
const Current_platorm = GetPlatform();
|
||||
function Player_Json(data = "", callback = () => {}){
|
||||
const Current_platorm = BdsSettings.GetPlatform();
|
||||
// Bedrock
|
||||
if (Current_platorm === "bedrock") {
|
||||
// "[INFO] Player connected: Sirherobrine, xuid: 2535413418839840",
|
||||
@ -352,8 +383,8 @@ function Player_Json(data = "aaaaaa\n\n\naa", callback = () => {}){
|
||||
}
|
||||
|
||||
const UpdateUserJSON = function (New_Object = []){
|
||||
const Player_Json_path = GetPaths("player");
|
||||
const Current_platorm = GetPlatform();
|
||||
const Player_Json_path = BdsSettings.GetPaths("player");
|
||||
const Current_platorm = BdsSettings.GetPlatform();
|
||||
let Players_Json = {
|
||||
bedrock: [],
|
||||
java: [],
|
||||
@ -370,8 +401,8 @@ const UpdateUserJSON = function (New_Object = []){
|
||||
}
|
||||
|
||||
// Search player in JSON
|
||||
function Player_Search(player = "dontSteve") {
|
||||
const Player_Json_path = GetPaths("player"), Current_platorm = GetPlatform();
|
||||
module.exports.Player_Search = function Player_Search(player = "dontSteve") {
|
||||
const Player_Json_path = BdsSettings.GetPaths("player"), Current_platorm = BdsSettings.GetPlatform();
|
||||
const Players_Json = JSON.parse(fs.readFileSync(Player_Json_path, "utf8"))[Current_platorm]
|
||||
for (let Player of Players_Json) {
|
||||
if (Player.Player === player.trim()) return Player;
|
||||
@ -379,42 +410,19 @@ function Player_Search(player = "dontSteve") {
|
||||
return {};
|
||||
}
|
||||
|
||||
function GetSessions(){
|
||||
const ArraySessions = Object.getOwnPropertyNames(global.BdsExecs)
|
||||
module.exports.GetFistSession = function GetFistSession(){
|
||||
const ArraySessions = Object.getOwnPropertyNames(ServerSessions)
|
||||
if (ArraySessions.length === 0) throw "Start Server";
|
||||
if (ArraySessions.length >= 2) throw "Select a session manually:" + ArraySessions.join(", ")
|
||||
return global.BdsExecs[0]
|
||||
return ServerSessions[0]
|
||||
}
|
||||
|
||||
function BdsCommand(command = "list", SessionID = null) {
|
||||
if (!(command)) return false;
|
||||
try {
|
||||
var Session = {}
|
||||
if (!(SessionID)) Session = GetSessions(); else Session = global.BdsExecs[SessionID]
|
||||
Session.command(command);
|
||||
return true
|
||||
} catch (error) {
|
||||
return false
|
||||
module.exports.CronBackups = BdsSettings.GetCronBackup().map(Crron => {
|
||||
const Cloud_Backup = {
|
||||
Azure: require("./clouds/Azure").Uploadbackups,
|
||||
Driver: require("./clouds/GoogleDriver").Uploadbackups,
|
||||
Oracle: require("./clouds/OracleCI").Uploadbackups,
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
CronFunction: new CronJob(Crron.cron, async () => {
|
||||
console.log("Starting Server and World Backup");
|
||||
@ -432,13 +440,4 @@ const CurrentBackups = GetCronBackup().map(Crron => {
|
||||
else console.info("Oracle Bucket Backup Disabled");
|
||||
})
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = {
|
||||
start,
|
||||
BdsCommand,
|
||||
stop,
|
||||
GetSessions,
|
||||
CronBackups: CurrentBackups,
|
||||
Player_Search,
|
||||
}
|
||||
});
|
@ -1,5 +1,5 @@
|
||||
// External User ip
|
||||
const Request = require("../lib/Requests");
|
||||
const Request = require("../src/lib/Requests");
|
||||
const os = require("os");
|
||||
|
||||
function LocalInterfaces() {
|
||||
@ -19,7 +19,7 @@ function LocalInterfaces() {
|
||||
netmask: "",
|
||||
cidr: ""
|
||||
},
|
||||
}
|
||||
};
|
||||
for (let iface of interfaces[name]) {
|
||||
if (!Inter.mac && iface.mac) Inter.mac = iface.mac;
|
||||
if (iface.family === "IPv4") {
|
||||
|
@ -3,10 +3,10 @@ const path = require("path");
|
||||
const { writeFileSync, existsSync, readFileSync, readdirSync, rmSync } = fs;
|
||||
const { join, resolve } = path;
|
||||
var AdmZip = require("adm-zip");
|
||||
const { GetServerPaths, GetPlatform } = require("../lib/BdsSettings");
|
||||
const { GetServerPaths, GetPlatform } = require("../src/lib/BdsSettings");
|
||||
const Extra = require("../BdsManegerInfo.json");
|
||||
const bds = require("../index");
|
||||
const Request = require("../lib/Requests");
|
||||
const Request = require("../src/lib/Requests");
|
||||
|
||||
// Get Platform Object Versions
|
||||
async function PlatformVersionsV2(SelectPlatform = "") {
|
||||
@ -53,7 +53,7 @@ async function php_download() {
|
||||
// Check Php Binary
|
||||
let urlPHPBin = PHPBin[process.platform]
|
||||
if (!(urlPHPBin)) throw new Error("unsupported system")
|
||||
urlPHPBin = urlPHPBin[bds.arch];
|
||||
urlPHPBin = urlPHPBin[bds.BdsSystemInfo.arch];
|
||||
if (!(urlPHPBin)) throw new Error("unsupported arch")
|
||||
|
||||
// Remove Old php Binary if it exists
|
||||
@ -85,26 +85,30 @@ async function php_download() {
|
||||
// New Download Method
|
||||
async function BdsDownloadV2(version = "latest") {
|
||||
const CurrentPlatform = GetPlatform();
|
||||
const { valid_platform, require_qemu } = await (require("../lib/BdsSystemInfo")).CheckSystemAsync();
|
||||
const LocalServersVersions = bds.BdsSettigs.GetServerVersion();
|
||||
const { ServersPaths } = bds.BdsSettigs;
|
||||
const { valid_platform, require_qemu } = await (require("../src/lib/BdsSystemInfo")).CheckSystemAsync();
|
||||
const LocalServersVersions = bds.BdsSettings.GetServerVersion();
|
||||
const { ServersPaths } = bds.BdsSettings;
|
||||
|
||||
const ReturnObject = {
|
||||
version,
|
||||
version: version,
|
||||
platform: CurrentPlatform,
|
||||
url: "",
|
||||
data: new Date(),
|
||||
skip: false
|
||||
}
|
||||
};
|
||||
|
||||
// Bedrock
|
||||
if (CurrentPlatform === "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 (LocalServersVersions.bedrock !== version) {
|
||||
// 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;
|
||||
|
||||
// Download and Add buffer to AdmZip
|
||||
@ -115,7 +119,7 @@ async function BdsDownloadV2(version = "latest") {
|
||||
proprieties: "",
|
||||
whitelist: "",
|
||||
permissions: "",
|
||||
}
|
||||
};
|
||||
|
||||
// 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");
|
||||
@ -131,7 +135,7 @@ async function BdsDownloadV2(version = "latest") {
|
||||
if (BedrockConfigFiles.permissions) fs.writeFileSync(path.join(ServersPaths.bedrock, "permissions.json"), BedrockConfigFiles.permissions, "utf8");
|
||||
|
||||
// Update Server Version
|
||||
bds.BdsSettigs.UpdateServerVersion(version, CurrentPlatform);
|
||||
bds.BdsSettings.UpdateServerVersion(version, CurrentPlatform);
|
||||
} else {
|
||||
ReturnObject.skip = true;
|
||||
}
|
||||
@ -197,7 +201,7 @@ async function BdsDownloadV2(version = "latest") {
|
||||
if (valid_platform.dragonfly) {
|
||||
if (LocalServersVersions.dragonfly !== version) {
|
||||
// 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;
|
||||
|
||||
// Download
|
||||
|
@ -1,6 +1,6 @@
|
||||
const bds = require("../index")
|
||||
const { CheckBan } = require("./UsersAndtokenChecks");
|
||||
const { GetPlatform, GetPaths } = require("../lib/BdsSettings");
|
||||
const { GetPlatform, GetPaths } = require("../src/lib/BdsSettings");
|
||||
const fs = require("fs");
|
||||
|
||||
function MytypeKill(player) {
|
||||
|
@ -1,8 +1,8 @@
|
||||
var fs = require("fs");
|
||||
const path = require("path");
|
||||
const propertiesToJSON = require("properties-to-json");
|
||||
const BdsInfo = require("../lib/BdsSystemInfo");
|
||||
const { GetServerPaths, GetPlatform } = require("../lib/BdsSettings");
|
||||
const BdsInfo = require("../src/lib/BdsSystemInfo");
|
||||
const { GetServerPaths, GetPlatform } = require("../src/lib/BdsSettings");
|
||||
const TOML = require("@iarna/toml");
|
||||
|
||||
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 { join } = require("path")
|
||||
|
||||
|
171
src/api.js
171
src/api.js
@ -1,33 +1,51 @@
|
||||
// Node Modules
|
||||
const os = require("os");
|
||||
const fs = require("fs");
|
||||
|
||||
const path = require("path");
|
||||
const { randomUUID } = require("crypto")
|
||||
// Bds Maneger Core
|
||||
const BdsManegerCore = require("../index");
|
||||
const BdsSystemInfo = require("../lib/BdsSystemInfo");
|
||||
const BdsSystemInfo = require("../src/lib/BdsSystemInfo");
|
||||
const BdsChecks = require("./UsersAndtokenChecks");
|
||||
const BdsSettings = require("../lib/BdsSettings");
|
||||
const BdsSettings = require("../src/lib/BdsSettings");
|
||||
|
||||
// Init Express
|
||||
const express = require("express");
|
||||
const app = express();
|
||||
|
||||
// Express Middleware
|
||||
const rateLimit = require("express-rate-limit");
|
||||
const bodyParser = require("body-parser");
|
||||
const fileUpload = require("express-fileupload");
|
||||
const pretty = require("express-prettify");
|
||||
const cors = require("cors");
|
||||
const express_rate_limit = require("express-rate-limit");
|
||||
app.use(cors());
|
||||
app.use(bodyParser.json()); /* https://github.com/github/fetch/issues/323#issuecomment-331477498 */
|
||||
app.use(bodyParser.urlencoded({ extended: true }));
|
||||
app.use(rateLimit({windowMs: 15 * 60 * 1000, /* 15 minutes */ max: 100 /* limit each IP to 100 requests per windowMs*/ }));
|
||||
app.use(pretty({always: true, spaces: 2}));
|
||||
app.use(fileUpload({limits: { fileSize: 512 * 1024 }}));
|
||||
app.use(require("request-ip").mw());
|
||||
app.use(express_rate_limit({
|
||||
windowMs: 1 * 60 * 1000, // 1 minutes
|
||||
max: 500 // limit each IP to 500 requests per windowMs
|
||||
}));
|
||||
|
||||
// Init Socket.io
|
||||
const Server = require("http").createServer(app);
|
||||
const SocketIo = require("socket.io");
|
||||
const io = new SocketIo.Server(Server);
|
||||
io.use(function (socket, next) {
|
||||
if (socket.handshake.query.token) {
|
||||
if (BdsChecks.token_verify(socket.handshake.query.token)) {
|
||||
socket.token = socket.handshake.query.token;
|
||||
next();
|
||||
}
|
||||
}
|
||||
return next(new Error("Token is not valid"));
|
||||
});
|
||||
module.exports.SocketIO = io;
|
||||
|
||||
// Routes
|
||||
|
||||
app.all(["/v2", "/v2/*"], ({res}) => res.status(401).json({
|
||||
Error: "v2 route moved to root routes"
|
||||
}));
|
||||
@ -35,14 +53,14 @@ app.all(["/v2", "/v2/*"], ({res}) => res.status(401).json({
|
||||
// ? /bds/
|
||||
app.get(["/bds/info", "/bds", "/"], ({res}) => {
|
||||
try {
|
||||
const BdsConfig = BdsManegerCore.getBdsConfig();
|
||||
const Players = JSON.parse(fs.readFileSync(BdsManegerCore.BdsSettigs.GetPaths("player"), "utf8"))[BdsSettings.GetPlatform()];
|
||||
const BdsConfig = BdsManegerCore.BdsSettings.GetJsonConfig();
|
||||
const Players = JSON.parse(fs.readFileSync(BdsManegerCore.BdsSettings.GetPaths("player"), "utf8"))[BdsSettings.GetPlatform()];
|
||||
const Offline = Players.filter(player => player.Action === "disconnect").filter((thing, index, self) => index === self.findIndex((t) => (t.place === thing.place && t.Player === thing.Player)));
|
||||
const Online = Players.filter(player => player.Action === "connect").filter((thing, index, self) => index === self.findIndex((t) => (t.place === thing.place && t.Player === thing.Player && Offline.findIndex((t) => (t.place === thing.place && t.Player === thing.Player)) === -1)))
|
||||
const Info = {
|
||||
core: {
|
||||
version: BdsManegerCore.package_json.version,
|
||||
Total_dependencies: Object.keys(BdsManegerCore.package_json.dependencies).length + Object.keys(BdsManegerCore.package_json.devDependencies).length,
|
||||
version: BdsManegerCore.version,
|
||||
Total_dependencies: Object.keys(BdsManegerCore.ExtraJSON.Package.dependencies).length + Object.keys(BdsManegerCore.ExtraJSON.Package.devDependencies).length,
|
||||
},
|
||||
server: {
|
||||
version: BdsConfig.server.versions[BdsSettings.GetPlatform()],
|
||||
@ -57,14 +75,17 @@ app.get(["/bds/info", "/bds", "/"], ({res}) => {
|
||||
Arch: BdsManegerCore.arch,
|
||||
Kernel: BdsSystemInfo.GetKernel(),
|
||||
Cpu_Model: (os.cpus()[0] || {}).model || null,
|
||||
IsDocker: false,
|
||||
IsNpx: false,
|
||||
IsCLI: false,
|
||||
Cores: os.cpus().length
|
||||
},
|
||||
Backend: {
|
||||
npx: false,
|
||||
Docker: false,
|
||||
CLI: false,
|
||||
}
|
||||
}
|
||||
if (process.env.BDS_DOCKER_IMAGE) Info.host.IsDocker = true;
|
||||
if (process.env.npm_lifecycle_event === "npx") Info.host.IsNpx = true;
|
||||
if (process.env.IS_BDS_CLI) Info.host.IsCLI = true;
|
||||
if (process.env.BDS_DOCKER_IMAGE) Info.Backend.Docker = true;
|
||||
if (process.env.npm_lifecycle_event === "npx") Info.Backend.npx = true;
|
||||
if (process.env.IS_BDS_CLI) Info.Backend.CLI = true;
|
||||
res.json(Info);
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
@ -79,8 +100,8 @@ app.get("/bds/info/server", ({res}) => {
|
||||
let ServerRunner = require("./BdsManegerServer").BdsRun;
|
||||
if (!ServerRunner)ServerRunner = {};
|
||||
try {
|
||||
const BdsConfig = BdsManegerCore.getBdsConfig();
|
||||
const Players = JSON.parse(fs.readFileSync(BdsManegerCore.BdsSettigs.GetPaths("player"), "utf8"))[BdsSettings.GetPlatform()];
|
||||
const BdsConfig = BdsManegerCore.BdsSettings.GetJsonConfig();
|
||||
const Players = JSON.parse(fs.readFileSync(BdsManegerCore.BdsSettings.GetPaths("player"), "utf8"))[BdsSettings.GetPlatform()];
|
||||
const Offline = Players.filter(player => player.Action === "disconnect").filter((thing, index, self) => index === self.findIndex((t) => (t.place === thing.place && t.Player === thing.Player)));
|
||||
const Online = Players.filter(player => player.Action === "connect").filter((thing, index, self) => index === self.findIndex((t) => (t.place === thing.place && t.Player === thing.Player && Offline.findIndex((t) => (t.place === thing.place && t.Player === thing.Player)) === -1)))
|
||||
const Info = {
|
||||
@ -90,7 +111,7 @@ app.get("/bds/info/server", ({res}) => {
|
||||
online: Online.length,
|
||||
offline: Offline.length,
|
||||
},
|
||||
Config: BdsManegerCore.get_config(),
|
||||
Config: BdsManegerCore.BdsSettings.GetJsonConfig(),
|
||||
Process: {
|
||||
PID: ServerRunner.pid || 0,
|
||||
Uptime: ServerRunner.uptime || 0,
|
||||
@ -106,9 +127,62 @@ app.get("/bds/info/server", ({res}) => {
|
||||
}
|
||||
});
|
||||
|
||||
// Check Token
|
||||
// app.all("*", (req, res, next) => {
|
||||
// if (req.method === "GET") {
|
||||
// if (req.query.token) {
|
||||
// if (BdsChecks.token_verify(req.query.token)) {
|
||||
// req.token = req.query.token;
|
||||
// return next();
|
||||
// }
|
||||
// } else if (req.headers.token) {
|
||||
// if (BdsChecks.token_verify(req.headers.token)) {
|
||||
// req.token = req.headers.token;
|
||||
// return next();
|
||||
// }
|
||||
// } else if (req.query.Token) {
|
||||
// if (BdsChecks.token_verify(req.query.Token)) {
|
||||
// req.token = req.query.Token;
|
||||
// return next();
|
||||
// }
|
||||
// } else if (req.headers.Token) {
|
||||
// if (BdsChecks.token_verify(req.headers.Token)) {
|
||||
// req.token = req.headers.token;
|
||||
// return next();
|
||||
// }
|
||||
// }
|
||||
// } else {
|
||||
// if (req.body.token) {
|
||||
// if (BdsChecks.token_verify(req.body.token)) {
|
||||
// req.token = req.body.token;
|
||||
// return next();
|
||||
// }
|
||||
// } else if (req.headers.token) {
|
||||
// if (BdsChecks.token_verify(req.headers.token)) {
|
||||
// req.token = req.headers.token;
|
||||
// return next();
|
||||
// }
|
||||
// } else if (req.body.Token) {
|
||||
// if (BdsChecks.token_verify(req.body.Token)) {
|
||||
// req.token = req.body.Token;
|
||||
// return next();
|
||||
// }
|
||||
// } else if (req.headers.Token) {
|
||||
// if (BdsChecks.token_verify(req.headers.Token)) {
|
||||
// req.token = req.headers.Token;
|
||||
// return next();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return res.status(401).json({
|
||||
// error: "Unauthorized",
|
||||
// message: "Token is not valid"
|
||||
// });
|
||||
// });
|
||||
|
||||
// Whitelist
|
||||
app.get("/bds/info/server/whitelist", (req, res) => {
|
||||
const ServerConfig = BdsManegerCore.get_config();
|
||||
const ServerConfig = BdsManegerCore.BdsSettings.GetJsonConfig();
|
||||
if (ServerConfig.whitelist) {
|
||||
const { Token = null , Action = null } = req.query;
|
||||
const WgiteList = BdsSettings.get_whitelist();
|
||||
@ -119,7 +193,7 @@ app.get("/bds/info/server/whitelist", (req, res) => {
|
||||
Token: Token,
|
||||
Time: Date.now()
|
||||
});
|
||||
fs.writeFileSync(BdsManegerCore.BdsSettigs.GetPaths("whitelist"), JSON.stringify(WgiteList));
|
||||
fs.writeFileSync(BdsManegerCore.BdsSettings.GetPaths("whitelist"), JSON.stringify(WgiteList));
|
||||
res.json({
|
||||
success: true,
|
||||
message: "Whitelist Added"
|
||||
@ -133,7 +207,7 @@ app.get("/bds/info/server/whitelist", (req, res) => {
|
||||
} else if (Action === "remove") {
|
||||
if (WgiteList.findIndex(WL => WL.Token === Token) !== -1) {
|
||||
WgiteList.splice(WgiteList.findIndex(WL => WL.Token === Token), 1);
|
||||
fs.writeFileSync(BdsManegerCore.BdsSettigs.GetPaths("whitelist"), JSON.stringify(WgiteList));
|
||||
fs.writeFileSync(BdsManegerCore.BdsSettings.GetPaths("whitelist"), JSON.stringify(WgiteList));
|
||||
res.json({
|
||||
success: true,
|
||||
message: "Whitelist Removed"
|
||||
@ -259,7 +333,7 @@ app.post("/bds/save_settings", (req, res) => {
|
||||
// Bds Maneger Bridge Communication
|
||||
app.get("/bds/bridge", (req, res) => {
|
||||
const ServerHost = require("./BdsNetwork").host || req.headers.host.replace(/^(.*?):\d+$/, (match, p1) => p1) || require("./BdsNetwork").externalIP.ipv4;
|
||||
const ServerConfig = BdsManegerCore.get_config();
|
||||
const ServerConfig = BdsManegerCore.BdsSettings.GetJsonConfig();
|
||||
res.json({
|
||||
host: ServerHost,
|
||||
port: ServerConfig.portv4,
|
||||
@ -267,7 +341,7 @@ app.get("/bds/bridge", (req, res) => {
|
||||
});
|
||||
|
||||
// ? /player
|
||||
const GetPlayerJson = (Platform = BdsManegerCore.getBdsConfig().server.platform) => ([...{...JSON.parse(fs.readFileSync(BdsManegerCore.BdsSettigs.GetPaths("player"), "utf8"))}[Platform]]);
|
||||
const GetPlayerJson = (Platform = BdsManegerCore.BdsSettings.GetJsonConfig().server.platform) => ([...{...JSON.parse(fs.readFileSync(BdsManegerCore.BdsSettings.GetPaths("player"), "utf8"))}[Platform]]);
|
||||
app.get("/players", (req, res) => {
|
||||
const { Platform = BdsSettings.GetPlatform(), Player = null, Action = null } = req.query;
|
||||
let PlayerList = GetPlayerJson(Platform);
|
||||
@ -416,20 +490,51 @@ function API(port_api = 1932, callback = port => {console.log("Bds Maneger Core
|
||||
});
|
||||
});
|
||||
const port = (port_api || 1932);
|
||||
app.listen(port, () => {
|
||||
Server.listen(port, () => {
|
||||
if (typeof callback === "function") callback(port);
|
||||
});
|
||||
return port;
|
||||
}
|
||||
|
||||
function MainAPI(apiConfig = {api_port: 1932}, callback = function (port){console.log("Bds Maneger Core REST API, http port", port)}){
|
||||
var port_rest = 1932;
|
||||
if (typeof apiConfig === "object" && apiConfig.api_port !== undefined) port_rest = apiConfig.api_port;
|
||||
else if (typeof apiConfig === "number") port_rest = apiConfig;
|
||||
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;
|
||||
}
|
||||
|
||||
module.exports = MainAPI;
|
||||
module.exports.api = API;
|
||||
module.exports.BdsRoutes = app;
|
||||
// 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.api = API;
|
||||
module.exports.token_register = token_register;
|
||||
module.exports.delete_token = delete_token;
|
||||
module.exports.TokensFilePath = path_tokens;
|
||||
module.exports.BdsRoutes = {
|
||||
App: app,
|
||||
Server: Server
|
||||
};
|
@ -5,7 +5,7 @@ const express = require("express");
|
||||
const { google } = require("googleapis");
|
||||
|
||||
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");
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
const path = require("path");
|
||||
const { BlobServiceClient, StorageSharedKeyCredential } = require("@azure/storage-blob");
|
||||
const NewBdsSettings = require("../../lib/BdsSettings");
|
||||
const NewBdsSettings = require("../../src/lib/BdsSettings");
|
||||
|
||||
// Upload Function
|
||||
async function Uploadbackups(object = "Backup.zip", fileLocation = "Backup.zip", callback = function (){}) {
|
||||
|
@ -1,7 +1,7 @@
|
||||
const fs = require("fs");
|
||||
const { google } = require("googleapis");
|
||||
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){
|
||||
return new Promise(async function (resolve, reject){
|
||||
|
@ -2,7 +2,7 @@ const oci_storage = require("oci-objectstorage");
|
||||
const oci_common = require("oci-common");
|
||||
const fs = require("fs");
|
||||
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)}){
|
||||
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
|
||||
}
|
||||
}
|
114
src/lib/BdsSystemInfo.js
Normal file
114
src/lib/BdsSystemInfo.js
Normal file
@ -0,0 +1,114 @@
|
||||
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.SystemInfo = 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
|
||||
}
|
22
src/lib/commandExist.js
Normal file
22
src/lib/commandExist.js
Normal file
@ -0,0 +1,22 @@
|
||||
const child_process = require("child_process");
|
||||
function commdExist(command){
|
||||
if (process.platform === "linux" || process.platform === "darwin" || process.platform === "android") {
|
||||
try {
|
||||
child_process.execSync(`command -v ${command}`);
|
||||
return true
|
||||
} catch (error) {
|
||||
return false
|
||||
}
|
||||
} else if (process.platform === "win32") {
|
||||
try {
|
||||
child_process.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