Stable #36
21
.devcontainer/Dockerfile
Normal file
21
.devcontainer/Dockerfile
Normal file
@ -0,0 +1,21 @@
|
||||
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.158.0/containers/javascript-node/.devcontainer/base.Dockerfile
|
||||
|
||||
# [Choice] Node.js version: 14, 12, 10
|
||||
ARG VARIANT="14-buster"
|
||||
FROM mcr.microsoft.com/vscode/devcontainers/javascript-node:0-${VARIANT}
|
||||
|
||||
# [Optional] Uncomment this section to install additional OS packages.
|
||||
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive && \
|
||||
apt-get -y install curl wget git zsh libnss3 libatk-bridge2.0-0 gconf-service libasound2 libatk1.0-0 libc6 \
|
||||
libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 \
|
||||
libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 \
|
||||
libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils libgbm-dev
|
||||
|
||||
RUN wget https://github.com/cli/cli/releases/download/v1.6.0-pre.3/gh_1.6.0-pre.3_linux_amd64.deb -O /tmp/gh.deb && dpkg -i /tmp/gh.deb
|
||||
|
||||
# [Optional] Uncomment if you want to install an additional version of node using nvm
|
||||
# ARG EXTRA_NODE_VERSION=10
|
||||
# RUN su node -c "source /usr/local/share/nvm/nvm.sh && nvm install ${EXTRA_NODE_VERSION}"
|
||||
|
||||
# [Optional] Uncomment if you want to install more global node modules
|
||||
# RUN su node -c "npm install -g <your-package-list-here>"
|
50
.devcontainer/devcontainer.json
Normal file
50
.devcontainer/devcontainer.json
Normal file
@ -0,0 +1,50 @@
|
||||
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
|
||||
// https://github.com/microsoft/vscode-dev-containers/tree/v0.158.0/containers/javascript-node
|
||||
{
|
||||
"name": "Node.js",
|
||||
"build": {
|
||||
"dockerfile": "Dockerfile",
|
||||
// Update 'VARIANT' to pick a Node version: 10, 12, 14
|
||||
"args": {
|
||||
"VARIANT": "14"
|
||||
}
|
||||
},
|
||||
|
||||
// Set *default* container specific settings.json values on container create.
|
||||
"settings": {
|
||||
"terminal.integrated.shell.linux": "/usr/bin/zsh"
|
||||
},
|
||||
|
||||
// Add the IDs of extensions you want installed when the container is created.
|
||||
"extensions": [
|
||||
"dbaeumer.vscode-eslint",
|
||||
"formulahendry.auto-rename-tag",
|
||||
"ms-vscode-remote.remote-containers",
|
||||
"benshabatnoam.google-translate-ext",
|
||||
"wix.vscode-import-cost",
|
||||
"eg2.vscode-npm-script",
|
||||
"christian-kohler.npm-intellisense",
|
||||
"christian-kohler.path-intellisense",
|
||||
"kodetech.electron-debug",
|
||||
"coenraads.bracket-pair-colorizer",
|
||||
"aaron-bond.better-comments",
|
||||
"msjsdiag.debugger-for-chrome",
|
||||
"smcpeak.default-keys-windows"
|
||||
],
|
||||
|
||||
// Use 'forwardPorts' to make a list of ports inside the container available locally.
|
||||
"forwardPorts": [
|
||||
19132,
|
||||
19133,
|
||||
1932,
|
||||
28574,
|
||||
3000,
|
||||
6565
|
||||
],
|
||||
|
||||
// Use 'postCreateCommand' to run commands after the container is created.
|
||||
"postCreateCommand": "npm install --no-save",
|
||||
|
||||
// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
|
||||
"remoteUser": "node"
|
||||
}
|
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:
|
||||
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 }}
|
25
.github/workflows/stable.yml
vendored
25
.github/workflows/stable.yml
vendored
@ -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
|
||||
@ -53,3 +56,19 @@ jobs:
|
||||
run: npm publish
|
||||
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: ${{ 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 }}
|
60
.gitlab-ci.yml
Normal file
60
.gitlab-ci.yml
Normal file
@ -0,0 +1,60 @@
|
||||
# This file is a template, and might need editing before it works on your project.
|
||||
default:
|
||||
image: node:latest
|
||||
|
||||
# Validate that the repository contains a package.json and extract a few values from it.
|
||||
before_script:
|
||||
- |
|
||||
if [[ ! -f package.json ]]; then
|
||||
echo "No package.json found! A package.json file is required to publish a package to GitLab's NPM registry."
|
||||
echo 'For more information, see https://docs.gitlab.com/ee/user/packages/npm_registry/#creating-a-project'
|
||||
exit 1
|
||||
fi
|
||||
- NPM_PACKAGE_NAME=$(node -p "require('./package.json').name")
|
||||
- NPM_PACKAGE_VERSION=$(node -p "require('./package.json').version")
|
||||
|
||||
# Validate that the package name is properly scoped to the project's root namespace.
|
||||
# For more information, see https://docs.gitlab.com/ee/user/packages/npm_registry/#package-naming-convention
|
||||
validate_package_scope:
|
||||
stage: build
|
||||
script:
|
||||
- |
|
||||
if [[ ! $NPM_PACKAGE_NAME =~ ^@$CI_PROJECT_ROOT_NAMESPACE/ ]]; then
|
||||
echo "Invalid package scope! Packages must be scoped in the root namespace of the project, e.g. \"@${CI_PROJECT_ROOT_NAMESPACE}/${CI_PROJECT_NAME}\""
|
||||
echo 'For more information, see https://docs.gitlab.com/ee/user/packages/npm_registry/#package-naming-convention'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# If no .npmrc if included in the repo, generate a temporary one to use during the publish step
|
||||
# that is configured to publish to GitLab's NPM registry
|
||||
create_npmrc:
|
||||
stage: build
|
||||
script:
|
||||
- |
|
||||
if [[ ! -f .npmrc ]]; then
|
||||
echo 'No .npmrc found! Creating one now. Please review the following link for more information: https://docs.gitlab.com/ee/user/packages/npm_registry/index.html#authenticating-with-a-ci-job-token'
|
||||
|
||||
{
|
||||
echo '@${CI_PROJECT_ROOT_NAMESPACE}:registry=${CI_SERVER_PROTOCOL}://${CI_SERVER_HOST}:${CI_SERVER_PORT}/api/v4/projects/${CI_PROJECT_ID}/packages/npm/'
|
||||
echo '//${CI_SERVER_HOST}:${CI_SERVER_PORT}/api/v4/packages/npm/:_authToken=${CI_JOB_TOKEN}'
|
||||
echo '//${CI_SERVER_HOST}:${CI_SERVER_PORT}/api/v4/projects/${CI_PROJECT_ID}/packages/npm/:_authToken=${CI_JOB_TOKEN}'
|
||||
} >> .npmrc
|
||||
|
||||
fi
|
||||
artifacts:
|
||||
paths:
|
||||
- .npmrc
|
||||
|
||||
# Publish the package. If the version in package.json has not yet been published, it will be
|
||||
# published to GitLab's NPM registry. If the version already exists, the publish command
|
||||
# will fail and the existing package will not be updated.
|
||||
publish_package:
|
||||
stage: deploy
|
||||
script:
|
||||
- |
|
||||
{
|
||||
npm publish &&
|
||||
echo "Successfully published version ${NPM_PACKAGE_VERSION} of ${NPM_PACKAGE_NAME} to GitLab's NPM registry: ${CI_PROJECT_URL}/-/packages"
|
||||
} || {
|
||||
echo "No new version of ${NPM_PACKAGE_NAME} published. This is most likely because version ${NPM_PACKAGE_VERSION} already exists in GitLab's NPM registry."
|
||||
}
|
109
API/api.js
109
API/api.js
@ -1,11 +1,11 @@
|
||||
module.exports = () => {
|
||||
global.bds_api_start = true
|
||||
global.bds_api_start = true;
|
||||
const express = require("express");
|
||||
const bds = require("../index");
|
||||
const fs = require("fs");
|
||||
const app = express();
|
||||
const path = require("path")
|
||||
var cors = require('cors');
|
||||
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)
|
||||
@ -19,6 +19,11 @@ module.exports = () => {
|
||||
app.use(cors());
|
||||
app.use(require("body-parser").json()); /* https://github.com/github/fetch/issues/323#issuecomment-331477498 */
|
||||
app.use(limiter);
|
||||
const bodyParser = require("body-parser");
|
||||
app.use(bodyParser.urlencoded({ extended: true }));
|
||||
app.get("/configs", (req, res) => {
|
||||
return res.send(bds.get_config());
|
||||
});
|
||||
app.get("/info", (req, res) => {
|
||||
const text = fs.readFileSync(localStorage.getItem("old_log_file"), "utf8");
|
||||
const versions = bds.version_raw
|
||||
@ -28,7 +33,7 @@ module.exports = () => {
|
||||
} else {
|
||||
v++;
|
||||
}
|
||||
};
|
||||
}
|
||||
const config = bds.get_config()
|
||||
var json_http = {
|
||||
"server": {
|
||||
@ -47,6 +52,7 @@ module.exports = () => {
|
||||
return res.send(json_http);
|
||||
});
|
||||
app.get("/", (req, res) => {
|
||||
<<<<<<< HEAD
|
||||
return res.send(`Hello, welcome to the Bds Maneger API, If this page has loaded it means that the API is working as planned, More information access the API documentation at: https://docs.srherobrine23.com/bds-maneger-api_whatis.html, Version: ${require(__dirname+'/../package.json').version}`);
|
||||
});
|
||||
app.get("/themes", (req, res) => {
|
||||
@ -60,10 +66,95 @@ module.exports = () => {
|
||||
}
|
||||
return res.send(themes_json);
|
||||
});
|
||||
=======
|
||||
return res.send(`Hello, welcome to the Bds Maneger API, If this page has loaded it means that the API is working as planned, More information access the API documentation at: https://docs.srherobrine23.com/bds-maneger-api_whatis.html, Version: ${require(path.join(__dirname, "..", "package.json")).version}`);
|
||||
>>>>>>> main
|
||||
});
|
||||
const bodyParser = require("body-parser");
|
||||
app.use(bodyParser.urlencoded({ extended: true }));
|
||||
|
||||
const http_port = "1932"
|
||||
app.listen(http_port);
|
||||
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"), "utf8"))
|
||||
var pass = false;
|
||||
for (let token_verify in tokens) {
|
||||
const element = tokens[token_verify].token;
|
||||
if (body.token == element){
|
||||
pass = true
|
||||
} else {
|
||||
token_verify++
|
||||
}
|
||||
}
|
||||
if (pass){
|
||||
var command_status
|
||||
if (command_bds === "start"){
|
||||
bds.start()
|
||||
command_status = "Bds Started"
|
||||
} else if (command_bds === "stop"){
|
||||
bds.stop()
|
||||
command_status = "Stopping the bds server"
|
||||
} else {
|
||||
command_status = "no command identified"
|
||||
}
|
||||
res.send({
|
||||
"status": 200,
|
||||
"bds_status": command_status
|
||||
})
|
||||
} else {
|
||||
res.send({
|
||||
"status": 401,
|
||||
"message": `Not authorized: ${body.token}`
|
||||
})
|
||||
}
|
||||
});
|
||||
app.post("/bds_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"), "utf8"))
|
||||
var pass = false;
|
||||
for (let token_verify in tokens) {
|
||||
const element = tokens[token_verify].token;
|
||||
if (body.token == element){
|
||||
pass = true
|
||||
} else {
|
||||
token_verify++
|
||||
}
|
||||
}
|
||||
var STA,EMN
|
||||
if (pass){
|
||||
STA = "wait"
|
||||
EMN = bds.download(ver)
|
||||
} else {
|
||||
STA = "401",
|
||||
EMN = "Unauthorized Token"
|
||||
}
|
||||
res.send({
|
||||
"status": STA,
|
||||
"message": EMN
|
||||
})
|
||||
});
|
||||
app.post("/bds_command", (req, res) => {
|
||||
const body = req.body
|
||||
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;
|
||||
// req.connection.remoteAddress
|
||||
if (body.token == element){pass = true} else {token_verify++}
|
||||
}
|
||||
if (pass){
|
||||
const command = body.command
|
||||
const teste = bds.command(command)
|
||||
res.send({
|
||||
"status": 200,
|
||||
"command": body.command,
|
||||
"log": teste,
|
||||
"message": `authorized to ${body.token}`
|
||||
})
|
||||
} else {
|
||||
res.send({
|
||||
"status": 401,
|
||||
"message": "not authorized"
|
||||
})
|
||||
}
|
||||
});
|
||||
app.listen(1932);
|
||||
}
|
42
API/log.js
42
API/log.js
@ -4,24 +4,46 @@ module.exports = () => {
|
||||
const bds = require("../index");
|
||||
const fs = require("fs");
|
||||
const app = express();
|
||||
var cors = require('cors');
|
||||
var cors = require("cors");
|
||||
app.use(cors());
|
||||
app.use(require("body-parser").json()); /* https://github.com/github/fetch/issues/323#issuecomment-331477498 */
|
||||
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 = 'The server is stopped';
|
||||
var sucess = false
|
||||
var text="";
|
||||
var log_file="";
|
||||
var sucess="";
|
||||
if (typeof bds_log_string === "undefined"){
|
||||
if (fs.existsSync(localStorage.getItem("old_log_file"))){
|
||||
text = `${fs.readFileSync(localStorage.getItem("old_log_file"), "utf8")}`
|
||||
log_file = localStorage.getItem("old_log_file")
|
||||
sucess = true
|
||||
} else {
|
||||
text = "The server is stopped"
|
||||
sucess = false
|
||||
}
|
||||
} else {
|
||||
var text = bds_log_string
|
||||
var sucess = true
|
||||
text = bds_log_string
|
||||
log_file = "string"
|
||||
sucess = true
|
||||
}
|
||||
res.json({
|
||||
"sucess": sucess,
|
||||
"log": text,
|
||||
"log_file": localStorage.getItem("old_log_file"),
|
||||
"log_file": log_file,
|
||||
"ip": `${req.clientIp}`,
|
||||
"requeset_date": bds.date()
|
||||
});
|
||||
});
|
||||
const http_port = "6565"
|
||||
app.listen(http_port);
|
||||
app.listen(6565);
|
||||
}
|
||||
|
17
API/theme.js
17
API/theme.js
@ -1,17 +0,0 @@
|
||||
module.exports = () => {
|
||||
require("express");
|
||||
if (typeof fetch === "undefined"){
|
||||
var fetch = require("node-fetch")
|
||||
}
|
||||
const themes = "https://raw.githubusercontent.com/Bds-Maneger/Raw_files/main/themes.json"
|
||||
fetch(themes).then(response => response.json()).then(array => {
|
||||
for (let index = 0; index < array.length; index++) {
|
||||
const name = array[index].name;
|
||||
const zip_url = array[index].zip_url;
|
||||
const git_url = array[index].git_url;
|
||||
console.log(`Name: ${name},\n Url Zip: ${zip_url},\n Git url: ${git_url}`)
|
||||
}
|
||||
}).catch(function(error) {
|
||||
console.log(`Could not get credentials, Error: \"${error.message}\"`);
|
||||
});
|
||||
}
|
11
CHANGELOG.md
11
CHANGELOG.md
@ -1,3 +1,14 @@
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
# 1.5.0
|
||||
|
||||
All scripts have been rewritten some features are still under maintenance
|
||||
|
||||
The Docker image has returned to work in the new version.
|
||||
|
||||
Some functions will be modified or removed from the next version in the Stable branch
|
||||
|
||||
>>>>>>> main
|
||||
# 1.4.2
|
||||
|
||||
Docker test fix
|
||||
|
@ -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
|
||||
|
@ -42,30 +42,52 @@ function getAccessToken(oAuth2Client, callback) {
|
||||
callback(oAuth2Client);
|
||||
});
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
module.exports.drive_backup = () => {
|
||||
<<<<<<< HEAD
|
||||
const file_json = require("../new_script/backups").Drive_backup()
|
||||
=======
|
||||
const file_json = require("../scripts/backups").Drive_backup()
|
||||
>>>>>>> main
|
||||
console.log(file_json)
|
||||
const parent_id = file_json.id
|
||||
const path_file = file_json.file_path
|
||||
const name_d = file_json.file_name;
|
||||
|
||||
<<<<<<< HEAD
|
||||
const gd_secret = '';
|
||||
console.log(gd_secret)
|
||||
function upload_backup(auth) {
|
||||
const drive = google.drive({version: "v3", auth});
|
||||
if (parent_id === undefined){
|
||||
var fileMetadata = {
|
||||
=======
|
||||
const gd_secret = "";
|
||||
console.log(gd_secret)
|
||||
function upload_backup(auth) {
|
||||
const drive = google.drive({version: "v3", auth});
|
||||
var fileMetadata;
|
||||
if (parent_id === undefined){
|
||||
fileMetadata = {
|
||||
>>>>>>> main
|
||||
name: name_d
|
||||
}
|
||||
console.log("Your backup will be saved to My Drive")
|
||||
} else {
|
||||
<<<<<<< HEAD
|
||||
var fileMetadata = {
|
||||
name: name_d,
|
||||
parents: [parent_id]
|
||||
}
|
||||
};
|
||||
=======
|
||||
fileMetadata = {
|
||||
name: name_d,
|
||||
parents: [parent_id]
|
||||
}
|
||||
}
|
||||
>>>>>>> main
|
||||
var media = {
|
||||
mimeType: "application/octet-stream",
|
||||
body: fs.createReadStream(path_file)
|
||||
@ -101,6 +123,10 @@ module.exports.mcpe = () => {
|
||||
progress += d.length / 1024 / 1024;
|
||||
if (process.stdout.isTTY) {process.stdout.clearLine();process.stdout.cursorTo(0);process.stdout.write(`Downloaded ${Math.trunc(progress)} Mbytes`);}
|
||||
}).pipe(dest)});
|
||||
<<<<<<< HEAD
|
||||
};
|
||||
=======
|
||||
}
|
||||
>>>>>>> main
|
||||
return authorize(gd_secret, download_mcpe);
|
||||
}
|
||||
|
@ -1,21 +1,38 @@
|
||||
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 {
|
||||
<<<<<<< HEAD
|
||||
var admins = `{"sh23_bot_not_config": {"allow": true}}`;
|
||||
console.warn("All allowed")
|
||||
console.log(`Create file in with name: ${require("../index").bds_dir}/telegram_admin.json`)
|
||||
=======
|
||||
const config = {
|
||||
"sh23_bot_not_config": {
|
||||
"allow": true
|
||||
}
|
||||
}
|
||||
fs.writeFileSync(telegram_admin, JSON.stringify(config))
|
||||
throw new console.error(`we just created the telegram authorization, edit before using: ${config}`);
|
||||
>>>>>>> main
|
||||
}
|
||||
var adm = JSON.parse(admins);
|
||||
for(index in adm){
|
||||
if (USERNAME == index){
|
||||
for(let check_ in adm){
|
||||
if (USERNAME == check_){
|
||||
return true
|
||||
<<<<<<< HEAD
|
||||
} else if (index == "sh23_bot_not_config"){
|
||||
=======
|
||||
} else if (check_ == "sh23_bot_not_config"){
|
||||
>>>>>>> main
|
||||
console.warn("Allow all")
|
||||
return true
|
||||
}; index++;
|
||||
};
|
||||
} check_++;
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
|
@ -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}
|
||||
@ -11,6 +11,8 @@ Commands:
|
||||
/log
|
||||
/command
|
||||
/list
|
||||
/mcpe
|
||||
/status
|
||||
The messages are re-transmitted to the minecraft chat if it is already connected: ✔
|
||||
Message Control: ❌`
|
||||
ctx.reply(amenssagem)
|
||||
@ -25,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
|
||||
@ -74,7 +76,11 @@ bot.command("list", (ctx) =>{
|
||||
bds_command("list")
|
||||
var old = bds_log_string;
|
||||
setTimeout(() => {
|
||||
<<<<<<< HEAD
|
||||
var name = bds_log_string.replace(old, "");
|
||||
=======
|
||||
var name = bds_log_string.replace(old, "End\n\n");
|
||||
>>>>>>> main
|
||||
ctx.reply(name)
|
||||
}, 1000);
|
||||
} else {
|
||||
@ -82,12 +88,21 @@ bot.command("list", (ctx) =>{
|
||||
}
|
||||
});
|
||||
bot.command("mcpe", (ctx) =>{
|
||||
// ctx.replyWithHTML(`<a href="https://storage.cloud.google.com/bds_mcpe_files/mcpe.apk">Minecraft for Android 1.16.201.01</a>`)
|
||||
const text = `[Minecraft for Android 1.16.201.01](https://storage.googleapis.com/bds_mcpe_files/0.16.201.01.apk)
|
||||
ctx.replyWithMarkdown(`[Minecraft for Android 1.16.201.01](https://files.sh33.org/mcpe/latest.sonic)
|
||||
|
||||
Iphone users are not privileged
|
||||
<<<<<<< HEAD
|
||||
`
|
||||
ctx.replyWithMarkdown(text)
|
||||
=======
|
||||
`)});
|
||||
bot.command("status", (ctx) =>{
|
||||
const {bds_cpu, current_cpu, ram_total, ram_free} = require("./system_monitor")
|
||||
const text = `Bds CPU usage: ${bds_cpu}%, Total CPU utilization: ${current_cpu}%
|
||||
|
||||
Total ram memory: ${ram_total} GB, Total free ram memory: ${ram_free} GB`
|
||||
ctx.replyWithMarkdown(text);
|
||||
>>>>>>> main
|
||||
});
|
||||
// bot.command("status", (ctx) =>{
|
||||
// const si = require("systeminformation");
|
||||
|
348
index.js
348
index.js
@ -1,3 +1,4 @@
|
||||
/* eslint-disable no-irregular-whitespace */
|
||||
console.log(`Running the Bds Maneger API in version ${require(__dirname+"/package.json").version}`)
|
||||
var shell = require("shelljs");
|
||||
let blanks;
|
||||
@ -14,10 +15,11 @@ function date(fu) {
|
||||
else
|
||||
return `${String(today.getDate()).padStart(2, "0")}-${String(today.getMonth() + 1).padStart(2, "0")}-${today.getFullYear()}_${today.getHours()}-${today.getSeconds()}`
|
||||
}
|
||||
var electron_de
|
||||
if (process.argv[0].includes("electron")){
|
||||
var electron_de = true;
|
||||
electron_de = true;
|
||||
} else if (process.argv[0].includes("node")){
|
||||
var electron_de = undefined;
|
||||
electron_de = undefined;
|
||||
if (process.env.BDS_MONI == blanks){
|
||||
process.env.BDS_MONI = true
|
||||
}
|
||||
@ -28,21 +30,18 @@ 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") {
|
||||
<<<<<<< HEAD
|
||||
var home = process.env.USERPROFILE;
|
||||
var desktop = path.join(home, "Desktop")
|
||||
if (fs.existsSync(package_root)){
|
||||
@ -66,6 +65,51 @@ if (process.platform == "win32") {
|
||||
|
||||
var tmp = `/tmp`;
|
||||
var system = `linux`;
|
||||
=======
|
||||
home = process.env.USERPROFILE;
|
||||
desktop = path.join(home, "Desktop")
|
||||
if (fs.existsSync(package_root)){
|
||||
cache_dir = path.join(home, "AppData", "Roaming", require(package_root).name)
|
||||
} else if (package_root_builder){
|
||||
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");
|
||||
cache_dir = path.join(process.env.TMP, "bds_tmp_configs");
|
||||
}
|
||||
tmp = process.env.TMP
|
||||
system = "windows";
|
||||
} else if (process.platform == "linux") {
|
||||
home = process.env.HOME;
|
||||
if (fs.existsSync(package_root)){
|
||||
cache_dir = path.join(home, ".config", require(package_root).name);
|
||||
} else if (fs.existsSync(package_root_builder)) {
|
||||
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");
|
||||
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){
|
||||
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"}
|
||||
|
||||
tmp = "/tmp";
|
||||
system = "linux";
|
||||
>>>>>>> main
|
||||
} else if (process.platform == "darwin") {
|
||||
require("open")("https://github.com/Bds-Maneger/Bds_Maneger/wiki/systems-support#a-message-for-mac-os-users")
|
||||
console.error("Please use Windows or Linux MacOS Not yet supported")
|
||||
@ -73,6 +117,7 @@ if (process.platform == "win32") {
|
||||
} else {
|
||||
console.log(`Please use an operating system (OS) compatible with Minecraft Bedrock Server ${process.platform} is not supported`);
|
||||
process.exit(2021)
|
||||
<<<<<<< HEAD
|
||||
};
|
||||
// ---------
|
||||
// ---------
|
||||
@ -118,6 +163,59 @@ if (!(fs.existsSync(cache_dir))){
|
||||
fs.mkdirSync(cache_dir)
|
||||
if (!(fs.existsSync(cache_dir))) shell.mkdir("-p", cache_dir);
|
||||
}
|
||||
=======
|
||||
}
|
||||
// ---------
|
||||
// ---------
|
||||
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");
|
||||
module.exports.backup_folder = bds_dir_backup
|
||||
|
||||
if (!(fs.existsSync(bds_dir))){
|
||||
console.log("Creating the bds directory")
|
||||
fs.mkdirSync(bds_dir)
|
||||
if (!(fs.existsSync(bds_dir))) shell.mkdir("-p", bds_dir);
|
||||
}
|
||||
|
||||
// Configs
|
||||
const bds_config_file = path.join(bds_dir, "bds_config.json")
|
||||
if (fs.existsSync(bds_config_file)){
|
||||
var bds_config = JSON.parse(fs.readFileSync(bds_config_file, "utf8"))
|
||||
} else {
|
||||
const bds_config = {
|
||||
"bds_platform": "bedrock",
|
||||
"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`)
|
||||
// Configs
|
||||
|
||||
var log_dir = path.join(bds_dir, "log");
|
||||
var log_file = path.join(log_dir, `${date()}_${bds_config.bds_platform}_Bds_log.log`);
|
||||
var log_date = date();
|
||||
|
||||
// ---------
|
||||
// ---------
|
||||
|
||||
|
||||
|
||||
if (!(fs.existsSync(cache_dir))){
|
||||
console.log(`Creating a folder for Storage in ${cache_dir}`);
|
||||
fs.mkdirSync(cache_dir)
|
||||
if (!(fs.existsSync(cache_dir))) shell.mkdir("-p", cache_dir);
|
||||
}
|
||||
>>>>>>> main
|
||||
// e
|
||||
if (!(fs.existsSync(bds_dir_java))){
|
||||
console.log("Creating the bds directory to Java")
|
||||
@ -135,6 +233,7 @@ if (!(fs.existsSync(log_dir))){
|
||||
console.log(`Creating the bds log dir (${log_dir})`)
|
||||
fs.mkdirSync(log_dir)
|
||||
if (!(fs.existsSync(log_dir))) shell.mkdir("-p", log_dir)
|
||||
<<<<<<< HEAD
|
||||
};
|
||||
};
|
||||
// e
|
||||
@ -160,6 +259,65 @@ if (process.env.JAVA_ENABLE !== undefined){
|
||||
localStorage.setItem('bds_edititon', 'java');
|
||||
}else{
|
||||
localStorage.setItem('bds_edititon', 'bedrock');
|
||||
=======
|
||||
}
|
||||
}
|
||||
// e
|
||||
|
||||
|
||||
/**
|
||||
* 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) =>{
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
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")
|
||||
}
|
||||
>>>>>>> main
|
||||
}
|
||||
|
||||
if (process.env.BDS_MONI == blanks){process.env.BDS_MONI = "false"}
|
||||
@ -168,17 +326,42 @@ 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
|
||||
<<<<<<< HEAD
|
||||
module.exports.mcpe_file = require("./global/auth").mcpe
|
||||
=======
|
||||
/**
|
||||
* download the latest version of minecraft bedrock for android available, remember to use if you want ✌
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
>>>>>>> main
|
||||
module.exports.drive_backup= require("./global/auth").drive_backup
|
||||
});
|
||||
fetch("https://raw.githubusercontent.com/Bds-Maneger/Raw_files/main/Server.json").then(response => response.json()).then(rawOUT => {
|
||||
const versions = Object.getOwnPropertyNames(rawOUT.bedrock);
|
||||
for (let v in versions){
|
||||
var html = `${versions[v]}`;
|
||||
<<<<<<< HEAD
|
||||
module.exports.version_select += `<option value=\"${html}\">${html}</option>\n`;
|
||||
v++;
|
||||
};
|
||||
=======
|
||||
module.exports.version_select += `<option value="${html}">${html}</option>\n`;
|
||||
v++;
|
||||
}
|
||||
>>>>>>> main
|
||||
module.exports.bedrock_all_versions = Object.getOwnPropertyNames(rawOUT.bedrock);
|
||||
module.exports.java_all_versions = Object.getOwnPropertyNames(rawOUT.java);
|
||||
module.exports.bds_latest = rawOUT.bedrock_lateste;
|
||||
@ -189,10 +372,16 @@ fetch("https://raw.githubusercontent.com/Bds-Maneger/Raw_files/main/Server.json"
|
||||
if (typeof bds_api_start === "undefined"){
|
||||
require("./API/api")();
|
||||
require("./API/log")();
|
||||
<<<<<<< HEAD
|
||||
require("./API/remote_access")();
|
||||
}
|
||||
} else {
|
||||
console.warn(`The API via http is disabled, for more information, visit https://docs.srherobrine23.com/enable_bds_requests.html`)
|
||||
=======
|
||||
}
|
||||
} else {
|
||||
console.warn("The API via http is disabled, for more information, visit https://docs.srherobrine23.com/enable_bds_requests.html")
|
||||
>>>>>>> main
|
||||
}
|
||||
module.exports.get_version = (type) => {
|
||||
if (type == "raw")
|
||||
@ -205,14 +394,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
|
||||
@ -220,12 +436,43 @@ 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
|
||||
<<<<<<< HEAD
|
||||
// module.exports.stop = require("./global/stop").Server_stop
|
||||
|
||||
// New management method
|
||||
@ -240,3 +487,76 @@ module.exports.kill = require("./new_script/kill_server")
|
||||
module.exports.config_example = require("./new_script/bds_settings").config_example
|
||||
module.exports.set_config = require("./new_script/bds_settings").config
|
||||
module.exports.get_config = require("./new_script/bds_settings").get_config
|
||||
=======
|
||||
// New management method
|
||||
|
||||
/**
|
||||
* 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
|
||||
>>>>>>> main
|
||||
|
2615
package-lock.json
generated
2615
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
27
package.json
27
package.json
@ -1,11 +1,20 @@
|
||||
{
|
||||
<<<<<<< HEAD
|
||||
"name": "bds_maneger_api",
|
||||
"version": "1.4.2",
|
||||
=======
|
||||
"name": "@the-bds-maneger/bds_maneger_api",
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"version": "1.5.4",
|
||||
>>>>>>> main
|
||||
"description": "scripts to manage minecraft bedrock server",
|
||||
"private": false,
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "exit 0",
|
||||
"test": "eslint .",
|
||||
"test:fix": "eslint --fix .",
|
||||
"server": "node index.js"
|
||||
},
|
||||
"repository": {
|
||||
@ -16,8 +25,9 @@
|
||||
"minecraft",
|
||||
"bds",
|
||||
"bds-server",
|
||||
"Windows",
|
||||
"linux"
|
||||
"bedrock",
|
||||
"java",
|
||||
"server_mode"
|
||||
],
|
||||
"author": "Sirherobrine23",
|
||||
"license": "AGPL-3.0-or-later",
|
||||
@ -40,8 +50,19 @@
|
||||
"properties-to-json": "^0.1.7",
|
||||
"qr-image": "^3.2.0",
|
||||
"qrcode": "^1.4.4",
|
||||
"request-ip": "^2.1.3",
|
||||
"shelljs": "^0.8.4",
|
||||
<<<<<<< HEAD
|
||||
"systeminformation": "^5.0.2",
|
||||
=======
|
||||
"systeminformation": "^5.0.10",
|
||||
>>>>>>> main
|
||||
"telegraf": "^4.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=14"
|
||||
},
|
||||
"devDependencies": {
|
||||
"eslint": "^7.19.0"
|
||||
}
|
||||
}
|
||||
|
73
scripts/backups.js
Normal file
73
scripts/backups.js
Normal file
@ -0,0 +1,73 @@
|
||||
module.exports.World_BAckup = () => {
|
||||
const bds = require("../index")
|
||||
const path = require("path")
|
||||
const java_pro = require("properties-to-json")
|
||||
const fs = require("fs")
|
||||
var AdmZip = require("adm-zip");
|
||||
|
||||
var today = bds.date()
|
||||
const name = path.join(bds.backup_folder ,`bds_backup_World_${today}.zip`)
|
||||
var dir_zip;
|
||||
if (bds.platform === "bedrock"){
|
||||
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"), "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()}
|
||||
var zip = new AdmZip();
|
||||
zip.addLocalFolder(dir_zip);
|
||||
zip.addZipComment(`Backup zip file in ${today}. \nBackup made to ${process.platform}, Free and open content for all\n\nSirherobrine23© By Bds Maneger.`);
|
||||
var zipEntries = zip.getEntries();
|
||||
zipEntries.forEach(function (zipEntry) {
|
||||
console.log(zipEntry.entryName.toString());
|
||||
});
|
||||
zip.writeZip(name);
|
||||
return {
|
||||
path: name,
|
||||
world_path: dir_zip
|
||||
}
|
||||
};
|
||||
|
||||
module.exports.Drive_backup = () => {
|
||||
const bds = require("../index")
|
||||
const path = require("path")
|
||||
const java_pro = require("properties-to-json")
|
||||
const fs = require("fs")
|
||||
var AdmZip = require("adm-zip");
|
||||
|
||||
var today = bds.date()
|
||||
const name = path.join(bds.backup_folder ,`bds_backup_World_${today}.zip`)
|
||||
var dir_zip;
|
||||
if (bds.platform === "bedrock"){
|
||||
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"), "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()}
|
||||
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.`);
|
||||
zip.writeZip(name);
|
||||
let es = 1;
|
||||
for(es == "0";es++;){
|
||||
if (!(status_b)) break
|
||||
}
|
||||
const js_ = {
|
||||
"file_path": name,
|
||||
"file_name": `bds_backup_World_${today}.zip`,
|
||||
"id": undefined
|
||||
}
|
||||
return js_
|
||||
};
|
||||
|
81
scripts/basic_server.js
Normal file
81
scripts/basic_server.js
Normal file
@ -0,0 +1,81 @@
|
||||
module.exports.start = () => {
|
||||
const bds = require("../index")
|
||||
const Storage = localStorage;
|
||||
const {exec, execSync} = require("child_process");
|
||||
const fs = require("fs")
|
||||
|
||||
|
||||
if (!(bds.detect())){
|
||||
const plat = bds.platform
|
||||
var start_server
|
||||
if (plat === "bedrock"){
|
||||
if (process.platform == "win32"){
|
||||
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())
|
||||
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")){
|
||||
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");
|
||||
console.log("http://docs.sirherobrine23.com/bds_maneger_api_java#Windows")
|
||||
} else if (bds.system === "linux"){
|
||||
require("open")("http://docs.sirherobrine23.com/bds_maneger_api_java#Linux");
|
||||
console.log("http://docs.sirherobrine23.com/bds_maneger_api_java#Linux")
|
||||
} else {
|
||||
require("open")("http://docs.sirherobrine23.com/bds_maneger_api_java");
|
||||
console.log("http://docs.sirherobrine23.com/bds_maneger_api_java")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Storage.setItem("old_log_file", bds.log_file)
|
||||
var logConsoleStream = require("fs").createWriteStream(bds.log_file, {flags: "a"});
|
||||
start_server.stdout.pipe(logConsoleStream);
|
||||
start_server.stdout.on("data", function(data){
|
||||
if (data.includes("agree", "EULA")){
|
||||
const path = require("path");
|
||||
require("open")("https://account.mojang.com/documents/minecraft_eula");
|
||||
const eula_file = path.join(bds.bds_dir_java, "eula.txt")
|
||||
const eula_make_true = fs.readFileSync(eula_file, "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")
|
||||
setTimeout(() => {
|
||||
process.exit(0)
|
||||
}, 1000);
|
||||
}
|
||||
}
|
||||
})
|
||||
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";
|
||||
}
|
||||
}
|
||||
module.exports.stop = () => {
|
||||
if (typeof bds_server_string == "undefined"){
|
||||
const detect = process.argv[0];
|
||||
if (detect.includes("electron")) alert("The server is stopped!");
|
||||
else console.log("The server is stopped!");
|
||||
} else {
|
||||
bds_server_string.stdin.write("stop\n");
|
||||
bds_server_string.stdout.on("data", function (data){
|
||||
if (data.includes("Quit correctly")){
|
||||
localStorage.setItem("bds_status", false)
|
||||
}
|
||||
});
|
||||
}
|
||||
return
|
||||
}
|
81
scripts/bds_download.js
Normal file
81
scripts/bds_download.js
Normal file
@ -0,0 +1,81 @@
|
||||
module.exports = (Vdown) => {
|
||||
console.warn("Do not exit BDS Manager")
|
||||
const bds = require("../index")
|
||||
|
||||
fetch("https://raw.githubusercontent.com/Bds-Maneger/Raw_files/main/Server.json").then(response => response.json()).then(versions => {
|
||||
var mine_name
|
||||
var downloadBDSchild
|
||||
if (bds.platform === "bedrock"){
|
||||
const system = bds.system
|
||||
mine_name = "bedrock.zip"
|
||||
var versions_get
|
||||
if (system === "linux"){
|
||||
versions_get = versions.bedrock[Vdown].url_linux;
|
||||
} else {
|
||||
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);
|
||||
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");
|
||||
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`, "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);
|
||||
console.log("Extract Sucess"); // End Unzip
|
||||
localStorage.setItem("Downlaod_sucess", "yes")
|
||||
if (_old){fs.writeFileSync(`${server_DIR}/server.properties`, old1);}
|
||||
if (_old2){fs.writeFileSync(`${server_DIR}/permissions.json`, old2);}
|
||||
if (_old3){fs.writeFileSync(`${server_DIR}/whitelist.json`, old3);}
|
||||
if (_old4){fs.writeFileSync(`${server_DIR}/valid_known_packs.json`, old4);}
|
||||
const docker_exit = process.env.BDS_DOCKER_IMAGE
|
||||
console.log(docker_exit)
|
||||
if (docker_exit == "true"){
|
||||
console.log("going out")
|
||||
process.exit(0)
|
||||
}
|
||||
} else {
|
||||
localStorage.setItem("Download_sucess", "no")
|
||||
throw new error("Could not download");
|
||||
}
|
||||
})
|
||||
} else {
|
||||
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);
|
||||
downloadBDSchild = exec(`curl ${versions_get} --output ${mine_name}`, {
|
||||
cwd: `${bds.bds_dir_java}`
|
||||
});
|
||||
downloadBDSchild.stdout.on("data", function(data){
|
||||
console.log(data)
|
||||
})
|
||||
downloadBDSchild.on("exit", function (code) {
|
||||
if (code === 0) {
|
||||
console.log("Download zip file success");
|
||||
localStorage.setItem("Downlaod_sucess", "yes")
|
||||
} else {
|
||||
localStorage.setItem("Download_sucess", "no")
|
||||
throw new error("Could not download");
|
||||
}
|
||||
})
|
||||
}
|
||||
// ---------------------------------------------------------
|
||||
})
|
||||
}
|
180
scripts/bds_settings.js
Normal file
180
scripts/bds_settings.js
Normal file
@ -0,0 +1,180 @@
|
||||
function bds_config(json_config){
|
||||
const bds = require("../index")
|
||||
const path = require("path")
|
||||
var fs = require("fs")
|
||||
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) tick = 2 ;
|
||||
else if (4 >= cpuCount) tick = 4;
|
||||
else if (6 >= cpuCount) tick = 6;
|
||||
else if (8 >= cpuCount) tick = 8;
|
||||
else if (10 >= cpuCount) tick = 10;
|
||||
else tick = 12
|
||||
|
||||
/*Save Files*/
|
||||
var config_file_content
|
||||
if (bds.platform === "bedrock"){
|
||||
config_file_content = `server-name=${description_name}
|
||||
gamemode=${gamemode}
|
||||
difficulty=${difficulty}
|
||||
allow-cheats=${allow_cheats}
|
||||
max-players=${max_players}
|
||||
online-mode=${online_mode}
|
||||
white-list=${white_list}
|
||||
server-port=${server_port}
|
||||
server-portv6=${server_portv6}
|
||||
view-distance=32
|
||||
tick-distance=${tick}
|
||||
player-idle-timeout=0
|
||||
max-threads=${CPU}
|
||||
level-name=${level_name}
|
||||
level-seed=
|
||||
default-player-permission-level=${player_permission}
|
||||
texturepack-required=true
|
||||
content-log-file-enabled=false
|
||||
compression-threshold=1
|
||||
server-authoritative-movement=server-auth
|
||||
player-movement-score-threshold=20
|
||||
player-movement-distance-threshold=0.3
|
||||
player-movement-duration-threshold-in-ms=500
|
||||
correct-player-movement=false
|
||||
|
||||
# Created on Bds-Manager by Sirherobrine23`
|
||||
|
||||
} else {
|
||||
config_file_content = `enable-jmx-monitoring=false
|
||||
rcon.port=25575
|
||||
level-seed=
|
||||
gamemode=${gamemode}
|
||||
enable-command-block=${allow_cheats}
|
||||
enable-query=true
|
||||
generator-settings=
|
||||
level-name=${level_name}
|
||||
motd=${description_name}
|
||||
query.port=${server_port}
|
||||
pvp=true
|
||||
generate-structures=true
|
||||
difficulty=${difficulty}
|
||||
network-compression-threshold=256
|
||||
max-tick-time=60000
|
||||
max-players=${max_players}
|
||||
use-native-transport=true
|
||||
online-mode=${online_mode}
|
||||
enable-status=true
|
||||
allow-flight=false
|
||||
broadcast-rcon-to-ops=true
|
||||
view-distance=32
|
||||
max-build-height=256
|
||||
server-ip=
|
||||
allow-nether=true
|
||||
server-port=${server_port}
|
||||
enable-rcon=${allow_cheats}
|
||||
sync-chunk-writes=true
|
||||
op-permission-level=4
|
||||
prevent-proxy-connections=false
|
||||
resource-pack=
|
||||
entity-broadcast-range-percentage=100
|
||||
rcon.password=25as65d3
|
||||
player-idle-timeout=0
|
||||
force-gamemode=false
|
||||
rate-limit=0
|
||||
hardcore=false
|
||||
white-list=${white_list}
|
||||
broadcast-console-to-ops=true
|
||||
spawn-npcs=true
|
||||
spawn-animals=true
|
||||
snooper-enabled=true
|
||||
function-permission-level=2
|
||||
level-type=default
|
||||
text-filtering-config=
|
||||
spawn-monsters=true
|
||||
enforce-whitelist=false
|
||||
resource-pack-sha1=
|
||||
spawn-protection=16
|
||||
max-world-size=29999984
|
||||
#
|
||||
# Created on Bds-Manager by Sirherobrine23`
|
||||
}
|
||||
// console.log(config_file_content);
|
||||
fs.writeFileSync(Server_Config, config_file_content);
|
||||
return true
|
||||
}
|
||||
function bds_get_config(){
|
||||
var fs = require("fs");
|
||||
const path = require("path");
|
||||
const bds = require("../index");
|
||||
const propertiesToJSON = require("properties-to-json");
|
||||
|
||||
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);
|
||||
}
|
||||
function config_example(){
|
||||
return {
|
||||
name: "Bedrock our Java",
|
||||
description: "BDS Maneger",
|
||||
gamemode: "survival",
|
||||
difficulty: "normal",
|
||||
player_permission: "member",
|
||||
xbox: true,
|
||||
white_list: false,
|
||||
cheats: false,
|
||||
players: 100,
|
||||
port: 19132,
|
||||
port6: 19133
|
||||
}
|
||||
}
|
||||
module.exports.config = bds_config
|
||||
module.exports.get_config = bds_get_config
|
||||
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