2015-08-03 00:27:05 +00:00
|
|
|
/* jslint node: true */
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var MenuModule = require('../core/menu_module.js').MenuModule;
|
|
|
|
var DropFile = require('../core/dropfile.js').DropFile;
|
|
|
|
var door = require('../core/door.js');
|
2015-08-04 05:11:17 +00:00
|
|
|
var theme = require('../core/theme.js');
|
|
|
|
var ansi = require('../core/ansi_term.js');
|
2015-08-03 00:27:05 +00:00
|
|
|
|
|
|
|
var async = require('async');
|
|
|
|
var assert = require('assert');
|
|
|
|
var mkdirp = require('mkdirp');
|
|
|
|
var paths = require('path');
|
2015-08-04 05:11:17 +00:00
|
|
|
var _ = require('lodash');
|
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;
|
|
|
|
|
2015-08-04 05:11:17 +00:00
|
|
|
var activeDoorNodeInstances = {};
|
|
|
|
|
2015-08-05 04:35:59 +00:00
|
|
|
var doorInstances = {}; // name -> { count : <instCount>, { <nodeNum> : <inst> } }
|
|
|
|
|
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:
|
|
|
|
|
|
|
|
{
|
|
|
|
"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-08-03 00:27:05 +00:00
|
|
|
function AbracadabraModule(options) {
|
|
|
|
MenuModule.call(this, options);
|
|
|
|
|
|
|
|
var self = this;
|
|
|
|
|
2015-08-04 05:11:17 +00:00
|
|
|
this.config = options.menuConfig.config;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
mkdirp(paths.dirname(fullPath), function dirCreated(err) {
|
|
|
|
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-08-04 05:21:23 +00:00
|
|
|
self.lastError = err;
|
2015-08-04 05:11:17 +00:00
|
|
|
self.fallbackModule();
|
|
|
|
} else {
|
|
|
|
self.finishedLoading();
|
|
|
|
}
|
2015-08-03 00:27:05 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2015-08-04 05:11:17 +00:00
|
|
|
this.runDosEmuDoor = function() {
|
2015-08-03 00:27:05 +00:00
|
|
|
|
|
|
|
};
|
2015-08-04 05:11:17 +00:00
|
|
|
|
|
|
|
this.runDoor = function() {
|
|
|
|
|
|
|
|
var exeInfo = {
|
|
|
|
cmd : this.config.cmd,
|
|
|
|
args : this.config.args,
|
|
|
|
};
|
|
|
|
|
|
|
|
// :TODO: this system should probably be generic
|
|
|
|
for(var i = 0; i < exeInfo.args.length; ++i) {
|
|
|
|
exeInfo.args[i] = exeInfo.args[i].replace(/\{dropfile\}/g, self.dropFile.fileName);
|
|
|
|
exeInfo.args[i] = exeInfo.args[i].replace(/\{node\}/g, self.client.node.toString());
|
|
|
|
}
|
|
|
|
|
|
|
|
var doorInstance = new door.Door(this.client, exeInfo);
|
|
|
|
|
|
|
|
doorInstance.on('finished', function doorFinished() {
|
|
|
|
self.fallbackModule();
|
|
|
|
});
|
|
|
|
|
|
|
|
self.client.term.write(ansi.resetScreen());
|
|
|
|
|
|
|
|
doorInstance.run();
|
2015-08-26 05:17:09 +00:00
|
|
|
};
|
2015-08-04 05:11:17 +00:00
|
|
|
|
|
|
|
this.fallbackModule = function() {
|
|
|
|
self.client.gotoMenuModule( { name : self.menuConfig.fallback } );
|
2015-08-26 05:17:09 +00:00
|
|
|
};
|
2015-08-03 00:27:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
require('util').inherits(AbracadabraModule, MenuModule);
|
|
|
|
|
|
|
|
AbracadabraModule.prototype.enter = function(client) {
|
|
|
|
AbracadabraModule.super_.prototype.enter.call(this, client);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
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
|
|
|
};
|