First pass formatting with Prettier

* Added .prettierrc.json
* Added .prettierignore
* Formatted
This commit is contained in:
Bryan Ashby
2022-06-05 14:04:25 -06:00
parent eecfb33ad5
commit 4881c2123a
172 changed files with 23696 additions and 18029 deletions

View File

@@ -1,21 +1,18 @@
/* jslint node: true */
'use strict';
const { MenuModule } = require('./menu_module.js');
const { resetScreen } = require('./ansi_term.js');
const { Errors } = require('./enig_error.js');
const {
trackDoorRunBegin,
trackDoorRunEnd
} = require('./door_util.js');
const { MenuModule } = require('./menu_module.js');
const { resetScreen } = require('./ansi_term.js');
const { Errors } = require('./enig_error.js');
const { trackDoorRunBegin, trackDoorRunEnd } = require('./door_util.js');
// deps
const async = require('async');
const http = require('http');
const net = require('net');
const crypto = require('crypto');
const async = require('async');
const http = require('http');
const net = require('net');
const crypto = require('crypto');
const packageJson = require('../package.json');
const packageJson = require('../package.json');
/*
Expected configuration block:
@@ -42,18 +39,18 @@ const packageJson = require('../package.json');
// :TODO: ENH: Support nodeMax and tooManyArt
exports.moduleInfo = {
name : 'BBSLink',
desc : 'BBSLink Access Module',
author : 'NuSkooler',
name: 'BBSLink',
desc: 'BBSLink Access Module',
author: 'NuSkooler',
};
exports.getModule = class BBSLinkModule extends MenuModule {
constructor(options) {
super(options);
this.config = options.menuConfig.config;
this.config.host = this.config.host || 'games.bbslink.net';
this.config.port = this.config.port || 23;
this.config = options.menuConfig.config;
this.config.host = this.config.host || 'games.bbslink.net';
this.config.port = this.config.port || 23;
}
initSequence() {
@@ -67,12 +64,12 @@ exports.getModule = class BBSLinkModule extends MenuModule {
function validateConfig(callback) {
return self.validateConfigFields(
{
host : 'string',
sysCode : 'string',
authCode : 'string',
schemeCode : 'string',
door : 'string',
port : 'number',
host: 'string',
sysCode: 'string',
authCode: 'string',
schemeCode: 'string',
door: 'string',
port: 'number',
},
callback
);
@@ -82,19 +79,26 @@ exports.getModule = class BBSLinkModule extends MenuModule {
// Acquire an authentication token
//
crypto.randomBytes(16, function rand(ex, buf) {
if(ex) {
if (ex) {
callback(ex);
} else {
randomKey = buf.toString('base64').substr(0, 6);
self.simpleHttpRequest('/token.php?key=' + randomKey, null, function resp(err, body) {
if(err) {
callback(err);
} else {
token = body.trim();
self.client.log.trace( { token : token }, 'BBSLink token');
callback(null);
self.simpleHttpRequest(
'/token.php?key=' + randomKey,
null,
function resp(err, body) {
if (err) {
callback(err);
} else {
token = body.trim();
self.client.log.trace(
{ token: token },
'BBSLink token'
);
callback(null);
}
}
});
);
}
});
},
@@ -103,26 +107,40 @@ exports.getModule = class BBSLinkModule extends MenuModule {
// Authenticate the token we acquired previously
//
const headers = {
'X-User' : self.client.user.userId.toString(),
'X-System' : self.config.sysCode,
'X-Auth' : crypto.createHash('md5').update(self.config.authCode + token).digest('hex'),
'X-Code' : crypto.createHash('md5').update(self.config.schemeCode + token).digest('hex'),
'X-Rows' : self.client.term.termHeight.toString(),
'X-Key' : randomKey,
'X-Door' : self.config.door,
'X-Token' : token,
'X-Type' : 'enigma-bbs',
'X-Version' : packageJson.version,
'X-User': self.client.user.userId.toString(),
'X-System': self.config.sysCode,
'X-Auth': crypto
.createHash('md5')
.update(self.config.authCode + token)
.digest('hex'),
'X-Code': crypto
.createHash('md5')
.update(self.config.schemeCode + token)
.digest('hex'),
'X-Rows': self.client.term.termHeight.toString(),
'X-Key': randomKey,
'X-Door': self.config.door,
'X-Token': token,
'X-Type': 'enigma-bbs',
'X-Version': packageJson.version,
};
self.simpleHttpRequest('/auth.php?key=' + randomKey, headers, function resp(err, body) {
var status = body.trim();
self.simpleHttpRequest(
'/auth.php?key=' + randomKey,
headers,
function resp(err, body) {
var status = body.trim();
if('complete' === status) {
return callback(null);
if ('complete' === status) {
return callback(null);
}
return callback(
Errors.AccessDenied(
`Bad authentication status: ${status}`
)
);
}
return callback(Errors.AccessDenied(`Bad authentication status: ${status}`));
});
);
},
function createTelnetBridge(callback) {
//
@@ -130,35 +148,48 @@ exports.getModule = class BBSLinkModule extends MenuModule {
// bridge from us to them
//
const connectOpts = {
port : self.config.port,
host : self.config.host,
port: self.config.port,
host: self.config.host,
};
let dataOut;
self.client.term.write(resetScreen());
self.client.term.write(` Connecting to ${self.config.host}, please wait...\n`);
self.client.term.write(
` Connecting to ${self.config.host}, please wait...\n`
);
const doorTracking = trackDoorRunBegin(self.client, `bbslink_${self.config.door}`);
const doorTracking = trackDoorRunBegin(
self.client,
`bbslink_${self.config.door}`
);
const bridgeConnection = net.createConnection(connectOpts, function connected() {
self.client.log.info(connectOpts, 'BBSLink bridge connection established');
const bridgeConnection = net.createConnection(
connectOpts,
function connected() {
self.client.log.info(
connectOpts,
'BBSLink bridge connection established'
);
dataOut = (data) => {
return bridgeConnection.write(data);
};
dataOut = data => {
return bridgeConnection.write(data);
};
self.client.term.output.on('data', dataOut);
self.client.term.output.on('data', dataOut);
self.client.once('end', function clientEnd() {
self.client.log.info('Connection ended. Terminating BBSLink connection');
clientTerminated = true;
bridgeConnection.end();
});
});
self.client.once('end', function clientEnd() {
self.client.log.info(
'Connection ended. Terminating BBSLink connection'
);
clientTerminated = true;
bridgeConnection.end();
});
}
);
const restore = () => {
if(dataOut && self.client.term.output) {
if (dataOut && self.client.term.output) {
self.client.term.output.removeListener('data', dataOut);
dataOut = null;
}
@@ -174,22 +205,31 @@ exports.getModule = class BBSLinkModule extends MenuModule {
bridgeConnection.on('end', function connectionEnd() {
restore();
return callback(clientTerminated ? Errors.General('Client connection terminated') : null);
return callback(
clientTerminated
? Errors.General('Client connection terminated')
: null
);
});
bridgeConnection.on('error', function error(err) {
self.client.log.info('BBSLink bridge connection error: ' + err.message);
self.client.log.info(
'BBSLink bridge connection error: ' + err.message
);
restore();
return callback(err);
});
}
},
],
function complete(err) {
if(err) {
self.client.log.warn( { error : err.toString() }, 'BBSLink connection error');
if (err) {
self.client.log.warn(
{ error: err.toString() },
'BBSLink connection error'
);
}
if(!clientTerminated) {
if (!clientTerminated) {
self.prevMenu();
}
}
@@ -198,9 +238,9 @@ exports.getModule = class BBSLinkModule extends MenuModule {
simpleHttpRequest(path, headers, cb) {
const getOpts = {
host : this.config.host,
path : path,
headers : headers,
host: this.config.host,
path: path,
headers: headers,
};
const req = http.get(getOpts, function response(resp) {