Merge #31

Merged
Sirherobrine23 merged 14 commits from main into stable 2021-02-09 17:53:17 +00:00
21 changed files with 4009 additions and 309 deletions
Showing only changes of commit 84c7186df6 - Show all commits

View File

@ -6,6 +6,10 @@
"node": true, "node": true,
"shelljs": true "shelljs": true
}, },
"globals": {
"bds_log_string": "writable",
"bds_server_string": "writable"
},
"extends": "eslint:recommended", "extends": "eslint:recommended",
"parserOptions": { "parserOptions": {
"ecmaVersion": 12, "ecmaVersion": 12,
@ -15,7 +19,10 @@
} }
}, },
"rules": { "rules": {
"quotes": ["error", "double"], "quotes": [
"error",
"double"
],
"eqeqeq": 0 "eqeqeq": 0
} }
} }

View File

@ -1,11 +1,11 @@
module.exports = () => { module.exports = () => {
global.bds_api_start = true: global.bds_api_start = true;
const express = require("express"); const express = require("express");
const bds = require("../index"); const bds = require("../index");
const fs = require("fs"); const fs = require("fs");
const app = express(); const app = express();
const path = require("path"); const path = require("path");
var cors = require('cors'); var cors = require("cors");
const rateLimit = require("express-rate-limit"); const rateLimit = require("express-rate-limit");
// Enable if you're behind a reverse proxy (Heroku, Bluemix, AWS ELB, Nginx, etc) // Enable if you're behind a reverse proxy (Heroku, Bluemix, AWS ELB, Nginx, etc)
@ -33,7 +33,7 @@ module.exports = () => {
} else { } else {
v++; v++;
} }
}; }
const config = bds.get_config() const config = bds.get_config()
var json_http = { var json_http = {
"server": { "server": {
@ -52,7 +52,7 @@ module.exports = () => {
return res.send(json_http); return res.send(json_http);
}); });
app.get("/", (req, res) => { app.get("/", (req, res) => {
return res.send(`Hello, welcome to the Bds Maneger API, If this page has loaded it means that the API is working as planned, More information access the API documentation at: https://docs.srherobrine23.com/bds-maneger-api_whatis.html, Version: ${require(__dirname+'/../package.json').version}`); return res.send(`Hello, welcome to the Bds Maneger API, If this page has loaded it means that the API is working as planned, More information access the API documentation at: https://docs.srherobrine23.com/bds-maneger-api_whatis.html, Version: ${require(path.join(__dirname, "..", "package.json")).version}`);
}); });
app.post("/service", (req, res) => { app.post("/service", (req, res) => {
const body = req.body const body = req.body
@ -68,14 +68,15 @@ module.exports = () => {
} }
} }
if (pass){ if (pass){
if (command_bds === 'start'){ var command_status
if (command_bds === "start"){
bds.start() bds.start()
var command_status = `Bds Started` command_status = "Bds Started"
} else if (command_bds === 'stop'){ } else if (command_bds === "stop"){
bds.stop() bds.stop()
var command_status = `Stopping the bds server` command_status = "Stopping the bds server"
} else { } else {
var command_status = `no command identified` command_status = "no command identified"
} }
res.send({ res.send({
"status": 200, "status": 200,
@ -101,12 +102,13 @@ module.exports = () => {
token_verify++ token_verify++
} }
} }
var STA,EMN
if (pass){ if (pass){
var STA = `wait` STA = "wait"
var EMN = bds.download(ver) EMN = bds.download(ver)
} else { } else {
var STA = `401`, STA = "401",
EMN = `Unauthorized Token` EMN = "Unauthorized Token"
} }
res.send({ res.send({
"status": STA, "status": STA,

View File

@ -20,19 +20,22 @@ module.exports = () => {
const requestIp = require("request-ip"); const requestIp = require("request-ip");
app.use(requestIp.mw()) app.use(requestIp.mw())
app.get("/", (req, res) => { app.get("/", (req, res) => {
var text="";
var log_file="";
var sucess="";
if (typeof bds_log_string === "undefined"){ if (typeof bds_log_string === "undefined"){
if (fs.existsSync(localStorage.getItem("old_log_file"))){ if (fs.existsSync(localStorage.getItem("old_log_file"))){
var text = `${fs.readFileSync(localStorage.getItem("old_log_file"), "utf8")}` text = `${fs.readFileSync(localStorage.getItem("old_log_file"), "utf8")}`
var log_file = localStorage.getItem("old_log_file") log_file = localStorage.getItem("old_log_file")
var sucess = true sucess = true
} else { } else {
var text = "The server is stopped" text = "The server is stopped"
var sucess = false sucess = false
} }
} else { } else {
var text = bds_log_string text = bds_log_string
var log_file = "string" log_file = "string"
var sucess = true sucess = true
} }
res.json({ res.json({
"sucess": sucess, "sucess": sucess,

View File

@ -55,13 +55,14 @@ module.exports.drive_backup = () => {
console.log(gd_secret) console.log(gd_secret)
function upload_backup(auth) { function upload_backup(auth) {
const drive = google.drive({version: "v3", auth}); const drive = google.drive({version: "v3", auth});
var fileMetadata;
if (parent_id === undefined){ if (parent_id === undefined){
var fileMetadata = { fileMetadata = {
name: name_d name: name_d
} }
console.log("Your backup will be saved to My Drive") console.log("Your backup will be saved to My Drive")
} else { } else {
var fileMetadata = { fileMetadata = {
name: name_d, name: name_d,
parents: [parent_id] parents: [parent_id]
} }

View File

@ -1,14 +1,21 @@
module.exports.checkUser = (USERNAME) => { module.exports.checkUser = (USERNAME) => {
const fs = require("fs") const fs = require("fs")
if (fs.existsSync(`${require("../index").bds_dir}/telegram_admin.json`)) { const path = require("path")
var admins = fs.readFileSync(`${require("../index").bds_dir}/telegram_admin.json`, "utf-8"); const bds = require("../index")
const telegram_admin = path.join(bds.bds_dir, "telegram_admin.json")
if (fs.existsSync(telegram_admin)) {
var admins = fs.readFileSync(telegram_admin, "utf-8");
} else { } else {
var admins = "{\"sh23_bot_not_config\": {\"allow\": true}}"; const config = {
console.warn("All allowed") "sh23_bot_not_config": {
console.log(`Create file in with name: ${require("../index").bds_dir}/telegram_admin.json`) "allow": true
}
}
fs.writeFileSync(telegram_admin, JSON.stringify(config))
throw new console.error(`we just created the telegram authorization, edit before using: ${config}`);
} }
var adm = JSON.parse(admins); var adm = JSON.parse(admins);
for(check_ in adm){ for(let check_ in adm){
if (USERNAME == check_){ if (USERNAME == check_){
return true return true
} else if (check_ == "sh23_bot_not_config"){ } else if (check_ == "sh23_bot_not_config"){

View File

@ -33,7 +33,7 @@ bot.command("server_start", (ctx) => {
ctx.reply(`${ctx.message.from.username} already started`) ctx.reply(`${ctx.message.from.username} already started`)
} else { } else {
console.log("Erro"); console.log("Erro");
ctx.reply(`Please contact the Server Administrator, You are not on the list, I count to add your username \(${ctx.message.from.username}\) on the whitelist`) ctx.reply(`Please contact the Server Administrator, You are not on the list, I count to add your username (${ctx.message.from.username}) on the whitelist`)
} }
}); });
bot.command("server_stop", (ctx) => { bot.command("server_stop", (ctx) => {
@ -46,7 +46,7 @@ bot.command("server_stop", (ctx) => {
ctx.reply(`${ctx.message.from.username} o servidor está parado`) ctx.reply(`${ctx.message.from.username} o servidor está parado`)
} else { } else {
console.log("Erro"); console.log("Erro");
ctx.reply(`Please contact the Server Administrator, You are not on the list, I count to add your username \(${ctx.message.from.username}\) on the whitelist`) ctx.reply(`Please contact the Server Administrator, You are not on the list, I count to add your username (${ctx.message.from.username}) on the whitelist`)
} }
}); });
bot.command("command", (ctx) =>{ bot.command("command", (ctx) =>{

View File

@ -1,3 +1,4 @@
/* eslint-disable no-irregular-whitespace */
console.log(`Running the Bds Maneger API in version ${require(__dirname+"/package.json").version}`) console.log(`Running the Bds Maneger API in version ${require(__dirname+"/package.json").version}`)
var shell = require("shelljs"); var shell = require("shelljs");
let blanks; let blanks;
@ -14,10 +15,11 @@ function date(fu) {
else else
return `${String(today.getDate()).padStart(2, "0")}-${String(today.getMonth() + 1).padStart(2, "0")}-${today.getFullYear()}_${today.getHours()}-${today.getSeconds()}` return `${String(today.getDate()).padStart(2, "0")}-${String(today.getMonth() + 1).padStart(2, "0")}-${today.getFullYear()}_${today.getHours()}-${today.getSeconds()}`
} }
var electron_de
if (process.argv[0].includes("electron")){ if (process.argv[0].includes("electron")){
var electron_de = true; electron_de = true;
} else if (process.argv[0].includes("node")){ } else if (process.argv[0].includes("node")){
var electron_de = undefined; electron_de = undefined;
if (process.env.BDS_MONI == blanks){ if (process.env.BDS_MONI == blanks){
process.env.BDS_MONI = true process.env.BDS_MONI = true
} }
@ -28,50 +30,60 @@ if (process.argv[0].includes("electron")){
// process.env.ENABLE_BDS_API // process.env.ENABLE_BDS_API
} else { } else {
var electron_de = false; electron_de = false;
} }
const arch = process.arch const arch = process.arch
if (arch == "x64"){ var archi = arch
var archi = "amd64"
} else if (arch == "arm64"){
console.warn("It is not recommended to use platforms that are not amd64 (x64), please inform you that you will need to manually configure some things. \!\!")
var archi = "arm"
} else {
console.warn(`Unsupported processor, ${arch} will not be supported by The Bds Maneger`)
}
const path = require("path") const path = require("path")
const fs = require("fs"); const fs = require("fs");
const { error } = require("console"); const { error } = require("console");
const package_root = path.join(process.cwd(), "package.json") const package_root = path.join(process.cwd(), "package.json")
const package_root_builder = path.resolve(".", "resources", "app", "package.json") const package_root_builder = path.resolve(".", "resources", "app", "package.json")
var cache_dir,home,desktop,tmp,system
if (process.platform == "win32") { if (process.platform == "win32") {
var home = process.env.USERPROFILE; home = process.env.USERPROFILE;
var desktop = path.join(home, "Desktop") desktop = path.join(home, "Desktop")
if (fs.existsSync(package_root)){ if (fs.existsSync(package_root)){
var cache_dir = path.join(home, "AppData", "Roaming", require(package_root).name) cache_dir = path.join(home, "AppData", "Roaming", require(package_root).name)
} else if (package_root_builder){ } else if (package_root_builder){
var cache_dir = path.join(home, "AppData", "Roaming", require(package_root_builder).name) cache_dir = path.join(home, "AppData", "Roaming", require(package_root_builder).name)
} else { } else {
console.warn("Temporary Storages, some functions will be lost after restarting the system"); console.warn("Temporary Storages, some functions will be lost after restarting the system");
var cache_dir = path.join(process.env.TMP, "bds_tmp_configs"); cache_dir = path.join(process.env.TMP, "bds_tmp_configs");
} }
var tmp = process.env.TMP tmp = process.env.TMP
var system = "windows"; system = "windows";
} else if (process.platform == "linux") { } else if (process.platform == "linux") {
var home = process.env.HOME; home = process.env.HOME;
if (fs.existsSync(package_root)){ if (fs.existsSync(package_root)){
var cache_dir = path.join(home, ".config", require(package_root).name); cache_dir = path.join(home, ".config", require(package_root).name);
} else if (fs.existsSync(package_root_builder)) { } else if (fs.existsSync(package_root_builder)) {
var cache_dir = path.join(home, ".config", require(package_root_builder).name); cache_dir = path.join(home, ".config", require(package_root_builder).name);
} else { } else {
console.warn("Temporary Storages, some functions will be lost after restarting the system"); console.warn("Temporary Storages, some functions will be lost after restarting the system");
var cache_dir = "/tmp/bds_tmp_configs"; cache_dir = "/tmp/bds_tmp_configs";
} }
var file = path.join(home, ".config", "user-dirs.dirs");var data = {}; var file = path.join(home, ".config", "user-dirs.dirs");var data = {};
if (fs.existsSync(file)){let content = fs.readFileSync(file,"utf8");let lines = content.split(/\r?\n/g).filter((a)=> !a.startsWith("#"));for(let line of lines){let i = line.indexOf("=");if(i >= 0){try{data[line.substring(0,i)] = JSON.parse(line.substring(i + 1))}catch(e){}}}}if(data["XDG_DESKTOP_DIR"]){var desktop = data["XDG_DESKTOP_DIR"];desktop = desktop.replace(/\$([A-Za-z\-\_]+)|\$\{([^\{^\}]+)\}/g, (_, a, b) => (process.env[a || b] || ""))}else{var desktop = "/tmp"} if (fs.existsSync(file)){
let content = fs.readFileSync(file,"utf8");
let lines = content.split(/\r?\n/g).filter((a)=> !a.startsWith("#"));
for(let line of lines){
let i = line.indexOf("=");
if(i >= 0){
try{data[line.substring(0,i)] = JSON.parse(line.substring(i + 1))}
catch(e){
error(e)
}
}
}
}
if(data["XDG_DESKTOP_DIR"]){
desktop = data["XDG_DESKTOP_DIR"];
desktop = desktop.replace(/\$([A-Za-z\-_]+)|\$\{([^{^}]+)\}/g, (_, a, b) => (process.env[a || b] || ""))}
else{desktop = "/tmp"}
var tmp = "/tmp"; tmp = "/tmp";
var system = "linux"; system = "linux";
} else if (process.platform == "darwin") { } else if (process.platform == "darwin") {
require("open")("https://github.com/Bds-Maneger/Bds_Maneger/wiki/systems-support#a-message-for-mac-os-users") require("open")("https://github.com/Bds-Maneger/Bds_Maneger/wiki/systems-support#a-message-for-mac-os-users")
console.error("Please use Windows or Linux MacOS Not yet supported") console.error("Please use Windows or Linux MacOS Not yet supported")
@ -113,7 +125,7 @@ if (fs.existsSync(bds_config_file)){
fs.writeFileSync(bds_config_file, JSON.stringify(bds_config)) fs.writeFileSync(bds_config_file, JSON.stringify(bds_config))
} }
module.exports.platform = bds_config.bds_platform module.exports.platform = bds_config.bds_platform
console.log(`Running on the \"${bds_config.bds_platform}\" platform`) console.log(`Running on the "${bds_config.bds_platform}" platform`)
// Configs // Configs
var log_dir = path.join(bds_dir, "log"); var log_dir = path.join(bds_dir, "log");
@ -161,9 +173,11 @@ if (!(fs.existsSync(log_dir))){
* @example change_platform("bedrock") * @example change_platform("bedrock")
*/ */
function platform_update(plate){ function platform_update(plate){
var complet_;
if (plate === "java") complet_ = true if (plate === "java") complet_ = true
else if (plate === "bedrock") complet_ = true else if (plate === "bedrock") complet_ = true
else throw new console.error(`platform not identified or does not exist, ${plate} informed platform`); else throw new console.error(`platform not identified or does not exist, ${plate} informed platform`);
localStorage.setItem("nulle", complet_)
const bds_config = path.join(bds_dir, "bds_config.json") const bds_config = path.join(bds_dir, "bds_config.json")
try { try {
const config_load = JSON.parse(fs.readFileSync(bds_config)) const config_load = JSON.parse(fs.readFileSync(bds_config))
@ -193,7 +207,7 @@ module.exports.telegram_token_save = (token) =>{
} }
if (require("fs").existsSync(path.join(bds_dir, "telegram_token.txt"))){ if (require("fs").existsSync(path.join(bds_dir, "telegram_token.txt"))){
console.log(`We identified the old telegram token file \(${path.join (bds_dir, "telegram_token.txt")}\), starting the immigration process`) console.log(`We identified the old telegram token file (${path.join (bds_dir, "telegram_token.txt")}), starting the immigration process`)
try { try {
const token = fs.readFileSync(path.join(bds_dir, "telegram_token.txt"), "utf-8").split("\n").join("") const token = fs.readFileSync(path.join(bds_dir, "telegram_token.txt"), "utf-8").split("\n").join("")
require("./index").telegram_token_save(token) require("./index").telegram_token_save(token)
@ -233,7 +247,7 @@ fetch("https://raw.githubusercontent.com/Bds-Maneger/Raw_files/main/Server.json"
const versions = Object.getOwnPropertyNames(rawOUT.bedrock); const versions = Object.getOwnPropertyNames(rawOUT.bedrock);
for (let v in versions){ for (let v in versions){
var html = `${versions[v]}`; var html = `${versions[v]}`;
module.exports.version_select += `<option value=\"${html}\">${html}</option>\n`; module.exports.version_select += `<option value="${html}">${html}</option>\n`;
v++; v++;
} }
module.exports.bedrock_all_versions = Object.getOwnPropertyNames(rawOUT.bedrock); module.exports.bedrock_all_versions = Object.getOwnPropertyNames(rawOUT.bedrock);
@ -317,15 +331,16 @@ module.exports.token_register = () => {
var token = buffer.toString("hex"); var token = buffer.toString("hex");
console.log(token); console.log(token);
var QRCode = require("qrcode"); var QRCode = require("qrcode");
QRCode.toString(token, function (err, url) { QRCode.toString(token, function (err) {
if (err){console.log(err);}
fs.readFile(path.join(bds_dir, "bds_tokens.json"), "utf8", function (err, data){ fs.readFile(path.join(bds_dir, "bds_tokens.json"), "utf8", function (err, data){
if (err){console.log(err);} if (err){console.log(err);}
else { else {
objeto = JSON.parse(data); var objeto = JSON.parse(data);
var count = Object.keys(obj).length; var count = Object.keys(objeto).length;
var teste = {count, token}; var teste = {count, token};
objeto.push(teste); objeto.push(teste);
json_ = JSON.stringify(objeto); var json_ = JSON.stringify(objeto);
fs.writeFileSync(path.join(bds_dir, "bds_tokens.json"), json_, "utf8");} fs.writeFileSync(path.join(bds_dir, "bds_tokens.json"), json_, "utf8");}
}); });
}) })

View File

@ -7,11 +7,12 @@ module.exports.World_BAckup = () => {
var today = bds.date() var today = bds.date()
const name = path.join(bds.backup_folder ,`bds_backup_World_${today}.zip`) const name = path.join(bds.backup_folder ,`bds_backup_World_${today}.zip`)
var dir_zip;
if (bds.platform === "bedrock"){ if (bds.platform === "bedrock"){
var dir_zip = path.join(bds_dir_bedrock, "worlds") //`${require("../index").}/worlds/` dir_zip = path.join(bds.bds_dir_bedrock, "worlds") //`${require("../index").}/worlds/`
} else { } else {
const world_name = JSON.parse(java_pro(fs.readFileSync(path.join(bds.bds_dir_java, "server.properties"), "utf-8").replaceAll("-", "_"))).level_name const world_name = JSON.parse(java_pro(fs.readFileSync(path.join(bds.bds_dir_java, "server.properties"), "utf-8").replaceAll("-", "_"))).level_name
var dir_zip = path.join(bds.bds_dir_java, world_name) //`${require("../index").bds_dir_bedrock}/${world_name}/` dir_zip = path.join(bds.bds_dir_java, world_name) //`${require("../index").bds_dir_bedrock}/${world_name}/`
} }
/** /**
* Before we can start it is good for the server not to have a Corrupted Backup * Before we can start it is good for the server not to have a Corrupted Backup
@ -41,30 +42,22 @@ module.exports.Drive_backup = () => {
var today = bds.date() var today = bds.date()
const name = path.join(bds.backup_folder ,`bds_backup_World_${today}.zip`) const name = path.join(bds.backup_folder ,`bds_backup_World_${today}.zip`)
var dir_zip;
if (bds.platform === "bedrock"){ if (bds.platform === "bedrock"){
var dir_zip = path.join(bds.bds_dir_bedrock, "worlds") //`${require("../index").}/worlds/` dir_zip = path.join(bds.bds_dir_bedrock, "worlds") //`${require("../index").}/worlds/`
} else { } else {
const world_name = JSON.parse(java_pro(fs.readFileSync(path.join(bds.bds_dir_java, "server.properties"), "utf-8").replaceAll("-", "_"))).level_name const world_name = JSON.parse(java_pro(fs.readFileSync(path.join(bds.bds_dir_java, "server.properties"), "utf-8").replaceAll("-", "_"))).level_name
var dir_zip = path.join(bds.bds_dir_java, world_name) //`${require("../index").bds_dir_bedrock}/${world_name}/` dir_zip = path.join(bds.bds_dir_java, world_name) //`${require("../index").bds_dir_bedrock}/${world_name}/`
} }
/** /**
* Before we can start it is good for the server not to have a Corrupted Backup * Before we can start it is good for the server not to have a Corrupted Backup
* this is only necessary once after the server has started manually * this is only necessary once after the server has started manually
*/ */
if (bds.bds_detect()){bds.stop()} if (bds.bds_detect()){bds.stop()}
global.status_b = true var status_b = true
var zip = new AdmZip(); var zip = new AdmZip();
zip.addLocalFolder(dir_zip); zip.addLocalFolder(dir_zip);
zip.addZipComment(`Backup zip file in ${today}. \nBackup made to ${process.platform}, Free and open content for all\n\nSirherobrine23© By Bds Maneger.`); zip.addZipComment(`Backup zip file in ${today}. \nBackup made to ${process.platform}, Free and open content for all\n\nSirherobrine23© By Bds Maneger.`);
var zipEntries = zip.getEntries();
var totalfiles = zipEntries.length
zipEntries.forEach(function(zipEntry) {
totalfiles--
console.log(totalfiles)
if (totalfiles === 0){
status_b = false
}
});
zip.writeZip(name); zip.writeZip(name);
let es = 1; let es = 1;
for(es == "0";es++;){ for(es == "0";es++;){

View File

@ -7,18 +7,19 @@ module.exports.start = () => {
if (!(bds.detect())){ if (!(bds.detect())){
const plat = bds.platform const plat = bds.platform
var start_server
if (plat === "bedrock"){ if (plat === "bedrock"){
if (process.platform == "win32"){ if (process.platform == "win32"){
var start_server = exec("bedrock_server.exe", {cwd: bds.bds_dir_bedrock}); start_server = exec("bedrock_server.exe", {cwd: bds.bds_dir_bedrock});
} else if (process.platform == "linux"){ } else if (process.platform == "linux"){
console.log(execSync("chmod 777 bedrock_server", {cwd: bds.bds_dir_bedrock}).toString()) console.log(execSync("chmod 777 bedrock_server", {cwd: bds.bds_dir_bedrock}).toString())
var start_server = exec("./bedrock_server", {env: {PATH: process.env.PATH, LD_LIBRARY_PATH: bds.bds_dir_bedrock}, cwd: bds.bds_dir_bedrock}); start_server = exec("./bedrock_server", {env: {PATH: process.env.PATH, LD_LIBRARY_PATH: bds.bds_dir_bedrock}, cwd: bds.bds_dir_bedrock});
} else { } else {
process.exit(210) process.exit(210)
} }
} else { } else {
if (require("command-exists").sync("java")){ if (require("command-exists").sync("java")){
var start_server = exec("java -Xmx1024M -Xms1024M -jar server.jar nogui", {cwd: bds.bds_dir_java}); start_server = exec("java -Xmx1024M -Xms1024M -jar server.jar nogui", {cwd: bds.bds_dir_java});
} else { } else {
if (bds.system == "windows"){ if (bds.system == "windows"){
require("open")("http://docs.sirherobrine23.com/bds_maneger_api_java#Windows"); require("open")("http://docs.sirherobrine23.com/bds_maneger_api_java#Windows");

View File

@ -3,18 +3,21 @@ module.exports = (Vdown) => {
const bds = require("../index") const bds = require("../index")
fetch("https://raw.githubusercontent.com/Bds-Maneger/Raw_files/main/Server.json").then(response => response.json()).then(versions => { fetch("https://raw.githubusercontent.com/Bds-Maneger/Raw_files/main/Server.json").then(response => response.json()).then(versions => {
var mine_name
var downloadBDSchild
if (bds.platform === "bedrock"){ if (bds.platform === "bedrock"){
const system = bds.system const system = bds.system
var mine_name = "bedrock.zip" mine_name = "bedrock.zip"
var versions_get
if (system === "linux"){ if (system === "linux"){
var versions_get = versions.bedrock[Vdown].url_linux; versions_get = versions.bedrock[Vdown].url_linux;
} else { } else {
var versions_get = versions.bedrock[Vdown].url_windows; versions_get = versions.bedrock[Vdown].url_windows;
} }
console.log("Starting download, with url "+versions_get) console.log("Starting download, with url "+versions_get)
const exec = require("child_process").exec const exec = require("child_process").exec
localStorage.setItem("bds_server_version", Vdown); localStorage.setItem("bds_server_version", Vdown);
var downloadBDSchild = exec(`curl ${versions_get} --output ${mine_name}`, { downloadBDSchild = exec(`curl ${versions_get} --output ${mine_name}`, {
cwd: `${bds.tmp_dir}` cwd: `${bds.tmp_dir}`
}); });
@ -51,13 +54,13 @@ module.exports = (Vdown) => {
} }
}) })
} else { } else {
var versions_get = versions.java[Vdown].url versions_get = versions.java[Vdown].url
var mine_name = "server.jar" mine_name = "server.jar"
console.log("Starting download") console.log("Starting download")
const exec = require("child_process").exec const exec = require("child_process").exec
localStorage.setItem("bds_server_version", Vdown); localStorage.setItem("bds_server_version", Vdown);
var downloadBDSchild = exec(`curl ${versions_get} --output ${mine_name}`, { downloadBDSchild = exec(`curl ${versions_get} --output ${mine_name}`, {
cwd: `${bds.bds_dir_java}` cwd: `${bds.bds_dir_java}`
}); });
downloadBDSchild.stdout.on("data", function(data){ downloadBDSchild.stdout.on("data", function(data){

View File

@ -2,69 +2,68 @@ function bds_config(json_config){
const bds = require("../index") const bds = require("../index")
const path = require("path") const path = require("path")
var fs = require("fs") var fs = require("fs")
if (bds.platform === "java") var Server_Config = path.join(bds.bds_dir_java, "server.properties");
else var Server_Config = path.join(bds.bds_dir_bedrock, "server.properties");
const cpuCount = require("os").cpus().length; const cpuCount = require("os").cpus().length;
if (2 < cpuCount - 2) var CPU = cpuCount - 2; var Server_Config;
else var CPU = cpuCount; if (bds.platform === "java") Server_Config = path.join(bds.bds_dir_java, "server.properties");
else Server_Config = path.join(bds.bds_dir_bedrock, "server.properties");
if (json_config.includes(".json")){ var CPU
var config = JSON.parse(fs.readFileSync(json_config, "utf8")) if (2 < cpuCount - 2) CPU = cpuCount - 2;
} else var config = JSON.parse(json_config) else CPU = cpuCount;
if (config.description == undefined) var description_name = "Dedicated Server"; var config;
else var description_name = config.description; if (json_config.includes(".json")) config = JSON.parse(fs.readFileSync(json_config, "utf8"));
else config = JSON.parse(json_config)
// Level Name //
if (config.name == undefined) var level_name = "Bedrock level"; var
else var level_name = config.name; description_name = "Dedicated Server",
level_name = "Bedrock level",
gamemode = "survival",
difficulty = "easy",
allow_cheats = false,
max_players = 10,
online_mode = true,
white_list = false,
server_port = 19132,
server_portv6 = 19133,
player_permission = "member",
tick = 0
// gamemode if (config.description !== undefined) description_name = config.description;
if (config.gamemode == undefined) var gamemode = "survival";
else var gamemode = config.gamemode;
// Difficulty if (config.name !== undefined) level_name = config.name;
if (config.difficulty == undefined) var difficulty = "easy";
else var difficulty = config.difficulty;
// cheats if (config.gamemode !== undefined) gamemode = config.gamemode;
if (config.cheats == undefined) var allow_cheats = false;
else var allow_cheats = config.cheats;
// Maximo de Jogadores if (config.difficulty !== undefined) difficulty = config.difficulty;
if (config.players == undefined) var max_players = 10;
else var max_players = config.players;
// Xbox authentication outside the internal network if (config.cheats !== undefined) allow_cheats = config.cheats;
if (config.xbox == undefined) var online_mode = true;
else var online_mode = config.xbox;
// Whitelist if (config.players !== undefined) max_players = config.players;
if (config.white_list == undefined){var white_list = false;} else {var white_list = config.white_list;}
// Server Port IPv4 if (config.xbox !== undefined) online_mode = config.xbox;
if (config.port == undefined){var server_port = 19132;} else {var server_port = config.port;}
// Server Port IPv6 if (config.white_list !== undefined) white_list = config.white_list;
if (config.port6 == undefined){var server_portv6 = 19133;} else {var server_portv6 = config.port6;}
// Default player permission if (config.port !== undefined) server_port = config.port;
if (config.player_permission == undefined) var player_permission = "member";
else var player_permission = config.player_permission;
if (2 >= cpuCount) var tick = 2 ; if (config.port6 !== undefined) server_portv6 = config.port6;
else if (4 >= cpuCount) var tick = 4;
else if (6 >= cpuCount) var tick = 6; if (config.player_permission !== undefined) player_permission = config.player_permission;
else if (8 >= cpuCount) var tick = 8;
else if (10 >= cpuCount) var tick = 10; if (2 >= cpuCount) tick = 2 ;
else var tick = 12 else if (4 >= cpuCount) tick = 4;
else if (6 >= cpuCount) tick = 6;
else if (8 >= cpuCount) tick = 8;
else if (10 >= cpuCount) tick = 10;
else tick = 12
/*Save Files*/ /*Save Files*/
var config_file_content
if (bds.platform === "bedrock"){ if (bds.platform === "bedrock"){
var config_file_content = `server-name=${description_name} config_file_content = `server-name=${description_name}
gamemode=${gamemode} gamemode=${gamemode}
difficulty=${difficulty} difficulty=${difficulty}
allow-cheats=${allow_cheats} allow-cheats=${allow_cheats}
@ -92,7 +91,7 @@ correct-player-movement=false
# Created on Bds-Manager by Sirherobrine23` # Created on Bds-Manager by Sirherobrine23`
} else { } else {
var config_file_content = `enable-jmx-monitoring=false config_file_content = `enable-jmx-monitoring=false
rcon.port=25575 rcon.port=25575
level-seed= level-seed=
gamemode=${gamemode} gamemode=${gamemode}
@ -147,20 +146,21 @@ max-world-size=29999984
} }
// console.log(config_file_content); // console.log(config_file_content);
fs.writeFileSync(Server_Config, config_file_content); fs.writeFileSync(Server_Config, config_file_content);
return "success" return true
} }
function bds_get_config(){ function bds_get_config(){
var fs = require("fs"); var fs = require("fs");
const path = require("path") const path = require("path");
const bds = require("../index") const bds = require("../index");
const propertiesToJSON = require("properties-to-json"); const propertiesToJSON = require("properties-to-json");
if (bds.platform === "bedrock") var config_path = path.join(bds.bds_dir_bedrock, "server.properties") var config_path;
else var config_path = path.join(bds.bds_dir_java, "server.properties") if (bds.platform === "bedrock") config_path = path.join(bds.bds_dir_bedrock, "server.properties");
var config = fs.readFileSync(config_path, "utf8").split("-").join("_") else config_path = path.join(bds.bds_dir_java, "server.properties");
var config = fs.readFileSync(config_path, "utf8").split("-").join("_");
return propertiesToJSON(config); return propertiesToJSON(config);
} }
module.exports.config_example = () =>{ function config_example(){
return { return {
name: "Bedrock our Java", name: "Bedrock our Java",
description: "BDS Maneger", description: "BDS Maneger",
@ -177,3 +177,4 @@ return {
} }
module.exports.config = bds_config module.exports.config = bds_config
module.exports.get_config = bds_get_config module.exports.get_config = bds_get_config
module.exports.config_example = config_example

View File

@ -1,18 +1,18 @@
module.exports = () => { module.exports = () => {
var spawn = require("child_process").execSync; var spawn = require("child_process").execSync;
const bds = require("../index") const bds = require("../index")
var killbds
if (bds.platform === "bedrock"){ if (bds.platform === "bedrock"){
if (process.platform == "win32") { if (process.platform == "win32") {
var killbds = spawn("tasklist /fi \"imagename eq bedrock_server.exe\" | find /i \"bedrock_server.exe\" > nul & if not errorlevel 1 (echo 0) else (echo 1)"); killbds = spawn("tasklist /fi \"imagename eq bedrock_server.exe\" | find /i \"bedrock_server.exe\" > nul & if not errorlevel 1 (echo 0) else (echo 1)");
} else if (process.platform == "linux") { } else if (process.platform == "linux") {
var killbds = spawn("ps aux|grep -v \"grep\"|grep \"bedrock_server\"|grep -q \"bedrock_server\";echo $?", {shell: true}); killbds = spawn("ps aux|grep -v \"grep\"|grep \"bedrock_server\"|grep -q \"bedrock_server\";echo $?", {shell: true});
} }
} else { } else {
if (process.platform == "win32") { if (process.platform == "win32") {
var killbds = spawn("tasklist /fi \"imagename eq server.jar\" | find /i \"server.jar\" > nul & if not errorlevel 1 (echo 0) else (echo 1)"); killbds = spawn("tasklist /fi \"imagename eq server.jar\" | find /i \"server.jar\" > nul & if not errorlevel 1 (echo 0) else (echo 1)");
} else if (process.platform == "linux") { } else if (process.platform == "linux") {
var killbds = spawn("ps aux|grep \"jar server.jar\"|grep -v 'grep'|grep -q \"jar server.jar\";echo $?", {shell: true}); killbds = spawn("ps aux|grep \"jar server.jar\"|grep -v 'grep'|grep -q \"jar server.jar\";echo $?", {shell: true});
} }
} }
// //

View File

@ -3,14 +3,15 @@ module.exports = () => {
var spawn = require("child_process").exec; var spawn = require("child_process").exec;
const Storage = localStorage const Storage = localStorage
if (bds.bds_detect()){ if (bds.bds_detect()){
var killbds
if (bds.platform === "bedrock"){ if (bds.platform === "bedrock"){
if (process.platform == "win32") var killbds = spawn("tasklist /fi \"imagename eq bedrock_server.exe\" | find /i \"bedrock_server.exe\" > nul & if not errorlevel 1 (taskkill /f /im \"bedrock_server.exe\" > nul && exit 0) else (exit 1)"); if (process.platform == "win32") killbds = spawn("tasklist /fi \"imagename eq bedrock_server.exe\" | find /i \"bedrock_server.exe\" > nul & if not errorlevel 1 (taskkill /f /im \"bedrock_server.exe\" > nul && exit 0) else (exit 1)");
else if (process.platform == "linux") var killbds = spawn("kill $(ps aux|grep -v \"grep\"|grep \"bedrock_server\"|awk '{print $2}')", {shell: true}); else if (process.platform == "linux") killbds = spawn("kill $(ps aux|grep -v \"grep\"|grep \"bedrock_server\"|awk '{print $2}')", {shell: true});
} else { } else {
if (process.platform == "win32") { if (process.platform == "win32") {
var killbds = spawn("tasklist /fi \"imagename eq server.jar\" | find /i \"server.jar\" > nul & if not errorlevel 1 (taskkill /f /im \"server.jar\" > nul && exit 0) else (exit 1)"); killbds = spawn("tasklist /fi \"imagename eq server.jar\" | find /i \"server.jar\" > nul & if not errorlevel 1 (taskkill /f /im \"server.jar\" > nul && exit 0) else (exit 1)");
} else if (process.platform == "linux") { } else if (process.platform == "linux") {
var killbds = spawn("kill $(ps aux|grep -v \"grep\"|grep \"server.jar\"|awk '{print $2}')", {shell: true}); killbds = spawn("kill $(ps aux|grep -v \"grep\"|grep \"server.jar\"|awk '{print $2}')", {shell: true});
} }
} }
killbds.on("exit", function () { killbds.on("exit", function () {