Skip to content

Commit

Permalink
Sync with master
Browse files Browse the repository at this point in the history
  • Loading branch information
NuSkooler committed Nov 5, 2024
2 parents 5e01a49 + 27a6f2d commit 01c84f2
Show file tree
Hide file tree
Showing 16 changed files with 171 additions and 80 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ ENiGMA has been tested with many terminals. However, the following are suggested
* [SyncTERM](http://syncterm.bbsdev.net/)
* [EtherTerm](https://github.com/M-griffin/EtherTerm)
* [NetRunner](http://mysticbbs.com/downloads.html)
* [MagiTerm](https://magickabbs.com/index.php/magiterm/)
* [MagiTerm](https://gitlab.com/magickabbs/MagiTerm)

## Some Boards
* :skull: [Xibalba - ENiGMA WHQ](https://l33t.codes/xibalba-bbs) :skull: (**ssh://xibalba.l33t.codes:44511** or **telnet://xibalba.l33t.codes:44510**)
Expand Down
2 changes: 2 additions & 0 deletions core/config_default.js
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,8 @@ module.exports = () => {
enabled: false,
serverHostname: 'mrc.bottomlessabyss.net',
serverPort: 5000,
serverSslPort: 5001,
useSsl: false,
retryDelay: 10000,
multiplexerPort: 5000,
},
Expand Down
4 changes: 2 additions & 2 deletions core/goldmine.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ exports.getModule = class GoldmineModule extends MenuModule {
this.setConfigWithExtraArgs(options);

// http://goldminebbs.com/
this.config.host = this.config.host || '165.232.153.209';
this.config.rloginPort = this.config.rloginPort || 513;
this.config.host = this.config.host || 'goldminedoors.com';
this.config.rloginPort = this.config.rloginPort || 2513;
}

initSequence() {
Expand Down
86 changes: 63 additions & 23 deletions core/mrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const MciViewIds = {
const helpText = `
|15General Chat|08:
|03/|11rooms |08& |03/|11join |03<room> |08- |07List all or join a room
|03/|11pm |03<user> <message> |08- |07Send a private message
|03/|11pm |03<user> <message> |08- |07Send a private message |08(/t /tell /msg)
----
|03/|11whoon |08- |07Who's on what BBS
|03/|11chatters |08- |07Who's in what room
Expand All @@ -57,6 +57,7 @@ const helpText = `
|03/|11meetups |08- |07Info about MRC MeetUps
|03/|11quote |08- |07Send raw command to server
|03/|11help |08- |07Server-side commands help
|03/|11quit |08- |07Quit MRC |08(/q)
---
|03/|11l33t |03<your message> |08- |07l337 5p34k
|03/|11kewl |03<your message> |08- |07BBS KeWL SPeaK
Expand Down Expand Up @@ -275,21 +276,7 @@ exports.getModule = class mrcModule extends MenuModule {
const chatLogView = this.viewControllers.mrcChat.getView(
MciViewIds.mrcChat.chatLog
);
const messageLength = stripMciColorCodes(msg).length;
const chatWidth = chatLogView.dimens.width;
let padAmount = 0;
let spaces = 2;

if (messageLength > chatWidth) {
padAmount = chatWidth - (messageLength % chatWidth) - spaces;
} else {
padAmount = chatWidth - messageLength - spaces;
}

if (padAmount < 0) padAmount = 0;

const padding = ' |00' + ' '.repeat(padAmount);
chatLogView.addText(pipeToAnsi(msg + padding));
chatLogView.addText(pipeToAnsi(msg));

if (chatLogView.getLineCount() > this.config.maxScrollbackLines) {
chatLogView.deleteLine(0);
Expand Down Expand Up @@ -380,7 +367,7 @@ exports.getModule = class mrcModule extends MenuModule {

// Deliver PrivMsg
else if (
message.to_user.toLowerCase() == this.state.alias.toLowerCase()
message.to_user.toUpperCase() == this.state.alias.toUpperCase()
) {
const currentTime = moment().format(
this.client.currentTheme.helpers.getTimeFormat()
Expand Down Expand Up @@ -437,11 +424,11 @@ exports.getModule = class mrcModule extends MenuModule {

const messageFormat =
this.config.messageFormat ||
'|00|10<|02{fromUserName}|10>|00 |03{message}|00';
'|00|10<|02{fromUserName}|10>|00 |03{message}';

const privateMessageFormat =
this.config.outgoingPrivateMessageFormat ||
'|00|10<|02{fromUserName}|10|14->|02{toUserName}>|00 |03{message}|00';
'|00|10<|02{fromUserName}|10|14->|02{toUserName}>|00 |03{message}';

let formattedMessage = '';
if (to_user == undefined) {
Expand All @@ -450,6 +437,14 @@ exports.getModule = class mrcModule extends MenuModule {
} else {
// pm
formattedMessage = stringFormat(privateMessageFormat, textFormatObj);

// Echo PrivMSG to chat log (the server does not echo it back)
const currentTime =moment().format(
this.client.currentTheme.helpers.getTimeFormat()
);
this.addMessageToChatLog(
'|08' + currentTime + '|00 ' + formattedMessage + '|00'
);
}

try {
Expand Down Expand Up @@ -477,6 +472,9 @@ exports.getModule = class mrcModule extends MenuModule {
cmd[0] = cmd[0].substr(1).toLowerCase();

switch (cmd[0]) {
case 't':
case 'tell':
case 'msg':
case 'pm':
const newmsg = cmd.slice(2).join(' ');
this.processOutgoingMessage(newmsg, cmd[1]);
Expand Down Expand Up @@ -562,6 +560,7 @@ exports.getModule = class mrcModule extends MenuModule {
/**
* Process known additional server commands directly
*/

case 'afk':
this.sendServerMessage(`AFK ${message.substr(5)}`);
break;
Expand All @@ -578,6 +577,10 @@ exports.getModule = class mrcModule extends MenuModule {
this.sendServerMessage(`STATUS ${message.substr(8)}`);
break;

case 'topics':
this.sendServerMessage(`TOPICS ${message.substr(8)}`);
break;

case 'lastseen':
this.sendServerMessage(`LASTSEEN ${message.substr(10)}`);
break;
Expand All @@ -594,6 +597,31 @@ exports.getModule = class mrcModule extends MenuModule {
this.sendServerMessage(cmd[0].toUpperCase());
break;

/**
* MRC Trust commands
*/

case 'trust':
this.sendServerMessage(`TRUST ${message.substr(7)}`);
break;

case 'register':
this.sendServerMessage(`REGISTER ${message.substr(10)}`);
break;

case 'identify':
this.sendServerMessage(`IDENTIFY ${message.substr(10)}`);
break;

case 'update':
this.sendServerMessage(`UPDATE ${message.substr(8)}`);
break;

/**
* Local client commands
*/

case 'q':
case 'quit':
return this.prevMenu();

Expand Down Expand Up @@ -621,6 +649,13 @@ exports.getModule = class mrcModule extends MenuModule {
chatLogView.setText('');
}

/**
* MRC Server flood protection requires messages to be spaced in time
*/
msgDelay(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}

/**
* Creates a json object, stringifies it and sends it to the MRC multiplexer
*/
Expand Down Expand Up @@ -657,21 +692,26 @@ exports.getModule = class mrcModule extends MenuModule {
/**
* Joins a room, unsurprisingly
*/
joinRoom(room) {
async joinRoom(room) {
// room names are displayed with a # but referred to without. confusing.
room = room.replace(/^#/, '');
this.state.room = room;
this.sendServerMessage(`NEWROOM:${this.state.room}:${room}`);

await this.msgDelay(100);
this.sendServerMessage('USERLIST');
}

/**
* Things that happen when a local user connects to the MRC multiplexer
*/
clientConnect() {
this.sendServerMessage('MOTD');
async clientConnect() {
this.sendHeartbeat();
await this.msgDelay(100);

this.joinRoom('lobby');
await this.msgDelay(100);

this.sendServerMessage('STATS');
this.sendHeartbeat();
}
};
51 changes: 40 additions & 11 deletions core/servers/chat/mrc_multiplexer.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ const _ = require('lodash');
const os = require('os');

// MRC
const protocolVersion = '1.2.9';
const lineDelimiter = new RegExp('\r\n|\r|\n'); // eslint-disable-line no-control-regex
const clientVersion = '1.3.1';
const lineDelimiter = new RegExp('\r\n|\r|\n|\n\r'); // eslint-disable-line no-control-regex

const ModuleInfo = (exports.moduleInfo = {
name: 'MRC',
Expand All @@ -35,20 +35,32 @@ exports.getModule = class MrcModule extends ServerModule {
this.log = Log.child({ server: 'MRC' });

const config = Config();
this.boardName = config.general.prettyBoardName || config.general.boardName;
this.mrcConnectOpts = {
this.boardName = config.general.boardName;

// Use prettyBoardName only if non-default
if (config.general.prettyBoardName != '|08XXXXX') this.boardName = config.general.prettyBoardName;

this.mrcConfig = {
host: config.chatServers.mrc.serverHostname || 'mrc.bottomlessabyss.net',
port: config.chatServers.mrc.serverPort || 5000,
sslport: config.chatServers.mrc.serverSslPort || 5001,
retryDelay: config.chatServers.mrc.retryDelay || 10000,
useSsl: config.chatServers.mrc.useSsl || false,
};

this.mrcConnectOpts = {
host: this.mrcConfig.host,
port: this.mrcConfig.port,
retryDelay: this.mrcConfig.retryDelay
}
}

_connectionHandler() {
const enigmaVersion = 'ENiGMA½-BBS_' + require('../../../package.json').version;

const handshake = `${
this.boardName
}~${enigmaVersion}/${os.platform()}.${os.arch()}/${protocolVersion}`;
}~${enigmaVersion}/${os.platform()}.${os.arch()}/${clientVersion}`;
this.log.debug({ handshake: handshake }, 'Handshaking with MRC server');

this.sendRaw(handshake);
Expand Down Expand Up @@ -96,13 +108,27 @@ exports.getModule = class MrcModule extends ServerModule {
connectToMrc() {
const self = this;

// create connection to MRC server
this.mrcClient = net.createConnection(
if (this.mrcConfig.useSsl) {
this.mrcConnectOpts.port = this.mrcConfig.sslport;
}

// Create connection
this.mrcSocket = net.createConnection(
this.mrcConnectOpts,
self._connectionHandler.bind(self)
);

this.mrcClient.requestedDisconnect = false;
this.mrcSocket.requestedDisconnect = false;

// Check if we upgrade the connection to SSL
if (this.mrcConfig.useSsl) {
const tls = require('tls')
this.mrcSecureSocket = new tls.TLSSocket(this.mrcSocket, { isServer: false });
this.mrcClient = this.mrcSecureSocket;
}
else {
this.mrcClient = this.mrcSocket;
}

// do things when we get data from MRC central
let buffer = new Buffer.from('');
Expand Down Expand Up @@ -219,8 +245,7 @@ exports.getModule = class MrcModule extends ServerModule {
connectedSockets.forEach(client => {
if (
message.to_user == '' ||
// Fix PrivMSG delivery on case mismatch
message.to_user.toUpperCase() == client.username.toUpperCase() ||
message.to_user == client.username.toUpperCase() ||
message.to_user == 'CLIENT' ||
message.from_user == client.username ||
message.to_user == 'NOTME'
Expand Down Expand Up @@ -302,14 +327,18 @@ exports.getModule = class MrcModule extends ServerModule {
* Takes an MRC message and parses it into something usable
*/
parseMessage(line) {
const [from_user, from_site, from_room, to_user, to_site, to_room, body] =
let [from_user, from_site, from_room, to_user, to_site, to_room, body] =
line.split('~');

// const msg = line.split('~');
// if (msg.length < 7) {
// return;
// }

// Make sure to_user and from_user are always uppercase
to_user = (to_user || '').toUpperCase();
from_user = (from_user || '').toUpperCase();

return { from_user, from_site, from_room, to_user, to_site, to_room, body };
}

Expand Down
37 changes: 19 additions & 18 deletions core/servers/login/websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,25 @@ class WebSocketClient extends TelnetClient {
})(ws);

super(wsDuplex);

Log.trace({ headers: req.headers }, 'WebSocket connection headers');

//
// If the config allows it, look for 'x-forwarded-proto' as "https"
// to override |isSecure|
//
if (
true === _.get(Config(), 'loginServers.webSocket.proxied') &&
'https' === req.headers['x-forwarded-proto']
) {
Log.debug(
`Assuming secure connection due to X-Forwarded-Proto of "${req.headers['x-forwarded-proto']}"`
);
this.proxied = true;
} else {
this.proxied = false;
}

wsDuplex.setClient(this, req);

// fudge remoteAddress on socket, which is now TelnetSocket
Expand All @@ -91,24 +110,6 @@ class WebSocketClient extends TelnetClient {
ws.isConnectionAlive = true;
});

Log.trace({ headers: req.headers }, 'WebSocket connection headers');

//
// If the config allows it, look for 'x-forwarded-proto' as "https"
// to override |isSecure|
//
if (
true === _.get(Config(), 'loginServers.webSocket.proxied') &&
'https' === req.headers['x-forwarded-proto']
) {
Log.debug(
`Assuming secure connection due to X-Forwarded-Proto of "${req.headers['x-forwarded-proto']}"`
);
this.proxied = true;
} else {
this.proxied = false;
}

// start handshake process
this.banner();
}
Expand Down
Loading

0 comments on commit 01c84f2

Please sign in to comment.