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'))
|
2017-11-30 06:40:56 +00:00
|
|
|
|
2017-12-03 12:05:13 +00:00
|
|
|
let mojangStatusListener
|
|
|
|
|
|
|
|
// Synchronous Listener
|
2017-11-30 08:00:06 +00:00
|
|
|
document.addEventListener('readystatechange', function(){
|
2017-11-30 06:40:56 +00:00
|
|
|
if (document.readyState === 'interactive'){
|
|
|
|
|
|
|
|
// 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..')
|
|
|
|
testdownloads()
|
|
|
|
})
|
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..')
|
|
|
|
try {
|
|
|
|
let status = 'grey'
|
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'
|
|
|
|
}
|
|
|
|
|
2017-12-03 13:12:55 +00:00
|
|
|
document.getElementById('mojang_status_icon').style.color = Mojang.statusToHex(status)
|
2017-12-03 12:05:13 +00:00
|
|
|
|
|
|
|
} catch (err) {
|
|
|
|
console.error('Unable to refresh Mojang service status..', err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
refreshMojangStatuses()
|
|
|
|
// Set refresh rate to once every 5 minutes.
|
|
|
|
mojangStatusListener = setInterval(refreshMojangStatuses, 300000)
|
|
|
|
|
2017-11-30 06:40:56 +00:00
|
|
|
}
|
2017-11-30 08:00:06 +00:00
|
|
|
}, false)
|
|
|
|
|
|
|
|
// Keep reference to AssetGuard object temporarily
|
|
|
|
let tracker;
|
2017-11-30 06:40:56 +00:00
|
|
|
|
|
|
|
testdownloads = async function(){
|
2017-12-03 13:12:55 +00:00
|
|
|
|
|
|
|
if(ConfigManager.getSelectedAccount() == null){
|
|
|
|
console.error('login first.')
|
|
|
|
//in devtools AuthManager.addAccount(username, pass)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2017-12-02 07:59:25 +00:00
|
|
|
const content = document.getElementById('launch_content')
|
|
|
|
const details = document.getElementById('launch_details')
|
|
|
|
const progress = document.getElementById('launch_progress')
|
|
|
|
const progress_text = document.getElementById('launch_progress_label')
|
|
|
|
const det_text = document.getElementById('launch_details_text')
|
2017-11-30 06:40:56 +00:00
|
|
|
|
|
|
|
det_text.innerHTML = 'Please wait..'
|
|
|
|
progress.setAttribute('max', '100')
|
|
|
|
details.style.display = 'flex'
|
|
|
|
content.style.display = 'none'
|
|
|
|
|
2017-12-03 05:38:22 +00:00
|
|
|
tracker = new AssetGuard(ConfigManager.getGameDirectory(), ConfigManager.getJavaExecutable())
|
2017-11-30 08:00:06 +00:00
|
|
|
|
2017-12-02 07:59:25 +00:00
|
|
|
det_text.innerHTML = 'Loading server information..'
|
2017-12-03 05:38:22 +00:00
|
|
|
const serv = await tracker.validateDistribution(ConfigManager.getSelectedServer())
|
2017-11-30 06:40:56 +00:00
|
|
|
progress.setAttribute('value', 20)
|
|
|
|
progress_text.innerHTML = '20%'
|
2017-12-02 07:59:25 +00:00
|
|
|
console.log('forge stuff done')
|
2017-11-30 06:40:56 +00:00
|
|
|
|
2017-12-02 07:59:25 +00:00
|
|
|
det_text.innerHTML = 'Loading version information..'
|
2017-12-03 03:41:47 +00:00
|
|
|
const versionData = await tracker.loadVersionData(serv.mc_version)
|
2017-11-30 06:40:56 +00:00
|
|
|
progress.setAttribute('value', 40)
|
|
|
|
progress_text.innerHTML = '40%'
|
2017-12-02 07:59:25 +00:00
|
|
|
|
|
|
|
det_text.innerHTML = 'Validating asset integrity..'
|
2017-12-03 03:41:47 +00:00
|
|
|
await tracker.validateAssets(versionData)
|
2017-12-02 07:59:25 +00:00
|
|
|
progress.setAttribute('value', 60)
|
|
|
|
progress_text.innerHTML = '60%'
|
2017-11-30 06:40:56 +00:00
|
|
|
console.log('assets done')
|
|
|
|
|
|
|
|
det_text.innerHTML = 'Validating library integrity..'
|
2017-12-03 03:41:47 +00:00
|
|
|
await tracker.validateLibraries(versionData)
|
2017-12-02 07:59:25 +00:00
|
|
|
progress.setAttribute('value', 80)
|
|
|
|
progress_text.innerHTML = '80%'
|
2017-11-30 06:40:56 +00:00
|
|
|
console.log('libs done')
|
|
|
|
|
|
|
|
det_text.innerHTML = 'Validating miscellaneous file integrity..'
|
2017-12-03 03:41:47 +00:00
|
|
|
await tracker.validateMiscellaneous(versionData)
|
2017-11-30 06:40:56 +00:00
|
|
|
progress.setAttribute('value', 100)
|
|
|
|
progress_text.innerHTML = '100%'
|
2017-12-02 07:59:25 +00:00
|
|
|
console.log('files done')
|
2017-11-30 06:40:56 +00:00
|
|
|
|
|
|
|
det_text.innerHTML = 'Downloading files..'
|
2017-11-30 08:00:06 +00:00
|
|
|
tracker.on('totaldlprogress', function(data){
|
2017-11-30 06:40:56 +00:00
|
|
|
progress.setAttribute('max', data.total)
|
|
|
|
progress.setAttribute('value', data.acc)
|
|
|
|
progress_text.innerHTML = parseInt((data.acc/data.total)*100) + '%'
|
|
|
|
})
|
|
|
|
|
2017-11-30 08:00:06 +00:00
|
|
|
tracker.on('dlcomplete', async function(){
|
|
|
|
|
2017-11-30 06:40:56 +00:00
|
|
|
det_text.innerHTML = 'Preparing to launch..'
|
2017-12-03 03:41:47 +00:00
|
|
|
const forgeData = await tracker.loadForgeData(serv.id)
|
2017-12-03 13:12:55 +00:00
|
|
|
const authUser = await AuthManager.validateSelected()
|
2017-12-03 05:38:22 +00:00
|
|
|
let pb = new ProcessBuilder(ConfigManager.getGameDirectory(), serv, versionData, forgeData, authUser)
|
2017-11-30 06:40:56 +00:00
|
|
|
det_text.innerHTML = 'Launching game..'
|
|
|
|
let proc;
|
|
|
|
try{
|
|
|
|
proc = pb.build()
|
|
|
|
det_text.innerHTML = 'Done. Enjoy the server!'
|
|
|
|
const tempListener = function(data){
|
|
|
|
if(data.indexOf('[Client thread/INFO]: -- System Details --') > -1){
|
|
|
|
details.style.display = 'none'
|
|
|
|
content.style.display = 'inline-flex'
|
|
|
|
proc.stdout.removeListener('data', tempListener)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
proc.stdout.on('data', tempListener)
|
2017-12-03 07:13:42 +00:00
|
|
|
// Init Discord Hook (Untested)
|
|
|
|
const distro = AssetGuard.retrieveDistributionDataSync(ConfigManager.getGameDirectory)
|
|
|
|
if(distro.discord != null && serv.discord != null){
|
|
|
|
DiscordWrapper.initRPC(distro.discord, serv.discord)
|
|
|
|
proc.on('close', (code, signal) => {
|
|
|
|
DiscordWrapper.shutdownRPC()
|
|
|
|
})
|
|
|
|
}
|
2017-11-30 06:40:56 +00:00
|
|
|
} catch(err) {
|
|
|
|
//det_text.innerHTML = 'Error: ' + err.message;
|
|
|
|
det_text.innerHTML = 'Error: See log for details..';
|
|
|
|
console.log(err)
|
|
|
|
setTimeout(function(){
|
|
|
|
details.style.display = 'none'
|
|
|
|
content.style.display = 'inline-flex'
|
|
|
|
}, 5000)
|
|
|
|
}
|
2017-11-30 08:00:06 +00:00
|
|
|
// Remove reference to tracker.
|
|
|
|
tracker = null
|
2017-11-30 06:40:56 +00:00
|
|
|
})
|
2017-11-30 08:00:06 +00:00
|
|
|
tracker.processDlQueues()
|
2017-11-30 06:40:56 +00:00
|
|
|
}
|