mirror of
https://github.com/NuSkooler/enigma-bbs.git
synced 2025-08-19 16:04:21 +02:00
more MRC bug squashing and tidy up
This commit is contained in:
parent
9f4f1fca13
commit
109b157c02
2 changed files with 88 additions and 51 deletions
72
core/mrc.js
72
core/mrc.js
|
@ -5,7 +5,8 @@
|
||||||
const Log = require('./logger.js').log;
|
const Log = require('./logger.js').log;
|
||||||
const { MenuModule } = require('./menu_module.js');
|
const { MenuModule } = require('./menu_module.js');
|
||||||
const {
|
const {
|
||||||
pipeToAnsi
|
pipeToAnsi,
|
||||||
|
stripMciColorCodes
|
||||||
} = require('./color_codes.js');
|
} = require('./color_codes.js');
|
||||||
const stringFormat = require('./string_format.js');
|
const stringFormat = require('./string_format.js');
|
||||||
const StringUtil = require('./string_util.js');
|
const StringUtil = require('./string_util.js');
|
||||||
|
@ -107,6 +108,12 @@ exports.getModule = class mrcModule extends MenuModule {
|
||||||
this.viewControllers.mrcChat.switchFocus(MciViewIds.mrcChat.inputArea);
|
this.viewControllers.mrcChat.switchFocus(MciViewIds.mrcChat.inputArea);
|
||||||
|
|
||||||
return cb(null);
|
return cb(null);
|
||||||
|
},
|
||||||
|
|
||||||
|
quit : (formData, extraArgs, cb) => {
|
||||||
|
this.sendServerMessage('LOGOFF');
|
||||||
|
this.state.socket.destroy();
|
||||||
|
return this.prevMenu(cb);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -167,11 +174,22 @@ exports.getModule = class mrcModule extends MenuModule {
|
||||||
*/
|
*/
|
||||||
addMessageToChatLog(message) {
|
addMessageToChatLog(message) {
|
||||||
const chatLogView = this.viewControllers.mrcChat.getView(MciViewIds.mrcChat.chatLog);
|
const chatLogView = this.viewControllers.mrcChat.getView(MciViewIds.mrcChat.chatLog);
|
||||||
chatLogView.addText(pipeToAnsi(message));
|
const messageLength = stripMciColorCodes(message).length;
|
||||||
|
const chatWidth = chatLogView.dimens.width;
|
||||||
|
let padAmount = 0;
|
||||||
|
|
||||||
|
if (messageLength > chatWidth) {
|
||||||
|
padAmount = chatWidth - (messageLength % chatWidth);
|
||||||
|
} else {
|
||||||
|
padAmount = chatWidth - messageLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
const padding = ' |00' + ' '.repeat(padAmount - 2);
|
||||||
|
chatLogView.addText(pipeToAnsi(message + padding));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Processes data received back from the MRC multiplexer
|
* Processes data received from the MRC multiplexer
|
||||||
*/
|
*/
|
||||||
processReceivedMessage(blob) {
|
processReceivedMessage(blob) {
|
||||||
blob.split('\n').forEach( message => {
|
blob.split('\n').forEach( message => {
|
||||||
|
@ -200,13 +218,13 @@ exports.getModule = class mrcModule extends MenuModule {
|
||||||
this.state.nicks = params[1].split(',');
|
this.state.nicks = params[1].split(',');
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'STATS':
|
case 'STATS': {
|
||||||
const stats = params[1].split(' ');
|
const stats = params[1].split(' ');
|
||||||
this.viewControllers.mrcChat.getView(MciViewIds.mrcChat.mrcUsers).setText(stats[2]);
|
this.viewControllers.mrcChat.getView(MciViewIds.mrcChat.mrcUsers).setText(stats[2]);
|
||||||
this.viewControllers.mrcChat.getView(MciViewIds.mrcChat.mrcBbses).setText(stats[0]);
|
this.viewControllers.mrcChat.getView(MciViewIds.mrcChat.mrcBbses).setText(stats[0]);
|
||||||
this.state.last_ping = stats[1];
|
this.state.last_ping = stats[1];
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
this.addMessageToChatLog(message.body);
|
this.addMessageToChatLog(message.body);
|
||||||
|
@ -214,22 +232,12 @@ exports.getModule = class mrcModule extends MenuModule {
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (message.from_user == this.state.alias && message.to_user == 'NOTME') {
|
if (message.to_room == this.state.room) {
|
||||||
// don't deliver NOTME messages
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
// if we're here then we want to show it to the user
|
// if we're here then we want to show it to the user
|
||||||
const currentTime = moment().format(this.client.currentTheme.helpers.getTimeFormat());
|
const currentTime = moment().format(this.client.currentTheme.helpers.getTimeFormat());
|
||||||
|
|
||||||
if (message.to_user == this.state.alias) {
|
|
||||||
// it's a pm
|
|
||||||
this.addMessageToChatLog('|08' + currentTime + ' |14PM|00 ' + message.body + '|00');
|
|
||||||
} else {
|
|
||||||
// it's not a pm
|
|
||||||
this.addMessageToChatLog('|08' + currentTime + '|00 ' + message.body + '|00');
|
this.addMessageToChatLog('|08' + currentTime + '|00 ' + message.body + '|00');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
this.viewControllers.mrcChat.switchFocus(MciViewIds.mrcChat.inputArea);
|
this.viewControllers.mrcChat.switchFocus(MciViewIds.mrcChat.inputArea);
|
||||||
});
|
});
|
||||||
|
@ -240,18 +248,18 @@ exports.getModule = class mrcModule extends MenuModule {
|
||||||
*/
|
*/
|
||||||
processOutgoingMessage(message, to_user) {
|
processOutgoingMessage(message, to_user) {
|
||||||
if (message.startsWith('/')) {
|
if (message.startsWith('/')) {
|
||||||
|
|
||||||
this.processSlashCommand(message);
|
this.processSlashCommand(message);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (message == '') {
|
if (message == '') {
|
||||||
|
// don't do anything if message is blank, just update stats
|
||||||
this.sendServerMessage('STATS');
|
this.sendServerMessage('STATS');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// just format and send
|
// else just format and send
|
||||||
const textFormatObj = {
|
const textFormatObj = {
|
||||||
fromUserName : this.state.alias,
|
fromUserName : this.state.alias,
|
||||||
|
toUserName : to_user,
|
||||||
message : message
|
message : message
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -259,8 +267,20 @@ exports.getModule = class mrcModule extends MenuModule {
|
||||||
this.config.messageFormat ||
|
this.config.messageFormat ||
|
||||||
'|00|10<|02{fromUserName}|10>|00 |03{message}|00';
|
'|00|10<|02{fromUserName}|10>|00 |03{message}|00';
|
||||||
|
|
||||||
|
const privateMessageFormat =
|
||||||
|
this.config.outgoingPrivateMessageFormat ||
|
||||||
|
'|00|10<|02{fromUserName}|10|14->|02{toUserName}>|00 |03{message}|00';
|
||||||
|
|
||||||
|
let formattedMessage = '';
|
||||||
|
if (to_user == undefined) {
|
||||||
|
// normal message
|
||||||
|
formattedMessage = stringFormat(messageFormat, textFormatObj);
|
||||||
|
} else {
|
||||||
|
// pm
|
||||||
|
formattedMessage = stringFormat(privateMessageFormat, textFormatObj);
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const formattedMessage = stringFormat(messageFormat, textFormatObj);
|
|
||||||
this.sendMessageToMultiplexer(to_user || '', '', this.state.room, formattedMessage);
|
this.sendMessageToMultiplexer(to_user || '', '', this.state.room, formattedMessage);
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
this.client.log.warn( { error : e.message }, 'MRC error');
|
this.client.log.warn( { error : e.message }, 'MRC error');
|
||||||
|
@ -283,7 +303,7 @@ exports.getModule = class mrcModule extends MenuModule {
|
||||||
case 'pm':
|
case 'pm':
|
||||||
this.processOutgoingMessage(cmd[2], cmd[1]);
|
this.processOutgoingMessage(cmd[2], cmd[1]);
|
||||||
break;
|
break;
|
||||||
case 'rainbow':
|
case 'rainbow': {
|
||||||
// this is brutal, but i love it
|
// this is brutal, but i love it
|
||||||
const line = message.replace(/^\/rainbow\s/, '').split(' ').reduce(function (a, c) {
|
const line = message.replace(/^\/rainbow\s/, '').split(' ').reduce(function (a, c) {
|
||||||
const cc = Math.floor((Math.random() * 31) + 1).toString().padStart(2, '0');
|
const cc = Math.floor((Math.random() * 31) + 1).toString().padStart(2, '0');
|
||||||
|
@ -293,17 +313,17 @@ exports.getModule = class mrcModule extends MenuModule {
|
||||||
|
|
||||||
this.processOutgoingMessage(line);
|
this.processOutgoingMessage(line);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case 'l33t':
|
case 'l33t':
|
||||||
this.processOutgoingMessage(StringUtil.stylizeString(message.substr(5), 'l33t'));
|
this.processOutgoingMessage(StringUtil.stylizeString(message.substr(6), 'l33t'));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'kewl':
|
case 'kewl': {
|
||||||
const text_modes = Array('f','v','V','i','M');
|
const text_modes = Array('f','v','V','i','M');
|
||||||
const mode = text_modes[Math.floor(Math.random() * text_modes.length)];
|
const mode = text_modes[Math.floor(Math.random() * text_modes.length)];
|
||||||
this.processOutgoingMessage(StringUtil.stylizeString(message.substr(5), mode));
|
this.processOutgoingMessage(StringUtil.stylizeString(message.substr(6), mode));
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case 'whoon':
|
case 'whoon':
|
||||||
this.sendServerMessage('WHOON');
|
this.sendServerMessage('WHOON');
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -6,6 +6,8 @@ const Log = require('../../logger.js').log;
|
||||||
const { ServerModule } = require('../../server_module.js');
|
const { ServerModule } = require('../../server_module.js');
|
||||||
const Config = require('../../config.js').get;
|
const Config = require('../../config.js').get;
|
||||||
const { Errors } = require('../../enig_error.js');
|
const { Errors } = require('../../enig_error.js');
|
||||||
|
const SysProps = require('../../system_property.js');
|
||||||
|
const StatLog = require('../../stat_log.js');
|
||||||
|
|
||||||
// deps
|
// deps
|
||||||
const net = require('net');
|
const net = require('net');
|
||||||
|
@ -30,9 +32,7 @@ let mrcCentralConnection = '';
|
||||||
exports.getModule = class MrcModule extends ServerModule {
|
exports.getModule = class MrcModule extends ServerModule {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.log = Log.child( { server : 'MRC' } );
|
this.log = Log.child( { server : 'MRC' } );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
createServer(cb) {
|
createServer(cb) {
|
||||||
|
@ -43,12 +43,12 @@ exports.getModule = class MrcModule extends ServerModule {
|
||||||
const self = this;
|
const self = this;
|
||||||
|
|
||||||
const config = Config();
|
const config = Config();
|
||||||
const boardName = config.general.boardName;
|
const boardName = config.general.prettyBoardName || config.general.boardName;
|
||||||
const enigmaVersion = 'ENiGMA-BBS_' + require('../../../package.json').version;
|
const enigmaVersion = 'ENiGMA-BBS_' + require('../../../package.json').version;
|
||||||
|
|
||||||
const mrcConnectOpts = {
|
const mrcConnectOpts = {
|
||||||
port : 50000,
|
host : config.chatServers.mrc.serverHostname || 'mrc.bottomlessabyss.net',
|
||||||
host : 'mrc.bottomlessabyss.net'
|
port : config.chatServers.mrc.serverPort || 5000
|
||||||
};
|
};
|
||||||
|
|
||||||
const handshake = `${boardName}~${enigmaVersion}/${os.platform()}-${os.arch()}/${PROTOCOL_VERSION}`;
|
const handshake = `${boardName}~${enigmaVersion}/${os.platform()}-${os.arch()}/${PROTOCOL_VERSION}`;
|
||||||
|
@ -91,7 +91,6 @@ exports.getModule = class MrcModule extends ServerModule {
|
||||||
socket.on('data', data => {
|
socket.on('data', data => {
|
||||||
// split on \n to deal with getting messages in batches
|
// split on \n to deal with getting messages in batches
|
||||||
data.toString().split('\n').forEach( item => {
|
data.toString().split('\n').forEach( item => {
|
||||||
|
|
||||||
if (item == '') return;
|
if (item == '') return;
|
||||||
|
|
||||||
// save username with socket
|
// save username with socket
|
||||||
|
@ -103,7 +102,6 @@ exports.getModule = class MrcModule extends ServerModule {
|
||||||
self.receiveFromClient(socket.username, item);
|
self.receiveFromClient(socket.username, item);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('end', function() {
|
socket.on('end', function() {
|
||||||
|
@ -117,7 +115,6 @@ exports.getModule = class MrcModule extends ServerModule {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
return cb(null);
|
return cb(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,22 +143,31 @@ exports.getModule = class MrcModule extends ServerModule {
|
||||||
return _.isNumber(_.get(config, 'chatServers.mrc.multiplexerPort'));
|
return _.isNumber(_.get(config, 'chatServers.mrc.multiplexerPort'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends received messages to local clients
|
||||||
|
*/
|
||||||
sendToClient(message) {
|
sendToClient(message) {
|
||||||
connectedSockets.forEach( (client) => {
|
connectedSockets.forEach( (client) => {
|
||||||
if (message.to_user == '' || message.to_user == client.username || message.to_user == 'CLIENT') {
|
if (message.to_user == '' || message.to_user == client.username || message.to_user == 'CLIENT' || message.from_user == client.username || message.to_user == 'NOTME' ) {
|
||||||
// this.log.debug({ server : 'MRC', username : client.username, message : message }, 'Forwarding message to connected user')
|
this.log.debug({ server : 'MRC', username : client.username, message : message }, 'Forwarding message to connected user');
|
||||||
client.write(JSON.stringify(message) + '\n');
|
client.write(JSON.stringify(message) + '\n');
|
||||||
|
} else {
|
||||||
|
this.log.debug({ server : 'MRC', username : client.username, message : message }, 'Not forwarding message');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Processes messages received // split raw data received into an object we can work withfrom the central MRC server
|
||||||
|
*/
|
||||||
receiveFromMRC(socket, message) {
|
receiveFromMRC(socket, message) {
|
||||||
|
|
||||||
const config = Config();
|
const config = Config();
|
||||||
const siteName = slugify(config.general.boardName);
|
const siteName = slugify(config.general.boardName);
|
||||||
|
|
||||||
if (message.from_user == 'SERVER' && message.body == 'HELLO') {
|
if (message.from_user == 'SERVER' && message.body == 'HELLO') {
|
||||||
// initial server hello, can ignore
|
// reply with extra bbs info
|
||||||
|
this.sendToMrcServer(socket, 'CLIENT', '', 'SERVER', 'ALL', '', `INFOSYS:${StatLog.getSystemStat(SysProps.SysOpUsername)}`);
|
||||||
|
|
||||||
} else if (message.from_user == 'SERVER' && message.body.toUpperCase() == 'PING') {
|
} else if (message.from_user == 'SERVER' && message.body.toUpperCase() == 'PING') {
|
||||||
// reply to heartbeat
|
// reply to heartbeat
|
||||||
|
@ -174,7 +180,9 @@ exports.getModule = class MrcModule extends ServerModule {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// split raw data received into an object we can work with
|
/**
|
||||||
|
* Takes an MRC message and parses it into something usable
|
||||||
|
*/
|
||||||
parseMessage(line) {
|
parseMessage(line) {
|
||||||
const msg = line.split('~');
|
const msg = line.split('~');
|
||||||
if (msg.length < 7) {
|
if (msg.length < 7) {
|
||||||
|
@ -192,6 +200,9 @@ exports.getModule = class MrcModule extends ServerModule {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Receives a message from a local client and sanity checks before sending on to the central MRC server
|
||||||
|
*/
|
||||||
receiveFromClient(username, message) {
|
receiveFromClient(username, message) {
|
||||||
try {
|
try {
|
||||||
message = JSON.parse(message);
|
message = JSON.parse(message);
|
||||||
|
@ -202,7 +213,9 @@ exports.getModule = class MrcModule extends ServerModule {
|
||||||
this.sendToMrcServer(mrcCentralConnection, message.from_user, message.from_room, message.to_user, message.to_site, message.to_room, message.body);
|
this.sendToMrcServer(mrcCentralConnection, message.from_user, message.from_room, message.to_user, message.to_site, message.to_room, message.body);
|
||||||
}
|
}
|
||||||
|
|
||||||
// send a message back to the mrc central server
|
/**
|
||||||
|
* Converts a message back into the MRC format and sends it to the central MRC server
|
||||||
|
*/
|
||||||
sendToMrcServer(socket, fromUser, fromRoom, toUser, toSite, toRoom, messageBody) {
|
sendToMrcServer(socket, fromUser, fromRoom, toUser, toSite, toRoom, messageBody) {
|
||||||
const config = Config();
|
const config = Config();
|
||||||
const siteName = slugify(config.general.boardName);
|
const siteName = slugify(config.general.boardName);
|
||||||
|
@ -222,8 +235,9 @@ exports.getModule = class MrcModule extends ServerModule {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
// User / site name must be ASCII 33-125, no MCI, 30 chars max, underscores
|
* User / site name must be ASCII 33-125, no MCI, 30 chars max, underscores
|
||||||
|
*/
|
||||||
function sanitiseName(str) {
|
function sanitiseName(str) {
|
||||||
return str.replace(
|
return str.replace(
|
||||||
/\s/g, '_'
|
/\s/g, '_'
|
||||||
|
@ -242,6 +256,9 @@ function sanitiseMessage(message) {
|
||||||
return message.replace(/[^\x20-\x7D]/g, '');
|
return message.replace(/[^\x20-\x7D]/g, '');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SLugifies the BBS name for use as an MRC "site name"
|
||||||
|
*/
|
||||||
function slugify(text) {
|
function slugify(text) {
|
||||||
return text.toString()
|
return text.toString()
|
||||||
.replace(/\s+/g, '_') // Replace spaces with _
|
.replace(/\s+/g, '_') // Replace spaces with _
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue