2018-01-19 04:45:50 +00:00
const cp = require ( 'child_process' )
2017-11-30 06:40:56 +00:00
const path = require ( 'path' )
2017-11-30 08:00:06 +00:00
const { AssetGuard } = require ( path . join ( _ _dirname , 'assets' , 'js' , 'assetguard.js' ) )
2017-11-30 06:40:56 +00:00
const ProcessBuilder = require ( path . join ( _ _dirname , 'assets' , 'js' , 'processbuilder.js' ) )
2017-12-03 05:38:22 +00:00
const ConfigManager = require ( path . join ( _ _dirname , 'assets' , 'js' , 'configmanager.js' ) )
2017-12-03 07:13:42 +00:00
const DiscordWrapper = require ( path . join ( _ _dirname , 'assets' , 'js' , 'discordwrapper.js' ) )
2017-12-03 13:12:55 +00:00
const Mojang = require ( path . join ( _ _dirname , 'assets' , 'js' , 'mojang.js' ) )
const AuthManager = require ( path . join ( _ _dirname , 'assets' , 'js' , 'authmanager.js' ) )
2018-04-16 02:35:14 +00:00
const ServerStatus = require ( path . join ( _ _dirname , 'assets' , 'js' , 'serverstatus.js' ) )
const { URL } = require ( 'url' )
2017-11-30 06:40:56 +00:00
2017-12-03 12:05:13 +00:00
let mojangStatusListener
2018-04-16 02:35:14 +00:00
let serverStatusListener
2017-12-03 12:05:13 +00:00
2018-01-19 04:45:50 +00:00
// Launch Elements
let launch _content , launch _details , launch _progress , launch _progress _label , launch _details _text
2017-12-03 12:05:13 +00:00
// Synchronous Listener
2017-11-30 08:00:06 +00:00
document . addEventListener ( 'readystatechange' , function ( ) {
2018-04-02 20:05:48 +00:00
if ( document . readyState === 'complete' ) {
if ( ConfigManager . isFirstLaunch ( ) ) {
$ ( '#welcomeContainer' ) . fadeIn ( 500 )
} else {
$ ( '#landingContainer' ) . fadeIn ( 500 )
}
}
2017-11-30 06:40:56 +00:00
if ( document . readyState === 'interactive' ) {
2018-01-19 04:45:50 +00:00
// Save a reference to the launch elements.
launch _content = document . getElementById ( 'launch_content' )
launch _details = document . getElementById ( 'launch_details' )
launch _progress = document . getElementById ( 'launch_progress' )
launch _progress _label = document . getElementById ( 'launch_progress_label' )
launch _details _text = document . getElementById ( 'launch_details_text' )
2017-11-30 06:40:56 +00:00
// Bind launch button
2017-12-02 07:59:25 +00:00
document . getElementById ( 'launch_button' ) . addEventListener ( 'click' , function ( e ) {
2017-11-30 06:40:56 +00:00
console . log ( 'Launching game..' )
2018-04-02 22:40:32 +00:00
const jExe = ConfigManager . getJavaExecutable ( )
if ( jExe == null ) {
asyncSystemScan ( )
} else {
2018-04-07 22:06:49 +00:00
setLaunchDetails ( 'Please wait..' )
toggleLaunchArea ( true )
setLaunchPercentage ( 0 , 100 )
2018-04-02 22:40:32 +00:00
AssetGuard . _validateJavaBinary ( jExe ) . then ( ( v ) => {
if ( v ) {
dlAsync ( )
} else {
asyncSystemScan ( )
}
} )
}
2017-11-30 06:40:56 +00:00
} )
2017-12-02 07:59:25 +00:00
// TODO convert this to dropdown menu.
// Bind selected server
2017-12-03 05:38:22 +00:00
document . getElementById ( 'server_selection' ) . innerHTML = '\u2022 ' + AssetGuard . getServerById ( ConfigManager . getGameDirectory ( ) , ConfigManager . getSelectedServer ( ) ) . name
2017-11-30 06:40:56 +00:00
2017-12-03 12:05:13 +00:00
// Update Mojang Status Color
const refreshMojangStatuses = async function ( ) {
console . log ( 'Refreshing Mojang Statuses..' )
2018-04-14 22:42:45 +00:00
let status = 'grey'
2017-12-03 12:05:13 +00:00
try {
2017-12-03 13:12:55 +00:00
const statuses = await Mojang . status ( )
2017-12-03 12:05:13 +00:00
greenCount = 0
for ( let i = 0 ; i < statuses . length ; i ++ ) {
if ( statuses [ i ] . status === 'yellow' && status !== 'red' ) {
status = 'yellow'
continue
} else if ( statuses [ i ] . status === 'red' ) {
status = 'red'
break
}
++ greenCount
}
if ( greenCount == statuses . length ) {
status = 'green'
}
} catch ( err ) {
2018-04-14 22:42:45 +00:00
console . warn ( 'Unable to refresh Mojang service status.' )
console . debug ( err )
2017-12-03 12:05:13 +00:00
}
2018-04-14 22:42:45 +00:00
document . getElementById ( 'mojang_status_icon' ) . style . color = Mojang . statusToHex ( status )
2017-12-03 12:05:13 +00:00
}
2018-04-16 02:35:14 +00:00
const refreshServerStatus = async function ( ) {
console . log ( 'Refreshing Server Status' )
const serv = AssetGuard . resolveSelectedServer ( ConfigManager . getGameDirectory ( ) )
let pLabel = 'SERVER'
let pVal = 'OFFLINE'
try {
const serverURL = new URL ( 'my://' + serv . server _ip )
const servStat = await ServerStatus . getStatus ( serverURL . hostname , serverURL . port )
if ( servStat . online ) {
pLabel = 'PLAYERS'
pVal = servStat . onlinePlayers + '/' + servStat . maxPlayers
}
} catch ( err ) {
console . warn ( 'Unable to refresh server status, assuming offline.' )
console . debug ( err )
}
document . getElementById ( 'landingPlayerLabel' ) . innerHTML = pLabel
document . getElementById ( 'player_count' ) . innerHTML = pVal
}
2017-12-03 12:05:13 +00:00
refreshMojangStatuses ( )
2018-04-16 02:35:14 +00:00
refreshServerStatus ( )
2017-12-03 12:05:13 +00:00
// Set refresh rate to once every 5 minutes.
mojangStatusListener = setInterval ( refreshMojangStatuses , 300000 )
2018-04-16 02:35:14 +00:00
serverStatusListener = setInterval ( refreshServerStatus , 300000 )
2017-12-03 12:05:13 +00:00
2017-11-30 06:40:56 +00:00
}
2017-11-30 08:00:06 +00:00
} , false )
2018-04-06 16:33:20 +00:00
/* Overlay Wrapper Functions */
/ * *
* Toggle the visibility of the overlay .
*
* @ param { boolean } toggleState True to display , false to hide .
2018-04-15 02:20:59 +00:00
* @ param { boolean } dismissable Optional . True to show the dismiss option , otherwise false .
2018-04-06 16:33:20 +00:00
* /
2018-04-15 02:20:59 +00:00
function toggleOverlay ( toggleState , dismissable = false ) {
2018-04-06 16:33:20 +00:00
if ( toggleState == null ) {
toggleState = ! document . getElementById ( 'main' ) . hasAttribute ( 'overlay' )
}
if ( toggleState ) {
document . getElementById ( 'main' ) . setAttribute ( 'overlay' , true )
2018-04-15 02:20:59 +00:00
$ ( '#overlayDismiss' ) . toggle ( dismissable )
2018-04-07 17:29:40 +00:00
$ ( '#overlayContainer' ) . fadeToggle ( 250 )
2018-04-06 16:33:20 +00:00
} else {
document . getElementById ( 'main' ) . removeAttribute ( 'overlay' )
2018-04-15 02:20:59 +00:00
$ ( '#overlayContainer' ) . fadeToggle ( 250 , ( ) => {
$ ( '#overlayDismiss' ) . toggle ( dismissable )
} )
2018-04-07 17:29:40 +00:00
}
}
/ * *
* Set the content of the overlay .
*
* @ param { string } title Overlay title text .
* @ param { string } description Overlay description text .
* @ param { string } acknowledge Acknowledge button text .
2018-04-15 02:20:59 +00:00
* @ param { string } dismiss Dismiss button text .
2018-04-07 17:29:40 +00:00
* /
2018-04-15 02:20:59 +00:00
function setOverlayContent ( title , description , acknowledge , dismiss = 'Dismiss' ) {
2018-04-07 17:29:40 +00:00
document . getElementById ( 'overlayTitle' ) . innerHTML = title
document . getElementById ( 'overlayDesc' ) . innerHTML = description
document . getElementById ( 'overlayAcknowledge' ) . innerHTML = acknowledge
2018-04-15 02:20:59 +00:00
document . getElementById ( 'overlayDismiss' ) . innerHTML = dismiss
2018-04-07 17:29:40 +00:00
}
/ * *
* Set the onclick handler of the overlay acknowledge button .
* If the handler is null , a default handler will be added .
*
* @ param { function } handler
* /
function setOverlayHandler ( handler ) {
if ( handler == null ) {
document . getElementById ( 'overlayAcknowledge' ) . onclick = ( ) => {
toggleOverlay ( false )
}
} else {
document . getElementById ( 'overlayAcknowledge' ) . onclick = handler
2018-04-06 16:33:20 +00:00
}
}
2018-04-15 02:20:59 +00:00
/ * *
* Set the onclick handler of the overlay dismiss button .
* If the handler is null , a default handler will be added .
*
* @ param { function } handler
* /
function setDismissHandler ( handler ) {
if ( handler == null ) {
document . getElementById ( 'overlayDismiss' ) . onclick = ( ) => {
toggleOverlay ( false )
}
} else {
document . getElementById ( 'overlayDismiss' ) . onclick = handler
}
}
2018-04-02 22:40:32 +00:00
/* Launch Progress Wrapper Functions */
2018-04-06 16:33:20 +00:00
/ * *
* Show / hide the loading area .
*
* @ param { boolean } loading True if the loading area should be shown , otherwise false .
* /
2018-04-02 22:40:32 +00:00
function toggleLaunchArea ( loading ) {
if ( loading ) {
launch _details . style . display = 'flex'
launch _content . style . display = 'none'
} else {
launch _details . style . display = 'none'
launch _content . style . display = 'inline-flex'
}
}
2018-04-06 16:33:20 +00:00
/ * *
* Set the details text of the loading area .
*
* @ param { string } details The new text for the loading details .
* /
2018-04-02 22:40:32 +00:00
function setLaunchDetails ( details ) {
launch _details _text . innerHTML = details
}
2018-04-06 16:33:20 +00:00
/ * *
* Set the value of the loading progress bar and display that value .
*
* @ param { number } value The progress value .
* @ param { number } max The total size .
* @ param { number | string } percent Optional . The percentage to display on the progress label .
* /
2018-04-02 22:40:32 +00:00
function setLaunchPercentage ( value , max , percent = ( ( value / max ) * 100 ) ) {
launch _progress . setAttribute ( 'max' , max )
launch _progress . setAttribute ( 'value' , value )
launch _progress _label . innerHTML = percent + '%'
}
2018-04-06 16:33:20 +00:00
/ * *
* Set the value of the OS progress bar and display that on the UI .
*
* @ param { number } value The progress value .
* @ param { number } max The total download size .
* @ param { number | string } percent Optional . The percentage to display on the progress label .
* /
2018-04-02 22:40:32 +00:00
function setDownloadPercentage ( value , max , percent = ( ( value / max ) * 100 ) ) {
remote . getCurrentWindow ( ) . setProgressBar ( value / max )
setLaunchPercentage ( value , max , percent )
}
2018-04-06 16:33:20 +00:00
/* System (Java) Scan */
2018-04-02 22:40:32 +00:00
let sysAEx
let scanAt
2018-04-07 22:06:49 +00:00
function asyncSystemScan ( launchAfter = true ) {
2018-04-02 22:40:32 +00:00
setLaunchDetails ( 'Please wait..' )
toggleLaunchArea ( true )
setLaunchPercentage ( 0 , 100 )
2018-04-07 22:06:49 +00:00
// Fork a process to run validations.
2018-04-02 22:40:32 +00:00
sysAEx = cp . fork ( path . join ( _ _dirname , 'assets' , 'js' , 'assetexec.js' ) , [
ConfigManager . getGameDirectory ( ) ,
ConfigManager . getJavaExecutable ( )
] )
sysAEx . on ( 'message' , ( m ) => {
if ( m . content === 'validateJava' ) {
2018-04-15 04:00:08 +00:00
2018-04-07 22:06:49 +00:00
if ( m . result == null ) {
// If the result is null, no valid Java installation was found.
// Show this information to the user.
setOverlayContent (
2018-04-07 22:24:13 +00:00
'No Compatible<br>Java Installation Found' ,
2018-04-07 22:06:49 +00:00
'In order to join WesterosCraft, you need a 64-bit installation of Java 8. Would you like us to install a copy? By installing, you accept <a href="http://www.oracle.com/technetwork/java/javase/terms/license/index.html">Oracle\'s license agreement</a>.' ,
2018-04-15 02:20:59 +00:00
'Install Java' ,
'Install Manually'
2018-04-07 22:06:49 +00:00
)
setOverlayHandler ( ( ) => {
setLaunchDetails ( 'Preparing Java Download..' )
sysAEx . send ( { task : 0 , content : '_enqueueOracleJRE' , argsArr : [ ConfigManager . getLauncherDirectory ( ) ] } )
toggleOverlay ( false )
} )
2018-04-15 02:20:59 +00:00
setDismissHandler ( ( ) => {
$ ( '#overlayContent' ) . fadeOut ( 250 , ( ) => {
//$('#overlayDismiss').toggle(false)
setOverlayContent (
'Don\'t Forget!<br>Java is Required' ,
'A valid x64 installation of Java 8 is required to launch. Downloads can be found on <a href="http://www.oracle.com/technetwork/java/javase/downloads/jre8-downloads-2133155.html">Oracle\'s website</a>. Once installed, you will be able to connect to the server.<br><br>Please refer to our <a href="http://westeroscraft.wikia.com/wiki/Troubleshooting_Guide">Troubleshooting Guide</a> if you have any difficulty.' ,
'I Understand' ,
'Go Back'
)
setOverlayHandler ( ( ) => {
toggleLaunchArea ( false )
toggleOverlay ( false )
} )
setDismissHandler ( ( ) => {
toggleOverlay ( false , true )
asyncSystemScan ( )
} )
$ ( '#overlayContent' ) . fadeIn ( 250 )
} )
} )
toggleOverlay ( true , true )
2018-04-07 22:06:49 +00:00
// TODO Add option to not install Java x64.
} else {
// Java installation found, use this to launch the game.
ConfigManager . setJavaExecutable ( m . result )
ConfigManager . save ( )
if ( launchAfter ) {
dlAsync ( )
}
sysAEx . disconnect ( )
}
} else if ( m . content === '_enqueueOracleJRE' ) {
if ( m . result === true ) {
// Oracle JRE enqueued successfully, begin download.
setLaunchDetails ( 'Downloading Java..' )
sysAEx . send ( { task : 0 , content : 'processDlQueues' , argsArr : [ [ { id : 'java' , limit : 1 } ] ] } )
} else {
// Oracle JRE enqueue failed. Probably due to a change in their website format.
// User will have to follow the guide to install Java.
setOverlayContent (
2018-04-07 22:24:13 +00:00
'Unexpected Issue:<br>Java Download Failed' ,
'Unfortunately we\'ve encountered an issue while attempting to install Java. You will need to manually install a copy. Please check out our <a href="http://westeroscraft.wikia.com/wiki/Troubleshooting_Guide">Troubleshooting Guide</a> for more details and instructions.' ,
'I Understand'
2018-04-07 22:06:49 +00:00
)
2018-04-07 22:24:13 +00:00
setOverlayHandler ( ( ) => {
toggleOverlay ( false )
toggleLaunchArea ( false )
} )
2018-04-07 22:06:49 +00:00
toggleOverlay ( true )
sysAEx . disconnect ( )
}
} else if ( m . content === 'dl' ) {
if ( m . task === 0 ) {
// Downloading..
setDownloadPercentage ( m . value , m . total , m . percent )
} else if ( m . task === 1 ) {
// Download will be at 100%, remove the loading from the OS progress bar.
remote . getCurrentWindow ( ) . setProgressBar ( - 1 )
// Wait for extration to complete.
setLaunchDetails ( 'Extracting..' )
} else if ( m . task === 2 ) {
// Extraction completed successfully.
ConfigManager . setJavaExecutable ( m . jPath )
ConfigManager . save ( )
setLaunchDetails ( 'Java Installed!' )
if ( launchAfter ) {
dlAsync ( )
}
sysAEx . disconnect ( )
} else {
console . error ( 'Unknown download data type.' , m )
}
2018-04-02 22:40:32 +00:00
}
} )
2018-04-07 22:06:49 +00:00
// Begin system Java scan.
2018-04-02 22:40:32 +00:00
setLaunchDetails ( 'Checking system info..' )
sysAEx . send ( { task : 0 , content : 'validateJava' , argsArr : [ ConfigManager . getLauncherDirectory ( ) ] } )
}
2018-01-19 04:45:50 +00:00
// Keep reference to Minecraft Process
let proc
// Is DiscordRPC enabled
let hasRPC = false
// Joined server regex
const servJoined = /[[0-2][0-9]:[0-6][0-9]:[0-6][0-9]\] \[Client thread\/INFO\]: \[CHAT\] [a-zA-Z0-9_]{1,16} joined the game/g
const gameJoined = /\[[0-2][0-9]:[0-6][0-9]:[0-6][0-9]\] \[Client thread\/WARN\]: Skipping bad option: lastServer:/g
const gameJoined2 = /\[[0-2][0-9]:[0-6][0-9]:[0-6][0-9]\] \[Client thread\/INFO\]: Created: \d+x\d+ textures-atlas/g
let aEx
let serv
let versionData
let forgeData
function dlAsync ( login = true ) {
// Login parameter is temporary for debug purposes. Allows testing the validation/downloads without
// launching the game.
if ( login ) {
if ( ConfigManager . getSelectedAccount ( ) == null ) {
console . error ( 'login first.' )
//in devtools AuthManager.addAccount(username, pass)
return
}
}
2018-04-02 22:40:32 +00:00
setLaunchDetails ( 'Please wait..' )
toggleLaunchArea ( true )
setLaunchPercentage ( 0 , 100 )
2017-11-30 06:40:56 +00:00
2018-04-02 22:40:32 +00:00
// Start AssetExec to run validations and downloads in a forked process.
2018-01-19 04:45:50 +00:00
aEx = cp . fork ( path . join ( _ _dirname , 'assets' , 'js' , 'assetexec.js' ) , [
ConfigManager . getGameDirectory ( ) ,
ConfigManager . getJavaExecutable ( )
] )
2017-12-03 13:12:55 +00:00
2018-04-02 22:40:32 +00:00
// Establish communications between the AssetExec and current process.
2018-01-19 04:45:50 +00:00
aEx . on ( 'message' , ( m ) => {
2018-04-02 22:40:32 +00:00
if ( m . content === 'validateDistribution' ) {
2017-12-03 13:12:55 +00:00
2018-04-02 22:40:32 +00:00
setLaunchPercentage ( 20 , 100 )
2018-01-19 04:45:50 +00:00
serv = m . result
2018-04-02 22:40:32 +00:00
console . log ( 'Forge Validation Complete.' )
2017-11-30 06:40:56 +00:00
2018-01-19 04:45:50 +00:00
// Begin version load.
2018-04-02 22:40:32 +00:00
setLaunchDetails ( 'Loading version information..' )
aEx . send ( { task : 0 , content : 'loadVersionData' , argsArr : [ serv . mc _version ] } )
2018-01-19 04:45:50 +00:00
2018-04-02 22:40:32 +00:00
} else if ( m . content === 'loadVersionData' ) {
2018-01-19 04:45:50 +00:00
2018-04-02 22:40:32 +00:00
setLaunchPercentage ( 40 , 100 )
2018-01-19 04:45:50 +00:00
versionData = m . result
2018-04-02 22:40:32 +00:00
console . log ( 'Version data loaded.' )
2018-01-19 04:45:50 +00:00
// Begin asset validation.
2018-04-02 22:40:32 +00:00
setLaunchDetails ( 'Validating asset integrity..' )
aEx . send ( { task : 0 , content : 'validateAssets' , argsArr : [ versionData ] } )
2018-01-19 04:45:50 +00:00
2018-04-02 22:40:32 +00:00
} else if ( m . content === 'validateAssets' ) {
2018-01-19 04:45:50 +00:00
2018-04-07 22:06:49 +00:00
// Asset validation can *potentially* take longer, so let's track progress.
if ( m . task === 0 ) {
const perc = ( m . value / m . total ) * 20
setLaunchPercentage ( 40 + perc , 100 , parseInt ( 40 + perc ) )
} else {
setLaunchPercentage ( 60 , 100 )
console . log ( 'Asset Validation Complete' )
2018-01-19 04:45:50 +00:00
2018-04-07 22:06:49 +00:00
// Begin library validation.
setLaunchDetails ( 'Validating library integrity..' )
aEx . send ( { task : 0 , content : 'validateLibraries' , argsArr : [ versionData ] } )
}
2018-01-19 04:45:50 +00:00
2018-04-02 22:40:32 +00:00
} else if ( m . content === 'validateLibraries' ) {
2018-01-19 04:45:50 +00:00
2018-04-02 22:40:32 +00:00
setLaunchPercentage ( 80 , 100 )
console . log ( 'Library validation complete.' )
2018-01-19 04:45:50 +00:00
// Begin miscellaneous validation.
2018-04-02 22:40:32 +00:00
setLaunchDetails ( 'Validating miscellaneous file integrity..' )
aEx . send ( { task : 0 , content : 'validateMiscellaneous' , argsArr : [ versionData ] } )
2018-01-19 04:45:50 +00:00
2018-04-02 22:40:32 +00:00
} else if ( m . content === 'validateMiscellaneous' ) {
2018-01-19 04:45:50 +00:00
2018-04-02 22:40:32 +00:00
setLaunchPercentage ( 100 , 100 )
console . log ( 'File validation complete.' )
2018-01-19 04:45:50 +00:00
2018-04-02 22:40:32 +00:00
// Download queued files.
setLaunchDetails ( 'Downloading files..' )
aEx . send ( { task : 0 , content : 'processDlQueues' } )
} else if ( m . content === 'dl' ) {
2018-01-19 04:45:50 +00:00
if ( m . task === 0 ) {
2018-04-02 22:40:32 +00:00
setDownloadPercentage ( m . value , m . total , m . percent )
2018-01-19 04:45:50 +00:00
} else if ( m . task === 1 ) {
2018-04-02 22:40:32 +00:00
// Download will be at 100%, remove the loading from the OS progress bar.
2018-01-19 04:45:50 +00:00
remote . getCurrentWindow ( ) . setProgressBar ( - 1 )
2018-04-02 22:40:32 +00:00
setLaunchDetails ( 'Preparing to launch..' )
aEx . send ( { task : 0 , content : 'loadForgeData' , argsArr : [ serv . id ] } )
2018-01-19 04:45:50 +00:00
} else {
2018-04-02 22:40:32 +00:00
2018-01-19 04:45:50 +00:00
console . error ( 'Unknown download data type.' , m )
2018-04-02 22:40:32 +00:00
2017-11-30 06:40:56 +00:00
}
2018-04-02 22:40:32 +00:00
} else if ( m . content === 'loadForgeData' ) {
2018-01-19 04:45:50 +00:00
forgeData = m . result
if ( login ) {
//if(!(await AuthManager.validateSelected())){
//
//}
2018-04-15 02:20:59 +00:00
const authUser = ConfigManager . getSelectedAccount ( )
2018-01-19 04:45:50 +00:00
console . log ( 'authu' , authUser )
let pb = new ProcessBuilder ( ConfigManager . getGameDirectory ( ) , serv , versionData , forgeData , authUser )
2018-04-02 22:40:32 +00:00
setLaunchDetails ( 'Launching game..' )
try {
// Build Minecraft process.
2018-01-19 04:45:50 +00:00
proc = pb . build ( )
2018-04-02 22:40:32 +00:00
setLaunchDetails ( 'Done. Enjoy the server!' )
// Attach a temporary listener to the client output.
// Will wait for a certain bit of text meaning that
// the client application has started, and we can hide
// the progress bar stuff.
2018-01-19 04:45:50 +00:00
const tempListener = function ( data ) {
if ( data . indexOf ( '[Client thread/INFO]: -- System Details --' ) > - 1 ) {
2018-04-02 22:40:32 +00:00
toggleLaunchArea ( false )
2018-01-19 04:45:50 +00:00
if ( hasRPC ) {
DiscordWrapper . updateDetails ( 'Loading game..' )
}
proc . stdout . removeListener ( 'data' , tempListener )
}
}
2018-04-02 22:40:32 +00:00
// Listener for Discord RPC.
2018-01-19 04:45:50 +00:00
const gameStateChange = function ( data ) {
if ( servJoined . test ( data ) ) {
DiscordWrapper . updateDetails ( 'Exploring the Realm!' )
} else if ( gameJoined . test ( data ) ) {
DiscordWrapper . updateDetails ( 'Idling on Main Menu' )
}
}
2018-04-02 22:40:32 +00:00
// Bind listeners to stdout.
2018-01-19 04:45:50 +00:00
proc . stdout . on ( 'data' , tempListener )
proc . stdout . on ( 'data' , gameStateChange )
2018-04-02 22:40:32 +00:00
// Init Discord Hook
2018-01-19 04:45:50 +00:00
const distro = AssetGuard . retrieveDistributionDataSync ( ConfigManager . getGameDirectory )
if ( distro . discord != null && serv . discord != null ) {
DiscordWrapper . initRPC ( distro . discord , serv . discord )
hasRPC = true
proc . on ( 'close' , ( code , signal ) => {
console . log ( 'Shutting down Discord Rich Presence..' )
DiscordWrapper . shutdownRPC ( )
hasRPC = false
proc = null
} )
}
2018-04-02 22:40:32 +00:00
2018-01-19 04:45:50 +00:00
} catch ( err ) {
2018-04-02 22:40:32 +00:00
// Show that there was an error then hide the
// progress area. Maybe switch this to an error
// alert in the future. TODO
setLaunchDetails ( 'Error: See log for details..' )
2018-01-19 04:45:50 +00:00
console . log ( err )
setTimeout ( function ( ) {
2018-04-02 22:40:32 +00:00
toggleLaunchArea ( false )
2018-01-19 04:45:50 +00:00
} , 5000 )
2018-04-02 22:40:32 +00:00
2018-01-19 04:45:50 +00:00
}
2017-12-03 07:13:42 +00:00
}
2018-01-19 04:45:50 +00:00
// Disconnect from AssetExec
aEx . disconnect ( )
2017-11-30 06:40:56 +00:00
}
} )
2018-01-19 04:45:50 +00:00
2018-04-02 22:40:32 +00:00
// Begin Validations
// Validate Forge files.
setLaunchDetails ( 'Loading server information..' )
aEx . send ( { task : 0 , content : 'validateDistribution' , argsArr : [ ConfigManager . getSelectedServer ( ) ] } )
2017-11-30 06:40:56 +00:00
}