Merge #20
							
								
								
									
										17
									
								
								API/api.js
									
									
									
									
									
								
							
							
						
						
									
										17
									
								
								API/api.js
									
									
									
									
									
								
							| @@ -47,11 +47,18 @@ module.exports = () => { | |||||||
|         return res.send(json_http); |         return res.send(json_http); | ||||||
|     }); |     }); | ||||||
|     app.get("/", (req, res) => { |     app.get("/", (req, res) => { | ||||||
|         return res.send({ |         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}`); | ||||||
|             "info": "/info", |     }); | ||||||
|             "Bds Commnd": "/bds_command (POST)", |     app.get("/themes", (req, res) => { | ||||||
|             "Log": "/log", |         fetch("https://raw.githubusercontent.com/Bds-Maneger/Raw_files/main/themes.json").then(response => response.json()).then(array => { | ||||||
|             "bds_maneger_API_version": require("../package.json").version |             var themes_json; | ||||||
|  |             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; | ||||||
|  |                 themes_json += `{Name: ${name},\n Url Zip: ${zip_url},\n Git url: ${git_url}},` | ||||||
|  |             } | ||||||
|  |             return res.send(themes_json); | ||||||
|         }); |         }); | ||||||
|     }); |     }); | ||||||
|     const bodyParser = require("body-parser"); |     const bodyParser = require("body-parser"); | ||||||
|   | |||||||
							
								
								
									
										26
									
								
								API/gdrive_save.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								API/gdrive_save.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,26 @@ | |||||||
|  | module.exports = () => { | ||||||
|  |     global.bds_api_start = true | ||||||
|  |     const express = require("express"); | ||||||
|  |     const app = express(); | ||||||
|  |     var cors = require('cors'); | ||||||
|  |     app.use(cors()); | ||||||
|  |     app.use(require("body-parser").json()); /* https://github.com/github/fetch/issues/323#issuecomment-331477498 */ | ||||||
|  |     const bodyParser = require("body-parser"); | ||||||
|  |     app.use(bodyParser.urlencoded({ extended: true })); | ||||||
|  |     app.get("/:DI", (req, res) => { | ||||||
|  |         return res.send(` | ||||||
|  |         <html> | ||||||
|  |             <head></head> | ||||||
|  |             <body> | ||||||
|  |                 <a>token Save</a> | ||||||
|  |                 <p> | ||||||
|  |                     <textarea disabled> | ||||||
|  |                         ${req.params.DI} | ||||||
|  |                     </textarea> | ||||||
|  |                 </p> | ||||||
|  |             </body> | ||||||
|  |         </html> | ||||||
|  |         `); | ||||||
|  |     }); | ||||||
|  |     app.listen(2212); | ||||||
|  | } | ||||||
| @@ -1,5 +1,3 @@ | |||||||
| const { bds_detect } = require("../bedrock/detect_bds"); |  | ||||||
|  |  | ||||||
| module.exports = () => { | module.exports = () => { | ||||||
|     global.bds_api_post_start = true |     global.bds_api_post_start = true | ||||||
|     const express = require("express"); |     const express = require("express"); | ||||||
| @@ -49,39 +47,42 @@ module.exports = () => { | |||||||
|             }) |             }) | ||||||
|         } |         } | ||||||
|     }); |     }); | ||||||
|     app.post("/bds/:command", (req, res) => { |     app.get("/bds/:command", (req, res) => { | ||||||
|         const body = req.body |         const body = req.body | ||||||
|         const command_bds = ''; |         const command_bds = ''; | ||||||
|         const tokens = JSON.parse(fs.readFileSync(path.join(bds.bds_dir, "bds_tokens.json"), "utf-8")) |         const tokens = JSON.parse(fs.readFileSync(path.join(bds.bds_dir, "bds_tokens.json"), "utf-8")) | ||||||
|         var pass = false; |         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){ |  | ||||||
|             if (command_bds === 'start'){ |  | ||||||
|                 var bds_init = bds.start() |  | ||||||
|                 var command_status = `Bds Started` |  | ||||||
|             } else if (command_bds === 'stop'){ |  | ||||||
|                 bds.stop() |  | ||||||
|                 var command_status = `Stopping the bds server` |  | ||||||
|             } else if (command_bds === 'reload'){ |  | ||||||
|                 const bds_status = bds.detect() |  | ||||||
|                 if (bds_detect){ |  | ||||||
|                     bds.stop() |  | ||||||
|                 } |  | ||||||
|                 var bds_init = bds.start() |  | ||||||
|                 var command_status = `Reloading` |  | ||||||
|             } else { |  | ||||||
|                 var command_status = `no command identified` |  | ||||||
|             } |  | ||||||
|         res.send({ |         res.send({ | ||||||
|                 "status": 200, |             "command": req.params.command | ||||||
|                 "bds_status": command_status |  | ||||||
|         }) |         }) | ||||||
|         } else { |         // for (let token_verify in tokens) {const element = tokens[token_verify].token;if (body.token == element){pass = true} else {token_verify++}} | ||||||
|             res.send({ |         // if (pass){ | ||||||
|                 "status": 401, |         //     if (command_bds === 'start'){ | ||||||
|                 "message": `Not authorized: ${body.token}` |         //         var bds_init = bds.start() | ||||||
|             }) |         //         var command_status = `Bds Started` | ||||||
|         } |         //     } else if (command_bds === 'stop'){ | ||||||
|  |         //         bds.stop() | ||||||
|  |         //         var command_status = `Stopping the bds server` | ||||||
|  |         //     } else if (command_bds === 'reload'){ | ||||||
|  |         //         const bds_status = bds.detect() | ||||||
|  |         //         if (bds_detect){ | ||||||
|  |         //             bds.stop() | ||||||
|  |         //         } | ||||||
|  |         //         var bds_init = bds.start() | ||||||
|  |         //         var command_status = `Reloading` | ||||||
|  |         //     } else { | ||||||
|  |         //         var 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_command", (req, res) => { |     app.post("/bds_command", (req, res) => { | ||||||
|         const body = req.body |         const body = req.body | ||||||
|   | |||||||
							
								
								
									
										12
									
								
								API/teste.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								API/teste.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,12 @@ | |||||||
|  | var qr = require('qr-image');   | ||||||
|  | var express = require('express'); | ||||||
|  |  | ||||||
|  | var app = express(); | ||||||
|  |  | ||||||
|  | app.get('/', function(req, res) {   | ||||||
|  |   var code = qr.image(`list: ${Math.random()}`, { type: 'svg' }); | ||||||
|  |   res.type('svg'); | ||||||
|  |   code.pipe(res); | ||||||
|  | }); | ||||||
|  |  | ||||||
|  | app.listen(3000); | ||||||
							
								
								
									
										15
									
								
								CHANGELOG.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								CHANGELOG.md
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,15 @@ | |||||||
|  | # 1.4.2 | ||||||
|  |  | ||||||
|  | Docker test fix | ||||||
|  |  | ||||||
|  | # 1.4.1 | ||||||
|  |  | ||||||
|  | Docker test fix | ||||||
|  |  | ||||||
|  | # 1.4.0 | ||||||
|  |  | ||||||
|  | Changes to the code base | ||||||
|  |  | ||||||
|  | Some scripts have been merged again for future maintenance. | ||||||
|  |  | ||||||
|  | An issue persists when starting the Docker Image, wait for the next API updates. | ||||||
| @@ -1,32 +0,0 @@ | |||||||
| module.exports.World_BAckup = () => { |  | ||||||
|     if (require("./detect_bds").bds_detect()){require("./stop").Server_stop()} |  | ||||||
|     const bds = require('../index') |  | ||||||
|     if (process.platform == "win32") { |  | ||||||
|         var today = bds.date() |  | ||||||
|         var name = `${process.env.USERPROFILE}/Desktop/bds_backup_World_${today}.zip` |  | ||||||
|         var dir_zip = `${require("../index").bds_dir}/worlds/` |  | ||||||
|     } else if (process.platform == "linux") { |  | ||||||
|         var today = bds.date() |  | ||||||
|         var name = `${process.env.HOME}/bds_backup_World_${today}.zip` |  | ||||||
|         var dir_zip = `${require("../index").bds_dir_bedrock}/worlds/` |  | ||||||
|     }; |  | ||||||
|     var AdmZip = require("adm-zip");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);console.log("Backup Sucess") |  | ||||||
| }; |  | ||||||
|  |  | ||||||
| module.exports.Drive_backup = () => { |  | ||||||
|     if (require("./detect_bds").bds_detect()){require("./stop").Server_stop()} |  | ||||||
|     const bds = require("../index"); |  | ||||||
|     const path = require("path"); |  | ||||||
|     var dir_zip = path.join(bds.bds_dir_bedrock, "worlds"); |  | ||||||
|     const today = bds.date(); |  | ||||||
|     const file_name = `bds_backup_World_${today}.zip` |  | ||||||
|     const name = path.join(bds.tmp_dir, file_name) |  | ||||||
|     /* Compress the folders */ |  | ||||||
|     var AdmZip = require("adm-zip");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();zip.writeZip(name);console.log("Backup Sucess") |  | ||||||
|     var json_return = { |  | ||||||
|         file_dir: name.replaceAll("\\", "/"), |  | ||||||
|         file_name: file_name |  | ||||||
|     } |  | ||||||
|     return json_return |  | ||||||
| }; |  | ||||||
|  |  | ||||||
| @@ -1,159 +0,0 @@ | |||||||
| function bds_config(json_config){ |  | ||||||
| var Server_Config = `${require("../index").bds_dir_bedrock}/server.properties` |  | ||||||
| const cpuCount = require("os").cpus().length; |  | ||||||
| var fs = require("fs") |  | ||||||
| if (2 < cpuCount - 2) var CPU = cpuCount - 2; else var CPU = cpuCount; |  | ||||||
| if (json_config.includes(".json")){var config = JSON.parse(fs.readFileSync(json_config, "utf8"))} else var config = JSON.parse(json_config) |  | ||||||
| if (config.description == undefined){var description_name = `Dedicated Server`;} else {var description_name = config.description;}; |  | ||||||
|  |  | ||||||
| // Level Name |  | ||||||
| if (config.name == undefined){var level_name = `Bedrock level`;} else {var level_name = config.name;}; |  | ||||||
|  |  | ||||||
| // gamemode |  | ||||||
| if (config.gamemode == undefined){var gamemode = `survival`;} else {var gamemode = config.gamemode;}; |  | ||||||
|  |  | ||||||
| // Difficulty |  | ||||||
| if (config.difficulty == undefined){var difficulty = `easy`;} else {var difficulty = config.difficulty;}; |  | ||||||
|  |  | ||||||
| // cheats |  | ||||||
| if (config.cheats == undefined){var allow_cheats = false;} else {var allow_cheats = config.cheats;}; |  | ||||||
|  |  | ||||||
| // Maximo de Jogadores |  | ||||||
| if (config.players == undefined){var max_players = 10;} else {var max_players = config.players;}; |  | ||||||
|  |  | ||||||
| // Xbox authentication outside the internal network |  | ||||||
| if (config.xbox == undefined){var online_mode = true;} else {var online_mode = config.xbox;}; |  | ||||||
|  |  | ||||||
| // Whitelist |  | ||||||
| if (config.white_list == undefined){var white_list = false;} else {var white_list = config.white_list;}; |  | ||||||
|  |  | ||||||
| // Server Port IPv4 |  | ||||||
| if (config.port == undefined){var server_port = 19132;} else {var server_port = config.port;}; |  | ||||||
|  |  | ||||||
| // Server Port IPv6 |  | ||||||
| if (config.port6 == undefined){var server_portv6 = 19133;} else {var server_portv6 = config.port6;}; |  | ||||||
|  |  | ||||||
| // Default player permission |  | ||||||
| if (config.player_permission == undefined){var player_permission = `member`;} else {var player_permission = config.player_permission;}; |  | ||||||
| const cpuCountTick = require("os").cpus().length; |  | ||||||
| if (2 >= cpuCountTick) var tick = 2 ;else if (4 >= cpuCountTick) var tick = 4;else if (6 >= cpuCountTick) var tick = 6;else if (8 >= cpuCountTick) var tick = 8;else if (10 >= cpuCountTick) var tick = 10;else var tick = 12 |  | ||||||
|  |  | ||||||
| /*Save Files*/ |  | ||||||
| if (localStorage.getItem("bds_edititon") === 'java'){ |  | ||||||
|     var config_file_content = ` |  | ||||||
| enable-jmx-monitoring=false |  | ||||||
| rcon.port=25575 |  | ||||||
| level-seed= |  | ||||||
| gamemode=${gamemode} |  | ||||||
| enable-command-block=false |  | ||||||
| enable-query=false |  | ||||||
| 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 |  | ||||||
| ` |  | ||||||
| } else { |  | ||||||
|     var 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 |  | ||||||
| ` |  | ||||||
| } |  | ||||||
|  |  | ||||||
| // console.log(config_file_content); |  | ||||||
| fs.writeFileSync(Server_Config, config_file_content); |  | ||||||
| return config_file_content |  | ||||||
| }; |  | ||||||
| function bds_get_config(){ |  | ||||||
|     var fs = require("fs"); |  | ||||||
|     const propertiesToJSON = require("properties-to-json"); |  | ||||||
|     if (localStorage.getItem("bds_edititon") === 'java') |  | ||||||
|     var Server_Config = `${require("../index").bds_dir_java}/server.properties` |  | ||||||
| else |  | ||||||
|     var Server_Config = `${require("../index").bds_dir_bedrock}/server.properties` |  | ||||||
|     const inGET = fs.readFileSync(Server_Config, "utf8").replaceAll("-","_"); |  | ||||||
|     return propertiesToJSON(inGET); |  | ||||||
| }; |  | ||||||
| module.exports.config_example = () =>{ |  | ||||||
| const example = `{ |  | ||||||
|     "name": "Bedrock" |  | ||||||
|     "description": "Hello Works" |  | ||||||
|     "gamemode": "survival" |  | ||||||
|     "difficulty": "hard" |  | ||||||
|     "cheats": false |  | ||||||
|     "players": 100 |  | ||||||
|     "xbox": true |  | ||||||
|     "white_list": false |  | ||||||
|     "port": 19132 |  | ||||||
|     "port6": 19133 |  | ||||||
|     "player_permission": "member" |  | ||||||
| }` |  | ||||||
| return example |  | ||||||
| } |  | ||||||
| module.exports.config = bds_config |  | ||||||
| module.exports.get_config = bds_get_config |  | ||||||
| @@ -1,9 +0,0 @@ | |||||||
| module.exports.bds_detect = () => { |  | ||||||
|     var spawn = require("child_process").execSync; |  | ||||||
|     if (process.platform == "win32") { |  | ||||||
|         var killbds = spawn(`tasklist /fi "imagename eq bedrock_server.exe" | find /i "bedrock_server.exe" > nul & if not errorlevel 1 (echo 0) else (echo 1)`); |  | ||||||
|     } else if (process.platform == "linux") { |  | ||||||
|         var killbds = spawn(`ps aux|grep -v "grep"|grep "bedrock_server"|grep -q "bedrock_server";echo $?`, {shell: true}); |  | ||||||
|     }; |  | ||||||
|     if (killbds == 0){return true} else {return false}; |  | ||||||
| } |  | ||||||
| @@ -1,53 +0,0 @@ | |||||||
| 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 => { |  | ||||||
|         console.log(Vdown, config) |  | ||||||
|         const mine = config.minecraft |  | ||||||
|  |  | ||||||
|         const system = bds.system |  | ||||||
|         var mine_name = `bedrock.zip` |  | ||||||
|         var server_DIR = bds.bds_dir_bedrock; |  | ||||||
|         if (system === 'linux') |  | ||||||
|             var versions_get = versions.bedrock[Vdown].url_linux; |  | ||||||
|         else |  | ||||||
|             var versions_get = versions.bedrock[Vdown].url_windows; |  | ||||||
|  |  | ||||||
|         console.log("Starting download") |  | ||||||
|         const exec = require("child_process").exec |  | ||||||
|         localStorage.setItem("bds_server_version", Vdown);         |  | ||||||
|         var downloadBDSchild = exec(`curl ${versions_get} --output ${mine_name}`, { |  | ||||||
|             cwd: `${bds.tmp_dir}` |  | ||||||
|         }); |  | ||||||
|         var ZIP_FILE_PATH = `${bds.bds_dir}/${mine_name}`; |  | ||||||
|         downloadBDSchild.stdout.on("data", function(data){ |  | ||||||
|             console.log(data) |  | ||||||
|         }) |  | ||||||
|         downloadBDSchild.on("exit", function (code) { |  | ||||||
|             if (code === 0) { |  | ||||||
|                 console.log(`Download zip file success`); |  | ||||||
|  |  | ||||||
|                 var AdmZip = require("adm-zip"); |  | ||||||
|                 const fs = require("fs") |  | ||||||
|                 if (fs.existsSync(`${server_DIR}/server.properties`)){var _old = true;var old1 = fs.readFileSync(`${server_DIR}/server.properties`, "utf-8");} |  | ||||||
|                 if (fs.existsSync(`${server_DIR}/permissions.json`)){var _old2 = true;var old2 = fs.readFileSync(`${server_DIR}/permissions.json`, "utf-8");} |  | ||||||
|                 if (fs.existsSync(`${server_DIR}/whitelist.json`)) {var _old3 = true;var old3 = fs.readFileSync(`${server_DIR}/whitelist.json`, "utf-8");} |  | ||||||
|                 if (fs.existsSync(`${server_DIR}/valid_known_packs.json`)){var _old4 = true;var old4 = fs.readFileSync(`${server_DIR}/valid_known_packs.json`, "utf-8");}; |  | ||||||
|                 // Unzip  |  | ||||||
|                 var ZIP_FILE_OUTPUT = `${server_DIR}`;var zip = new AdmZip(ZIP_FILE_PATH); |  | ||||||
|                 zip.extractAllTo(ZIP_FILE_OUTPUT, true); |  | ||||||
|                 // Unzip  |  | ||||||
|                 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);}; |  | ||||||
|  |  | ||||||
|                 console.log("Downlod Sucess"); // End Unzip |  | ||||||
|                 localStorage.setItem("Downlaod_sucess", "yes") |  | ||||||
|             } else { |  | ||||||
|                 localStorage.setItem("Download_sucess", "no") |  | ||||||
|                 throw new error(`Could not download`); |  | ||||||
|             } |  | ||||||
|         }) |  | ||||||
|     }) |  | ||||||
| } |  | ||||||
| @@ -1,17 +0,0 @@ | |||||||
| module.exports.bds_kill = () => { |  | ||||||
|     var spawn = require("child_process").exec; |  | ||||||
|     const Storage = localStorage |  | ||||||
|     if (require("./detect_bds").bds_detect()){ |  | ||||||
|         if (process.platform == "win32") { |  | ||||||
|             var killbds = spawn(`tasklist /fi "imagename eq bedrock_server.exe" | find /i "bedrock_server.exe" > nul & if not errorlevel 1 (taskkill /f /im "bedrock_server.exe" > nul && exit 0) else (exit 1)`); |  | ||||||
|         } else if (process.platform == "linux") { |  | ||||||
|             var killbds = spawn(`kill $(ps aux|grep -v "grep"|grep "bedrock_server"|awk '{print $2}')`, {shell: true}); |  | ||||||
|         }; |  | ||||||
|         killbds.on("exit", function () {killbds.stdin.end();}); |  | ||||||
|         Storage.setItem("bds_status", false); |  | ||||||
|         return true |  | ||||||
|     } else { |  | ||||||
|         Storage.setItem("bds_status", false); |  | ||||||
|         return false |  | ||||||
|     }; |  | ||||||
| } |  | ||||||
| @@ -1,24 +0,0 @@ | |||||||
| module.exports.Server_start = () => { |  | ||||||
|     const bds = require("../index") |  | ||||||
|     const Storage = localStorage; |  | ||||||
|     var exec = require("child_process").exec; |  | ||||||
|     const mine = localStorage.getItem('bds_edititon') |  | ||||||
|     if (!(bds.detect())){ |  | ||||||
|         if (process.platform == "win32"){ |  | ||||||
|             var serverstated = exec(`bedrock_server.exe`, {cwd: bds.bds_dir_bedrock}); |  | ||||||
|         } else if (process.platform == "linux"){ |  | ||||||
|             var serverstated = exec(`chmod 777 bedrock_server && ./bedrock_server`, {env: {PATH: process.env.PATH, LD_LIBRARY_PATH: bds.bds_dir_bedrock}, cwd: bds.bds_dir_bedrock}); |  | ||||||
|         }; |  | ||||||
|         var logConsoleStream = require("fs").createWriteStream(bds.log_file, {flags: "a"}); |  | ||||||
|         Storage.setItem("old_log_file", bds.log_file) |  | ||||||
|         serverstated.stdout.pipe(logConsoleStream); |  | ||||||
|         if (typeof bds_log_string !== "undefined"){delete(bds_log_string)} |  | ||||||
|         serverstated.stdout.on("data", function(data){global.bds_log_string += data}) |  | ||||||
|         Storage.setItem("bds_status", true); |  | ||||||
|         global.bds_server_string = serverstated; |  | ||||||
|         return serverstated; |  | ||||||
|     } else { |  | ||||||
|         console.warn(`You already have a server running`) |  | ||||||
|         return `You already have a server running` |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @@ -3,14 +3,16 @@ const path = require("path") | |||||||
| const readline = require("readline"); | const readline = require("readline"); | ||||||
| const {google} = require("googleapis"); | const {google} = require("googleapis"); | ||||||
| const bds =  require("../index"); | const bds =  require("../index"); | ||||||
| const SCOPES = ["https://www.googleapis.com/auth/drive"]; | const open = require("open") | ||||||
| const TOKEN_PATH = path.join(bds.bds_dir, "google_token.json"); | const TOKEN_PATH = path.join(bds.bds_dir, "google_token.json"); | ||||||
|  |  | ||||||
|  |  | ||||||
| function authorize(credentials, callback) { | function authorize(credentials, callback) { | ||||||
|   const {client_secret, client_id, redirect_uris} = credentials.installed; |   const gd = JSON.parse(require("../index").google_drive_credential); | ||||||
|   const oAuth2Client = new google.auth.OAuth2( |   const client_secret = gd.installed.client_secret; | ||||||
|       client_id, client_secret, redirect_uris[0]); |   const client_id = gd.installed.client_id; | ||||||
|  |   const redirect_uris = gd.installed.redirect_uris; | ||||||
|  |   const oAuth2Client = new google.auth.OAuth2(client_id, client_secret, redirect_uris[0]); | ||||||
|  |  | ||||||
|   fs.readFile(TOKEN_PATH, (err, token) => { |   fs.readFile(TOKEN_PATH, (err, token) => { | ||||||
|     if (err) return getAccessToken(oAuth2Client, callback); |     if (err) return getAccessToken(oAuth2Client, callback); | ||||||
| @@ -20,9 +22,10 @@ function authorize(credentials, callback) { | |||||||
| function getAccessToken(oAuth2Client, callback) { | function getAccessToken(oAuth2Client, callback) { | ||||||
|   const authUrl = oAuth2Client.generateAuthUrl({ |   const authUrl = oAuth2Client.generateAuthUrl({ | ||||||
|     access_type: "offline", |     access_type: "offline", | ||||||
|     scope: SCOPES, |     scope: ["https://www.googleapis.com/auth/drive"], | ||||||
|   }); |   }); | ||||||
|   console.log("Authorize this app by visiting this url:", authUrl); |   console.log("Authorize this app by visiting this url:", authUrl); | ||||||
|  |   open(authUrl) | ||||||
|   const rl = readline.createInterface({ |   const rl = readline.createInterface({ | ||||||
|     input: process.stdin, |     input: process.stdin, | ||||||
|     output: process.stdout, |     output: process.stdout, | ||||||
| @@ -41,24 +44,47 @@ function getAccessToken(oAuth2Client, callback) { | |||||||
|   }); |   }); | ||||||
| }; | }; | ||||||
|  |  | ||||||
| const CREDENTIAL = require("../index").google_drive_credential | module.exports.drive_backup = () => { | ||||||
| module.exports.drive_backup = (parent_id) => { |   const file_json = require("../new_script/backups").Drive_backup() | ||||||
|  |   console.log(file_json) | ||||||
|  |   const parent_id = file_json.id | ||||||
|  |   const path_file = file_json.file_path | ||||||
|  |   const name_d = file_json.file_name; | ||||||
|  |    | ||||||
|  |   const gd_secret = ''; | ||||||
|  |   console.log(gd_secret) | ||||||
|   function upload_backup(auth) { |   function upload_backup(auth) { | ||||||
|     const bds_backup = require("../backup").Drive_backup(); |  | ||||||
|     const drive = google.drive({version: "v3", auth}); |     const drive = google.drive({version: "v3", auth}); | ||||||
|     if (parent_id == undefined){var fileMetadata = {"name": bds_backup.file_name,};console.log("Your backup will be saved to My Drive")} else {var fileMetadata = {"name": bds_backup.file_name,parents: [parent_id]};}; |     if (parent_id === undefined){ | ||||||
|     var media = {mimeType: "application/octet-stream",body: fs.createReadStream(bds_backup.file_dir)}; |       var fileMetadata = { | ||||||
|     drive.files.create({resource: fileMetadata, media: media, fields: "id"}, function (err, file) { |         name: name_d | ||||||
|       if (err) {console.error(err);} else { |       } | ||||||
|         global.backup_id = file.data.id; |       console.log("Your backup will be saved to My Drive") | ||||||
|         console.log("File: ", file.data.id);} |     } else { | ||||||
|  |       var fileMetadata = { | ||||||
|  |         name: name_d, | ||||||
|  |         parents: [parent_id] | ||||||
|  |       } | ||||||
|  |     }; | ||||||
|  |     var media = { | ||||||
|  |       mimeType: "application/octet-stream", | ||||||
|  |       body: fs.createReadStream(path_file) | ||||||
|  |     } | ||||||
|  |     drive.files.create({ | ||||||
|  |       resource: fileMetadata, | ||||||
|  |       media: media, | ||||||
|  |       fields: "id" | ||||||
|  |     }, function (err, file) { | ||||||
|  |       if (err) console.error(err) | ||||||
|  |       else {global.backup_id = file.data.id;console.log("File: ", file.data.id);} | ||||||
|     }); |     }); | ||||||
|   } |   } | ||||||
|   return authorize(JSON.parse(CREDENTIAL), upload_backup); |   return authorize(gd_secret, upload_backup); | ||||||
|   // End Upload Backup |   // End Upload Backup | ||||||
| }; | }; | ||||||
|  |  | ||||||
| module.exports.mcpe = () => { | module.exports.mcpe = () => { | ||||||
|  |   const gd_secret = JSON.parse(require("../index").google_drive_credential) | ||||||
|   global.mcpe_file_end = false; |   global.mcpe_file_end = false; | ||||||
|   function download_mcpe(auth) { |   function download_mcpe(auth) { | ||||||
|       const drive = google.drive({version: "v3", auth}); |       const drive = google.drive({version: "v3", auth}); | ||||||
| @@ -76,5 +102,5 @@ module.exports.mcpe = () => { | |||||||
|           if (process.stdout.isTTY) {process.stdout.clearLine();process.stdout.cursorTo(0);process.stdout.write(`Downloaded ${Math.trunc(progress)} Mbytes`);} |           if (process.stdout.isTTY) {process.stdout.clearLine();process.stdout.cursorTo(0);process.stdout.write(`Downloaded ${Math.trunc(progress)} Mbytes`);} | ||||||
|       }).pipe(dest)}); |       }).pipe(dest)}); | ||||||
|   }; |   }; | ||||||
|   return authorize(JSON.parse(CREDENTIAL), download_mcpe); |   return authorize(gd_secret, download_mcpe); | ||||||
| } | } | ||||||
|   | |||||||
| @@ -4,14 +4,15 @@ module.exports.checkUser = (USERNAME) => { | |||||||
|         var admins = fs.readFileSync(`${require("../index").bds_dir}/telegram_admin.json`, "utf-8"); |         var admins = fs.readFileSync(`${require("../index").bds_dir}/telegram_admin.json`, "utf-8"); | ||||||
|     } else { |     } else { | ||||||
|         var admins = `{"sh23_bot_not_config": {"allow": true}}`; |         var admins = `{"sh23_bot_not_config": {"allow": true}}`; | ||||||
|         console.log("All allowed") |         console.warn("All allowed") | ||||||
|  |         console.log(`Create file in with name: ${require("../index").bds_dir}/telegram_admin.json`) | ||||||
|     } |     } | ||||||
|     var adm = JSON.parse(admins); |     var adm = JSON.parse(admins); | ||||||
|     for(index in adm){ |     for(index in adm){ | ||||||
|         if (USERNAME == index){ |         if (USERNAME == index){ | ||||||
|             return true |             return true | ||||||
|         } else if (index == "sh23_bot_not_config"){ |         } else if (index == "sh23_bot_not_config"){ | ||||||
|             console.log("Allow all") |             console.warn("Allow all") | ||||||
|             return true |             return true | ||||||
|         }; index++; |         }; index++; | ||||||
|     }; |     }; | ||||||
|   | |||||||
| @@ -1,14 +0,0 @@ | |||||||
| module.exports.Server_stop = () => { |  | ||||||
|     if (typeof bds_server_string == "undefined") |  | ||||||
|         console.log("The server is stopped!"); |  | ||||||
|      else { |  | ||||||
|         const Storage = localStorage; |  | ||||||
|         bds_server_string.stdin.write("stop\n"); |  | ||||||
|         bds_server_string.stdout.on("data", function (data){ |  | ||||||
|             if (data.includes("Quit correctly")){ |  | ||||||
|                 Storage.setItem("bds_status", false) |  | ||||||
|             }; |  | ||||||
|         }); |  | ||||||
|     }; |  | ||||||
|     return |  | ||||||
| } |  | ||||||
| @@ -56,10 +56,9 @@ bot.command("command", (ctx) =>{ | |||||||
|     const detect_log_file = fs.existsSync(bds.log_file); |     const detect_log_file = fs.existsSync(bds.log_file); | ||||||
|     bds_command(command) |     bds_command(command) | ||||||
|     if (detect_log_file){ |     if (detect_log_file){ | ||||||
|         const old = fs.readFileSync(bds.log_file, "utf8"); |         const old = bds_log_string; | ||||||
|         setTimeout(() => { |         setTimeout(() => { | ||||||
|             var out = fs.readFileSync(bds.log_file, "utf8"); |             var name = bds_log_string.replace(old, ""); | ||||||
|             var name = out.replace(old, ""); |  | ||||||
|             ctx.reply(name) |             ctx.reply(name) | ||||||
|         }, 1000);    |         }, 1000);    | ||||||
|     } else { |     } else { | ||||||
| @@ -71,12 +70,11 @@ bot.command("list", (ctx) =>{ | |||||||
|     const fs = require("fs"); |     const fs = require("fs"); | ||||||
|     const bds = require("../index"); |     const bds = require("../index"); | ||||||
|     const detect_log_file = fs.existsSync(bds.log_file); |     const detect_log_file = fs.existsSync(bds.log_file); | ||||||
|     bds_command("list") |  | ||||||
|     if (detect_log_file){ |     if (detect_log_file){ | ||||||
|         const old = fs.readFileSync(bds.log_file, "utf8"); |         bds_command("list") | ||||||
|  |         var old = bds_log_string; | ||||||
|         setTimeout(() => { |         setTimeout(() => { | ||||||
|             var out = fs.readFileSync(bds.log_file, "utf8"); |             var name = bds_log_string.replace(old, ""); | ||||||
|             var name = out.replace(old, ""); |  | ||||||
|             ctx.reply(name) |             ctx.reply(name) | ||||||
|         }, 1000);    |         }, 1000);    | ||||||
|     } else { |     } else { | ||||||
| @@ -87,18 +85,41 @@ 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>`) |     // 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) | const text = `[Minecraft for Android 1.16.201.01](https://storage.googleapis.com/bds_mcpe_files/0.16.201.01.apk) | ||||||
|  |  | ||||||
| [Minecraft for IOS](https://apps.apple.com/br/app/minecraft/id479516143) | Iphone users are not privileged | ||||||
| ` |  | ||||||
| ctx.replyWithMarkdown(text) |  | ||||||
| }); |  | ||||||
| bot.command("status", (ctx) =>{ |  | ||||||
| const bds = require("../index") |  | ||||||
| const text = `Bds CPU usage: ${bds.bds_cpu}%, Total CPU utilization: ${bds.current_cpu}% |  | ||||||
|  |  | ||||||
| Total ram memory: ${bds.ram_total} GB, Total free ram memory: ${bds.ram_free} GB |  | ||||||
| ` | ` | ||||||
| ctx.replyWithMarkdown(text) | ctx.replyWithMarkdown(text) | ||||||
| }); | }); | ||||||
|  | // bot.command("status", (ctx) =>{ | ||||||
|  | // const si = require("systeminformation"); | ||||||
|  | //         // si.cpu().then(data => {module.exports.cpu_speed = Math.trunc(data.speed)}) | ||||||
|  | //     si.mem().then(data => { | ||||||
|  | //         global.ram_free = Math.trunc(data.free / 1024 / 1024 / 1024); | ||||||
|  | //         global.ram_total = Math.trunc(data.total / 1024 / 1024 / 1024); | ||||||
|  | //         si.currentLoad().then(data => { | ||||||
|  | //             global.current_cpu = Math.trunc(data.currentload) | ||||||
|  | //             si.processes().then(data => { | ||||||
|  | //                 const list = data.list | ||||||
|  | //                 for (let pid in list) { | ||||||
|  | //                     var pids = list[pid].command | ||||||
|  | //                     if (pids.includes("bedrock_server")){global.bds_cpu = Math.trunc(list[pid].pcpu)} else if (pids.includes("server.jar")){global.bds_cpu = Math.trunc(list[pid].pcpu)} else {pid++} | ||||||
|  | //                 } | ||||||
|  | //                 si.processes().then(data => { | ||||||
|  | //                     const list = data.list | ||||||
|  | //                     for (let pid in list) { | ||||||
|  | //                         var pids = list[pid].command | ||||||
|  | //                         if (pids.includes("bedrock_server")){global.bds_cpu = Math.trunc(list[pid].pcpu)} else {pid++} | ||||||
|  | //                     } | ||||||
|  | //                     const text = `Bds CPU usage: ${bds_cpu}%, Total CPU utilization: ${current_cpu}%\n\n\nTotal ram memory: ${ram_total} GB, Total free ram memory: ${ram_free} GB` | ||||||
|  | //                     ctx.replyWithMarkdown(text); | ||||||
|  | //                     delete(bds_cpu); | ||||||
|  | //                     delete(current_cpu); | ||||||
|  | //                     delete(ram_total); | ||||||
|  | //                     delete(ram_free); | ||||||
|  | //                 }) | ||||||
|  | //             }) | ||||||
|  | //         }) | ||||||
|  | //     }) | ||||||
|  | // }); | ||||||
| bot.command("log", (ctx) => { | bot.command("log", (ctx) => { | ||||||
|     const file_log_path = require("../index").log_file; |     const file_log_path = require("../index").log_file; | ||||||
|     const fs = require("fs") |     const fs = require("fs") | ||||||
|   | |||||||
							
								
								
									
										200
									
								
								index.js
									
									
									
									
									
								
							
							
						
						
									
										200
									
								
								index.js
									
									
									
									
									
								
							| @@ -1,4 +1,5 @@ | |||||||
| console.log(`Running the Bds Maneger API in version ${require(__dirname+"/package.json").version}`) | console.log(`Running the Bds Maneger API in version ${require(__dirname+"/package.json").version}`) | ||||||
|  | var shell = require("shelljs"); | ||||||
| let blanks; | let blanks; | ||||||
| function date(fu) { | function date(fu) { | ||||||
|     var today = new Date(); |     var today = new Date(); | ||||||
| @@ -44,24 +45,27 @@ const package_root = path.join(process.cwd(), "package.json") | |||||||
| if (process.platform == "win32") { | if (process.platform == "win32") { | ||||||
|     var home = process.env.USERPROFILE; |     var home = process.env.USERPROFILE; | ||||||
|     var desktop = path.join(home, "Desktop") |     var desktop = path.join(home, "Desktop") | ||||||
|     var bds_dir = path.join(home, `bds_Server`); |     if (fs.existsSync(package_root)){ | ||||||
|     var bds_dir_bedrock = path.join(home, `bds_Server`, 'bedrock'); |         var cache_dir = path.join(home, "AppData", "Roaming", require(package_root).name) | ||||||
|     var bds_dir_java = path.join(home, `bds_Server`, 'java'); |     } else { | ||||||
|     if (fs.existsSync(package_root)){var cache_dir = path.join(home, "AppData", "Roaming", require(package_root).name)} else {console.warn(`Temporary Storages, some functions will be lost after restarting the system`);var cache_dir = path.join(process.env.TMP, `bds_tmp_configs`);} |         console.warn(`Temporary Storages, some functions will be lost after restarting the system`); | ||||||
|     var log_dir = path.join(bds_dir, "log") |         var cache_dir = path.join(process.env.TMP, `bds_tmp_configs`); | ||||||
|     var log_file = path.join(log_dir, `${date()}_Bds_log.log`) |     } | ||||||
|     var log_date = `${date()}` |  | ||||||
|     var tmp = process.env.TMP |     var tmp = process.env.TMP | ||||||
|     var system = `windows`; |     var system = `windows`; | ||||||
| } else if (process.platform == "linux") { | } else if (process.platform == "linux") { | ||||||
|     var home = process.env.HOME; |     var home = process.env.HOME; | ||||||
|     var bds_dir = path.join(home, "bds_Server"); |     if (fs.existsSync(package_root)){ | ||||||
|     var bds_dir_bedrock = path.join(home, `bds_Server`, 'bedrock'); |         var cache_dir = path.join(home, ".config", require(package_root).name); | ||||||
|     var bds_dir_java = path.join(home, `bds_Server`, 'java'); |     } else { | ||||||
|     if (fs.existsSync(package_root)){var cache_dir = path.join(home, ".config", require(package_root).name);} else {console.warn(`Temporary Storages, some functions will be lost after restarting the system`);var cache_dir = `/tmp/bds_tmp_configs`;} |         console.warn(`Temporary Storages, some functions will be lost after restarting the system`); | ||||||
|  |         var cache_dir = `/tmp/bds_tmp_configs`; | ||||||
|  |     } | ||||||
|     var file = path.join(home, ".config", "user-dirs.dirs");var data = {}; |     var file = path.join(home, ".config", "user-dirs.dirs");var data = {}; | ||||||
|     if (fs.existsSync(file)){let content = fs.readFileSync(file,"utf8");let lines = content.split(/\r?\n/g).filter((a)=> !a.startsWith("#"));for(let line of lines){let i = line.indexOf("=");if(i >= 0){try{data[line.substring(0,i)] = JSON.parse(line.substring(i + 1))}catch(e){}}}};if(data["XDG_DESKTOP_DIR"]){var desktop = data["XDG_DESKTOP_DIR"];desktop = desktop.replace(/\$([A-Za-z\-\_]+)|\$\{([^\{^\}]+)\}/g, (_, a, b) => (process.env[a || b] || ""))}else{var desktop = "/tmp"} |     if (fs.existsSync(file)){let content = fs.readFileSync(file,"utf8");let lines = content.split(/\r?\n/g).filter((a)=> !a.startsWith("#"));for(let line of lines){let i = line.indexOf("=");if(i >= 0){try{data[line.substring(0,i)] = JSON.parse(line.substring(i + 1))}catch(e){}}}};if(data["XDG_DESKTOP_DIR"]){var desktop = data["XDG_DESKTOP_DIR"];desktop = desktop.replace(/\$([A-Za-z\-\_]+)|\$\{([^\{^\}]+)\}/g, (_, a, b) => (process.env[a || b] || ""))}else{var desktop = "/tmp"} | ||||||
|     var log_dir = path.join(bds_dir, "log");var log_file = path.join(log_dir, `${date()}_Bds_log.log`);var log_date = `${date()}`;var tmp = `/tmp`;var system = `linux`; |      | ||||||
|  |     var tmp = `/tmp`; | ||||||
|  |     var system = `linux`; | ||||||
| } else if (process.platform == "darwin") { | } else if (process.platform == "darwin") { | ||||||
|     require("open")("https://github.com/Bds-Maneger/Bds_Maneger/wiki/systems-support#a-message-for-mac-os-users") |     require("open")("https://github.com/Bds-Maneger/Bds_Maneger/wiki/systems-support#a-message-for-mac-os-users") | ||||||
|     console.error("Please use Windows or Linux MacOS Not yet supported") |     console.error("Please use Windows or Linux MacOS Not yet supported") | ||||||
| @@ -70,42 +74,93 @@ if (process.platform == "win32") { | |||||||
|     console.log(`Please use an operating system (OS) compatible with Minecraft Bedrock Server ${process.platform} is not supported`); |     console.log(`Please use an operating system (OS) compatible with Minecraft Bedrock Server ${process.platform} is not supported`); | ||||||
|     process.exit(2021) |     process.exit(2021) | ||||||
| }; | }; | ||||||
| var shell = require("shelljs"); | // --------- | ||||||
| if (!(fs.existsSync(cache_dir))){ | // --------- | ||||||
|     console.log(`Creating a folder for Storage in ${cache_dir}`); | var bds_dir = path.join(home, "bds_Server"); | ||||||
|     shell.mkdir("-p", cache_dir); | var bds_dir_bedrock = path.join(bds_dir, 'bedrock'); | ||||||
| } | var bds_dir_java = path.join(bds_dir, 'java'); | ||||||
| // e | var bds_dir_backup = path.join(bds_dir, 'backups'); | ||||||
|  | module.exports.backup_folder = bds_dir_backup | ||||||
|  |  | ||||||
| if (!(fs.existsSync(bds_dir))){ | if (!(fs.existsSync(bds_dir))){ | ||||||
|     console.log("Creating the bds directory") |     console.log("Creating the bds directory") | ||||||
|     shell.mkdir("-p", bds_dir); |     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, "utf-8")) | ||||||
|  | } else { | ||||||
|  |     const _config = `{ | ||||||
|  |         "bds_platform": "bedrock", | ||||||
|  |         "telegram_token": null | ||||||
|  |     }` | ||||||
|  |     var bds_config = JSON.parse(_config) | ||||||
|  |     fs.writeFileSync(bds_config_file, _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); | ||||||
|  | } | ||||||
|  | // e | ||||||
| if (!(fs.existsSync(bds_dir_java))){ | if (!(fs.existsSync(bds_dir_java))){ | ||||||
|     console.log("Creating the bds directory to Java") |     console.log("Creating the bds directory to Java") | ||||||
|     shell.mkdir("-p", bds_dir_java); |     fs.mkdirSync(bds_dir_java) | ||||||
|  |     if (!(fs.existsSync(bds_dir_java))) shell.mkdir("-p", bds_dir_java); | ||||||
| } | } | ||||||
| if (!(fs.existsSync(bds_dir_bedrock))){ | if (!(fs.existsSync(bds_dir_bedrock))){ | ||||||
|     console.log("Creating the bds directory to Bedrock") |     console.log("Creating the bds directory to Bedrock") | ||||||
|     shell.mkdir("-p", bds_dir_bedrock); |     fs.mkdirSync(bds_dir_bedrock) | ||||||
|  |     if (!(fs.existsSync(bds_dir_bedrock))) shell.mkdir("-p", bds_dir_bedrock); | ||||||
| } | } | ||||||
| // e | // e | ||||||
| if (fs.existsSync(log_dir)){ | if (!(fs.existsSync(log_dir))){ | ||||||
|     if (!fs.existsSync(log_dir)){ |     if (!fs.existsSync(log_dir)){ | ||||||
|         console.log("Creating the bds log dir") |         console.log(`Creating the bds log dir (${log_dir})`) | ||||||
|         shell.mkdir("-p", log_dir); |         fs.mkdirSync(log_dir) | ||||||
|  |         if (!(fs.existsSync(log_dir))) shell.mkdir("-p", log_dir) | ||||||
|     }; |     }; | ||||||
| }; | }; | ||||||
| // e | // e | ||||||
| if (require("fs").existsSync(`${bds_dir}/telegram_token.txt`)){module.exports.token = require("fs").readFileSync(`${bds_dir}/telegram_token.txt`, "utf8").replaceAll("\n", "");} else {module.exports.token = undefined;} | 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; | ||||||
|  | } | ||||||
|  |  | ||||||
| // Depacretd function | module.exports.telegram_token_save = (token) =>{ | ||||||
| module.exports.Storage = () => {var localStorage = require("node-localstorage").localStorage;return new localStorage(`${cache_dir}/Local_Storage`)();} |     fs.writeFileSync(`${bds_dir}/telegram_token.txt`, token); | ||||||
|  |     return "OK" | ||||||
| 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 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`);} | if (typeof localStorage === "undefined"){ | ||||||
| if (process.env.JAVA_ENABLE !== undefined){localStorage.setItem('bds_edititon', 'java');}else{localStorage.setItem('bds_edititon', 'bedrock');} |     var localStorageS = require("node-localstorage").LocalStorage; | ||||||
|  |     global.localStorage = new localStorageS(`${cache_dir}/Local_Storage`); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // Java or Bedrock | ||||||
|  | if (process.env.JAVA_ENABLE !== undefined){ | ||||||
|  |     localStorage.setItem('bds_edititon', 'java'); | ||||||
|  | }else{ | ||||||
|  |     localStorage.setItem('bds_edititon', 'bedrock'); | ||||||
|  | } | ||||||
|  |  | ||||||
| if (process.env.BDS_MONI == blanks){process.env.BDS_MONI = "false"} | if (process.env.BDS_MONI == blanks){process.env.BDS_MONI = "false"} | ||||||
| if (process.env.ENABLE_BDS_API == blanks){process.env.ENABLE_BDS_API = "false"} | if (process.env.ENABLE_BDS_API == blanks){process.env.ENABLE_BDS_API = "false"} | ||||||
| @@ -114,13 +169,37 @@ if (process.env.ENABLE_BDS_API == blanks){process.env.ENABLE_BDS_API = "false"} | |||||||
| // Fetchs | // Fetchs | ||||||
| fetch("https://raw.githubusercontent.com/Bds-Maneger/Raw_files/main/credentials.json").then(response => response.text()).then(gd_cre => { | fetch("https://raw.githubusercontent.com/Bds-Maneger/Raw_files/main/credentials.json").then(response => response.text()).then(gd_cre => { | ||||||
|     module.exports.google_drive_credential = gd_cre |     module.exports.google_drive_credential = gd_cre | ||||||
|     module.exports.drive_backup = require("./global/auth").drive_backup |  | ||||||
|     module.exports.mcpe_file = require("./global/auth").mcpe |     module.exports.mcpe_file = require("./global/auth").mcpe | ||||||
|  |     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]}`;var out = `${out}\n <option value=\"${html}\">${html}</option>`;v++;}; | fetch("https://raw.githubusercontent.com/Bds-Maneger/Raw_files/main/Server.json").then(response => response.json()).then(rawOUT => { | ||||||
|     module.exports.version_select = out.replaceAll(undefined, "");module.exports.version_raw = Object.getOwnPropertyNames(rawOUT.bedrock);module.exports.bds_latest = rawOUT.bedrock_lateste; |     const versions = Object.getOwnPropertyNames(rawOUT.bedrock); | ||||||
|     const enable_api = process.env.ENABLE_BDS_API.includes("true");if (enable_api){if (typeof bds_api_start === "undefined"){require("./API/api")();require("./API/log")();require("./API/remote_access")()} else {console.log(`API already started`)}} else {console.warn(`The API via http is disabled, for more information, visit https://docs.srherobrine23.com/enable_bds_requests.html`)} |     for (let v in versions){ | ||||||
|     module.exports.get_version = (type) => {if (type == "raw")return rawOUT.Versions; else return out.replaceAll(undefined, "");} |         var html = `${versions[v]}`; | ||||||
|  |         module.exports.version_select += `<option value=\"${html}\">${html}</option>\n`; | ||||||
|  |         v++; | ||||||
|  |     }; | ||||||
|  |     module.exports.bedrock_all_versions = Object.getOwnPropertyNames(rawOUT.bedrock); | ||||||
|  |     module.exports.java_all_versions = Object.getOwnPropertyNames(rawOUT.java); | ||||||
|  |     module.exports.bds_latest = rawOUT.bedrock_lateste; | ||||||
|  |     module.exports.bedrock_latest = rawOUT.bedrock_lateste; | ||||||
|  |     module.exports.java_latest = rawOUT.java_lateste; | ||||||
|  |  | ||||||
|  |     if (process.env.ENABLE_BDS_API.includes("true")){ | ||||||
|  |         if (typeof bds_api_start === "undefined"){ | ||||||
|  |             require("./API/api")(); | ||||||
|  |             require("./API/log")(); | ||||||
|  |             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`) | ||||||
|  |     } | ||||||
|  |     module.exports.get_version = (type) => { | ||||||
|  |         if (type == "raw") | ||||||
|  |             return rawOUT.Versions; | ||||||
|  |         else | ||||||
|  |             return require("./").version_select; | ||||||
|  |     } | ||||||
| }) | }) | ||||||
| // Fetchs | // Fetchs | ||||||
|  |  | ||||||
| @@ -147,40 +226,17 @@ 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.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 | module.exports.date = date | ||||||
| module.exports.command = require("./global/command").command | module.exports.command = require("./global/command").command | ||||||
| module.exports.stop = require("./global/stop").Server_stop | // module.exports.stop = require("./global/stop").Server_stop | ||||||
|  |  | ||||||
| const bds_config_file = path.join(bds_dir, "bds_config.json") | // New management method | ||||||
| if (fs.existsSync(bds_config_file)){ | module.exports.start = require("./new_script/basic_server").start | ||||||
|     var bds_config = JSON.parse(fs.readFileSync(bds_config_file, "utf-8")) | module.exports.stop = require("./new_script/basic_server").stop | ||||||
| } else { | module.exports.backup = require("./new_script/backups").World_BAckup | ||||||
|     const _config = `{"bds_platform": "bedrock"}` | module.exports.detect = require("./new_script/detect") | ||||||
|     // fs.writeFileSync(_config, bds_config_file) | module.exports.bds_detect = require("./new_script/detect") | ||||||
|     fs.writeFileSync(bds_config_file,_config) | module.exports.version_Download = require("./new_script/bds_download") | ||||||
|     var bds_config = JSON.parse(_config) | 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 | ||||||
| // Platform selection in the most primitive way | module.exports.set_config = require("./new_script/bds_settings").config | ||||||
| const plataforma = bds_config.bds_platform; | module.exports.get_config = require("./new_script/bds_settings").get_config | ||||||
| if (plataforma === 'bedrock'){ |  | ||||||
|     module.exports.bds_plataform = `bedrock` |  | ||||||
|     module.exports.detect = require("./bedrock/detect_bds").bds_detect |  | ||||||
|     module.exports.start = require("./bedrock/start").Server_start |  | ||||||
|     module.exports.backup = require("./bedrock/backup").World_BAckup |  | ||||||
|     module.exports.kill = require("./bedrock/kill").bds_kill |  | ||||||
|     module.exports.version_Download = require("./bedrock/download") |  | ||||||
|     module.exports.set_config = require("./bedrock/bds_settings").config |  | ||||||
|     module.exports.get_config = require("./bedrock/bds_settings").get_config |  | ||||||
|     module.exports.config_example = require("./bedrock/bds_settings").config_example |  | ||||||
|     module.exports.world_dir = path.join(bds_dir, "worlds") |  | ||||||
| } else { |  | ||||||
|     module.exports.bds_plataform = `java` |  | ||||||
|     module.exports.detect = require("./java/detect_bds").bds_detect |  | ||||||
|     module.exports.start = require("./java/start").Server_start |  | ||||||
|     module.exports.backup = require("./java/backup").World_BAckup |  | ||||||
|     module.exports.kill = require("./java/kill").bds_kill |  | ||||||
|     module.exports.version_Download = require("./java/download") |  | ||||||
|     module.exports.set_config = require("./java/bds_settings").config |  | ||||||
|     module.exports.get_config = require("./java/bds_settings").get_config |  | ||||||
|     module.exports.config_example = require("./java/bds_settings").config_example |  | ||||||
|     module.exports.world_dir = path.join(bds_dir, "worlds") |  | ||||||
| } |  | ||||||
|   | |||||||
| @@ -1,68 +0,0 @@ | |||||||
| module.exports.World_BAckup = () => { |  | ||||||
|     if (process.platform == "win32") { |  | ||||||
|          |  | ||||||
|         var dd = String(today.getDate()).padStart(2, "0"); |  | ||||||
|         var mm = String(today.getMonth() + 1).padStart(2, "0"); |  | ||||||
|         var yyyy = today.getFullYear(); |  | ||||||
|         var hour = today.getHours(); |  | ||||||
|         var minu = today.getMinutes(); |  | ||||||
|         today = `Date_${yyyy}-${mm}-${dd}(Hour_${hour}-Minutes_${minu})`; |  | ||||||
|         var name = `${process.env.USERPROFILE}/Desktop/bds_backup_World_${today}.zip` |  | ||||||
|         var dir_zip = `${require("../index").bds_dir}/worlds/` |  | ||||||
|     } else if (process.platform == "linux") { |  | ||||||
|          |  | ||||||
|         var dd = String(today.getDate()).padStart(2, "0"); |  | ||||||
|         var mm = String(today.getMonth() + 1).padStart(2, "0"); |  | ||||||
|         var yyyy = today.getFullYear(); |  | ||||||
|         var hour = today.getHours(); |  | ||||||
|         var minu = today.getMinutes(); |  | ||||||
|         today = `Date_${yyyy}-${mm}-${dd} Hour_${hour}-Minutes_${minu}`; |  | ||||||
|         var name = `${process.env.HOME}/bds_backup_World_${today}.zip` |  | ||||||
|         var dir_zip = `${require("../index").bds_dir_bedrock}/worlds/` |  | ||||||
|     }; /* End Files name */ |  | ||||||
|     /* Compress the folders */ |  | ||||||
|     var AdmZip = require("adm-zip"); |  | ||||||
|     var zip = new AdmZip(); |  | ||||||
|     zip.addLocalFolder(dir_zip); /* var willSendthis = zip.toBuffer(); */ |  | ||||||
|     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); /* Zip file destination */ |  | ||||||
|     console.log("Backup Sucess") |  | ||||||
|     /* Compress the folders */ |  | ||||||
|     return "Sucess" |  | ||||||
| }; |  | ||||||
|  |  | ||||||
| module.exports.Drive_backup = () => { |  | ||||||
|     if (require("./detect_bds").bds_detect()){ |  | ||||||
|         require("../global/stop").Server_stop() |  | ||||||
|     } |  | ||||||
|     const bds = require("../index"); |  | ||||||
|     const path = require("path"); |  | ||||||
|     if (localStorage.getItem('bds_edititon') === 'java') |  | ||||||
|         var dir_zip = path.join(bds.bds_dir_java, "world"); |  | ||||||
|     else |  | ||||||
|         var dir_zip = path.join(bds.bds_dir_bedrock, "worlds"); |  | ||||||
|     const today = bds.date(); |  | ||||||
|     const file_name = `bds_backup_World_${today}.zip` |  | ||||||
|     const name = path.join(bds.tmp_dir, file_name) |  | ||||||
|     /* Compress the folders */ |  | ||||||
|     var AdmZip = require("adm-zip"); |  | ||||||
|     var zip = new AdmZip(); |  | ||||||
|     zip.addLocalFolder(dir_zip); /* var willSendthis = zip.toBuffer(); */ |  | ||||||
|     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); /* Zip file destination */ |  | ||||||
|     console.log("Backup Sucess") |  | ||||||
|     /* Compress the folders */ |  | ||||||
| return JSON.parse(`{ |  | ||||||
|     "file_dir": "${name.replaceAll("\\", "/")}", |  | ||||||
|     "file_name": "${file_name}" |  | ||||||
| }`) |  | ||||||
| }; |  | ||||||
|  |  | ||||||
| @@ -1,129 +0,0 @@ | |||||||
| function bds_config(json_config){ |  | ||||||
| var Server_Config = `${require("../index").bds_dir_java}/server.properties` |  | ||||||
| const cpuCount = require("os").cpus().length; |  | ||||||
| var fs = require("fs") |  | ||||||
| if (2 < cpuCount - 2) var CPU = cpuCount - 2; else var CPU = cpuCount; |  | ||||||
| if (json_config.includes(".json")){var config = JSON.parse(fs.readFileSync(json_config, "utf8"))} else var config = JSON.parse(json_config) |  | ||||||
|  |  | ||||||
| // description |  | ||||||
| if (config.description == undefined){var description_name = `Dedicated Server`;} else {var description_name = config.description;}; |  | ||||||
|  |  | ||||||
| // Level Name |  | ||||||
| if (config.name == undefined){var level_name = `Bedrock level`;} else {var level_name = config.name;}; |  | ||||||
|  |  | ||||||
| // gamemode |  | ||||||
| if (config.gamemode == undefined){var gamemode = `survival`;} else {var gamemode = config.gamemode;}; |  | ||||||
|  |  | ||||||
| // Difficulty |  | ||||||
| if (config.difficulty == undefined){var difficulty = `easy`;} else {var difficulty = config.difficulty;}; |  | ||||||
|  |  | ||||||
| // cheats |  | ||||||
| if (config.cheats == undefined){var allow_cheats = false;} else {var allow_cheats = config.cheats;}; |  | ||||||
|  |  | ||||||
| // Maximo de Jogadores |  | ||||||
| if (config.players == undefined){var max_players = 10;} else {var max_players = config.players;}; |  | ||||||
|  |  | ||||||
| // Xbox authentication outside the internal network |  | ||||||
| if (config.xbox == undefined){var online_mode = true;} else {var online_mode = config.xbox;}; |  | ||||||
|  |  | ||||||
| // Whitelist |  | ||||||
| if (config.white_list == undefined){var white_list = false;} else {var white_list = config.white_list;}; |  | ||||||
|  |  | ||||||
| // Server Port IPv4 |  | ||||||
| if (config.port == undefined){var server_port = 19132;} else {var server_port = config.port;}; |  | ||||||
|  |  | ||||||
| // Server Port IPv6 |  | ||||||
| if (config.port6 == undefined){var server_portv6 = 19133;} else {var server_portv6 = config.port6;}; |  | ||||||
|  |  | ||||||
| // Default player permission |  | ||||||
| if (config.player_permission == undefined){var player_permission = `member`;} else {var player_permission = config.player_permission;}; |  | ||||||
| const cpuCountTick = require("os").cpus().length; |  | ||||||
| if (2 >= cpuCountTick) var tick = 2;else if (4 >= cpuCountTick) var tick = 4;else if (6 >= cpuCountTick) var tick = 6;else if (8 >= cpuCountTick) var tick = 8; else if (10 >= cpuCountTick) var tick = 10;else var tick = 12 |  | ||||||
|  |  | ||||||
| /*Save Files*/ |  | ||||||
| var config_file_content = ` |  | ||||||
| enable-jmx-monitoring=false |  | ||||||
| rcon.port=25575 |  | ||||||
| level-seed= |  | ||||||
| gamemode=${gamemode} |  | ||||||
| enable-command-block=false |  | ||||||
| enable-query=false |  | ||||||
| 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 config_file_content}; |  | ||||||
|  |  | ||||||
| function bds_get_config(){ |  | ||||||
|     var fs = require("fs"); |  | ||||||
|     const propertiesToJSON = require("properties-to-json"); |  | ||||||
|     if (localStorage.getItem("bds_edititon") === 'java') |  | ||||||
|     var Server_Config = `${require("../index").bds_dir_java}/server.properties` |  | ||||||
| else |  | ||||||
|     var Server_Config = `${require("../index").bds_dir_bedrock}/server.properties` |  | ||||||
|     const inGET = fs.readFileSync(Server_Config, "utf8").replaceAll("-","_"); |  | ||||||
|     return propertiesToJSON(inGET); |  | ||||||
| }; |  | ||||||
| module.exports.config_example = () =>{ |  | ||||||
| const example = `{ |  | ||||||
|     "name": "java" |  | ||||||
|     "description": "Hello Works" |  | ||||||
|     "gamemode": "survival" |  | ||||||
|     "difficulty": "hard" |  | ||||||
|     "cheats": false |  | ||||||
|     "players": 100 |  | ||||||
|     "xbox": true |  | ||||||
|     "white_list": false |  | ||||||
|     "port": 19132 |  | ||||||
|     "port6": 19133 |  | ||||||
|     "player_permission": "member" |  | ||||||
| }` |  | ||||||
| return example |  | ||||||
| } |  | ||||||
| module.exports.config = bds_config |  | ||||||
| module.exports.get_config = bds_get_config |  | ||||||
| @@ -1,10 +0,0 @@ | |||||||
| module.exports.bds_detect = () => { |  | ||||||
|     var spawn = require("child_process").execSync; |  | ||||||
|     if (process.platform == "win32") { |  | ||||||
|         var killbds = spawn(`tasklist /fi "imagename eq server.jar" | find /i "server.jar" > nul & if not errorlevel 1 (echo 0) else (echo 1)`); |  | ||||||
|     } else if (process.platform == "linux") { |  | ||||||
|         var killbds = spawn(`ps aux|grep "jar server.jar"|grep -v 'grep'|grep -q "jar server.jar";echo $?`, {shell: true}); |  | ||||||
|     } |  | ||||||
|     //  |  | ||||||
|     if (killbds == 0){return true} else {return false}; |  | ||||||
| }; |  | ||||||
| @@ -1,27 +0,0 @@ | |||||||
| 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 versions_get = versions.java[Vdown].url |  | ||||||
|         var mine_name = `server.jar` |  | ||||||
|  |  | ||||||
|         console.log("Starting download") |  | ||||||
|         const exec = require("child_process").exec |  | ||||||
|         localStorage.setItem("bds_server_version", Vdown);         |  | ||||||
|         var downloadBDSchild = exec(`curl ${versions_get} --output ${mine_name}`, { |  | ||||||
|             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`); |  | ||||||
|             } |  | ||||||
|         }) |  | ||||||
|     }) |  | ||||||
| } |  | ||||||
							
								
								
									
										25
									
								
								java/kill.js
									
									
									
									
									
								
							
							
						
						
									
										25
									
								
								java/kill.js
									
									
									
									
									
								
							| @@ -1,25 +0,0 @@ | |||||||
| function bds_kill() { |  | ||||||
|     var spawn = require("child_process").exec; |  | ||||||
|     const Storage = localStorage |  | ||||||
|     if (require("./detect_bds").bds_detect()){ |  | ||||||
|  |  | ||||||
|         if (process.platform == "win32") { |  | ||||||
|             var killbds = spawn(`tasklist /fi "imagename eq server.jar" | find /i "server.jar" > nul & if not errorlevel 1 (taskkill /f /im "server.jar" > nul && exit 0) else (exit 1)`); |  | ||||||
|         } else if (process.platform == "linux") { |  | ||||||
|             var killbds = spawn(`kill $(ps aux|grep -v "grep"|grep "server.jar"|awk '{print $2}')`, {shell: true}); |  | ||||||
|         }; |  | ||||||
|  |  | ||||||
|         killbds.on("exit", function () { |  | ||||||
|             killbds.stdin.end(); |  | ||||||
|         }); |  | ||||||
|         Storage.setItem("bds_status", false); |  | ||||||
|         return true |  | ||||||
|     } else { |  | ||||||
|         Storage.setItem("bds_status", false); |  | ||||||
|         return false |  | ||||||
|     }; |  | ||||||
| }; |  | ||||||
|  |  | ||||||
| module.exports = { |  | ||||||
|     bds_kill: bds_kill |  | ||||||
| }; |  | ||||||
| @@ -1,33 +0,0 @@ | |||||||
| module.exports.Server_start = () => { |  | ||||||
|     const bds = require("../index") |  | ||||||
|     const Storage = localStorage; |  | ||||||
|     var exec = require("child_process").exec; |  | ||||||
|     if (!(bds.detect())){ |  | ||||||
|         if (require('command-exists').sync('java')){ |  | ||||||
|             var serverstated = exec(`java -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")} |  | ||||||
|         } |  | ||||||
|         var logConsoleStream = require("fs").createWriteStream(bds.log_file, {flags: "a"}); |  | ||||||
|         Storage.setItem("old_log_file", bds.log_file) |  | ||||||
|         serverstated.stdout.pipe(logConsoleStream); |  | ||||||
|         serverstated.stdout.on("data", function(data){ |  | ||||||
|             if (data.includes("agree", "EULA")){ |  | ||||||
|                 const path = require('path'); |  | ||||||
|                 require('open')("https://account.mojang.com/documents/minecraft_eula"); |  | ||||||
|                 require('fs').writeFileSync(path.join(bds.bds_dir_java, "eula.txt"), "eula=true") |  | ||||||
|                 setTimeout(() => { |  | ||||||
|                     process.exit(0) |  | ||||||
|                 }, 1000); |  | ||||||
|             } |  | ||||||
|         }) |  | ||||||
|         if (typeof bds_log_string !== "undefined"){delete(bds_log_string)} |  | ||||||
|         serverstated.stdout.on("data", function(data){global.bds_log_string += data}) |  | ||||||
|         Storage.setItem("bds_status", true); |  | ||||||
|         global.bds_server_string = serverstated; |  | ||||||
|         return serverstated; |  | ||||||
|     } else { |  | ||||||
|         console.warn(`You already have a server running`); |  | ||||||
|         return `You already have a server running`; |  | ||||||
|     } |  | ||||||
| } |  | ||||||
							
								
								
									
										81
									
								
								new_script/backups.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										81
									
								
								new_script/backups.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,81 @@ | |||||||
|  | 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`) | ||||||
|  |     if (bds.platform === "bedrock"){ | ||||||
|  |         var dir_zip = path.join(bds_dir_bedrock, "worlds") //`${require("../index").}/worlds/` | ||||||
|  |     } else { | ||||||
|  |         const world_name = JSON.parse(java_pro(fs.readFileSync(path.join(bds.bds_dir_java, "server.properties"), "utf-8").replaceAll("-", "_"))).level_name | ||||||
|  |         var dir_zip = path.join(bds.bds_dir_java, world_name) //`${require("../index").bds_dir_bedrock}/${world_name}/` | ||||||
|  |     } | ||||||
|  |     /** | ||||||
|  |      * 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`) | ||||||
|  |     if (bds.platform === "bedrock"){ | ||||||
|  |         var dir_zip = path.join(bds.bds_dir_bedrock, "worlds") //`${require("../index").}/worlds/` | ||||||
|  |     } else { | ||||||
|  |         const world_name = JSON.parse(java_pro(fs.readFileSync(path.join(bds.bds_dir_java, "server.properties"), "utf-8").replaceAll("-", "_"))).level_name | ||||||
|  |         var dir_zip = path.join(bds.bds_dir_java, world_name) //`${require("../index").bds_dir_bedrock}/${world_name}/` | ||||||
|  |     } | ||||||
|  |     /** | ||||||
|  |      * Before we can start it is good for the server not to have a Corrupted Backup | ||||||
|  |      * this is only necessary once after the server has started manually | ||||||
|  |     */ | ||||||
|  |     if (bds.bds_detect()){bds.stop()} | ||||||
|  |     global.status_b = true | ||||||
|  |     var zip = new AdmZip(); | ||||||
|  |     zip.addLocalFolder(dir_zip); | ||||||
|  |     zip.addZipComment(`Backup zip file in ${today}. \nBackup made to ${process.platform}, Free and open content for all\n\nSirherobrine23© By Bds Maneger.`); | ||||||
|  |     var zipEntries = zip.getEntries(); | ||||||
|  |     var totalfiles = zipEntries.length | ||||||
|  |     zipEntries.forEach(function(zipEntry) { | ||||||
|  |         totalfiles-- | ||||||
|  |         console.log(totalfiles) | ||||||
|  |         if (totalfiles === 0){ | ||||||
|  |             status_b = false | ||||||
|  |         }    | ||||||
|  |     }); | ||||||
|  |     zip.writeZip(name); | ||||||
|  |     let es = 0; | ||||||
|  |     for(es == "-0";es++;){ | ||||||
|  |         if (!(status_b)) break | ||||||
|  |     } | ||||||
|  |     delete(status_b) | ||||||
|  |     const js_ = { | ||||||
|  |         "file_path": name, | ||||||
|  |         "file_name": `bds_backup_World_${today}.zip`, | ||||||
|  |         "id": undefined | ||||||
|  |     } | ||||||
|  |     return js_ | ||||||
|  | }; | ||||||
|  |  | ||||||
							
								
								
									
										79
									
								
								new_script/basic_server.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										79
									
								
								new_script/basic_server.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,79 @@ | |||||||
|  | module.exports.start = () => { | ||||||
|  |     const bds = require("../index") | ||||||
|  |     const Storage = localStorage; | ||||||
|  |     const exec = require("child_process").exec; | ||||||
|  |     const fs = require('fs') | ||||||
|  |  | ||||||
|  |  | ||||||
|  |     if (!(bds.detect())){ | ||||||
|  |         const plat = bds.platform | ||||||
|  |         if (plat === "bedrock"){ | ||||||
|  |             if (process.platform == "win32"){ | ||||||
|  |                 var start_server = exec(`bedrock_server.exe`, {cwd: bds.bds_dir_bedrock}); | ||||||
|  |             } else if (process.platform == "linux"){ | ||||||
|  |                 var start_server = exec(`chmod 777 bedrock_server && ./bedrock_server`, {env: {PATH: process.env.PATH, LD_LIBRARY_PATH: bds.bds_dir_bedrock}, cwd: bds.bds_dir_bedrock}); | ||||||
|  |             } else { | ||||||
|  |                 process.exit(210) | ||||||
|  |             } | ||||||
|  |         } else { | ||||||
|  |             if (require('command-exists').sync('java')){ | ||||||
|  |                 var start_server = exec(`java -jar server.jar nogui`, {cwd: bds.bds_dir_java}); | ||||||
|  |             } 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, "utf-8").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"){delete(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 | ||||||
|  | } | ||||||
							
								
								
									
										88
									
								
								new_script/bds_download.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										88
									
								
								new_script/bds_download.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,88 @@ | |||||||
|  | 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 => { | ||||||
|  |         if (bds.platform === "bedrock"){ | ||||||
|  |             const system = bds.system | ||||||
|  |             var mine_name = `bedrock.zip` | ||||||
|  |             var server_DIR = bds.bds_dir_bedrock; | ||||||
|  |             if (system === 'linux'){ | ||||||
|  |                 var versions_get = versions.bedrock[Vdown].url_linux; | ||||||
|  |             } else { | ||||||
|  |                 var versions_get = versions.bedrock[Vdown].url_windows; | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             console.log("Starting download") | ||||||
|  |             const exec = require("child_process").exec | ||||||
|  |             localStorage.setItem("bds_server_version", Vdown);         | ||||||
|  |             var downloadBDSchild = exec(`curl ${versions_get} --output ${mine_name}`, { | ||||||
|  |                 cwd: `${bds.tmp_dir}` | ||||||
|  |             }); | ||||||
|  |             var ZIP_FILE_PATH = `${bds.tmp_dir}/${mine_name}`; | ||||||
|  |             downloadBDSchild.stdout.on("data", function(data){ | ||||||
|  |                 console.log(data) | ||||||
|  |             }) | ||||||
|  |             downloadBDSchild.on("exit", function (code) { | ||||||
|  |                 if (code === 0) { | ||||||
|  |                     console.log(`Download zip file success`); | ||||||
|  |  | ||||||
|  |                     var AdmZip = require("adm-zip"); | ||||||
|  |                     const fs = require("fs") | ||||||
|  |                     if (fs.existsSync(`${server_DIR}/server.properties`)){var _old = true;var old1 = fs.readFileSync(`${server_DIR}/server.properties`, "utf-8");} | ||||||
|  |                     if (fs.existsSync(`${server_DIR}/permissions.json`)){var _old2 = true;var old2 = fs.readFileSync(`${server_DIR}/permissions.json`, "utf-8");} | ||||||
|  |                     if (fs.existsSync(`${server_DIR}/whitelist.json`)) {var _old3 = true;var old3 = fs.readFileSync(`${server_DIR}/whitelist.json`, "utf-8");} | ||||||
|  |                     if (fs.existsSync(`${server_DIR}/valid_known_packs.json`)){var _old4 = true;var old4 = fs.readFileSync(`${server_DIR}/valid_known_packs.json`, "utf-8");}; | ||||||
|  |                     // Unzip  | ||||||
|  |                     var zip = new AdmZip(ZIP_FILE_PATH); | ||||||
|  |                     var zipEntries = zip.getEntries(); | ||||||
|  |                     var totalfiles = zipEntries.length | ||||||
|  |                     zipEntries.forEach(function(zipEntry) { | ||||||
|  |                         totalfiles-- | ||||||
|  |                         if (totalfiles === 0){ | ||||||
|  |                             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) | ||||||
|  |                             } | ||||||
|  |                         }    | ||||||
|  |                     }); | ||||||
|  |                     zip.extractAllTo(server_DIR, true); | ||||||
|  |                     console.log("Downlod Sucess"); // End Unzip | ||||||
|  |                     localStorage.setItem("Downlaod_sucess", "yes") | ||||||
|  |                 } else { | ||||||
|  |                     localStorage.setItem("Download_sucess", "no") | ||||||
|  |                     throw new error(`Could not download`); | ||||||
|  |                 } | ||||||
|  |             }) | ||||||
|  |         } else { | ||||||
|  |             var versions_get = versions.java[Vdown].url | ||||||
|  |             var mine_name = `server.jar` | ||||||
|  |  | ||||||
|  |             console.log("Starting download") | ||||||
|  |             const exec = require("child_process").exec | ||||||
|  |             localStorage.setItem("bds_server_version", Vdown);         | ||||||
|  |             var downloadBDSchild = exec(`curl ${versions_get} --output ${mine_name}`, { | ||||||
|  |                 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`); | ||||||
|  |                 } | ||||||
|  |             }) | ||||||
|  |         } | ||||||
|  |     // --------------------------------------------------------- | ||||||
|  |     }) | ||||||
|  | } | ||||||
							
								
								
									
										178
									
								
								new_script/bds_settings.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										178
									
								
								new_script/bds_settings.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,178 @@ | |||||||
|  | function bds_config(json_config){ | ||||||
|  |     const bds = require("../index") | ||||||
|  |     const path = require("path") | ||||||
|  |     var fs = require("fs") | ||||||
|  |  | ||||||
|  |     if (bds.platform === 'java') var Server_Config = path.join(bds.bds_dir_java, "server.properties"); | ||||||
|  |     else var Server_Config = path.join(bds.bds_dir_bedrock, "server.properties"); | ||||||
|  |  | ||||||
|  |     const cpuCount = require("os").cpus().length; | ||||||
|  |      | ||||||
|  |     if (2 < cpuCount - 2) var CPU = cpuCount - 2; | ||||||
|  |     else var CPU = cpuCount; | ||||||
|  |      | ||||||
|  |     if (json_config.includes(".json")){ | ||||||
|  |         var config = JSON.parse(fs.readFileSync(json_config, "utf8")) | ||||||
|  |     } else var config = JSON.parse(json_config) | ||||||
|  |  | ||||||
|  |     if (config.description == undefined) var description_name = `Dedicated Server`; | ||||||
|  |     else var description_name = config.description; | ||||||
|  |  | ||||||
|  |     // Level Name | ||||||
|  |     if (config.name == undefined) var level_name = `Bedrock level`; | ||||||
|  |     else var level_name = config.name; | ||||||
|  |  | ||||||
|  |     // gamemode | ||||||
|  |     if (config.gamemode == undefined) var gamemode = `survival`; | ||||||
|  |     else var gamemode = config.gamemode; | ||||||
|  |  | ||||||
|  |     // Difficulty | ||||||
|  |     if (config.difficulty == undefined) var difficulty = `easy`; | ||||||
|  |     else var difficulty = config.difficulty; | ||||||
|  |  | ||||||
|  |     // cheats | ||||||
|  |     if (config.cheats == undefined) var allow_cheats = false; | ||||||
|  |     else var allow_cheats = config.cheats; | ||||||
|  |  | ||||||
|  |     // Maximo de Jogadores | ||||||
|  |     if (config.players == undefined) var max_players = 10; | ||||||
|  |     else var max_players = config.players; | ||||||
|  |  | ||||||
|  |     // Xbox authentication outside the internal network | ||||||
|  |     if (config.xbox == undefined) var online_mode = true; | ||||||
|  |     else var online_mode = config.xbox; | ||||||
|  |  | ||||||
|  |     // Whitelist | ||||||
|  |     if (config.white_list == undefined){var white_list = false;} else {var white_list = config.white_list;}; | ||||||
|  |  | ||||||
|  |     // Server Port IPv4 | ||||||
|  |     if (config.port == undefined){var server_port = 19132;} else {var server_port = config.port;}; | ||||||
|  |  | ||||||
|  |     // Server Port IPv6 | ||||||
|  |     if (config.port6 == undefined){var server_portv6 = 19133;} else {var server_portv6 = config.port6;}; | ||||||
|  |  | ||||||
|  |     // Default player permission | ||||||
|  |     if (config.player_permission == undefined) var player_permission = `member`; | ||||||
|  |     else var player_permission = config.player_permission; | ||||||
|  |      | ||||||
|  |     if (2 >= cpuCount) var tick = 2 ; | ||||||
|  |     else if (4 >= cpuCount) var tick = 4; | ||||||
|  |     else if (6 >= cpuCount) var tick = 6; | ||||||
|  |     else if (8 >= cpuCount) var tick = 8; | ||||||
|  |     else if (10 >= cpuCount) var tick = 10; | ||||||
|  |     else var tick = 12 | ||||||
|  |  | ||||||
|  | /*Save Files*/ | ||||||
|  | if (bds.platform === 'bedrock'){ | ||||||
|  |     var 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 { | ||||||
|  |     var 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 `success` | ||||||
|  | }; | ||||||
|  | function bds_get_config(){ | ||||||
|  |     var fs = require("fs"); | ||||||
|  |     const path = require("path") | ||||||
|  |     const bds = require("../index") | ||||||
|  |     const propertiesToJSON = require("properties-to-json"); | ||||||
|  |  | ||||||
|  |     if (bds.platform === "bedrock") var config_path = path.join(bds.bds_dir_bedrock, "server.properties") | ||||||
|  |     else var config_path = path.join(bds.bds_dir_java, "server.properties") | ||||||
|  |     return propertiesToJSON(fs.readFileSync(config_path, "utf8").replaceAll("-","_")); | ||||||
|  | } | ||||||
|  | module.exports.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 | ||||||
							
								
								
									
										20
									
								
								new_script/detect.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								new_script/detect.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,20 @@ | |||||||
|  | module.exports = () => { | ||||||
|  |     var spawn = require("child_process").execSync; | ||||||
|  |     const bds = require("../index") | ||||||
|  |  | ||||||
|  |     if (bds.platform === "bedrock"){ | ||||||
|  |         if (process.platform == "win32") { | ||||||
|  |             var killbds = spawn(`tasklist /fi "imagename eq server.jar" | find /i "server.jar" > nul & if not errorlevel 1 (echo 0) else (echo 1)`); | ||||||
|  |         } else if (process.platform == "linux") { | ||||||
|  |             var killbds = spawn(`ps aux|grep "jar server.jar"|grep -v 'grep'|grep -q "jar server.jar";echo $?`, {shell: true}); | ||||||
|  |         } | ||||||
|  |     } else { | ||||||
|  |         if (process.platform == "win32") { | ||||||
|  |             var killbds = spawn(`tasklist /fi "imagename eq bedrock_server.exe" | find /i "bedrock_server.exe" > nul & if not errorlevel 1 (echo 0) else (echo 1)`); | ||||||
|  |         } else if (process.platform == "linux") { | ||||||
|  |             var killbds = spawn(`ps aux|grep -v "grep"|grep "bedrock_server"|grep -q "bedrock_server";echo $?`, {shell: true}); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |     //  | ||||||
|  |     if (killbds == 0){return true} else {return false}; | ||||||
|  | }; | ||||||
							
								
								
									
										25
									
								
								new_script/kill_server.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								new_script/kill_server.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,25 @@ | |||||||
|  | module.exports = () => { | ||||||
|  |     const bds = require("../index") | ||||||
|  |     var spawn = require("child_process").exec; | ||||||
|  |     const Storage = localStorage | ||||||
|  |     if (bds.bds_detect()){ | ||||||
|  |         if (bds.platform === "bedrock"){ | ||||||
|  |             if (process.platform == "win32") var killbds = spawn(`tasklist /fi "imagename eq bedrock_server.exe" | find /i "bedrock_server.exe" > nul & if not errorlevel 1 (taskkill /f /im "bedrock_server.exe" > nul && exit 0) else (exit 1)`); | ||||||
|  |             else if (process.platform == "linux") var killbds = spawn(`kill $(ps aux|grep -v "grep"|grep "bedrock_server"|awk '{print $2}')`, {shell: true}); | ||||||
|  |         } else { | ||||||
|  |             if (process.platform == "win32") { | ||||||
|  |                 var killbds = spawn(`tasklist /fi "imagename eq server.jar" | find /i "server.jar" > nul & if not errorlevel 1 (taskkill /f /im "server.jar" > nul && exit 0) else (exit 1)`); | ||||||
|  |             } else if (process.platform == "linux") { | ||||||
|  |                 var killbds = spawn(`kill $(ps aux|grep -v "grep"|grep "server.jar"|awk '{print $2}')`, {shell: true}); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |         killbds.on("exit", function () { | ||||||
|  |             killbds.stdin.end(); | ||||||
|  |         }); | ||||||
|  |         Storage.setItem("bds_status", false); | ||||||
|  |         return true | ||||||
|  |     } else { | ||||||
|  |         Storage.setItem("bds_status", false); | ||||||
|  |         return false | ||||||
|  |     }; | ||||||
|  | }; | ||||||
							
								
								
									
										1520
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										1520
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @@ -1,6 +1,6 @@ | |||||||
| { | { | ||||||
|   "name": "bds_maneger_api", |   "name": "bds_maneger_api", | ||||||
|   "version": "1.3.0", |   "version": "1.4.2", | ||||||
|   "description": "scripts to manage minecraft bedrock server", |   "description": "scripts to manage minecraft bedrock server", | ||||||
|   "private": false, |   "private": false, | ||||||
|   "main": "index.js", |   "main": "index.js", | ||||||
| @@ -38,9 +38,10 @@ | |||||||
|     "node-localstorage": "^2.1.6", |     "node-localstorage": "^2.1.6", | ||||||
|     "open": "^7.3.1", |     "open": "^7.3.1", | ||||||
|     "properties-to-json": "^0.1.7", |     "properties-to-json": "^0.1.7", | ||||||
|  |     "qr-image": "^3.2.0", | ||||||
|     "qrcode": "^1.4.4", |     "qrcode": "^1.4.4", | ||||||
|     "shelljs": "^0.8.4", |     "shelljs": "^0.8.4", | ||||||
|     "systeminformation": "^4.34.5", |     "systeminformation": "^5.0.2", | ||||||
|     "telegraf": "^4.0.0" |     "telegraf": "^4.0.0" | ||||||
|   } |   } | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user