From 5c978e05bf468ffa7b10deb78ef113a5ac570af7 Mon Sep 17 00:00:00 2001 From: Bryan Ashby Date: Sun, 9 Jun 2019 13:41:11 -0600 Subject: [PATCH] Ability to override idle time and/or temporary disable from MRC --- core/client.js | 21 ++++++++++++++++++++- core/mrc.js | 16 ++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/core/client.js b/core/client.js index d340981b..76d56529 100644 --- a/core/client.js +++ b/core/client.js @@ -439,6 +439,11 @@ Client.prototype.setTermType = function(termType) { }; Client.prototype.startIdleMonitor = function() { + // clear existing, if any + if(this.idleCheck) { + this.stopIdleMonitor(); + } + this.lastKeyPressMs = Date.now(); // @@ -474,6 +479,9 @@ Client.prototype.startIdleMonitor = function() { idleLogoutSeconds = Config().users.preAuthIdleLogoutSeconds; } + // use override value if set + idleLogoutSeconds = this.idleLogoutSecondsOverride || idleLogoutSeconds; + if(nowMs - this.lastKeyPressMs >= (idleLogoutSeconds * 1000)) { this.emit('idle timeout'); } @@ -481,7 +489,18 @@ Client.prototype.startIdleMonitor = function() { }; Client.prototype.stopIdleMonitor = function() { - clearInterval(this.idleCheck); + if(this.idleCheck) { + clearInterval(this.idleCheck); + delete this.idleCheck; + } +}; + +Client.prototype.overrideIdleLogoutSeconds = function(seconds) { + this.idleLogoutSecondsOverride = seconds; +}; + +Client.prototype.restoreIdleLogoutSeconds = function() { + delete this.idleLogoutSecondsOverride; }; Client.prototype.end = function () { diff --git a/core/mrc.js b/core/mrc.js index 6987be32..96637dfa 100644 --- a/core/mrc.js +++ b/core/mrc.js @@ -158,6 +158,16 @@ exports.getModule = class mrcModule extends MenuModule { this.sendHeartbeat(); this.sendServerMessage('STATS'); }, 60000); + + // override idle logout seconds if configured + const idleLogoutSeconds = parseInt(this.config.idleLogoutSeconds); + if(0 === idleLogoutSeconds) { + this.log.debug('Temporary disable idle monitor due to config'); + this.client.stopIdleMonitor(); + } else if (!isNaN(idleLogoutSeconds) && idleLogoutSeconds >= 60) { + this.log.debug( { idleLogoutSeconds }, 'Temporary override idle logout seconds due to config'); + this.client.overrideIdleLogoutSeconds(idleLogoutSeconds); + } }); // when we get data, process it @@ -187,6 +197,12 @@ exports.getModule = class mrcModule extends MenuModule { leave() { this.quitServer(); + + // restore idle monitor to previous state + this.log.debug('Restoring idle monitor to previous state'); + this.client.restoreIdleLogoutSeconds(); + this.client.startIdleMonitor(); + return super.leave(); }