@ -41,6 +41,7 @@ if (arch == "x64"){
}
const path = require ( "path" )
const fs = require ( "fs" ) ;
const { error } = require ( "console" ) ;
const package _root = path . join ( process . cwd ( ) , "package.json" )
const package _root _builder = path . resolve ( "." , "resources" , "app" , "package.json" )
if ( process . platform == "win32" ) {
@ -81,6 +82,13 @@ if (process.platform == "win32") {
} ;
// ---------
// ---------
if ( typeof fetch === "undefined" ) {
global . fetch = require ( "node-fetch" )
}
if ( typeof localStorage === "undefined" ) {
var localStorageS = require ( "node-localstorage" ) . LocalStorage ;
global . localStorage = new localStorageS ( path . join ( cache _dir , ` Local_Storage ` ) ) ;
}
var bds _dir = path . join ( home , "bds_Server" ) ;
var bds _dir _bedrock = path . join ( bds _dir , 'bedrock' ) ;
var bds _dir _java = path . join ( bds _dir , 'java' ) ;
@ -98,12 +106,11 @@ const bds_config_file = path.join(bds_dir, "bds_config.json")
if ( fs . existsSync ( bds _config _file ) ) {
var bds _config = JSON . parse ( fs . readFileSync ( bds _config _file , "utf-8" ) )
} else {
const _config = ` {
const bds _config = {
"bds_platform" : "bedrock" ,
"telegram_token": null
}`
var bds _config = JSON . parse ( _config )
fs . writeFileSync ( bds _config _file , _config )
"telegram_token": "not User defined"
}
fs . writeFileSync ( bds _config _file , JSON . stringify ( bds _config ) )
}
module . exports . platform = bds _config . bds _platform
console . log ( ` Running on the \" ${ bds _config . bds _platform } \" platform ` )
@ -143,28 +150,58 @@ if (!(fs.existsSync(log_dir))){
} ;
} ;
// e
if ( require ( "fs" ) . existsSync ( ` ${ bds _dir } /telegram_token.txt ` ) ) {
module . exports . token = fs . readFileSync ( ` ${ bds _dir } /telegram_token.txt ` , "utf8" ) . replaceAll ( "\n" , "" ) ;
} else {
module . exports . token = undefined ;
/**
* with this command we can change the platform with this script
*
* bedrock change_platform("bedrock")
*
* java change_platform("java")
* @example change_platform("bedrock")
*/
function platform _update ( plate ) {
if ( plate === "java" ) true
else if ( plate === "bedrock" ) true
else throw new console . error ( ` platform not identified or does not exist, ${ plate } informed platform ` ) ;
const bds _config = path . join ( bds _dir , "bds_config.json" )
try {
const config _load = JSON . parse ( fs . readFileSync ( bds _config ) )
config _load . bds _platform = plate
fs . writeFileSync ( bds _config , JSON . stringify ( config _load ) )
console . log ( ` upgrading the bedrock ${ plate } ` )
} catch ( error ) {
throw new console . error ( ` Something happened error code: ${ error } ` ) ;
}
}
if ( ( process . env . SERVER || "bedrock" ) . includes ( "java" , "JAVA" ) ) {
platform _update ( "java" )
} else {
platform _update ( "bedrock" )
}
module . exports . telegram _token _save = ( token ) => {
fs . writeFileSync ( ` ${ bds _dir } /telegram_token.txt ` , token ) ;
return "OK"
}
if ( typeof fetch === "undefined" ) { g lobal . fetch = require ( "node-fetch" ) }
if ( typeof localStorage === "undefined" ) {
var localStorageS = require ( "node-localstorage" ) . LocalStorage ;
global . localStorage = new localStorageS ( ` ${ cache _dir } /Local_Storage ` ) ;
try {
const bds _config = path . join ( bds _dir , "bds_config.json" )
const config _load = JSON . parse ( fs . readFileSync ( bds _config ) )
config _ load . telegram _token = token
fs . writeFileSync ( bds _config , JSON . stringify ( config _load ) )
return true
} catch {
return false
}
}
// Java or Bedrock
if ( process . env . JAVA _ENABLE !== undefined ) {
localStorage . setItem ( 'bds_edititon' , 'java' ) ;
} else {
localStorage . setItem ( 'bds_edititon' , 'bedrock' ) ;
if ( require ( "fs" ) . existsSync ( path . join ( bds _dir , "telegram_token.txt" ) ) ) {
console . log ( ` We identified the old telegram token file \( ${ path . join ( bds _dir , "telegram_token.txt" ) } \) , starting the immigration process ` )
try {
const token = fs . readFileSync ( path . join ( bds _dir , "telegram_token.txt" ) , "utf-8" ) . split ( "\n" ) . join ( "" )
require ( "./index" ) . telegram _token _save ( token )
fs . rmSync ( path . join ( bds _dir , "telegram_token.txt" ) )
console . log ( ` We finished migrating the old telegram token file ` )
} catch {
throw new error ( ` It was not possible to move the old telegram token file to the new bds maneger api file ` )
}
}
if ( process . env . BDS _MONI == blanks ) { process . env . BDS _MONI = "false" }
@ -173,8 +210,23 @@ if (process.env.ENABLE_BDS_API == blanks){process.env.ENABLE_BDS_API = "false"}
// Fetchs
fetch ( "https://raw.githubusercontent.com/Bds-Maneger/Raw_files/main/credentials.json" ) . then ( response => response . text ( ) ) . then ( gd _cre => {
/**
* backup credentials and an interesting design feature, plus privacy is important
*/
module . exports . google _drive _credential = gd _cre
/**
* download the latest version of minecraft bedrock for android available, remember to use if you want ✌
*
* you are taking responsibility for that
*/
module . exports . mcpe _file = require ( "./global/auth" ) . mcpe
/**
* perform a backup of the map, some resources are still under construction in the code more works
*
* on the bedrock platform, all maps will be backed up into the "worlds" folder
*
* on the java platform the map selected in the server configuration will be backed up, any other map will have to change in the server settings to perform the backup
*/
module . exports . drive _backup = require ( "./global/auth" ) . drive _backup
} ) ;
fetch ( "https://raw.githubusercontent.com/Bds-Maneger/Raw_files/main/Server.json" ) . then ( response => response . json ( ) ) . then ( rawOUT => {
@ -209,14 +261,41 @@ fetch("https://raw.githubusercontent.com/Bds-Maneger/Raw_files/main/Server.json"
// Module export
/* Variaveis */
/**
* this variable makes available the location of the user profile directory as
*
* Linux: /home/USER/
*
* Windows: C:\\Users\\USER\\
*
* MacOS: not supported
*/
module . exports . home = home
/**
* With different languages and systems we want to find the user's desktop for some link in the directory or even a nice shortcut
*/
module . exports . desktop = desktop
/**
* Identifying a system in the script can be simple with this variable
*/
module . exports . system = system
/**
* The most important directory of this project, here are saved some important things like:
*
* The server software
*
* configuration of the Bds Manager API
*
* Backups etc ...
*/
module . exports . bds _dir = bds _dir
module . exports . bds _dir _bedrock = bds _dir _bedrock
module . exports . bds _dir _java = bds _dir _java
module . exports . tmp _dir = tmp
module . exports . electron = electron _de
module . exports . api _dir = cache _dir
@ -224,23 +303,109 @@ module.exports.log_file = log_file
module . exports . log _date = log _date
module . exports . arch = archi
// module.exports.token = JSON.parse(fs.readFileSync(path.join(bds_dir, "bds_config.json"))).telegram_token
module . exports . telegram _token = JSON . parse ( fs . readFileSync ( path . join ( bds _dir , "bds_config.json" ) ) ) . telegram _token
// Global commands
module . exports . telegram = require ( "./global/telegram_bot" )
module . exports . token _register = ( ) => { if ( ! ( fs . existsSync ( path . join ( bds _dir , "bds_tokens.json" ) ) ) ) { fs . writeFileSync ( path . join ( bds _dir , "bds_tokens.json" ) , "[]" ) } ; require ( "crypto" ) . randomBytes ( 10 , function ( err , buffer ) { var token = buffer . toString ( "hex" ) ; console . log ( token ) ; var QRCode = require ( "qrcode" ) ; QRCode . toString ( token , function ( err , url ) { fs . readFile ( path . join ( bds _dir , "bds_tokens.json" ) , "utf8" , function ( err , data ) { if ( err ) { console . log ( err ) ; } else { obj = JSON . parse ( data ) ; var count = Object . keys ( obj ) . length ; var teste = { count , token } ; obj . push ( teste ) ; json = JSON . stringify ( obj ) ; fs . writeFileSync ( path . join ( bds _dir , "bds_tokens.json" ) , json , "utf8" ) ; } } ) ; } ) } ) ; }
module . exports . change _platform = platform _update
module . exports . token _register = ( ) => {
if ( ! ( fs . existsSync ( path . join ( bds _dir , "bds_tokens.json" ) ) ) ) {
fs . writeFileSync ( path . join ( bds _dir , "bds_tokens.json" ) , "[]" ) } ;
require ( "crypto" ) . randomBytes ( 10 , function ( err , buffer ) {
var token = buffer . toString ( "hex" ) ;
console . log ( token ) ;
var QRCode = require ( "qrcode" ) ;
QRCode . toString ( token , function ( err , url ) {
fs . readFile ( path . join ( bds _dir , "bds_tokens.json" ) , "utf8" , function ( err , data ) {
if ( err ) { console . log ( err ) ; }
else {
obj = JSON . parse ( data ) ;
var count = Object . keys ( obj ) . length ;
var teste = { count , token } ;
obj . push ( teste ) ;
json = JSON . stringify ( obj ) ;
fs . writeFileSync ( path . join ( bds _dir , "bds_tokens.json" ) , json , "utf8" ) ; }
} ) ;
} )
} )
}
module . exports . date = date
/**
* sending commands more simply to the server
*
* @example bds.command("say hello from Bds Maneger")
*/
module . exports . command = require ( "./global/command" ) . command
// module.exports.stop = require("./global/stop").Server_stop
// New management method
module . exports . start = require ( "./new_script/basic_server" ) . start
module . exports . stop = require ( "./new_script/basic_server" ) . stop
module . exports . backup = require ( "./new_script/backups" ) . World _BAckup
module . exports . detect = require ( "./new_script/detect" )
module . exports . bds _detect = require ( "./new_script/detect" )
module . exports . version _Download = require ( "./new_script/bds_download" )
module . exports . download = require ( "./new_script/bds_download" )
module . exports . kill = require ( "./new_ script/kill _server" )
module . exports . config _example = require ( "./new_script/bds_settings" ) . config _example
module . exports . set _config = require ( "./new_script/bds_settings" ) . config
module . exports . get _config = require ( "./new_script/bds_settings" ) . get _config
/**
* to start the server here in the sera script with child_process, then you will have to use the return function for your log custumization or anything else
*
* @example const server = bds.start();
* server.on.stdout("date", function (log){console.log(log)})
*/
module . exports . start = require ( "./scripts/basic _server" ) . start
/**
* use this command for the server, that's all
*/
module . exports . stop = require ( "./scripts/basic_server" ) . stop
/**
* backup your map locally
*/
module . exports . backup = require ( "./scripts/backups" ) . World _BAckup
/**
* identify if there are any servers running in the background
*
* @example bds.detect()
* // true: if the server is running
* // false: if not already
*/
module . exports . detect = require ( "./scripts/detect" )
module . exports . bds _detect = require ( "./scripts/detect" )
/**
* @deprecated
*/
module . exports . version _Download = require ( "./scripts/bds_download" )
/**
* download some version of the java and Bedrock servers in the highest possible form
*
* @example
* bedrock: bds.download("1.16.201.02")
*
* java: bds.download("1.16.5")
*/
module . exports . download = require ( "./scripts/bds_download" )
/**
* this function will be used to kill the server in the background
*/
module . exports . kill = require ( "./scripts/kill_server" )
module . exports . config _example = require ( "./scripts/bds_settings" ) . config _example
/**
* use this command to modify server settings
*
* @example
*
* bds.set_config({
name: "Bedrock our Java",
description: "BDS Maneger",
gamemode: "survival",
difficulty: "normal",
player_permission: "member",
xbox: true,
white_list: false,
cheats: false,
players: 100,
port: 19132,
port6: 19133
})
*/
module . exports . set _config = require ( "./scripts/bds_settings" ) . config
/**
* takes the server settings in JSON format
*/
module . exports . get _config = require ( "./scripts/bds_settings" ) . get _config