Merge #31
28
.eslintrc.json
Normal file
28
.eslintrc.json
Normal 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
5
.github/workflows/get_version.sh
vendored
Normal 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
|
@ -4,9 +4,12 @@ on:
|
|||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
|
paths-ignore:
|
||||||
|
- 'README.md'
|
||||||
|
- '.github/*/**'
|
||||||
|
- 'package-lock.json'
|
||||||
|
- '.devcontainer/**'
|
||||||
|
- 'CHANGELOG.md'
|
||||||
jobs:
|
jobs:
|
||||||
check:
|
check:
|
||||||
strategy:
|
strategy:
|
||||||
@ -62,3 +65,20 @@ jobs:
|
|||||||
run: npm publish --tag dev
|
run: npm publish --tag dev
|
||||||
env:
|
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: ${{ 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 }}
|
25
.github/workflows/stable.yml
vendored
25
.github/workflows/stable.yml
vendored
@ -1,11 +1,14 @@
|
|||||||
name: Stable Publish
|
name: Stable Publish
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
tags:
|
|
||||||
- "*.*"
|
|
||||||
- "v*.*"
|
|
||||||
branches:
|
branches:
|
||||||
- stable
|
- stable
|
||||||
|
paths-ignore:
|
||||||
|
- 'README.md'
|
||||||
|
- '.github/*/**'
|
||||||
|
- 'package-lock.json'
|
||||||
|
- '.devcontainer/**'
|
||||||
|
- 'CHANGELOG.md'
|
||||||
jobs:
|
jobs:
|
||||||
Publish:
|
Publish:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@ -53,3 +56,19 @@ jobs:
|
|||||||
run: npm publish
|
run: npm publish
|
||||||
env:
|
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 }}
|
38
API/api.js
38
API/api.js
@ -1,11 +1,11 @@
|
|||||||
module.exports = () => {
|
module.exports = () => {
|
||||||
global.bds_api_start = true
|
global.bds_api_start = true;
|
||||||
const express = require("express");
|
const express = require("express");
|
||||||
const bds = require("../index");
|
const bds = require("../index");
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const app = express();
|
const app = express();
|
||||||
const path = require("path")
|
const path = require("path");
|
||||||
var cors = require('cors');
|
var cors = require("cors");
|
||||||
const rateLimit = require("express-rate-limit");
|
const rateLimit = require("express-rate-limit");
|
||||||
|
|
||||||
// Enable if you're behind a reverse proxy (Heroku, Bluemix, AWS ELB, Nginx, etc)
|
// Enable if you're behind a reverse proxy (Heroku, Bluemix, AWS ELB, Nginx, etc)
|
||||||
@ -33,7 +33,7 @@ module.exports = () => {
|
|||||||
} else {
|
} else {
|
||||||
v++;
|
v++;
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
const config = bds.get_config()
|
const config = bds.get_config()
|
||||||
var json_http = {
|
var json_http = {
|
||||||
"server": {
|
"server": {
|
||||||
@ -52,12 +52,12 @@ module.exports = () => {
|
|||||||
return res.send(json_http);
|
return res.send(json_http);
|
||||||
});
|
});
|
||||||
app.get("/", (req, res) => {
|
app.get("/", (req, res) => {
|
||||||
return res.send(`Hello, welcome to the Bds Maneger API, If this page has loaded it means that the API is working as planned, More information access the API documentation at: https://docs.srherobrine23.com/bds-maneger-api_whatis.html, Version: ${require(__dirname+'/../package.json').version}`);
|
return res.send(`Hello, welcome to the Bds Maneger API, If this page has loaded it means that the API is working as planned, More information access the API documentation at: https://docs.srherobrine23.com/bds-maneger-api_whatis.html, Version: ${require(path.join(__dirname, "..", "package.json")).version}`);
|
||||||
});
|
});
|
||||||
app.post("/service", (req, res) => {
|
app.post("/service", (req, res) => {
|
||||||
const body = req.body
|
const body = req.body
|
||||||
const command_bds = body.command
|
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;
|
var pass = false;
|
||||||
for (let token_verify in tokens) {
|
for (let token_verify in tokens) {
|
||||||
const element = tokens[token_verify].token;
|
const element = tokens[token_verify].token;
|
||||||
@ -68,14 +68,15 @@ module.exports = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (pass){
|
if (pass){
|
||||||
if (command_bds === 'start'){
|
var command_status
|
||||||
var bds_init = bds.start()
|
if (command_bds === "start"){
|
||||||
var command_status = `Bds Started`
|
bds.start()
|
||||||
} else if (command_bds === 'stop'){
|
command_status = "Bds Started"
|
||||||
|
} else if (command_bds === "stop"){
|
||||||
bds.stop()
|
bds.stop()
|
||||||
var command_status = `Stopping the bds server`
|
command_status = "Stopping the bds server"
|
||||||
} else {
|
} else {
|
||||||
var command_status = `no command identified`
|
command_status = "no command identified"
|
||||||
}
|
}
|
||||||
res.send({
|
res.send({
|
||||||
"status": 200,
|
"status": 200,
|
||||||
@ -91,7 +92,7 @@ module.exports = () => {
|
|||||||
app.post("/bds_download", (req, res) => {
|
app.post("/bds_download", (req, res) => {
|
||||||
const body = req.body
|
const body = req.body
|
||||||
const ver = body.version
|
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;
|
var pass = false;
|
||||||
for (let token_verify in tokens) {
|
for (let token_verify in tokens) {
|
||||||
const element = tokens[token_verify].token;
|
const element = tokens[token_verify].token;
|
||||||
@ -101,12 +102,13 @@ module.exports = () => {
|
|||||||
token_verify++
|
token_verify++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
var STA,EMN
|
||||||
if (pass){
|
if (pass){
|
||||||
var STA = `wait`
|
STA = "wait"
|
||||||
var EMN = bds.download(ver)
|
EMN = bds.download(ver)
|
||||||
} else {
|
} else {
|
||||||
var STA = `401`,
|
STA = "401",
|
||||||
EMN = `Unauthorized Token`
|
EMN = "Unauthorized Token"
|
||||||
}
|
}
|
||||||
res.send({
|
res.send({
|
||||||
"status": STA,
|
"status": STA,
|
||||||
@ -115,7 +117,7 @@ module.exports = () => {
|
|||||||
});
|
});
|
||||||
app.post("/bds_command", (req, res) => {
|
app.post("/bds_command", (req, res) => {
|
||||||
const body = req.body
|
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;
|
var pass = false;
|
||||||
for (let token_verify in tokens) {
|
for (let token_verify in tokens) {
|
||||||
const element = tokens[token_verify].token;
|
const element = tokens[token_verify].token;
|
||||||
|
37
API/log.js
37
API/log.js
@ -4,27 +4,44 @@ module.exports = () => {
|
|||||||
const bds = require("../index");
|
const bds = require("../index");
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const app = express();
|
const app = express();
|
||||||
var cors = require('cors');
|
var cors = require("cors");
|
||||||
app.use(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) => {
|
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"))){
|
if (fs.existsSync(localStorage.getItem("old_log_file"))){
|
||||||
var text = `${fs.readFileSync(localStorage.getItem("old_log_file"), "utf8")}`
|
text = `${fs.readFileSync(localStorage.getItem("old_log_file"), "utf8")}`
|
||||||
var log_file = localStorage.getItem("old_log_file")
|
log_file = localStorage.getItem("old_log_file")
|
||||||
var sucess = true
|
sucess = true
|
||||||
} else {
|
} else {
|
||||||
var text = `The server is stopped`
|
text = "The server is stopped"
|
||||||
var sucess = false
|
sucess = false
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
var text = bds_log_string
|
text = bds_log_string
|
||||||
var log_file = "string"
|
log_file = "string"
|
||||||
var sucess = true
|
sucess = true
|
||||||
}
|
}
|
||||||
res.json({
|
res.json({
|
||||||
"sucess": sucess,
|
"sucess": sucess,
|
||||||
"log": text,
|
"log": text,
|
||||||
"log_file": log_file,
|
"log_file": log_file,
|
||||||
|
"ip": `${req.clientIp}`,
|
||||||
"requeset_date": bds.date()
|
"requeset_date": bds.date()
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -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:
|
some deven ports are unlocked by the firewall if enabled:
|
||||||
|
|
||||||
- 28574
|
|
||||||
- 1932
|
- 1932
|
||||||
- 6565
|
- 6565
|
||||||
|
@ -42,30 +42,31 @@ function getAccessToken(oAuth2Client, callback) {
|
|||||||
callback(oAuth2Client);
|
callback(oAuth2Client);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
module.exports.drive_backup = () => {
|
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)
|
console.log(file_json)
|
||||||
const parent_id = file_json.id
|
const parent_id = file_json.id
|
||||||
const path_file = file_json.file_path
|
const path_file = file_json.file_path
|
||||||
const name_d = file_json.file_name;
|
const name_d = file_json.file_name;
|
||||||
|
|
||||||
const gd_secret = '';
|
const gd_secret = "";
|
||||||
console.log(gd_secret)
|
console.log(gd_secret)
|
||||||
function upload_backup(auth) {
|
function upload_backup(auth) {
|
||||||
const drive = google.drive({version: "v3", auth});
|
const drive = google.drive({version: "v3", auth});
|
||||||
|
var fileMetadata;
|
||||||
if (parent_id === undefined){
|
if (parent_id === undefined){
|
||||||
var fileMetadata = {
|
fileMetadata = {
|
||||||
name: name_d
|
name: name_d
|
||||||
}
|
}
|
||||||
console.log("Your backup will be saved to My Drive")
|
console.log("Your backup will be saved to My Drive")
|
||||||
} else {
|
} else {
|
||||||
var fileMetadata = {
|
fileMetadata = {
|
||||||
name: name_d,
|
name: name_d,
|
||||||
parents: [parent_id]
|
parents: [parent_id]
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
var media = {
|
var media = {
|
||||||
mimeType: "application/octet-stream",
|
mimeType: "application/octet-stream",
|
||||||
body: fs.createReadStream(path_file)
|
body: fs.createReadStream(path_file)
|
||||||
@ -101,6 +102,6 @@ module.exports.mcpe = () => {
|
|||||||
progress += d.length / 1024 / 1024;
|
progress += d.length / 1024 / 1024;
|
||||||
if (process.stdout.isTTY) {process.stdout.clearLine();process.stdout.cursorTo(0);process.stdout.write(`Downloaded ${Math.trunc(progress)} Mbytes`);}
|
if (process.stdout.isTTY) {process.stdout.clearLine();process.stdout.cursorTo(0);process.stdout.write(`Downloaded ${Math.trunc(progress)} Mbytes`);}
|
||||||
}).pipe(dest)});
|
}).pipe(dest)});
|
||||||
};
|
}
|
||||||
return authorize(gd_secret, download_mcpe);
|
return authorize(gd_secret, download_mcpe);
|
||||||
}
|
}
|
||||||
|
@ -1,21 +1,28 @@
|
|||||||
module.exports.checkUser = (USERNAME) => {
|
module.exports.checkUser = (USERNAME) => {
|
||||||
const fs = require("fs")
|
const fs = require("fs")
|
||||||
if (fs.existsSync(`${require("../index").bds_dir}/telegram_admin.json`)) {
|
const path = require("path")
|
||||||
var admins = fs.readFileSync(`${require("../index").bds_dir}/telegram_admin.json`, "utf-8");
|
const bds = require("../index")
|
||||||
|
const telegram_admin = path.join(bds.bds_dir, "telegram_admin.json")
|
||||||
|
if (fs.existsSync(telegram_admin)) {
|
||||||
|
var admins = fs.readFileSync(telegram_admin, "utf8");
|
||||||
} else {
|
} else {
|
||||||
var admins = `{"sh23_bot_not_config": {"allow": true}}`;
|
const config = {
|
||||||
console.warn("All allowed")
|
"sh23_bot_not_config": {
|
||||||
console.log(`Create file in with name: ${require("../index").bds_dir}/telegram_admin.json`)
|
"allow": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fs.writeFileSync(telegram_admin, JSON.stringify(config))
|
||||||
|
throw new console.error(`we just created the telegram authorization, edit before using: ${config}`);
|
||||||
}
|
}
|
||||||
var adm = JSON.parse(admins);
|
var adm = JSON.parse(admins);
|
||||||
for(index in adm){
|
for(let check_ in adm){
|
||||||
if (USERNAME == index){
|
if (USERNAME == check_){
|
||||||
return true
|
return true
|
||||||
} else if (index == "sh23_bot_not_config"){
|
} else if (check_ == "sh23_bot_not_config"){
|
||||||
console.warn("Allow all")
|
console.warn("Allow all")
|
||||||
return true
|
return true
|
||||||
}; index++;
|
} check_++;
|
||||||
};
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
const { Telegraf } = require("telegraf")
|
const { Telegraf } = require("telegraf")
|
||||||
const token = require("../index").token
|
const token = require("../index").telegram_token
|
||||||
const bot = new Telegraf(token)
|
const bot = new Telegraf(token)
|
||||||
bot.start((ctx) => {
|
bot.start((ctx) => {
|
||||||
const amenssagem = `Hello ${ctx.message.from.username}
|
const amenssagem = `Hello ${ctx.message.from.username}
|
||||||
@ -27,27 +27,27 @@ bot.command("server_start", (ctx) => {
|
|||||||
document.getElementById("startButtom").click()
|
document.getElementById("startButtom").click()
|
||||||
} else {
|
} else {
|
||||||
require("../index").start()
|
require("../index").start()
|
||||||
};
|
}
|
||||||
ctx.reply(`The server has started`)
|
ctx.reply("The server has started")
|
||||||
} else
|
} else
|
||||||
ctx.reply(`${ctx.message.from.username} already started`)
|
ctx.reply(`${ctx.message.from.username} already started`)
|
||||||
} else {
|
} else {
|
||||||
console.log("Erro");
|
console.log("Erro");
|
||||||
ctx.reply(`Please contact the Server Administrator, You are not on the list, I count to add your username \(${ctx.message.from.username}\) on the whitelist`)
|
ctx.reply(`Please contact the Server Administrator, You are not on the list, I count to add your username (${ctx.message.from.username}) on the whitelist`)
|
||||||
};
|
}
|
||||||
});
|
});
|
||||||
bot.command("server_stop", (ctx) => {
|
bot.command("server_stop", (ctx) => {
|
||||||
if (require("./check").checkUser(ctx.message.from.username)){
|
if (require("./check").checkUser(ctx.message.from.username)){
|
||||||
const bds_status = require("../index").detect()
|
const bds_status = require("../index").detect()
|
||||||
if (bds_status){
|
if (bds_status){
|
||||||
require("../index").stop()
|
require("../index").stop()
|
||||||
ctx.reply(`O servidor esta parando`)
|
ctx.reply("O servidor esta parando")
|
||||||
} else
|
} else
|
||||||
ctx.reply(`${ctx.message.from.username} o servidor está parado`)
|
ctx.reply(`${ctx.message.from.username} o servidor está parado`)
|
||||||
} else {
|
} else {
|
||||||
console.log("Erro");
|
console.log("Erro");
|
||||||
ctx.reply(`Please contact the Server Administrator, You are not on the list, I count to add your username \(${ctx.message.from.username}\) on the whitelist`)
|
ctx.reply(`Please contact the Server Administrator, You are not on the list, I count to add your username (${ctx.message.from.username}) on the whitelist`)
|
||||||
};
|
}
|
||||||
});
|
});
|
||||||
bot.command("command", (ctx) =>{
|
bot.command("command", (ctx) =>{
|
||||||
const bds_command = require("../index").command
|
const bds_command = require("../index").command
|
||||||
|
332
index.js
332
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}`)
|
console.log(`Running the Bds Maneger API in version ${require(__dirname+"/package.json").version}`)
|
||||||
var shell = require("shelljs");
|
var shell = require("shelljs");
|
||||||
let blanks;
|
let blanks;
|
||||||
@ -14,10 +15,11 @@ function date(fu) {
|
|||||||
else
|
else
|
||||||
return `${String(today.getDate()).padStart(2, "0")}-${String(today.getMonth() + 1).padStart(2, "0")}-${today.getFullYear()}_${today.getHours()}-${today.getSeconds()}`
|
return `${String(today.getDate()).padStart(2, "0")}-${String(today.getMonth() + 1).padStart(2, "0")}-${today.getFullYear()}_${today.getHours()}-${today.getSeconds()}`
|
||||||
}
|
}
|
||||||
|
var electron_de
|
||||||
if (process.argv[0].includes("electron")){
|
if (process.argv[0].includes("electron")){
|
||||||
var electron_de = true;
|
electron_de = true;
|
||||||
} else if (process.argv[0].includes("node")){
|
} else if (process.argv[0].includes("node")){
|
||||||
var electron_de = undefined;
|
electron_de = undefined;
|
||||||
if (process.env.BDS_MONI == blanks){
|
if (process.env.BDS_MONI == blanks){
|
||||||
process.env.BDS_MONI = true
|
process.env.BDS_MONI = true
|
||||||
}
|
}
|
||||||
@ -28,49 +30,60 @@ if (process.argv[0].includes("electron")){
|
|||||||
// process.env.ENABLE_BDS_API
|
// process.env.ENABLE_BDS_API
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
var electron_de = false;
|
electron_de = false;
|
||||||
}
|
}
|
||||||
const arch = process.arch
|
const arch = process.arch
|
||||||
if (arch == "x64"){
|
var archi = arch
|
||||||
var archi = "amd64"
|
|
||||||
} else if (arch == "arm64"){
|
|
||||||
console.warn(`It is not recommended to use platforms that are not amd64 (x64), please inform you that you will need to manually configure some things. \!\!`)
|
|
||||||
var archi = "arm"
|
|
||||||
} else {
|
|
||||||
console.warn(`Unsupported processor, ${arch} will not be supported by The Bds Maneger`)
|
|
||||||
}
|
|
||||||
const path = require("path")
|
const path = require("path")
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
|
const { error } = require("console");
|
||||||
const package_root = path.join(process.cwd(), "package.json")
|
const package_root = path.join(process.cwd(), "package.json")
|
||||||
const package_root_builder = path.resolve(".", "resources", "app", "package.json")
|
const package_root_builder = path.resolve(".", "resources", "app", "package.json")
|
||||||
|
var cache_dir,home,desktop,tmp,system
|
||||||
if (process.platform == "win32") {
|
if (process.platform == "win32") {
|
||||||
var home = process.env.USERPROFILE;
|
home = process.env.USERPROFILE;
|
||||||
var desktop = path.join(home, "Desktop")
|
desktop = path.join(home, "Desktop")
|
||||||
if (fs.existsSync(package_root)){
|
if (fs.existsSync(package_root)){
|
||||||
var cache_dir = path.join(home, "AppData", "Roaming", require(package_root).name)
|
cache_dir = path.join(home, "AppData", "Roaming", require(package_root).name)
|
||||||
} else if (package_root_builder){
|
} else if (package_root_builder){
|
||||||
var cache_dir = path.join(home, "AppData", "Roaming", require(package_root_builder).name)
|
cache_dir = path.join(home, "AppData", "Roaming", require(package_root_builder).name)
|
||||||
} else {
|
} else {
|
||||||
console.warn(`Temporary Storages, some functions will be lost after restarting the system`);
|
console.warn("Temporary Storages, some functions will be lost after restarting the system");
|
||||||
var cache_dir = path.join(process.env.TMP, `bds_tmp_configs`);
|
cache_dir = path.join(process.env.TMP, "bds_tmp_configs");
|
||||||
}
|
}
|
||||||
var tmp = process.env.TMP
|
tmp = process.env.TMP
|
||||||
var system = `windows`;
|
system = "windows";
|
||||||
} else if (process.platform == "linux") {
|
} else if (process.platform == "linux") {
|
||||||
var home = process.env.HOME;
|
home = process.env.HOME;
|
||||||
if (fs.existsSync(package_root)){
|
if (fs.existsSync(package_root)){
|
||||||
var cache_dir = path.join(home, ".config", require(package_root).name);
|
cache_dir = path.join(home, ".config", require(package_root).name);
|
||||||
} else if (fs.existsSync(package_root_builder)) {
|
} else if (fs.existsSync(package_root_builder)) {
|
||||||
var cache_dir = path.join(home, ".config", require(package_root_builder).name);
|
cache_dir = path.join(home, ".config", require(package_root_builder).name);
|
||||||
} else {
|
} else {
|
||||||
console.warn(`Temporary Storages, some functions will be lost after restarting the system`);
|
console.warn("Temporary Storages, some functions will be lost after restarting the system");
|
||||||
var cache_dir = `/tmp/bds_tmp_configs`;
|
cache_dir = "/tmp/bds_tmp_configs";
|
||||||
}
|
}
|
||||||
var file = path.join(home, ".config", "user-dirs.dirs");var data = {};
|
var file = path.join(home, ".config", "user-dirs.dirs");var data = {};
|
||||||
if (fs.existsSync(file)){let content = fs.readFileSync(file,"utf8");let lines = content.split(/\r?\n/g).filter((a)=> !a.startsWith("#"));for(let line of lines){let i = line.indexOf("=");if(i >= 0){try{data[line.substring(0,i)] = JSON.parse(line.substring(i + 1))}catch(e){}}}};if(data["XDG_DESKTOP_DIR"]){var desktop = data["XDG_DESKTOP_DIR"];desktop = desktop.replace(/\$([A-Za-z\-\_]+)|\$\{([^\{^\}]+)\}/g, (_, a, b) => (process.env[a || b] || ""))}else{var desktop = "/tmp"}
|
if (fs.existsSync(file)){
|
||||||
|
let content = fs.readFileSync(file,"utf8");
|
||||||
|
let lines = content.split(/\r?\n/g).filter((a)=> !a.startsWith("#"));
|
||||||
|
for(let line of lines){
|
||||||
|
let i = line.indexOf("=");
|
||||||
|
if(i >= 0){
|
||||||
|
try{data[line.substring(0,i)] = JSON.parse(line.substring(i + 1))}
|
||||||
|
catch(e){
|
||||||
|
error(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(data["XDG_DESKTOP_DIR"]){
|
||||||
|
desktop = data["XDG_DESKTOP_DIR"];
|
||||||
|
desktop = desktop.replace(/\$([A-Za-z\-_]+)|\$\{([^{^}]+)\}/g, (_, a, b) => (process.env[a || b] || ""))}
|
||||||
|
else{desktop = "/tmp"}
|
||||||
|
|
||||||
var tmp = `/tmp`;
|
tmp = "/tmp";
|
||||||
var system = `linux`;
|
system = "linux";
|
||||||
} else if (process.platform == "darwin") {
|
} else if (process.platform == "darwin") {
|
||||||
require("open")("https://github.com/Bds-Maneger/Bds_Maneger/wiki/systems-support#a-message-for-mac-os-users")
|
require("open")("https://github.com/Bds-Maneger/Bds_Maneger/wiki/systems-support#a-message-for-mac-os-users")
|
||||||
console.error("Please use Windows or Linux MacOS Not yet supported")
|
console.error("Please use Windows or Linux MacOS Not yet supported")
|
||||||
@ -78,13 +91,20 @@ if (process.platform == "win32") {
|
|||||||
} else {
|
} else {
|
||||||
console.log(`Please use an operating system (OS) compatible with Minecraft Bedrock Server ${process.platform} is not supported`);
|
console.log(`Please use an operating system (OS) compatible with Minecraft Bedrock Server ${process.platform} is not supported`);
|
||||||
process.exit(2021)
|
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 = path.join(home, "bds_Server");
|
||||||
var bds_dir_bedrock = path.join(bds_dir, 'bedrock');
|
var bds_dir_bedrock = path.join(bds_dir, "bedrock");
|
||||||
var bds_dir_java = path.join(bds_dir, 'java');
|
var bds_dir_java = path.join(bds_dir, "java");
|
||||||
var bds_dir_backup = path.join(bds_dir, 'backups');
|
var bds_dir_backup = path.join(bds_dir, "backups");
|
||||||
module.exports.backup_folder = bds_dir_backup
|
module.exports.backup_folder = bds_dir_backup
|
||||||
|
|
||||||
if (!(fs.existsSync(bds_dir))){
|
if (!(fs.existsSync(bds_dir))){
|
||||||
@ -96,17 +116,16 @@ if (!(fs.existsSync(bds_dir))){
|
|||||||
// Configs
|
// Configs
|
||||||
const bds_config_file = path.join(bds_dir, "bds_config.json")
|
const bds_config_file = path.join(bds_dir, "bds_config.json")
|
||||||
if (fs.existsSync(bds_config_file)){
|
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 {
|
} else {
|
||||||
const _config = `{
|
const bds_config = {
|
||||||
"bds_platform": "bedrock",
|
"bds_platform": "bedrock",
|
||||||
"telegram_token": null
|
"telegram_token": "not User defined"
|
||||||
}`
|
}
|
||||||
var bds_config = JSON.parse(_config)
|
fs.writeFileSync(bds_config_file, JSON.stringify(bds_config))
|
||||||
fs.writeFileSync(bds_config_file, _config)
|
|
||||||
}
|
}
|
||||||
module.exports.platform = bds_config.bds_platform
|
module.exports.platform = bds_config.bds_platform
|
||||||
console.log(`Running on the \"${bds_config.bds_platform}\" platform`)
|
console.log(`Running on the "${bds_config.bds_platform}" platform`)
|
||||||
// Configs
|
// Configs
|
||||||
|
|
||||||
var log_dir = path.join(bds_dir, "log");
|
var log_dir = path.join(bds_dir, "log");
|
||||||
@ -140,31 +159,63 @@ if (!(fs.existsSync(log_dir))){
|
|||||||
console.log(`Creating the bds log dir (${log_dir})`)
|
console.log(`Creating the bds log dir (${log_dir})`)
|
||||||
fs.mkdirSync(log_dir)
|
fs.mkdirSync(log_dir)
|
||||||
if (!(fs.existsSync(log_dir))) shell.mkdir("-p", log_dir)
|
if (!(fs.existsSync(log_dir))) shell.mkdir("-p", log_dir)
|
||||||
};
|
}
|
||||||
};
|
}
|
||||||
// e
|
// 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) =>{
|
module.exports.telegram_token_save = (token) =>{
|
||||||
fs.writeFileSync(`${bds_dir}/telegram_token.txt`, token);
|
try {
|
||||||
return "OK"
|
const bds_config = path.join(bds_dir, "bds_config.json")
|
||||||
}
|
const config_load = JSON.parse(fs.readFileSync(bds_config))
|
||||||
if (typeof fetch === "undefined"){global.fetch = require("node-fetch")}
|
config_load.telegram_token = token
|
||||||
|
fs.writeFileSync(bds_config, JSON.stringify(config_load))
|
||||||
if (typeof localStorage === "undefined"){
|
return true
|
||||||
var localStorageS = require("node-localstorage").LocalStorage;
|
} catch {
|
||||||
global.localStorage = new localStorageS(`${cache_dir}/Local_Storage`);
|
return false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Java or Bedrock
|
if (require("fs").existsSync(path.join(bds_dir, "telegram_token.txt"))){
|
||||||
if (process.env.JAVA_ENABLE !== undefined){
|
console.log(`We identified the old telegram token file (${path.join (bds_dir, "telegram_token.txt")}), starting the immigration process`)
|
||||||
localStorage.setItem('bds_edititon', 'java');
|
try {
|
||||||
}else{
|
const token = fs.readFileSync(path.join(bds_dir, "telegram_token.txt"), "utf8").split("\n").join("")
|
||||||
localStorage.setItem('bds_edititon', 'bedrock');
|
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"}
|
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
|
// Fetchs
|
||||||
fetch("https://raw.githubusercontent.com/Bds-Maneger/Raw_files/main/credentials.json").then(response => response.text()).then(gd_cre => {
|
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
|
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
|
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
|
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 => {
|
fetch("https://raw.githubusercontent.com/Bds-Maneger/Raw_files/main/Server.json").then(response => response.json()).then(rawOUT => {
|
||||||
const versions = Object.getOwnPropertyNames(rawOUT.bedrock);
|
const versions = Object.getOwnPropertyNames(rawOUT.bedrock);
|
||||||
for (let v in versions){
|
for (let v in versions){
|
||||||
var html = `${versions[v]}`;
|
var html = `${versions[v]}`;
|
||||||
module.exports.version_select += `<option value=\"${html}\">${html}</option>\n`;
|
module.exports.version_select += `<option value="${html}">${html}</option>\n`;
|
||||||
v++;
|
v++;
|
||||||
};
|
}
|
||||||
module.exports.bedrock_all_versions = Object.getOwnPropertyNames(rawOUT.bedrock);
|
module.exports.bedrock_all_versions = Object.getOwnPropertyNames(rawOUT.bedrock);
|
||||||
module.exports.java_all_versions = Object.getOwnPropertyNames(rawOUT.java);
|
module.exports.java_all_versions = Object.getOwnPropertyNames(rawOUT.java);
|
||||||
module.exports.bds_latest = rawOUT.bedrock_lateste;
|
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")();
|
require("./API/log")();
|
||||||
}
|
}
|
||||||
} else {
|
} 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) => {
|
module.exports.get_version = (type) => {
|
||||||
if (type == "raw")
|
if (type == "raw")
|
||||||
@ -209,14 +275,41 @@ fetch("https://raw.githubusercontent.com/Bds-Maneger/Raw_files/main/Server.json"
|
|||||||
|
|
||||||
// Module export
|
// Module export
|
||||||
/* Variaveis */
|
/* 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
|
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
|
module.exports.desktop = desktop
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Identifying a system in the script can be simple with this variable
|
||||||
|
*/
|
||||||
module.exports.system = system
|
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 = bds_dir
|
||||||
|
|
||||||
|
|
||||||
module.exports.bds_dir_bedrock = bds_dir_bedrock
|
module.exports.bds_dir_bedrock = bds_dir_bedrock
|
||||||
module.exports.bds_dir_java = bds_dir_java
|
module.exports.bds_dir_java = bds_dir_java
|
||||||
|
|
||||||
module.exports.tmp_dir = tmp
|
module.exports.tmp_dir = tmp
|
||||||
module.exports.electron = electron_de
|
module.exports.electron = electron_de
|
||||||
module.exports.api_dir = cache_dir
|
module.exports.api_dir = cache_dir
|
||||||
@ -224,23 +317,110 @@ module.exports.log_file = log_file
|
|||||||
module.exports.log_date = log_date
|
module.exports.log_date = log_date
|
||||||
module.exports.arch = archi
|
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
|
// Global commands
|
||||||
module.exports.telegram = require("./global/telegram_bot")
|
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
|
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.command = require("./global/command").command
|
||||||
// module.exports.stop = require("./global/stop").Server_stop
|
|
||||||
|
|
||||||
// New management method
|
// 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
|
* 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
|
||||||
module.exports.detect = require("./new_script/detect")
|
*
|
||||||
module.exports.bds_detect = require("./new_script/detect")
|
* @example const server = bds.start();
|
||||||
module.exports.version_Download = require("./new_script/bds_download")
|
* server.on.stdout("date", function (log){console.log(log)})
|
||||||
module.exports.download = require("./new_script/bds_download")
|
*/
|
||||||
module.exports.kill = require("./new_script/kill_server")
|
module.exports.start = require("./scripts/basic_server").start
|
||||||
module.exports.config_example = require("./new_script/bds_settings").config_example
|
/**
|
||||||
module.exports.set_config = require("./new_script/bds_settings").config
|
* use this command for the server, that's all
|
||||||
module.exports.get_config = require("./new_script/bds_settings").get_config
|
*/
|
||||||
|
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
|
||||||
|
@ -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};
|
|
||||||
};
|
|
@ -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
3424
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
10
package.json
10
package.json
@ -5,7 +5,8 @@
|
|||||||
"private": false,
|
"private": false,
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "exit 0",
|
"test": "eslint .",
|
||||||
|
"test:fix": "eslint --fix .",
|
||||||
"server": "node index.js"
|
"server": "node index.js"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
@ -41,8 +42,15 @@
|
|||||||
"properties-to-json": "^0.1.7",
|
"properties-to-json": "^0.1.7",
|
||||||
"qr-image": "^3.2.0",
|
"qr-image": "^3.2.0",
|
||||||
"qrcode": "^1.4.4",
|
"qrcode": "^1.4.4",
|
||||||
|
"request-ip": "^2.1.3",
|
||||||
"shelljs": "^0.8.4",
|
"shelljs": "^0.8.4",
|
||||||
"systeminformation": "^5.0.10",
|
"systeminformation": "^5.0.10",
|
||||||
"telegraf": "^4.0.0"
|
"telegraf": "^4.0.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=14"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"eslint": "^7.19.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
module.exports.World_BAckup = () => {
|
module.exports.World_BAckup = () => {
|
||||||
const bds = require('../index')
|
const bds = require("../index")
|
||||||
const path = require("path")
|
const path = require("path")
|
||||||
const java_pro = require("properties-to-json")
|
const java_pro = require("properties-to-json")
|
||||||
const fs = require("fs")
|
const fs = require("fs")
|
||||||
@ -7,11 +7,12 @@ module.exports.World_BAckup = () => {
|
|||||||
|
|
||||||
var today = bds.date()
|
var today = bds.date()
|
||||||
const name = path.join(bds.backup_folder ,`bds_backup_World_${today}.zip`)
|
const name = path.join(bds.backup_folder ,`bds_backup_World_${today}.zip`)
|
||||||
|
var dir_zip;
|
||||||
if (bds.platform === "bedrock"){
|
if (bds.platform === "bedrock"){
|
||||||
var dir_zip = path.join(bds_dir_bedrock, "worlds") //`${require("../index").}/worlds/`
|
dir_zip = path.join(bds.bds_dir_bedrock, "worlds") //`${require("../index").}/worlds/`
|
||||||
} else {
|
} else {
|
||||||
const world_name = JSON.parse(java_pro(fs.readFileSync(path.join(bds.bds_dir_java, "server.properties"), "utf-8").replaceAll("-", "_"))).level_name
|
const world_name = JSON.parse(java_pro(fs.readFileSync(path.join(bds.bds_dir_java, "server.properties"), "utf8").replaceAll("-", "_"))).level_name
|
||||||
var dir_zip = path.join(bds.bds_dir_java, world_name) //`${require("../index").bds_dir_bedrock}/${world_name}/`
|
dir_zip = path.join(bds.bds_dir_java, world_name) //`${require("../index").bds_dir_bedrock}/${world_name}/`
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Before we can start it is good for the server not to have a Corrupted Backup
|
* Before we can start it is good for the server not to have a Corrupted Backup
|
||||||
@ -33,7 +34,7 @@ module.exports.World_BAckup = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
module.exports.Drive_backup = () => {
|
module.exports.Drive_backup = () => {
|
||||||
const bds = require('../index')
|
const bds = require("../index")
|
||||||
const path = require("path")
|
const path = require("path")
|
||||||
const java_pro = require("properties-to-json")
|
const java_pro = require("properties-to-json")
|
||||||
const fs = require("fs")
|
const fs = require("fs")
|
||||||
@ -41,36 +42,27 @@ module.exports.Drive_backup = () => {
|
|||||||
|
|
||||||
var today = bds.date()
|
var today = bds.date()
|
||||||
const name = path.join(bds.backup_folder ,`bds_backup_World_${today}.zip`)
|
const name = path.join(bds.backup_folder ,`bds_backup_World_${today}.zip`)
|
||||||
|
var dir_zip;
|
||||||
if (bds.platform === "bedrock"){
|
if (bds.platform === "bedrock"){
|
||||||
var dir_zip = path.join(bds.bds_dir_bedrock, "worlds") //`${require("../index").}/worlds/`
|
dir_zip = path.join(bds.bds_dir_bedrock, "worlds") //`${require("../index").}/worlds/`
|
||||||
} else {
|
} else {
|
||||||
const world_name = JSON.parse(java_pro(fs.readFileSync(path.join(bds.bds_dir_java, "server.properties"), "utf-8").replaceAll("-", "_"))).level_name
|
const world_name = JSON.parse(java_pro(fs.readFileSync(path.join(bds.bds_dir_java, "server.properties"), "utf8").replaceAll("-", "_"))).level_name
|
||||||
var dir_zip = path.join(bds.bds_dir_java, world_name) //`${require("../index").bds_dir_bedrock}/${world_name}/`
|
dir_zip = path.join(bds.bds_dir_java, world_name) //`${require("../index").bds_dir_bedrock}/${world_name}/`
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Before we can start it is good for the server not to have a Corrupted Backup
|
* Before we can start it is good for the server not to have a Corrupted Backup
|
||||||
* this is only necessary once after the server has started manually
|
* this is only necessary once after the server has started manually
|
||||||
*/
|
*/
|
||||||
if (bds.bds_detect()){bds.stop()}
|
if (bds.bds_detect()){bds.stop()}
|
||||||
global.status_b = true
|
var status_b = true
|
||||||
var zip = new AdmZip();
|
var zip = new AdmZip();
|
||||||
zip.addLocalFolder(dir_zip);
|
zip.addLocalFolder(dir_zip);
|
||||||
zip.addZipComment(`Backup zip file in ${today}. \nBackup made to ${process.platform}, Free and open content for all\n\nSirherobrine23© By Bds Maneger.`);
|
zip.addZipComment(`Backup zip file in ${today}. \nBackup made to ${process.platform}, Free and open content for all\n\nSirherobrine23© By Bds Maneger.`);
|
||||||
var zipEntries = zip.getEntries();
|
|
||||||
var totalfiles = zipEntries.length
|
|
||||||
zipEntries.forEach(function(zipEntry) {
|
|
||||||
totalfiles--
|
|
||||||
console.log(totalfiles)
|
|
||||||
if (totalfiles === 0){
|
|
||||||
status_b = false
|
|
||||||
}
|
|
||||||
});
|
|
||||||
zip.writeZip(name);
|
zip.writeZip(name);
|
||||||
let es = 0;
|
let es = 1;
|
||||||
for(es == "-0";es++;){
|
for(es == "0";es++;){
|
||||||
if (!(status_b)) break
|
if (!(status_b)) break
|
||||||
}
|
}
|
||||||
delete(status_b)
|
|
||||||
const js_ = {
|
const js_ = {
|
||||||
"file_path": name,
|
"file_path": name,
|
||||||
"file_name": `bds_backup_World_${today}.zip`,
|
"file_name": `bds_backup_World_${today}.zip`,
|
@ -2,32 +2,33 @@ module.exports.start = () => {
|
|||||||
const bds = require("../index")
|
const bds = require("../index")
|
||||||
const Storage = localStorage;
|
const Storage = localStorage;
|
||||||
const {exec, execSync} = require("child_process");
|
const {exec, execSync} = require("child_process");
|
||||||
const fs = require('fs')
|
const fs = require("fs")
|
||||||
|
|
||||||
|
|
||||||
if (!(bds.detect())){
|
if (!(bds.detect())){
|
||||||
const plat = bds.platform
|
const plat = bds.platform
|
||||||
|
var start_server
|
||||||
if (plat === "bedrock"){
|
if (plat === "bedrock"){
|
||||||
if (process.platform == "win32"){
|
if (process.platform == "win32"){
|
||||||
var start_server = exec(`bedrock_server.exe`, {cwd: bds.bds_dir_bedrock});
|
start_server = exec("bedrock_server.exe", {cwd: bds.bds_dir_bedrock});
|
||||||
} else if (process.platform == "linux"){
|
} else if (process.platform == "linux"){
|
||||||
console.log(execSync(`chmod 777 bedrock_server`, {cwd: bds.bds_dir_bedrock}).toString())
|
console.log(execSync("chmod 777 bedrock_server", {cwd: bds.bds_dir_bedrock}).toString())
|
||||||
var start_server = exec(`./bedrock_server`, {env: {PATH: process.env.PATH, LD_LIBRARY_PATH: bds.bds_dir_bedrock}, cwd: bds.bds_dir_bedrock});
|
start_server = exec("./bedrock_server", {env: {PATH: process.env.PATH, LD_LIBRARY_PATH: bds.bds_dir_bedrock}, cwd: bds.bds_dir_bedrock});
|
||||||
} else {
|
} else {
|
||||||
process.exit(210)
|
process.exit(210)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (require('command-exists').sync('java')){
|
if (require("command-exists").sync("java")){
|
||||||
var start_server = exec(`java -jar server.jar nogui`, {cwd: bds.bds_dir_java});
|
start_server = exec("java -Xmx1024M -Xms1024M -jar server.jar nogui", {cwd: bds.bds_dir_java});
|
||||||
} else {
|
} else {
|
||||||
if (bds.system == 'windows'){
|
if (bds.system == "windows"){
|
||||||
require('open')("http://docs.sirherobrine23.com/bds_maneger_api_java#Windows");
|
require("open")("http://docs.sirherobrine23.com/bds_maneger_api_java#Windows");
|
||||||
console.log("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'){
|
} else if (bds.system === "linux"){
|
||||||
require('open')("http://docs.sirherobrine23.com/bds_maneger_api_java#Linux");
|
require("open")("http://docs.sirherobrine23.com/bds_maneger_api_java#Linux");
|
||||||
console.log("http://docs.sirherobrine23.com/bds_maneger_api_java#Linux")
|
console.log("http://docs.sirherobrine23.com/bds_maneger_api_java#Linux")
|
||||||
} else {
|
} 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")
|
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.pipe(logConsoleStream);
|
||||||
start_server.stdout.on("data", function(data){
|
start_server.stdout.on("data", function(data){
|
||||||
if (data.includes("agree", "EULA")){
|
if (data.includes("agree", "EULA")){
|
||||||
const path = require('path');
|
const path = require("path");
|
||||||
require('open')("https://account.mojang.com/documents/minecraft_eula");
|
require("open")("https://account.mojang.com/documents/minecraft_eula");
|
||||||
const eula_file = path.join(bds.bds_dir_java, "eula.txt")
|
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)
|
fs.writeFileSync(eula_file, eula_make_true)
|
||||||
const node_detect = process.argv[0]
|
const node_detect = process.argv[0]
|
||||||
if (node_detect.includes('node')){
|
if (node_detect.includes("node")){
|
||||||
console.warn(`Ending the process`)
|
console.warn("Ending the process")
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
process.exit(0)
|
process.exit(0)
|
||||||
}, 1000);
|
}, 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})
|
start_server.stdout.on("data", function(data){global.bds_log_string += data})
|
||||||
Storage.setItem("bds_status", true);
|
Storage.setItem("bds_status", true);
|
||||||
global.bds_server_string = start_server;
|
global.bds_server_string = start_server;
|
||||||
return start_server;
|
return start_server;
|
||||||
} else {
|
} else {
|
||||||
console.warn(`You already have a server running`);
|
console.warn("You already have a server running");
|
||||||
return `You already have a server running`;
|
return "You already have a server running";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
module.exports.stop = () => {
|
module.exports.stop = () => {
|
||||||
if (typeof bds_server_string == "undefined"){
|
if (typeof bds_server_string == "undefined"){
|
||||||
const detect = process.argv[0];
|
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 console.log("The server is stopped!");
|
||||||
} else {
|
} else {
|
||||||
bds_server_string.stdin.write("stop\n");
|
bds_server_string.stdin.write("stop\n");
|
||||||
bds_server_string.stdout.on("data", function (data){
|
bds_server_string.stdout.on("data", function (data){
|
||||||
if (data.includes("Quit correctly")){
|
if (data.includes("Quit correctly")){
|
||||||
localStorage.setItem("bds_status", false)
|
localStorage.setItem("bds_status", false)
|
||||||
};
|
}
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
@ -1,35 +1,38 @@
|
|||||||
module.exports = (Vdown) => {
|
module.exports = (Vdown) => {
|
||||||
console.warn("Do not exit BDS Manager")
|
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 => {
|
fetch("https://raw.githubusercontent.com/Bds-Maneger/Raw_files/main/Server.json").then(response => response.json()).then(versions => {
|
||||||
|
var mine_name
|
||||||
|
var downloadBDSchild
|
||||||
if (bds.platform === "bedrock"){
|
if (bds.platform === "bedrock"){
|
||||||
const system = bds.system
|
const system = bds.system
|
||||||
var mine_name = `bedrock.zip`
|
mine_name = "bedrock.zip"
|
||||||
if (system === 'linux'){
|
var versions_get
|
||||||
var versions_get = versions.bedrock[Vdown].url_linux;
|
if (system === "linux"){
|
||||||
|
versions_get = versions.bedrock[Vdown].url_linux;
|
||||||
} else {
|
} else {
|
||||||
var versions_get = versions.bedrock[Vdown].url_windows;
|
versions_get = versions.bedrock[Vdown].url_windows;
|
||||||
}
|
}
|
||||||
console.log("Starting download, with url "+versions_get)
|
console.log("Starting download, with url "+versions_get)
|
||||||
const exec = require("child_process").exec
|
const exec = require("child_process").exec
|
||||||
localStorage.setItem("bds_server_version", Vdown);
|
localStorage.setItem("bds_server_version", Vdown);
|
||||||
var downloadBDSchild = exec(`curl ${versions_get} --output ${mine_name}`, {
|
downloadBDSchild = exec(`curl ${versions_get} --output ${mine_name}`, {
|
||||||
cwd: `${bds.tmp_dir}`
|
cwd: `${bds.tmp_dir}`
|
||||||
});
|
});
|
||||||
|
|
||||||
downloadBDSchild.stdout.on("data", function(data){console.log(data)})
|
downloadBDSchild.stdout.on("data", function(data){console.log(data)})
|
||||||
downloadBDSchild.on("exit", function (code) {
|
downloadBDSchild.on("exit", function (code) {
|
||||||
if (code === 0) {
|
if (code === 0) {
|
||||||
console.log(`Download zip file success`);
|
console.log("Download zip file success");
|
||||||
var server_DIR = bds.bds_dir_bedrock;
|
var server_DIR = bds.bds_dir_bedrock;
|
||||||
var ZIP_FILE_PATH = require("path").join(bds.tmp_dir, mine_name);
|
var ZIP_FILE_PATH = require("path").join(bds.tmp_dir, mine_name);
|
||||||
var AdmZip = require("adm-zip");
|
var AdmZip = require("adm-zip");
|
||||||
const fs = require("fs")
|
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}/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`, "utf-8");}
|
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`, "utf-8");}
|
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`, "utf-8");};
|
if (fs.existsSync(`${server_DIR}/valid_known_packs.json`)){var _old4 = true;var old4 = fs.readFileSync(`${server_DIR}/valid_known_packs.json`, "utf8");}
|
||||||
// Unzip
|
// Unzip
|
||||||
var zip = new AdmZip(ZIP_FILE_PATH);
|
var zip = new AdmZip(ZIP_FILE_PATH);
|
||||||
zip.extractAllTo(server_DIR, true);
|
zip.extractAllTo(server_DIR, true);
|
||||||
@ -38,26 +41,26 @@ module.exports = (Vdown) => {
|
|||||||
if (_old){fs.writeFileSync(`${server_DIR}/server.properties`, old1);}
|
if (_old){fs.writeFileSync(`${server_DIR}/server.properties`, old1);}
|
||||||
if (_old2){fs.writeFileSync(`${server_DIR}/permissions.json`, old2);}
|
if (_old2){fs.writeFileSync(`${server_DIR}/permissions.json`, old2);}
|
||||||
if (_old3){fs.writeFileSync(`${server_DIR}/whitelist.json`, old3);}
|
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
|
const docker_exit = process.env.BDS_DOCKER_IMAGE
|
||||||
console.log(docker_exit)
|
console.log(docker_exit)
|
||||||
if (docker_exit == "true"){
|
if (docker_exit == "true"){
|
||||||
console.log(`going out`)
|
console.log("going out")
|
||||||
process.exit(0)
|
process.exit(0)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
localStorage.setItem("Download_sucess", "no")
|
localStorage.setItem("Download_sucess", "no")
|
||||||
throw new error(`Could not download`);
|
throw new error("Could not download");
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
var versions_get = versions.java[Vdown].url
|
versions_get = versions.java[Vdown].url
|
||||||
var mine_name = `server.jar`
|
mine_name = "server.jar"
|
||||||
|
|
||||||
console.log("Starting download")
|
console.log("Starting download")
|
||||||
const exec = require("child_process").exec
|
const exec = require("child_process").exec
|
||||||
localStorage.setItem("bds_server_version", Vdown);
|
localStorage.setItem("bds_server_version", Vdown);
|
||||||
var downloadBDSchild = exec(`curl ${versions_get} --output ${mine_name}`, {
|
downloadBDSchild = exec(`curl ${versions_get} --output ${mine_name}`, {
|
||||||
cwd: `${bds.bds_dir_java}`
|
cwd: `${bds.bds_dir_java}`
|
||||||
});
|
});
|
||||||
downloadBDSchild.stdout.on("data", function(data){
|
downloadBDSchild.stdout.on("data", function(data){
|
||||||
@ -65,11 +68,11 @@ module.exports = (Vdown) => {
|
|||||||
})
|
})
|
||||||
downloadBDSchild.on("exit", function (code) {
|
downloadBDSchild.on("exit", function (code) {
|
||||||
if (code === 0) {
|
if (code === 0) {
|
||||||
console.log(`Download zip file success`);
|
console.log("Download zip file success");
|
||||||
localStorage.setItem("Downlaod_sucess", "yes")
|
localStorage.setItem("Downlaod_sucess", "yes")
|
||||||
} else {
|
} else {
|
||||||
localStorage.setItem("Download_sucess", "no")
|
localStorage.setItem("Download_sucess", "no")
|
||||||
throw new error(`Could not download`);
|
throw new error("Could not download");
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
@ -2,69 +2,68 @@ function bds_config(json_config){
|
|||||||
const bds = require("../index")
|
const bds = require("../index")
|
||||||
const path = require("path")
|
const path = require("path")
|
||||||
var fs = require("fs")
|
var fs = require("fs")
|
||||||
|
|
||||||
if (bds.platform === 'java') var Server_Config = path.join(bds.bds_dir_java, "server.properties");
|
|
||||||
else var Server_Config = path.join(bds.bds_dir_bedrock, "server.properties");
|
|
||||||
|
|
||||||
const cpuCount = require("os").cpus().length;
|
const cpuCount = require("os").cpus().length;
|
||||||
|
|
||||||
if (2 < cpuCount - 2) var CPU = cpuCount - 2;
|
var Server_Config;
|
||||||
else var CPU = cpuCount;
|
if (bds.platform === "java") Server_Config = path.join(bds.bds_dir_java, "server.properties");
|
||||||
|
else Server_Config = path.join(bds.bds_dir_bedrock, "server.properties");
|
||||||
|
|
||||||
if (json_config.includes(".json")){
|
var CPU
|
||||||
var config = JSON.parse(fs.readFileSync(json_config, "utf8"))
|
if (2 < cpuCount - 2) CPU = cpuCount - 2;
|
||||||
} else var config = JSON.parse(json_config)
|
else CPU = cpuCount;
|
||||||
|
|
||||||
if (config.description == undefined) var description_name = `Dedicated Server`;
|
var config;
|
||||||
else var description_name = config.description;
|
if (json_config.includes(".json")) config = JSON.parse(fs.readFileSync(json_config, "utf8"));
|
||||||
|
else config = JSON.parse(json_config)
|
||||||
|
|
||||||
// Level Name
|
//
|
||||||
if (config.name == undefined) var level_name = `Bedrock level`;
|
var
|
||||||
else var level_name = config.name;
|
description_name = "Dedicated Server",
|
||||||
|
level_name = "Bedrock level",
|
||||||
|
gamemode = "survival",
|
||||||
|
difficulty = "easy",
|
||||||
|
allow_cheats = false,
|
||||||
|
max_players = 10,
|
||||||
|
online_mode = true,
|
||||||
|
white_list = false,
|
||||||
|
server_port = 19132,
|
||||||
|
server_portv6 = 19133,
|
||||||
|
player_permission = "member",
|
||||||
|
tick = 0
|
||||||
|
|
||||||
// gamemode
|
if (config.description !== undefined) description_name = config.description;
|
||||||
if (config.gamemode == undefined) var gamemode = `survival`;
|
|
||||||
else var gamemode = config.gamemode;
|
|
||||||
|
|
||||||
// Difficulty
|
if (config.name !== undefined) level_name = config.name;
|
||||||
if (config.difficulty == undefined) var difficulty = `easy`;
|
|
||||||
else var difficulty = config.difficulty;
|
|
||||||
|
|
||||||
// cheats
|
if (config.gamemode !== undefined) gamemode = config.gamemode;
|
||||||
if (config.cheats == undefined) var allow_cheats = false;
|
|
||||||
else var allow_cheats = config.cheats;
|
|
||||||
|
|
||||||
// Maximo de Jogadores
|
if (config.difficulty !== undefined) difficulty = config.difficulty;
|
||||||
if (config.players == undefined) var max_players = 10;
|
|
||||||
else var max_players = config.players;
|
|
||||||
|
|
||||||
// Xbox authentication outside the internal network
|
if (config.cheats !== undefined) allow_cheats = config.cheats;
|
||||||
if (config.xbox == undefined) var online_mode = true;
|
|
||||||
else var online_mode = config.xbox;
|
|
||||||
|
|
||||||
// Whitelist
|
if (config.players !== undefined) max_players = config.players;
|
||||||
if (config.white_list == undefined){var white_list = false;} else {var white_list = config.white_list;};
|
|
||||||
|
|
||||||
// Server Port IPv4
|
if (config.xbox !== undefined) online_mode = config.xbox;
|
||||||
if (config.port == undefined){var server_port = 19132;} else {var server_port = config.port;};
|
|
||||||
|
|
||||||
// Server Port IPv6
|
if (config.white_list !== undefined) white_list = config.white_list;
|
||||||
if (config.port6 == undefined){var server_portv6 = 19133;} else {var server_portv6 = config.port6;};
|
|
||||||
|
|
||||||
// Default player permission
|
if (config.port !== undefined) server_port = config.port;
|
||||||
if (config.player_permission == undefined) var player_permission = `member`;
|
|
||||||
else var player_permission = config.player_permission;
|
|
||||||
|
|
||||||
if (2 >= cpuCount) var tick = 2 ;
|
if (config.port6 !== undefined) server_portv6 = config.port6;
|
||||||
else if (4 >= cpuCount) var tick = 4;
|
|
||||||
else if (6 >= cpuCount) var tick = 6;
|
if (config.player_permission !== undefined) player_permission = config.player_permission;
|
||||||
else if (8 >= cpuCount) var tick = 8;
|
|
||||||
else if (10 >= cpuCount) var tick = 10;
|
if (2 >= cpuCount) tick = 2 ;
|
||||||
else var tick = 12
|
else if (4 >= cpuCount) tick = 4;
|
||||||
|
else if (6 >= cpuCount) tick = 6;
|
||||||
|
else if (8 >= cpuCount) tick = 8;
|
||||||
|
else if (10 >= cpuCount) tick = 10;
|
||||||
|
else tick = 12
|
||||||
|
|
||||||
/*Save Files*/
|
/*Save Files*/
|
||||||
if (bds.platform === 'bedrock'){
|
var config_file_content
|
||||||
var config_file_content = `server-name=${description_name}
|
if (bds.platform === "bedrock"){
|
||||||
|
config_file_content = `server-name=${description_name}
|
||||||
gamemode=${gamemode}
|
gamemode=${gamemode}
|
||||||
difficulty=${difficulty}
|
difficulty=${difficulty}
|
||||||
allow-cheats=${allow_cheats}
|
allow-cheats=${allow_cheats}
|
||||||
@ -92,7 +91,7 @@ correct-player-movement=false
|
|||||||
# Created on Bds-Manager by Sirherobrine23`
|
# Created on Bds-Manager by Sirherobrine23`
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
var config_file_content = `enable-jmx-monitoring=false
|
config_file_content = `enable-jmx-monitoring=false
|
||||||
rcon.port=25575
|
rcon.port=25575
|
||||||
level-seed=
|
level-seed=
|
||||||
gamemode=${gamemode}
|
gamemode=${gamemode}
|
||||||
@ -147,20 +146,21 @@ max-world-size=29999984
|
|||||||
}
|
}
|
||||||
// console.log(config_file_content);
|
// console.log(config_file_content);
|
||||||
fs.writeFileSync(Server_Config, config_file_content);
|
fs.writeFileSync(Server_Config, config_file_content);
|
||||||
return `success`
|
return true
|
||||||
};
|
}
|
||||||
function bds_get_config(){
|
function bds_get_config(){
|
||||||
var fs = require("fs");
|
var fs = require("fs");
|
||||||
const path = require("path")
|
const path = require("path");
|
||||||
const bds = require("../index")
|
const bds = require("../index");
|
||||||
const propertiesToJSON = require("properties-to-json");
|
const propertiesToJSON = require("properties-to-json");
|
||||||
|
|
||||||
if (bds.platform === "bedrock") var config_path = path.join(bds.bds_dir_bedrock, "server.properties")
|
var config_path;
|
||||||
else var config_path = path.join(bds.bds_dir_java, "server.properties")
|
if (bds.platform === "bedrock") config_path = path.join(bds.bds_dir_bedrock, "server.properties");
|
||||||
var config = fs.readFileSync(config_path, "utf8").split("-").join("_")
|
else config_path = path.join(bds.bds_dir_java, "server.properties");
|
||||||
|
var config = fs.readFileSync(config_path, "utf8").split("-").join("_");
|
||||||
return propertiesToJSON(config);
|
return propertiesToJSON(config);
|
||||||
}
|
}
|
||||||
module.exports.config_example = () =>{
|
function config_example(){
|
||||||
return {
|
return {
|
||||||
name: "Bedrock our Java",
|
name: "Bedrock our Java",
|
||||||
description: "BDS Maneger",
|
description: "BDS Maneger",
|
||||||
@ -177,3 +177,4 @@ return {
|
|||||||
}
|
}
|
||||||
module.exports.config = bds_config
|
module.exports.config = bds_config
|
||||||
module.exports.get_config = bds_get_config
|
module.exports.get_config = bds_get_config
|
||||||
|
module.exports.config_example = config_example
|
21
scripts/detect.js
Normal file
21
scripts/detect.js
Normal 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
26
scripts/kill_server.js
Normal 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
|
||||||
|
}
|
||||||
|
};
|
Reference in New Issue
Block a user