Merge #31

Merged
Sirherobrine23 merged 14 commits from main into stable 2021-02-09 17:53:17 +00:00
12 changed files with 247 additions and 44 deletions
Showing only changes of commit e0b4f540d9 - Show all commits

View File

@ -67,7 +67,7 @@ jobs:
run: |
sudo apt install -y jq
echo "bds_api_version=$(cat package.json | jq '.version')" >> $GITHUB_ENV
echo "bds_api_depe=\"$(cat package.json | jq '.dependencies')\"" >> $GITHUB_ENV
echo "bds_api_depe=\"$(cat package.json | jq '.dependencies'|tr "\n" " "|sed "s|\^||g"|sed "s| ||g")\"" >> $GITHUB_ENV
- name: Tag
uses: softprops/action-gh-release@v1

View File

@ -54,7 +54,7 @@ jobs:
- name: Get Infos
run: |
echo "bds_api_version=$(cat package.json | jq '.version')" >> $GITHUB_ENV
echo "bds_api_depe=\"$(cat package.json | jq '.dependencies')\"" >> $GITHUB_ENV
echo "bds_api_depe=\"$(cat package.json | jq '.dependencies'|tr "\n" " "|sed "s|\^||g"|sed "s| ||g")\"" >> $GITHUB_ENV
- name: Tag
uses: softprops/action-gh-release@v1

View File

