2017-11-02 00:41:20 +00:00
|
|
|
/* jslint node: true */
|
|
|
|
'use strict';
|
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
// enigma-bbs
|
2022-06-05 20:04:25 +00:00
|
|
|
const { MenuModule } = require('../core/menu_module.js');
|
|
|
|
const { resetScreen } = require('../core/ansi_term.js');
|
|
|
|
const { Errors } = require('./enig_error.js');
|
|
|
|
const { trackDoorRunBegin, trackDoorRunEnd } = require('./door_util.js');
|
2017-11-02 00:41:20 +00:00
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
// deps
|
2022-06-05 20:04:25 +00:00
|
|
|
const async = require('async');
|
|
|
|
const RLogin = require('rlogin');
|
2017-11-02 00:41:20 +00:00
|
|
|
|
|
|
|
exports.moduleInfo = {
|
2022-06-05 20:04:25 +00:00
|
|
|
name: 'CombatNet',
|
|
|
|
desc: 'CombatNet Access Module',
|
|
|
|
author: 'Dave Stephens',
|
2017-11-02 00:41:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.getModule = class CombatNetModule extends MenuModule {
|
2018-06-22 05:15:04 +00:00
|
|
|
constructor(options) {
|
|
|
|
super(options);
|
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
// establish defaults
|
2022-06-05 20:04:25 +00:00
|
|
|
this.config = options.menuConfig.config;
|
|
|
|
this.config.host = this.config.host || 'bbs.combatnet.us';
|
|
|
|
this.config.rloginPort = this.config.rloginPort || 4513;
|
2018-06-22 05:15:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
initSequence() {
|
|
|
|
const self = this;
|
|
|
|
|
|
|
|
async.series(
|
|
|
|
[
|
|
|
|
function validateConfig(callback) {
|
2018-12-03 02:33:07 +00:00
|
|
|
return self.validateConfigFields(
|
|
|
|
{
|
2022-06-05 20:04:25 +00:00
|
|
|
host: 'string',
|
|
|
|
password: 'string',
|
|
|
|
bbsTag: 'string',
|
|
|
|
rloginPort: 'number',
|
2018-12-03 02:33:07 +00:00
|
|
|
},
|
|
|
|
callback
|
|
|
|
);
|
2018-06-22 05:15:04 +00:00
|
|
|
},
|
|
|
|
function establishRloginConnection(callback) {
|
|
|
|
self.client.term.write(resetScreen());
|
|
|
|
self.client.term.write('Connecting to CombatNet, please wait...\n');
|
|
|
|
|
2019-01-19 05:09:10 +00:00
|
|
|
let doorTracking;
|
2019-01-07 01:01:03 +00:00
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
const restorePipeToNormal = function () {
|
|
|
|
if (self.client.term.output) {
|
|
|
|
self.client.term.output.removeListener(
|
|
|
|
'data',
|
|
|
|
sendToRloginBuffer
|
|
|
|
);
|
2019-01-07 01:01:03 +00:00
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
if (doorTracking) {
|
2019-01-19 05:09:10 +00:00
|
|
|
trackDoorRunEnd(doorTracking);
|
2019-01-07 01:01:03 +00:00
|
|
|
}
|
2018-06-22 05:15:04 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
const rlogin = new RLogin({
|
|
|
|
clientUsername: self.config.password,
|
|
|
|
serverUsername: `${self.config.bbsTag}${self.client.user.username}`,
|
|
|
|
host: self.config.host,
|
|
|
|
port: self.config.rloginPort,
|
|
|
|
terminalType: self.client.term.termClient,
|
|
|
|
terminalSpeed: 57600,
|
|
|
|
});
|
2018-06-22 05:15:04 +00:00
|
|
|
|
|
|
|
// If there was an error ...
|
|
|
|
rlogin.on('error', err => {
|
2022-06-05 20:04:25 +00:00
|
|
|
self.client.log.info(
|
|
|
|
`CombatNet rlogin client error: ${err.message}`
|
|
|
|
);
|
2018-06-22 05:15:04 +00:00
|
|
|
restorePipeToNormal();
|
|
|
|
return callback(err);
|
|
|
|
});
|
|
|
|
|
|
|
|
// If we've been disconnected ...
|
|
|
|
rlogin.on('disconnect', () => {
|
|
|
|
self.client.log.info('Disconnected from CombatNet');
|
|
|
|
restorePipeToNormal();
|
|
|
|
return callback(null);
|
|
|
|
});
|
|
|
|
|
|
|
|
function sendToRloginBuffer(buffer) {
|
|
|
|
rlogin.send(buffer);
|
|
|
|
}
|
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
rlogin.on(
|
|
|
|
'connect',
|
2018-06-23 03:26:46 +00:00
|
|
|
/* The 'connect' event handler will be supplied with one argument,
|
2017-11-02 00:41:20 +00:00
|
|
|
a boolean indicating whether or not the connection was established. */
|
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
function (state) {
|
|
|
|
if (state) {
|
2018-06-22 05:15:04 +00:00
|
|
|
self.client.log.info('Connected to CombatNet');
|
|
|
|
self.client.term.output.on('data', sendToRloginBuffer);
|
|
|
|
|
2019-01-19 05:09:10 +00:00
|
|
|
doorTracking = trackDoorRunBegin(self.client);
|
2018-06-22 05:15:04 +00:00
|
|
|
} else {
|
2022-06-05 20:04:25 +00:00
|
|
|
return callback(
|
|
|
|
Errors.General(
|
|
|
|
'Failed to establish establish CombatNet connection'
|
|
|
|
)
|
|
|
|
);
|
2018-06-22 05:15:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
// If data (a Buffer) has been received from the server ...
|
2022-06-05 20:04:25 +00:00
|
|
|
rlogin.on('data', data => {
|
2018-06-22 05:15:04 +00:00
|
|
|
self.client.term.rawWrite(data);
|
|
|
|
});
|
|
|
|
|
|
|
|
// connect...
|
|
|
|
rlogin.connect();
|
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
// note: no explicit callback() until we're finished!
|
2022-06-05 20:04:25 +00:00
|
|
|
},
|
2018-06-22 05:15:04 +00:00
|
|
|
],
|
|
|
|
err => {
|
2022-06-05 20:04:25 +00:00
|
|
|
if (err) {
|
|
|
|
self.client.log.warn({ error: err.message }, 'CombatNet error');
|
2018-06-22 05:15:04 +00:00
|
|
|
}
|
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
// if the client is still here, go to previous
|
2018-06-22 05:15:04 +00:00
|
|
|
self.prevMenu();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2017-11-02 00:41:20 +00:00
|
|
|
};
|