2015-08-03 00:27:05 +00:00
|
|
|
/* jslint node: true */
|
|
|
|
'use strict';
|
|
|
|
|
2016-03-29 04:07:21 +00:00
|
|
|
let MenuModule = require('../core/menu_module.js').MenuModule;
|
|
|
|
let DropFile = require('../core/dropfile.js').DropFile;
|
|
|
|
let door = require('../core/door.js');
|
|
|
|
let theme = require('../core/theme.js');
|
|
|
|
let ansi = require('../core/ansi_term.js');
|
|
|
|
|
|
|
|
let async = require('async');
|
|
|
|
let assert = require('assert');
|
|
|
|
let paths = require('path');
|
|
|
|
let _ = require('lodash');
|
|
|
|
let net = require('net');
|
|
|
|
let 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
|
|
|
|
|
|
|
|
exports.getModule = AbracadabraModule;
|
|
|
|
|
2016-03-29 04:07:21 +00:00
|
|
|
let activeDoorNodeInstances = {};
|
2015-08-04 05:11:17 +00:00
|
|
|
|
2016-03-29 04:07:21 +00:00
|
|
|
let doorInstances = {}; // name -> { count : <instCount>, { <nodeNum> : <inst> } }
|
2015-08-05 04:35:59 +00:00
|
|
|
|
2015-08-03 00:27:05 +00:00
|
|
|
exports.moduleInfo = {
|
|
|
|
name : 'Abracadabra',
|
|
|
|
desc : 'External BBS Door Module',
|
|
|
|
author : 'NuSkooler',
|
|
|
|
};
|
|
|
|
|
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
|
|
|
function AbracadabraModule(options) {
|
|
|
|
MenuModule.call(this, options);
|
|
|
|
|
2016-03-29 04:07:21 +00:00
|
|
|
let self = this;
|
2015-08-03 00:27:05 +00:00
|
|
|
|
2015-08-04 05:11:17 +00:00
|
|
|
this.config = options.menuConfig.config;
|
|
|
|
|
2015-12-08 04:44:42 +00:00
|
|
|
// :TODO: MenuModule.validateConfig(cb) -- validate config section gracefully instead of asserts!
|
2015-08-04 05:11:17 +00:00
|
|
|
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 || [];
|
2015-08-03 00:27:05 +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
|
|
|
*/
|
|
|
|
|
|
|
|
this.initSequence = function() {
|
|
|
|
async.series(
|
|
|
|
[
|
|
|
|
function validateNodeCount(callback) {
|
2015-08-04 05:11:17 +00:00
|
|
|
if(self.config.nodeMax > 0 &&
|
|
|
|
_.isNumber(activeDoorNodeInstances[self.config.name]) &&
|
|
|
|
activeDoorNodeInstances[self.config.name] + 1 > self.config.nodeMax)
|
|
|
|
{
|
|
|
|
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() {
|
2015-08-04 05:21:23 +00:00
|
|
|
theme.displayThemedPause( { client : self.client }, function keyPressed() {
|
|
|
|
callback(new Error('Too many active instances'));
|
|
|
|
});
|
2015-08-04 05:11:17 +00:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
self.client.term.write('\nToo many active instances. Try again later.\n');
|
|
|
|
|
2015-08-04 05:21:23 +00:00
|
|
|
theme.displayThemedPause( { client : self.client }, function keyPressed() {
|
2015-08-04 05:11:17 +00:00
|
|
|
callback(new Error('Too many active instances'));
|
2015-08-04 05:21:23 +00:00
|
|
|
});
|
|
|
|
}
|
2015-08-04 05:11:17 +00:00
|
|
|
} 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);
|
|
|
|
}
|
2015-08-03 00:27:05 +00:00
|
|
|
},
|
|
|
|
function generateDropfile(callback) {
|
|
|
|
self.dropFile = new DropFile(self.client, self.config.dropFileType);
|
|
|
|
var fullPath = self.dropFile.fullPath;
|
|
|
|
|
2016-03-29 04:07:21 +00:00
|
|
|
mkdirs(paths.dirname(fullPath), function dirCreated(err) {
|
2015-08-03 00:27:05 +00:00
|
|
|
if(err) {
|
|
|
|
callback(err);
|
|
|
|
} else {
|
|
|
|
self.dropFile.createFile(function created(err) {
|
|
|
|
callback(err);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
],
|
|
|
|
function complete(err) {
|
2015-08-04 05:11:17 +00:00
|
|
|
if(err) {
|
2015-12-08 04:44:42 +00:00
|
|
|
self.client.log.warn( { error : err.toString() }, 'Could not start door');
|
2015-08-04 05:21:23 +00:00
|
|
|
self.lastError = err;
|
2015-11-04 06:25:35 +00:00
|
|
|
self.prevMenu();
|
2015-08-04 05:11:17 +00:00
|
|
|
} else {
|
|
|
|
self.finishedLoading();
|
|
|
|
}
|
2015-08-03 00:27:05 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2015-08-04 05:11:17 +00:00
|
|
|
this.runDoor = function() {
|
|
|
|
|
2016-03-29 04:07:21 +00:00
|
|
|
const exeInfo = {
|
2015-12-03 05:10:45 +00:00
|
|
|
cmd : self.config.cmd,
|
|
|
|
args : self.config.args,
|
|
|
|
io : self.config.io || 'stdio',
|
|
|
|
encoding : self.config.encoding || self.client.term.outputEncoding,
|
|
|
|
dropFile : self.dropFile.fileName,
|
|
|
|
node : self.client.node,
|
2015-12-08 04:44:42 +00:00
|
|
|
//inhSocket : self.client.output._handle.fd,
|
2015-08-04 05:11:17 +00:00
|
|
|
};
|
|
|
|
|
2016-03-29 04:07:21 +00:00
|
|
|
const doorInstance = new door.Door(self.client, exeInfo);
|
2015-08-04 05:11:17 +00:00
|
|
|
|
2016-03-29 04:07:21 +00:00
|
|
|
doorInstance.on('finished', () => {
|
2015-11-04 06:25:35 +00:00
|
|
|
self.prevMenu();
|
2015-08-04 05:11:17 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
self.client.term.write(ansi.resetScreen());
|
|
|
|
|
|
|
|
doorInstance.run();
|
2015-08-26 05:17:09 +00:00
|
|
|
};
|
2015-08-03 00:27:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
require('util').inherits(AbracadabraModule, MenuModule);
|
|
|
|
|
|
|
|
AbracadabraModule.prototype.leave = function() {
|
2015-08-04 05:11:17 +00:00
|
|
|
AbracadabraModule.super_.prototype.leave.call(this);
|
2015-08-03 00:27:05 +00:00
|
|
|
|
2015-08-04 05:21:23 +00:00
|
|
|
if(!this.lastError) {
|
|
|
|
activeDoorNodeInstances[this.config.name] -= 1;
|
|
|
|
}
|
2015-08-03 00:27:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
AbracadabraModule.prototype.finishedLoading = function() {
|
2015-08-04 05:11:17 +00:00
|
|
|
this.runDoor();
|
2015-08-03 00:27:05 +00:00
|
|
|
};
|