2021-02-09 06:48:31 +00:00
/* eslint-disable no-irregular-whitespace */
2021-06-11 17:13:40 -03:00
const { resolve } = require ( "path" ) ;
2021-04-18 23:36:41 -03:00
const { CronJob } = require ( "cron" ) ;
2021-03-23 23:38:28 -03:00
const path = require ( "path" )
const fs = require ( "fs" ) ;
2021-06-15 19:45:13 -03:00
const { getConfigHome } = require ( "./lib/GetPlatformFolder" ) ;
2021-06-11 17:13:40 -03:00
const commandExistsSync = require ( "./lib/commandExist" ) ;
const FetchSync = require ( "./lib/fetchSync" ) ;
2021-05-20 21:06:00 -03:00
const { randomBytes } = require ( "crypto" )
2021-06-14 20:58:57 -03:00
module . exports = require ( "./lib/bdsgetPaths" ) ;
2021-05-02 23:11:17 -03:00
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-06-11 17:13:40 -03:00
const bds _core _package = resolve ( _ _dirname , "package.json" )
2021-04-23 21:40:08 -03:00
module . exports . package _path = bds _core _package
2021-06-11 17:13:40 -03:00
const package _json = JSON . parse ( fs . readFileSync ( bds _core _package ) )
module . exports . package _json = package _json
2021-04-23 21:40:08 -03:00
2021-06-14 20:58:57 -03:00
const { bds _dir , log _dir } = require ( "./lib/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-05-16 23:14:17 -03:00
const SERVER _URLs = FetchSync ( "https://raw.githubusercontent.com/Bds-Maneger/Raw_files/main/Server.json" ) . json ( )
const PHPbinsUrl = FetchSync ( "https://raw.githubusercontent.com/The-Bds-Maneger/Raw_files/main/php_bin.json" ) . json ( )
const GoogleDriveCredentials = FetchSync ( "https://raw.githubusercontent.com/Bds-Maneger/Raw_files/main/credentials.json" ) . json ( )
2021-04-23 21:40:08 -03:00
// -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
2021-04-29 10:28:45 -03:00
var system ,
2021-05-16 23:14:17 -03:00
require _qemu = false ,
valid _platform = {
bedrock : true ,
pocketmine : true ,
2021-06-11 17:13:40 -03:00
java : commandExistsSync ( "java" ) ,
2021-05-17 23:22:32 -03:00
jsprismarine : commandExistsSync ( "node" )
2021-05-16 23:14:17 -03:00
}
// check php bin
if ( PHPbinsUrl [ process . platform ] ) {
if ( PHPbinsUrl [ process . platform ] [ arch ] ) valid _platform [ "pocketmine" ] = true ; else valid _platform [ "pocketmine" ] = false
} else valid _platform [ "pocketmine" ] = false
// SoSystem X
2021-01-15 15:41:16 -03:00
if ( process . platform == "win32" ) {
2021-04-07 23:00:30 -03:00
system = "Windows" ;
2021-05-16 23:14:17 -03:00
// arm64 and X64
if ( ! ( arch === "x64" || arch === "aarch64" ) ) valid _platform [ "bedrock" ] = false ;
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-16 23:14:17 -03:00
if ( SERVER _URLs . bedrock [ SERVER _URLs . bedrock _latest ] [ arch ] ) {
if ( SERVER _URLs . bedrock [ SERVER _URLs . bedrock _latest ] [ arch ] [ process . platform ] ) valid _platform [ "bedrock" ] = true ; else valid _platform [ "bedrock" ] = false ;
} else valid _platform [ "bedrock" ] = false
if ( valid _platform [ "bedrock" ] === false ) {
if ( commandExistsSync ( "qemu-x86_64-static" ) ) {
console . warn ( "The Minecraft Bedrock Server is only being validated because you can use 'qemu-x86_64-static'" ) ;
valid _platform [ "bedrock" ] = true
require _qemu = true
}
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-05-16 23:14:17 -03:00
module . exports . require _qemu = require _qemu
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-05-17 23:22:32 -03:00
module . exports . extra _json = JSON . parse ( fs . readFileSync ( resolve ( _ _dirname , "extra.json" ) ) )
2021-05-03 18:44:57 -03:00
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
2021-04-07 23:00:30 -03:00
module . exports . SERVER _URLs = SERVER _URLs
2021-05-06 22:58:17 -03:00
module . exports . ServerJson = SERVER _URLs
// Get server version
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-04-07 23:00:30 -03:00
// PHP Bins
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
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-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-06-11 17:13:40 -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-06-11 17:13:40 -03:00
// User IP
2021-05-17 23:22:32 -03:00
const maneger _ips = require ( "./scripts/external_ip" )
module . exports . internal _ip = maneger _ips . internal _ip
module . exports . external _ip = maneger _ips . external _ip
2021-05-04 14:46:10 -03:00
2021-04-29 00:35:47 -03:00
// Config File
2021-05-17 23:22:32 -03:00
var Oldbds _config
if ( fs . existsSync ( bds _config _file ) ) Oldbds _config = JSON . parse ( fs . readFileSync ( bds _config _file , "utf8" ) ) ; else Oldbds _config = { platform _version : { } , telegram _admin : [ "all_users" ] }
2021-04-29 00:35:47 -03:00
bds _config = {
2021-06-11 17:13:40 -03:00
"version" : package _json . version ,
"bds_pages" : ( Oldbds _config . bds _pages || "default" ) ,
"bds_platform" : ( Oldbds _config . bds _platform || default _platformConfig ) ,
"LoadTelemetry" : ( ( ) => { if ( Oldbds _config . LoadTelemetry === undefined ) return true ; else return Oldbds _config . LoadTelemetry } ) ( ) ,
"TelemetryID" : ( Oldbds _config . TelemetryID || FetchSync ( ` https://telemetry.the-bds-maneger.org/getid?external_ip= ${ maneger _ips . external _ip } ` ) . toString ( ) ) ,
"platform_version" : {
"bedrock" : ( Oldbds _config . platform _version . bedrock || null ) ,
"java" : ( Oldbds _config . platform _version . java || null ) ,
"pocketmine" : ( Oldbds _config . platform _version . pocketmine || null ) ,
"jsprismarine" : "latest"
2021-04-29 00:35:47 -03:00
} ,
2021-06-11 17:13:40 -03:00
"bds_ban" : ( Oldbds _config . bds _ban || [ "Steve" , "Alex" , "steve" , "alex" ] ) ,
"telegram_token" : ( Oldbds _config . telegram _token || "not User defined" ) ,
"Google_Drive_root_backup_id" : ( Oldbds _config . Google _Drive _root _backup _id || undefined ) ,
"BackupCron" : ( Oldbds _config . BackupCron || [ ] ) ,
"telegram_admin" : Oldbds _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 ) )
2021-05-20 21:06:00 -03:00
function bds _config _export ( ) {
const Config = JSON . parse ( fs . readFileSync ( path . join ( bds _dir , "bds_config.json" ) , "utf8" ) )
/ * *
* Get current bds core config
*
* @ example bds _config . bds _platform // return bedrock, java, pocketmine or jsprismarine
*
* /
module . exports . bds _config = Config
module . exports . telegram _token = Config . telegram _toke
module . exports . platform = Config . bds _platform
}
2021-04-29 00:35:47 -03:00
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-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-05-06 22:58:17 -03: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-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-05-05 23:48:25 -03:00
const user _file _connected = path . join ( bds _dir , "bds_usersV3.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
2021-05-05 23:48:25 -03:00
if ( ! ( fs . existsSync ( user _file _connected ) ) ) {
let config = { } ;
config [ "bedrock" ] = { } ;
config [ "java" ] = { } ;
config [ "pocketmine" ] = { } ;
config [ "jsprismarine" ] = { } ;
let NewJson = JSON . stringify ( config , null , 4 ) ;
fs . writeFileSync ( user _file _connected , NewJson ) ;
}
2021-03-14 16:55:05 -03:00
const file _user _check = fs . readFileSync ( user _file _connected , "utf8" ) ;
2021-05-06 22:58:17 -03:00
try {
JSON . parse ( file _user _check )
} catch ( error ) {
fs . renameSync ( user _file _connected , ` ${ user _file _connected } _old_ ${ Math . random ( ) } _ ${ new Date ( ) . getDate ( ) } _ ${ new Date ( ) . getMonth ( ) } _ ${ new Date ( ) . getFullYear ( ) } .json ` )
}
2021-04-23 21:40:08 -03:00
module . exports . telegram _token = bds _config . telegram _token
2021-05-20 21:06:00 -03:00
function token _register ( ) {
const bds _token _path = path . join ( bds _dir , "bds_tokens.json" ) ;
if ( ! ( fs . existsSync ( bds _token _path ) ) ) fs . writeFileSync ( bds _token _path , "[]" ) ;
randomBytes ( ( Math . trunc ( 15 * ( 10 * Math . random ( ) ) ) ) , function ( err , buffer ) {
if ( err ) return console . warn ( err ) ;
2021-02-17 19:17:00 +00:00
const new _token = buffer . toString ( "hex" ) ;
var tokens = JSON . parse ( fs . readFileSync ( bds _token _path , "utf8" ) ) ;
2021-05-20 21:06:00 -03:00
tokens . push ( { token : new _token } ) ;
2021-03-14 01:55:34 +00:00
fs . writeFileSync ( bds _token _path , JSON . stringify ( tokens , null , 4 ) , "utf8" ) ;
2021-04-12 00:36:47 -03:00
console . log ( ` Bds Maneger API REST token: " ${ new _token } " ` ) ;
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 { config , get _config , config _example } = require ( "./scripts/bds_settings" ) ;
2021-04-23 21:40:08 -03:00
const download = require ( "./scripts/download" ) ;
2021-05-20 21:06:00 -03:00
const { start , stop , BdsCommand } = require ( "./scripts/basic_server" )
2021-04-18 23:36:41 -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-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 ( ) ;
2021-05-20 21:06:00 -03:00
* server . log ( function ( log ) { console . log ( log ) } )
2021-02-09 01:29:08 -03:00
* /
2021-05-20 21:06:00 -03:00
module . exports . start = start
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-06-11 17:13:40 -03:00
// Core Applications
2021-05-20 21:06:00 -03:00
/ * *
* This is telegram bot
* /
2021-06-11 17:13:40 -03:00
module . exports . telegram = require ( "./scripts/telegram_bot" )
// Backups
const Jobs = { } ;
for ( let index of bds _config . BackupCron ) {
Jobs [ index ] = new CronJob ( index , function ( ) {
World _BAckup ( )
} ) ;
}
2021-06-14 18:39:33 +00:00
module . exports . CronBackups = Jobs