Code Modifications #261

Merged
Sirherobrine23 merged 8 commits from Sirherobrine23Changes into main 2021-12-07 18:50:16 +00:00
33 changed files with 510 additions and 829 deletions

View File

@ -1,67 +0,0 @@
#!/usr/bin/env bash
set -ex
# Update Debian Repository
apt update
# Install Necessary Packages
apt -qq install -y curl wget git zsh sudo unzip zip jq python3 screen xz-utils
# Install nodejs from github release
NODEVERSION=$(curl -sL https://api.github.com/repos/nodejs/node/releases | grep tag_name | cut -d '"' -f 4 | sort -V | tail -n 1)
case $(uname -m) in
x86_64 ) wget -q "https://nodejs.org/download/release/$NODEVERSION/node-$NODEVERSION-linux-x64.tar.xz" -O /tmp/node.tar.xz;;
aarch64 ) wget -q "https://nodejs.org/download/release/$NODEVERSION/node-$NODEVERSION-linux-arm64.tar.xz" -O /tmp/node.tar.xz;;
armv7l ) wget -q "https://nodejs.org/download/release/$NODEVERSION/node-$NODEVERSION-linux-armv7l.tar.xz" -O /tmp/node.tar.xz;;
ppc64el ) wget -q "https://nodejs.org/download/release/$NODEVERSION/node-$NODEVERSION-linux-ppc64le.tar.xz" -O /tmp/node.tar.xz;;
s390x ) wget -q "https://nodejs.org/download/release/$NODEVERSION/node-$NODEVERSION-linux-s390x.tar.xz" -O /tmp/node.tar.xz;;
*) echo "Unsupported architecture"; exit 1;;
esac
# Extract nodejs
mkdir /tmp/Node
tar -xJf /tmp/node.tar.xz -C /tmp/Node
rm -rf /tmp/node.tar.xz
cp -rf /tmp/Node/*/* /usr
# Install Build Dependencies and others Packages
apt -qq install -y ca-certificates make build-essential procps lsb-release xdg-utils g++ libatomic1 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 libxrandr2 libxrender1 libxss1 libxtst6 fonts-liberation libnss3 libgbm-dev
# Update npm
npm -g install npm@$(curl -sL https://api.github.com/repos/npm/cli/releases/latest | grep tag_name | cut -d '"' -f 4)
# Install Dependencies to diferent architectures
if ! [ "$(uname -m)" == "x86_64" ];then
mkdir -p /lib64
apt install -y qemu-user-static
wget -q "https://github.com/The-Bds-Maneger/external_files/raw/main/Linux/libs_amd64.zip" -O /tmp/libries.zip
unzip -o /tmp/libries.zip -d /
rm -rfv /tmp/libries.zip
fi
# Install openjdk
case "$(apt search openjdk)" in
*openjdk-17* ) apt install -y openjdk-17*;;
*openjdk-11* ) apt install -y openjdk-11*;;
* ) echo "No openjdk version found, skipping";;
esac
# Setup non root user
setup_user() {
useradd -m -p "$(perl -e 'print crypt($ARGV[0], "password")' "LucaA1113ba21")" "thebds"
addgroup thebds sudo
addgroup thebds root
usermod --shell /usr/bin/zsh thebds;
echo "thebds ALL=(ALL:ALL) NOPASSWD: ALL" >> /etc/sudoers
}
# Remove Unnecessary Packages
apt autoremove -y
# Clean up apt cache
apt clean -y
# Remove Unnecessary Files
rm -rf /var/lib/apt/lists/* /root/.gnupg /tmp/*
# Sucessfully installed
exit 0

View File

@ -1,13 +0,0 @@
#!/usr/bin/env node
const path = require("path");
process.env.Docker_Root = path.resolve(__dirname, "../");
const Docker = require("docker-run_build");
Docker.Build().then(() => {
Docker.Run().catch((e) => {
console.log(e);
process.exit(2);
});
}).catch(e => {
console.log(e);
process.exit(1);
});

View File

@ -1,28 +0,0 @@
const child_process = require("child_process");
const fs = require("fs");
const path = require("path");
const cli_color = require("cli-color");
async function Render() {
// Fetch
if (typeof fetch === "undefined") global.fetch = (await import("node-fetch")).default;
fetch("https://registry.npmjs.org/@the-bds-maneger/core").then(res => res.json()).then(data => {
data.versions = Object.getOwnPropertyNames(data.versions).filter(version => /[0-9]+\.[0-9][0-9][0-9]/.test(version) && version !== data["dist-tags"].dev && version !== data["dist-tags"].latest)
fs.writeFileSync(path.resolve(__dirname, "Releases.json"), JSON.stringify(data, null, 2));
const Package = require("../package.json");
data.versions.map(version => {
const cmd = `npm unpublish ${Package.name}@${version}`;
console.log(cli_color.yellow(cmd));
try {
child_process.execSync(cmd).toString()
console.log(cli_color.green(`Sucess to remove ${Package.name}@${version}`, "\n"));
return cmd;
} catch (e) {
console.log(cli_color.red(`Failed to remove package: ${Package.name}@${version}`), "\n");
return version;
}
});
fs.writeFileSync(path.resolve(__dirname, "Releases.json"), JSON.stringify(data, null, 2));
});
}
Render();

View File

@ -1,4 +0,0 @@
const version = require("../package.json").version;
const ActionsCore = require("@actions/core");
console.log(version);
ActionsCore.exportVariable("BdsCoreVersion", version);

View File

@ -1,19 +0,0 @@
(async ()=>{
try {
const bds = require("../../index");
await bds.download("latest", true);
console.log("Api:", bds.api());
console.log("Backup:", bds.backup());
console.log("Detect Server:", bds.detect());
console.log("Kill Server:", bds.kill());
console.log("Get Config:", bds.get_config());
console.log("Start:", bds.start());
setTimeout(() => {
console.log("Kill Server:", bds.kill());
setTimeout(() => process.exit(0), 1000);
}, 1 * 30 * 1000);
} catch (err) {
console.log("Detect Error:", err);
process.exit(1)
}
})()

View File

@ -1,10 +1,5 @@
node_modules/
Docker/
!Docker/root_path
.git/
Docker.sh
BuildRunDocker.js
docker_config.json
*.log
Test
test

View File

@ -1,2 +0,0 @@
test/**
Docker/

View File

@ -1,6 +0,0 @@
const fs = require('fs');
const Package_JSon = JSON.parse(fs.readFileSync(process.cwd()+'/package.json', 'utf8'));
const run_ID = process.env.RunID || "1111111111111111111111111111111111111";
Package_JSon.version = `${run_ID.slice(0, 2)}.${run_ID.slice(3, 6)}.${run_ID.slice(7, 11)}`;
fs.writeFileSync(process.cwd()+'/package.json', JSON.stringify(Package_JSon, null, 2));
console.log(Package_JSon.version);

View File

@ -1,10 +1,10 @@
version: 2
updates:
- package-ecosystem: "npm"
directory: "/"
- package-ecosystem: npm
directory: /
schedule:
interval: "daily"
- package-ecosystem: "github-actions"
directory: "/"
interval: daily
- package-ecosystem: github-actions
directory: /
schedule:
interval: "daily"
interval: daily

View File

@ -1,31 +1,10 @@
name: Docker And Node Test
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
CodeQL:
name: Analyze
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
languages: "javascript"
- name: Autobuild
uses: github/codeql-action/autobuild@v1
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
Node:
runs-on: ubuntu-latest
strategy:
@ -42,10 +21,16 @@ jobs:
with:
node-version: ${{ matrix.node-version }}
- name: Edit Version
env:
RunID: ${{ github.run_id }}
run: node .github/ChangeVersion.js
- name: Edit Version to next release
if: github.event_name != 'release'
shell: node {0}
run: |
const fs = require("fs");
const JsonPackage = JSON.parse(fs.readFileSync(process.cwd()+"/package.json", "utf8"));
const run_ID = "${{ github.run_id }}";
JsonPackage.version = `${run_ID.slice(0, 2)}.${run_ID.slice(3, 6)}.${run_ID.slice(7, 11)}`;
fs.writeFileSync(process.cwd()+"/package.json", JSON.stringify(JsonPackage, null, 2));
console.log("New Version to Package:", JsonPackage.version);
- name: Install node depedencies
run: npm install --no-save

View File

@ -1,107 +0,0 @@
name: Publish dev npm package and Docker Image
on:
push:
branches:
- main
env:
DOCKER_ARCH: linux/amd64,linux/arm64,linux/arm/v7
jobs:
CodeQL:
name: Analyze
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
languages: "javascript"
- name: Autobuild
uses: github/codeql-action/autobuild@v1
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
npm:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@master
- name: Npm and Node Setup
uses: actions/setup-node@v2.5.0
with:
node-version: 16.x
registry-url: https://registry.npmjs.org/
- name: Edit Version
env:
RunID: ${{ github.run_id }}
run: node .github/ChangeVersion.js
- name: Install Packages
run: npm install
- name: Install node depedencies
run: npm run esm_module
- name: NPM Publish
run: npm publish --tag dev
env:
NODE_AUTH_TOKEN: '${{ secrets.NPM_ORG_TOKEN }}'
DockerImage:
needs:
- npm
runs-on: ubuntu-latest
name: Build Docker Image to Bds Core and Bds Base
steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: checkout
uses: actions/checkout@master
- name: Install Node Depedencies
run: npm install --no-save -d
- name: Install node depedencies
run: npm run esm_module
- name: Get And Export Release Version
shell: node -p '{0}'
run: |
const version = require("./package.json").version;
const ActionsCore = require("@actions/core");
console.log(version);
ActionsCore.exportVariable("BdsCoreVersion", version);
- name: Build Docker image (Bds Maneger Base)
uses: docker/build-push-action@v2
with:
push: true
target: bdsbase
tags: ghcr.io/the-bds-maneger/base:main
platforms: ${{ env.DOCKER_ARCH }}
- name: Build Docker image (Bds Maneger core)
uses: docker/build-push-action@v2
with:
push: true
target: bdscore
cache-from: ghcr.io/the-bds-maneger/base:main
tags: ghcr.io/the-bds-maneger/core:main
platforms: ${{ env.DOCKER_ARCH }}

View File

@ -1,83 +0,0 @@
name: Publish Releases
on:
release:
types:
- created
env:
DOCKER_ARCH: linux/amd64,linux/arm64,linux/arm/v7
jobs:
npm:
runs-on: ubuntu-latest
if: ${{ github.actor }} == ${{ github.repository_owner }} && (contains('tag', ${{ github.ref }}) && contains('v', ${{ github.ref }}) || contains('V', ${{ github.ref }}))
steps:
- uses: actions/checkout@master
- uses: actions/setup-node@v2.5.0
with:
node-version: 16.x
registry-url: https://registry.npmjs.org/
- name: Install Depedencies
run: npm install --no-save
- name: Install node depedencies
run: npm run esm_module
- name: Publish
continue-on-error: true
run: npm publish
env:
NODE_AUTH_TOKEN: '${{ secrets.NPM_ORG_TOKEN }}'
- name: Remove Dev Versions
run: npm run cirelease
env:
NODE_AUTH_TOKEN: '${{ secrets.NPM_ORG_TOKEN }}'
DockerImage:
runs-on: ubuntu-latest
name: Build Docker Image to Bds Core and Bds Base
steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: checkout
uses: actions/checkout@master
- name: Install Node Depedencies
run: npm install --no-save -d
- name: Get And Export Release Version
run: node .Build/SetCIEnvs.js
- name: Build Docker image (Bds Maneger Base)
uses: docker/build-push-action@v2
with:
push: true
target: bdsbase
tags: |
ghcr.io/the-bds-maneger/base:latest
ghcr.io/the-bds-maneger/base:${{ env.BdsCoreVersion }}
platforms: ${{ env.DOCKER_ARCH }}
- name: Build Docker image (Bds Maneger core)
uses: docker/build-push-action@v2
with:
push: true
target: bdscore
cache-from: ghcr.io/the-bds-maneger/base:latest
tags: |
ghcr.io/the-bds-maneger/core:latest
ghcr.io/the-bds-maneger/core:${{ env.BdsCoreVersion }}
platforms: ${{ env.DOCKER_ARCH }}

184
.github/workflows/root.yml vendored Normal file
View File

@ -0,0 +1,184 @@
name: "Publish Packages"
on:
push:
branches:
- main
release:
types:
- released
jobs:
CodeQL:
name: Analyze
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
languages: "javascript"
- name: Autobuild
uses: github/codeql-action/autobuild@v1
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
test:
name: Test
runs-on: ubuntu-latest
strategy:
matrix:
node_version:
- 15.x
- 16.x
steps:
- name: Checkout Code
uses: actions/checkout@v2
- name: Setup Node.JS and NPM
uses: actions/setup-node@v2.5.0
with:
registry-url: https://registry.npmjs.org/
node-version: ${{ matrix.node_version }}
- name: Install Node Dependencies
run: npm ci
- name: Test
run: npm test
npm:
name: Npm Publish
runs-on: ubuntu-latest
needs: [test]
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_ORG_TOKEN }}
steps:
- name: Checkout Code
uses: actions/checkout@v2
- name: Setup Node.JS and NPM
uses: actions/setup-node@v2.5.0
with:
node-version: 16.x
registry-url: https://registry.npmjs.org/
- name: Edit Version to next release
if: github.event_name != 'release'
shell: node {0}
run: |
const fs = require("fs");
const JsonPackage = JSON.parse(fs.readFileSync(process.cwd()+"/package.json", "utf8"));
const run_ID = "${{ github.run_id }}";
JsonPackage.version = `${run_ID.slice(0, 2)}.${run_ID.slice(3, 6)}.${run_ID.slice(7, 11)}`;
fs.writeFileSync(process.cwd()+"/package.json", JSON.stringify(JsonPackage, null, 2));
console.log("New Version to Package:", JsonPackage.version);
- name: Install Node Dependencies
run: npm install -d
- name: ESM Modules
run: npm run esm_module
- name: Remove Dev Version
if: github.event_name == 'release'
shell: node {0}
run: |
const child_process = require("child_process");
const fs = require("fs");
const path = require("path");
const cli_color = require("cli-color");
(async function() {
global.fetch = (await import("node-fetch")).default;
fetch("https://registry.npmjs.org/@the-bds-maneger/core").then(res => res.json()).then(data => {
data.versions = Object.getOwnPropertyNames(data.versions).filter(version => /[0-9]+\.[0-9][0-9][0-9]/.test(version) && version !== data["dist-tags"].dev && version !== data["dist-tags"].latest)
fs.writeFileSync(path.resolve(__dirname, "Releases.json"), JSON.stringify(data, null, 2));
const Package = require("../package.json");
data.versions.map(version => {
const cmd = `npm unpublish ${Package.name}@${version}`;
console.log(cli_color.yellow(cmd));
try {
child_process.execSync(cmd).toString()
console.log(cli_color.green(`Sucess to remove ${Package.name}@${version}`, "\n"));
return cmd;
} catch (e) {
console.log(cli_color.red(`Failed to remove package: ${Package.name}@${version}`), "\n");
return version;
}
});
fs.writeFileSync(path.resolve(__dirname, "Releases.json"), JSON.stringify(data, null, 2));
});
})();
- name: Publish Package
run: |
if [[ "${{ github.event_name }}" == "release" ]];then
npm publish
else
npm publish --tag next
fi
docker:
runs-on: ubuntu-latest
name: Publish Docker Image
needs: [test]
steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Checkout Code
uses: actions/checkout@v2
- name: Edit Version to next release
if: github.event_name != 'release'
shell: node {0}
run: |
const fs = require("fs");
const JsonPackage = JSON.parse(fs.readFileSync(process.cwd()+"/package.json", "utf8"));
const run_ID = "${{ github.run_id }}";
JsonPackage.version = `${run_ID.slice(0, 2)}.${run_ID.slice(3, 6)}.${run_ID.slice(7, 11)}`;
fs.writeFileSync(process.cwd()+"/package.json", JSON.stringify(JsonPackage, null, 2));
console.log("New Version to Package:", JsonPackage.version);
- name: Get Version and Set in Env
shell: node {0}
run: |
const { version } = require("../package.json");
const ActionsCore = require("@actions/core");
console.log(version);
ActionsCore.exportVariable("CoreVersion", version);
- name: Install Node Dependencies
if: github.event_name != 'release'
run: npm ci
- name: Build Bds Maneger Core (Release)
uses: docker/build-push-action@v2
if: github.event_name == 'release'
with:
push: true
tags: |
ghcr.io/the-bds-maneger/core:latest
ghcr.io/the-bds-maneger/core:${{ env.CoreVersion }}
platforms: linux/amd64,linux/arm64,linux/arm/v7
- name: Build Bds Maneger Core (Main)
uses: docker/build-push-action@v2
if: github.event_name != 'release'
with:
push: true
tags: ghcr.io/the-bds-maneger/core:nightly
platforms: linux/amd64,linux/arm64,linux/arm/v7

View File

@ -1,2 +0,0 @@
include:
- .gitlab/workflows/*.yml

View File

@ -1,13 +0,0 @@
terminal:
image: bdsmaneger/core:latest
services:
- docker:dind
before_script:
- apt update && apt install -y curl &> /dev/null
- curl https://get.docker.com | bash -
variables:
DOCKER_TLS_CERTDIR: ""
DOCKER_DRIVER: overlay2
DOCKER_HOST: tcp://docker:2375
DEVELOP_WEBIDE: true
script: sleep 80

View File

@ -1,19 +0,0 @@
Docker:
image: ubuntu:latest
variables:
DOCKER_TLS_CERTDIR: ""
DOCKER_DRIVER: overlay2
DOCKER_HOST: tcp://docker:2375
services:
- docker:dind
before_script:
- |
apt update && apt install -y curl &> /dev/null
curl https://get.docker.com | bash - &> /dev/null
docker info
docker run --privileged --rm tonistiigi/binfmt --install all
docker run --privileged --rm multiarch/qemu-user-static --reset -p yes
docker buildx create --name multiarch --driver docker-container --use
docker buildx inspect --bootstrap
script:
- docker buildx build -t bdsmaneger/maneger:latest --platform=linux/amd64,linux/arm64,linux/arm/v7 .

View File

@ -11,7 +11,8 @@
# test files
*.test
*test*.js*
*test*.*js
*Test*.*js
test/
Test/

View File

@ -1,16 +1,28 @@
# Setup Bds Manerger Project Docker Base
FROM debian:testing AS bdsbase
FROM ubuntu:latest
USER root
ENV DEBIAN_FRONTEND="noninteractive" DOCKER_IMAGE="true"
# Copy Docker Files
COPY .Build/Docker/* /tmp
# Install Core Packages
RUN apt update && apt install -y curl wget git sudo unzip zip jq python3 xz-utils tar
# Configure BASE
RUN bash /tmp/Configure.sh
# Install Node.js
RUN NODEVERSION=$(curl -sL https://api.github.com/repos/nodejs/node/releases | grep tag_name | cut -d '"' -f 4 | sort -V | tail -n 1) && \
case $(uname -m) in x86_64 ) wget -q "https://nodejs.org/download/release/$NODEVERSION/node-$NODEVERSION-linux-x64.tar.xz" -O /tmp/node.tar.xz;;aarch64 ) wget -q "https://nodejs.org/download/release/$NODEVERSION/node-$NODEVERSION-linux-arm64.tar.xz" -O /tmp/node.tar.xz;;armv7l ) wget -q "https://nodejs.org/download/release/$NODEVERSION/node-$NODEVERSION-linux-armv7l.tar.xz" -O /tmp/node.tar.xz;;ppc64el ) wget -q "https://nodejs.org/download/release/$NODEVERSION/node-$NODEVERSION-linux-ppc64le.tar.xz" -O /tmp/node.tar.xz;;s390x ) wget -q "https://nodejs.org/download/release/$NODEVERSION/node-$NODEVERSION-linux-s390x.tar.xz" -O /tmp/node.tar.xz;;*) echo "Unsupported architecture"; exit 1;;esac && \
mkdir /tmp/Node && \
tar -xJf /tmp/node.tar.xz -C /tmp/Node && \
rm -rf /tmp/node.tar.xz && \
cp -rf /tmp/Node/*/* /usr && \
rm -rf /tmp/Node
# Setup bdsmaneger/core
FROM bdsbase AS bdscore
# Update NPM
RUN npm -g install npm@latest
# Install external Libries to ARM64
ARG LibrieZip="https://github.com/The-Bds-Maneger/external_files/raw/main/Linux/libs_amd64.zip"
RUN if ! [ "$(uname -m)" == "x86_64" ];then mkdir -p /lib64;apt install -y qemu-user-static;wget -q "${LibrieZip}" -O /tmp/libries.zip;unzip -o /tmp/libries.zip -d /;rm -rfv /tmp/libries.zip; fi
# Install Java
RUN case "$(apt search openjdk)" in *openjdk-17* ) apt install -y openjdk-17*;; *openjdk-11* ) apt install -y openjdk-11*;; * ) echo "No openjdk version found, skipping";;esac
# Create Volume to Storage Server And Config
VOLUME [ "/root/bds_core" ]
@ -24,7 +36,7 @@ ENV PLAYERS="5" \
ENABLE_COMMANDS="false" \
ACCOUNT="false" \
SERVER="bedrock" \
UPDATE_SERVER="true"
SERVER_VERSION="true"
# Bds Maneger Core required ports
EXPOSE 19132/udp 19133/udp 1932/tcp
@ -38,8 +50,7 @@ RUN npm install
# Copy BdsManger Core
COPY ./ ./
RUN chmod a+x -v bin/*
RUN npm run esm_module
RUN chmod a+x -vR bin/*
# Set Entrypint
ENTRYPOINT [ "node", "./bin/Docker.js" ]

View File

@ -1,80 +1,50 @@
#!/usr/bin/env node
process.env.BDS_DOCKER_IMAGE = true;
const fs = require("fs");
const BdsCore = require("../index");
const { GetPlatform } = require("../src/lib/BdsSettings");
const { CronJob } = require("cron");
const { PlatformVersionsV2 } = require("../src/BdsServersDownload");
// Get Current Tokens and Show in the console
function ShowToken() {
const TokenFilePath = BdsCore.BdsToken.TokenFile;
let Tokens = 1
if (fs.existsSync(TokenFilePath)) {
[...JSON.parse(fs.readFileSync(TokenFilePath, "utf8"))].slice(0, 5).forEach(token => {console.log(Tokens+":", "Bds API Token:", token.Token); Tokens++});
async function UpdateInstallServer(OldServerRunner, pre_stop = () => {}) {
if (process.env.SERVER_VERSION === "true") {
if (typeof pre_stop === "function") await pre_stop();
if (typeof OldServerRunner === "function") {
OldServerRunner.stop();
}
// Create Backup and Write
(BdsCore.BdsBackup.CreateBackup()).write_file()
const ServerDownloadResult = await BdsCore.BdsDownload("latest");
if (ServerDownloadResult.skip) {
console.log("Server Update Sucess, Version:", ServerDownloadResult.version);
}
return StartServer();
} else {
console.log(Tokens+":", "Bds API Token:", (BdsCore.BdsToken.CreateToken()).Token);
await BdsCore.BdsDownload(process.env.SERVER_VERSION);
}
}
async function CheckAndUpdateServer() {
const LatestVersion = (await BdsCore.BdsDownload.PlatformVersionsV2()).latest;
const LocalVersion = BdsCore.BdsSettings.GetServerVersion()[GetPlatform()];
if (!LocalVersion) {
console.log("Server is not installed, starting server implementation");
const __InitInstall = await BdsCore.BdsDownload(true);
console.log("Installed Version:", __InitInstall.version, `Release Version: ${__InitInstall.data.getDate()}/${__InitInstall.data.getMonth()}/${__InitInstall.data.getFullYear()}`);
} else if (LocalVersion !== LatestVersion) {
console.log("Server is out of date, starting server implementation");
const __UpdateInstall = await BdsCore.BdsDownload(true);
console.log("Updated Version:", __UpdateInstall.version, `Release Version: ${__UpdateInstall.data.getDate()}/${__UpdateInstall.data.getMonth()}/${__UpdateInstall.data.getFullYear()}`);
function StartServer() {
let IsUpdate = false;
const Server = BdsCore.BdsManegerServer.StartServer();
Server.on("log", data => {
if (process.env.PULLIMAGE) {
const { value: DataToTest, regex: IsRegex } = BdsCore.ExtraJSON.Extra.StartedServer[BdsCore.BdsSettings.GetPlatform()];
if (IsRegex) {
if (RegExp(DataToTest, "gi").test(data)) {
return Server.stop();
}
}
async function StartServer(){
ShowToken();
console.log("The entire log can be accessed via the api and/or the docker log");
const ServerStarted = BdsCore.BdsManegerServer.StartServer();
BdsCore.BdsManegerAPI.api();
ServerStarted.on("log", a => process.stdout.write(a));
ServerStarted.on("exit", code => process.exit(code));
if (process.env.PULL_REQUEST === "true") {
console.log((require("cli-color")).red("Pull Request Actived 1 Min to exit"));
setTimeout(() => {
ServerStarted.stop();
}, 1 * 60 * 1000)
}
new CronJob("0 */1 * * *", async () => {
try {
const CurrentLocalVersion = BdsCore.BdsSettings.GetServerVersion()[GetPlatform()],
CurrentRemoteVersion = (await PlatformVersionsV2(GetPlatform())).latest;
if (CurrentLocalVersion !== CurrentRemoteVersion) {
let currenttime = `Hello we are starting the server upgrade from version ${CurrentLocalVersion} to version ${CurrentRemoteVersion}, you have 20 seconds to exit the server`
console.log("Update Server:", currenttime);
ServerStarted.say(currenttime);
let countdown = 20;
while (countdown > 1) {
currenttime = `${countdown} seconds remaining to stop Server!`;
console.log(currenttime);
ServerStarted.say(currenttime);
countdown--;
await new Promise(resolve => setTimeout(resolve, 1000));
}
currenttime = "Stopping the server"
console.log(currenttime);
ServerStarted.say(currenttime);
await new Promise(resolve => setTimeout(resolve, 600));
ServerStarted.stop();
}
} catch (err) {
console.log(err);
} else return Server.stop();
}
return process.stdout.write(data)
});
Server.on("exit", code => {
if (!IsUpdate) process.exit(code);
});
new CronJob("*/1 * * * *", async () => {
console.log("Checking for updates...");
await UpdateInstallServer(Server, () => IsUpdate = true);
});
}
async function RenderCLI(){
await CheckAndUpdateServer();
function WriteServerConfig() {
const { DESCRIPTION, WORLD_NAME, GAMEMODE, DIFFICULTY, ACCOUNT, PLAYERS, SERVER, ENABLE_COMMANDS } = process.env;
BdsCore.BdsSettings.UpdatePlatform(SERVER || "bedrock");
const ServerConfig = {
@ -90,6 +60,10 @@ async function RenderCLI(){
portv6: 19133,
}
BdsCore.BdsServerSettings.config(ServerConfig);
await StartServer();
}
RenderCLI();
(async () => {
WriteServerConfig();
await UpdateInstallServer();
StartServer();
})();

View File

@ -3,7 +3,7 @@
// Load Root JSON
const BdsManegerCoreJSONs = {
Package: require("./package.json"),
Extra: require("./BdsManegerInfo.json")
Extra: require("./src/BdsManegerInfo.json")
};
// Bds Maneger Core Version

View File

@ -1,7 +1,7 @@
// Mount Module Oject
const ModuleExport = {}
import package_json from "./package.json";
import BdsManegerInfo from "./BdsManegerInfo.json";
import BdsManegerInfo from "./src/BdsManegerInfo.json";
const BdsManegerCoreJSONs = {
Package: package_json,

213
package-lock.json generated
View File

@ -15,8 +15,8 @@
"android"
],
"dependencies": {
"@azure/storage-blob": "^12.6.0",
"@iarna/toml": "^2.2.5",
"@the-bds-maneger/clouds_uploads": "^0.1.0",
"adm-zip": "^0.5.1",
"body-parser": "^1.19.0",
"cli-color": "^2.0.0",
@ -27,13 +27,11 @@
"express-fileupload": "^1.2.1",
"express-prettify": "^0.1.1",
"express-rate-limit": "^5.5.1",
"googleapis": "^92.0.0",
"inquirer": "^8.1.5",
"js-yaml": "^4.1.0",
"minimist": "^1.2.5",
"node-cron": "^3.0.0",
"node-fetch": "^3.0.0",
"oci-sdk": "^2.0.0",
"ora": "^6.0.1",
"properties-to-json": "^0.2.1",
"request-ip": "^2.1.3",
@ -103,9 +101,9 @@
}
},
"node_modules/@azure/core-http": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/@azure/core-http/-/core-http-2.2.0.tgz",
"integrity": "sha512-DCXm8OTNhPxErNvwuNgd9r/W+LjMrHHNc9/q4QgIOpCaoBvpJd1O5Nl2gbAhrwfiwmEBNWHMeGoe5+g3Lx2H/A==",
"version": "2.2.2",
"resolved": "https://registry.npmjs.org/@azure/core-http/-/core-http-2.2.2.tgz",
"integrity": "sha512-V1DdoO9V/sFimKpdWoNBgsE+QUjQgpXYnxrTdUp5RyhsTJjvEVn/HKmTQXIHuLUUo6IyIWj+B+Dg4VaXse9dIA==",
"dependencies": {
"@azure/abort-controller": "^1.0.0",
"@azure/core-asynciterator-polyfill": "^1.0.0",
@ -128,9 +126,9 @@
}
},
"node_modules/@azure/core-http/node_modules/node-fetch": {
"version": "2.6.5",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.5.tgz",
"integrity": "sha512-mmlIVHJEu5rnIxgEgez6b9GgWXbkZj5YZ7fx+2r94a2E+Uirsp6HsPTPlomfdHtpt/B0cdKviwkoaM6pyvUOpQ==",
"version": "2.6.6",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.6.tgz",
"integrity": "sha512-Z8/6vRlTUChSdIgMa51jxQ4lrw/Jy5SOW10ObaA47/RElsAN2c5Pn8bTgFGWn/ibwzXTE8qwr1Yzx28vsecXEA==",
"dependencies": {
"whatwg-url": "^5.0.0"
},
@ -139,9 +137,9 @@
}
},
"node_modules/@azure/core-lro": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/@azure/core-lro/-/core-lro-2.2.0.tgz",
"integrity": "sha512-TJo95eNT1dwYOPCb0m1C2zyxVlHuRRkKGeg9TKu8XMF2qh4v6c1weD63r9RVIrLdHdnSqS0n6PTXBpWoB8NqMw==",
"version": "2.2.1",
"resolved": "https://registry.npmjs.org/@azure/core-lro/-/core-lro-2.2.1.tgz",
"integrity": "sha512-HE6PBl+mlKa0eBsLwusHqAqjLc5n9ByxeDo3Hz4kF3B1hqHvRkBr4oMgoT6tX7Hc3q97KfDctDUon7EhvoeHPA==",
"dependencies": {
"@azure/abort-controller": "^1.0.0",
"@azure/core-tracing": "1.0.0-preview.13",
@ -177,14 +175,14 @@
}
},
"node_modules/@azure/logger": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/@azure/logger/-/logger-1.0.2.tgz",
"integrity": "sha512-YZNjNV0vL3nN2nedmcjQBcpCTo3oqceXmgiQtEm6fLpucjRZyQKAQruhCmCpRlB1iykqKJJ/Y8CDmT5rIE6IJw==",
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/@azure/logger/-/logger-1.0.3.tgz",
"integrity": "sha512-aK4s3Xxjrx3daZr3VylxejK3vG5ExXck5WOHDJ8in/k9AqlfIyFMMT1uG7u8mNjX+QRILTIn0/Xgschfh/dQ9g==",
"dependencies": {
"tslib": "^2.0.0"
"tslib": "^2.2.0"
},
"engines": {
"node": ">=8.0.0"
"node": ">=12.0.0"
}
},
"node_modules/@azure/storage-blob": {
@ -2231,6 +2229,21 @@
"node": ">=6"
}
},
"node_modules/@the-bds-maneger/clouds_uploads": {
"version": "0.1.0",
"resolved": "https://registry.npmjs.org/@the-bds-maneger/clouds_uploads/-/clouds_uploads-0.1.0.tgz",
"integrity": "sha512-RART4i5EIZPp4vlPefPhnnAPtVY19x9Asl7Bx0Ol3O/ZhNR06TXRtJ3bzJFPGLkMQ4guhSYiClo6gNH0WMiTLg==",
"dependencies": {
"@azure/storage-blob": "^12.8.0",
"body-parser": "^1.19.0",
"cors": "^2.8.5",
"express": "^4.17.1",
"express-rate-limit": "^5.5.1",
"googleapis": "^92.0.0",
"oci-sdk": "^2.9.0",
"open": "^8.4.0"
}
},
"node_modules/@types/component-emitter": {
"version": "1.2.11",
"resolved": "https://registry.npmjs.org/@types/component-emitter/-/component-emitter-1.2.11.tgz",
@ -2605,9 +2618,9 @@
}
},
"node_modules/agent-base/node_modules/debug": {
"version": "4.3.2",
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.2.tgz",
"integrity": "sha512-mOp8wKcvj7XxC78zLgw/ZA+6TSgkoE2C/ienthhRD298T7UNwAg9diBpLRxC0mOezLl4B0xV7M0cCO6P/O0Xhw==",
"version": "4.3.3",
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.3.tgz",
"integrity": "sha512-/zxw5+vh1Tfv+4Qn7a5nsbcJKPaSvCDhojn6FEl9vupwK2VCSDtEiEtqr8DFtzYFOdz63LBkxec7DYuc2jon6Q==",
"dependencies": {
"ms": "2.1.2"
},
@ -3930,6 +3943,14 @@
"integrity": "sha512-0ISdNousHvZT2EiFlZeZAHBUvSxmKswVCEf8hW7KWgG4a8MVEu/3Vb6uWYozkjylyCxe0JBIiRB1jV45S70WVQ==",
"dev": true
},
"node_modules/define-lazy-prop": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/define-lazy-prop/-/define-lazy-prop-2.0.0.tgz",
"integrity": "sha512-Ds09qNh8yw3khSjiJjiUInaGX9xlqZDY7JVryGxdxV7NPeuqQfplOpQ66yJFZut3jLa5zOwkXw1g9EI2uKh4Og==",
"engines": {
"node": ">=8"
}
},
"node_modules/define-properties": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.1.3.tgz",
@ -5143,9 +5164,9 @@
}
},
"node_modules/gaxios/node_modules/node-fetch": {
"version": "2.6.5",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.5.tgz",
"integrity": "sha512-mmlIVHJEu5rnIxgEgez6b9GgWXbkZj5YZ7fx+2r94a2E+Uirsp6HsPTPlomfdHtpt/B0cdKviwkoaM6pyvUOpQ==",
"version": "2.6.6",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.6.tgz",
"integrity": "sha512-Z8/6vRlTUChSdIgMa51jxQ4lrw/Jy5SOW10ObaA47/RElsAN2c5Pn8bTgFGWn/ibwzXTE8qwr1Yzx28vsecXEA==",
"dependencies": {
"whatwg-url": "^5.0.0"
},
@ -5327,9 +5348,9 @@
}
},
"node_modules/google-auth-library": {
"version": "7.9.2",
"resolved": "https://registry.npmjs.org/google-auth-library/-/google-auth-library-7.9.2.tgz",
"integrity": "sha512-HjxbJt660a+YUTYAgYor87JCuBZvjUSNBExk4bXTEaMuCn8IHSDeHmFxKqThuDPrLCiKJp8blk/Ze8f7SI4N6g==",
"version": "7.10.2",
"resolved": "https://registry.npmjs.org/google-auth-library/-/google-auth-library-7.10.2.tgz",
"integrity": "sha512-M37o9Kxa/TLvOLgF71SXvLeVEP5sbSTmKl1zlIgl72SFy5PtsU3pOdu8G8MIHHpQ3/NZabDI8rQkA9DvQVKkPA==",
"dependencies": {
"arrify": "^2.0.0",
"base64-js": "^1.3.0",
@ -5597,9 +5618,9 @@
}
},
"node_modules/https-proxy-agent/node_modules/debug": {
"version": "4.3.2",
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.2.tgz",
"integrity": "sha512-mOp8wKcvj7XxC78zLgw/ZA+6TSgkoE2C/ienthhRD298T7UNwAg9diBpLRxC0mOezLl4B0xV7M0cCO6P/O0Xhw==",
"version": "4.3.3",
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.3.tgz",
"integrity": "sha512-/zxw5+vh1Tfv+4Qn7a5nsbcJKPaSvCDhojn6FEl9vupwK2VCSDtEiEtqr8DFtzYFOdz63LBkxec7DYuc2jon6Q==",
"dependencies": {
"ms": "2.1.2"
},
@ -5940,6 +5961,20 @@
"node": ">=0.10.0"
}
},
"node_modules/is-docker": {
"version": "2.2.1",
"resolved": "https://registry.npmjs.org/is-docker/-/is-docker-2.2.1.tgz",
"integrity": "sha512-F+i2BKsFrH66iaUFc0woD8sLy8getkwTwtOBjvs56Cx4CgJDeKQeqfz8wAYiSb8JOprWhHH5p77PbmYCvvUuXQ==",
"bin": {
"is-docker": "cli.js"
},
"engines": {
"node": ">=8"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/is-extendable": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/is-extendable/-/is-extendable-1.0.1.tgz",
@ -6119,6 +6154,17 @@
"node": ">=0.10.0"
}
},
"node_modules/is-wsl": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/is-wsl/-/is-wsl-2.2.0.tgz",
"integrity": "sha512-fKzAra0rGJUUBwGBgNkHZuToZcn+TtXHpeCgmkMJMMYx1sQDYaCSyjJBSCa2nH1DGm7s3n1oBnohoVTBaN7Lww==",
"dependencies": {
"is-docker": "^2.0.0"
},
"engines": {
"node": ">=8"
}
},
"node_modules/is-yarn-global": {
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/is-yarn-global/-/is-yarn-global-0.3.0.tgz",
@ -8391,6 +8437,22 @@
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/open": {
"version": "8.4.0",
"resolved": "https://registry.npmjs.org/open/-/open-8.4.0.tgz",
"integrity": "sha512-XgFPPM+B28FtCCgSb9I+s9szOC1vZRSwgWsRUA5ylIxRTgKozqjOCrVOqGsYABPYK5qnfqClxZTFBa8PKt2v6Q==",
"dependencies": {
"define-lazy-prop": "^2.0.0",
"is-docker": "^2.1.1",
"is-wsl": "^2.2.0"
},
"engines": {
"node": ">=12"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/opossum": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/opossum/-/opossum-5.0.1.tgz",
@ -10906,9 +10968,9 @@
}
},
"@azure/core-http": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/@azure/core-http/-/core-http-2.2.0.tgz",
"integrity": "sha512-DCXm8OTNhPxErNvwuNgd9r/W+LjMrHHNc9/q4QgIOpCaoBvpJd1O5Nl2gbAhrwfiwmEBNWHMeGoe5+g3Lx2H/A==",
"version": "2.2.2",
"resolved": "https://registry.npmjs.org/@azure/core-http/-/core-http-2.2.2.tgz",
"integrity": "sha512-V1DdoO9V/sFimKpdWoNBgsE+QUjQgpXYnxrTdUp5RyhsTJjvEVn/HKmTQXIHuLUUo6IyIWj+B+Dg4VaXse9dIA==",
"requires": {
"@azure/abort-controller": "^1.0.0",
"@azure/core-asynciterator-polyfill": "^1.0.0",
@ -10928,9 +10990,9 @@
},
"dependencies": {
"node-fetch": {
"version": "2.6.5",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.5.tgz",
"integrity": "sha512-mmlIVHJEu5rnIxgEgez6b9GgWXbkZj5YZ7fx+2r94a2E+Uirsp6HsPTPlomfdHtpt/B0cdKviwkoaM6pyvUOpQ==",
"version": "2.6.6",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.6.tgz",
"integrity": "sha512-Z8/6vRlTUChSdIgMa51jxQ4lrw/Jy5SOW10ObaA47/RElsAN2c5Pn8bTgFGWn/ibwzXTE8qwr1Yzx28vsecXEA==",
"requires": {
"whatwg-url": "^5.0.0"
}
@ -10938,9 +11000,9 @@
}
},
"@azure/core-lro": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/@azure/core-lro/-/core-lro-2.2.0.tgz",
"integrity": "sha512-TJo95eNT1dwYOPCb0m1C2zyxVlHuRRkKGeg9TKu8XMF2qh4v6c1weD63r9RVIrLdHdnSqS0n6PTXBpWoB8NqMw==",
"version": "2.2.1",
"resolved": "https://registry.npmjs.org/@azure/core-lro/-/core-lro-2.2.1.tgz",
"integrity": "sha512-HE6PBl+mlKa0eBsLwusHqAqjLc5n9ByxeDo3Hz4kF3B1hqHvRkBr4oMgoT6tX7Hc3q97KfDctDUon7EhvoeHPA==",
"requires": {
"@azure/abort-controller": "^1.0.0",
"@azure/core-tracing": "1.0.0-preview.13",
@ -10967,11 +11029,11 @@
}
},
"@azure/logger": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/@azure/logger/-/logger-1.0.2.tgz",
"integrity": "sha512-YZNjNV0vL3nN2nedmcjQBcpCTo3oqceXmgiQtEm6fLpucjRZyQKAQruhCmCpRlB1iykqKJJ/Y8CDmT5rIE6IJw==",
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/@azure/logger/-/logger-1.0.3.tgz",
"integrity": "sha512-aK4s3Xxjrx3daZr3VylxejK3vG5ExXck5WOHDJ8in/k9AqlfIyFMMT1uG7u8mNjX+QRILTIn0/Xgschfh/dQ9g==",
"requires": {
"tslib": "^2.0.0"
"tslib": "^2.2.0"
}
},
"@azure/storage-blob": {
@ -12418,6 +12480,21 @@
"defer-to-connect": "^1.0.1"
}
},
"@the-bds-maneger/clouds_uploads": {
"version": "0.1.0",
"resolved": "https://registry.npmjs.org/@the-bds-maneger/clouds_uploads/-/clouds_uploads-0.1.0.tgz",
"integrity": "sha512-RART4i5EIZPp4vlPefPhnnAPtVY19x9Asl7Bx0Ol3O/ZhNR06TXRtJ3bzJFPGLkMQ4guhSYiClo6gNH0WMiTLg==",
"requires": {
"@azure/storage-blob": "^12.8.0",
"body-parser": "^1.19.0",
"cors": "^2.8.5",
"express": "^4.17.1",
"express-rate-limit": "^5.5.1",
"googleapis": "^92.0.0",
"oci-sdk": "^2.9.0",
"open": "^8.4.0"
}
},
"@types/component-emitter": {
"version": "1.2.11",
"resolved": "https://registry.npmjs.org/@types/component-emitter/-/component-emitter-1.2.11.tgz",
@ -12742,9 +12819,9 @@
},
"dependencies": {
"debug": {
"version": "4.3.2",
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.2.tgz",
"integrity": "sha512-mOp8wKcvj7XxC78zLgw/ZA+6TSgkoE2C/ienthhRD298T7UNwAg9diBpLRxC0mOezLl4B0xV7M0cCO6P/O0Xhw==",
"version": "4.3.3",
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.3.tgz",
"integrity": "sha512-/zxw5+vh1Tfv+4Qn7a5nsbcJKPaSvCDhojn6FEl9vupwK2VCSDtEiEtqr8DFtzYFOdz63LBkxec7DYuc2jon6Q==",
"requires": {
"ms": "2.1.2"
}
@ -13744,6 +13821,11 @@
"integrity": "sha512-0ISdNousHvZT2EiFlZeZAHBUvSxmKswVCEf8hW7KWgG4a8MVEu/3Vb6uWYozkjylyCxe0JBIiRB1jV45S70WVQ==",
"dev": true
},
"define-lazy-prop": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/define-lazy-prop/-/define-lazy-prop-2.0.0.tgz",
"integrity": "sha512-Ds09qNh8yw3khSjiJjiUInaGX9xlqZDY7JVryGxdxV7NPeuqQfplOpQ66yJFZut3jLa5zOwkXw1g9EI2uKh4Og=="
},
"define-properties": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.1.3.tgz",
@ -14693,9 +14775,9 @@
},
"dependencies": {
"node-fetch": {
"version": "2.6.5",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.5.tgz",
"integrity": "sha512-mmlIVHJEu5rnIxgEgez6b9GgWXbkZj5YZ7fx+2r94a2E+Uirsp6HsPTPlomfdHtpt/B0cdKviwkoaM6pyvUOpQ==",
"version": "2.6.6",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.6.tgz",
"integrity": "sha512-Z8/6vRlTUChSdIgMa51jxQ4lrw/Jy5SOW10ObaA47/RElsAN2c5Pn8bTgFGWn/ibwzXTE8qwr1Yzx28vsecXEA==",
"requires": {
"whatwg-url": "^5.0.0"
}
@ -14827,9 +14909,9 @@
}
},
"google-auth-library": {
"version": "7.9.2",
"resolved": "https://registry.npmjs.org/google-auth-library/-/google-auth-library-7.9.2.tgz",
"integrity": "sha512-HjxbJt660a+YUTYAgYor87JCuBZvjUSNBExk4bXTEaMuCn8IHSDeHmFxKqThuDPrLCiKJp8blk/Ze8f7SI4N6g==",
"version": "7.10.2",
"resolved": "https://registry.npmjs.org/google-auth-library/-/google-auth-library-7.10.2.tgz",
"integrity": "sha512-M37o9Kxa/TLvOLgF71SXvLeVEP5sbSTmKl1zlIgl72SFy5PtsU3pOdu8G8MIHHpQ3/NZabDI8rQkA9DvQVKkPA==",
"requires": {
"arrify": "^2.0.0",
"base64-js": "^1.3.0",
@ -15035,9 +15117,9 @@
},
"dependencies": {
"debug": {
"version": "4.3.2",
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.2.tgz",
"integrity": "sha512-mOp8wKcvj7XxC78zLgw/ZA+6TSgkoE2C/ienthhRD298T7UNwAg9diBpLRxC0mOezLl4B0xV7M0cCO6P/O0Xhw==",
"version": "4.3.3",
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.3.tgz",
"integrity": "sha512-/zxw5+vh1Tfv+4Qn7a5nsbcJKPaSvCDhojn6FEl9vupwK2VCSDtEiEtqr8DFtzYFOdz63LBkxec7DYuc2jon6Q==",
"requires": {
"ms": "2.1.2"
}
@ -15277,6 +15359,11 @@
"kind-of": "^6.0.2"
}
},
"is-docker": {
"version": "2.2.1",
"resolved": "https://registry.npmjs.org/is-docker/-/is-docker-2.2.1.tgz",
"integrity": "sha512-F+i2BKsFrH66iaUFc0woD8sLy8getkwTwtOBjvs56Cx4CgJDeKQeqfz8wAYiSb8JOprWhHH5p77PbmYCvvUuXQ=="
},
"is-extendable": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/is-extendable/-/is-extendable-1.0.1.tgz",
@ -15393,6 +15480,14 @@
"integrity": "sha512-eXK1UInq2bPmjyX6e3VHIzMLobc4J94i4AWn+Hpq3OU5KkrRC96OAcR3PRJ/pGu6m8TRnBHP9dkXQVsT/COVIA==",
"dev": true
},
"is-wsl": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/is-wsl/-/is-wsl-2.2.0.tgz",
"integrity": "sha512-fKzAra0rGJUUBwGBgNkHZuToZcn+TtXHpeCgmkMJMMYx1sQDYaCSyjJBSCa2nH1DGm7s3n1oBnohoVTBaN7Lww==",
"requires": {
"is-docker": "^2.0.0"
}
},
"is-yarn-global": {
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/is-yarn-global/-/is-yarn-global-0.3.0.tgz",
@ -17371,6 +17466,16 @@
"mimic-fn": "^2.1.0"
}
},
"open": {
"version": "8.4.0",
"resolved": "https://registry.npmjs.org/open/-/open-8.4.0.tgz",
"integrity": "sha512-XgFPPM+B28FtCCgSb9I+s9szOC1vZRSwgWsRUA5ylIxRTgKozqjOCrVOqGsYABPYK5qnfqClxZTFBa8PKt2v6Q==",
"requires": {
"define-lazy-prop": "^2.0.0",
"is-docker": "^2.1.1",
"is-wsl": "^2.2.0"
}
},
"opossum": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/opossum/-/opossum-5.0.1.tgz",

