2019-05-17 23:25:35 +00:00
|
|
|
/* jslint node: true */
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
// ENiGMA½
|
2022-06-05 20:04:25 +00:00
|
|
|
const Log = require('./logger.js').log;
|
|
|
|
const { MenuModule } = require('./menu_module.js');
|
|
|
|
const { pipeToAnsi, stripMciColorCodes } = require('./color_codes.js');
|
|
|
|
const stringFormat = require('./string_format.js');
|
|
|
|
const StringUtil = require('./string_util.js');
|
|
|
|
const Config = require('./config.js').get;
|
2019-05-17 23:25:35 +00:00
|
|
|
|
|
|
|
// deps
|
2022-06-05 20:04:25 +00:00
|
|
|
const _ = require('lodash');
|
|
|
|
const async = require('async');
|
|
|
|
const net = require('net');
|
|
|
|
const moment = require('moment');
|
2019-05-17 23:25:35 +00:00
|
|
|
|
|
|
|
exports.moduleInfo = {
|
2022-06-05 20:04:25 +00:00
|
|
|
name: 'MRC Client',
|
|
|
|
desc: 'Connects to an MRC chat server',
|
|
|
|
author: 'RiPuk',
|
|
|
|
packageName: 'codes.l33t.enigma.mrc.client',
|
2019-05-18 23:01:58 +00:00
|
|
|
|
2019-05-22 22:43:41 +00:00
|
|
|
// Whilst this module was put together by me (RiPuk), it should be noted that a lot of the ideas (and even some code snippets) were
|
2019-05-18 23:01:58 +00:00
|
|
|
// borrowed from the Synchronet implementation of MRC by echicken. So...thanks, your code was very helpful in putting this together.
|
|
|
|
// Source at http://cvs.synchro.net/cgi-bin/viewcvs.cgi/xtrn/mrc/.
|
2019-05-17 23:25:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const FormIds = {
|
2022-06-05 20:04:25 +00:00
|
|
|
mrcChat: 0,
|
2019-05-17 23:25:35 +00:00
|
|
|
};
|
|
|
|
|
2019-06-08 05:23:06 +00:00
|
|
|
const MciViewIds = {
|
2022-06-05 20:04:25 +00:00
|
|
|
mrcChat: {
|
|
|
|
chatLog: 1,
|
|
|
|
inputArea: 2,
|
|
|
|
roomName: 3,
|
|
|
|
roomTopic: 4,
|
|
|
|
mrcUsers: 5,
|
|
|
|
mrcBbses: 6,
|
|
|
|
|
|
|
|
customRangeStart: 20, // 20+ = customs
|
|
|
|
},
|
2019-05-17 23:25:35 +00:00
|
|
|
};
|
|
|
|
|
2019-05-20 22:37:32 +00:00
|
|
|
// TODO: this is a bit shit, could maybe do it with an ansi instead
|
|
|
|
const helpText = `
|
2019-06-08 05:23:06 +00:00
|
|
|
|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
|
2019-05-20 22:37:32 +00:00
|
|
|
----
|
2019-06-08 05:23:06 +00:00
|
|
|
|03/|11whoon |08- |07Who's on what BBS
|
|
|
|
|03/|11chatters |08- |07Who's in what room
|
|
|
|
|03/|11clear |08- |07Clear back buffer
|
2019-06-08 17:58:21 +00:00
|
|
|
|03/|11topic |03<message> |08- |07Set the room topic
|
|
|
|
|03/|11bbses |08& |03/|11info <id> |08- |07Info about BBS's connected
|
2019-06-08 05:23:06 +00:00
|
|
|
|03/|11meetups |08- |07Info about MRC MeetUps
|
2023-03-31 17:46:07 +00:00
|
|
|
|03/|11quote |08- |07Send raw command to server
|
|
|
|
|03/|11help |08- |07Server-side commands help
|
2019-05-20 22:37:32 +00:00
|
|
|
---
|
2019-06-08 17:58:21 +00:00
|
|
|
|03/|11l33t |03<your message> |08- |07l337 5p34k
|
|
|
|
|03/|11kewl |03<your message> |08- |07BBS KeWL SPeaK
|
|
|
|
|03/|11rainbow |03<your message> |08- |07Crazy rainbow text
|
2019-05-20 22:37:32 +00:00
|
|
|
`;
|
|
|
|
|
2019-05-17 23:25:35 +00:00
|
|
|
exports.getModule = class mrcModule extends MenuModule {
|
|
|
|
constructor(options) {
|
|
|
|
super(options);
|
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
this.log = Log.child({ module: 'MRC' });
|
|
|
|
this.config = Object.assign({}, _.get(options, 'menuConfig.config'), {
|
|
|
|
extraArgs: options.extraArgs,
|
|
|
|
});
|
2019-05-22 22:43:41 +00:00
|
|
|
|
2019-06-08 18:12:29 +00:00
|
|
|
this.config.maxScrollbackLines = this.config.maxScrollbackLines || 500;
|
|
|
|
|
2019-05-20 22:37:32 +00:00
|
|
|
this.state = {
|
|
|
|
socket: '',
|
|
|
|
alias: this.client.user.username,
|
|
|
|
room: '',
|
|
|
|
room_topic: '',
|
|
|
|
nicks: [],
|
2022-06-05 20:04:25 +00:00
|
|
|
lastSentMsg: {}, // used for latency est.
|
2019-05-20 22:37:32 +00:00
|
|
|
};
|
2019-05-22 22:43:41 +00:00
|
|
|
|
2019-06-10 04:36:24 +00:00
|
|
|
this.customFormatObj = {
|
2022-06-05 20:04:25 +00:00
|
|
|
roomName: '',
|
|
|
|
roomTopic: '',
|
|
|
|
roomUserCount: 0,
|
|
|
|
userCount: 0,
|
|
|
|
boardCount: 0,
|
|
|
|
roomCount: 0,
|
|
|
|
latencyMs: 0,
|
|
|
|
activityLevel: 0,
|
|
|
|
activityLevelIndicator: ' ',
|
2019-06-10 04:36:24 +00:00
|
|
|
};
|
|
|
|
|
2019-05-17 23:25:35 +00:00
|
|
|
this.menuMethods = {
|
2022-06-05 20:04:25 +00:00
|
|
|
sendChatMessage: (formData, extraArgs, cb) => {
|
|
|
|
const inputAreaView = this.viewControllers.mrcChat.getView(
|
|
|
|
MciViewIds.mrcChat.inputArea
|
|
|
|
);
|
|
|
|
const inputData = inputAreaView.getData();
|
2019-05-18 23:01:58 +00:00
|
|
|
|
2019-05-22 22:43:41 +00:00
|
|
|
this.processOutgoingMessage(inputData);
|
2019-05-17 23:25:35 +00:00
|
|
|
inputAreaView.clearText();
|
2019-05-22 22:43:41 +00:00
|
|
|
|
2019-05-17 23:25:35 +00:00
|
|
|
return cb(null);
|
2019-05-18 23:01:58 +00:00
|
|
|
},
|
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
movementKeyPressed: (formData, extraArgs, cb) => {
|
|
|
|
const bodyView = this.viewControllers.mrcChat.getView(
|
|
|
|
MciViewIds.mrcChat.chatLog
|
|
|
|
);
|
|
|
|
switch (formData.key.name) {
|
|
|
|
case 'down arrow':
|
|
|
|
bodyView.scrollDocumentUp();
|
|
|
|
break;
|
|
|
|
case 'up arrow':
|
|
|
|
bodyView.scrollDocumentDown();
|
|
|
|
break;
|
|
|
|
case 'page up':
|
|
|
|
bodyView.keyPressPageUp();
|
|
|
|
break;
|
|
|
|
case 'page down':
|
|
|
|
bodyView.keyPressPageDown();
|
|
|
|
break;
|
2019-05-18 23:01:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.viewControllers.mrcChat.switchFocus(MciViewIds.mrcChat.inputArea);
|
|
|
|
|
|
|
|
return cb(null);
|
2019-05-25 23:14:36 +00:00
|
|
|
},
|
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
quit: (formData, extraArgs, cb) => {
|
2019-05-25 23:14:36 +00:00
|
|
|
return this.prevMenu(cb);
|
2019-06-09 06:09:07 +00:00
|
|
|
},
|
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
clearMessages: (formData, extraArgs, cb) => {
|
2019-06-09 06:09:07 +00:00
|
|
|
this.clearMessages();
|
|
|
|
return cb(null);
|
2022-06-05 20:04:25 +00:00
|
|
|
},
|
2019-05-22 22:43:41 +00:00
|
|
|
};
|
2019-05-17 23:25:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mciReady(mciData, cb) {
|
|
|
|
super.mciReady(mciData, err => {
|
2022-06-05 20:04:25 +00:00
|
|
|
if (err) {
|
2019-05-17 23:25:35 +00:00
|
|
|
return cb(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
async.series(
|
2019-05-20 22:37:32 +00:00
|
|
|
[
|
2022-06-05 20:04:25 +00:00
|
|
|
callback => {
|
|
|
|
return this.prepViewController(
|
|
|
|
'mrcChat',
|
|
|
|
FormIds.mrcChat,
|
|
|
|
mciData.menu,
|
|
|
|
callback
|
|
|
|
);
|
2019-05-17 23:25:35 +00:00
|
|
|
},
|
2022-06-05 20:04:25 +00:00
|
|
|
callback => {
|
|
|
|
return this.validateMCIByViewIds(
|
|
|
|
'mrcChat',
|
|
|
|
[MciViewIds.mrcChat.chatLog, MciViewIds.mrcChat.inputArea],
|
|
|
|
callback
|
|
|
|
);
|
2019-05-17 23:25:35 +00:00
|
|
|
},
|
2022-06-05 20:04:25 +00:00
|
|
|
callback => {
|
2019-05-17 23:25:35 +00:00
|
|
|
const connectOpts = {
|
2022-06-05 20:04:25 +00:00
|
|
|
port: _.get(
|
|
|
|
Config(),
|
|
|
|
'chatServers.mrc.multiplexerPort',
|
|
|
|
5000
|
|
|
|
),
|
|
|
|
host: 'localhost',
|
2019-05-17 23:25:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// connect to multiplexer
|
2019-05-20 22:37:32 +00:00
|
|
|
this.state.socket = net.createConnection(connectOpts, () => {
|
2019-06-08 05:23:06 +00:00
|
|
|
this.client.once('end', () => {
|
|
|
|
this.quitServer();
|
|
|
|
});
|
|
|
|
|
2019-05-17 23:25:35 +00:00
|
|
|
// handshake with multiplexer
|
2019-06-08 05:23:06 +00:00
|
|
|
this.state.socket.write(`--DUDE-ITS--|${this.state.alias}\n`);
|
2019-05-17 23:25:35 +00:00
|
|
|
|
2019-06-08 05:23:06 +00:00
|
|
|
this.clientConnect();
|
2019-05-17 23:25:35 +00:00
|
|
|
|
2019-05-18 23:01:58 +00:00
|
|
|
// send register to central MRC and get stats every 60s
|
2022-06-05 20:04:25 +00:00
|
|
|
this.heartbeat = setInterval(() => {
|
2019-06-08 05:23:06 +00:00
|
|
|
this.sendHeartbeat();
|
|
|
|
this.sendServerMessage('STATS');
|
2019-05-20 22:37:32 +00:00
|
|
|
}, 60000);
|
2019-06-09 19:41:11 +00:00
|
|
|
|
|
|
|
// override idle logout seconds if configured
|
2022-06-05 20:04:25 +00:00
|
|
|
const idleLogoutSeconds = parseInt(
|
|
|
|
this.config.idleLogoutSeconds
|
|
|
|
);
|
|
|
|
if (0 === idleLogoutSeconds) {
|
|
|
|
this.log.debug(
|
|
|
|
'Temporary disable idle monitor due to config'
|
|
|
|
);
|
2019-06-09 19:41:11 +00:00
|
|
|
this.client.stopIdleMonitor();
|
2022-06-05 20:04:25 +00:00
|
|
|
} else if (
|
|
|
|
!isNaN(idleLogoutSeconds) &&
|
|
|
|
idleLogoutSeconds >= 60
|
|
|
|
) {
|
|
|
|
this.log.debug(
|
|
|
|
{ idleLogoutSeconds },
|
|
|
|
'Temporary override idle logout seconds due to config'
|
|
|
|
);
|
2019-06-09 19:41:11 +00:00
|
|
|
this.client.overrideIdleLogoutSeconds(idleLogoutSeconds);
|
|
|
|
}
|
2019-05-17 23:25:35 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// when we get data, process it
|
2019-05-20 22:37:32 +00:00
|
|
|
this.state.socket.on('data', data => {
|
2019-05-17 23:25:35 +00:00
|
|
|
data = data.toString();
|
|
|
|
this.processReceivedMessage(data);
|
|
|
|
});
|
|
|
|
|
2019-06-09 06:09:07 +00:00
|
|
|
this.state.socket.once('error', err => {
|
2022-06-05 20:04:25 +00:00
|
|
|
this.log.warn(
|
|
|
|
{ error: err.message },
|
|
|
|
'MRC multiplexer socket error'
|
|
|
|
);
|
2019-06-09 06:09:07 +00:00
|
|
|
this.state.socket.destroy();
|
|
|
|
delete this.state.socket;
|
|
|
|
|
|
|
|
// bail with error - fall back to prev menu
|
|
|
|
return callback(err);
|
|
|
|
});
|
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
return callback;
|
|
|
|
},
|
2019-05-17 23:25:35 +00:00
|
|
|
],
|
|
|
|
err => {
|
|
|
|
return cb(err);
|
|
|
|
}
|
2019-05-22 22:43:41 +00:00
|
|
|
);
|
2019-05-17 23:25:35 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-06-08 05:23:06 +00:00
|
|
|
leave() {
|
|
|
|
this.quitServer();
|
2019-06-09 19:41:11 +00:00
|
|
|
|
|
|
|
// restore idle monitor to previous state
|
|
|
|
this.log.debug('Restoring idle monitor to previous state');
|
|
|
|
this.client.restoreIdleLogoutSeconds();
|
|
|
|
this.client.startIdleMonitor();
|
|
|
|
|
2019-06-08 05:23:06 +00:00
|
|
|
return super.leave();
|
|
|
|
}
|
|
|
|
|
|
|
|
quitServer() {
|
|
|
|
clearInterval(this.heartbeat);
|
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
if (this.state.socket) {
|
2019-06-08 05:23:06 +00:00
|
|
|
this.sendServerMessage('LOGOFF');
|
|
|
|
this.state.socket.destroy();
|
2019-06-08 17:58:21 +00:00
|
|
|
delete this.state.socket;
|
2019-06-08 05:23:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-22 22:43:41 +00:00
|
|
|
/**
|
|
|
|
* Adds a message to the chat log on screen
|
|
|
|
*/
|
|
|
|
addMessageToChatLog(message) {
|
2022-06-05 20:04:25 +00:00
|
|
|
if (!Array.isArray(message)) {
|
|
|
|
message = [message];
|
2019-05-25 23:14:36 +00:00
|
|
|
}
|
|
|
|
|
2019-06-08 05:23:06 +00:00
|
|
|
message.forEach(msg => {
|
2022-06-05 20:04:25 +00:00
|
|
|
const chatLogView = this.viewControllers.mrcChat.getView(
|
|
|
|
MciViewIds.mrcChat.chatLog
|
|
|
|
);
|
2019-06-08 05:23:06 +00:00
|
|
|
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;
|
2019-05-31 19:34:07 +00:00
|
|
|
|
2019-06-08 05:23:06 +00:00
|
|
|
const padding = ' |00' + ' '.repeat(padAmount);
|
|
|
|
chatLogView.addText(pipeToAnsi(msg + padding));
|
2019-06-08 18:12:29 +00:00
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
if (chatLogView.getLineCount() > this.config.maxScrollbackLines) {
|
2019-06-08 18:12:29 +00:00
|
|
|
chatLogView.deleteLine(0);
|
|
|
|
}
|
2019-06-08 05:23:06 +00:00
|
|
|
});
|
2019-05-22 22:43:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-05-25 23:14:36 +00:00
|
|
|
* Processes data received from the MRC multiplexer
|
|
|
|
*/
|
2019-05-17 23:25:35 +00:00
|
|
|
processReceivedMessage(blob) {
|
2022-06-05 20:04:25 +00:00
|
|
|
blob.split('\n').forEach(message => {
|
2019-05-17 23:25:35 +00:00
|
|
|
try {
|
2019-05-22 22:43:41 +00:00
|
|
|
message = JSON.parse(message);
|
2019-05-17 23:25:35 +00:00
|
|
|
} catch (e) {
|
2019-05-22 22:43:41 +00:00
|
|
|
return;
|
2019-05-17 23:25:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (message.from_user == 'SERVER') {
|
|
|
|
const params = message.body.split(':');
|
|
|
|
|
|
|
|
switch (params[0]) {
|
|
|
|
case 'BANNER':
|
2019-05-22 22:43:41 +00:00
|
|
|
this.addMessageToChatLog(params[1].replace(/^\s+/, ''));
|
2019-05-18 23:01:58 +00:00
|
|
|
break;
|
2019-05-17 23:25:35 +00:00
|
|
|
|
|
|
|
case 'ROOMTOPIC':
|
2019-06-10 04:36:24 +00:00
|
|
|
this.setText(MciViewIds.mrcChat.roomName, `#${params[1]}`);
|
|
|
|
this.setText(MciViewIds.mrcChat.roomTopic, params[2]);
|
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
this.customFormatObj.roomName = params[1];
|
|
|
|
this.customFormatObj.roomTopic = params[2];
|
2019-06-10 04:36:24 +00:00
|
|
|
this.updateCustomViews();
|
|
|
|
|
2019-05-20 22:37:32 +00:00
|
|
|
this.state.room = params[1];
|
2019-05-18 23:01:58 +00:00
|
|
|
break;
|
2019-05-22 22:43:41 +00:00
|
|
|
|
2019-05-17 23:25:35 +00:00
|
|
|
case 'USERLIST':
|
2019-05-20 22:37:32 +00:00
|
|
|
this.state.nicks = params[1].split(',');
|
2019-06-10 04:36:24 +00:00
|
|
|
|
|
|
|
this.customFormatObj.roomUserCount = this.state.nicks.length;
|
|
|
|
this.updateCustomViews();
|
2019-05-18 23:01:58 +00:00
|
|
|
break;
|
2019-05-22 22:43:41 +00:00
|
|
|
|
2019-05-25 23:14:36 +00:00
|
|
|
case 'STATS': {
|
2022-06-05 20:04:25 +00:00
|
|
|
const [boardCount, roomCount, userCount, activityLevel] =
|
|
|
|
params[1].split(' ').map(v => parseInt(v));
|
|
|
|
|
|
|
|
const activityLevelIndicator =
|
|
|
|
this.getActivityLevelIndicator(activityLevel);
|
|
|
|
|
|
|
|
Object.assign(this.customFormatObj, {
|
2019-06-11 02:07:45 +00:00
|
|
|
boardCount,
|
|
|
|
roomCount,
|
|
|
|
userCount,
|
2022-06-05 20:04:25 +00:00
|
|
|
activityLevel,
|
|
|
|
activityLevelIndicator,
|
|
|
|
});
|
2019-06-10 04:36:24 +00:00
|
|
|
|
2019-06-11 02:07:45 +00:00
|
|
|
this.setText(MciViewIds.mrcChat.mrcUsers, userCount);
|
|
|
|
this.setText(MciViewIds.mrcChat.mrcBbses, boardCount);
|
2019-06-10 04:36:24 +00:00
|
|
|
|
2019-06-11 02:07:45 +00:00
|
|
|
this.updateCustomViews();
|
2019-05-18 23:01:58 +00:00
|
|
|
break;
|
2019-05-25 23:14:36 +00:00
|
|
|
}
|
2019-05-18 23:01:58 +00:00
|
|
|
|
|
|
|
default:
|
2019-05-22 22:43:41 +00:00
|
|
|
this.addMessageToChatLog(message.body);
|
2019-05-18 23:01:58 +00:00
|
|
|
break;
|
2019-05-17 23:25:35 +00:00
|
|
|
}
|
|
|
|
} else {
|
2022-06-05 20:04:25 +00:00
|
|
|
if (message.body === this.state.lastSentMsg.msg) {
|
|
|
|
this.customFormatObj.latencyMs = moment
|
|
|
|
.duration(moment().diff(this.state.lastSentMsg.time))
|
|
|
|
.asMilliseconds();
|
2019-06-11 02:07:45 +00:00
|
|
|
delete this.state.lastSentMsg.msg;
|
|
|
|
}
|
|
|
|
|
2019-05-25 23:14:36 +00:00
|
|
|
if (message.to_room == this.state.room) {
|
2019-05-18 23:01:58 +00:00
|
|
|
// if we're here then we want to show it to the user
|
2022-06-05 20:04:25 +00:00
|
|
|
const currentTime = moment().format(
|
|
|
|
this.client.currentTheme.helpers.getTimeFormat()
|
|
|
|
);
|
|
|
|
this.addMessageToChatLog(
|
|
|
|
'|08' + currentTime + '|00 ' + message.body + '|00'
|
|
|
|
);
|
2019-05-18 23:01:58 +00:00
|
|
|
}
|
2023-03-31 17:46:07 +00:00
|
|
|
|
|
|
|
// Deliver PrivMsg
|
2023-05-11 14:40:53 +00:00
|
|
|
else if (
|
|
|
|
message.to_user.toLowerCase() == this.state.alias.toLowerCase()
|
|
|
|
) {
|
2023-03-31 17:46:07 +00:00
|
|
|
const currentTime = moment().format(
|
|
|
|
this.client.currentTheme.helpers.getTimeFormat()
|
|
|
|
);
|
|
|
|
this.addMessageToChatLog(
|
|
|
|
'|08' + currentTime + '|00 ' + message.body + '|00'
|
|
|
|
);
|
|
|
|
}
|
2019-05-17 23:25:35 +00:00
|
|
|
}
|
|
|
|
|
2019-05-18 23:01:58 +00:00
|
|
|
this.viewControllers.mrcChat.switchFocus(MciViewIds.mrcChat.inputArea);
|
2019-05-17 23:25:35 +00:00
|
|
|
});
|
|
|
|
}
|
2019-05-18 23:01:58 +00:00
|
|
|
|
2019-06-11 02:07:45 +00:00
|
|
|
getActivityLevelIndicator(level) {
|
|
|
|
let indicators = this.config.activityLevelIndicators;
|
2022-06-05 20:04:25 +00:00
|
|
|
if (!Array.isArray(indicators) || indicators.length < level + 1) {
|
|
|
|
indicators = [' ', '░', '▒', '▓'];
|
2019-06-11 02:07:45 +00:00
|
|
|
}
|
2019-06-11 02:12:17 +00:00
|
|
|
return indicators[level];
|
2019-06-11 02:07:45 +00:00
|
|
|
}
|
|
|
|
|
2019-06-10 04:36:24 +00:00
|
|
|
setText(mciId, text) {
|
|
|
|
return this.setViewText('mrcChat', mciId, text);
|
|
|
|
}
|
|
|
|
|
|
|
|
updateCustomViews() {
|
|
|
|
return this.updateCustomViewTextsWithFilter(
|
|
|
|
'mrcChat',
|
|
|
|
MciViewIds.mrcChat.customRangeStart,
|
|
|
|
this.customFormatObj
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-05-22 22:43:41 +00:00
|
|
|
/**
|
|
|
|
* Receives the message input from the user and does something with it based on what it is
|
|
|
|
*/
|
|
|
|
processOutgoingMessage(message, to_user) {
|
2019-05-18 23:01:58 +00:00
|
|
|
if (message.startsWith('/')) {
|
2019-05-22 22:43:41 +00:00
|
|
|
this.processSlashCommand(message);
|
2019-05-20 22:37:32 +00:00
|
|
|
} else {
|
|
|
|
if (message == '') {
|
2019-05-25 23:14:36 +00:00
|
|
|
// don't do anything if message is blank, just update stats
|
2019-05-22 22:43:41 +00:00
|
|
|
this.sendServerMessage('STATS');
|
2019-05-20 22:37:32 +00:00
|
|
|
return;
|
2019-05-18 23:01:58 +00:00
|
|
|
}
|
|
|
|
|
2019-05-25 23:14:36 +00:00
|
|
|
// else just format and send
|
2019-05-18 23:01:58 +00:00
|
|
|
const textFormatObj = {
|
2022-06-05 20:04:25 +00:00
|
|
|
fromUserName: this.state.alias,
|
|
|
|
toUserName: to_user,
|
|
|
|
message: message,
|
2019-05-18 23:01:58 +00:00
|
|
|
};
|
2019-05-20 22:37:32 +00:00
|
|
|
|
2019-05-18 23:01:58 +00:00
|
|
|
const messageFormat =
|
|
|
|
this.config.messageFormat ||
|
|
|
|
'|00|10<|02{fromUserName}|10>|00 |03{message}|00';
|
2019-06-08 05:23:06 +00:00
|
|
|
|
2019-05-25 23:14:36 +00: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 {
|
2020-06-16 01:08:55 +00:00
|
|
|
// pm
|
2019-05-25 23:14:36 +00:00
|
|
|
formattedMessage = stringFormat(privateMessageFormat, textFormatObj);
|
|
|
|
}
|
2019-06-08 05:23:06 +00:00
|
|
|
|
2019-05-18 23:01:58 +00:00
|
|
|
try {
|
2019-06-11 02:07:45 +00:00
|
|
|
this.state.lastSentMsg = {
|
2022-06-05 20:04:25 +00:00
|
|
|
msg: formattedMessage,
|
|
|
|
time: moment(),
|
2019-06-11 02:07:45 +00:00
|
|
|
};
|
2022-06-05 20:04:25 +00:00
|
|
|
this.sendMessageToMultiplexer(
|
|
|
|
to_user || '',
|
|
|
|
'',
|
|
|
|
this.state.room,
|
|
|
|
formattedMessage
|
|
|
|
);
|
|
|
|
} catch (e) {
|
|
|
|
this.client.log.warn({ error: e.message }, 'MRC error');
|
2019-05-18 23:01:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-05-20 22:37:32 +00:00
|
|
|
|
2019-05-22 22:43:41 +00:00
|
|
|
/**
|
|
|
|
* Processes a message that begins with a slash
|
|
|
|
*/
|
2019-05-20 22:37:32 +00:00
|
|
|
processSlashCommand(message) {
|
|
|
|
const cmd = message.split(' ');
|
|
|
|
cmd[0] = cmd[0].substr(1).toLowerCase();
|
|
|
|
|
|
|
|
switch (cmd[0]) {
|
|
|
|
case 'pm':
|
2022-01-29 11:40:13 +00:00
|
|
|
const newmsg = cmd.slice(2).join(' ');
|
|
|
|
this.processOutgoingMessage(newmsg, cmd[1]);
|
2019-05-20 22:37:32 +00:00
|
|
|
break;
|
2019-06-11 02:07:45 +00:00
|
|
|
|
2019-05-25 23:14:36 +00:00
|
|
|
case 'rainbow': {
|
2019-05-20 22:37:32 +00:00
|
|
|
// this is brutal, but i love it
|
2022-06-05 20:04:25 +00:00
|
|
|
const line = message
|
|
|
|
.replace(/^\/rainbow\s/, '')
|
|
|
|
.split(' ')
|
|
|
|
.reduce(function (a, c) {
|
|
|
|
const cc = Math.floor(Math.random() * 31 + 1)
|
|
|
|
.toString()
|
|
|
|
.padStart(2, '0');
|
|
|
|
a += `|${cc}${c}|00 `;
|
|
|
|
return a;
|
|
|
|
}, '')
|
|
|
|
.substr(0, 140)
|
|
|
|
.replace(/\\s\|\d*$/, '');
|
2019-05-20 22:37:32 +00:00
|
|
|
|
2019-05-22 22:43:41 +00:00
|
|
|
this.processOutgoingMessage(line);
|
2019-05-20 22:37:32 +00:00
|
|
|
break;
|
2019-05-25 23:14:36 +00:00
|
|
|
}
|
2019-06-11 02:07:45 +00:00
|
|
|
|
2019-05-20 22:37:32 +00:00
|
|
|
case 'l33t':
|
2022-06-05 20:04:25 +00:00
|
|
|
this.processOutgoingMessage(
|
|
|
|
StringUtil.stylizeString(message.substr(6), 'l33t')
|
|
|
|
);
|
2019-05-20 22:37:32 +00:00
|
|
|
break;
|
|
|
|
|
2019-05-25 23:14:36 +00:00
|
|
|
case 'kewl': {
|
2022-06-05 20:04:25 +00:00
|
|
|
const text_modes = Array('f', 'v', 'V', 'i', 'M');
|
2019-05-20 22:37:32 +00:00
|
|
|
const mode = text_modes[Math.floor(Math.random() * text_modes.length)];
|
2022-06-05 20:04:25 +00:00
|
|
|
this.processOutgoingMessage(
|
|
|
|
StringUtil.stylizeString(message.substr(6), mode)
|
|
|
|
);
|
2019-05-20 22:37:32 +00:00
|
|
|
break;
|
2019-05-25 23:14:36 +00:00
|
|
|
}
|
2019-06-11 02:07:45 +00:00
|
|
|
|
2019-05-20 22:37:32 +00:00
|
|
|
case 'whoon':
|
2019-05-22 22:43:41 +00:00
|
|
|
this.sendServerMessage('WHOON');
|
2019-05-20 22:37:32 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'motd':
|
2019-05-22 22:43:41 +00:00
|
|
|
this.sendServerMessage('MOTD');
|
2019-05-20 22:37:32 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'meetups':
|
2019-05-22 22:43:41 +00:00
|
|
|
this.sendServerMessage('MEETUPS');
|
2019-05-20 22:37:32 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'bbses':
|
2019-05-22 22:43:41 +00:00
|
|
|
this.sendServerMessage('CONNECTED');
|
2019-05-20 22:37:32 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'topic':
|
2022-06-05 20:04:25 +00:00
|
|
|
this.sendServerMessage(
|
|
|
|
`NEWTOPIC:${this.state.room}:${message.substr(7)}`
|
|
|
|
);
|
2019-05-20 22:37:32 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'info':
|
2019-05-22 22:43:41 +00:00
|
|
|
this.sendServerMessage(`INFO ${cmd[1]}`);
|
2019-05-20 22:37:32 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'join':
|
|
|
|
this.joinRoom(cmd[1]);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'chatters':
|
2019-05-22 22:43:41 +00:00
|
|
|
this.sendServerMessage('CHATTERS');
|
2019-05-20 22:37:32 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'rooms':
|
2019-05-22 22:43:41 +00:00
|
|
|
this.sendServerMessage('LIST');
|
2019-05-20 22:37:32 +00:00
|
|
|
break;
|
|
|
|
|
2023-03-31 17:46:07 +00:00
|
|
|
// Allow support for new server commands without change to client
|
|
|
|
case 'quote':
|
|
|
|
this.sendServerMessage(`${message.substr(7)}`);
|
|
|
|
break;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Process known additional server commands directly
|
|
|
|
*/
|
|
|
|
case 'afk':
|
2023-05-11 14:40:53 +00:00
|
|
|
this.sendServerMessage(`AFK ${message.substr(5)}`);
|
2023-03-31 17:46:07 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'roomconfig':
|
2023-05-11 14:40:53 +00:00
|
|
|
this.sendServerMessage(`ROOMCONFIG ${message.substr(12)}`);
|
2023-03-31 17:46:07 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'roompass':
|
2023-05-11 14:40:53 +00:00
|
|
|
this.sendServerMessage(`ROOMPASS ${message.substr(12)}`);
|
2023-03-31 17:46:07 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'status':
|
2023-05-11 14:40:53 +00:00
|
|
|
this.sendServerMessage(`STATUS ${message.substr(8)}`);
|
2023-03-31 17:46:07 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'lastseen':
|
2023-05-11 14:40:53 +00:00
|
|
|
this.sendServerMessage(`LASTSEEN ${message.substr(10)}`);
|
2023-03-31 17:46:07 +00:00
|
|
|
break;
|
2023-05-11 14:40:53 +00:00
|
|
|
|
2023-03-31 17:46:07 +00:00
|
|
|
case 'help':
|
2023-05-11 14:40:53 +00:00
|
|
|
this.sendServerMessage(`HELP ${message.substr(6)}`);
|
2023-03-31 17:46:07 +00:00
|
|
|
break;
|
2023-05-11 14:40:53 +00:00
|
|
|
|
2023-03-31 17:46:07 +00:00
|
|
|
case 'statistics':
|
|
|
|
case 'changelog':
|
|
|
|
case 'listbans':
|
|
|
|
case 'listmutes':
|
|
|
|
case 'routing':
|
2023-05-11 14:40:53 +00:00
|
|
|
this.sendServerMessage(cmd[0].toUpperCase());
|
2023-03-31 17:46:07 +00:00
|
|
|
break;
|
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
case 'quit':
|
2019-06-09 06:09:07 +00:00
|
|
|
return this.prevMenu();
|
|
|
|
|
2019-05-20 22:37:32 +00:00
|
|
|
case 'clear':
|
2019-06-09 06:09:07 +00:00
|
|
|
this.clearMessages();
|
2019-05-20 22:37:32 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case '?':
|
2019-06-08 05:23:06 +00:00
|
|
|
this.addMessageToChatLog(helpText.split(/\n/g));
|
2019-05-20 22:37:32 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// just do something to get the cursor back to the right place ¯\_(ツ)_/¯
|
2019-06-11 02:07:45 +00:00
|
|
|
// :TODO: fix me!
|
2019-05-22 22:43:41 +00:00
|
|
|
this.sendServerMessage('STATS');
|
2019-06-09 06:09:07 +00:00
|
|
|
}
|
2019-05-20 22:37:32 +00:00
|
|
|
|
2019-06-09 06:09:07 +00:00
|
|
|
clearMessages() {
|
2022-06-05 20:04:25 +00:00
|
|
|
const chatLogView = this.viewControllers.mrcChat.getView(
|
|
|
|
MciViewIds.mrcChat.chatLog
|
|
|
|
);
|
2019-06-09 06:09:07 +00:00
|
|
|
chatLogView.setText('');
|
2019-05-22 22:43:41 +00:00
|
|
|
}
|
2019-05-20 22:37:32 +00:00
|
|
|
|
2019-05-22 22:43:41 +00:00
|
|
|
/**
|
|
|
|
* Creates a json object, stringifies it and sends it to the MRC multiplexer
|
|
|
|
*/
|
|
|
|
sendMessageToMultiplexer(to_user, to_site, to_room, body) {
|
2019-05-20 22:37:32 +00:00
|
|
|
const message = {
|
2019-06-08 05:23:06 +00:00
|
|
|
to_user,
|
|
|
|
to_site,
|
|
|
|
to_room,
|
|
|
|
body,
|
2022-06-05 20:04:25 +00:00
|
|
|
from_user: this.state.alias,
|
|
|
|
from_room: this.state.room,
|
2019-05-20 22:37:32 +00:00
|
|
|
};
|
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
if (this.state.socket) {
|
2019-06-08 05:23:06 +00:00
|
|
|
this.state.socket.write(JSON.stringify(message) + '\n');
|
|
|
|
}
|
2019-05-22 22:43:41 +00:00
|
|
|
}
|
2019-05-20 22:37:32 +00:00
|
|
|
|
2019-05-22 22:43:41 +00:00
|
|
|
/**
|
|
|
|
* Sends an MRC 'server' message
|
|
|
|
*/
|
|
|
|
sendServerMessage(command, to_site) {
|
2019-05-20 22:37:32 +00:00
|
|
|
Log.debug({ module: 'mrc', command: command }, 'Sending server command');
|
2019-05-22 22:43:41 +00:00
|
|
|
this.sendMessageToMultiplexer('SERVER', to_site || '', this.state.room, command);
|
|
|
|
}
|
2019-05-17 23:25:35 +00:00
|
|
|
|
2019-05-22 22:43:41 +00:00
|
|
|
/**
|
|
|
|
* Sends a heartbeat to the MRC server
|
|
|
|
*/
|
2019-05-20 22:37:32 +00:00
|
|
|
sendHeartbeat() {
|
2019-05-22 22:43:41 +00:00
|
|
|
this.sendServerMessage('IAMHERE');
|
2019-05-17 23:25:35 +00:00
|
|
|
}
|
2019-05-20 22:37:32 +00:00
|
|
|
|
2019-05-22 22:43:41 +00:00
|
|
|
/**
|
|
|
|
* Joins a room, unsurprisingly
|
|
|
|
*/
|
2019-05-20 22:37:32 +00:00
|
|
|
joinRoom(room) {
|
|
|
|
// room names are displayed with a # but referred to without. confusing.
|
|
|
|
room = room.replace(/^#/, '');
|
|
|
|
this.state.room = room;
|
2019-05-22 22:43:41 +00:00
|
|
|
this.sendServerMessage(`NEWROOM:${this.state.room}:${room}`);
|
|
|
|
this.sendServerMessage('USERLIST');
|
2019-05-20 22:37:32 +00:00
|
|
|
}
|
|
|
|
|
2019-05-22 22:43:41 +00:00
|
|
|
/**
|
|
|
|
* Things that happen when a local user connects to the MRC multiplexer
|
|
|
|
*/
|
2019-05-20 22:37:32 +00:00
|
|
|
clientConnect() {
|
2019-05-22 22:43:41 +00:00
|
|
|
this.sendServerMessage('MOTD');
|
2019-05-20 22:37:32 +00:00
|
|
|
this.joinRoom('lobby');
|
2019-05-22 22:43:41 +00:00
|
|
|
this.sendServerMessage('STATS');
|
2019-05-20 22:37:32 +00:00
|
|
|
this.sendHeartbeat();
|
|
|
|
}
|
|
|
|
};
|