Add new Bds Maneger Core CLI #194

Merged
Sirherobrine23 merged 12 commits from CLI into main 2021-09-25 06:20:18 +00:00
5 changed files with 50 additions and 61 deletions
Showing only changes of commit 0530612a94 - Show all commits

View File

@ -5,6 +5,7 @@ process.env.IS_BDS_CLI = process.env.IS_BIN_BDS = true;
// External Modules
const cli_color = require("cli-color");
const inquirer = require("inquirer");
const serverline = require("serverline");
// Bin Args
const ProcessArgs = require("minimist")(process.argv.slice(2));
@ -52,26 +53,11 @@ async function Runner() {
console.log(cli_color.redBright(`Bds Core Exit with code ${code}, Uptimed: ${BdsCoreStart.uptime}`));
process.exit(code);
});
const BdsCliMenus = require("./bds_maneger/menus");
const InfinitCommands = async () => {
const CommandtoRun = (await inquirer.prompt([
{
type: "list",
name: "commands",
message: "Select a command",
choices: [
"tp"
]
}
])).commands;
if (CommandtoRun === "tp") {
BdsCliMenus.tp();
return await InfinitCommands();
} else {
BdsCliMenus.Command();
return await InfinitCommands();
}
}
InfinitCommands();
serverline.init();
serverline.setCompletion(["tp"]);
serverline.setPrompt("Command > ");
serverline.on('line', function(line) {
BdsCoreStart.command(line);
});
}
Runner();
Runner();

14
package-lock.json generated
View File

@ -30,6 +30,7 @@
"ora": "^6.0.1",
"properties-to-json": "^0.2.1",
"request-ip": "^2.1.3",
"serverline": "^1.5.0",
"telegraf": "^4.0.0",
"uuid": "^8.3.2"
},
@ -4995,6 +4996,14 @@
"node": ">= 0.8.0"
}
},
"node_modules/serverline": {
"version": "1.5.0",
"resolved": "https://registry.npmjs.org/serverline/-/serverline-1.5.0.tgz",
"integrity": "sha512-QzNBH8omGchv+L5n/irZEeU2IGK3r8EMRh3EKRIlbfTklf9PtNRiRbWcYr8kqdNeWdc5M5jS13VtspDKgFXFFg==",
"engines": {
"node": ">=10.0.0"
}
},
"node_modules/setprototypeof": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.1.1.tgz",
@ -9773,6 +9782,11 @@
"send": "0.17.1"
}
},
"serverline": {
"version": "1.5.0",
"resolved": "https://registry.npmjs.org/serverline/-/serverline-1.5.0.tgz",
"integrity": "sha512-QzNBH8omGchv+L5n/irZEeU2IGK3r8EMRh3EKRIlbfTklf9PtNRiRbWcYr8kqdNeWdc5M5jS13VtspDKgFXFFg=="
},
"setprototypeof": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.1.1.tgz",

View File

@ -69,6 +69,7 @@
"ora": "^6.0.1",
"properties-to-json": "^0.2.1",
"request-ip": "^2.1.3",
"serverline": "^1.5.0",
"telegraf": "^4.0.0",
"uuid": "^8.3.2"
},

View File

