Stable #36

Merged
Sirherobrine23 merged 2 commits from stable into main 2021-02-14 05:52:15 +00:00
18 changed files with 1244 additions and 31 deletions

View File

@ -52,7 +52,23 @@ module.exports = () => {
return res.send(json_http);
});
app.get("/", (req, res) => {
<<<<<<< HEAD
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}`);
});
app.get("/themes", (req, res) => {
fetch("https://raw.githubusercontent.com/Bds-Maneger/Raw_files/main/themes.json").then(response => response.json()).then(array => {
var themes_json;
for (let index = 0; index < array.length; index++) {
const name = array[index].name;
const zip_url = array[index].zip_url;
const git_url = array[index].git_url;
themes_json += `{Name: ${name},\n Url Zip: ${zip_url},\n Git url: ${git_url}},`
}
return res.send(themes_json);
});
=======
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}`);
>>>>>>> main
});
app.post("/service", (req, res) => {
const body = req.body

26
API/gdrive_save.js Normal file
View File

@ -0,0 +1,26 @@
module.exports = () => {
global.bds_api_start = true
const express = require("express");
const app = express();
var cors = require('cors');
app.use(cors());
app.use(require("body-parser").json()); /* https://github.com/github/fetch/issues/323#issuecomment-331477498 */
const bodyParser = require("body-parser");
app.use(bodyParser.urlencoded({ extended: true }));
app.get("/:DI", (req, res) => {
return res.send(`
<html>
<head></head>
<body>
<a>token Save</a>
<p>
<textarea disabled>
${req.params.DI}
</textarea>
</p>
</body>
</html>
`);
});
app.listen(2212);
}

114
API/remote_access.js Normal file
View File

@ -0,0 +1,114 @@
module.exports = () => {
global.bds_api_post_start = true
const express = require("express");
const bds = require("../index");
const fs = require("fs");
const app = express();
var cors = require('cors');
const path = require("path")
const bodyParser = require("body-parser");
const rateLimit = require("express-rate-limit");
// Enable if you're behind a reverse proxy (Heroku, Bluemix, AWS ELB, Nginx, etc)
// see https://expressjs.com/en/guide/behind-proxies.html
// app.set('trust proxy', 1);
const limiter = rateLimit({
windowMs: 15 * 60 * 1000, // 15 minutes
max: 100 // limit each IP to 100 requests per windowMs
});
app.use(cors());
app.use(limiter);
app.use(bodyParser.urlencoded({ extended: true }));
app.use(require("body-parser").json()); /* https://github.com/github/fetch/issues/323#issuecomment-331477498 */
app.post("/info", (req, res) => {
const body = req.body
const tokens = JSON.parse(fs.readFileSync(path.join(bds.bds_dir, "bds_tokens.json"), "utf-8"))
var pass = false;
var teste = 'Sucess'
for (let token_verify in tokens) {const element = tokens[token_verify].token;if (body.token == element){pass = true} else {token_verify++}}
if (pass){
if (fs.existsSync(process.cwd()+"/package.json")){
var api_v = require(process.cwd()+"/package.json").version
var name = bds.get_config().level_name
} else {
var api_v = null
var name = 'Bds_Maneger_api'
}
res.send({
"status": 200,
"api_version": api_v,
"name": name
})
} else {
res.send({
"status": 401,
"message": `Not authorized: ${body.token}`
})
}
});
app.get("/bds/:command", (req, res) => {
const body = req.body
const command_bds = '';
const tokens = JSON.parse(fs.readFileSync(path.join(bds.bds_dir, "bds_tokens.json"), "utf-8"))
var pass = false;
res.send({
"command": req.params.command
})
// for (let token_verify in tokens) {const element = tokens[token_verify].token;if (body.token == element){pass = true} else {token_verify++}}
// if (pass){
// if (command_bds === 'start'){
// var bds_init = bds.start()
// var command_status = `Bds Started`
// } else if (command_bds === 'stop'){
// bds.stop()
// var command_status = `Stopping the bds server`
// } else if (command_bds === 'reload'){
// const bds_status = bds.detect()
// if (bds_detect){
// bds.stop()
// }
// var bds_init = bds.start()
// var command_status = `Reloading`
// } else {
// var command_status = `no command identified`
// }
// res.send({
// "status": 200,
// "bds_status": command_status
// })
// } else {
// res.send({
// "status": 401,
// "message": `Not authorized: ${body.token}`
// })
// }
});
app.post("/bds_command", (req, res) => {
const body = req.body
const tokens = JSON.parse(fs.readFileSync(path.join(bds.bds_dir, "bds_tokens.json"), "utf-8"))
var pass = false;
for (let token_verify in tokens) {
const element = tokens[token_verify].token;
// req.connection.remoteAddress
if (body.token == element){pass = true} else {token_verify++}
}
if (pass){
const command = body.command
const teste = bds.command(command)
res.send({
"status": 200,
"command": body.command,
"log": teste,
"message": `authorized to ${body.token}`
})
} else {
res.send({
"status": 401,
"message": "not authorized"
})
}
});
const http_port = "28574"
app.listen(http_port);
}

12
API/teste.js Normal file
View File

@ -0,0 +1,12 @@
var qr = require('qr-image');
var express = require('express');
var app = express();
app.get('/', function(req, res) {
var code = qr.image(`list: ${Math.random()}`, { type: 'svg' });
res.type('svg');
code.pipe(res);
});
app.listen(3000);

View File

@ -1,3 +1,5 @@
<<<<<<< HEAD
=======
# 1.5.0
All scripts have been rewritten some features are still under maintenance
@ -6,6 +8,7 @@ The Docker image has returned to work in the new version.
Some functions will be modified or removed from the next version in the Stable branch
>>>>>>> main
# 1.4.2
Docker test fix

View File

@ -45,12 +45,24 @@ function getAccessToken(oAuth2Client, callback) {
}
module.exports.drive_backup = () => {
<<<<<<< HEAD
const file_json = require("../new_script/backups").Drive_backup()
=======
const file_json = require("../scripts/backups").Drive_backup()
>>>>>>> main
console.log(file_json)
const parent_id = file_json.id
const path_file = file_json.file_path
const name_d = file_json.file_name;
<<<<<<< HEAD
const gd_secret = '';
console.log(gd_secret)
function upload_backup(auth) {
const drive = google.drive({version: "v3", auth});
if (parent_id === undefined){
var fileMetadata = {
=======
const gd_secret = "";
console.log(gd_secret)
function upload_backup(auth) {
@ -58,15 +70,24 @@ module.exports.drive_backup = () => {
var fileMetadata;
if (parent_id === undefined){
fileMetadata = {
>>>>>>> main
name: name_d
}
console.log("Your backup will be saved to My Drive")
} else {
<<<<<<< HEAD
var fileMetadata = {
name: name_d,
parents: [parent_id]
}
};
=======
fileMetadata = {
name: name_d,
parents: [parent_id]
}
}
>>>>>>> main
var media = {
mimeType: "application/octet-stream",
body: fs.createReadStream(path_file)
@ -102,6 +123,10 @@ module.exports.mcpe = () => {
progress += d.length / 1024 / 1024;
if (process.stdout.isTTY) {process.stdout.clearLine();process.stdout.cursorTo(0);process.stdout.write(`Downloaded ${Math.trunc(progress)} Mbytes`);}
}).pipe(dest)});
<<<<<<< HEAD
};
=======
}
>>>>>>> main
return authorize(gd_secret, download_mcpe);
}

View File

@ -6,6 +6,11 @@ module.exports.checkUser = (USERNAME) => {
if (fs.existsSync(telegram_admin)) {
var admins = fs.readFileSync(telegram_admin, "utf8");
} else {
<<<<<<< HEAD
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
@ -13,12 +18,17 @@ module.exports.checkUser = (USERNAME) => {
}
fs.writeFileSync(telegram_admin, JSON.stringify(config))
throw new console.error(`we just created the telegram authorization, edit before using: ${config}`);
>>>>>>> main
}
var adm = JSON.parse(admins);
for(let check_ in adm){
if (USERNAME == check_){
return true
<<<<<<< HEAD
} else if (index == "sh23_bot_not_config"){
=======
} else if (check_ == "sh23_bot_not_config"){
>>>>>>> main
console.warn("Allow all")
return true
} check_++;

View File

@ -1,41 +1,41 @@
const si = require("systeminformation");
module.exports.current_cpu = undefined
module.exports.ram_free = undefined
module.exports.ram_total = undefined
module.exports.cpu_speed = undefined
module.exports.bds_cpu = undefined
// module.exports.system = si
function init_1(){
si.cpu().then(data => {
module.exports.cpu_speed = Math.trunc(data.speed)
})
const bds_monitor = process.env.BDS_MONI.includes("true")
if (bds_monitor){
const si = require("systeminformation");
setInterval(() => {
// si.cpu().then(data => {module.exports.cpu_speed = Math.trunc(data.speed)})
si.mem().then(data => {
module.exports.ram_free = Math.trunc(data.free / 1024 / 1024 / 1024)
module.exports.ram_total = Math.trunc(data.total / 1024 / 1024 / 1024)
module.exports.ram_free = Math.trunc(data.free / 1024 / 1024 / 1024);
module.exports.ram_total = Math.trunc(data.total / 1024 / 1024 / 1024);
})
si.currentLoad().then(data => {
module.exports.current_cpu = Math.trunc(data.currentLoad)
module.exports.current_cpu = Math.trunc(data.currentload)
})
}
function init_2(){
}, 1000);
si.processes().then(data => {
const list = data.list
for (let pid in list) {
var pids = list[pid].command
if (pids.includes("server.")){
module.exports.bds_cpu = Math.trunc(list[pid].cpu)
if (pids.includes("bedrock_server")){
module.exports.bds_cpu = Math.trunc(list[pid].pcpu)
} else {
pid++
}
}
})
setInterval(() => {
si.processes().then(data => {
const list = data.list
for (let pid in list) {
var pids = list[pid].command
if (pids.includes("bedrock_server")){
module.exports.bds_cpu = Math.trunc(list[pid].pcpu)
} else {
pid++
}
}
})
}, 3000);
}else {
console.warn(`the use of cpu is disabled, for more information, visit https://docs.srherobrine23.com/enable_bds_requests.html`)
}
init_1()
init_2()
setInterval(() => {
init_1()
init_2()
}, 3000);

View File

@ -76,7 +76,11 @@ bot.command("list", (ctx) =>{
bds_command("list")
var old = bds_log_string;
setTimeout(() => {
<<<<<<< HEAD
var name = bds_log_string.replace(old, "");
=======
var name = bds_log_string.replace(old, "End\n\n");
>>>>>>> main
ctx.reply(name)
}, 1000);
} else {
@ -87,6 +91,10 @@ bot.command("mcpe", (ctx) =>{
ctx.replyWithMarkdown(`[Minecraft for Android 1.16.201.01](https://files.sh33.org/mcpe/latest.sonic)
Iphone users are not privileged
<<<<<<< HEAD
`
ctx.replyWithMarkdown(text)
=======
`)});
bot.command("status", (ctx) =>{
const {bds_cpu, current_cpu, ram_total, ram_free} = require("./system_monitor")
@ -94,7 +102,39 @@ const text = `Bds CPU usage: ${bds_cpu}%, Total CPU utilization: ${current_cpu}%
Total ram memory: ${ram_total} GB, Total free ram memory: ${ram_free} GB`
ctx.replyWithMarkdown(text);
>>>>>>> main
});
// bot.command("status", (ctx) =>{
// const si = require("systeminformation");
// // si.cpu().then(data => {module.exports.cpu_speed = Math.trunc(data.speed)})
// si.mem().then(data => {
// global.ram_free = Math.trunc(data.free / 1024 / 1024 / 1024);
// global.ram_total = Math.trunc(data.total / 1024 / 1024 / 1024);
// si.currentLoad().then(data => {
// global.current_cpu = Math.trunc(data.currentload)
// si.processes().then(data => {
// const list = data.list
// for (let pid in list) {
// var pids = list[pid].command
// if (pids.includes("bedrock_server")){global.bds_cpu = Math.trunc(list[pid].pcpu)} else if (pids.includes("server.jar")){global.bds_cpu = Math.trunc(list[pid].pcpu)} else {pid++}
// }
// si.processes().then(data => {
// const list = data.list
// for (let pid in list) {
// var pids = list[pid].command
// if (pids.includes("bedrock_server")){global.bds_cpu = Math.trunc(list[pid].pcpu)} else {pid++}
// }
// const text = `Bds CPU usage: ${bds_cpu}%, Total CPU utilization: ${current_cpu}%\n\n\nTotal ram memory: ${ram_total} GB, Total free ram memory: ${ram_free} GB`
// ctx.replyWithMarkdown(text);
// delete(bds_cpu);
// delete(current_cpu);
// delete(ram_total);
// delete(ram_free);
// })
// })
// })
// })
// });
bot.command("log", (ctx) => {
const file_log_path = require("../index").log_file;
const fs = require("fs")

136
index.js
View File

@ -41,6 +41,31 @@ 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") {
<<<<<<< HEAD
var home = process.env.USERPROFILE;
var desktop = path.join(home, "Desktop")
if (fs.existsSync(package_root)){
var cache_dir = path.join(home, "AppData", "Roaming", require(package_root).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`);
}
var tmp = process.env.TMP
var system = `windows`;
} else if (process.platform == "linux") {
var home = process.env.HOME;
if (fs.existsSync(package_root)){
var cache_dir = path.join(home, ".config", require(package_root).name);
} else {
console.warn(`Temporary Storages, some functions will be lost after restarting the system`);
var 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"}
var tmp = `/tmp`;
var system = `linux`;
=======
home = process.env.USERPROFILE;
desktop = path.join(home, "Desktop")
if (fs.existsSync(package_root)){
@ -84,6 +109,7 @@ if (process.platform == "win32") {
tmp = "/tmp";
system = "linux";
>>>>>>> main
} 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")
@ -91,6 +117,53 @@ if (process.platform == "win32") {
} else {
console.log(`Please use an operating system (OS) compatible with Minecraft Bedrock Server ${process.platform} is not supported`);
process.exit(2021)
<<<<<<< HEAD
};
// ---------
// ---------
var bds_dir = path.join(home, "bds_Server");
var bds_dir_bedrock = path.join(bds_dir, 'bedrock');
var bds_dir_java = path.join(bds_dir, 'java');
var bds_dir_backup = path.join(bds_dir, 'backups');
module.exports.backup_folder = bds_dir_backup
if (!(fs.existsSync(bds_dir))){
console.log("Creating the bds directory")
fs.mkdirSync(bds_dir)
if (!(fs.existsSync(bds_dir))) shell.mkdir("-p", bds_dir);
}
// Configs
const bds_config_file = path.join(bds_dir, "bds_config.json")
if (fs.existsSync(bds_config_file)){
var bds_config = JSON.parse(fs.readFileSync(bds_config_file, "utf-8"))
} else {
const _config = `{
"bds_platform": "bedrock",
"telegram_token": null
}`
var bds_config = JSON.parse(_config)
fs.writeFileSync(bds_config_file, _config)
}
module.exports.platform = bds_config.bds_platform
console.log(`Running on the \"${bds_config.bds_platform}\" platform`)
// Configs
var log_dir = path.join(bds_dir, "log");
var log_file = path.join(log_dir, `${date()}_${bds_config.bds_platform}_Bds_log.log`);
var log_date = date();
// ---------
// ---------
if (!(fs.existsSync(cache_dir))){
console.log(`Creating a folder for Storage in ${cache_dir}`);
fs.mkdirSync(cache_dir)
if (!(fs.existsSync(cache_dir))) shell.mkdir("-p", cache_dir);
}
=======
}
// ---------
// ---------
@ -142,6 +215,7 @@ if (!(fs.existsSync(cache_dir))){
fs.mkdirSync(cache_dir)
if (!(fs.existsSync(cache_dir))) shell.mkdir("-p", cache_dir);
}
>>>>>>> main
// e
if (!(fs.existsSync(bds_dir_java))){
console.log("Creating the bds directory to Java")
@ -159,6 +233,33 @@ if (!(fs.existsSync(log_dir))){
console.log(`Creating the bds log dir (${log_dir})`)
fs.mkdirSync(log_dir)
if (!(fs.existsSync(log_dir))) shell.mkdir("-p", log_dir)
<<<<<<< HEAD
};
};
// e
if (require("fs").existsSync(`${bds_dir}/telegram_token.txt`)){
module.exports.token = fs.readFileSync(`${bds_dir}/telegram_token.txt`, "utf8").replaceAll("\n", "");
} else {
module.exports.token = undefined;
}
module.exports.telegram_token_save = (token) =>{
fs.writeFileSync(`${bds_dir}/telegram_token.txt`, token);
return "OK"
}
if (typeof fetch === "undefined"){global.fetch = require("node-fetch")}
if (typeof localStorage === "undefined"){
var localStorageS = require("node-localstorage").LocalStorage;
global.localStorage = new localStorageS(`${cache_dir}/Local_Storage`);
}
// Java or Bedrock
if (process.env.JAVA_ENABLE !== undefined){
localStorage.setItem('bds_edititon', 'java');
}else{
localStorage.setItem('bds_edititon', 'bedrock');
=======
}
}
// e
@ -216,6 +317,7 @@ if (require("fs").existsSync(path.join(bds_dir, "telegram_token.txt"))){
} catch {
throw new error("It was not possible to move the old telegram token file to the new bds maneger api file")
}
>>>>>>> main
}
if (process.env.BDS_MONI == blanks){process.env.BDS_MONI = "false"}
@ -228,6 +330,9 @@ fetch("https://raw.githubusercontent.com/Bds-Maneger/Raw_files/main/credentials.
* backup credentials and an interesting design feature, plus privacy is important
*/
module.exports.google_drive_credential = gd_cre
<<<<<<< HEAD
module.exports.mcpe_file = require("./global/auth").mcpe
=======
/**
* download the latest version of minecraft bedrock for android available, remember to use if you want
*
@ -241,15 +346,22 @@ fetch("https://raw.githubusercontent.com/Bds-Maneger/Raw_files/main/credentials.
*
* on the java platform the map selected in the server configuration will be backed up, any other map will have to change in the server settings to perform the backup
*/
>>>>>>> main
module.exports.drive_backup= require("./global/auth").drive_backup
});
fetch("https://raw.githubusercontent.com/Bds-Maneger/Raw_files/main/Server.json").then(response => response.json()).then(rawOUT => {
const versions = Object.getOwnPropertyNames(rawOUT.bedrock);
for (let v in versions){
var html = `${versions[v]}`;
<<<<<<< HEAD
module.exports.version_select += `<option value=\"${html}\">${html}</option>\n`;
v++;
};
=======
module.exports.version_select += `<option value="${html}">${html}</option>\n`;
v++;
}
>>>>>>> main
module.exports.bedrock_all_versions = Object.getOwnPropertyNames(rawOUT.bedrock);
module.exports.java_all_versions = Object.getOwnPropertyNames(rawOUT.java);
module.exports.bds_latest = rawOUT.bedrock_lateste;
@ -260,9 +372,16 @@ fetch("https://raw.githubusercontent.com/Bds-Maneger/Raw_files/main/Server.json"
if (typeof bds_api_start === "undefined"){
require("./API/api")();
require("./API/log")();
<<<<<<< HEAD
require("./API/remote_access")();
}
} else {
console.warn(`The API via http is disabled, for more information, visit https://docs.srherobrine23.com/enable_bds_requests.html`)
=======
}
} else {
console.warn("The API via http is disabled, for more information, visit https://docs.srherobrine23.com/enable_bds_requests.html")
>>>>>>> main
}
module.exports.get_version = (type) => {
if (type == "raw")
@ -353,6 +472,22 @@ module.exports.date = date
* @example bds.command("say hello from Bds Maneger")
*/
module.exports.command = require("./global/command").command
<<<<<<< HEAD
// module.exports.stop = require("./global/stop").Server_stop
// New management method
module.exports.start = require("./new_script/basic_server").start
module.exports.stop = require("./new_script/basic_server").stop
module.exports.backup = require("./new_script/backups").World_BAckup
module.exports.detect = require("./new_script/detect")
module.exports.bds_detect = require("./new_script/detect")
module.exports.version_Download = require("./new_script/bds_download")
module.exports.download = require("./new_script/bds_download")
module.exports.kill = require("./new_script/kill_server")
module.exports.config_example = require("./new_script/bds_settings").config_example
module.exports.set_config = require("./new_script/bds_settings").config
module.exports.get_config = require("./new_script/bds_settings").get_config
=======
// New management method
/**
@ -424,3 +559,4 @@ module.exports.set_config = require("./scripts/bds_settings").config
* takes the server settings in JSON format
*/
module.exports.get_config = require("./scripts/bds_settings").get_config
>>>>>>> main

81
new_script/backups.js Normal file
View File

@ -0,0 +1,81 @@
module.exports.World_BAckup = () => {
const bds = require('../index')
const path = require("path")
const java_pro = require("properties-to-json")
const fs = require("fs")
var AdmZip = require("adm-zip");
var today = bds.date()
const name = path.join(bds.backup_folder ,`bds_backup_World_${today}.zip`)
if (bds.platform === "bedrock"){
var dir_zip = path.join(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}/`
}
/**
* 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()}
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();
zipEntries.forEach(function (zipEntry) {
console.log(zipEntry.entryName.toString());
});
zip.writeZip(name);
return {
path: name,
world_path: dir_zip
}
};
module.exports.Drive_backup = () => {
const bds = require('../index')
const path = require("path")
const java_pro = require("properties-to-json")
const fs = require("fs")
var AdmZip = require("adm-zip");
var today = bds.date()
const name = path.join(bds.backup_folder ,`bds_backup_World_${today}.zip`)
if (bds.platform === "bedrock"){
var 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}/`
}
/**
* 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 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 = 0;
for(es == "-0";es++;){
if (!(status_b)) break
}
delete(status_b)
const js_ = {
"file_path": name,
"file_name": `bds_backup_World_${today}.zip`,
"id": undefined
}
return js_
};

View File

@ -0,0 +1,79 @@
module.exports.start = () => {
const bds = require("../index")
const Storage = localStorage;
const exec = require("child_process").exec;
const fs = require('fs')
if (!(bds.detect())){
const plat = bds.platform
if (plat === "bedrock"){
if (process.platform == "win32"){
var start_server = exec(`bedrock_server.exe`, {cwd: bds.bds_dir_bedrock});
} else if (process.platform == "linux"){
var start_server = exec(`chmod 777 bedrock_server && ./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 -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");
console.log("http://docs.sirherobrine23.com/bds_maneger_api_java#Windows")
} else if (bds.system === 'linux'){
require('open')("http://docs.sirherobrine23.com/bds_maneger_api_java#Linux");
console.log("http://docs.sirherobrine23.com/bds_maneger_api_java#Linux")
} else {
require('open')("http://docs.sirherobrine23.com/bds_maneger_api_java");
console.log("http://docs.sirherobrine23.com/bds_maneger_api_java")
}
}
}
Storage.setItem("old_log_file", bds.log_file)
var logConsoleStream = require("fs").createWriteStream(bds.log_file, {flags: "a"});
start_server.stdout.pipe(logConsoleStream);
start_server.stdout.on("data", function(data){
if (data.includes("agree", "EULA")){
const path = require('path');
require('open')("https://account.mojang.com/documents/minecraft_eula");
const eula_file = path.join(bds.bds_dir_java, "eula.txt")
const eula_make_true = fs.readFileSync(eula_file, "utf-8").replace("eula=false", "eula=true")
fs.writeFileSync(eula_file, eula_make_true)
const node_detect = process.argv[0]
if (node_detect.includes('node')){
console.warn(`Ending the process`)
setTimeout(() => {
process.exit(0)
}, 1000);
}
}
})
if (typeof bds_log_string !== "undefined"){delete(bds_log_string)}
start_server.stdout.on("data", function(data){global.bds_log_string += data})
Storage.setItem("bds_status", true);
global.bds_server_string = start_server;
return start_server;
} else {
console.warn(`You already have a server running`);
return `You already have a server running`;
}
}
module.exports.stop = () => {
if (typeof bds_server_string == "undefined"){
const detect = process.argv[0];
if (detect.includes('electron')) alert("The server is stopped!");
else console.log("The server is stopped!");
} else {
bds_server_string.stdin.write("stop\n");
bds_server_string.stdout.on("data", function (data){
if (data.includes("Quit correctly")){
localStorage.setItem("bds_status", false)
};
});
};
return
}

View File

@ -0,0 +1,88 @@
module.exports = (Vdown) => {
console.warn("Do not exit BDS Manager")
const bds = require('../index')
fetch("https://raw.githubusercontent.com/Bds-Maneger/Raw_files/main/Server.json").then(response => response.json()).then(versions => {
if (bds.platform === "bedrock"){
const system = bds.system
var mine_name = `bedrock.zip`
var server_DIR = bds.bds_dir_bedrock;
if (system === 'linux'){
var versions_get = versions.bedrock[Vdown].url_linux;
} else {
var versions_get = versions.bedrock[Vdown].url_windows;
}
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}`, {
cwd: `${bds.tmp_dir}`
});
var ZIP_FILE_PATH = `${bds.tmp_dir}/${mine_name}`;
downloadBDSchild.stdout.on("data", function(data){
console.log(data)
})
downloadBDSchild.on("exit", function (code) {
if (code === 0) {
console.log(`Download zip file success`);
var AdmZip = require("adm-zip");
const fs = require("fs")
if (fs.existsSync(`${server_DIR}/server.properties`)){var _old = true;var old1 = fs.readFileSync(`${server_DIR}/server.properties`, "utf-8");}
if (fs.existsSync(`${server_DIR}/permissions.json`)){var _old2 = true;var old2 = fs.readFileSync(`${server_DIR}/permissions.json`, "utf-8");}
if (fs.existsSync(`${server_DIR}/whitelist.json`)) {var _old3 = true;var old3 = fs.readFileSync(`${server_DIR}/whitelist.json`, "utf-8");}
if (fs.existsSync(`${server_DIR}/valid_known_packs.json`)){var _old4 = true;var old4 = fs.readFileSync(`${server_DIR}/valid_known_packs.json`, "utf-8");};
// Unzip
var zip = new AdmZip(ZIP_FILE_PATH);
var zipEntries = zip.getEntries();
var totalfiles = zipEntries.length
zipEntries.forEach(function(zipEntry) {
totalfiles--
if (totalfiles === 0){
if (_old){fs.writeFileSync(`${server_DIR}/server.properties`, old1);}
if (_old2){fs.writeFileSync(`${server_DIR}/permissions.json`, old2);}
if (_old3){fs.writeFileSync(`${server_DIR}/whitelist.json`, old3);}
if (_old4){fs.writeFileSync(`${server_DIR}/valid_known_packs.json`, old4);};
const docker_exit = process.env.BDS_DOCKER_IMAGE
console.log(docker_exit)
if (docker_exit == "true"){
console.log(`going out`)
process.exit(0)
}
}
});
zip.extractAllTo(server_DIR, true);
console.log("Downlod Sucess"); // End Unzip
localStorage.setItem("Downlaod_sucess", "yes")
} else {
localStorage.setItem("Download_sucess", "no")
throw new error(`Could not download`);
}
})
} else {
var versions_get = versions.java[Vdown].url
var 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}`, {
cwd: `${bds.bds_dir_java}`
});
downloadBDSchild.stdout.on("data", function(data){
console.log(data)
})
downloadBDSchild.on("exit", function (code) {
if (code === 0) {
console.log(`Download zip file success`);
localStorage.setItem("Downlaod_sucess", "yes")
} else {
localStorage.setItem("Download_sucess", "no")
throw new error(`Could not download`);
}
})
}
// ---------------------------------------------------------
})
}

178
new_script/bds_settings.js Normal file
View File

@ -0,0 +1,178 @@
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;
if (json_config.includes(".json")){
var config = JSON.parse(fs.readFileSync(json_config, "utf8"))
} else var config = JSON.parse(json_config)
if (config.description == undefined) var description_name = `Dedicated Server`;
else var description_name = config.description;
// Level Name
if (config.name == undefined) var level_name = `Bedrock level`;
else var level_name = config.name;
// gamemode
if (config.gamemode == undefined) var gamemode = `survival`;
else var gamemode = config.gamemode;
// Difficulty
if (config.difficulty == undefined) var difficulty = `easy`;
else var difficulty = config.difficulty;
// cheats
if (config.cheats == undefined) var allow_cheats = false;
else var allow_cheats = config.cheats;
// Maximo de Jogadores
if (config.players == undefined) var max_players = 10;
else var max_players = config.players;
// Xbox authentication outside the internal network
if (config.xbox == undefined) var online_mode = true;
else var online_mode = config.xbox;
// Whitelist
if (config.white_list == undefined){var white_list = false;} else {var white_list = config.white_list;};
// Server Port IPv4
if (config.port == undefined){var server_port = 19132;} else {var server_port = config.port;};
// Server Port IPv6
if (config.port6 == undefined){var server_portv6 = 19133;} else {var server_portv6 = config.port6;};
// Default player permission
if (config.player_permission == undefined) var player_permission = `member`;
else var player_permission = config.player_permission;
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
/*Save Files*/
if (bds.platform === 'bedrock'){
var config_file_content = `server-name=${description_name}
gamemode=${gamemode}
difficulty=${difficulty}
allow-cheats=${allow_cheats}
max-players=${max_players}
online-mode=${online_mode}
white-list=${white_list}
server-port=${server_port}
server-portv6=${server_portv6}
view-distance=32
tick-distance=${tick}
player-idle-timeout=0
max-threads=${CPU}
level-name=${level_name}
level-seed=
default-player-permission-level=${player_permission}
texturepack-required=true
content-log-file-enabled=false
compression-threshold=1
server-authoritative-movement=server-auth
player-movement-score-threshold=20
player-movement-distance-threshold=0.3
player-movement-duration-threshold-in-ms=500
correct-player-movement=false
# Created on Bds-Manager by Sirherobrine23`
} else {
var config_file_content = `enable-jmx-monitoring=false
rcon.port=25575
level-seed=
gamemode=${gamemode}
enable-command-block=${allow_cheats}
enable-query=true
generator-settings=
level-name=${level_name}
motd=${description_name}
query.port=${server_port}
pvp=true
generate-structures=true
difficulty=${difficulty}
network-compression-threshold=256
max-tick-time=60000
max-players=${max_players}
use-native-transport=true
online-mode=${online_mode}
enable-status=true
allow-flight=false
broadcast-rcon-to-ops=true
view-distance=32
max-build-height=256
server-ip=
allow-nether=true
server-port=${server_port}
enable-rcon=${allow_cheats}
sync-chunk-writes=true
op-permission-level=4
prevent-proxy-connections=false
resource-pack=
entity-broadcast-range-percentage=100
rcon.password=25as65d3
player-idle-timeout=0
force-gamemode=false
rate-limit=0
hardcore=false
white-list=${white_list}
broadcast-console-to-ops=true
spawn-npcs=true
spawn-animals=true
snooper-enabled=true
function-permission-level=2
level-type=default
text-filtering-config=
spawn-monsters=true
enforce-whitelist=false
resource-pack-sha1=
spawn-protection=16
max-world-size=29999984
#
# Created on Bds-Manager by Sirherobrine23`
}
// console.log(config_file_content);
fs.writeFileSync(Server_Config, config_file_content);
return `success`
};
function bds_get_config(){
var fs = require("fs");
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")
return propertiesToJSON(fs.readFileSync(config_path, "utf8").replaceAll("-","_"));
}
module.exports.config_example = () =>{
return {
name: "Bedrock our Java",
description: "BDS Maneger",
gamemode: "survival",
difficulty: "normal",
player_permission: "member",
xbox: true,
white_list: false,
cheats: false,
players: 100,
port: 19132,
port6: 19133
}
}
module.exports.config = bds_config
module.exports.get_config = bds_get_config

20
new_script/detect.js Normal file
View File

@ -0,0 +1,20 @@
module.exports = () => {
var spawn = require("child_process").execSync;
const bds = require("../index")
if (bds.platform === "bedrock"){
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)`);
} 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});
}
} else {
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)`);
} else if (process.platform == "linux") {
var killbds = spawn(`ps aux|grep -v "grep"|grep "bedrock_server"|grep -q "bedrock_server";echo $?`, {shell: true});
}
}
//
if (killbds == 0){return true} else {return false};
};

25
new_script/kill_server.js Normal file
View File

@ -0,0 +1,25 @@
module.exports = () => {
const bds = require("../index")
var spawn = require("child_process").exec;
const Storage = localStorage
if (bds.bds_detect()){
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});
} 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)`);
} else if (process.platform == "linux") {
var killbds = spawn(`kill $(ps aux|grep -v "grep"|grep "server.jar"|awk '{print $2}')`, {shell: true});
}
}
killbds.on("exit", function () {
killbds.stdin.end();
});
Storage.setItem("bds_status", false);
return true
} else {
Storage.setItem("bds_status", false);
return false
};
};

351
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,9 +1,14 @@
{
<<<<<<< HEAD
"name": "bds_maneger_api",
"version": "1.4.2",
=======
"name": "@the-bds-maneger/bds_maneger_api",
"publishConfig": {
"access": "public"
},
"version": "1.5.4",
>>>>>>> main
"description": "scripts to manage minecraft bedrock server",
"private": false,
"main": "index.js",
@ -47,7 +52,11 @@
"qrcode": "^1.4.4",
"request-ip": "^2.1.3",
"shelljs": "^0.8.4",
<<<<<<< HEAD
"systeminformation": "^5.0.2",
=======
"systeminformation": "^5.0.10",
>>>>>>> main
"telegraf": "^4.0.0"
},
"engines": {