2021-02-09 06:48:31 +00:00
/* eslint-disable no-irregular-whitespace */
2021-04-23 21:40:08 -03:00
const { resolve } = require ( "path" ) ;
2021-04-18 23:36:41 -03:00
const { error } = console ;
const { execSync } = require ( "child_process" ) ;
const { CronJob } = require ( "cron" ) ;
2021-03-23 23:38:28 -03:00
const path = require ( "path" )
const fs = require ( "fs" ) ;
2021-04-23 21:40:08 -03:00
const { getConfigHome } = require ( "./GetPlatformFolder" )
2021-05-02 23:11:17 -03:00
const commandExistsSync = require ( "./commandExist" ) ;
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-05-02 23:11:17 -03:00
module . exports = require ( "./bdsgetPaths" ) ;
2021-04-22 19:50:21 -03:00
if ( process . env . SHOW _BDS _VERSION !== 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-04-23 21:40:08 -03:00
module . exports . package _path = bds _core _package
const { bds _dir , log _dir } = require ( "./bdsgetPaths" ) ;
2021-05-02 23:11:17 -03:00
2021-04-23 21:40:08 -03:00
// System Architect (x64, aarch64 and others)
2021-05-03 18:44:57 -03:00
var arch ;
if ( process . arch === "arm64" ) arch = "aarch64" ; else arch = process . arch
2021-03-24 14:51:12 +00:00
module . exports . arch = arch
2021-04-23 21:40:08 -03:00
// -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
2021-04-29 10:28:45 -03:00
var system ,
valid _platform = {
bedrock : true ,
pocketmine : true ,
java : true ,
jsprismarine : true
}
2021-01-15 15:41:16 -03:00
if ( process . platform == "win32" ) {
2021-04-07 23:00:30 -03:00
system = "Windows" ;
2021-04-29 00:35:47 -03:00
// ia32
2021-04-29 10:28:45 -03:00
if ( process . arch !== "x64" ) {
valid _platform [ "bedrock" ] = false
valid _platform [ "pocketmine" ] = false
2021-04-05 17:40:10 -07:00
}
2021-01-15 15:41:16 -03:00
} else if ( process . platform == "linux" ) {
2021-04-07 23:00:30 -03:00
system = "Linux" ;
2021-05-02 23:11:17 -03:00
if ( commandExistsSync ( "qemu-x86_64-static" ) ) {
valid _platform [ "bedrock" ] = true
valid _platform [ "pocketmine" ] = true
} else if ( process . arch !== "x64" ) {
2021-04-29 10:28:45 -03:00
valid _platform [ "bedrock" ] = false
valid _platform [ "pocketmine" ] = false
2021-04-05 17:40:10 -07:00
}
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-04-07 23:00:30 -03:00
system = "MacOS" ;
2021-04-29 10:28:45 -03:00
valid _platform [ "bedrock" ] = false
2021-04-29 01:33:44 -03:00
} else if ( process . platform === "android" ) {
system = "Android" ;
2021-04-29 10:28:45 -03:00
valid _platform [ "bedrock" ] = false
valid _platform [ "java" ] = false
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. ` ) ;
system = "Other" ;
2021-04-29 10:28:45 -03:00
valid _platform [ "bedrock" ] = false
valid _platform [ "pocketmine" ] = false
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-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
const log _date = date ( ) ;
2021-04-23 21:40:08 -03:00
module . exports . log _date = log _date ;
module . exports . latest _log = path . join ( bds _dir , "log" , "latest.log" ) ;
2021-03-24 14:51:12 +00:00
2021-05-03 18:44:57 -03:00
module . exports . package _json = JSON . parse ( fs . readFileSync ( bds _core _package ) )
2021-03-24 14:51:12 +00:00
if ( typeof fetch === "undefined" ) global . fetch = require ( "node-fetch" ) ;
2021-04-13 12:46:08 -03:00
if ( typeof localStorage === "undefined" ) {
2021-04-18 23:36:41 -03:00
let Bdsname = JSON . parse ( fs . readFileSync ( resolve ( _ _dirname , "package.json" ) ) ) . name ;
let LocalStorageFolder = path . join ( getConfigHome ( ) , Bdsname )
2021-04-13 12:46:08 -03:00
// Create localStorage folder
2021-05-04 14:46:10 -03:00
if ( ! ( fs . existsSync ( LocalStorageFolder ) ) ) fs . mkdirSync ( LocalStorageFolder , { recursive : true } )
2021-04-18 23:36:41 -03:00
let Local = require ( "node-localstorage" )
global . localStorage = new Local . 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
2021-04-23 21:40:08 -03:00
var CurlWgetCommand ;
if ( commandExistsSync ( "wget" ) ) CurlWgetCommand = "wget -qO-" ;
else if ( commandExistsSync ( "curl" ) ) CurlWgetCommand = "curl -sS" ;
else throw new Error ( "Curl or Wget command not found" )
const SERVER _URLs = JSON . parse ( execSync ( ` ${ CurlWgetCommand } "https://raw.githubusercontent.com/Bds-Maneger/Raw_files/main/Server.json" ` ) . toString ( ) )
2021-04-07 23:00:30 -03:00
module . exports . SERVER _URLs = SERVER _URLs
// PHP Bins
2021-04-23 21:40:08 -03:00
const PHPbinsUrl = JSON . parse ( execSync ( ` ${ CurlWgetCommand } "https://raw.githubusercontent.com/The-Bds-Maneger/Raw_files/main/php_bin.json" ` ) . toString ( ) )
2021-04-07 23:00:30 -03:00
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-04-23 21:40:08 -03:00
// Google Drive Credentials
const GoogleDriveCredentials = JSON . parse ( execSync ( "curl -sS \"https://raw.githubusercontent.com/Bds-Maneger/Raw_files/main/credentials.json\"" ) . toString ( ) )
module . exports . GoogleDriveCredentials = GoogleDriveCredentials
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-29 00:35:47 -03:00
// Set default platform for bds maneger
2021-04-08 12:00:05 -03:00
var default _platformConfig ;
2021-04-29 13:59:01 -03:00
if ( valid _platform [ "bedrock" ] ) default _platformConfig = "bedrock" ; else if ( valid _platform [ "java" ] ) default _platformConfig = "java" ; else if ( valid _platform [ "pocketmine" ] ) default _platformConfig = "pocketmine" ; else default _platformConfig = "jsprismarine"
2021-04-29 00:35:47 -03:00
2021-05-04 14:46:10 -03:00
module . exports . internal _ip = require ( "./scripts/external_ip" ) . internal _ip
module . exports . external _ip = require ( "./scripts/external_ip" ) . external _ip
2021-04-29 00:35:47 -03:00
// Config File
if ( fs . existsSync ( bds _config _file ) ) bds _config = JSON . parse ( fs . readFileSync ( bds _config _file , "utf8" ) ) ; else bds _config = { platform _version : { } , telegram _admin : [ "all_users" ] }
bds _config = {
"version" : current _version _bds _core ,
"bds_pages" : ( bds _config . bds _pages || "default" ) ,
"bds_platform" : ( bds _config . bds _platform || default _platformConfig ) ,
2021-05-02 23:11:17 -03:00
"LoadTelemetry" : ( ( ) => { if ( bds _config . LoadTelemetry === undefined ) return true ; else return bds _config . LoadTelemetry } ) ( ) ,
2021-05-04 14:46:10 -03:00
"TelemetryID" : ( bds _config . TelemetryID || execSync ( ` curl -sS https://telemetry.the-bds-maneger.org/getid?external_ip= ${ require ( "./scripts/external_ip" ) . external _ip } ` ) . toString ( ) ) ,
2021-04-29 00:35:47 -03:00
"platform_version" : {
2021-05-03 23:49:40 -03:00
"bedrock" : ( bds _config . platform _version . bedrock || null ) ,
"java" : ( bds _config . platform _version . java || null ) ,
"pocketmine" : ( bds _config . platform _version . pocketmine || null ) ,
2021-04-29 00:35:47 -03:00
"jsprismarine" : "latest"
} ,
"bds_ban" : ( bds _config . bds _ban || [ "Steve" , "Alex" , "steve" , "alex" ] ) ,
"telegram_token" : ( bds _config . telegram _token || "not User defined" ) ,
"Google_Drive_root_backup_id" : ( bds _config . Google _Drive _root _backup _id || undefined ) ,
"BackupCron" : ( bds _config . BackupCron || [ ] ) ,
"telegram_admin" : bds _config . telegram _admin
2021-01-30 22:24:05 -03:00
}
2021-04-29 00:35:47 -03:00
fs . writeFileSync ( bds _config _file , JSON . stringify ( bds _config , null , 4 ) )
bds _config _export ( )
2021-04-23 21:40:08 -03:00
2021-05-03 18:44:57 -03:00
require ( "./logger" )
2021-05-02 23:11:17 -03:00
2021-04-23 21:40:08 -03:00
/ * *
* Update bds config version installed
*
* @ param bedrock
* @ param java
* @ param pocketmine
* /
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-04-29 00:35:47 -03:00
else if ( bds _config . bds _platform === "pocketmine" ) bds _config . platform _version . pocketmine = version
else if ( bds _config . bds _platform === "jsprismarine" ) bds _config . platform _version . jsprismarine = 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-23 21:40:08 -03:00
} ;
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-04-23 21:40:08 -03:00
2021-01-30 22:24:05 -03:00
module . exports . platform = bds _config . bds _platform
2021-04-18 23:36:41 -03:00
module . exports . bds _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 ( ) {
2021-04-19 23:26:14 -03:00
const Config = JSON . parse ( fs . readFileSync ( path . join ( bds _dir , "bds_config.json" ) , "utf8" ) )
2021-03-14 22:52:36 -03:00
/ * *
* Get current bds core config
*
2021-04-29 00:35:47 -03:00
* @ example bds _config . bds _platform // return bedrock, java, pocketmine or jsprismarine
2021-03-14 22:52:36 -03:00
*
* /
2021-04-19 23:26:14 -03:00
module . exports . bds _config = Config
module . exports . platform = Config . bds _platform
2021-03-14 22:52:36 -03:00
}
bds _config _export ( )
2021-03-24 14:51:12 +00:00
2021-04-18 23:36:41 -03:00
function getBdsConfig ( ) {
const Config = fs . readFileSync ( path . join ( bds _dir , "bds_config.json" ) , "utf8" )
return JSON . parse ( Config )
}
module . exports . getBdsConfig = getBdsConfig
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" )
2021-04-29 00:35:47 -03:00
*
* pocketmine change _platform ( "pocketmine" )
*
* jsprismarine change _platform ( "jsprismarine" )
*
2021-02-09 01:29:08 -03:00
* @ example change _platform ( "bedrock" )
2021-04-23 21:40:08 -03:00
*
* @ param "bedrock"
* @ param "java"
* @ param "pocketmine"
2021-04-29 00:35:47 -03:00
* @ param "jsprismarine"
2021-02-09 01:29:08 -03:00
* /
function platform _update ( plate ) {
2021-04-01 23:01:53 -03:00
// Server platform detect
2021-04-29 00:35:47 -03:00
if ( ! ( plate === "java" || plate === "bedrock" || plate === "pocketmine" || plate === "jsprismarine" ) ) throw new Error ( ` platform not identified or does not exist, ${ plate } informed platform ` ) ;
2021-04-01 23:01:53 -03:00
// Platforma Update
2021-04-18 23:36:41 -03:00
const bds _config = path . join ( bds _dir , "bds_config.json" ) ;
2021-02-09 01:29:08 -03:00
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-04-23 21:40:08 -03:00
throw new Error ( ` Something happened error: ${ error } ` )
2021-02-09 01:29:08 -03:00
}
}
2021-04-23 21:40:08 -03:00
2021-04-18 23:36:41 -03:00
module . exports . change _platform = platform _update
module . exports . platform _update = platform _update
2021-04-23 21:40:08 -03:00
2021-03-14 01:55:34 +00:00
if ( process . env . SERVER !== undefined ) {
2021-04-18 23:36:41 -03:00
let PlaformSelectServer = ( process . env . SERVER || "bedrock" )
if ( PlaformSelectServer . includes ( "java" , "JAVA" ) ) platform _update ( "java" ) ;
else if ( PlaformSelectServer . includes ( "bedrock" , "BEDROCK" ) ) platform _update ( "bedrock" ) ;
else if ( PlaformSelectServer . includes ( "pocketmine" , "POCKETMINE" , "pocketmine-mp" , "POCKETMINE-MP" ) ) platform _update ( "pocketmine" ) ;
2021-04-29 00:35:47 -03:00
else if ( PlaformSelectServer . includes ( "JSPrismarine" , "JSPRISMARINE" , "jsprismarine" ) ) platform _update ( "jsprismarine" ) ;
2021-04-18 23:36:41 -03:00
else throw new Error ( "Server Plaform Error: " + process . env . SERVER )
2021-01-30 22:24:05 -03:00
}
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-01-16 20:08:27 -03:00
2021-04-01 23:01:53 -03:00
// Get server version
2021-04-22 19:50:21 -03:00
module . exports . bedrock _all _versions = Object . getOwnPropertyNames ( SERVER _URLs . bedrock ) ;
module . exports . java _all _versions = Object . getOwnPropertyNames ( SERVER _URLs . java ) ;
module . exports . bds _latest = ( SERVER _URLs . bedrock _lateste || SERVER _URLs . bedrock _latest ) ;
module . exports . bedrock _latest = SERVER _URLs . bedrock _latest ;
module . exports . java _latest = SERVER _URLs . java _latest ;
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
// ------------
2021-04-20 22:09:34 -03:00
const user _file _connected = path . join ( bds _dir , "bds_usersV2.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
2021-04-20 22:09:34 -03:00
if ( ! ( fs . existsSync ( user _file _connected ) ) ) fs . writeFileSync ( user _file _connected , "{}" )
2021-03-14 16:55:05 -03:00
const file _user _check = fs . readFileSync ( user _file _connected , "utf8" ) ;
2021-04-20 22:09:34 -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-04-23 21:40:08 -03:00
module . exports . telegram _token = bds _config . telegram _token
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
2021-04-18 23:36:41 -03:00
// Requires
const { World _BAckup } = require ( "./scripts/backups" ) ;
const { stop , BdsCommand } = require ( "./scripts/basic_server" ) ;
2021-05-04 14:46:10 -03:00
const bdsStart = require ( "./scripts/basic_server" ) . start ;
2021-04-18 23:36:41 -03:00
const { config , get _config , config _example } = require ( "./scripts/bds_settings" ) ;
const { mcpe , drive _backup } = require ( "./scripts/GoogleDrive" ) ;
2021-04-23 21:40:08 -03:00
const download = require ( "./scripts/download" ) ;
2021-04-18 23:36:41 -03:00
const Jobs = { } ;
for ( let index of bds _config . BackupCron ) {
Jobs [ index ] = new CronJob ( index , function ( ) {
World _BAckup ( )
} ) ;
}
module . exports . CronBackups = Jobs
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-18 23:36:41 -03:00
module . exports . command = 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 ) } )
* /
2021-05-04 14:46:10 -03:00
module . exports . start = bdsStart
2021-02-09 01:29:08 -03:00
/ * *
* use this command for the server , that ' s all
* /
2021-04-18 23:36:41 -03:00
module . exports . stop = stop
2021-02-09 01:29:08 -03:00
/ * *
* backup your map locally
* /
2021-04-18 23:36:41 -03:00
module . exports . backup = World _BAckup
2021-02-09 01:29:08 -03:00
/ * *
* 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" )
/ * *
* 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-04-18 23:36:41 -03:00
module . exports . download = 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" )
2021-04-18 23:36:41 -03:00
module . exports . config _example = 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
} )
* /
2021-04-18 23:36:41 -03:00
module . exports . set _config = config
2021-02-09 01:29:08 -03:00
/ * *
* takes the server settings in JSON format
* /
2021-04-18 23:36:41 -03:00
module . exports . get _config = 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
* /
2021-04-18 23:36:41 -03:00
module . exports . mcpe _file = 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
* /
2021-04-29 00:35:47 -03:00
module . exports . drive _backup = drive _backup