Merge #31

Merged
Sirherobrine23 merged 14 commits from main into stable 2021-02-09 17:53:17 +00:00
21 changed files with 4019 additions and 319 deletions

28
.eslintrc.json Normal file
View File

@ -0,0 +1,28 @@
{
"env": {
"browser": true,
"commonjs": true,
"es2021": true,
"node": true,
"shelljs": true
},
"globals": {
"bds_log_string": "writable",
"bds_server_string": "writable"
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": 12,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
}
},
"rules": {
"quotes": [
"error",
"double"
],
"eqeqeq": 0
}
}

5
.github/workflows/get_version.sh vendored Normal file
View File

@ -0,0 +1,5 @@
#!/bin/bash
v=`cat package.json | jq '.version'|sed 's|"||g'`
d=`cat package.json | jq '.dependencies' | tr "\n" " " | sed 's|\^||g' | sed 's| ||g'`
echo "bds_api_version=${v}" >> $GITHUB_ENV
echo "bds_api_depe=${d}" >> $GITHUB_ENV

View File

@ -4,9 +4,12 @@ on:
push:
branches:
- main
paths-ignore:
- 'README.md'
- '.github/*/**'
- 'package-lock.json'
- '.devcontainer/**'
- 'CHANGELOG.md'
jobs:
check:
strategy:
@ -62,3 +65,20 @@ jobs:
run: npm publish --tag dev
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Get Infos
run: bash .github/workflows/get_version.sh
- name: Tag
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
name: Bds Maneger API v${{ env.bds_api_version }}
tag_name: ${{ github.run_id }}
prerelease: true
body: |
Install: npm install bds_maneger_api@dev
Install: npm install bds_maneger_api@${{ env.bds_api_version }}
Bds Maneger API publish Version (dev): ${{ env.bds_api_version }}
Bds Maneger API depedencies: ${{ env.bds_api_depe }}

View File

@ -1,11 +1,14 @@
name: Stable Publish
on:
push:
tags:
- "*.*"
- "v*.*"
branches:
- stable
paths-ignore:
- 'README.md'
- '.github/*/**'
- 'package-lock.json'
- '.devcontainer/**'
- 'CHANGELOG.md'
jobs:
Publish:
runs-on: ubuntu-latest
@ -52,4 +55,20 @@ jobs:
- name: Publish
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Get Infos
run: bash .github/workflows/get_version.sh
- name: Tag
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
name: Bds Maneger API v${{ env.bds_api_version }}
tag_name: ${{ env.bds_api_version }}
body: |
Install: npm install bds_maneger_api@latest
Install: npm install bds_maneger_api@${{ env.bds_api_version }}
Bds Maneger API publish Version: ${{ env.bds_api_version }}
Bds Maneger API depedencies: ${{ env.bds_api_depe }}

View File

@ -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');
const path = require("path");
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,12 +52,12 @@ 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
const command_bds = body.command
const tokens = JSON.parse(fs.readFileSync(path.join(bds.bds_dir, "bds_tokens.json"), "utf-8"))
const tokens = JSON.parse(fs.readFileSync(path.join(bds.bds_dir, "bds_tokens.json"), "utf8"))
var pass = false;
for (let token_verify in tokens) {
const element = tokens[token_verify].token;
@ -68,14 +68,15 @@ module.exports = () => {
}
}
if (pass){
if (command_bds === 'start'){
var bds_init = bds.start()
var command_status = `Bds Started`
} else if (command_bds === 'stop'){
var command_status
if (command_bds === "start"){
bds.start()
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,
@ -91,7 +92,7 @@ module.exports = () => {
app.post("/bds_download", (req, res) => {
const body = req.body
const ver = body.version
const tokens = JSON.parse(fs.readFileSync(path.join(bds.bds_dir, "bds_tokens.json"), "utf-8"))
const tokens = JSON.parse(fs.readFileSync(path.join(bds.bds_dir, "bds_tokens.json"), "utf8"))
var pass = false;
for (let token_verify in tokens) {
const element = tokens[token_verify].token;
@ -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,
@ -115,7 +117,7 @@ module.exports = () => {
});
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"))
const tokens = JSON.parse(fs.readFileSync(path.join(bds.bds_dir, "bds_tokens.json"), "utf8"))
var pass = false;
for (let token_verify in tokens) {
const element = tokens[token_verify].token;

View File

@ -4,27 +4,44 @@ module.exports = () => {
const bds = require("../index");
const fs = require("fs");
const app = express();
var cors = require('cors');
var cors = require("cors");
app.use(cors());
const rateLimit = require("express-rate-limit");
const limiter = rateLimit({
windowMs: 5 * 60 * 1000, // 5 minutes
message: {
"status": false,
"log": "we had an overflow of log requests, please wait 5 minutes."
},
statusCode: 200,
max: 5000 // limit each IP to 5000 requests per windowMs
});
app.use(limiter);
const requestIp = require("request-ip");
app.use(requestIp.mw())
app.get("/", (req, res) => {
if (typeof bds_log_string === 'undefined'){
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,
"log": text,
"log_file": log_file,
"ip": `${req.clientIp}`,
"requeset_date": bds.date()
});
});

View File

@ -18,6 +18,5 @@ This module was made to work both in the cli version and in gui versions like el
some deven ports are unlocked by the firewall if enabled:
- 28574
- 1932
- 6565

View File

@ -42,30 +42,31 @@ function getAccessToken(oAuth2Client, callback) {
callback(oAuth2Client);
});
});
};
}
module.exports.drive_backup = () => {
const file_json = require("../new_script/backups").Drive_backup()
const file_json = require("../scripts/backups").Drive_backup()
console.log(file_json)
const parent_id = file_json.id
const path_file = file_json.file_path
const name_d = file_json.file_name;
const gd_secret = '';
const gd_secret = "";
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]
}
};
}
var media = {
mimeType: "application/octet-stream",
body: fs.createReadStream(path_file)
@ -101,6 +102,6 @@ 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)});
};
}
return authorize(gd_secret, download_mcpe);
}

