2021-02-09 06:48:31 +00:00
/* eslint-disable no-irregular-whitespace */
2021-03-23 23:38:28 -03:00
const path = require ( "path" )
const fs = require ( "fs" ) ;
const { resolve } = require ( "path" ) ;
const { error } = console ;
2021-03-24 14:51:12 +00:00
const shell = require ( "shelljs" ) ;
2021-04-13 12:46:08 -03:00
const { getDesktopFolder , getConfigHome } = require ( "./GetPlatformFolder" )
2021-04-07 23:00:30 -03:00
const { execSync } = require ( "child_process" ) ;
2021-03-24 14:51:12 +00:00
const bds _core _package = resolve ( _ _dirname , "package.json" )
const bds _maneger _version = require ( bds _core _package ) . version
2021-03-23 23:38:28 -03:00
if ( process . env . IS _BIN _BDS === undefined ) console . log ( ` Running the Bds Maneger API in version ${ bds _maneger _version } ` )
2021-04-06 12:13:52 -03:00
function date ( format ) {
const today = new Date ( ) ,
yaer = today . getFullYear ( ) ,
day = String ( today . getDate ( ) ) . padStart ( 2 , "0" ) ,
month = String ( today . getMonth ( ) + 1 ) . padStart ( 2 , "0" ) ,
hour = today . getHours ( ) ,
minute = today . getMinutes ( ) ;
// ---------------------------------------------------------
if ( format === "year" ) return yaer
else if ( format === "day" ) return day
else if ( format === "month" ) return month
else if ( format === "hour" ) return hour
else if ( format === "minute" ) return minute
else if ( format === "hour_minu" ) return ` ${ hour } - ${ minute } `
else return ` ${ day } - ${ month } - ${ yaer } _ ${ hour } - ${ minute } `
2020-12-04 11:33:24 -03:00
}
2021-03-24 14:51:12 +00:00
// System Architect (X64 or ARM64)
2021-01-13 17:38:21 -03:00
const arch = process . arch
2021-03-24 14:51:12 +00:00
module . exports . arch = arch
2021-03-23 23:38:28 -03:00
2021-04-13 12:46:08 -03:00
var home , tmp , system , valid _platform
2021-03-24 14:51:12 +00:00
module . exports . package _path = bds _core _package
2021-01-15 15:41:16 -03:00
if ( process . platform == "win32" ) {
2021-02-09 06:48:31 +00:00
home = process . env . USERPROFILE ;
tmp = process . env . TMP
2021-04-07 23:00:30 -03:00
system = "Windows" ;
2021-04-05 17:40:10 -07:00
valid _platform = {
2021-04-06 12:13:52 -03:00
"bedrock" : true ,
2021-04-07 23:00:30 -03:00
"pocketmine" : true ,
2021-04-06 12:13:52 -03:00
"java" : true
2021-04-05 17:40:10 -07:00
}
2021-01-15 15:41:16 -03:00
} else if ( process . platform == "linux" ) {
2021-02-09 06:48:31 +00:00
home = process . env . HOME ;
tmp = "/tmp" ;
2021-04-07 23:00:30 -03:00
system = "Linux" ;
2021-04-05 17:40:10 -07:00
valid _platform = {
2021-04-06 12:13:52 -03:00
"bedrock" : true ,
2021-04-07 23:00:30 -03:00
"pocketmine" : true ,
2021-04-06 12:13:52 -03:00
"java" : true
2021-04-05 17:40:10 -07:00
}
2021-04-10 00:17:40 -03:00
if ( process . arch === "aarch64" ) valid _platform . pocketmine = false ;
2021-01-15 15:41:16 -03:00
} else if ( process . platform == "darwin" ) {
2021-04-06 12:13:52 -03:00
if ( arch === "arm64" ) require ( "open" ) ( "https://github.com/The-Bds-Maneger/core/wiki/system_support#information-for-users-of-macbooks-and-imacs-with-m1-processor" )
else require ( "open" ) ( "https://github.com/The-Bds-Maneger/core/wiki/system_support#macos-with-intel-processors" ) ;
2021-03-24 14:51:12 +00:00
home = process . env . HOME ;
tmp = "/tmp" ;
2021-04-07 23:00:30 -03:00
system = "MacOS" ;
2021-04-05 17:40:10 -07:00
valid _platform = {
2021-04-06 12:13:52 -03:00
"bedrock" : false ,
2021-04-07 23:00:30 -03:00
"pocketmine" : true ,
2021-04-06 12:13:52 -03:00
"java" : true
2021-04-05 17:40:10 -07:00
}
2020-12-12 00:37:02 -03:00
} else {
2021-04-13 12:46:08 -03:00
console . log ( ` The Bds Maneger Core does not support ${ process . platform } systems, as no tests have been done. ` ) ;
2021-04-06 12:13:52 -03:00
home = process . env . HOME ;
tmp = "/tmp" ;
2021-04-13 12:46:08 -03:00
system = "Other" ;
2021-04-06 12:13:52 -03:00
valid _platform = {
"bedrock" : false ,
2021-04-13 12:46:08 -03:00
"pocketmine" : false ,
2021-04-06 12:13:52 -03:00
"java" : true
}
2021-03-24 14:51:12 +00:00
process . exit ( 254 )
2021-02-09 01:29:08 -03:00
}
2021-03-24 14:51:12 +00:00
/* ------------------------------------------------------------ Take the variables of different systems ------------------------------------------------------------ */
2021-04-13 12:46:08 -03:00
const desktop = getDesktopFolder ( )
2021-03-24 14:51:12 +00:00
/ * *
* 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
2021-04-05 17:40:10 -07:00
/ * *
* Platforms valid from deferents systems
* /
module . exports . valid _platform = valid _platform
2021-04-01 23:01:53 -03:00
/ * *
2021-03-24 14:51:12 +00:00
* Identifying a system in the script can be simple with this variable
* /
module . exports . system = system
/ * *
* Temporary system directory
* /
module . exports . tmp _dir = tmp
2021-04-01 23:01:53 -03:00
2021-03-24 14:51:12 +00:00
/ * *
2021-04-01 23:01:53 -03:00
* this variable makes available the location of the user profile directory as
*
* Linux : / h o m e / U S E R /
*
* Windows : C : \ \ Users \ \ USER \ \
*
* MacOS : In tests
2021-03-24 14:51:12 +00:00
* /
2021-04-01 23:01:53 -03:00
module . exports . home = home
2021-03-24 14:51:12 +00:00
// save bds core files
const bds _dir = resolve ( home , "bds_core" ) ;
const old _bds _dir = resolve ( home , "bds_Server" ) ;
// Bds Backups Folder
2021-02-09 06:48:31 +00:00
var bds _dir _backup = path . join ( bds _dir , "backups" ) ;
2021-01-30 22:24:05 -03:00
module . exports . backup _folder = bds _dir _backup
2021-03-24 14:51:12 +00:00
// Move old configs to new folder
if ( fs . existsSync ( old _bds _dir ) ) {
2021-04-05 18:04:16 -03:00
if ( fs . existsSync ( bds _dir ) ) {
fs . renameSync ( old _bds _dir , old _bds _dir + "_Conflit_" + Math . trunc ( Math . random ( ) * 10000 * Math . random ( ) ) ) ;
throw Error ( "Conflit folders check home dir" )
} else {
console . log ( "Moving the old files to the new folder" ) ;
fs . renameSync ( old _bds _dir , bds _dir ) ;
}
2021-03-24 14:51:12 +00:00
}
// Create Main save files
2021-01-30 23:10:11 -03:00
if ( ! ( fs . existsSync ( bds _dir ) ) ) {
console . log ( "Creating the bds directory" )
fs . mkdirSync ( bds _dir )
if ( ! ( fs . existsSync ( bds _dir ) ) ) shell . mkdir ( "-p" , bds _dir ) ;
}
2021-03-24 14:51:12 +00:00
/ * *
* 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
// Servers Paths
/* Java Path */
const bds _dir _java = path . join ( bds _dir , "java" ) ;
if ( ! ( fs . existsSync ( bds _dir _java ) ) ) {
console . log ( "Creating the bds directory to Java" )
fs . mkdirSync ( bds _dir _java )
if ( ! ( fs . existsSync ( bds _dir _java ) ) ) shell . mkdir ( "-p" , bds _dir _java ) ;
}
module . exports . bds _dir _java = bds _dir _java
/* Bedrock Path */
const bds _dir _bedrock = path . join ( bds _dir , "bedrock" ) ;
if ( ! ( fs . existsSync ( bds _dir _bedrock ) ) ) {
console . log ( "Creating the bds directory to Bedrock" )
fs . mkdirSync ( bds _dir _bedrock )
if ( ! ( fs . existsSync ( bds _dir _bedrock ) ) ) shell . mkdir ( "-p" , bds _dir _bedrock ) ;
}
module . exports . bds _dir _bedrock = bds _dir _bedrock
2021-04-07 23:00:30 -03:00
/* PocketMine Path */
const bds _dir _pocketmine = path . join ( bds _dir , "pocketmine" ) ;
if ( ! ( fs . existsSync ( bds _dir _pocketmine ) ) ) {
console . log ( "Creating the bds directory to Pocketmine" )
fs . mkdirSync ( bds _dir _pocketmine )
if ( ! ( fs . existsSync ( bds _dir _pocketmine ) ) ) shell . mkdir ( "-p" , bds _dir _pocketmine ) ;
}
module . exports . bds _dir _pocketmine = bds _dir _pocketmine
2021-03-24 14:51:12 +00:00
// Create backup folder
if ( ! ( fs . existsSync ( bds _dir _backup ) ) ) {
fs . mkdirSync ( bds _dir _backup )
if ( ! ( fs . existsSync ( bds _dir _backup ) ) ) shell . mkdir ( "-p" , bds _dir _backup ) ;
}
2021-04-13 12:46:08 -03:00
// Link Bds Dir in Desktop
2021-04-14 18:06:07 -03:00
let fileShortcut ;
if ( process . platform === "win32" ) fileShortcut = ".lnk" ; else fileShortcut = "" ;
const BdsCoreInDesktop = resolve ( desktop , "Bds Maneger Core" + fileShortcut )
2021-04-13 12:46:08 -03:00
if ( ! ( fs . existsSync ( BdsCoreInDesktop ) ) ) {
console . log ( "Creating a Bds Core shortcut on the Desktop" )
2021-04-14 18:06:07 -03:00
if ( process . platform === "win32" ) require ( "create-desktop-shortcuts" ) ( {
windows : {
filePath : bds _dir ,
name : "Bds Maneger Core"
}
} ) ;
else fs . symlinkSync ( bds _dir , BdsCoreInDesktop )
2021-04-13 12:46:08 -03:00
}
2021-01-30 23:10:11 -03:00
2021-03-24 14:51:12 +00:00
// Log Dir
const log _dir = path . join ( bds _dir , "log" ) ;
const log _date = date ( ) ;
module . exports . log _date = log _date
module . exports . latest _log = path . join ( bds _dir , "log" , "latest.log" )
if ( ! ( fs . existsSync ( log _dir ) ) ) {
fs . mkdirSync ( log _dir )
if ( ! fs . existsSync ( log _dir ) ) {
console . log ( ` Creating the bds log dir ( ${ log _dir } ) ` )
if ( ! ( fs . existsSync ( log _dir ) ) ) shell . mkdir ( "-p" , log _dir )
}
}
if ( typeof fetch === "undefined" ) global . fetch = require ( "node-fetch" ) ;
2021-04-13 12:46:08 -03:00
if ( typeof localStorage === "undefined" ) {
let LocalStorageFolder = path . join ( getConfigHome ( ) , "bds_core" )
// Create localStorage folder
if ( ! ( fs . existsSync ( LocalStorageFolder ) ) ) shell . mkdir ( "-p" , LocalStorageFolder ) ;
if ( ! ( fs . existsSync ( LocalStorageFolder ) ) ) fs . mkdirSync ( LocalStorageFolder )
global . localStorage = new require ( "node-localstorage" ) . LocalStorage ( path . join ( LocalStorageFolder , "Local_Storage" ) ) ; }
2021-03-24 14:51:12 +00:00
2021-04-07 23:00:30 -03:00
/* Minecraft Servers URLs and depedencies */
// urls
const SERVER _URLs = JSON . parse ( execSync ( "curl -sS \"https://raw.githubusercontent.com/Bds-Maneger/Raw_files/main/Server.json\"" ) . toString ( ) )
module . exports . SERVER _URLs = SERVER _URLs
// PHP Bins
const PHPbinsUrl = JSON . parse ( execSync ( "curl -sS \"https://raw.githubusercontent.com/The-Bds-Maneger/Raw_files/main/php_bin.json\"" ) . toString ( ) )
module . exports . PHPbinsUrls = PHPbinsUrl
2021-04-09 13:09:07 -03:00
// PHP bins System availble in Json File
2021-04-07 23:00:30 -03:00
const PHPurlNames = Object . getOwnPropertyNames ( PHPbinsUrl )
module . exports . PHPurlNames = PHPurlNames
2021-03-24 14:51:12 +00:00
/* ---------------------------------------------------------------------------- Variables ---------------------------------------------------------------------------- */
2021-01-30 22:24:05 -03:00
// Configs
2021-03-15 20:04:06 -03:00
var bds _config , bds _config _file = path . join ( bds _dir , "bds_config.json" ) ;
2021-03-23 23:38:28 -03:00
const current _version _bds _core = bds _maneger _version
2021-04-08 12:00:05 -03:00
var default _platformConfig ;
if ( process . platform . includes ( "win32" , "linux" ) ) default _platformConfig = "bedrock"
else default _platformConfig = "java"
2021-01-30 22:24:05 -03:00
if ( fs . existsSync ( bds _config _file ) ) {
2021-02-17 17:23:17 +00:00
bds _config = JSON . parse ( fs . readFileSync ( bds _config _file , "utf8" ) )
2021-03-15 20:04:06 -03:00
if ( bds _config . version !== current _version _bds _core ) {
2021-04-09 13:09:07 -03:00
2021-03-26 16:37:49 -03:00
if ( bds _config . platform _version === undefined ) bds _config . platform _version = { }
2021-04-09 13:09:07 -03:00
// New Config JSon
2021-03-15 20:04:06 -03:00
bds _config = {
"version" : current _version _bds _core ,
2021-04-02 12:38:02 -03:00
"bds_pages" : ( bds _config . bds _pages || "default" ) ,
2021-04-08 12:00:05 -03:00
"bds_platform" : ( bds _config . bds _platform || default _platformConfig ) ,
2021-03-23 23:38:28 -03:00
"platform_version" : {
"bedrock" : ( bds _config . platform _version . bedrock || "latest" ) ,
"java" : ( bds _config . platform _version . java || "latest" )
} ,
2021-04-01 23:01:53 -03:00
"bds_ban" : ( bds _config . bds _ban || [ "Steve" , "Alex" , "steve" , "alex" ] ) ,
2021-04-06 12:13:52 -03:00
"telegram_token" : ( bds _config . telegram _token || undefined ) ,
2021-04-10 00:17:40 -03:00
"Google_Drive_root_backup_id" : ( bds _config . Google _Drive _root _backup _id || undefined )
2021-03-15 20:04:06 -03:00
}
fs . writeFileSync ( bds _config _file , JSON . stringify ( bds _config , null , 4 ) )
bds _config _export ( )
}
2021-01-30 22:24:05 -03:00
} else {
2021-03-15 20:04:06 -03:00
let ram _total = Math . trunc ( ( require ( "os" ) . freemem ( ) / 1000 / 1000 ) - 212 )
if ( ram _total >= 1000 ) ram _total = ram _total - 1000
2021-02-17 17:23:17 +00:00
bds _config = {
2021-03-15 20:04:06 -03:00
"version" : current _version _bds _core ,
2021-04-02 12:38:02 -03:00
"bds_pages" : "default" ,
2021-04-08 12:00:05 -03:00
"bds_platform" : default _platformConfig ,
2021-03-23 23:38:28 -03:00
"platform_version" : {
"bedrock" : "latest" ,
"java" : "latest"
} ,
2021-04-01 23:01:53 -03:00
"bds_ban" : [ "Steve" , "Alex" , "steve" , "alex" ] ,
2021-02-17 17:23:17 +00:00
"telegram_token" : "not User defined" ,
2021-03-15 20:04:06 -03:00
"Google_Drive_root_backup_id" : undefined ,
2021-02-17 17:23:17 +00:00
"telegram_admin" : [
2021-03-14 16:55:05 -03:00
"all_users"
2021-04-10 00:17:40 -03:00
]
2021-02-09 01:29:08 -03:00
}
2021-03-14 01:55:34 +00:00
fs . writeFileSync ( bds _config _file , JSON . stringify ( bds _config , null , 4 ) )
2021-01-30 22:24:05 -03:00
}
2021-03-23 23:38:28 -03:00
module . exports . platform _version _update = function ( version ) {
let bds _config = JSON . parse ( fs . readFileSync ( bds _config _file , "utf8" ) )
if ( bds _config . bds _platform === "bedrock" ) bds _config . platform _version . bedrock = version
2021-04-10 21:58:18 -03:00
else if ( bds _config . bds _platform === "java" ) bds _config . platform _version . java = version
2021-03-23 23:38:28 -03:00
fs . writeFileSync ( bds _config _file , JSON . stringify ( bds _config , null , 4 ) )
bds _config _export ( )
}
2021-04-10 00:17:40 -03:00
/ * *
* Save ID Google Drive folder to Backups
* /
2021-03-15 20:04:06 -03:00
module . exports . save _google _id = function ( id ) {
let bds _config = JSON . parse ( fs . readFileSync ( bds _config _file , "utf8" ) )
bds _config . Google _Drive _root _backup _id = id
fs . writeFileSync ( bds _config _file , JSON . stringify ( bds _config , null , 4 ) )
bds _config _export ( )
return true
}
2021-01-30 22:24:05 -03:00
module . exports . platform = bds _config . bds _platform
2021-03-24 14:51:12 +00:00
2021-03-15 20:04:06 -03:00
/ * *
2021-04-10 00:17:40 -03:00
* Bds Maneger Latest log file .
2021-03-15 20:04:06 -03:00
* /
2021-04-10 00:17:40 -03:00
const log _file = path . join ( log _dir , ` ${ date ( ) } _ ${ bds _config . bds _platform } _Bds_log.log ` ) ;
module . exports . log _file = log _file
2021-03-15 20:04:06 -03:00
2021-03-14 22:52:36 -03:00
function bds _config _export ( ) {
/ * *
* Get current bds core config
*
* @ example bds . bds _config . bds _platform // return bedrock or java
*
* * it updates every second
* /
module . exports . bds _config = JSON . parse ( fs . readFileSync ( path . join ( bds _dir , "bds_config.json" ) ) )
}
bds _config _export ( )
2021-03-24 14:51:12 +00:00
2021-02-09 01:29:08 -03:00
/ * *
* 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 ) {
2021-04-01 23:01:53 -03:00
// Server platform detect
if ( plate === "java" ) null ;
else if ( plate === "bedrock" ) null ;
2021-04-10 21:58:18 -03:00
else if ( plate === "pocketmine" ) null ;
2021-04-01 23:01:53 -03:00
else throw new Error ( ` platform not identified or does not exist, ${ plate } informed platform ` ) ;
// Platforma Update
2021-02-09 01:29:08 -03:00
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
2021-03-14 01:55:34 +00:00
fs . writeFileSync ( bds _config , JSON . stringify ( config _load , null , 4 ) )
2021-02-17 17:23:17 +00:00
console . log ( ` upgrading the platform ${ plate } ` )
2021-03-14 22:52:36 -03:00
bds _config _export ( )
2021-03-15 20:04:06 -03:00
return true
2021-02-09 01:29:08 -03:00
} catch ( error ) {
2021-03-15 20:04:06 -03:00
throw new Error ( ` Something happened error code: ${ error } ` )
2021-02-09 01:29:08 -03:00
}
}
2021-03-14 01:55:34 +00:00
if ( process . env . SERVER !== undefined ) {
if ( ( process . env . SERVER || "bedrock" ) . includes ( "java" , "JAVA" ) ) platform _update ( "java" ) ;
else platform _update ( "bedrock" ) ;
2021-01-30 22:24:05 -03:00
}
2021-03-15 20:04:06 -03:00
module . exports . change _platform = platform _update
2021-01-12 21:46:22 -03:00
2021-03-14 22:52:36 -03:00
const telegram _token _save = function ( token ) {
2021-02-09 01:29:08 -03:00
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
2021-03-14 01:55:34 +00:00
fs . writeFileSync ( bds _config , JSON . stringify ( config _load , null , 4 ) )
2021-03-14 22:52:36 -03:00
bds _config _export ( )
2021-02-09 01:29:08 -03:00
return true
} catch {
return false
}
2021-01-30 22:24:05 -03:00
}
2021-03-14 22:52:36 -03:00
module . exports . telegram _token _save = telegram _token _save
2021-02-09 01:29:08 -03:00
if ( require ( "fs" ) . existsSync ( path . join ( bds _dir , "telegram_token.txt" ) ) ) {
2021-04-01 23:01:53 -03:00
console . log ( ` We identified the old telegram token file ( ${ path . join ( bds _dir , "telegram_token.txt" ) } ), starting the migration process ` )
2021-02-09 01:29:08 -03:00
try {
2021-02-09 06:48:31 +00:00
const token = fs . readFileSync ( path . join ( bds _dir , "telegram_token.txt" ) , "utf8" ) . split ( "\n" ) . join ( "" )
2021-04-01 23:01:53 -03:00
telegram _token _save ( token )
2021-02-09 01:29:08 -03:00
fs . rmSync ( path . join ( bds _dir , "telegram_token.txt" ) )
2021-02-09 06:48:31 +00:00
console . log ( "We finished migrating the old telegram token file" )
2021-02-09 01:29:08 -03:00
} catch {
2021-02-09 06:48:31 +00:00
throw new error ( "It was not possible to move the old telegram token file to the new bds maneger api file" )
2021-02-09 01:29:08 -03:00
}
2021-01-30 23:44:48 -03:00
}
2021-04-07 23:00:30 -03:00
const getSize = require ( "get-folder-size" ) ;
2021-04-03 22:03:38 -03:00
getSize ( bds _dir _backup , function ( err , info ) {
if ( err ) throw err
function toGB ( x ) { return ( x / ( 1024 * 1024 * 1024 ) ) . toFixed ( 1 ) ; }
/ * *
* The disk space is used for each backup made , and it is good to take a look at this information before creating another backup .
*
* The return value will always be in gigabyte ( GB )
* /
module . exports . backup _folder _size = toGB ( info )
} ) ;
2021-01-16 20:08:27 -03:00
2021-04-01 23:01:53 -03:00
// Get server version
2021-01-30 23:44:48 -03:00
fetch ( "https://raw.githubusercontent.com/Bds-Maneger/Raw_files/main/Server.json" ) . then ( response => response . json ( ) ) . then ( rawOUT => {
module . exports . bedrock _all _versions = Object . getOwnPropertyNames ( rawOUT . bedrock ) ;
module . exports . java _all _versions = Object . getOwnPropertyNames ( rawOUT . java ) ;
2021-04-01 23:01:53 -03:00
module . exports . bds _latest = ( rawOUT . bedrock _lateste || rawOUT . bedrock _latest ) ;
2021-03-15 20:04:06 -03:00
module . exports . bedrock _latest = rawOUT . bedrock _latest ;
module . exports . java _latest = rawOUT . java _latest ;
2021-01-10 20:39:56 -03:00
} )
2021-03-14 16:55:05 -03:00
/ * *
* Activate an API via expresss . js , to receive requests via http such as the log , send and receive commands
*
* to activate use :
* * bds . api ( ) // to activate requests via http
* * bds . log ( )
* /
2021-03-23 23:38:28 -03:00
module . exports . api = require ( "./rest/api" ) ;
module . exports . rest = require ( "./rest/api" ) ;
2021-03-14 16:55:05 -03:00
2021-04-01 23:01:53 -03:00
// ------------
const user _file _connected = path . join ( bds _dir , "bds_users.json" )
2021-03-14 16:55:05 -03:00
/ * *
* get the location of the file where the player history connected to the server is saved
* /
module . exports . players _files = user _file _connected
if ( ! ( fs . existsSync ( user _file _connected ) ) ) fs . writeFileSync ( user _file _connected , "[]" )
const file _user _check = fs . readFileSync ( user _file _connected , "utf8" ) ;
2021-04-01 23:01:53 -03:00
if ( file _user _check . charAt ( 0 ) !== "[" ) console . warn ( "ok, we have an error in the file of the connected players, please check the file, it should start on the first line with --> [ ,and end with -->]" )
else if ( file _user _check . slice ( - 1 ) !== "]" ) console . warn ( "ok, we have an error in the file of the connected players, please check the file, it should start on the first line with --> [ ,and end with -->]" )
2021-02-09 01:29:08 -03:00
module . exports . telegram _token = JSON . parse ( fs . readFileSync ( path . join ( bds _dir , "bds_config.json" ) ) ) . telegram _token
2021-04-01 23:01:53 -03:00
module . exports . internal _ip = require ( "./scripts/external_ip" ) . internal _ip
2021-03-30 13:53:23 -03:00
module . exports . telegram = require ( "./scripts/telegram_bot" )
2021-04-12 00:36:47 -03:00
const token _register = function ( username , passworld ) {
2021-02-17 19:17:00 +00:00
const bds _token _path = path . join ( bds _dir , "bds_tokens.json" )
if ( ! ( fs . existsSync ( bds _token _path ) ) ) fs . writeFileSync ( bds _token _path , "[]" )
2021-04-12 00:36:47 -03:00
function getRandomNumber ( ) {
const number = Math . trunc ( 15 * ( 10 * Math . random ( ) ) )
if ( number < 10 ) return getRandomNumber ( )
else if ( number > 15 ) return getRandomNumber ( )
else return number
}
let number = getRandomNumber ( )
require ( "crypto" ) . randomBytes ( number , function ( err , buffer ) {
2021-02-17 19:17:00 +00:00
if ( err ) console . warn ( err ) ;
const new _token = buffer . toString ( "hex" ) ;
var tokens = JSON . parse ( fs . readFileSync ( bds _token _path , "utf8" ) ) ;
2021-04-12 00:36:47 -03:00
tokens . push ( {
"token" : ( passworld || new _token ) ,
"user" : ( username || "all" )
} ) ;
2021-03-14 01:55:34 +00:00
fs . writeFileSync ( bds _token _path , JSON . stringify ( tokens , null , 4 ) , "utf8" ) ;
2021-02-17 19:17:00 +00:00
2021-04-12 00:36:47 -03:00
console . log ( ` Bds Maneger API REST token: " ${ new _token } " ` ) ;
if ( process . stdout . isTTY === false ) {
2021-04-01 23:01:53 -03:00
require ( "qrcode" ) . toString ( new _token , { type : "terminal" } , function ( err , url ) {
if ( err ) throw Error ( err )
2021-03-23 23:38:28 -03:00
console . log ( url )
} )
}
2021-02-17 19:17:00 +00:00
} )
2021-02-09 01:29:08 -03:00
}
2021-04-12 00:36:47 -03:00
/ * *
* Register tokens to use in Bds Maneger REST and other supported applications
*
* @ example token _register ( )
* /
module . exports . token _register = token _register
/ * *
* Take the current date
* /
2020-12-13 00:26:42 -03:00
module . exports . date = date
2021-02-09 01:29:08 -03:00
/ * *
* sending commands more simply to the server
*
* @ example bds . command ( "say hello from Bds Maneger" )
* /
2021-04-01 23:01:53 -03:00
module . exports . command = require ( "./scripts/basic_server" ) . BdsCommand
2021-01-30 22:24:05 -03:00
// New management method
2021-02-09 01:29:08 -03:00
/ * *
* 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
2021-03-14 22:52:36 -03:00
*
* use bds . download
2021-02-09 01:29:08 -03:00
* /
module . exports . version _Download = require ( "./scripts/bds_download" )
/ * *
* download some version of the java and Bedrock servers in the highest possible form
*
2021-03-24 14:51:12 +00:00
* use download ( version , boolean ) // the boolean is for if you want to force the installation of the server
*
2021-02-09 01:29:08 -03:00
* @ example
* bedrock : bds . download ( "1.16.201.02" )
*
* java : bds . download ( "1.16.5" )
2021-03-14 22:52:36 -03:00
*
* any platform : bds . download ( "latest" ) // It will download the latest version available for download
2021-02-09 01:29:08 -03:00
* /
2021-03-14 22:52:36 -03:00
module . exports . download = require ( "./scripts/download" )
2021-02-09 01:29:08 -03:00
/ * *
* 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
2021-04-12 00:36:47 -03:00
2021-02-09 01:29:08 -03:00
/ * *
* use this command to modify server settings
*
2021-04-12 00:36:47 -03:00
* @ example bds . set _config ( {
2021-02-09 01:29:08 -03:00
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
2021-03-15 20:04:06 -03:00
2021-04-01 23:01:53 -03:00
/ * *
* 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 ( "./scripts/GoogleDrive" ) . mcpe
2021-04-12 00:36:47 -03:00
2021-04-01 23:01:53 -03:00
/ * *
* 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 ( "./scripts/GoogleDrive" ) . drive _backup