Modifications #241
@ -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 = [];
|
||||
@ -50,7 +46,7 @@ fs.readdirSync(path.join(__dirname, "plugins")).map(file => path.resolve(__dirna
|
||||
|
||||
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",
|
||||
@ -59,7 +55,7 @@ async function DownloadServer() {
|
||||
})).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,23 @@ async function DownloadServer() {
|
||||
}
|
||||
|
||||
async function info() {
|
||||
const { valid_platform } = await (require("../lib/BdsSystemInfo"))();
|
||||
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: ${commandExits("qemu-x86_64-static")}\n`}
|
||||
if (process.platform === "android" && BdsCore.BdsSystemInfo.arch !== "x64"){checkothearch = `qemu-x86_64 is installed to emulate an x64 system: ${commandExits("qemu-x86_64")}\n`}
|
||||
const info = [
|
||||
`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 +89,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 +129,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,13 +152,19 @@ async function Runner() {
|
||||
// Download
|
||||
if (ProcessArgs.download || ProcessArgs.d) await DownloadServer();
|
||||
|
||||
|
||||
// Load Plugins
|
||||
for (let Plugin of BeforeRun) {
|
||||
if (!(ProcessArgs[Plugin.arg])) Plugin.main(ProcessArgs[Plugin.arg], ProcessArgs).catch(err => console.log("Plugin Crash:", "\n\n", err));
|
||||
}
|
||||
|
||||
// Start Server
|
||||
if (!(ProcessArgs.start || ProcessArgs.s)) return;
|
||||
|
||||
// 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);
|
||||
process.on("exit", async () => {
|
||||
await HostInfo.delete_host();
|
||||
@ -172,12 +175,7 @@ async function Runner() {
|
||||
}
|
||||
}
|
||||
|
||||
// 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();
|
||||
const BdsManegerServer = BdsCore.BdsManegerServer.StartServer();
|
||||
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}`));
|
||||
|
185
bin/Docker.js
185
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, bds_dir } = 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()}`);
|
||||
}
|
||||
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 StartServer(){
|
||||
ShowToken();
|
||||
console.log("The entire log can be accessed via the api and/or the docker log");
|
||||
const ServerStarted = BdsCore.BdsManegerServer.StartServer();
|
||||
ServerStarted.log(a => process.stdout.write(a));
|
||||
ServerStarted.exit(code => process.exit(code));
|
||||
BdsCore.BdsManegerAPI.api();
|
||||
if (process.env.PULL_REQUEST === "true") {
|
||||
console.log((require("cli-color")).red("Pull Request Actived 1 Min to exit"));
|
||||
setTimeout(() => {
|
||||
ServerStarted.stop();
|
||||
}, 1 * 60 * 1000)
|
||||
}
|
||||
}
|
||||
|
||||
async function RenderCLI(){
|
||||
// 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();
|
@ -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");
|
||||
|
@ -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
|
||||
}
|
@ -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,22 +1,19 @@
|
||||
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() {
|
||||
module.exports.StartServer = function start() {
|
||||
const commandExists = require("../src/lib/commandExist");
|
||||
const BdsDetect = require("./CheckKill").Detect;
|
||||
if (BdsDetect()) throw new Error("You already have a server running");
|
||||
const CurrentBdsPlatform = GetPlatform();
|
||||
const CurrentBdsPlatform = BdsSettings.GetPlatform();
|
||||
const SetupCommands = {
|
||||
command: String,
|
||||
args: [],
|
||||
@ -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 {require("open")(PackageJson.docs_base + "Java-Download#windows"); throw new Error(`Open: ${PackageJson.docs_base + "Java-Download#windows"}`)}
|
||||
}
|
||||
|
||||
// Dragonfly
|
||||
else if (CurrentBdsPlatform === "dragonfly") {
|
||||
SetupCommands.cwd = GetServerPaths("dragonfly");
|
||||
SetupCommands.cwd = BdsSettings.GetServerPaths("dragonfly");
|
||||
if (process.platform === "win32") {
|
||||
SetupCommands.command = "Dragonfly.exe";
|
||||
} else {
|
||||
@ -92,10 +89,10 @@ 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
|
||||
@ -108,8 +105,8 @@ function start() {
|
||||
});
|
||||
|
||||
// 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 +282,18 @@ 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);
|
||||
});
|
||||
|
||||
// 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 +349,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 +367,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 +376,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 +406,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")
|
||||
|
||||
|
45
src/api.js
45
src/api.js
@ -1,12 +1,13 @@
|
||||
// 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");
|
||||
@ -429,7 +430,43 @@ function MainAPI(apiConfig = {api_port: 1932}, callback = function (port){consol
|
||||
return API(port_rest, callback);
|
||||
}
|
||||
|
||||
// Bds Maneger Core API token Register
|
||||
const path_tokens = path.join(BdsSettings.bds_dir, "bds_tokens.json");
|
||||
function token_register(Admin_Scoper = ["web_admin", "admin"]) {
|
||||
Admin_Scoper = Array.from(Admin_Scoper).filter(scoper => /admin/.test(scoper));
|
||||
let tokens = [];
|
||||
if (fs.existsSync(path_tokens)) tokens = JSON.parse(fs.readFileSync(path_tokens, "utf8"));
|
||||
// Get UUID
|
||||
const getBdsUUId = randomUUID().split("-");
|
||||
const bdsuid = "bds_" + (getBdsUUId[0]+getBdsUUId[2].slice(0, 15));
|
||||
// Save BdsUUID
|
||||
tokens.push({
|
||||
token: bdsuid,
|
||||
date: new Date(),
|
||||
scopers: Admin_Scoper
|
||||
});
|
||||
fs.writeFileSync(path_tokens, JSON.stringify(tokens, null, 4), "utf8");
|
||||
return bdsuid;
|
||||
}
|
||||
|
||||
// Bds Maneger Core API Delet token
|
||||
function delete_token(Token = "") {
|
||||
if (!Token) return false;
|
||||
if (typeof Token !== "string") return false;
|
||||
let tokens = [];
|
||||
if (fs.existsSync(path_tokens)) tokens = JSON.parse(fs.readFileSync(path_tokens, "utf8"));
|
||||
if (tokens.filter(token => token.token === Token).length > 0) {
|
||||
fs.writeFileSync(path_tokens, JSON.stringify(tokens, null, 4), "utf8");
|
||||
return true;
|
||||
} else return false;
|
||||
}
|
||||
|
||||
// Check Exists Tokens Files
|
||||
if (!(fs.existsSync(path_tokens))) token_register();
|
||||
|
||||
module.exports = MainAPI;
|
||||
module.exports.api = API;
|
||||
module.exports.BdsRoutes = app;
|
||||
|
||||
module.exports.token_register = token_register;
|
||||
module.exports.delete_token = delete_token;
|
||||
module.exports.TokensFilePath = path_tokens;
|
@ -5,7 +5,7 @@ const express = require("express");
|
||||
const { google } = require("googleapis");
|
||||
|
||||
const 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
|
||||
}
|
||||
}
|
113
src/lib/BdsSystemInfo.js
Normal file
113
src/lib/BdsSystemInfo.js
Normal file
@ -0,0 +1,113 @@
|
||||
const { release } = require("os");
|
||||
const { readdirSync } = require("fs");
|
||||
const { execSync } = require("child_process");
|
||||
const commadExist = require("./commandExist");
|
||||
const Request = require("./Requests");
|
||||
const { PlatformVersionsV2 } = require("../BdsServersDownload");
|
||||
|
||||
// System Architect (x64, aarch64 and others)
|
||||
let arch;
|
||||
if (process.arch === "arm64") arch = "aarch64";
|
||||
else arch = process.arch
|
||||
|
||||
// Get System Basic Info
|
||||
async function CheckSystemAsync() {
|
||||
const
|
||||
PHPBin = await Request.JSON("https://raw.githubusercontent.com/The-Bds-Maneger/Php_Static_Binary/main/binarys.json"),
|
||||
Servers = {
|
||||
bedrock: await PlatformVersionsV2("bedrock"),
|
||||
spigot: await PlatformVersionsV2("spigot"),
|
||||
dragonfly: await PlatformVersionsV2("dragonfly"),
|
||||
}
|
||||
const BasicConfigJSON = {
|
||||
require_qemu: false,
|
||||
valid_platform: {
|
||||
bedrock: true,
|
||||
pocketmine: true,
|
||||
java: commadExist("java"),
|
||||
dragonfly: true
|
||||
}
|
||||
}
|
||||
|
||||
// check php bin
|
||||
if ((PHPBin[process.platform] || {})[arch]) BasicConfigJSON.valid_platform["pocketmine"] = true;
|
||||
else BasicConfigJSON.valid_platform["pocketmine"] = false;
|
||||
|
||||
// Check for Dragonfly
|
||||
if (!(Servers.dragonfly.versions[Servers.dragonfly.latest][process.platform][arch])) BasicConfigJSON.valid_platform["dragonfly"] = false;
|
||||
|
||||
// SoSystem X
|
||||
if (process.platform == "linux") {
|
||||
// Bedrock Check
|
||||
if (Servers.bedrock.versions[Servers.bedrock.latest][process.platform]) {
|
||||
if (Servers.bedrock.versions[Servers.bedrock.latest][process.platform][arch]) BasicConfigJSON.valid_platform["bedrock"] = true;
|
||||
else BasicConfigJSON.valid_platform["bedrock"] = false;
|
||||
} else BasicConfigJSON.valid_platform["bedrock"] = false;
|
||||
|
||||
if (BasicConfigJSON.valid_platform["bedrock"] === false) {
|
||||
if (commadExist("qemu-x86_64-static")) {
|
||||
// console.warn("The Minecraft Bedrock Server is only being validated because you can use 'qemu-x86_64-static'");;
|
||||
BasicConfigJSON.valid_platform["bedrock"] = true
|
||||
BasicConfigJSON.require_qemu = true;
|
||||
}
|
||||
}
|
||||
} else if (process.platform === "android") {
|
||||
if (BasicConfigJSON.valid_platform["bedrock"]) BasicConfigJSON.valid_platform["bedrock"] = false;
|
||||
}
|
||||
|
||||
return BasicConfigJSON;
|
||||
}
|
||||
|
||||
/**
|
||||
* Platforms valid from deferents systems
|
||||
*/
|
||||
function GetKernel() {
|
||||
if (process.platform === "win32") {
|
||||
const kernelVersion = parseFloat(release());
|
||||
if (kernelVersion <= 6.1) return "Windows 7";
|
||||
else if (kernelVersion <= 6.2) return "Windows 8";
|
||||
else if (kernelVersion <= 6.3) return "Windows 8.1";
|
||||
else if (kernelVersion <= 10.0) return "Windows 10 or Windows 11";
|
||||
else return "Other Windows";
|
||||
} else if (process.platform === "android") return `Android: ${release()}, CPU Core ${readdirSync("/sys/devices/system/cpu/").filter(data => /cpu[0-9]/.test(data)).length}`;
|
||||
else if (commadExist("uname")) {
|
||||
const str = execSync("uname -rv").toString("ascii");
|
||||
// Amazon web services
|
||||
if (/aws/.test(str)) {
|
||||
if (/arm64|aarch64/.test(process.arch)) return "Amazon AWS Cloud arm64: AWS Graviton Serie";
|
||||
else return `Amazon AWS Cloud ${process.arch}: ${require("os").cpus()[0].model}`;
|
||||
}
|
||||
|
||||
// Windows subsystem for Linux
|
||||
else if (/WSL2|microsft/.test(str)) return "Microsoft WSL";
|
||||
|
||||
// Azure Virtual Machinime (VM)
|
||||
else if (/[aA]zure/.test(str)) return "Microsoft Azure";
|
||||
|
||||
// Google Cloud Virtual Machinime (VM)
|
||||
else if (/[gG]cp/.test(str)) return "Google Cloud Platform";
|
||||
|
||||
// Oracle cloud Virtual Machinime (VM)
|
||||
else if (/[oO]racle/.test(str)) return "Oracle Cloud infrastructure";
|
||||
|
||||
// Darwin
|
||||
else if (/[dD]arwin/.test(str)) return "Apple MacOS";
|
||||
|
||||
// Others Kernels
|
||||
else return str.replace(/\n|\t|\r/gi, "");
|
||||
} else return "Not identified";
|
||||
}
|
||||
|
||||
// Get CPU Core Count
|
||||
function GetCpuCoreCount() {
|
||||
if (process.platform === "win32") return require("os").cpus().length;
|
||||
else if (process.platform === "android" || process.platform === "linux") return readdirSync("/sys/devices/system/cpu/").filter(data => /cpu[0-9]/.test(data)).length;
|
||||
else if (process.platform === "darwin") return require("os").cpus().length;
|
||||
else return 1;
|
||||
}
|
||||
|
||||
module.exports = CheckSystemAsync;
|
||||
module.exports.arch = arch
|
||||
module.exports.GetKernel = GetKernel;
|
||||
module.exports.CheckSystemAsync = CheckSystemAsync;
|
||||
module.exports.GetCpuCoreCount = GetCpuCoreCount;
|
40
src/lib/Requests.js
Normal file
40
src/lib/Requests.js
Normal file
@ -0,0 +1,40 @@
|
||||
if (typeof global.fetch !== "function") {
|
||||
global.fetch = (...args) => import("node-fetch").then(m => m.default(...args));
|
||||
import("node-fetch").then(m => global.fetch = m.default);
|
||||
}
|
||||
|
||||
async function BufferHTTP(url = "", args = {}) {
|
||||
const res = await fetch(url, {
|
||||
mode: "cors",
|
||||
...args
|
||||
});
|
||||
if (res.ok) return Buffer.from(await res.arrayBuffer());
|
||||
else throw {
|
||||
Error: await res.text(),
|
||||
status: res.status
|
||||
}
|
||||
}
|
||||
|
||||
async function JsonHTTP(url = "", args = {}) {
|
||||
const res = await BufferHTTP(url, args);
|
||||
return JSON.parse(res.toString());
|
||||
}
|
||||
|
||||
async function TextHTTP(url = "", args = {}) {
|
||||
return (await BufferHTTP(url, args)).toString();
|
||||
}
|
||||
|
||||
// Export Bds Request
|
||||
module.exports = {
|
||||
// JSON
|
||||
JSON: JsonHTTP,
|
||||
json: JsonHTTP,
|
||||
|
||||
// Raw Text
|
||||
TEXT: TextHTTP,
|
||||
text: TextHTTP,
|
||||
|
||||
// Buffer
|
||||
BUFFER: BufferHTTP,
|
||||
buffer: BufferHTTP
|
||||
}
|
11
src/lib/commandExist.js
Normal file
11
src/lib/commandExist.js
Normal file
@ -0,0 +1,11 @@
|
||||
const { execSync } = require("child_process");
|
||||
const { readdirSync, existsSync } = require("fs");
|
||||
|
||||
function commdExist(command){
|
||||
if (process.platform === "linux" || process.platform === "darwin" || process.platform === "android") {try {execSync(`command -v ${command}`);return true} catch (error) {return false}}
|
||||
else if (process.platform === "win32") {try {execSync(`where ${command} > nul 2> nul`);return true} catch (error) {return false}}
|
||||
throw new Error(`Platform ${process.platform} not supported`);
|
||||
}
|
||||
|
||||
module.exports = commdExist
|
||||
module.exports.sync = commdExist
|
Reference in New Issue
Block a user