View File

@ -1,21 +1,28 @@
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, "utf8");
} 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(index in adm){
if (USERNAME == index){
for(let check_ in adm){
if (USERNAME == check_){
return true
} else if (index == "sh23_bot_not_config"){
} else if (check_ == "sh23_bot_not_config"){
console.warn("Allow all")
return true
}; index++;
};
} check_++;
}
return false
}

View File

@ -1,5 +1,5 @@
const { Telegraf } = require("telegraf")
const token = require("../index").token
const token = require("../index").telegram_token
const bot = new Telegraf(token)
bot.start((ctx) => {
const amenssagem = `Hello ${ctx.message.from.username}
@ -27,27 +27,27 @@ bot.command("server_start", (ctx) => {
document.getElementById("startButtom").click()
} else {
require("../index").start()
};
ctx.reply(`The server has started`)
}
ctx.reply("The server has started")
} else
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) => {
if (require("./check").checkUser(ctx.message.from.username)){
const bds_status = require("../index").detect()
if (bds_status){
require("../index").stop()
ctx.reply(`O servidor esta parando`)
ctx.reply("O servidor esta parando")
} else
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) =>{
const bds_command = require("../index").command

332
index.js
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}`)
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,49 +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`);
console.warn("Temporary Storages, some functions will be lost after restarting the system");
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`;
console.warn("Temporary Storages, some functions will be lost after restarting the system");
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")
@ -78,13 +91,20 @@ 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)
};
}
// ---------
// ---------
if (typeof fetch === "undefined"){
global.fetch = require("node-fetch")
}
if (typeof localStorage === "undefined"){
var localStorageS = require("node-localstorage").LocalStorage;
global.localStorage = new localStorageS(path.join(cache_dir, "Local_Storage"));
}
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');
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))){
@ -96,17 +116,16 @@ if (!(fs.existsSync(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"))
var bds_config = JSON.parse(fs.readFileSync(bds_config_file, "utf8"))
} else {
const _config = `{
const bds_config = {
"bds_platform": "bedrock",
"telegram_token": null
}`
var bds_config = JSON.parse(_config)
fs.writeFileSync(bds_config_file, _config)
"telegram_token": "not User defined"
}
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");
@ -140,31 +159,63 @@ 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)
};
};
}
}
// 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;
/**
* with this command we can change the platform with this script
*
* bedrock change_platform("bedrock")
*
* java change_platform("java")
* @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))
config_load.bds_platform = plate
fs.writeFileSync(bds_config, JSON.stringify(config_load))
console.log(`upgrading the bedrock ${plate}`)
} catch (error) {
throw new console.error(`Something happened error code: ${error}`);
}
}
if ((process.env.SERVER || "bedrock").includes("java", "JAVA")){
platform_update("java")
}else{
platform_update("bedrock")
}
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`);
try {
const bds_config = path.join(bds_dir, "bds_config.json")
const config_load = JSON.parse(fs.readFileSync(bds_config))
config_load.telegram_token = token
fs.writeFileSync(bds_config, JSON.stringify(config_load))
return true
} catch {
return false
}
}
// Java or Bedrock
if (process.env.JAVA_ENABLE !== undefined){
localStorage.setItem('bds_edititon', 'java');
}else{
localStorage.setItem('bds_edititon', 'bedrock');
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`)
try {
const token = fs.readFileSync(path.join(bds_dir, "telegram_token.txt"), "utf8").split("\n").join("")
require("./index").telegram_token_save(token)
fs.rmSync(path.join(bds_dir, "telegram_token.txt"))
console.log("We finished migrating the old telegram token file")
} catch {
throw new error("It was not possible to move the old telegram token file to the new bds maneger api file")
}
}
if (process.env.BDS_MONI == blanks){process.env.BDS_MONI = "false"}
@ -173,17 +224,32 @@ if (process.env.ENABLE_BDS_API == blanks){process.env.ENABLE_BDS_API = "false"}
// Fetchs
fetch("https://raw.githubusercontent.com/Bds-Maneger/Raw_files/main/credentials.json").then(response => response.text()).then(gd_cre => {
/**
* backup credentials and an interesting design feature, plus privacy is important
*/
module.exports.google_drive_credential = gd_cre
/**
* download the latest version of minecraft bedrock for android available, remember to use if you want
*
* you are taking responsibility for that
*/
module.exports.mcpe_file = require("./global/auth").mcpe
/**
* perform a backup of the map, some resources are still under construction in the code more works
*
* on the bedrock platform, all maps will be backed up into the "worlds" folder
*
* 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
*/
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]}`;
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);
module.exports.java_all_versions = Object.getOwnPropertyNames(rawOUT.java);
module.exports.bds_latest = rawOUT.bedrock_lateste;
@ -196,7 +262,7 @@ fetch("https://raw.githubusercontent.com/Bds-Maneger/Raw_files/main/Server.json"
require("./API/log")();
}
} else {
console.warn(`The API via http is disabled, for more information, visit https://docs.srherobrine23.com/enable_bds_requests.html`)
console.warn("The API via http is disabled, for more information, visit https://docs.srherobrine23.com/enable_bds_requests.html")
}
module.exports.get_version = (type) => {
if (type == "raw")
@ -209,14 +275,41 @@ fetch("https://raw.githubusercontent.com/Bds-Maneger/Raw_files/main/Server.json"
// Module export
/* Variaveis */
/**
* this variable makes available the location of the user profile directory as
*
* Linux: /home/USER/
*
* Windows: C:\\Users\\USER\\
*
* MacOS: not supported
*/
module.exports.home = home
/**
* With different languages and systems we want to find the user's desktop for some link in the directory or even a nice shortcut
*/
module.exports.desktop = desktop
/**
* Identifying a system in the script can be simple with this variable
*/
module.exports.system = system
/**
* The most important directory of this project, here are saved some important things like:
*
* The server software
*
* configuration of the Bds Manager API
*
* Backups etc ...
*/
module.exports.bds_dir = bds_dir
module.exports.bds_dir_bedrock = bds_dir_bedrock
module.exports.bds_dir_java = bds_dir_java
module.exports.tmp_dir = tmp
module.exports.electron = electron_de
module.exports.api_dir = cache_dir
@ -224,23 +317,110 @@ module.exports.log_file = log_file
module.exports.log_date = log_date
module.exports.arch = archi
// module.exports.token = JSON.parse(fs.readFileSync(path.join(bds_dir, "bds_config.json"))).telegram_token
module.exports.telegram_token = JSON.parse(fs.readFileSync(path.join(bds_dir, "bds_config.json"))).telegram_token
// Global commands
module.exports.telegram = require("./global/telegram_bot")
module.exports.token_register = () => {if (!(fs.existsSync(path.join(bds_dir, "bds_tokens.json")))){fs.writeFileSync(path.join(bds_dir, "bds_tokens.json"), "[]")};require("crypto").randomBytes(10, function(err, buffer) {var token = buffer.toString("hex");console.log(token);var QRCode = require("qrcode");QRCode.toString(token, function (err, url) {fs.readFile(path.join(bds_dir, "bds_tokens.json"), "utf8", function (err, data){if (err){console.log(err);} else {obj = JSON.parse(data);var count = Object.keys(obj).length;var teste = {count, token};obj.push(teste);json = JSON.stringify(obj);fs.writeFileSync(path.join(bds_dir, "bds_tokens.json"), json, "utf8");}});})});}
module.exports.change_platform = platform_update
module.exports.token_register = () => {
if (!(fs.existsSync(path.join(bds_dir, "bds_tokens.json")))){
fs.writeFileSync(path.join(bds_dir, "bds_tokens.json"), "[]")}
require("crypto").randomBytes(10, function(err, buffer) {
var token = buffer.toString("hex");
console.log(token);
var QRCode = require("qrcode");
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 {
var objeto = JSON.parse(data);
var count = Object.keys(objeto).length;
var teste = {count, token};
objeto.push(teste);
var json_ = JSON.stringify(objeto);
fs.writeFileSync(path.join(bds_dir, "bds_tokens.json"), json_, "utf8");}
});
})
})
}
module.exports.date = date
/**
* sending commands more simply to the server
*
* @example bds.command("say hello from Bds Maneger")
*/
module.exports.command = require("./global/command").command
// 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
/**
* to start the server here in the sera script with child_process, then you will have to use the return function for your log custumization or anything else
*
* @example const server = bds.start();
* server.on.stdout("date", function (log){console.log(log)})
*/
module.exports.start = require("./scripts/basic_server").start
/**
* use this command for the server, that's all
*/
module.exports.stop = require("./scripts/basic_server").stop
/**
* backup your map locally
*/
module.exports.backup = require("./scripts/backups").World_BAckup
/**
* identify if there are any servers running in the background
*
* @example bds.detect()
* // true: if the server is running
* // false: if not already
*/
module.exports.detect = require("./scripts/detect")
module.exports.bds_detect = require("./scripts/detect")
/**
* @deprecated
*/
module.exports.version_Download = require("./scripts/bds_download")
/**
* download some version of the java and Bedrock servers in the highest possible form
*
* @example
* bedrock: bds.download("1.16.201.02")
*
* java: bds.download("1.16.5")
*/
module.exports.download = require("./scripts/bds_download")
/**
* this function will be used to kill the server in the background
*/
module.exports.kill = require("./scripts/kill_server")
module.exports.config_example = require("./scripts/bds_settings").config_example
/**
* use this command to modify server settings
*
* @example
*
* bds.set_config({
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.set_config = require("./scripts/bds_settings").config
/**
* takes the server settings in JSON format
*/
module.exports.get_config = require("./scripts/bds_settings").get_config