@ -45,7 +45,7 @@ function getAccessToken(oAuth2Client, callback) {
};
module.exports.drive_backup = () => {
const file_json = require("../new_script/backups").Drive_backup()
const file_json = require("../scripts/backups").Drive_backup()
console.log(file_json)
const parent_id = file_json.id
const path_file = file_json.file_path

View File

@ -1,5 +1,5 @@
const { Telegraf } = require("telegraf")
const token = require("../index").token
const token = require("../index").telegram_token
const bot = new Telegraf(token)
bot.start((ctx) => {
const amenssagem = `Hello ${ctx.message.from.username}

241
index.js
View File

@ -41,6 +41,7 @@ if (arch == "x64"){
}
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")
if (process.platform == "win32") {
@ -81,6 +82,13 @@ if (process.platform == "win32") {
};
// ---------
// ---------
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');
@ -98,12 +106,11 @@ const bds_config_file = path.join(bds_dir, "bds_config.json")
if (fs.existsSync(bds_config_file)){
var bds_config = JSON.parse(fs.readFileSync(bds_config_file, "utf-8"))
} else {
const _config = `{
const bds_config = {
"bds_platform": "bedrock",
"telegram_token": null
}`
var bds_config = JSON.parse(_config)
fs.writeFileSync(bds_config_file, _config)
"telegram_token": "not User defined"
}
fs.writeFileSync(bds_config_file, JSON.stringify(bds_config))
}
module.exports.platform = bds_config.bds_platform
console.log(`Running on the \"${bds_config.bds_platform}\" platform`)
@ -143,28 +150,58 @@ if (!(fs.existsSync(log_dir))){
};
};
// e
if (require("fs").existsSync(`${bds_dir}/telegram_token.txt`)){
module.exports.token = fs.readFileSync(`${bds_dir}/telegram_token.txt`, "utf8").replaceAll("\n", "");
} else {
module.exports.token = undefined;
/**
* with this command we can change the platform with this script
*
* bedrock change_platform("bedrock")
*
* java change_platform("java")
* @example change_platform("bedrock")
*/
function platform_update(plate){
if (plate === "java") true
else if (plate === "bedrock") true
else throw new console.error(`platform not identified or does not exist, ${plate} informed platform`);
const bds_config = path.join(bds_dir, "bds_config.json")
try {
const config_load = JSON.parse(fs.readFileSync(bds_config))
config_load.bds_platform = plate
fs.writeFileSync(bds_config, JSON.stringify(config_load))
console.log(`upgrading the bedrock ${plate}`)
} catch (error) {
throw new console.error(`Something happened error code: ${error}`);
}
}
if ((process.env.SERVER || "bedrock").includes("java", "JAVA")){
platform_update("java")
}else{
platform_update("bedrock")
}
module.exports.telegram_token_save = (token) =>{
fs.writeFileSync(`${bds_dir}/telegram_token.txt`, token);
return "OK"
}
if (typeof fetch === "undefined"){global.fetch = require("node-fetch")}
if (typeof localStorage === "undefined"){
var localStorageS = require("node-localstorage").LocalStorage;
global.localStorage = new localStorageS(`${cache_dir}/Local_Storage`);
try {
const bds_config = path.join(bds_dir, "bds_config.json")
const config_load = JSON.parse(fs.readFileSync(bds_config))
config_load.telegram_token = token
fs.writeFileSync(bds_config, JSON.stringify(config_load))
return true
} catch {
return false
}
}
// Java or Bedrock
if (process.env.JAVA_ENABLE !== undefined){
localStorage.setItem('bds_edititon', 'java');
}else{
localStorage.setItem('bds_edititon', 'bedrock');
if (require("fs").existsSync(path.join(bds_dir, "telegram_token.txt"))){
console.log(`We identified the old telegram token file \(${path.join (bds_dir, "telegram_token.txt")}\), starting the immigration process`)
try {
const token = fs.readFileSync(path.join(bds_dir, "telegram_token.txt"), "utf-8").split("\n").join("")
require("./index").telegram_token_save(token)
fs.rmSync(path.join(bds_dir, "telegram_token.txt"))
console.log(`We finished migrating the old telegram token file`)
} catch {
throw new error(`It was not possible to move the old telegram token file to the new bds maneger api file`)
}
}
if (process.env.BDS_MONI == blanks){process.env.BDS_MONI = "false"}
@ -173,8 +210,23 @@ if (process.env.ENABLE_BDS_API == blanks){process.env.ENABLE_BDS_API = "false"}
// Fetchs
fetch("https://raw.githubusercontent.com/Bds-Maneger/Raw_files/main/credentials.json").then(response => response.text()).then(gd_cre => {
/**
* backup credentials and an interesting design feature, plus privacy is important
*/
module.exports.google_drive_credential = gd_cre
/**
* download the latest version of minecraft bedrock for android available, remember to use if you want ✌
*
* you are taking responsibility for that
*/
module.exports.mcpe_file = require("./global/auth").mcpe
/**
* perform a backup of the map, some resources are still under construction in the code more works
*
* on the bedrock platform, all maps will be backed up into the "worlds" folder
*
* on the java platform the map selected in the server configuration will be backed up, any other map will have to change in the server settings to perform the backup
*/
module.exports.drive_backup= require("./global/auth").drive_backup
});
fetch("https://raw.githubusercontent.com/Bds-Maneger/Raw_files/main/Server.json").then(response => response.json()).then(rawOUT => {
@ -209,14 +261,41 @@ fetch("https://raw.githubusercontent.com/Bds-Maneger/Raw_files/main/Server.json"
// Module export
/* Variaveis */
/**
* this variable makes available the location of the user profile directory as
*
* Linux: /home/USER/
*
* Windows: C:\\Users\\USER\\
*
* MacOS: not supported
*/
module.exports.home = home
/**
* With different languages and systems we want to find the user's desktop for some link in the directory or even a nice shortcut
*/
module.exports.desktop = desktop
/**
* Identifying a system in the script can be simple with this variable
*/
module.exports.system = system
/**
* The most important directory of this project, here are saved some important things like:
*
* The server software
*
* configuration of the Bds Manager API
*
* Backups etc ...
*/
module.exports.bds_dir = bds_dir
module.exports.bds_dir_bedrock = bds_dir_bedrock
module.exports.bds_dir_java = bds_dir_java
module.exports.tmp_dir = tmp
module.exports.electron = electron_de
module.exports.api_dir = cache_dir
@ -224,23 +303,109 @@ 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, 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.date = date
/**
* sending commands more simply to the server
*
* @example bds.command("say hello from Bds Maneger")
*/
module.exports.command = require("./global/command").command
// module.exports.stop = require("./global/stop").Server_stop
// New management method
module.exports.start = require("./new_script/basic_server").start
module.exports.stop = require("./new_script/basic_server").stop
module.exports.backup = require("./new_script/backups").World_BAckup
module.exports.detect = require("./new_script/detect")
module.exports.bds_detect = require("./new_script/detect")
module.exports.version_Download = require("./new_script/bds_download")
module.exports.download = require("./new_script/bds_download")
module.exports.kill = require("./new_script/kill_server")
module.exports.config_example = require("./new_script/bds_settings").config_example
module.exports.set_config = require("./new_script/bds_settings").config
module.exports.get_config = require("./new_script/bds_settings").get_config
/**
* to start the server here in the sera script with child_process, then you will have to use the return function for your log custumization or anything else
*
* @example const server = bds.start();
* server.on.stdout("date", function (log){console.log(log)})
*/
module.exports.start = require("./scripts/basic_server").start
/**
* use this command for the server, that's all
*/
module.exports.stop = require("./scripts/basic_server").stop
/**
* backup your map locally
*/
module.exports.backup = require("./scripts/backups").World_BAckup
/**
* identify if there are any servers running in the background
*
* @example bds.detect()
* // true: if the server is running
* // false: if not already
*/
module.exports.detect = require("./scripts/detect")
module.exports.bds_detect = require("./scripts/detect")
/**
* @deprecated
*/
module.exports.version_Download = require("./scripts/bds_download")
/**
* download some version of the java and Bedrock servers in the highest possible form
*
* @example
* bedrock: bds.download("1.16.201.02")
*
* java: bds.download("1.16.5")
*/
module.exports.download = require("./scripts/bds_download")
/**
* this function will be used to kill the server in the background
*/
module.exports.kill = require("./scripts/kill_server")
module.exports.config_example = require("./scripts/bds_settings").config_example
/**
* use this command to modify server settings
*
* @example
*
* bds.set_config({
name: "Bedrock our Java",
description: "BDS Maneger",
gamemode: "survival",
difficulty: "normal",
player_permission: "member",
xbox: true,
white_list: false,
cheats: false,
players: 100,
port: 19132,
port6: 19133
})
*/
module.exports.set_config = require("./scripts/bds_settings").config
/**
* takes the server settings in JSON format
*/
module.exports.get_config = require("./scripts/bds_settings").get_config

View File

@ -44,5 +44,8 @@
"shelljs": "^0.8.4",
"systeminformation": "^5.0.10",
"telegraf": "^4.0.0"
},
"engines": {
"node": ">=14"
}
}