dropFileType is now optional when using abracadabra

* Can be left out or set to 'none'
* Allows doors that do not use a drop file
* Additionally: Clean up drop file upon door exit if one is used
This commit is contained in:
Bryan Ashby
2020-12-14 12:02:25 -07:00
parent 12ca811476
commit f202600571
3 changed files with 26 additions and 15 deletions

View File

@@ -11,12 +11,14 @@ const {
trackDoorRunBegin,
trackDoorRunEnd
} = require('./door_util.js');
const Log = require('./logger').log;
// deps
const async = require('async');
const assert = require('assert');
const _ = require('lodash');
const paths = require('path');
const fs = require('graceful-fs');
const activeDoorNodeInstances = {};
@@ -70,20 +72,12 @@ exports.getModule = class AbracadabraModule extends MenuModule {
// :TODO: MenuModule.validateConfig(cb) -- validate config section gracefully instead of asserts! -- { key : type, key2 : type2, ... }
// .. and/or EnigAssert
assert(_.isString(this.config.name, 'Config \'name\' is required'));
assert(_.isString(this.config.dropFileType, 'Config \'dropFileType\' is required'));
assert(_.isString(this.config.cmd, 'Config \'cmd\' is required'));
this.config.nodeMax = this.config.nodeMax || 0;
this.config.args = this.config.args || [];
}
/*
:TODO:
* disconnecting while door is open leaves dosemu
* http://bbslink.net/sysop.php support
* Font support ala all other menus... or does this just work?
*/
incrementActiveDoorNodeInstances() {
if(activeDoorNodeInstances[this.config.name]) {
activeDoorNodeInstances[this.config.name] += 1;
@@ -141,11 +135,15 @@ exports.getModule = class AbracadabraModule extends MenuModule {
return self.doorInstance.prepare(self.config.io || 'stdio', callback);
},
function generateDropfile(callback) {
const dropFileOpts = {
fileType : self.config.dropFileType,
};
if (!self.config.dropFileType || self.config.dropFileType.toLowerCase() === 'none') {
return callback(null);
}
self.dropFile = new DropFile(
self.client,
{ fileType : self.config.dropFileType }
);
self.dropFile = new DropFile(self.client, dropFileOpts);
return self.dropFile.createFile(callback);
}
],
@@ -170,18 +168,30 @@ exports.getModule = class AbracadabraModule extends MenuModule {
args : this.config.args,
io : this.config.io || 'stdio',
encoding : this.config.encoding || 'cp437',
dropFile : this.dropFile.fileName,
dropFilePath : this.dropFile.fullPath,
node : this.client.node,
env : this.config.env,
};
if (this.dropFile) {
exeInfo.dropFile = this.dropFile.fileName;
exeInfo.dropFilePath = this.dropFile.fullPath;
}
const doorTracking = trackDoorRunBegin(this.client, this.config.name);
this.doorInstance.run(exeInfo, () => {
trackDoorRunEnd(doorTracking);
this.decrementActiveDoorNodeInstances();
// Clean up dropfile, if any
if (exeInfo.dropFilePath) {
fs.unlink(exeInfo.dropFilePath, err => {
if (err) {
Log.warn({ error : err, path : exeInfo.dropFilePath }, 'Failed to remove drop file.');
}
});
}
// client may have disconnected while process was active -
// we're done here if so.
if(!this.client.term.output) {