Move files from Scripts/ to src/ and add 'on' to start server. #144
@ -19,7 +19,13 @@
|
|||||||
"smcpeak.default-keys-windows",
|
"smcpeak.default-keys-windows",
|
||||||
"vscode-icons-team.vscode-icons",
|
"vscode-icons-team.vscode-icons",
|
||||||
"me-dutour-mathieu.vscode-github-actions",
|
"me-dutour-mathieu.vscode-github-actions",
|
||||||
"cschleiden.vscode-github-actions"
|
"cschleiden.vscode-github-actions",
|
||||||
|
"github.copilot",
|
||||||
|
"eamodio.gitlens",
|
||||||
|
"github.vscode-pull-request-github",
|
||||||
|
"oderwat.indent-rainbow",
|
||||||
|
"visualstudioexptteam.vscodeintellicode",
|
||||||
|
"redhat.vscode-yaml"
|
||||||
],
|
],
|
||||||
|
|
||||||
// Use 'forwardPorts' to make a list of ports inside the container available locally.
|
// Use 'forwardPorts' to make a list of ports inside the container available locally.
|
||||||
|
5
.gitattributes
vendored
5
.gitattributes
vendored
@ -1 +1,4 @@
|
|||||||
*.sh text eol=lf
|
*.sh text=LF eol=LF
|
||||||
|
.devcontainer/* eol=LF text=LF
|
||||||
|
*.js text=LF eol=LF
|
||||||
|
* text=CRLF eol=CRLF
|
@ -5,7 +5,7 @@ const bds = require("../index");
|
|||||||
const { valid_platform } = require("../lib/BdsSystemInfo");
|
const { valid_platform } = require("../lib/BdsSystemInfo");
|
||||||
const { bds_dir, GetServerVersion, GetPlatform, UpdatePlatform, GetServerPaths, GetPaths } = require("../lib/BdsSettings");
|
const { bds_dir, GetServerVersion, GetPlatform, UpdatePlatform, GetServerPaths, GetPaths } = require("../lib/BdsSettings");
|
||||||
const commandExits = require("../lib/commandExist");
|
const commandExits = require("../lib/commandExist");
|
||||||
const download = require("../src/Scripts/download");
|
const download = require("../src/download");
|
||||||
process.env.IS_BDS_CLI = process.env.IS_BIN_BDS = true;
|
process.env.IS_BDS_CLI = process.env.IS_BIN_BDS = true;
|
||||||
// Bds Maneger ArgV
|
// Bds Maneger ArgV
|
||||||
const argv = require("minimist")(process.argv.slice(2));
|
const argv = require("minimist")(process.argv.slice(2));
|
||||||
|
@ -4,7 +4,7 @@ const path = require("path");
|
|||||||
const bds = require("../index");
|
const bds = require("../index");
|
||||||
const { GetPlatform, GetPaths } = require("../lib/BdsSettings");
|
const { GetPlatform, GetPaths } = require("../lib/BdsSettings");
|
||||||
const { GetKernel, arch, system } = require("../lib/BdsSystemInfo");
|
const { GetKernel, arch, system } = require("../lib/BdsSystemInfo");
|
||||||
const { Detect } = require("../src/Scripts/CheckKill");
|
const { Detect } = require("../src/CheckKill");
|
||||||
const TelegramOptions = require("minimist")(process.argv.slice(2));
|
const TelegramOptions = require("minimist")(process.argv.slice(2));
|
||||||
|
|
||||||
if (TelegramOptions.h || TelegramOptions.help) {
|
if (TelegramOptions.h || TelegramOptions.help) {
|
||||||
|
23
index.js
23
index.js
@ -3,6 +3,7 @@ const { resolve } = require("path");
|
|||||||
const path = require("path")
|
const path = require("path")
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const { randomUUID } = require("crypto");
|
const { randomUUID } = require("crypto");
|
||||||
|
|
||||||
function date(format) {
|
function date(format) {
|
||||||
const today = new Date(),
|
const today = new Date(),
|
||||||
yaer = today.getFullYear(),
|
yaer = today.getFullYear(),
|
||||||
@ -32,7 +33,7 @@ const { GetPaths, GetJsonConfig, UpdatePlatform, UpdateTelegramToken, GetTelegra
|
|||||||
module.exports.arch = arch
|
module.exports.arch = arch
|
||||||
if (typeof fetch === "undefined") global.fetch = require("node-fetch");
|
if (typeof fetch === "undefined") global.fetch = require("node-fetch");
|
||||||
|
|
||||||
const maneger_ips = require("./src/Scripts/external_ip")
|
const maneger_ips = require("./src/external_ip")
|
||||||
module.exports.internal_ip = maneger_ips.internal_ip
|
module.exports.internal_ip = maneger_ips.internal_ip
|
||||||
module.exports.external_ip = maneger_ips.external_ip
|
module.exports.external_ip = maneger_ips.external_ip
|
||||||
module.exports.save_google_id = require("./lib/BdsSettings").CloudConfig.Driver
|
module.exports.save_google_id = require("./lib/BdsSettings").CloudConfig.Driver
|
||||||
@ -89,10 +90,10 @@ function token_register() {
|
|||||||
module.exports.BdsSettigs = require("./lib/BdsSettings");
|
module.exports.BdsSettigs = require("./lib/BdsSettings");
|
||||||
|
|
||||||
// Requires
|
// Requires
|
||||||
const { World_BAckup } = require("./src/Scripts/backups");
|
const { World_BAckup } = require("./src/backups");
|
||||||
const { config, get_config, config_example } = require("./src/Scripts/ServerSettings");
|
const { config, get_config, config_example } = require("./src/ServerSettings");
|
||||||
const download = require("./src/Scripts/download");
|
const download = require("./src/download");
|
||||||
const { start, stop, BdsCommand } = require("./src/Scripts/basic_server")
|
const { start, stop, BdsCommand } = require("./src/basic_server")
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register tokens to use in Bds Maneger REST and other supported applications
|
* Register tokens to use in Bds Maneger REST and other supported applications
|
||||||
@ -130,14 +131,14 @@ module.exports.stop = stop
|
|||||||
*/
|
*/
|
||||||
module.exports.backup = World_BAckup
|
module.exports.backup = World_BAckup
|
||||||
|
|
||||||
const { Kill, Detect } = require("./src/Scripts/CheckKill")
|
const { Kill, Detect } = require("./src/CheckKill")
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* identify if there are any servers running in the background
|
* identify if there are any servers running in the background
|
||||||
*
|
*
|
||||||
* @example bds.detect()
|
* @example bds.detect()
|
||||||
* // true: if the server is running
|
* true: if the server is running
|
||||||
* // false: if not already
|
* false: if not already
|
||||||
*/
|
*/
|
||||||
module.exports.detect = Detect
|
module.exports.detect = Detect
|
||||||
module.exports.bds_detect = Detect
|
module.exports.bds_detect = Detect
|
||||||
@ -165,7 +166,7 @@ module.exports.config_example = config_example
|
|||||||
/**
|
/**
|
||||||
* use this command to modify server settings
|
* use this command to modify server settings
|
||||||
*
|
*
|
||||||
* @example bds.set_config({
|
* @example set_config({
|
||||||
name: "Bedrock our Java",
|
name: "Bedrock our Java",
|
||||||
description: "BDS Maneger",
|
description: "BDS Maneger",
|
||||||
gamemode: "survival",
|
gamemode: "survival",
|
||||||
@ -177,7 +178,7 @@ module.exports.config_example = config_example
|
|||||||
players: 100,
|
players: 100,
|
||||||
port: 19132,
|
port: 19132,
|
||||||
port6: 19133
|
port6: 19133
|
||||||
})
|
});
|
||||||
*/
|
*/
|
||||||
module.exports.set_config = config
|
module.exports.set_config = config
|
||||||
/**
|
/**
|
||||||
@ -196,4 +197,4 @@ module.exports.tmphost = require("./lib/tempHost")
|
|||||||
/**
|
/**
|
||||||
* Load Crontab Backup
|
* Load Crontab Backup
|
||||||
*/
|
*/
|
||||||
module.exports.Cron_Loaded = require("./src/Scripts/LoadCronBackup")
|
module.exports.Cron_Loaded = require("./src/LoadCronBackup")
|
@ -6,7 +6,7 @@ const yaml = {
|
|||||||
stringify: require("js-yaml").dump
|
stringify: require("js-yaml").dump
|
||||||
}
|
}
|
||||||
const FetchSync = require("@the-bds-maneger/fetchsync");
|
const FetchSync = require("@the-bds-maneger/fetchsync");
|
||||||
const { external_ip } = require("../src/Scripts/external_ip");
|
const { external_ip } = require("../src/external_ip");
|
||||||
const { valid_platform } = require("./BdsSystemInfo");
|
const { valid_platform } = require("./BdsSystemInfo");
|
||||||
|
|
||||||
// PATHs
|
// PATHs
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
const fetchSync = require("@the-bds-maneger/fetchsync");
|
const fetchSync = require("@the-bds-maneger/fetchsync");
|
||||||
const { external_ip, Interfaces } = require("../src/Scripts/external_ip");
|
const { external_ip, Interfaces } = require("../src/external_ip");
|
||||||
const { GetTempHost } = require("./BdsSettings")
|
const { GetTempHost } = require("./BdsSettings")
|
||||||
|
|
||||||
if (GetTempHost()){
|
if (GetTempHost()){
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
const { CronJob } = require("cron");
|
const { CronJob } = require("cron");
|
||||||
const { GetCronBackup } = require("../../lib/BdsSettings");
|
const { GetCronBackup } = require("../lib/BdsSettings");
|
||||||
const { Backup } = require("./backups")
|
const { Backup } = require("./backups")
|
||||||
const Cloud = {
|
const Cloud = {
|
||||||
Azure: require("../clouds/Azure").Uploadbackups,
|
Azure: require("./clouds/Azure").Uploadbackups,
|
||||||
Driver: require("../clouds/GoogleDriver").Uploadbackups,
|
Driver: require("./clouds/GoogleDriver").Uploadbackups,
|
||||||
Oracle: require("../clouds/OracleCI").Uploadbackups,
|
Oracle: require("./clouds/OracleCI").Uploadbackups,
|
||||||
}
|
}
|
||||||
|
|
||||||
const CurrentBackups = GetCronBackup();
|
const CurrentBackups = GetCronBackup();
|
@ -1,6 +1,6 @@
|
|||||||
const bds = require("../../index")
|
const bds = require("../index")
|
||||||
const { CheckBan } = require("./check");
|
const { CheckBan } = require("./check");
|
||||||
const { GetPlatform, GetPaths } = require("../../lib/BdsSettings");
|
const { GetPlatform, GetPaths } = require("../lib/BdsSettings");
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
|
|
||||||
function MytypeKill(player) {
|
function MytypeKill(player) {
|
@ -1,182 +0,0 @@
|
|||||||
const { exec, execFile } = require("child_process");
|
|
||||||
const fs = require("fs");
|
|
||||||
const path = require("path");
|
|
||||||
const { resolve, join } = require("path");
|
|
||||||
const commandExists = require("../../lib/commandExist");
|
|
||||||
const saveUser = require("./PlayersSave");
|
|
||||||
const bds = require("../../index");
|
|
||||||
const { GetServerPaths, GetPaths, GetServerSettings, GetPlatform } = require("../../lib/BdsSettings");
|
|
||||||
const BdsDetect = require("./CheckKill").Detect;
|
|
||||||
const { randomUUID } = require("crypto");
|
|
||||||
const { warn } = console;
|
|
||||||
|
|
||||||
// Set bdsexec functions
|
|
||||||
global.BdsExecs = {};
|
|
||||||
|
|
||||||
function saveLog(data = "", LogFile = ""){
|
|
||||||
fs.appendFileSync(path.join(GetPaths("log"), "latest.log"), data)
|
|
||||||
fs.appendFileSync(LogFile, data)
|
|
||||||
}
|
|
||||||
function start() {
|
|
||||||
if (BdsDetect()){
|
|
||||||
console.warn("You already have a server running");
|
|
||||||
throw "You already have a server running";
|
|
||||||
} else {
|
|
||||||
var start_server;
|
|
||||||
|
|
||||||
// Minecraft Bedrock Oficial
|
|
||||||
if (GetPlatform() === "bedrock"){
|
|
||||||
if (process.platform === "darwin") throw Error("Use a imagem Docker");
|
|
||||||
else if (process.platform == "win32") start_server = exec("bedrock_server.exe", {
|
|
||||||
cwd: GetServerPaths("bedrock"),
|
|
||||||
});
|
|
||||||
else if (process.platform == "linux"){
|
|
||||||
// Set Executable file
|
|
||||||
execFile("chmod 777 bedrock_server", {cwd: GetServerPaths("bedrock")});
|
|
||||||
var BedrockCommand = "./bedrock_server";
|
|
||||||
|
|
||||||
// Emulation of the x86_64 architecture
|
|
||||||
if (commandExists("qemu-x86_64-static") && process.arch !== "x64") BedrockCommand = "qemu-x86_64-static "+BedrockCommand;
|
|
||||||
|
|
||||||
// Start Bedrock Server
|
|
||||||
start_server = exec(BedrockCommand, {cwd: GetServerPaths("bedrock"), env: {...process.env, LD_LIBRARY_PATH: GetServerPaths("bedrock")}})
|
|
||||||
} else throw new Error("your system does not support Minecraft Bedrock (yet)")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Minecraft Java Oficial
|
|
||||||
else if (GetPlatform() === "java") {
|
|
||||||
const JavaConfig = GetServerSettings("java")
|
|
||||||
|
|
||||||
// Checking if java is installed on the device
|
|
||||||
if (commandExists("java")) {
|
|
||||||
start_server = execFile("java", [
|
|
||||||
"-jar",
|
|
||||||
`-Xms${JavaConfig.ram_mb}M`,
|
|
||||||
`-Xmx${JavaConfig.ram_mb}M`,
|
|
||||||
"MinecraftServerJava.jar",
|
|
||||||
"nogui"
|
|
||||||
], {cwd: GetServerPaths("java")})
|
|
||||||
} else {
|
|
||||||
var url = bds.package_json.docs_base; if (bds.system == "windows") url += "Java-Download#windows"; else if (bds.system === "linux") url = "Java-Download#linux"; else if (process.platform === "darwin") url = "Java-Download#macos"; else url = "Java-Download";
|
|
||||||
require("open")(url);
|
|
||||||
throw new Error(`Open: ${url}`)
|
|
||||||
}
|
|
||||||
} else if (GetPlatform() === "pocketmine") {
|
|
||||||
// Start PocketMine-MP
|
|
||||||
const php_bin_path = join(resolve(GetServerPaths("pocketmine"), "bin", "php7", "bin"), "php");
|
|
||||||
start_server = execFile(php_bin_path, [
|
|
||||||
"./PocketMine-MP.phar"
|
|
||||||
], {
|
|
||||||
cwd: GetServerPaths("pocketmine")
|
|
||||||
})
|
|
||||||
} else if (GetPlatform() === "jsprismarine") {
|
|
||||||
// Start JSPrismarine
|
|
||||||
start_server = execFile("node", [
|
|
||||||
"./packages/server/dist/Server.js"
|
|
||||||
], {
|
|
||||||
cwd: GetServerPaths("jsprismarine")
|
|
||||||
});
|
|
||||||
} else throw Error("Bds Config Error")
|
|
||||||
|
|
||||||
// Post Start
|
|
||||||
if (GetPlatform() === "java") {
|
|
||||||
start_server.stdout.on("data", function(data){
|
|
||||||
if (data.includes("agree"))
|
|
||||||
if (data.includes("EULA")){
|
|
||||||
const eula_file = path.join(GetServerPaths("java"), "eula.txt");
|
|
||||||
fs.writeFileSync(eula_file, fs.readFileSync(eula_file, "utf8").split("eula=false").join("eula=true"));
|
|
||||||
throw new Error("Restart application/CLI")
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Log file
|
|
||||||
const LogFile = join(GetPaths("log"), `${bds.date()}_${GetPlatform()}_Bds_log.log`);
|
|
||||||
// save User in Json
|
|
||||||
start_server.stdout.on("data", data => saveUser(data))
|
|
||||||
start_server.stderr.on("data", data => saveUser(data))
|
|
||||||
// ---------------------------------------------------
|
|
||||||
// Clear latest.log
|
|
||||||
fs.writeFileSync(path.join(GetPaths("log"), "latest.log"), "")
|
|
||||||
|
|
||||||
// ---------------------------------------------------
|
|
||||||
// stdout
|
|
||||||
start_server.stdout.on("data", a=>saveLog(a, LogFile));
|
|
||||||
start_server.stderr.on("data", a=>saveLog(a, LogFile));
|
|
||||||
// ---------------------------------------------------
|
|
||||||
// Global and Run
|
|
||||||
global.bds_log_string = ""
|
|
||||||
start_server.stdout.on("data", function(data){
|
|
||||||
if (global.bds_log_string === undefined || global.bds_log_string === "") global.bds_log_string = data; else global.bds_log_string += data
|
|
||||||
});
|
|
||||||
global.bds_server_string = start_server;
|
|
||||||
|
|
||||||
// Functions return
|
|
||||||
const returnFuntion = {
|
|
||||||
uuid: randomUUID(),
|
|
||||||
exec: start_server,
|
|
||||||
stop: function (){start_server.stdin.write("stop\n")},
|
|
||||||
command: function (command = "list", callback){
|
|
||||||
const oldLog = global.bds_log_string;
|
|
||||||
start_server.stdin.write(`${command}\n`);
|
|
||||||
if (typeof callback === "function") {
|
|
||||||
setTimeout(() => {
|
|
||||||
// Run commands from command run in server;
|
|
||||||
const log = global.bds_log_string.replace(oldLog, "").split(/\r/).filter(data => {if (data === "") return false; else return true;}).join("\n")
|
|
||||||
if (log.length >= 1) callback(log); else callback("no log")
|
|
||||||
}, 1555);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
log: function (logCallback = function(data = ""){data.split("\n").filter(d=>{return (d !== "")}).forEach(l=>console.log(l))}){
|
|
||||||
if (typeof logCallback !== "function") {
|
|
||||||
warn("The log callback is not a function using console.log");
|
|
||||||
logCallback = function(data = ""){data.split("\n").filter(d=>{return (d !== "")}).forEach(l=>console.log(l))}
|
|
||||||
}
|
|
||||||
start_server.stdout.on("data", data => logCallback(data));
|
|
||||||
start_server.stderr.on("data", data => logCallback(data));
|
|
||||||
},
|
|
||||||
exit: function (exitCallback = process.exit){if (
|
|
||||||
typeof exitCallback === "function") start_server.on("exit", code => exitCallback(code));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
start_server.on("exit", ()=>{delete global.BdsExecs[returnFuntion.uuid]})
|
|
||||||
global.BdsExecs[returnFuntion.uuid] = returnFuntion
|
|
||||||
return returnFuntion
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function GetSessions(){
|
|
||||||
const ArraySessions = Object.getOwnPropertyNames(global.BdsExecs)
|
|
||||||
if (ArraySessions.length === 0) throw "Start Server";
|
|
||||||
if (ArraySessions.length >= 2) throw "Select a session manually:" + ArraySessions.join(", ")
|
|
||||||
return global.BdsExecs[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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function stop(SessionID = null) {
|
|
||||||
try {
|
|
||||||
var Session = {}
|
|
||||||
if (!(SessionID)) Session = GetSessions(); else Session = global.BdsExecs[SessionID]
|
|
||||||
Session.stop()
|
|
||||||
return true
|
|
||||||
} catch (error) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
start,
|
|
||||||
BdsCommand,
|
|
||||||
stop
|
|
||||||
}
|
|
@ -2,7 +2,7 @@ var fs = require("fs");
|
|||||||
const path = require("path");
|
const path = require("path");
|
||||||
const propertiesToJSON = require("properties-to-json");
|
const propertiesToJSON = require("properties-to-json");
|
||||||
const { join } = require("path");
|
const { join } = require("path");
|
||||||
const { GetServerPaths, GetPlatform } = require("../../lib/BdsSettings");
|
const { GetServerPaths, GetPlatform } = require("../lib/BdsSettings");
|
||||||
const bds_dir_bedrock = GetServerPaths("bedrock"), bds_dir_java = GetServerPaths("java"), bds_dir_pocketmine = GetServerPaths("pocketmine");
|
const bds_dir_bedrock = GetServerPaths("bedrock"), bds_dir_java = GetServerPaths("java"), bds_dir_pocketmine = GetServerPaths("pocketmine");
|
||||||
const bedrockCPUThread = require("os").cpus().length;
|
const bedrockCPUThread = require("os").cpus().length;
|
||||||
|
|
@ -1,8 +1,8 @@
|
|||||||
const bds = require("../../index")
|
const bds = require("../index")
|
||||||
const { join, resolve } = require("path");
|
const { join, resolve } = require("path");
|
||||||
const { readdirSync, existsSync, readFileSync, statSync } = require("fs")
|
const { readdirSync, existsSync, readFileSync, statSync } = require("fs")
|
||||||
const AdmZip = require("adm-zip");
|
const AdmZip = require("adm-zip");
|
||||||
const { GetServerPaths, GetPaths, bds_dir } = require("../../lib/BdsSettings")
|
const { GetServerPaths, GetPaths, bds_dir } = require("../lib/BdsSettings")
|
||||||
|
|
||||||
function Backup() {
|
function Backup() {
|
||||||
const zip = new AdmZip();
|
const zip = new AdmZip();
|
188
src/basic_server.js
Normal file
188
src/basic_server.js
Normal file
@ -0,0 +1,188 @@
|
|||||||
|
const { exec, execFile } = require("child_process");
|
||||||
|
const fs = require("fs");
|
||||||
|
const path = require("path");
|
||||||
|
const { resolve, join } = require("path");
|
||||||
|
const { randomUUID } = require("crypto");
|
||||||
|
|
||||||
|
// Bds Maneger Inports
|
||||||
|
const commandExists = require("../lib/commandExist");
|
||||||
|
const BdsDetect = require("./CheckKill").Detect;
|
||||||
|
const saveUser = require("./PlayersSave");
|
||||||
|
const bds = require("../index");
|
||||||
|
const { GetServerPaths, GetPaths, GetServerSettings, GetPlatform } = require("../lib/BdsSettings");
|
||||||
|
const BdsInfo = require("../BdsManegerInfo.json");
|
||||||
|
|
||||||
|
// Set bdsexec functions
|
||||||
|
global.BdsExecs = {};
|
||||||
|
|
||||||
|
function saveLog(data = "", LogFile = ""){
|
||||||
|
fs.appendFileSync(path.join(GetPaths("log"), "latest.log"), data)
|
||||||
|
fs.appendFileSync(LogFile, data)
|
||||||
|
}
|
||||||
|
|
||||||
|
function start() {
|
||||||
|
if (BdsDetect()){
|
||||||
|
let ErrorReturn = "You already have a server running";
|
||||||
|
console.warn(ErrorReturn);
|
||||||
|
throw new Error(ErrorReturn);
|
||||||
|
}
|
||||||
|
var ServerExec;
|
||||||
|
|
||||||
|
// Minecraft Bedrock Oficial
|
||||||
|
if (GetPlatform() === "bedrock"){
|
||||||
|
if (process.platform === "darwin") throw new Error("Use a imagem Docker");
|
||||||
|
else if (process.platform == "win32") ServerExec = execFile("bedrock_server.exe", {
|
||||||
|
cwd: GetServerPaths("bedrock"),
|
||||||
|
});
|
||||||
|
else if (process.platform == "linux"){
|
||||||
|
// Set Executable file
|
||||||
|
execFile("chmod 777 bedrock_server", {cwd: GetServerPaths("bedrock")});
|
||||||
|
var BedrockCommand = "./bedrock_server";
|
||||||
|
|
||||||
|
// Emulation of the x86_64 architecture
|
||||||
|
if (commandExists("qemu-x86_64-static") && process.arch !== "x64") BedrockCommand = "qemu-x86_64-static "+BedrockCommand;
|
||||||
|
|
||||||
|
// Start Bedrock Server
|
||||||
|
ServerExec = exec(BedrockCommand, {cwd: GetServerPaths("bedrock"), env: {...process.env, LD_LIBRARY_PATH: GetServerPaths("bedrock")}})
|
||||||
|
} else throw new Error("your system does not support Minecraft Bedrock (yet)")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Minecraft Java Oficial
|
||||||
|
else if (GetPlatform() === "java") {
|
||||||
|
const JavaConfig = GetServerSettings("java")
|
||||||
|
|
||||||
|
// Checking if java is installed on the device
|
||||||
|
if (commandExists("java")) {
|
||||||
|
ServerExec = execFile("java", [
|
||||||
|
"-jar",
|
||||||
|
`-Xms${JavaConfig.ram_mb}M`,
|
||||||
|
`-Xmx${JavaConfig.ram_mb}M`,
|
||||||
|
"MinecraftServerJava.jar",
|
||||||
|
"nogui"
|
||||||
|
], {cwd: GetServerPaths("java")})
|
||||||
|
} else {
|
||||||
|
var url = bds.package_json.docs_base; if (bds.system == "windows") url += "Java-Download#windows"; else if (bds.system === "linux") url = "Java-Download#linux"; else if (process.platform === "darwin") url = "Java-Download#macos"; else url = "Java-Download";
|
||||||
|
require("open")(url);
|
||||||
|
throw new Error(`Open: ${url}`)
|
||||||
|
}
|
||||||
|
} else if (GetPlatform() === "pocketmine") {
|
||||||
|
// Start PocketMine-MP
|
||||||
|
const php_bin_path = join(resolve(GetServerPaths("pocketmine"), "bin", "php7", "bin"), "php");
|
||||||
|
ServerExec = execFile(php_bin_path, [
|
||||||
|
"./PocketMine-MP.phar"
|
||||||
|
], {
|
||||||
|
cwd: GetServerPaths("pocketmine")
|
||||||
|
})
|
||||||
|
} else if (GetPlatform() === "jsprismarine") {
|
||||||
|
// Start JSPrismarine
|
||||||
|
ServerExec = execFile("node", [
|
||||||
|
"./packages/server/dist/Server.js"
|
||||||
|
], {
|
||||||
|
cwd: GetServerPaths("jsprismarine")
|
||||||
|
});
|
||||||
|
} else throw Error("Bds Config Error")
|
||||||
|
|
||||||
|
// Post Start
|
||||||
|
if (GetPlatform() === "java") {
|
||||||
|
ServerExec.stdout.on("data", function(data){
|
||||||
|
if (data.includes("agree"))
|
||||||
|
if (data.includes("EULA")){
|
||||||
|
const eula_file = path.join(GetServerPaths("java"), "eula.txt");
|
||||||
|
fs.writeFileSync(eula_file, fs.readFileSync(eula_file, "utf8").split("eula=false").join("eula=true"));
|
||||||
|
throw new Error("Restart application/CLI")
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Log file
|
||||||
|
const LogFile = join(GetPaths("log"), `${bds.date()}_${GetPlatform()}_Bds_log.log`);
|
||||||
|
// save User in Json
|
||||||
|
ServerExec.stdout.on("data", data => saveUser(data))
|
||||||
|
ServerExec.stderr.on("data", data => saveUser(data))
|
||||||
|
// ---------------------------------------------------
|
||||||
|
// Clear latest.log
|
||||||
|
fs.writeFileSync(path.join(GetPaths("log"), "latest.log"), "")
|
||||||
|
|
||||||
|
// ---------------------------------------------------
|
||||||
|
// stdout
|
||||||
|
ServerExec.stdout.on("data", a=>saveLog(a, LogFile));
|
||||||
|
ServerExec.stderr.on("data", a=>saveLog(a, LogFile));
|
||||||
|
// ---------------------------------------------------
|
||||||
|
// Global and Run
|
||||||
|
global.bds_log_string = ""
|
||||||
|
ServerExec.stdout.on("data", function(data){
|
||||||
|
if (global.bds_log_string === undefined || global.bds_log_string === "") global.bds_log_string = data; else global.bds_log_string += data
|
||||||
|
});
|
||||||
|
global.bds_server_string = ServerExec;
|
||||||
|
|
||||||
|
// Functions return
|
||||||
|
const returnFuntion = {
|
||||||
|
uuid: randomUUID(),
|
||||||
|
exec: ServerExec,
|
||||||
|
stop: function (){
|
||||||
|
ServerExec.stdin.write(BdsInfo.Servers[GetPlatform()].stop);
|
||||||
|
return BdsInfo.Servers[GetPlatform()].stop;
|
||||||
|
},
|
||||||
|
command: function (command = "list", callback){
|
||||||
|
const oldLog = global.bds_log_string;
|
||||||
|
ServerExec.stdin.write(`${command}\n`);
|
||||||
|
if (typeof callback === "function") {
|
||||||
|
setTimeout(() => {
|
||||||
|
// Run commands from command run in server;
|
||||||
|
const log = global.bds_log_string.replace(oldLog, "").split(/\r/).filter(data => {if (data === "") return false; else return true;}).join("\n")
|
||||||
|
if (log.length >= 1) callback(log); else callback("no log")
|
||||||
|
}, 1555);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
log: function (logCallback = function(data = ""){data.split("\n").filter(d=>{return (d !== "")}).forEach(l=>console.log(l))}){
|
||||||
|
if (typeof logCallback !== "function") {
|
||||||
|
console.warn("The log callback is not a function using console.log");
|
||||||
|
logCallback = function(data = ""){data.split("\n").filter(d=>{return (d !== "")}).forEach(l=>console.log(l))}
|
||||||
|
}
|
||||||
|
ServerExec.stdout.on("data", data => logCallback(data));
|
||||||
|
ServerExec.stderr.on("data", data => logCallback(data));
|
||||||
|
},
|
||||||
|
exit: function (exitCallback = process.exit){if (
|
||||||
|
typeof exitCallback === "function") ServerExec.on("exit", code => exitCallback(code));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ServerExec.on("exit", ()=>{delete global.BdsExecs[returnFuntion.uuid]});
|
||||||
|
global.BdsExecs[returnFuntion.uuid] = returnFuntion;
|
||||||
|
return returnFuntion;
|
||||||
|
}
|
||||||
|
|
||||||
|
function GetSessions(){
|
||||||
|
const ArraySessions = Object.getOwnPropertyNames(global.BdsExecs)
|
||||||
|
if (ArraySessions.length === 0) throw "Start Server";
|
||||||
|
if (ArraySessions.length >= 2) throw "Select a session manually:" + ArraySessions.join(", ")
|
||||||
|
return global.BdsExecs[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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function stop(SessionID = null) {
|
||||||
|
try {
|
||||||
|
var Session = {}
|
||||||
|
if (!(SessionID)) Session = GetSessions(); else Session = global.BdsExecs[SessionID]
|
||||||
|
Session.stop()
|
||||||
|
return true
|
||||||
|
} catch (error) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
start,
|
||||||
|
BdsCommand,
|
||||||
|
stop
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
const { bds_dir, GetServerBan, GetTelegramAdmins, GetPlatform, GetPaths } = require("../../lib/BdsSettings");
|
const { bds_dir, GetServerBan, GetTelegramAdmins, GetPlatform, GetPaths } = require("../lib/BdsSettings");
|
||||||
const { existsSync, readFileSync } = require("fs")
|
const { existsSync, readFileSync } = require("fs")
|
||||||
const { join } = require("path")
|
const { join } = require("path")
|
||||||
|
|
@ -8,7 +8,7 @@ var cors = require("cors");
|
|||||||
const rateLimit = require("express-rate-limit");
|
const rateLimit = require("express-rate-limit");
|
||||||
const bodyParser = require("body-parser");
|
const bodyParser = require("body-parser");
|
||||||
const fetchSync = require("@the-bds-maneger/fetchsync");
|
const fetchSync = require("@the-bds-maneger/fetchsync");
|
||||||
const Ips = require("../../Scripts/external_ip");
|
const Ips = require("../../external_ip");
|
||||||
const DefaultLoginDrive = {
|
const DefaultLoginDrive = {
|
||||||
access_type: "offline",
|
access_type: "offline",
|
||||||
scope: [
|
scope: [
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
var AdmZip = require("adm-zip");
|
var AdmZip = require("adm-zip");
|
||||||
const { writeFileSync, existsSync, readFileSync, readdirSync } = require("fs");
|
const { writeFileSync, existsSync, readFileSync, readdirSync } = require("fs");
|
||||||
const { join, resolve } = require("path");
|
const { join, resolve } = require("path");
|
||||||
const bds = require("../../index")
|
const bds = require("../index")
|
||||||
const { valid_platform } = require("../../lib/BdsSystemInfo");
|
const { valid_platform } = require("../lib/BdsSystemInfo");
|
||||||
const { GetServerPaths, GetServerVersion, UpdateServerVersion, GetPlatform } = require("../../lib/BdsSettings");
|
const { GetServerPaths, GetServerVersion, UpdateServerVersion, GetPlatform } = require("../lib/BdsSettings");
|
||||||
const { GitClone } = require("../../lib/git_simples");
|
const { GitClone } = require("../lib/git_simples");
|
||||||
const { execSync } = require("child_process");
|
const { execSync } = require("child_process");
|
||||||
const Extra = require("../../BdsManegerInfo.json");
|
const Extra = require("../BdsManegerInfo.json");
|
||||||
|
|
||||||
const
|
const
|
||||||
bds_dir_bedrock = GetServerPaths("bedrock"),
|
bds_dir_bedrock = GetServerPaths("bedrock"),
|
@ -5,7 +5,7 @@ const commandExist = require("../../../lib/commandExist");
|
|||||||
const { GetPlatform, GetServerVersion, UpdatePlatform, bds_dir } = require("../../../lib/BdsSettings")
|
const { GetPlatform, GetServerVersion, UpdatePlatform, bds_dir } = require("../../../lib/BdsSettings")
|
||||||
const admzip = require("adm-zip");
|
const admzip = require("adm-zip");
|
||||||
const bds = require("../../../index");
|
const bds = require("../../../index");
|
||||||
const { token_verify } = require("../../Scripts/check");
|
const { token_verify } = require("../../check");
|
||||||
|
|
||||||
// Backup
|
// Backup
|
||||||
app.get("/backup", (req, res) => {
|
app.get("/backup", (req, res) => {
|
||||||
|
@ -2,7 +2,7 @@ const express = require("express");
|
|||||||
const app = express.Router();
|
const app = express.Router();
|
||||||
const { GetPlatform } = require("../../../lib/BdsSettings")
|
const { GetPlatform } = require("../../../lib/BdsSettings")
|
||||||
const bds = require("../../../index");
|
const bds = require("../../../index");
|
||||||
const { token_verify, CheckPlayer } = require("../../Scripts/check");
|
const { token_verify, CheckPlayer } = require("../../check");
|
||||||
const { readFileSync } = require("fs");
|
const { readFileSync } = require("fs");
|
||||||
const docs = require("../../../BdsManegerInfo.json").docs;
|
const docs = require("../../../BdsManegerInfo.json").docs;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user