const cp = require('child_process') const path = require('path') const {AssetGuard} = require(path.join(__dirname, 'assets', 'js', 'assetguard.js')) const ProcessBuilder = require(path.join(__dirname, 'assets', 'js', 'processbuilder.js')) const ConfigManager = require(path.join(__dirname, 'assets', 'js', 'configmanager.js')) const DiscordWrapper = require(path.join(__dirname, 'assets', 'js', 'discordwrapper.js')) const Mojang = require(path.join(__dirname, 'assets', 'js', 'mojang.js')) const AuthManager = require(path.join(__dirname, 'assets', 'js', 'authmanager.js')) let mojangStatusListener // Launch Elements let launch_content, launch_details, launch_progress, launch_progress_label, launch_details_text // Synchronous Listener document.addEventListener('readystatechange', function(){ if (document.readyState === 'interactive'){ // 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') // Bind launch button document.getElementById('launch_button').addEventListener('click', function(e){ console.log('Launching game..') //testdownloads() dlAsync() }) // TODO convert this to dropdown menu. // Bind selected server document.getElementById('server_selection').innerHTML = '\u2022 ' + AssetGuard.getServerById(ConfigManager.getGameDirectory(), ConfigManager.getSelectedServer()).name // Update Mojang Status Color const refreshMojangStatuses = async function(){ console.log('Refreshing Mojang Statuses..') try { let status = 'grey' const statuses = await Mojang.status() greenCount = 0 for(let i=0; i { if(currentProc === 'validateDistribution'){ launch_progress.setAttribute('value', 20) launch_progress_label.innerHTML = '20%' serv = m.result console.log('forge stuff done') // Begin version load. launch_details_text.innerHTML = 'Loading version information..' currentProc = 'loadVersionData' aEx.send({task: 0, content: currentProc, argsArr: [serv.mc_version]}) } else if(currentProc === 'loadVersionData'){ launch_progress.setAttribute('value', 40) launch_progress_label.innerHTML = '40%' versionData = m.result // Begin asset validation. launch_details_text.innerHTML = 'Validating asset integrity..' currentProc = 'validateAssets' aEx.send({task: 0, content: currentProc, argsArr: [versionData]}) } else if(currentProc === 'validateAssets'){ launch_progress.setAttribute('value', 60) launch_progress_label.innerHTML = '60%' console.log('assets done') // Begin library validation. launch_details_text.innerHTML = 'Validating library integrity..' currentProc = 'validateLibraries' aEx.send({task: 0, content: currentProc, argsArr: [versionData]}) } else if(currentProc === 'validateLibraries'){ launch_progress.setAttribute('value', 80) launch_progress_label.innerHTML = '80%' console.log('libs done') // Begin miscellaneous validation. launch_details_text.innerHTML = 'Validating miscellaneous file integrity..' currentProc = 'validateMiscellaneous' aEx.send({task: 0, content: currentProc, argsArr: [versionData]}) } else if(currentProc === 'validateMiscellaneous'){ launch_progress.setAttribute('value', 100) launch_progress_label.innerHTML = '100%' console.log('files done') launch_details_text.innerHTML = 'Downloading files..' currentProc = 'processDlQueues' aEx.send({task: 0, content: currentProc}) } else if(currentProc === 'processDlQueues'){ if(m.task === 0){ remote.getCurrentWindow().setProgressBar(m.value/m.total) launch_progress.setAttribute('max', m.total) launch_progress.setAttribute('value', m.value) launch_progress_label.innerHTML = m.percent + '%' } else if(m.task === 1){ remote.getCurrentWindow().setProgressBar(-1) launch_details_text.innerHTML = 'Preparing to launch..' currentProc = 'loadForgeData' aEx.send({task: 0, content: currentProc, argsArr: [serv.id]}) } else { console.error('Unknown download data type.', m) } } else if(currentProc === 'loadForgeData'){ forgeData = m.result if(login) { //if(!(await AuthManager.validateSelected())){ // //} const authUser = ConfigManager.getSelectedAccount(); console.log('authu', authUser) let pb = new ProcessBuilder(ConfigManager.getGameDirectory(), serv, versionData, forgeData, authUser) launch_details_text.innerHTML = 'Launching game..' try{ proc = pb.build() launch_details_text.innerHTML = 'Done. Enjoy the server!' const tempListener = function(data){ if(data.indexOf('[Client thread/INFO]: -- System Details --') > -1){ launch_details.style.display = 'none' launch_content.style.display = 'inline-flex' if(hasRPC){ DiscordWrapper.updateDetails('Loading game..') } proc.stdout.removeListener('data', tempListener) } } const gameStateChange = function(data){ if(servJoined.test(data)){ DiscordWrapper.updateDetails('Exploring the Realm!') } else if(gameJoined.test(data)){ DiscordWrapper.updateDetails('Idling on Main Menu') } } proc.stdout.on('data', tempListener) proc.stdout.on('data', gameStateChange) // Init Discord Hook (Untested) 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 }) } } catch(err) { //launch_details_text.innerHTML = 'Error: ' + err.message; launch_details_text.innerHTML = 'Error: See log for details..'; console.log(err) setTimeout(function(){ launch_details.style.display = 'none' launch_content.style.display = 'inline-flex' }, 5000) } } // Disconnect from AssetExec aEx.disconnect() } }) launch_details_text.innerHTML = 'Loading server information..' currentProc = 'validateDistribution' aEx.send({task: 0, content: currentProc, argsArr: [ConfigManager.getSelectedServer()]}) }