Update Server list versions #225
@ -7,6 +7,7 @@ const BdsCore = require("../index");
|
||||
const { GetPlatform, bds_dir } = require("../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() {
|
||||
@ -36,7 +37,7 @@ function StartServer(){
|
||||
new CronJob("0 */1 * * *", async () => {
|
||||
try {
|
||||
const CurrentLocalVersion = BdsCore.getBdsConfig().server.versions[GetPlatform()],
|
||||
CurrentRemoteVersion = Object.getOwnPropertyNames((await (await fetch(BdsInfo.Fetchs.servers)).json())[GetPlatform()])[0];
|
||||
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);
|
||||
|
@ -1,215 +1,131 @@
|
||||
#!/usr/bin/env node
|
||||
const readline = require("readline");
|
||||
const cli_color = require("cli-color");
|
||||
const BdsConfigAndInfo = require("../BdsManegerInfo.json");
|
||||
if (process.platform === "win32") process.title = "Bds Maneger CLI"; else process.title = "Bds-Manger-CLI";
|
||||
process.env.IS_BDS_CLI = process.env.IS_BIN_BDS = true;
|
||||
|
||||
// Bds Maneger ArgV
|
||||
const argv = require("minimist")(process.argv.slice(2));
|
||||
if (Object.getOwnPropertyNames(argv).length <= 1) argv.help = true
|
||||
// External Modules
|
||||
const cli_color = require("cli-color");
|
||||
const inquirer = require("inquirer");
|
||||
|
||||
// Bds Core Imports
|
||||
const bds = require("../index");
|
||||
const SystemInfo = require("../lib/BdsSystemInfo");
|
||||
const { bds_dir, GetServerVersion, GetPlatform, UpdatePlatform, GetServerPaths, GetPaths } = require("../lib/BdsSettings");
|
||||
// Bin Args
|
||||
const ProcessArgs = require("minimist")(process.argv.slice(2));
|
||||
|
||||
// Import Bds Core
|
||||
const BdsCore = require("../index");
|
||||
const commandExits = require("../lib/commandExist");
|
||||
const download = require("../src/BdsServersDownload");
|
||||
const readline = require("readline");
|
||||
// const BdsMenus = require("./bds_maneger/menus");
|
||||
const { PlatformVersionsV2 } = require("../src/BdsServersDownload");
|
||||
const { GetPlatform } = require("../lib/BdsSettings");
|
||||
|
||||
// Options
|
||||
const
|
||||
server = (argv.p || argv.platform),
|
||||
version = (argv.v || argv.version),
|
||||
SystemCheck = (argv.S || argv.system_info),
|
||||
bds_version = (argv.d || argv.download),
|
||||
start = (argv.s || argv.server_version),
|
||||
help = (argv.h || argv.help),
|
||||
kill = (argv.k || argv.kill);
|
||||
|
||||
// --------------------------
|
||||
const Versions = GetServerVersion();
|
||||
|
||||
// Bds kill
|
||||
if (kill) bds.kill();
|
||||
|
||||
// Set Bds Platform
|
||||
if (server) {
|
||||
console.log(cli_color.yellow(`Set Platform: ${server}`));
|
||||
UpdatePlatform(server);
|
||||
async function DownloadServer() {
|
||||
const ora = (await import("ora")).default;
|
||||
const PlatformVersion = await PlatformVersionsV2()
|
||||
const waitUserSelectVersion = (await inquirer.prompt({
|
||||
type: "list",
|
||||
name: "version",
|
||||
message: `Select the version to download ${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);
|
||||
RunSpinner.succeed(`Downloaded ${DownloadRes.version}, Published in ${DownloadRes.data.getDate()}/${DownloadRes.data.getMonth()}/${DownloadRes.data.getFullYear()}`);
|
||||
} catch (err) {
|
||||
RunSpinner.fail(String(err));
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
// Start Server
|
||||
async function StartServer(){
|
||||
const Servers = (await (await fetch(BdsConfigAndInfo.Fetchs.servers)).json());
|
||||
// Check Server Update
|
||||
if (Versions[GetPlatform()] !== null) {
|
||||
if (Versions[GetPlatform()] !== Servers.latest[GetPlatform()]) {
|
||||
const message = [
|
||||
`Hello, I have a little warning, There is a new version of ${GetPlatform()}, going from version ${GetServerVersion[GetPlatform()]} to ${Servers.latest[GetPlatform()]}`,
|
||||
"And we strongly recommend keeping the servers up to date, to maintain compatibility between game versions.",
|
||||
`At any time you can update using the options -p ${GetPlatform()} -d "${Servers.latest[GetPlatform()]}"`
|
||||
]
|
||||
console.log(cli_color.yellow(message.join("\n")));
|
||||
}
|
||||
} else if (Versions[GetPlatform()] === null) {
|
||||
console.log(cli_color.red("Install Server"));
|
||||
process.exit(1)
|
||||
}
|
||||
async function info() {
|
||||
const { valid_platform } = await (require("../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`}
|
||||
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}`,
|
||||
"*",
|
||||
"**************************************************************"
|
||||
];
|
||||
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
|
||||
return;
|
||||
}
|
||||
|
||||
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)}`,
|
||||
"**************************************************************",
|
||||
"* Usage: bds-maneger-cli [options]",
|
||||
"*",
|
||||
"* Options:",
|
||||
"* -h, --help Print this help",
|
||||
"* -i, --info Print info about Bds Maneger Core and Platforms",
|
||||
"* -d, --download Download a server",
|
||||
"* -s, --start Start a server",
|
||||
"* -p, --platform Change the platform",
|
||||
"* -n, --no-api Don't start the Bds Maneger API Rest",
|
||||
"*",
|
||||
"* Examples:",
|
||||
"* bds-maneger-cli -d",
|
||||
"* bds-maneger-cli -s",
|
||||
"* bds-maneger-cli -p bedrock",
|
||||
"* bds-maneger-cli -i",
|
||||
"* bds-maneger-cli -h",
|
||||
"**************************************************************"
|
||||
];
|
||||
return console.log(cli_color.whiteBright(help.join("\n").replace(/true/gi, cli_color.greenBright("true")).replace(/false/gi, cli_color.redBright("false")).replace(/undefined/gi, cli_color.red("undefined"))));
|
||||
}
|
||||
|
||||
// Async functiona
|
||||
async function Runner() {
|
||||
// ESM Modules
|
||||
const ora = (await import("ora")).default;
|
||||
|
||||
// Update Bds Core Platform
|
||||
if (ProcessArgs.platform || ProcessArgs.p) {
|
||||
const UpdatePla = ora("Updating Bds Platform").start();
|
||||
try {
|
||||
console.log(cli_color.yellow("Send a \"@stop\" command to stop the server and exit\nUse CTRL + C to force exit"), "\n");
|
||||
// Start Server
|
||||
const bds_server = bds.start();
|
||||
bds_server.log(data => process.stdout.write(cli_color.cyan(data)));
|
||||
bds_server.exit(function (code){
|
||||
if (code === 3221225781 && process.platform === "win32") {
|
||||
console.log(cli_color.red("Open the url: https://docs.the-bds-maneger.org/Bds Maneger core/WindowsFixDll"));
|
||||
return open("https://docs.the-bds-maneger.org/Bds Maneger core/WindowsFixDll");
|
||||
}
|
||||
console.log(cli_color.red(`"leaving the server, status code: ${code}"`));
|
||||
process.exit(code);
|
||||
});
|
||||
|
||||
// CLI Commands
|
||||
const rl = readline.createInterface({input: process.stdin,output: process.stdout});
|
||||
rl.on("line", (input) => {
|
||||
// Stop
|
||||
if (input.trim() === "@stop") {
|
||||
rl.close();
|
||||
bds_server.stop()
|
||||
}
|
||||
// Server input
|
||||
else bds_server.command(input);
|
||||
});
|
||||
rl.on("close", ()=>{
|
||||
console.log(cli_color.redBright("stopping server"));
|
||||
bds_server.stop();
|
||||
})
|
||||
bds_server.exit(function(c){
|
||||
if (c !== 0) rl.close();
|
||||
})
|
||||
bds.api();
|
||||
} catch (err) {
|
||||
console.log(cli_color.redBright(`Bds Maneger Start Server Error: \n******\n${err}`));
|
||||
process.exit(2)
|
||||
BdsCore.platform_update(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}`);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
// Print Info about Bds Core and Platforms
|
||||
if (ProcessArgs.info || ProcessArgs.i) {
|
||||
await info();
|
||||
return;
|
||||
}
|
||||
|
||||
// Help
|
||||
if (ProcessArgs.help || ProcessArgs.h) {
|
||||
await help();
|
||||
return;
|
||||
}
|
||||
|
||||
// Download
|
||||
if (ProcessArgs.download || ProcessArgs.d) await DownloadServer();
|
||||
if (!(ProcessArgs.start || ProcessArgs.s)) return;
|
||||
|
||||
// Start
|
||||
const BdsCoreStart = BdsCore.start();
|
||||
BdsCoreStart.log(data => console.log(cli_color.blueBright(data.replace(/\n$/gi, ""))));
|
||||
BdsCoreStart.exit(code => {
|
||||
console.log(cli_color.redBright(`Bds Core Exit with code ${code}, Uptimed: ${BdsCoreStart.uptime}`));
|
||||
process.exit(code);
|
||||
});
|
||||
if (!(ProcessArgs["no-api"])) BdsCore.api();
|
||||
readline
|
||||
}
|
||||
(async () => {
|
||||
// Bds Maneger CLI Help
|
||||
if (help) {
|
||||
let help = [
|
||||
"usage: bds_maneger [options]",
|
||||
"",
|
||||
"options:",
|
||||
" -s --start Start Server",
|
||||
" -k --kill Detect and kill bds servers",
|
||||
" -p --platform Select server platform",
|
||||
" -d --download server version to install, default \"latest\"",
|
||||
" --interactive Install the server interactively",
|
||||
" -S --system_info System info and test",
|
||||
" -h --help Print this list and exit.",
|
||||
" -v --version Print the version and exit."
|
||||
]
|
||||
console.log(cli_color.yellow(help.join("\n")));
|
||||
process.exit();
|
||||
}
|
||||
|
||||
// Get Bds Core Version
|
||||
if (version) {
|
||||
const Info = [
|
||||
`Bds Maneger Core version: ${bds.package_json.version}`,
|
||||
"",
|
||||
"****************** Bds Maneger Core contributors ******************",
|
||||
"",
|
||||
]
|
||||
for (let contri of bds.extra_json.contributors) {
|
||||
Info.push(`********* ${contri.name} *********`)
|
||||
if (contri.email) Info.push(`* ${contri.email}`)
|
||||
if (contri.url) Info.push(`* ${contri.url}`)
|
||||
Info.push("*")
|
||||
Info.push("*********")
|
||||
}
|
||||
console.log(Info.join("\n"));
|
||||
process.exit();
|
||||
}
|
||||
|
||||
if (SystemCheck) {
|
||||
const { valid_platform } = await SystemInfo();
|
||||
var checkothearch = "";
|
||||
if (process.platform === "linux" && bds.arch !== "x64"){checkothearch = `qemu-x86_64-static is installed to emulate an x64 system: ${commandExits("qemu-x86_64-static")}\n`}
|
||||
if (process.platform === "android" && bds.arch !== "x64"){checkothearch = `qemu-x86_64 is installed to emulate an x64 system: ${commandExits("qemu-x86_64")}\n`}
|
||||
const help = [
|
||||
`Bds Maneger Core And Bds Maneger CLI version: ${cli_color.magentaBright(bds.package_json.version)}`,
|
||||
`System: ${cli_color.yellow(process.platform)}, architecture: ${cli_color.blue(bds.arch)}`,
|
||||
checkothearch,
|
||||
"**************************************************************",
|
||||
"* Bds Maneger dirs:",
|
||||
`* - Config: ${cli_color.yellowBright(bds_dir)}`,
|
||||
`* - Players File: ${cli_color.yellowBright(GetPaths("player"))}`,
|
||||
"*",
|
||||
"* Bds Servers dirs:",
|
||||
`* - Bedrock Server: ${cli_color.yellowBright(GetServerPaths("bedrock"))}`,
|
||||
`* - Pocketmine-MP Server: ${cli_color.yellowBright(GetServerPaths("pocketmine"))}`,
|
||||
`* - Dragonfly: ${cli_color.yellowBright(GetServerPaths("dragonfly"))}`,
|
||||
`* - Java Server: ${cli_color.yellowBright(GetServerPaths("java"))}`,
|
||||
`* - Spigot Server: ${cli_color.yellowBright(GetServerPaths("spigot"))}`,
|
||||
"*",
|
||||
"**************************************************************",
|
||||
"* Servers currently available:",
|
||||
`* - Bedrock: ${valid_platform.bedrock}`,
|
||||
`* - Pocketmine-MP: ${valid_platform.pocketmine}`,
|
||||
`* - Dragonfly: ${valid_platform.dragonfly}`,
|
||||
`* - Java: ${valid_platform.java}`,
|
||||
`* - Spigot: ${valid_platform.java}`,
|
||||
"*",
|
||||
"**************************************************************"
|
||||
];
|
||||
console.log(
|
||||
cli_color.whiteBright(help.join("\n")
|
||||
.replace(/true/gi, cli_color.greenBright("true"))
|
||||
.replace(/false/gi, cli_color.redBright("false"))
|
||||
.replace(/undefined/gi, cli_color.red("undefined"))
|
||||
));
|
||||
process.exit(0)
|
||||
}
|
||||
|
||||
// Download server
|
||||
if (bds_version){
|
||||
(async () => {
|
||||
try {
|
||||
if (argv.interactive) {
|
||||
const LoadVersion = (await (await fetch(BdsConfigAndInfo.Fetchs.servers)).json())[GetPlatform()]
|
||||
const Version = Object.getOwnPropertyNames(LoadVersion)
|
||||
|
||||
const StartQuestion = (Readline) => {
|
||||
Readline.question("Select a version to download: ", input => {
|
||||
if (Version[parseInt(input) - 1]) {
|
||||
Readline.close();
|
||||
download(Version[parseInt(input) - 1], true, function(){
|
||||
if (start) return StartServer();
|
||||
console.log("Installation was successful, so start the server with the -s option");
|
||||
process.exit(0);
|
||||
})
|
||||
} else {
|
||||
console.log("Invalid Option");
|
||||
StartQuestion(Readline);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
console.log(`Selected platform: ${GetPlatform()}, Total available versions: ${Version.length}`);
|
||||
console.log(`${cli_color.red("Option")} ${cli_color.green("Version")}`);
|
||||
|
||||
for (let option in Version) console.log(`${cli_color.red(parseInt(option) + 1)}: ${cli_color.green(Version[option])}`);
|
||||
StartQuestion(readline.createInterface({input: process.stdin,output: process.stdout}));
|
||||
}
|
||||
else bds.download(bds_version, true, function(){
|
||||
if (start) StartServer();
|
||||
})
|
||||
} catch (error) {console.error(error);process.exit(165);}
|
||||
})();
|
||||
}
|
||||
|
||||
// Start server
|
||||
if (start && !(server || version || SystemCheck || bds_version || help)) StartServer();
|
||||
|
||||
})()
|
||||
Runner();
|
||||
|
@ -1,116 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
if (process.platform === "win32") process.title = "Bds Maneger CLI"; else process.title = "Bds-Manger-CLI";
|
||||
process.env.IS_BDS_CLI = process.env.IS_BIN_BDS = true;
|
||||
|
||||
// External Modules
|
||||
const cli_color = require("cli-color");
|
||||
const serverline = require("serverline");
|
||||
const inquirer = require("inquirer");
|
||||
|
||||
// Bin Args
|
||||
const ProcessArgs = require("minimist")(process.argv.slice(2));
|
||||
|
||||
// Import Bds Core
|
||||
const BdsCore = require("../index");
|
||||
const BdsReq = require("../lib/Requests");
|
||||
const BdsExtraInfo = require("../BdsManegerInfo.json");
|
||||
const commandExits = require("../lib/commandExist");
|
||||
const BdsMenus = require("./bds_maneger/menus");
|
||||
|
||||
// Async functiona
|
||||
async function Runner() {
|
||||
// ESM Modules
|
||||
const ora = (await import("ora")).default;
|
||||
|
||||
// Update Bds Core Platform
|
||||
if (ProcessArgs.platform || ProcessArgs.p) {
|
||||
const UpdatePla = ora("Updating Bds Platform").start();
|
||||
try {
|
||||
BdsCore.platform_update(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}`);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
// Print Info about Bds Core and Platforms
|
||||
if (ProcessArgs.info || ProcessArgs.i) {
|
||||
const { valid_platform } = await (require("../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`}
|
||||
const help = [
|
||||
`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}`,
|
||||
`* - Pocketmine-MP: ${valid_platform.pocketmine}`,
|
||||
`* - Dragonfly: ${valid_platform.dragonfly}`,
|
||||
`* - Java: ${valid_platform.java}`,
|
||||
`* - Spigot: ${valid_platform.java}`,
|
||||
"*",
|
||||
"**************************************************************"
|
||||
];
|
||||
console.log(cli_color.whiteBright(help.join("\n").replace(/true/gi, cli_color.greenBright("true")).replace(/false/gi, cli_color.redBright("false")).replace(/undefined/gi, cli_color.red("undefined"))));
|
||||
// End
|
||||
return;
|
||||
}
|
||||
|
||||
// Download
|
||||
if (ProcessArgs.download || ProcessArgs.d) {
|
||||
const VersionList = Object.getOwnPropertyNames((await BdsReq.json(BdsExtraInfo.Fetchs.servers))[BdsCore.BdsSettigs.GetPlatform()]).map(version => ({
|
||||
name: `${BdsCore.BdsSettigs.GetPlatform()}: v${version}`,
|
||||
value: version,
|
||||
}))
|
||||
if ((ProcessArgs.download || ProcessArgs.d) === true || (ProcessArgs.download || ProcessArgs.d) === "latest") ProcessArgs.d = ProcessArgs.download = (await inquirer.prompt([
|
||||
{
|
||||
type: "list",
|
||||
name: "download",
|
||||
message: "Select the platform to download",
|
||||
choices: VersionList
|
||||
}
|
||||
])).download;
|
||||
const oraDownload = ora(`Downloading ${BdsCore.BdsSettigs.GetPlatform()} on version ${ProcessArgs.d || ProcessArgs.download}`).start();
|
||||
try {
|
||||
const DownloadInfo = await BdsCore.download.v2(ProcessArgs.d || ProcessArgs.download, true);
|
||||
const DownloadSucess = ["Downloaded Successfully"];
|
||||
if (DownloadInfo.version) DownloadSucess.push(`Version: ${DownloadInfo.version}`);
|
||||
if (DownloadInfo.data) DownloadSucess.push(`Data: ${DownloadInfo.data}`);
|
||||
if (DownloadInfo.platform) DownloadSucess.push(`Bds Core Platform: ${DownloadInfo.platform}`);
|
||||
oraDownload.succeed(DownloadSucess.join(", "))
|
||||
} catch (error) {
|
||||
oraDownload.fail(error.message);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
if (!(ProcessArgs.start || ProcessArgs.s)) return;
|
||||
|
||||
// Start
|
||||
const BdsCoreStart = BdsCore.start();
|
||||
BdsCoreStart.log(data => console.log(cli_color.blueBright(data.replace(/\n$/gi, ""))));
|
||||
BdsCoreStart.exit(code => {
|
||||
console.log(cli_color.redBright(`Bds Core Exit with code ${code}, Uptimed: ${BdsCoreStart.uptime}`));
|
||||
process.exit(code);
|
||||
});
|
||||
serverline.init();
|
||||
serverline.setCompletion(["tp"]);
|
||||
serverline.setPrompt("Command > ");
|
||||
serverline.on("line", async function(line) {
|
||||
if (/^@/.test(line)) {
|
||||
serverline.close();
|
||||
if (/^@stop/.test(line)) {
|
||||
BdsCoreStart.stop();
|
||||
return;
|
||||
} else if (/^@tp/.test(line)) {
|
||||
await BdsMenus.TpMenu();
|
||||
}
|
||||
return serverline.init();
|
||||
} else BdsCoreStart.command(line);
|
||||
});
|
||||
if (!(ProcessArgs["no-api"])) BdsCore.api()
|
||||
}
|
||||
Runner();
|
215
bin/old_bds_maneger.js
Normal file
215
bin/old_bds_maneger.js
Normal file
@ -0,0 +1,215 @@
|
||||
#!/usr/bin/env node
|
||||
const readline = require("readline");
|
||||
const cli_color = require("cli-color");
|
||||
const BdsConfigAndInfo = require("../BdsManegerInfo.json");
|
||||
if (process.platform === "win32") process.title = "Bds Maneger CLI"; else process.title = "Bds-Manger-CLI";
|
||||
process.env.IS_BDS_CLI = process.env.IS_BIN_BDS = true;
|
||||
|
||||
// Bds Maneger ArgV
|
||||
const argv = require("minimist")(process.argv.slice(2));
|
||||
if (Object.getOwnPropertyNames(argv).length <= 1) argv.help = true
|
||||
|
||||
// Bds Core Imports
|
||||
const bds = require("../index");
|
||||
const SystemInfo = require("../lib/BdsSystemInfo");
|
||||
const { bds_dir, GetServerVersion, GetPlatform, UpdatePlatform, GetServerPaths, GetPaths } = require("../lib/BdsSettings");
|
||||
const commandExits = require("../lib/commandExist");
|
||||
const download = require("../src/BdsServersDownload");
|
||||
|
||||
// Options
|
||||
const
|
||||
server = (argv.p || argv.platform),
|
||||
version = (argv.v || argv.version),
|
||||
SystemCheck = (argv.S || argv.system_info),
|
||||
bds_version = (argv.d || argv.download),
|
||||
start = (argv.s || argv.server_version),
|
||||
help = (argv.h || argv.help),
|
||||
kill = (argv.k || argv.kill);
|
||||
|
||||
// --------------------------
|
||||
const Versions = GetServerVersion();
|
||||
|
||||
// Bds kill
|
||||
if (kill) bds.kill();
|
||||
|
||||
// Set Bds Platform
|
||||
if (server) {
|
||||
console.log(cli_color.yellow(`Set Platform: ${server}`));
|
||||
UpdatePlatform(server);
|
||||
}
|
||||
|
||||
// Start Server
|
||||
async function StartServer(){
|
||||
const Servers = (await (await fetch(BdsConfigAndInfo.Fetchs.servers)).json());
|
||||
// Check Server Update
|
||||
if (Versions[GetPlatform()] !== null) {
|
||||
if (Versions[GetPlatform()] !== Servers.latest[GetPlatform()]) {
|
||||
const message = [
|
||||
`Hello, I have a little warning, There is a new version of ${GetPlatform()}, going from version ${GetServerVersion[GetPlatform()]} to ${Servers.latest[GetPlatform()]}`,
|
||||
"And we strongly recommend keeping the servers up to date, to maintain compatibility between game versions.",
|
||||
`At any time you can update using the options -p ${GetPlatform()} -d "${Servers.latest[GetPlatform()]}"`
|
||||
]
|
||||
console.log(cli_color.yellow(message.join("\n")));
|
||||
}
|
||||
} else if (Versions[GetPlatform()] === null) {
|
||||
console.log(cli_color.red("Install Server"));
|
||||
process.exit(1)
|
||||
}
|
||||
try {
|
||||
console.log(cli_color.yellow("Send a \"@stop\" command to stop the server and exit\nUse CTRL + C to force exit"), "\n");
|
||||
// Start Server
|
||||
const bds_server = bds.start();
|
||||
bds_server.log(data => process.stdout.write(cli_color.cyan(data)));
|
||||
bds_server.exit(function (code){
|
||||
if (code === 3221225781 && process.platform === "win32") {
|
||||
console.log(cli_color.red("Open the url: https://docs.the-bds-maneger.org/Bds Maneger core/WindowsFixDll"));
|
||||
return open("https://docs.the-bds-maneger.org/Bds Maneger core/WindowsFixDll");
|
||||
}
|
||||
console.log(cli_color.red(`"leaving the server, status code: ${code}"`));
|
||||
process.exit(code);
|
||||
});
|
||||
|
||||
// CLI Commands
|
||||
const rl = readline.createInterface({input: process.stdin,output: process.stdout});
|
||||
rl.on("line", (input) => {
|
||||
// Stop
|
||||
if (input.trim() === "@stop") {
|
||||
rl.close();
|
||||
bds_server.stop()
|
||||
}
|
||||
// Server input
|
||||
else bds_server.command(input);
|
||||
});
|
||||
rl.on("close", ()=>{
|
||||
console.log(cli_color.redBright("stopping server"));
|
||||
bds_server.stop();
|
||||
})
|
||||
bds_server.exit(function(c){
|
||||
if (c !== 0) rl.close();
|
||||
})
|
||||
bds.api();
|
||||
} catch (err) {
|
||||
console.log(cli_color.redBright(`Bds Maneger Start Server Error: \n******\n${err}`));
|
||||
process.exit(2)
|
||||
}
|
||||
}
|
||||
(async () => {
|
||||
// Bds Maneger CLI Help
|
||||
if (help) {
|
||||
let help = [
|
||||
"usage: bds_maneger [options]",
|
||||
"",
|
||||
"options:",
|
||||
" -s --start Start Server",
|
||||
" -k --kill Detect and kill bds servers",
|
||||
" -p --platform Select server platform",
|
||||
" -d --download server version to install, default \"latest\"",
|
||||
" --interactive Install the server interactively",
|
||||
" -S --system_info System info and test",
|
||||
" -h --help Print this list and exit.",
|
||||
" -v --version Print the version and exit."
|
||||
]
|
||||
console.log(cli_color.yellow(help.join("\n")));
|
||||
process.exit();
|
||||
}
|
||||
|
||||
// Get Bds Core Version
|
||||
if (version) {
|
||||
const Info = [
|
||||
`Bds Maneger Core version: ${bds.package_json.version}`,
|
||||
"",
|
||||
"****************** Bds Maneger Core contributors ******************",
|
||||
"",
|
||||
]
|
||||
for (let contri of bds.extra_json.contributors) {
|
||||
Info.push(`********* ${contri.name} *********`)
|
||||
if (contri.email) Info.push(`* ${contri.email}`)
|
||||
if (contri.url) Info.push(`* ${contri.url}`)
|
||||
Info.push("*")
|
||||
Info.push("*********")
|
||||
}
|
||||
console.log(Info.join("\n"));
|
||||
process.exit();
|
||||
}
|
||||
|
||||
if (SystemCheck) {
|
||||
const { valid_platform } = await SystemInfo();
|
||||
var checkothearch = "";
|
||||
if (process.platform === "linux" && bds.arch !== "x64"){checkothearch = `qemu-x86_64-static is installed to emulate an x64 system: ${commandExits("qemu-x86_64-static")}\n`}
|
||||
if (process.platform === "android" && bds.arch !== "x64"){checkothearch = `qemu-x86_64 is installed to emulate an x64 system: ${commandExits("qemu-x86_64")}\n`}
|
||||
const help = [
|
||||
`Bds Maneger Core And Bds Maneger CLI version: ${cli_color.magentaBright(bds.package_json.version)}`,
|
||||
`System: ${cli_color.yellow(process.platform)}, architecture: ${cli_color.blue(bds.arch)}`,
|
||||
checkothearch,
|
||||
"**************************************************************",
|
||||
"* Bds Maneger dirs:",
|
||||
`* - Config: ${cli_color.yellowBright(bds_dir)}`,
|
||||
`* - Players File: ${cli_color.yellowBright(GetPaths("player"))}`,
|
||||
"*",
|
||||
"* Bds Servers dirs:",
|
||||
`* - Bedrock Server: ${cli_color.yellowBright(GetServerPaths("bedrock"))}`,
|
||||
`* - Pocketmine-MP Server: ${cli_color.yellowBright(GetServerPaths("pocketmine"))}`,
|
||||
`* - Dragonfly: ${cli_color.yellowBright(GetServerPaths("dragonfly"))}`,
|
||||
`* - Java Server: ${cli_color.yellowBright(GetServerPaths("java"))}`,
|
||||
`* - Spigot Server: ${cli_color.yellowBright(GetServerPaths("spigot"))}`,
|
||||
"*",
|
||||
"**************************************************************",
|
||||
"* Servers currently available:",
|
||||
`* - Bedrock: ${valid_platform.bedrock}`,
|
||||
`* - Pocketmine-MP: ${valid_platform.pocketmine}`,
|
||||
`* - Dragonfly: ${valid_platform.dragonfly}`,
|
||||
`* - Java: ${valid_platform.java}`,
|
||||
`* - Spigot: ${valid_platform.java}`,
|
||||
"*",
|
||||
"**************************************************************"
|
||||
];
|
||||
console.log(
|
||||
cli_color.whiteBright(help.join("\n")
|
||||
.replace(/true/gi, cli_color.greenBright("true"))
|
||||
.replace(/false/gi, cli_color.redBright("false"))
|
||||
.replace(/undefined/gi, cli_color.red("undefined"))
|
||||
));
|
||||
process.exit(0)
|
||||
}
|
||||
|
||||
// Download server
|
||||
if (bds_version){
|
||||
(async () => {
|
||||
try {
|
||||
if (argv.interactive) {
|
||||
const LoadVersion = (await (await fetch(BdsConfigAndInfo.Fetchs.servers)).json())[GetPlatform()]
|
||||
const Version = Object.getOwnPropertyNames(LoadVersion)
|
||||
|
||||
const StartQuestion = (Readline) => {
|
||||
Readline.question("Select a version to download: ", input => {
|
||||
if (Version[parseInt(input) - 1]) {
|
||||
Readline.close();
|
||||
download(Version[parseInt(input) - 1], true, function(){
|
||||
if (start) return StartServer();
|
||||
console.log("Installation was successful, so start the server with the -s option");
|
||||
process.exit(0);
|
||||
})
|
||||
} else {
|
||||
console.log("Invalid Option");
|
||||
StartQuestion(Readline);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
console.log(`Selected platform: ${GetPlatform()}, Total available versions: ${Version.length}`);
|
||||
console.log(`${cli_color.red("Option")} ${cli_color.green("Version")}`);
|
||||
|
||||
for (let option in Version) console.log(`${cli_color.red(parseInt(option) + 1)}: ${cli_color.green(Version[option])}`);
|
||||
StartQuestion(readline.createInterface({input: process.stdin,output: process.stdout}));
|
||||
}
|
||||
else bds.download(bds_version, true, function(){
|
||||
if (start) StartServer();
|
||||
})
|
||||
} catch (error) {console.error(error);process.exit(165);}
|
||||
})();
|
||||
}
|
||||
|
||||
// Start server
|
||||
if (start && !(server || version || SystemCheck || bds_version || help)) StartServer();
|
||||
|
||||
})()
|
@ -4,11 +4,16 @@ 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 = await Request.JSON("https://raw.githubusercontent.com/The-Bds-Maneger/external_files/main/Server.json");
|
||||
Servers = {
|
||||
bedrock: await PlatformVersionsV2("bedrock"),
|
||||
spigot: await PlatformVersionsV2("spigot"),
|
||||
dragonfly: await PlatformVersionsV2("dragonfly"),
|
||||
}
|
||||
|
||||
let system, require_qemu = false;
|
||||
const valid_platform = {
|
||||
@ -23,7 +28,7 @@ async function CheckSystemAsync() {
|
||||
else valid_platform["pocketmine"] = false;
|
||||
|
||||
//
|
||||
if (!(Servers.dragonfly[Servers.latest.dragonfly][process.platform][bds.arch])) valid_platform["dragonfly"] = false;
|
||||
if (!(Servers.dragonfly.versions[Servers.dragonfly.latest][process.platform][bds.arch])) valid_platform["dragonfly"] = false;
|
||||
|
||||
// SoSystem X
|
||||
if (process.platform == "win32") {
|
||||
@ -32,8 +37,8 @@ async function CheckSystemAsync() {
|
||||
system = "Linux";
|
||||
|
||||
// Bedrock Check
|
||||
if (Servers.bedrock[Servers.latest.bedrock][arch]) {
|
||||
if (Servers.bedrock[Servers.latest.bedrock][arch][process.platform]) valid_platform["bedrock"] = true;
|
||||
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;
|
||||
|
||||
@ -46,22 +51,21 @@ async function CheckSystemAsync() {
|
||||
}
|
||||
} else if (process.platform == "darwin") {
|
||||
system = "MacOS";
|
||||
valid_platform["bedrock"] = false
|
||||
} else if (process.platform === "android") {
|
||||
system = "Android";
|
||||
valid_platform["bedrock"] = false
|
||||
} else {
|
||||
throw new Error(`The Bds Maneger Core does not support ${process.platform} systems, as no tests have been done.`);
|
||||
}
|
||||
|
||||
return {
|
||||
system,
|
||||
require_qemu,
|
||||
valid_platform,
|
||||
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;
|
||||
|
@ -3,12 +3,46 @@ const path = require("path");
|
||||
const { writeFileSync, existsSync, readFileSync, readdirSync, rmSync } = fs;
|
||||
const { join, resolve } = path;
|
||||
var AdmZip = require("adm-zip");
|
||||
const BdsInfo = require("../lib/BdsSystemInfo");
|
||||
const { GetServerPaths, GetPlatform } = require("../lib/BdsSettings");
|
||||
const Extra = require("../BdsManegerInfo.json");
|
||||
const bds = require("../index");
|
||||
const Request = require("../lib/Requests");
|
||||
|
||||
// Get Platform Object Versions
|
||||
async function PlatformVersionsV2(SelectPlatform = "") {
|
||||
const CurrentPlatform = SelectPlatform || GetPlatform();
|
||||
let ResToRetuen = {
|
||||
latest: "",
|
||||
versions: {
|
||||
"123.123.123": {
|
||||
data: `${new Date()}`,
|
||||
url: "",
|
||||
linux: {
|
||||
aarch64: "",
|
||||
armv7: "",
|
||||
x64: "",
|
||||
i386: ""
|
||||
},
|
||||
win32: {
|
||||
aarch64: "",
|
||||
x64: "",
|
||||
i386: ""
|
||||
},
|
||||
darwin: {
|
||||
aarch64: "",
|
||||
x64: ""
|
||||
},
|
||||
android: {
|
||||
aarch64: "",
|
||||
x64: ""
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ResToRetuen = await Request.json(`https://raw.githubusercontent.com/The-Bds-Maneger/ServerVersions/main/${CurrentPlatform}/server.json`);
|
||||
return ResToRetuen;
|
||||
}
|
||||
|
||||
// Php download and install
|
||||
async function php_download() {
|
||||
const bds_dir_pocketmine = GetServerPaths("pocketmine");
|
||||
@ -51,32 +85,27 @@ async function php_download() {
|
||||
// New Download Method
|
||||
async function BdsDownloadV2(version = "latest") {
|
||||
const CurrentPlatform = GetPlatform();
|
||||
const { valid_platform, require_qemu } = await BdsInfo();
|
||||
const { valid_platform, require_qemu } = await (require("../lib/BdsSystemInfo")).CheckSystemAsync();
|
||||
const LocalServersVersions = bds.BdsSettigs.GetServerVersion();
|
||||
const { ServersPaths } = bds.BdsSettigs;
|
||||
|
||||
// Load Version List
|
||||
const ServerDownloadJSON = await Request.json(Extra.Fetchs.servers);
|
||||
|
||||
// Check is latest version options or boolean
|
||||
if (typeof version === "boolean" || /true|false|null|undefined|latest/.test(`${version}`.toLocaleLowerCase())) version = ServerDownloadJSON.latest[CurrentPlatform];
|
||||
if (!version) throw Error("No version found");
|
||||
|
||||
const ReturnObject = {
|
||||
version,
|
||||
platform: CurrentPlatform,
|
||||
url: "",
|
||||
data: "",
|
||||
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 (valid_platform.bedrock) {
|
||||
if (LocalServersVersions.bedrock !== version) {
|
||||
// Add info to ReturnObject
|
||||
if (require_qemu) ReturnObject.url = ServerDownloadJSON.bedrock[version]["x64"][process.platform]; else ReturnObject.url = ServerDownloadJSON.bedrock[version][bds.arch][process.platform];
|
||||
ReturnObject.data = ServerDownloadJSON.bedrock[version].data;
|
||||
if (require_qemu) ReturnObject.url = BedrockVersions.versions[version][process.platform]["x64"]; else ReturnObject.url = BedrockVersions.versions[version][process.platform][bds.arch];
|
||||
ReturnObject.data = BedrockVersions.versions[version].data ? new Date(BedrockVersions.versions[version].data) : null;
|
||||
|
||||
// Download and Add buffer to AdmZip
|
||||
const BedrockZip = new AdmZip(await Request.buffer(ReturnObject.url));
|
||||
@ -113,11 +142,13 @@ async function BdsDownloadV2(version = "latest") {
|
||||
|
||||
// Java
|
||||
else if (CurrentPlatform === "java") {
|
||||
const JavaVersions = await PlatformVersionsV2("java");
|
||||
if (typeof version === "boolean" || /true|false|null|undefined|latest/.test(`${version}`.toLocaleLowerCase())) version = JavaVersions.latest;
|
||||
if (valid_platform.java) {
|
||||
if (LocalServersVersions.java !== version) {
|
||||
// Add info to ReturnObject
|
||||
ReturnObject.url = ServerDownloadJSON.java[version].url;
|
||||
ReturnObject.data = ServerDownloadJSON.java[version].data;
|
||||
ReturnObject.url = JavaVersions.versions[version].url;
|
||||
ReturnObject.data = JavaVersions.versions[version].data;
|
||||
|
||||
// Download and write java file
|
||||
const JavaBufferJar = await Request.buffer(ReturnObject.url);
|
||||
@ -138,12 +169,13 @@ async function BdsDownloadV2(version = "latest") {
|
||||
|
||||
// Spigot
|
||||
else if (CurrentPlatform === "spigot") {
|
||||
const SpigotVersions = await PlatformVersionsV2("spigot");
|
||||
if (typeof version === "boolean" || /true|false|null|undefined|latest/.test(`${version}`.toLocaleLowerCase())) version = SpigotVersions.latest;
|
||||
if (valid_platform.spigot) {
|
||||
if (LocalServersVersions.spigot !== version) {
|
||||
// Add info to ReturnObject
|
||||
const FindedSpigot = ServerDownloadJSON.spigot.find(spigot => spigot.version === version);
|
||||
ReturnObject.url = FindedSpigot.url;
|
||||
ReturnObject.data = FindedSpigot.data;
|
||||
ReturnObject.url = SpigotVersions.versions[version].url;
|
||||
ReturnObject.data = SpigotVersions.versions[version].data;
|
||||
|
||||
// Download and write java file
|
||||
fs.writeFileSync(path.join(ServersPaths.spigot, "spigot.jar"), await Request.buffer(ReturnObject.url), "binary");
|
||||
@ -160,11 +192,13 @@ async function BdsDownloadV2(version = "latest") {
|
||||
|
||||
// Dragonfly
|
||||
else if (CurrentPlatform === "dragonfly") {
|
||||
const DragonflyVersions = await PlatformVersionsV2("dragonfly");
|
||||
if (typeof version === "boolean" || /true|false|null|undefined|latest/.test(`${version}`.toLocaleLowerCase())) version = DragonflyVersions.latest;
|
||||
if (valid_platform.dragonfly) {
|
||||
if (LocalServersVersions.dragonfly !== version) {
|
||||
// Add info to ReturnObject
|
||||
ReturnObject.url = ServerDownloadJSON.dragonfly[version][process.platform][bds.arch]
|
||||
ReturnObject.data = ServerDownloadJSON.dragonfly[version].data;
|
||||
ReturnObject.url = DragonflyVersions.versions[version][process.platform][bds.arch]
|
||||
ReturnObject.data = DragonflyVersions.versions[version].data;
|
||||
|
||||
// Download
|
||||
let DgBin = path.join(ServersPaths.dragonfly, "Dragonfly");
|
||||
@ -183,11 +217,13 @@ async function BdsDownloadV2(version = "latest") {
|
||||
|
||||
// Pocketmine-MP
|
||||
else if (CurrentPlatform === "pocketmine") {
|
||||
const PocketmineVersions = await PlatformVersionsV2("pocketmine");
|
||||
if (typeof version === "boolean" || /true|false|null|undefined|latest/.test(`${version}`.toLocaleLowerCase())) version = PocketmineVersions.latest;
|
||||
if (valid_platform.pocketmine) {
|
||||
if (LocalServersVersions.pocketmine !== version) {
|
||||
// Add info to ReturnObject
|
||||
ReturnObject.url = ServerDownloadJSON.pocketmine[version].url;
|
||||
ReturnObject.data = ServerDownloadJSON.pocketmine[version].data;
|
||||
ReturnObject.url = PocketmineVersions.versions[version].url;
|
||||
ReturnObject.data = PocketmineVersions.versions[version].data;
|
||||
|
||||
// Download PHP Bin
|
||||
await php_download();
|
||||
@ -216,3 +252,4 @@ async function BdsDownloadV2(version = "latest") {
|
||||
// Export
|
||||
module.exports = BdsDownloadV2;
|
||||
module.exports.v2 = BdsDownloadV2;
|
||||
module.exports.PlatformVersionsV2 = PlatformVersionsV2;
|
Reference in New Issue
Block a user