2015-08-03 00:27:05 +00:00
|
|
|
/* jslint node: true */
|
|
|
|
'use strict';
|
|
|
|
|
2017-11-24 23:23:15 +00:00
|
|
|
const MenuModule = require('./menu_module.js').MenuModule;
|
|
|
|
const DropFile = require('./dropfile.js').DropFile;
|
|
|
|
const door = require('./door.js');
|
|
|
|
const theme = require('./theme.js');
|
|
|
|
const ansi = require('./ansi_term.js');
|
2017-01-26 05:18:05 +00:00
|
|
|
|
|
|
|
const async = require('async');
|
|
|
|
const assert = require('assert');
|
|
|
|
const paths = require('path');
|
|
|
|
const _ = require('lodash');
|
|
|
|
const mkdirs = require('fs-extra').mkdirs;
|
2015-08-03 00:27:05 +00:00
|
|
|
|
|
|
|
// :TODO: This should really be a system module... needs a little work to allow for such
|
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
const activeDoorNodeInstances = {};
|
2015-08-04 05:11:17 +00:00
|
|
|
|
2015-08-03 00:27:05 +00:00
|
|
|
exports.moduleInfo = {
|
2018-06-22 05:15:04 +00:00
|
|
|
name : 'Abracadabra',
|
|
|
|
desc : 'External BBS Door Module',
|
|
|
|
author : 'NuSkooler',
|
2015-08-03 00:27:05 +00:00
|
|
|
};
|
|
|
|
|
2015-08-04 05:11:17 +00:00
|
|
|
/*
|
|
|
|
Example configuration for LORD under DOSEMU:
|
|
|
|
|
2015-12-03 05:10:45 +00:00
|
|
|
{
|
|
|
|
config: {
|
|
|
|
name: PimpWars
|
|
|
|
dropFileType: DORINFO
|
|
|
|
cmd: qemu-system-i386
|
|
|
|
args: [
|
|
|
|
"-localtime",
|
|
|
|
"freedos.img",
|
|
|
|
"-chardev",
|
|
|
|
"socket,port={srvPort},nowait,host=localhost,id=s0",
|
|
|
|
"-device",
|
|
|
|
"isa-serial,chardev=s0"
|
|
|
|
]
|
|
|
|
io: socket
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
listen: socket | stdio
|
|
|
|
|
2015-08-04 05:11:17 +00:00
|
|
|
{
|
|
|
|
"config" : {
|
|
|
|
"name" : "LORD",
|
|
|
|
"dropFileType" : "DOOR",
|
|
|
|
"cmd" : "/usr/bin/dosemu",
|
|
|
|
"args" : [ "-quiet", "-f", "/etc/dosemu/dosemu.conf", "X:\\PW\\START.BAT {dropfile} {node}" ] ],
|
|
|
|
"nodeMax" : 32,
|
|
|
|
"tooManyArt" : "toomany-lord.ans"
|
|
|
|
}
|
|
|
|
}
|
2015-10-28 03:12:55 +00:00
|
|
|
|
|
|
|
:TODO: See Mystic & others for other arg options that we may need to support
|
2015-08-04 05:11:17 +00:00
|
|
|
*/
|
2015-08-03 00:27:05 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
exports.getModule = class AbracadabraModule extends MenuModule {
|
2018-06-22 05:15:04 +00:00
|
|
|
constructor(options) {
|
|
|
|
super(options);
|
2015-08-04 05:11:17 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
this.config = options.menuConfig.config;
|
|
|
|
// :TODO: MenuModule.validateConfig(cb) -- validate config section gracefully instead of asserts! -- { key : type, key2 : type2, ... }
|
|
|
|
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'));
|
2015-08-04 05:11:17 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
this.config.nodeMax = this.config.nodeMax || 0;
|
|
|
|
this.config.args = this.config.args || [];
|
|
|
|
}
|
2015-08-03 00:27:05 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
/*
|
2015-08-04 05:11:17 +00:00
|
|
|
:TODO:
|
|
|
|
* disconnecting wile door is open leaves dosemu
|
2015-08-05 04:35:59 +00:00
|
|
|
* http://bbslink.net/sysop.php support
|
|
|
|
* Font support ala all other menus... or does this just work?
|
2015-08-03 00:27:05 +00:00
|
|
|
*/
|
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
initSequence() {
|
|
|
|
const self = this;
|
2017-01-26 05:18:05 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
async.series(
|
|
|
|
[
|
|
|
|
function validateNodeCount(callback) {
|
|
|
|
if(self.config.nodeMax > 0 &&
|
2018-01-15 19:22:11 +00:00
|
|
|
_.isNumber(activeDoorNodeInstances[self.config.name]) &&
|
2015-08-04 05:11:17 +00:00
|
|
|
activeDoorNodeInstances[self.config.name] + 1 > self.config.nodeMax)
|
2018-06-22 05:15:04 +00:00
|
|
|
{
|
|
|
|
self.client.log.info(
|
|
|
|
{
|
|
|
|
name : self.config.name,
|
|
|
|
activeCount : activeDoorNodeInstances[self.config.name]
|
|
|
|
},
|
|
|
|
'Too many active instances');
|
|
|
|
|
|
|
|
if(_.isString(self.config.tooManyArt)) {
|
|
|
|
theme.displayThemeArt( { client : self.client, name : self.config.tooManyArt }, function displayed() {
|
|
|
|
self.pausePrompt( () => {
|
|
|
|
callback(new Error('Too many active instances'));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
self.client.term.write('\nToo many active instances. Try again later.\n');
|
|
|
|
|
|
|
|
// :TODO: Use MenuModule.pausePrompt()
|
|
|
|
self.pausePrompt( () => {
|
|
|
|
callback(new Error('Too many active instances'));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} 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);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
function generateDropfile(callback) {
|
|
|
|
self.dropFile = new DropFile(self.client, self.config.dropFileType);
|
|
|
|
var fullPath = self.dropFile.fullPath;
|
|
|
|
|
|
|
|
mkdirs(paths.dirname(fullPath), function dirCreated(err) {
|
|
|
|
if(err) {
|
|
|
|
callback(err);
|
|
|
|
} else {
|
|
|
|
self.dropFile.createFile(function created(err) {
|
|
|
|
callback(err);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
],
|
|
|
|
function complete(err) {
|
|
|
|
if(err) {
|
|
|
|
self.client.log.warn( { error : err.toString() }, 'Could not start door');
|
|
|
|
self.lastError = err;
|
|
|
|
self.prevMenu();
|
|
|
|
} else {
|
|
|
|
self.finishedLoading();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
runDoor() {
|
|
|
|
|
|
|
|
const exeInfo = {
|
|
|
|
cmd : this.config.cmd,
|
|
|
|
args : this.config.args,
|
|
|
|
io : this.config.io || 'stdio',
|
|
|
|
encoding : this.config.encoding || this.client.term.outputEncoding,
|
|
|
|
dropFile : this.dropFile.fileName,
|
|
|
|
node : this.client.node,
|
|
|
|
//inhSocket : this.client.output._handle.fd,
|
|
|
|
};
|
|
|
|
|
|
|
|
const doorInstance = new door.Door(this.client, exeInfo);
|
|
|
|
|
|
|
|
doorInstance.once('finished', () => {
|
|
|
|
//
|
|
|
|
// Try to clean up various settings such as scroll regions that may
|
|
|
|
// have been set within the door
|
|
|
|
//
|
|
|
|
this.client.term.rawWrite(
|
|
|
|
ansi.normal() +
|
2017-01-26 05:18:05 +00:00
|
|
|
ansi.goto(this.client.term.termHeight, this.client.term.termWidth) +
|
2016-06-21 03:38:43 +00:00
|
|
|
ansi.setScrollRegion() +
|
2017-01-26 05:18:05 +00:00
|
|
|
ansi.goto(this.client.term.termHeight, 0) +
|
2016-06-21 03:38:43 +00:00
|
|
|
'\r\n\r\n'
|
2018-06-22 05:15:04 +00:00
|
|
|
);
|
2016-06-21 03:38:43 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
this.prevMenu();
|
|
|
|
});
|
2015-08-04 05:11:17 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
this.client.term.write(ansi.resetScreen());
|
2015-08-04 05:11:17 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
doorInstance.run();
|
|
|
|
}
|
2015-08-03 00:27:05 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
leave() {
|
|
|
|
super.leave();
|
|
|
|
if(!this.lastError) {
|
|
|
|
activeDoorNodeInstances[this.config.name] -= 1;
|
|
|
|
}
|
|
|
|
}
|
2015-08-03 00:27:05 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
finishedLoading() {
|
|
|
|
this.runDoor();
|
|
|
|
}
|
2015-08-03 00:27:05 +00:00
|
|
|
};
|