2021-06-24 17:36:34 -03:00
const commadExist = require ( "./commandExist" )
const { execSync } = require ( "child_process" ) ;
const { readdirSync } = require ( "fs" ) ;
const { release } = require ( "os" )
const { PHPBin , Servers } = require ( "./ServerURL" ) ;
// System Architect (x64, aarch64 and others)
var arch ;
if ( process . arch === "arm64" ) arch = "aarch64" ; else arch = process . arch
module . exports . arch = arch
var system ,
require _qemu = false ,
valid _platform = {
bedrock : true ,
pocketmine : true ,
java : commadExist ( "java" ) ,
jsprismarine : commadExist ( "node" )
}
// check php bin
if ( PHPBin [ process . platform ] ) {
if ( PHPBin [ process . platform ] [ arch ] ) valid _platform [ "pocketmine" ] = true ; else valid _platform [ "pocketmine" ] = false
} else valid _platform [ "pocketmine" ] = false
// SoSystem X
if ( process . platform == "win32" ) {
system = "Windows" ;
// arm64 and X64
2021-06-24 19:56:44 -03:00
// if (!(arch === "x64" || arch === "aarch64")) valid_platform["bedrock"] = false;
2021-06-24 17:36:34 -03:00
} else if ( process . platform == "linux" ) {
system = "Linux" ;
2021-06-24 19:56:44 -03:00
if ( Servers . bedrock [ Servers . latest . bedrock ] [ arch ] ) {
2021-06-24 17:36:34 -03:00
if ( Servers . bedrock [ Servers . bedrock _latest ] [ arch ] [ process . platform ] ) valid _platform [ "bedrock" ] = true ; else valid _platform [ "bedrock" ] = false ;
} else valid _platform [ "bedrock" ] = false
2021-06-24 19:56:44 -03:00
if ( PHPBin [ process . platform ] [ arch ] ) valid _platform [ "pocketmine" ] = true ; else valid _platform [ "pocketmine" ] = false
2021-06-24 17:36:34 -03:00
if ( valid _platform [ "bedrock" ] === false ) {
if ( commadExist ( "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
}
}
} else if ( process . platform == "darwin" ) {
system = "MacOS" ;
valid _platform [ "bedrock" ] = false
} else if ( process . platform === "android" ) {
system = "Android" ;
valid _platform [ "bedrock" ] = false
valid _platform [ "java" ] = false
} else {
console . log ( ` The Bds Maneger Core does not support ${ process . platform } systems, as no tests have been done. ` ) ;
system = "Other" ;
valid _platform [ "bedrock" ] = false
valid _platform [ "pocketmine" ] = false
process . exit ( 254 )
}
function GetKernel ( ) {
if ( process . platform === "win32" ) {
const kernelVersion = parseFloat ( release ( ) ) ;
2021-06-25 19:32:18 -03:00
if ( kernelVersion <= 6.1 ) return "Windows 7" ;
else if ( kernelVersion <= 6.2 ) return "Windows 8" ;
else if ( kernelVersion <= 6.3 ) return "Windows 8.1" ;
else if ( kernelVersion <= 10.0 ) return "Windows 10" ;
else return "Other Windows or Windows 11" ;
2021-06-24 17:36:34 -03:00
}
else if ( process . platform === "android" ) return ` ${ release ( ) } , CPU Core ${ readdirSync ( "/sys/devices/system/cpu/" ) . filter ( data => { return /cpu[0-9]/ . test ( data ) } ).length} ` ;
else if ( commadExist ( "uname" ) ) {
const str = execSync ( "uname -rv" ) . toString ( "ascii" ) ;
switch ( true ) {
// amazon aws EC2
case /aws/ . test ( str ) :
if ( process . arch === "arm64" || process . arch === "aarch64" ) return "Amazon AWS Cloud arm64: AWS Graviton" ;
else return ` Amazon AWS Cloud ${ process . arch } : ${ require ( "os" ) . cpus ( ) [ 0 ] . model } ` ;
// Windows WSL 1
case /microsoft/ . test ( str ) :
return "Microsoft WSL 1" ;
// Windows WSL 2
case /Microsoft/ . test ( str ) :
return "Microsoft WSL 2" ;
// Azure Virtual Machinime (VM)
case /[aA]zure/ . test ( str ) :
return "Microsoft Azure" ;
// Google Cloud Virtual Machinime (VM)
case /[gG]cp/ . test ( str ) :
return "Google Cloud Platform" ;
// Oracle cloud Virtual Machinime (VM)
case /[oO]racle/ . test ( str ) :
return "Oracle Cloud infrastructure" ;
// Darwin
case /[dD]arwin/ . test ( str ) :
return "Apple MacOS" ;
// Others Kernels
default :
return str . split ( "\n" ) . join ( "" ) ;
}
} else return null ;
}
/ * *
* Platforms valid from deferents systems
* /
module . exports . valid _platform = valid _platform
module . exports . require _qemu = require _qemu
module . exports . system = system
module . exports . GetKernel = GetKernel ;