View File

@ -1,21 +0,0 @@
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 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});
}
} 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)`);
} 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});
}
}
//
console.log(`Detect code ${killbds}`)
if (killbds == 0){return true} else {return false};
};

View File

@ -1,25 +0,0 @@
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
};
};

3424
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -5,7 +5,8 @@
"private": false,
"main": "index.js",
"scripts": {
"test": "exit 0",
"test": "eslint .",
"test:fix": "eslint --fix .",
"server": "node index.js"
},
"repository": {
@ -41,8 +42,15 @@
"properties-to-json": "^0.1.7",
"qr-image": "^3.2.0",
"qrcode": "^1.4.4",
"request-ip": "^2.1.3",
"shelljs": "^0.8.4",
"systeminformation": "^5.0.10",
"telegraf": "^4.0.0"
},
"engines": {
"node": ">=14"
},
"devDependencies": {
"eslint": "^7.19.0"
}
}

View File

@ -1,5 +1,5 @@
module.exports.World_BAckup = () => {
const bds = require('../index')
const bds = require("../index")
const path = require("path")
const java_pro = require("properties-to-json")
const fs = require("fs")
@ -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}/`
const world_name = JSON.parse(java_pro(fs.readFileSync(path.join(bds.bds_dir_java, "server.properties"), "utf8").replaceAll("-", "_"))).level_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
@ -33,7 +34,7 @@ module.exports.World_BAckup = () => {
};
module.exports.Drive_backup = () => {
const bds = require('../index')
const bds = require("../index")
const path = require("path")
const java_pro = require("properties-to-json")
const fs = require("fs")
@ -41,36 +42,27 @@ 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}/`
const world_name = JSON.parse(java_pro(fs.readFileSync(path.join(bds.bds_dir_java, "server.properties"), "utf8").replaceAll("-", "_"))).level_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 = 0;
for(es == "-0";es++;){
let es = 1;
for(es == "0";es++;){
if (!(status_b)) break
}
delete(status_b)
const js_ = {
"file_path": name,
"file_name": `bds_backup_World_${today}.zip`,

View File

@ -2,32 +2,33 @@ module.exports.start = () => {
const bds = require("../index")
const Storage = localStorage;
const {exec, execSync} = require("child_process");
const fs = require('fs')
const fs = require("fs")
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});
console.log(execSync("chmod 777 bedrock_server", {cwd: bds.bds_dir_bedrock}).toString())
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 -jar server.jar nogui`, {cwd: bds.bds_dir_java});
if (require("command-exists").sync("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");
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");
} 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");
require("open")("http://docs.sirherobrine23.com/bds_maneger_api_java");
console.log("http://docs.sirherobrine23.com/bds_maneger_api_java")
}
}
@ -39,42 +40,42 @@ module.exports.start = () => {
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 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")
const eula_make_true = fs.readFileSync(eula_file, "utf8").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`)
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)}
if (typeof bds_log_string !== "undefined"){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`;
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!");
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

@ -1,35 +1,38 @@
module.exports = (Vdown) => {
console.warn("Do not exit BDS Manager")
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 => {
var mine_name
var downloadBDSchild
if (bds.platform === "bedrock"){
const system = bds.system
var mine_name = `bedrock.zip`
if (system === 'linux'){
var versions_get = versions.bedrock[Vdown].url_linux;
mine_name = "bedrock.zip"
var versions_get
if (system === "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}`
});
downloadBDSchild.stdout.on("data", function(data){console.log(data)})
downloadBDSchild.on("exit", function (code) {
if (code === 0) {
console.log(`Download zip file success`);
console.log("Download zip file success");
var server_DIR = bds.bds_dir_bedrock;
var ZIP_FILE_PATH = require("path").join(bds.tmp_dir, mine_name);
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");};
if (fs.existsSync(`${server_DIR}/server.properties`)){var _old = true;var old1 = fs.readFileSync(`${server_DIR}/server.properties`, "utf8");}
if (fs.existsSync(`${server_DIR}/permissions.json`)){var _old2 = true;var old2 = fs.readFileSync(`${server_DIR}/permissions.json`, "utf8");}
if (fs.existsSync(`${server_DIR}/whitelist.json`)) {var _old3 = true;var old3 = fs.readFileSync(`${server_DIR}/whitelist.json`, "utf8");}
if (fs.existsSync(`${server_DIR}/valid_known_packs.json`)){var _old4 = true;var old4 = fs.readFileSync(`${server_DIR}/valid_known_packs.json`, "utf8");}
// Unzip
var zip = new AdmZip(ZIP_FILE_PATH);
zip.extractAllTo(server_DIR, true);
@ -38,26 +41,26 @@ module.exports = (Vdown) => {
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);};
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`)
console.log("going out")
process.exit(0)
}
} else {
localStorage.setItem("Download_sucess", "no")
throw new error(`Could not download`);
throw new error("Could not download");
}
})
} 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){
@ -65,11 +68,11 @@ module.exports = (Vdown) => {
})
downloadBDSchild.on("exit", function (code) {
if (code === 0) {
console.log(`Download zip file success`);
console.log("Download zip file success");
localStorage.setItem("Downlaod_sucess", "yes")
} else {
localStorage.setItem("Download_sucess", "no")
throw new error(`Could not download`);
throw new error("Could not download");
}
})
}

View File

@ -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;
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");
var CPU
if (2 < cpuCount - 2) CPU = cpuCount - 2;
else CPU = cpuCount;
var config;
if (json_config.includes(".json")) config = JSON.parse(fs.readFileSync(json_config, "utf8"));
else config = JSON.parse(json_config)
//
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
if (config.description !== undefined) description_name = config.description;
if (config.name !== undefined) level_name = config.name;
if (config.gamemode !== undefined) gamemode = config.gamemode;
if (config.difficulty !== undefined) difficulty = config.difficulty;
if (config.cheats !== undefined) allow_cheats = config.cheats;
if (config.players !== undefined) max_players = config.players;
if (config.xbox !== undefined) online_mode = config.xbox;
if (config.white_list !== undefined) white_list = config.white_list;
if (config.port !== undefined) server_port = config.port;
if (config.port6 !== undefined) server_portv6 = config.port6;
if (config.player_permission !== undefined) player_permission = config.player_permission;
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
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*/
if (bds.platform === 'bedrock'){
var config_file_content = `server-name=${description_name}
var config_file_content
if (bds.platform === "bedrock"){
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",
@ -176,4 +176,5 @@ return {
}
}
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

21
scripts/detect.js Normal file
View File

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

26
scripts/kill_server.js Normal file
View File

@ -0,0 +1,26 @@
module.exports = () => {
const bds = require("../index")
var spawn = require("child_process").exec;
const Storage = localStorage
if (bds.bds_detect()){
var killbds
if (bds.platform === "bedrock"){
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") {
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") {
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
}
};