@ -46,7 +46,7 @@ function start() {
// Set Env and Cwd
SetupCommands.cwd = GetServerPaths("bedrock");
SetupCommands.env.LD_LIBRARY_PATH = GetServerPaths("bedrock");
// In case the cpu is different from x64, the command will use qemu static to run the server
if (process.arch !== "x64") {
if (!(commandExists("qemu-x86_64-static"))) throw new Error("Install qemu static")
@ -67,7 +67,7 @@ function start() {
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"}`)}
}
// Minecraft Bedrock (Pocketmine-MP)
else if (GetPlatform() === "pocketmine") {
// Start PocketMine-MP
@ -75,32 +75,16 @@ function start() {
SetupCommands.args.push("./PocketMine-MP.phar");
SetupCommands.cwd = GetServerPaths("pocketmine");
}
// Show Error platform
else throw Error("Bds Config Error")
// Setup commands
const ServerExec = child_process.execFile(SetupCommands.command, SetupCommands.args, {
cwd: SetupCommands.cwd,
env: SetupCommands.env
});
// Post Start
if (GetPlatform() === "java") {
const eula_file_path = path.join(GetServerPaths("java"), "eula.txt");
if (fs.existsSync(eula_file_path)) {
const eula_file = fs.readFileSync(eula_file_path, "utf8");
console.log(eula_file);
if (eula_file.includes("eula=false")) {
fs.writeFileSync(eula_file_path, eula_file.replace(/eula=false/gi, "eula=true"));
throw new Error("Restart application/CLI")
}
} else {
console.log("EULA file not found");
throw new Error("EULA file not found")
}
}
// 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");
@ -110,11 +94,11 @@ function start() {
return data;
}
fs.writeFileSync(LatestLog_Path, "");
// Player JSON File
ServerExec.stdout.on("data", data => Player_Json(data, UpdateUserJSON));
ServerExec.stderr.on("data", data => Player_Json(data, UpdateUserJSON));
// Log File
ServerExec.stdout.on("data", LogSaveFunction);
ServerExec.stderr.on("data", LogSaveFunction);
@ -149,7 +133,7 @@ function start() {
};
const on = function(action = String, callback = Function) {
if (!(action === "all" || action === "connect" || action === "disconnect")) throw new Error("Use some valid action: all, connect, disconnect");
// Functions
const data = data => Player_Json(data, function (array_status){
array_status.filter(On => {if ("all" === action || On.Action === action) return true; else return false;}).forEach(_player => callback(_player))
@ -190,7 +174,7 @@ function start() {
return command;
};
const say = (text = "") => ServerExec.stdin.write(BdsInfo.Servers.bedrock.say.replace("{{Text}}", text));
// Mount commands to Return
const returnFuntion = {
uuid: randomUUID(),
@ -222,7 +206,7 @@ function Player_Json(data = "aaaaaa\n\n\naa", callback = () => {}){
const BedrockMap = data.split(/\n|\r/gi).map(line => {
if (line.includes("connected") || line.includes("disconnected")) {
let SplitLine = line.replace(/\[.+\]\s+Player/gi, "").trim().split(/\s+/gi);
// player
let Player = line.trim().replace(/\[.+\]\s+Player/gi, "").trim().replace(/disconnected:|connected:/, "").trim().split(/,\s+xuid:/).filter(a=>a).map(a=>a.trim()).filter(a=>a);
@ -253,7 +237,7 @@ function Player_Json(data = "aaaaaa\n\n\naa", callback = () => {}){
let Actions = null;
if (/joined/.test(line)) Actions = "connect";
else if (/left/.test(line)) Actions = "disconnect";
// Player Object
const JavaObject = {
Player: line.replace(/joined the game|left the game/gi, "").trim(),
@ -279,7 +263,7 @@ const UpdateUserJSON = function (New_Object = []){
jsprismarine: [],
}
if (fs.existsSync(Player_Json_path)) Players_Json = JSON.parse(fs.readFileSync(Player_Json_path, "utf8"));
// Array
Players_Json[Current_platorm] = Players_Json[Current_platorm].concat(New_Object)
@ -340,11 +324,11 @@ const CurrentBackups = GetCronBackup().map(Crron => {
// Azure
if (Crron.Azure) Cloud_Backup.Azure(CurrentBackup.file_name, CurrentBackup.file_path);
else console.info("Azure Backup Disabled");
// Google Driver
if (Crron.Driver) Cloud_Backup.Driver(CurrentBackup.file_name, CurrentBackup.file_path);
else console.info("Google Driver Backup Disabled");
// Oracle Bucket
if (Crron.Oracle) Cloud_Backup.Oracle(CurrentBackup.file_name, CurrentBackup.file_path);
else console.info("Oracle Bucket Backup Disabled");

View File

@ -222,7 +222,7 @@ module.exports.v2 = async (version = true, force = true) => {
// Load Version List
const ServerDownloadJSON = await Request.json(Extra.Fetchs.servers);
// Check is latest version options or boolean
if (typeof version === "boolean" || /true|false|latest/.test(`${version}`.toLocaleLowerCase())) version = ServerDownloadJSON.latest[CurrentPlatform];
if (!version) throw Error("No version found");
@ -238,7 +238,7 @@ module.exports.v2 = async (version = true, force = true) => {
// Bedrock
if (CurrentPlatform === "bedrock") {
if (valid_platform.bedrock) {
if (!(force === true && typeof force === "boolean") && LocalServersVersions !== version) {
if (!(force === true && typeof force === "boolean") && LocalServersVersions.bedrock !== version) {
// Add info to ReturnObject
ReturnObject.url = ServerDownloadJSON.bedrock[version][bds.arch][process.platform];
ReturnObject.data = ServerDownloadJSON.bedrock[version].data;
@ -279,13 +279,14 @@ module.exports.v2 = async (version = true, force = true) => {
// Java
else if (CurrentPlatform === "java") {
if (valid_platform.java) {
if (!(force === true && typeof force === "boolean") && LocalServersVersions !== version) {
if (!(force === true && typeof force === "boolean") && LocalServersVersions.java !== version) {
// Add info to ReturnObject
ReturnObject.url = ServerDownloadJSON.java[version].url;
ReturnObject.data = ServerDownloadJSON.java[version].data;
// Download and write java file
fs.writeFileSync(path.join(ServersPaths.java, "MinecraftServerJava.jar"), await Request.buffer(ReturnObject.url), "binary");
const JavaBufferJar = await Request.buffer(ReturnObject.url);
fs.writeFileSync(path.join(ServersPaths.java, "MinecraftServerJava.jar"), JavaBufferJar, "binary");
// Write EULA
fs.writeFileSync(path.join(ServersPaths.java, "eula.txt"), "eula=true");
@ -303,7 +304,7 @@ module.exports.v2 = async (version = true, force = true) => {
// Spigot
else if (CurrentPlatform === "spigot") {
if (valid_platform.spigot) {
if (!(force === true && typeof force === "boolean") && LocalServersVersions !== version) {
if (!(force === true && typeof force === "boolean") && LocalServersVersions.spigot !== version) {
// Add info to ReturnObject
const FindedSpigot = ServerDownloadJSON.spigot.findOne(spigot => spigot.version === version);
ReturnObject.url = FindedSpigot.url;
@ -325,11 +326,11 @@ module.exports.v2 = async (version = true, force = true) => {
// Dragonfly
else if (CurrentPlatform === "dragonfly") {
if (valid_platform.dragonfly) {
if (!(force === true && typeof force === "boolean") && LocalServersVersions !== version) {
if (!(force === true && typeof force === "boolean") && LocalServersVersions.dragonfly !== version) {
// Add info to ReturnObject
ReturnObject.url = "https://github.com/df-mc/dragonfly/tree/master";
ReturnObject.data = "";
// Build Dragonfly
const TmpDragonflyDir = path.join(os.tmpdir(), `dragonfly_${Math.random().toString(36).substring(7)}`);
child_process.execFileSync("git", ["clone", "https://github.com/df-mc/dragonfly", "--depth", "1", TmpDragonflyDir]);
@ -352,7 +353,10 @@ module.exports.v2 = async (version = true, force = true) => {
throw Error("Dragonfly not suported");
}
}
// Pocketmine-MP
else if (CurrentPlatform === "pocketmine") {throw new Error("We are still creating for Pocketmine-MP");}
// if the platform does not exist
else throw Error("No Valid Platform");
@ -401,4 +405,4 @@ async function php_download() {
writeFileSync(join(phpFolder, "php7", "bin", "php.ini"), phpConfigInit);
}
return true;
}
}