View File

@ -14,11 +14,9 @@
"scripts": {
"start": "node bin/bds_maneger.js -sk",
"test": "mocha --exit .test/*.js",
"ci": "node .Build/test/ci.js",
"esm_module": "cjs2esm",
"eslint": "eslint --debug --fix .",
"Docker": "docker-compose build && docker-compose up",
"cirelease": "node .Build/RemoveVersions.js"
"Docker": "docker-compose build && docker-compose up"
},
"bin": {
"bds_maneger": "bin/BdsManeger.js"
@ -53,8 +51,8 @@
"android"
],
"dependencies": {
"@azure/storage-blob": "^12.6.0",
"@iarna/toml": "^2.2.5",
"@the-bds-maneger/clouds_uploads": "^0.1.0",
"adm-zip": "^0.5.1",
"body-parser": "^1.19.0",
"cli-color": "^2.0.0",
@ -65,13 +63,11 @@
"express-fileupload": "^1.2.1",
"express-prettify": "^0.1.1",
"express-rate-limit": "^5.5.1",
"googleapis": "^92.0.0",
"inquirer": "^8.1.5",
"js-yaml": "^4.1.0",
"minimist": "^1.2.5",
"node-cron": "^3.0.0",
"node-fetch": "^3.0.0",
"oci-sdk": "^2.0.0",
"ora": "^6.0.1",
"properties-to-json": "^0.2.1",
"request-ip": "^2.1.3",

View File

@ -64,11 +64,13 @@ function CreateBackup() {
// Zip Buffer
const ZipBuffer = zip.toBuffer();
fs.writeFileSync(PathBackup, ZipBuffer, "binary");
return {
file_path: PathBackup,
Buffer: ZipBuffer,
file_name: ZipName,
write_file: () => {
fs.writeFileSync(PathBackup, ZipBuffer, "binary");
}
}
}

View File

@ -2,23 +2,16 @@ const child_process = require("child_process");
const fs = require("fs");
const path = require("path");
const { randomUUID } = require("crypto");
const { Backup } = require("./BdsBackup");
const BdsBackup = require("./BdsBackup");
const { CronJob } = require("cron");
const BdsSettings = require("../src/lib/BdsSettings");
const PlayerJson = require("./ManegerServer/Players_json");
const BasicCommands = require("./ManegerServer/BasicCommands");
const ServerSessions = {};
module.exports.GetSessions = () => ServerSessions;
module.exports.GetSessionsArray = () => Object.keys(ServerSessions).map(key => ServerSessions[key]);
const PlayersCallbacks = [];
module.exports.RegisterPlayerGlobalyCallbacks = function RegisterPlayerGlobalyCallbacks(callback){
PlayersCallbacks.push(callback);
}
module.exports.StartServer = function start() {
function StartServer() {
const commandExists = require("../src/lib/commandExist");
const io = require("./api").SocketIO;
const CurrentBdsPlatform = BdsSettings.GetPlatform();
@ -239,28 +232,26 @@ module.exports.StartServer = function start() {
return returnFuntion;
}
module.exports.CronBackups = BdsSettings.GetCronBackup().map(Crron => {
const Cloud_Backup = {
Azure: require("./clouds/Azure").Uploadbackups,
Driver: require("./clouds/GoogleDriver").Uploadbackups,
Oracle: require("./clouds/OracleCI").Uploadbackups,
}
//
return {
CronFunction: new CronJob(Crron.cron, async () => {
console.log("Starting Server and World Backup");
const CurrentBackup = Backup();
// Azure
if (Crron.Azure) Cloud_Backup.Azure(CurrentBackup.file_name, CurrentBackup.file_path);
else console.info("Azure Backup Disabled");
// Google Driver
if (Crron.Driver) Cloud_Backup.Driver(CurrentBackup.file_name, CurrentBackup.file_path);
else console.info("Google Driver Backup Disabled");
// Oracle Bucket
if (Crron.Oracle) Cloud_Backup.Oracle(CurrentBackup.file_name, CurrentBackup.file_path);
else console.info("Oracle Bucket Backup Disabled");
})
}
const CronBackups = BdsSettings.GetCronBackup().map(CronConfig => {
if (!CronConfig.enabled) return;
const BackupUpload = require("@the-bds-maneger/clouds_uploads");
return new CronJob(CronConfig.cron, async () => {
console.log("Starting Backup, Cron:", CronConfig.cron);
const CurrentBackup = BdsBackup.CreateBackup();
const BackupClass = new BackupUpload(CurrentBackup.Buffer, CurrentBackup.file_name);
BackupClass.upload.GoogleDriver = CronConfig.Driver;
BackupClass.upload.OracleCloudInfrastructure = CronConfig.Oracle;
BackupClass.upload.Azure = CronConfig.Azure;
return await BackupClass.Start();
});
});
module.exports = {
GetSessions: () => ServerSessions,
GetSessionsArray: () => Object.keys(ServerSessions).map(key => ServerSessions[key]),
RegisterPlayerGlobalyCallbacks: function RegisterPlayerGlobalyCallbacks(callback){
PlayersCallbacks.push(callback);
},
StartServer: StartServer,
CronBackups: CronBackups
}

View File

@ -4,7 +4,7 @@ const { writeFileSync, existsSync, readFileSync, readdirSync, rmSync } = fs;
const { join, resolve } = path;
var AdmZip = require("adm-zip");
const { GetServerPaths, GetPlatform } = require("../src/lib/BdsSettings");
const Extra = require("../BdsManegerInfo.json");
const Extra = require("./BdsManegerInfo.json");
const bds = require("../index");
const Request = require("../src/lib/Requests");

View File

@ -1,98 +0,0 @@
const fs = require("fs");
const { join } = require("path")
const { randomUUID } = require("crypto");
const express = require("express");
const { google } = require("googleapis");
const ip_andress = require("../../BdsNetwork");
const { bds_dir } = require("../../../src/lib/BdsSettings");
const PathToToken = join(bds_dir, "google_user_token.json");
// Urls
global.GoogleAuth = {}
async function LoadExpress(GoogleDriveCredentials, app = express(), closer = express().listen(1221)){
return new Promise((resolve => {
app.get("/request", (req, res) => {
const SessionUUID = randomUUID();
const secret = GoogleDriveCredentials.installed.client_secret;
const client = GoogleDriveCredentials.installed.client_id;
const redirect = `${req.protocol}://${req.headers.host}/${SessionUUID}/save`;
const oAuth2Client = new google.auth.OAuth2(client, secret, redirect);
global.GoogleAuth[SessionUUID] = oAuth2Client;
res.redirect(oAuth2Client.generateAuthUrl({
access_type: "offline",
scope: [
"https://www.googleapis.com/auth/drive"
]
}));
});
app.get("/:SessionUUID/save", (req, res) => {
const { code } = req.query;
const { SessionUUID } = req.params;
// http://localhost:6899/save?code=********************************************************************&scope=https://www.googleapis.com/auth/drive
const oAuth2Client = global.GoogleAuth[SessionUUID];
oAuth2Client.getToken(code, (err, save_token) => {
if (err) return console.error("Error accessing keys and saving, Error:", err);
oAuth2Client.setCredentials(save_token);
// Save Token File
fs.writeFile(PathToToken, JSON.stringify(save_token, null, 4), function (err){
if (err) {
console.error("We were unable to save json, please try again later");
return closer();
}
res.json({
"token": save_token,
status: "success"
})
closer.close()
resolve(oAuth2Client);
});
});
});
app.all("*", ({res}) => res.redirect("/request"));
}));
}
function RandomPort(){
let Port = parseInt(Math.random().toString().replace(/[01]\./, "").slice(0, 4));
if (Port > 1024 && Port < 2542) return Port; else return RandomPort();
}
async function authorize() {
return new Promise(async resolve => {
const GoogleDriveCredentials = (await (await fetch("https://raw.githubusercontent.com/The-Bds-Maneger/external_files/main/Credentials/Google.json")).json())
const client_secret = GoogleDriveCredentials.installed.client_secret;
const client_id = GoogleDriveCredentials.installed.client_id;
const redirect_uris = "http://localhost:1932/SaveToken"
const oAuth2Client = new google.auth.OAuth2(client_id, client_secret, redirect_uris);
fs.readFile(PathToToken, async (err, user_cred) => {
if (err) {
const app = express();
app.use(require("body-parser").json());
app.use(require("body-parser").urlencoded({ extended: true }));
app.use(require("express-rate-limit")({windowMs: 1 * 60 * 1000, max: 100}));
app.use(require("cors")());
const port = RandomPort();
ip_andress.internal_ip.forEach(ips => {
let { ipv4, ipv6 } = ips.Interna_IP;
console.log(`Open: http://${ipv4}:${port}/request`);
if (ipv6) console.log(`Open: http://[${ipv6}]:${port}/request`);
});
// Return auth
const AuthToken = await LoadExpress(GoogleDriveCredentials, app, app.listen(port));
resolve(AuthToken);
} else {
oAuth2Client.setCredentials(JSON.parse(user_cred));
resolve(oAuth2Client);
}
});
});
}
module.exports = {
authorize,
}

View File

@ -1,30 +0,0 @@
const path = require("path");
const { BlobServiceClient, StorageSharedKeyCredential } = require("@azure/storage-blob");
const NewBdsSettings = require("../../src/lib/BdsSettings");
// Upload Function
async function Uploadbackups(object = "Backup.zip", fileLocation = "Backup.zip", callback = function (){}) {
return new Promise(async function(resolve, reject){
try {
const { Account, AccountKey, Container } = NewBdsSettings.GetCloudConfig("Azure");
const sharedKeyCredential = new StorageSharedKeyCredential(Account, AccountKey);
const blobClient = new BlobServiceClient(`https://${Account}.blob.core.windows.net`, sharedKeyCredential).getContainerClient(Container)
if (!(blobClient.exists())) await blobClient.create();
const containerClient = blobClient.getBlockBlobClient(path.resolve(object));
const Reponse = await containerClient.uploadFile(fileLocation, {
blockSize: 4 * 1024 * 1024,
concurrency: 20,
onProgress: (env) => console.log(env)
})
if (typeof callback === "function") callback(Reponse);
resolve(Reponse);
} catch (err) {
console.log(`uploadFile failed, requestId - ${err.details.requestId}, statusCode - ${err.statusCode}, errorCode - ${err.details.errorCode}`);
reject(err);
}
})
}
module.exports = {
Uploadbackups
}

View File

@ -1,34 +0,0 @@
const fs = require("fs");
const { google } = require("googleapis");
const { authorize } = require("./Auth/Google");
const { GetCloudConfig } = require("../../src/lib/BdsSettings");
module.exports.Uploadbackups = async function (file_name = "Backup.zip", fileLocation = "Backup.zip", BackupCallback){
return new Promise(async function (resolve, reject){
const parent_id = GetCloudConfig("Driver").RootID
const UploadFile = {
resource: {
name: file_name
},
media: {
mimeType: "application/octet-stream",
body: fs.createReadStream(fileLocation)
},
fields: "id"
}
// Driver Root ID Backups
if (parent_id) UploadFile.resource.parents = [parent_id];
const auth = await authorize();
const drive = google.drive({version: "v3", auth});
drive.files.create(UploadFile, (err, file) => {
if (err) reject(err)
else {
console.log(`File URL: https://drive.google.com/file/d/${file.data.id}/`);
if (typeof BackupCallback === "function") BackupCallback(file);
resolve(`https://drive.google.com/file/d/${file.data.id}/`);
}
});
});
};

View File

@ -1,41 +0,0 @@
const oci_storage = require("oci-objectstorage");
const oci_common = require("oci-common");
const fs = require("fs");
const { resolve } = require("path");
const { CloudConfig } = require("../../src/lib/BdsSettings");
async function Uploadbackups(object = "Backup.zip", fileLocation = resolve(__dirname, "../Backup.zip"), callback = function (data){console.log(data)}){
return new Promise(async function (resolve, reject){
try {
const bucket = CloudConfig.Oracle().Bucket;
const provider = new oci_common.ConfigFileAuthenticationDetailsProvider();
const client = new oci_storage.ObjectStorageClient({
authenticationDetailsProvider: provider
});
const request = {};
const response = await client.getNamespace(request);
const namespace = response.value;
const stats = fs.statSync(fileLocation);
const nodeFsBlob = new oci_storage.NodeFSBlob(fileLocation, stats.size);
const objectData = await nodeFsBlob.getData();
const putObjectRequest = {
namespaceName: namespace,
bucketName: bucket,
putObjectBody: objectData,
objectName: object,
contentLength: stats.size
};
const putObjectResponse = await client.putObject(putObjectRequest);
console.log("File upload successful");
if (typeof callback === "function") return callback(putObjectResponse);
resolve(putObjectResponse);
} catch (error) {
console.log("Error ", error);
reject(error);
}
});
}
module.exports = {
Uploadbackups,
}

View File

@ -1,21 +1,25 @@
const { join, basename } = require("path");
const { existsSync, writeFileSync, mkdirSync, readFileSync } = require("fs");
const fs = require("fs");
const path = require("path");
const { existsSync, writeFileSync, mkdirSync, readFileSync } = fs;
const { homedir } = require("os");
const yaml = require("js-yaml");
const deepmerge = require("deepmerge");
// PATHs
const home = homedir();
const bds_dir = join(home, "bds_core");
if (!(existsSync(bds_dir))) mkdirSync(bds_dir, {recursive: true})
const home = homedir(),
bds_dir = path.join(home, "bds_core"),
ExternalPlugins = path.join(bds_dir, "plugins");
if (!(existsSync(bds_dir))) fs.mkdirSync(bds_dir, {recursive: true});
if (!(existsSync(ExternalPlugins))) fs.mkdirSync(ExternalPlugins, {recursive: true});
// Config Base to Bds Maneger Core and others Projects
var Config = {
paths: {
servers: join(bds_dir, "Servers"),
backups: join(bds_dir, "Backups"),
log: join(bds_dir, "Logs"),
player: join(bds_dir, "Players.json")
servers: path.join(bds_dir, "Servers"),
backups: path.join(bds_dir, "Backups"),
log: path.join(bds_dir, "Logs"),
player: path.join(bds_dir, "Players.json")
},
bds: {
enable_tmp_host: false
@ -67,30 +71,6 @@ var Config = {
pocketmine: true,
jsprismarine: true,
spigot: true,
},
{
username: "Alex",
bedrock: true,
java: true,
pocketmine: true,
jsprismarine: true,
spigot: true,
},
{
username: "steve",
bedrock: true,
java: true,
pocketmine: true,
jsprismarine: true,
spigot: true,
},
{
username: "alex",
bedrock: true,
java: true,
pocketmine: true,
jsprismarine: true,
spigot: true,
}
],
telegram: {
@ -101,7 +81,7 @@ var Config = {
}
// Config
const ConfigPath = join(bds_dir, "BdsConfig.yaml")
const ConfigPath = path.join(bds_dir, "BdsConfig.yaml")
const SaveConfig = () => writeFileSync(ConfigPath, yaml.dump(Config));
process.on("exit", () => SaveConfig());
@ -121,16 +101,16 @@ if (!(existsSync(Config.paths["servers"]))) mkdirSync(Config.paths["servers"], {
// Server Paths
const ServersPaths = {
bedrock: join(Config.paths.servers, "Bedrock"),
java: join(Config.paths.servers, "Java"),
pocketmine: join(Config.paths.servers, "Pocketmine-MP"),
dragonfly: join(Config.paths.servers, "Dragonfly_go"),
spigot: join(Config.paths.servers, "Spigot")
bedrock: path.join(Config.paths.servers, "Bedrock"),
java: path.join(Config.paths.servers, "Java"),
pocketmine: path.join(Config.paths.servers, "Pocketmine-MP"),
dragonfly: path.join(Config.paths.servers, "Dragonfly_go"),
spigot: path.join(Config.paths.servers, "Spigot")
}
Object.getOwnPropertyNames(ServersPaths).map(Servers => ServersPaths[Servers]).forEach(Servers => {
if (!(existsSync(Servers))) {
console.log(`Creating the ${basename(Servers)} Folder`);
console.log(`Creating the ${path.basename(Servers)} Folder`);
mkdirSync(Servers, {recursive: true})
}
});
@ -267,6 +247,8 @@ if (!(existsSync(GetPaths("player")))) {
module.exports = {
bds_dir: bds_dir,
BdsDir: bds_dir,
ExternalPlugins: ExternalPlugins,
ServersPaths: ServersPaths,
GetJsonConfig,
GetPaths,

21
src/lib/LoadPlugin.js Normal file
View File

@ -0,0 +1,21 @@
const fs = require("fs");
const path = require("path");
const BdsSettings = require("./BdsSettings");
function LoadPlugins() {
return fs.readdirSync(BdsSettings.ExternalPlugins).filter(file => fs.fstatSync(path.join(BdsSettings.ExternalPlugins, file)).isFile()).map(files => {
try {
return require(path.join(BdsSettings.ExternalPlugins, files));
} catch (err) {
console.log(err);
return null;
}
}).filter(plugin => plugin);
}
module.exports.plugin = LoadPlugins();
fs.watch(BdsSettings.ExternalPlugins, () => {
module.exports.plugin = LoadPlugins();
});
module.exports.LoadPlugins = LoadPlugins;