Skip to content

Commit

Permalink
Merge pull request #15 from Taraman17/fixUpdate
Browse files Browse the repository at this point in the history
Fix update
  • Loading branch information
Taraman17 authored Oct 27, 2020
2 parents 43b005d + 8b1a271 commit 06e390d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
5 changes: 5 additions & 0 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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`];
Expand Down
5 changes: 5 additions & 0 deletions example/js/gameserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
19 changes: 16 additions & 3 deletions serverControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 06e390d

Please sign in to comment.