diff --git a/config.js b/config.js index e7dbd2d..efef949 100755 --- a/config.js +++ b/config.js @@ -39,6 +39,8 @@ module.exports = class config { // For possible values see: // https://expressjs.com/en/resources/middleware/cors.html#configuration-options 'corsOrigin': 'localhost', + // Change this to any string of your liking to make it harder for attackers to profile your cookies. + 'sessionSecret': 'nodejs-csgo-api', // The folder, where your srcds_run is located. 'csgoDir': '/home/csgo/csgo_ds', // Anything you want your server command line to have additional to: @@ -138,6 +140,9 @@ module.exports = class config { get corsOrigin() { return this._userOptions.corsOrigin; } + get sessionSecret() { + return this._userOptions.sessionSecret; + } script(type) { return this._userOptions[`${type}Script`]; diff --git a/example/js/gameserver.js b/example/js/gameserver.js index a43fcb5..4db9995 100755 --- a/example/js/gameserver.js +++ b/example/js/gameserver.js @@ -68,6 +68,11 @@ $( document ).ready(() => { } } else if (data.type == "updateProgress") { $('#popupText').html(`${data.payload.step}: ${data.payload.progress}%`); + if (data.payload.step == 'Update Successful!') { + window.setTimeout( () => { + $('.container-popup').css('display', 'none'); + }, 2000); + } } else if (data.type == "mapchange") { if (data.payload.success) { setupPage('mapchange'); diff --git a/serverControl.js b/serverControl.js index 91cfd84..ead685b 100755 --- a/serverControl.js +++ b/serverControl.js @@ -243,7 +243,7 @@ const limit = rateLimit({ }); app.use(limit); app.use(session({ - secret: 'nodejs-csgo-api', + secret: cfg.sessionSecret, name: `csgo-api-${cfg.host}`, cookie: { expires: cfg.loginValidity, @@ -356,11 +356,24 @@ app.get("/control", ensureAuthenticated, (req, res) => { let updateProcess = pty.spawn(cfg.updateCommand, cfg.updateArguments); updateProcess.on('data', (data) => { console.log(data); - if (data.indexOf('Update state (0x') != -1) { - let rex = /Update state \(0x\d+\) (.+), progress: (\d{1,2})\.\d{2}/; + if (data.indexOf('Checking for available updates') != -1) { + updateEmitter.emit('progress', 'Checking Steam client updates', 0); + } else if (data.indexOf('Verifying installation') != -1) { + updateEmitter.emit('progress', 'Verifying client installation', 0); + } else if (data.indexOf('Logging in user') != -1) { + updateEmitter.emit('progress', 'Logging in steam user', 0); + } else if (data.indexOf('Logged in OK') != -1) { + updateEmitter.emit('progress', 'Login OK', 100); + } else if(data.indexOf('Update state (0x') != -1) { + let rex = /Update state \(0x\d+\) (.+), progress: (\d{1,3})\.\d{2}/; let matches = rex.exec(data); updateEmitter.emit('progress', matches[1], matches[2]); + } else if (data.indexOf('Downloading update (') != -1) { + let rex = /\[(.+)] Downloading update/; + let matches = rex.exec(data); + updateEmitter.emit('progress', 'Updating Steam client', matches[1].slice(0, -1)); } else if (data.indexOf('Success!') != -1) { + updateEmitter.emit('progress', 'Update Successful!', 100); console.log('update succeeded'); updateSuccess = true; state.operationPending = false;