diff --git a/core/abracadabra.js b/core/abracadabra.js index 34374049..9ac4dec7 100644 --- a/core/abracadabra.js +++ b/core/abracadabra.js @@ -84,6 +84,22 @@ exports.getModule = class AbracadabraModule extends MenuModule { * Font support ala all other menus... or does this just work? */ + incrementActiveDoorNodeInstances() { + if(activeDoorNodeInstances[this.config.name]) { + activeDoorNodeInstances[this.config.name] += 1; + } else { + activeDoorNodeInstances[this.config.name] = 1; + } + this.activeDoorInstancesIncremented = true; + } + + decrementActiveDoorNodeInstances() { + if(true === this.activeDoorInstancesIncremented) { + activeDoorNodeInstances[this.config.name] -= 1; + this.activeDoorInstancesIncremented = false; + } + } + initSequence() { const self = this; @@ -116,14 +132,8 @@ exports.getModule = class AbracadabraModule extends MenuModule { }); } } else { - // :TODO: JS elegant way to do this? - if(activeDoorNodeInstances[self.config.name]) { - activeDoorNodeInstances[self.config.name] += 1; - } else { - activeDoorNodeInstances[self.config.name] = 1; - } - - callback(null); + self.incrementActiveDoorNodeInstances(); + return callback(null); } }, function prepareDoor(callback) { @@ -169,6 +179,13 @@ exports.getModule = class AbracadabraModule extends MenuModule { this.doorInstance.run(exeInfo, () => { trackDoorRunEnd(doorTracking); + this.decrementActiveDoorNodeInstances(); + + // client may have disconnected while process was active - + // we're done here if so. + if(!this.client.term.output) { + return; + } // // Try to clean up various settings such as scroll regions that may @@ -188,9 +205,7 @@ exports.getModule = class AbracadabraModule extends MenuModule { leave() { super.leave(); - if(!this.lastError) { - activeDoorNodeInstances[this.config.name] -= 1; - } + this.decrementActiveDoorNodeInstances(); } finishedLoading() { diff --git a/core/login_server_module.js b/core/login_server_module.js index 041f317c..a08abfe9 100644 --- a/core/login_server_module.js +++ b/core/login_server_module.js @@ -40,6 +40,10 @@ module.exports = class LoginServerModule extends ServerModule { } handleNewClient(client, clientSock, modInfo) { + clientSock.on('error', err => { + logger.log.warn({ modInfo, error : err.message }, 'Client socket error'); + }); + // // Start tracking the client. A session ID aka client ID // will be established in addNewClient() below. @@ -68,7 +72,7 @@ module.exports = class LoginServerModule extends ServerModule { }); client.on('error', err => { - logger.log.info({ clientId : client.session.id }, 'Connection error: %s' % err.message); + logger.log.info({ clientId : client.session.id, error : err.message }, 'Connection error'); }); client.on('close', err => {