Merge #31
@ -6,6 +6,10 @@
|
||||
"node": true,
|
||||
"shelljs": true
|
||||
},
|
||||
"globals": {
|
||||
"bds_log_string": "writable",
|
||||
"bds_server_string": "writable"
|
||||
},
|
||||
"extends": "eslint:recommended",
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 12,
|
||||
@ -15,7 +19,10 @@
|
||||
}
|
||||
},
|
||||
"rules": {
|
||||
"quotes": ["error", "double"],
|
||||
"quotes": [
|
||||
"error",
|
||||
"double"
|
||||
],
|
||||
"eqeqeq": 0
|
||||
}
|
||||
}
|
||||
|
28
API/api.js
28
API/api.js
@ -1,11 +1,11 @@
|
||||
module.exports = () => {
|
||||
global.bds_api_start = true:
|
||||
global.bds_api_start = true;
|
||||
const express = require("express");
|
||||
const bds = require("../index");
|
||||
const fs = require("fs");
|
||||
const app = express();
|
||||
const path = require("path");
|
||||
var cors = require('cors');
|
||||
var cors = require("cors");
|
||||
const rateLimit = require("express-rate-limit");
|
||||
|
||||
// Enable if you're behind a reverse proxy (Heroku, Bluemix, AWS ELB, Nginx, etc)
|
||||
@ -33,7 +33,7 @@ module.exports = () => {
|
||||
} else {
|
||||
v++;
|
||||
}
|
||||
};
|
||||
}
|
||||
const config = bds.get_config()
|
||||
var json_http = {
|
||||
"server": {
|
||||
@ -52,7 +52,7 @@ module.exports = () => {
|
||||
return res.send(json_http);
|
||||
});
|
||||
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) => {
|
||||
const body = req.body
|
||||
@ -68,14 +68,15 @@ module.exports = () => {
|
||||
}
|
||||
}
|
||||
if (pass){
|
||||
if (command_bds === 'start'){
|
||||
var command_status
|
||||
if (command_bds === "start"){
|
||||
bds.start()
|
||||
var command_status = `Bds Started`
|
||||
} else if (command_bds === 'stop'){
|
||||
command_status = "Bds Started"
|
||||
} else if (command_bds === "stop"){
|
||||
bds.stop()
|
||||
var command_status = `Stopping the bds server`
|
||||
command_status = "Stopping the bds server"
|
||||
} else {
|
||||
var command_status = `no command identified`
|
||||
command_status = "no command identified"
|
||||
}
|
||||
res.send({
|
||||
"status": 200,
|
||||
@ -101,12 +102,13 @@ module.exports = () => {
|
||||
token_verify++
|
||||
}
|
||||
}
|
||||
var STA,EMN
|
||||
if (pass){
|
||||
var STA = `wait`
|
||||
var EMN = bds.download(ver)
|
||||
STA = "wait"
|
||||
EMN = bds.download(ver)
|
||||
} else {
|
||||
var STA = `401`,
|
||||
EMN = `Unauthorized Token`
|
||||
STA = "401",
|
||||
EMN = "Unauthorized Token"
|
||||
}
|
||||
res.send({
|
||||
"status": STA,
|
||||
|
19
API/log.js
19
API/log.js
@ -20,19 +20,22 @@ module.exports = () => {
|
||||
const requestIp = require("request-ip");
|
||||
app.use(requestIp.mw())
|
||||
app.get("/", (req, res) => {
|
||||
var text="";
|
||||
var log_file="";
|
||||
var sucess="";
|
||||
if (typeof bds_log_string === "undefined"){
|
||||
if (fs.existsSync(localStorage.getItem("old_log_file"))){
|
||||
var text = `${fs.readFileSync(localStorage.getItem("old_log_file"), "utf8")}`
|
||||
var log_file = localStorage.getItem("old_log_file")
|
||||
var sucess = true
|
||||
text = `${fs.readFileSync(localStorage.getItem("old_log_file"), "utf8")}`
|
||||
log_file = localStorage.getItem("old_log_file")
|
||||
sucess = true
|
||||
} else {
|
||||
var text = "The server is stopped"
|
||||
var sucess = false
|
||||
text = "The server is stopped"
|
||||
sucess = false
|
||||
}
|
||||
} else {
|
||||
var text = bds_log_string
|
||||
var log_file = "string"
|
||||
var sucess = true
|
||||
text = bds_log_string
|
||||
log_file = "string"
|
||||
sucess = true
|
||||
}
|
||||
res.json({
|
||||
"sucess": sucess,
|
||||
|
@ -55,13 +55,14 @@ module.exports.drive_backup = () => {
|
||||
console.log(gd_secret)
|
||||
function upload_backup(auth) {
|
||||
const drive = google.drive({version: "v3", auth});
|
||||
var fileMetadata;
|
||||
if (parent_id === undefined){
|
||||
var fileMetadata = {
|
||||
fileMetadata = {
|
||||
name: name_d
|
||||
}
|
||||
console.log("Your backup will be saved to My Drive")
|
||||
} else {
|
||||
var fileMetadata = {
|
||||
fileMetadata = {
|
||||
name: name_d,
|
||||
parents: [parent_id]
|
||||
}
|
||||
|
@ -1,14 +1,21 @@
|
||||
module.exports.checkUser = (USERNAME) => {
|
||||
const fs = require("fs")
|
||||
if (fs.existsSync(`${require("../index").bds_dir}/telegram_admin.json`)) {
|
||||
var admins = fs.readFileSync(`${require("../index").bds_dir}/telegram_admin.json`, "utf-8");
|
||||
const path = require("path")
|
||||
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 {
|
||||
var admins = "{\"sh23_bot_not_config\": {\"allow\": true}}";
|
||||
console.warn("All allowed")
|
||||
console.log(`Create file in with name: ${require("../index").bds_dir}/telegram_admin.json`)
|
||||
const config = {
|
||||
"sh23_bot_not_config": {
|
||||
"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);
|
||||
for(check_ in adm){
|
||||
for(let check_ in adm){
|
||||
if (USERNAME == check_){
|
||||
return true
|
||||
} else if (check_ == "sh23_bot_not_config"){
|
||||
|
@ -33,7 +33,7 @@ bot.command("server_start", (ctx) => {
|
||||
ctx.reply(`${ctx.message.from.username} already started`)
|
||||
} else {
|
||||
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) => {
|
||||
@ -46,7 +46,7 @@ bot.command("server_stop", (ctx) => {
|
||||
ctx.reply(`${ctx.message.from.username} o servidor está parado`)
|
||||
} else {
|
||||
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) =>{
|
||||
|
79
index.js
79
index.js
@ -1,3 +1,4 @@
|
||||
/* eslint-disable no-irregular-whitespace */
|
||||
console.log(`Running the Bds Maneger API in version ${require(__dirname+"/package.json").version}`)
|
||||
var shell = require("shelljs");
|
||||
let blanks;
|
||||
@ -14,10 +15,11 @@ function date(fu) {
|
||||
else
|
||||
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")){
|
||||
var electron_de = true;
|
||||
electron_de = true;
|
||||
} else if (process.argv[0].includes("node")){
|
||||
var electron_de = undefined;
|
||||
electron_de = undefined;
|
||||
if (process.env.BDS_MONI == blanks){
|
||||
process.env.BDS_MONI = true
|
||||
}
|
||||
@ -28,50 +30,60 @@ if (process.argv[0].includes("electron")){
|
||||
// process.env.ENABLE_BDS_API
|
||||
|
||||
} else {
|
||||
var electron_de = false;
|
||||
electron_de = false;
|
||||
}
|
||||
const arch = process.arch
|
||||
if (arch == "x64"){
|
||||
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`)
|
||||
}
|
||||
var archi = arch
|
||||
const path = require("path")
|
||||
const fs = require("fs");
|
||||
const { error } = require("console");
|
||||
const package_root = path.join(process.cwd(), "package.json")
|
||||
const package_root_builder = path.resolve(".", "resources", "app", "package.json")
|
||||
var cache_dir,home,desktop,tmp,system
|
||||
if (process.platform == "win32") {
|
||||
var home = process.env.USERPROFILE;
|
||||
var desktop = path.join(home, "Desktop")
|
||||
home = process.env.USERPROFILE;
|
||||
desktop = path.join(home, "Desktop")
|
||||
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){
|
||||
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 {
|
||||
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
|
||||
var system = "windows";
|
||||
tmp = process.env.TMP
|
||||
system = "windows";
|
||||
} else if (process.platform == "linux") {
|
||||
var home = process.env.HOME;
|
||||
home = process.env.HOME;
|
||||
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)) {
|
||||
var cache_dir = path.join(home, ".config", require(package_root_builder).name);
|
||||
cache_dir = path.join(home, ".config", require(package_root_builder).name);
|
||||
} else {
|
||||
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 = {};
|
||||
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";
|
||||
var system = "linux";
|
||||
tmp = "/tmp";
|
||||
system = "linux";
|
||||
} else if (process.platform == "darwin") {
|
||||
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")
|
||||
@ -113,7 +125,7 @@ if (fs.existsSync(bds_config_file)){
|
||||
fs.writeFileSync(bds_config_file, JSON.stringify(bds_config))
|
||||
}
|
||||
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
|
||||
|
||||
var log_dir = path.join(bds_dir, "log");
|
||||
@ -161,9 +173,11 @@ if (!(fs.existsSync(log_dir))){
|
||||
* @example change_platform("bedrock")
|
||||
*/
|
||||
function platform_update(plate){
|
||||
var complet_;
|
||||
if (plate === "java") complet_ = true
|
||||
else if (plate === "bedrock") complet_ = true
|
||||
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")
|
||||
try {
|
||||
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"))){
|
||||
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 {
|
||||
const token = fs.readFileSync(path.join(bds_dir, "telegram_token.txt"), "utf-8").split("\n").join("")
|
||||
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);
|
||||
for (let v in versions){
|
||||
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++;
|
||||
}
|
||||
module.exports.bedrock_all_versions = Object.getOwnPropertyNames(rawOUT.bedrock);
|
||||
@ -317,15 +331,16 @@ module.exports.token_register = () => {
|
||||
var token = buffer.toString("hex");
|
||||
console.log(token);
|
||||
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){
|
||||
if (err){console.log(err);}
|
||||
else {
|
||||
objeto = JSON.parse(data);
|
||||
var count = Object.keys(obj).length;
|
||||
var objeto = JSON.parse(data);
|
||||
var count = Object.keys(objeto).length;
|
||||
var teste = {count, token};
|
||||
objeto.push(teste);
|
||||
json_ = JSON.stringify(objeto);
|
||||
var json_ = JSON.stringify(objeto);
|
||||
fs.writeFileSync(path.join(bds_dir, "bds_tokens.json"), json_, "utf8");}
|
||||
});
|
||||
})
|
||||
|
@ -7,11 +7,12 @@ module.exports.World_BAckup = () => {
|
||||
|
||||
var today = bds.date()
|
||||
const name = path.join(bds.backup_folder ,`bds_backup_World_${today}.zip`)
|
||||
var dir_zip;
|
||||
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 {
|
||||
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
|
||||
@ -41,30 +42,22 @@ module.exports.Drive_backup = () => {
|
||||
|
||||
var today = bds.date()
|
||||
const name = path.join(bds.backup_folder ,`bds_backup_World_${today}.zip`)
|
||||
var dir_zip;
|
||||
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 {
|
||||
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
|
||||
* this is only necessary once after the server has started manually
|
||||
*/
|
||||
if (bds.bds_detect()){bds.stop()}
|
||||
global.status_b = true
|
||||
var status_b = true
|
||||
var zip = new AdmZip();
|
||||
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.`);
|
||||
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);
|
||||
let es = 1;
|
||||
for(es == "0";es++;){
|
||||
|
@ -7,18 +7,19 @@ module.exports.start = () => {
|
||||
|
||||
if (!(bds.detect())){
|
||||
const plat = bds.platform
|
||||
var start_server
|
||||
if (plat === "bedrock"){
|
||||
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"){
|
||||
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 {
|
||||
process.exit(210)
|
||||
}
|
||||
} else {
|
||||
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 {
|
||||
if (bds.system == "windows"){
|
||||
require("open")("http://docs.sirherobrine23.com/bds_maneger_api_java#Windows");
|
||||
|
@ -3,18 +3,21 @@ module.exports = (Vdown) => {
|
||||
const bds = require("../index")
|
||||
|
||||
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"){
|
||||
const system = bds.system
|
||||
var mine_name = "bedrock.zip"
|
||||
mine_name = "bedrock.zip"
|
||||
var versions_get
|
||||
if (system === "linux"){
|
||||
var versions_get = versions.bedrock[Vdown].url_linux;
|
||||
versions_get = versions.bedrock[Vdown].url_linux;
|
||||
} else {
|
||||
var versions_get = versions.bedrock[Vdown].url_windows;
|
||||
versions_get = versions.bedrock[Vdown].url_windows;
|
||||
}
|
||||
console.log("Starting download, with url "+versions_get)
|
||||
const exec = require("child_process").exec
|
||||
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}`
|
||||
});
|
||||
|
||||
@ -51,13 +54,13 @@ module.exports = (Vdown) => {
|
||||
}
|
||||
})
|
||||
} else {
|
||||
var versions_get = versions.java[Vdown].url
|
||||
var mine_name = "server.jar"
|
||||
versions_get = versions.java[Vdown].url
|
||||
mine_name = "server.jar"
|
||||
|
||||
console.log("Starting download")
|
||||
const exec = require("child_process").exec
|
||||
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}`
|
||||
});
|
||||
downloadBDSchild.stdout.on("data", function(data){
|
||||
|
@ -2,69 +2,68 @@ function bds_config(json_config){
|
||||
const bds = require("../index")
|
||||
const path = require("path")
|
||||
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;
|
||||
|
||||
if (2 < cpuCount - 2) var CPU = cpuCount - 2;
|
||||
else var CPU = cpuCount;
|
||||
var Server_Config;
|
||||
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 config = JSON.parse(fs.readFileSync(json_config, "utf8"))
|
||||
} else var config = JSON.parse(json_config)
|
||||
var CPU
|
||||
if (2 < cpuCount - 2) CPU = cpuCount - 2;
|
||||
else CPU = cpuCount;
|
||||
|
||||
if (config.description == undefined) var description_name = "Dedicated Server";
|
||||
else var description_name = config.description;
|
||||
var config;
|
||||
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";
|
||||
else var level_name = config.name;
|
||||
//
|
||||
var
|
||||
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.gamemode == undefined) var gamemode = "survival";
|
||||
else var gamemode = config.gamemode;
|
||||
if (config.description !== undefined) description_name = config.description;
|
||||
|
||||
// Difficulty
|
||||
if (config.difficulty == undefined) var difficulty = "easy";
|
||||
else var difficulty = config.difficulty;
|
||||
if (config.name !== undefined) level_name = config.name;
|
||||
|
||||
// cheats
|
||||
if (config.cheats == undefined) var allow_cheats = false;
|
||||
else var allow_cheats = config.cheats;
|
||||
if (config.gamemode !== undefined) gamemode = config.gamemode;
|
||||
|
||||
// Maximo de Jogadores
|
||||
if (config.players == undefined) var max_players = 10;
|
||||
else var max_players = config.players;
|
||||
if (config.difficulty !== undefined) difficulty = config.difficulty;
|
||||
|
||||
// Xbox authentication outside the internal network
|
||||
if (config.xbox == undefined) var online_mode = true;
|
||||
else var online_mode = config.xbox;
|
||||
if (config.cheats !== undefined) allow_cheats = config.cheats;
|
||||
|
||||
// Whitelist
|
||||
if (config.white_list == undefined){var white_list = false;} else {var white_list = config.white_list;}
|
||||
if (config.players !== undefined) max_players = config.players;
|
||||
|
||||
// Server Port IPv4
|
||||
if (config.port == undefined){var server_port = 19132;} else {var server_port = config.port;}
|
||||
if (config.xbox !== undefined) online_mode = config.xbox;
|
||||
|
||||
// Server Port IPv6
|
||||
if (config.port6 == undefined){var server_portv6 = 19133;} else {var server_portv6 = config.port6;}
|
||||
if (config.white_list !== undefined) white_list = config.white_list;
|
||||
|
||||
// Default player permission
|
||||
if (config.player_permission == undefined) var player_permission = "member";
|
||||
else var player_permission = config.player_permission;
|
||||
if (config.port !== undefined) server_port = config.port;
|
||||
|
||||
if (2 >= cpuCount) var tick = 2 ;
|
||||
else if (4 >= cpuCount) var tick = 4;
|
||||
else if (6 >= cpuCount) var tick = 6;
|
||||
else if (8 >= cpuCount) var tick = 8;
|
||||
else if (10 >= cpuCount) var tick = 10;
|
||||
else var tick = 12
|
||||
if (config.port6 !== undefined) server_portv6 = config.port6;
|
||||
|
||||
if (config.player_permission !== undefined) player_permission = config.player_permission;
|
||||
|
||||
if (2 >= cpuCount) tick = 2 ;
|
||||
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*/
|
||||
var config_file_content
|
||||
if (bds.platform === "bedrock"){
|
||||
var config_file_content = `server-name=${description_name}
|
||||
config_file_content = `server-name=${description_name}
|
||||
gamemode=${gamemode}
|
||||
difficulty=${difficulty}
|
||||
allow-cheats=${allow_cheats}
|
||||
@ -92,7 +91,7 @@ correct-player-movement=false
|
||||
# Created on Bds-Manager by Sirherobrine23`
|
||||
|
||||
} else {
|
||||
var config_file_content = `enable-jmx-monitoring=false
|
||||
config_file_content = `enable-jmx-monitoring=false
|
||||
rcon.port=25575
|
||||
level-seed=
|
||||
gamemode=${gamemode}
|
||||
@ -147,20 +146,21 @@ max-world-size=29999984
|
||||
}
|
||||
// console.log(config_file_content);
|
||||
fs.writeFileSync(Server_Config, config_file_content);
|
||||
return "success"
|
||||
return true
|
||||
}
|
||||
function bds_get_config(){
|
||||
var fs = require("fs");
|
||||
const path = require("path")
|
||||
const bds = require("../index")
|
||||
const path = require("path");
|
||||
const bds = require("../index");
|
||||
const propertiesToJSON = require("properties-to-json");
|
||||
|
||||
if (bds.platform === "bedrock") var config_path = path.join(bds.bds_dir_bedrock, "server.properties")
|
||||
else var config_path = path.join(bds.bds_dir_java, "server.properties")
|
||||
var config = fs.readFileSync(config_path, "utf8").split("-").join("_")
|
||||
var config_path;
|
||||
if (bds.platform === "bedrock") config_path = path.join(bds.bds_dir_bedrock, "server.properties");
|
||||
else config_path = path.join(bds.bds_dir_java, "server.properties");
|
||||
var config = fs.readFileSync(config_path, "utf8").split("-").join("_");
|
||||
return propertiesToJSON(config);
|
||||
}
|
||||
module.exports.config_example = () =>{
|
||||
function config_example(){
|
||||
return {
|
||||
name: "Bedrock our Java",
|
||||
description: "BDS Maneger",
|
||||
@ -177,3 +177,4 @@ return {
|
||||
}
|
||||
module.exports.config = bds_config
|
||||
module.exports.get_config = bds_get_config
|
||||
module.exports.config_example = config_example
|
@ -1,18 +1,18 @@
|
||||
module.exports = () => {
|
||||
var spawn = require("child_process").execSync;
|
||||
const bds = require("../index")
|
||||
|
||||
var killbds
|
||||
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 (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") {
|
||||
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 {
|
||||
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") {
|
||||
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});
|
||||
}
|
||||
}
|
||||
//
|
||||
|
@ -3,14 +3,15 @@ module.exports = () => {
|
||||
var spawn = require("child_process").exec;
|
||||
const Storage = localStorage
|
||||
if (bds.bds_detect()){
|
||||
var killbds
|
||||
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)");
|
||||
else if (process.platform == "linux") var killbds = spawn("kill $(ps aux|grep -v \"grep\"|grep \"bedrock_server\"|awk '{print $2}')", {shell: true});
|
||||
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") killbds = spawn("kill $(ps aux|grep -v \"grep\"|grep \"bedrock_server\"|awk '{print $2}')", {shell: true});
|
||||
} else {
|
||||
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") {
|
||||
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 () {
|
||||
|
Reference in New Issue
Block a user