Added ERC Module

This commit is contained in:
Andrew Pamment 2016-06-27 17:29:17 +10:00
parent b6cada6f3c
commit be6af161ec
4 changed files with 318 additions and 58 deletions

View File

@ -114,6 +114,11 @@ function MultiLineEditTextView(options) {
this.topVisibleIndex = 0;
this.mode = options.mode || 'edit'; // edit | preview | read-only
if (this.mode == 'edit') {
this.autoScroll = options.autoScroll || 'true';
} else {
this.autoScroll = options.autoScroll || 'false';
}
//
// cursorPos represents zero-based row, col positions
// within the editor itself
@ -1007,9 +1012,9 @@ MultiLineEditTextView.prototype.setText = function(text) {
MultiLineEditTextView.prototype.addText = function(text) {
this.insertRawText(text);
if(this.isEditMode()) {
if(this.autoScroll) {
this.cursorEndOfDocument();
} else if(this.isPreviewMode()) {
} else {
this.cursorStartOfDocument();
}
};
@ -1068,6 +1073,22 @@ MultiLineEditTextView.prototype.onKeyPress = function(ch, key) {
}
};
MultiLineEditTextView.prototype.scrollUp = function() {
this.scrollDocumentUp();
}
MultiLineEditTextView.prototype.scrollDown = function() {
this.scrollDocumentDown();
}
MultiLineEditTextView.prototype.deleteLine = function(line) {
this.textLines.splice(line, 1);
}
MultiLineEditTextView.prototype.getLineCount = function() {
return this.textLines.length;
}
MultiLineEditTextView.prototype.getTextEditMode = function() {
return this.overtypeMode ? 'overtype' : 'insert';
};
@ -1082,4 +1103,3 @@ MultiLineEditTextView.prototype.getEditPosition = function() {
below : this.getRemainingLinesBelowRow(),
};
};

BIN
mods/art/erc.ans Normal file

Binary file not shown.

184
mods/erc_client.js Normal file
View File

@ -0,0 +1,184 @@
/* jslint node: true */
'use strict';
var MenuModule = require('../core/menu_module.js').MenuModule;
const async = require('async');
const _ = require('lodash');
const net = require('net');
const packageJson = require('../package.json');
/*
Expected configuration block:
ercClient: {
art: erc
module: erc_client
config: {
host: 192.168.1.171
port: 5001
bbsTag: SUPER
}
form: {
0: {
mci: {
MT1: {
width: 79
height: 21
mode: preview
autoScroll: true
}
ET3: {
autoScale: false
width: 77
argName: chattxt
focus: true
submit: true
}
}
submit: {
*: [
{
value: { chattxt: null }
action: @method:processInput
}
]
}
actionKeys: [
{
keys: [ "tab" ]
}
{
keys: [ "up arrow" ]
action: @method:scrollDown
}
{
keys: [ "down arrow" ]
action: @method:scrollUp
}
]
}
}
}
*/
exports.getModule = ErcClientModule;
exports.moduleInfo = {
name : 'ENiGMA Relay Chat Client',
desc : 'Chat with other ENiGMA BBSes',
author : 'Andrew Pamment',
};
var MciViewIds = {
chatDisplay : 1,
inputArea : 3,
};
function ErcClientModule(options) {
MenuModule.call(this, options);
var self = this;
this.config = options.menuConfig.config;
this.chatConnection = null;
this.finishedLoading = function() {
async.series(
[
function validateConfig(callback) {
if(_.isString(self.config.host) &&
_.isNumber(self.config.port) &&
_.isString(self.config.bbsTag))
{
callback(null);
} else {
callback(new Error('Configuration is missing required option(s)'));
}
},
function connectToServer(callback) {
const connectOpts = {
port : self.config.port,
host : self.config.host,
};
var chatMessageView = self.viewControllers.menu.getView(MciViewIds.chatDisplay);
chatMessageView.setText("Connecting to server...");
chatMessageView.redraw();
self.viewControllers.menu.switchFocus(MciViewIds.inputArea);
self.chatConnection = net.createConnection(connectOpts.port, connectOpts.host);
self.chatConnection.on('data', data => {
var chatMessageView = self.viewControllers.menu.getView(MciViewIds.chatDisplay);
if (data.toString().substring(0, 12) == "ERCHANDSHAKE") {
self.chatConnection.write("ERCMAGIC|" + self.config.bbsTag + "|" + self.client.user.username + "\r\n");
} else {
chatMessageView.addText(data.toString());
if (chatMessageView.getLineCount() > 30) {
chatMessageView.deleteLine(0);
chatMessageView.scrollDown();
}
chatMessageView.redraw();
self.viewControllers.menu.switchFocus(MciViewIds.inputArea);
}
});
self.chatConnection.once('end', () => {
return callback(null);
});
self.chatConnection.once('error', err => {
self.client.log.info(`Telnet bridge connection error: ${err.message}`);
});
}
],
err => {
if(err) {
self.client.log.warn( { error : err.message }, 'Telnet connection error');
}
self.prevMenu();
}
);
};
this.menuMethods = {
processInput : function(data, cb) {
let chatInput = self.viewControllers.menu.getView(MciViewIds.inputArea);
let chatData = chatInput.getData();
if (chatData[0] === '/') {
if (chatData[1] === 'q' || chatInput[1] === 'Q') {
self.chatConnection.end();
}
} else {
self.chatConnection.write(chatData + "\r\n");
chatInput.clearText();
}
},
scrollUp : function(data, cb) {
let chatInput = self.viewControllers.menu.getView(MciViewIds.inputArea);
let chatMessageView = self.viewControllers.menu.getView(MciViewIds.chatDisplay);
chatMessageView.scrollUp();
chatMessageView.redraw();
chatInput.setFocus(true);
},
scrollDown : function(data, cb) {
let chatInput = self.viewControllers.menu.getView(MciViewIds.inputArea);
let chatMessageView = self.viewControllers.menu.getView(MciViewIds.chatDisplay);
chatMessageView.scrollDown();
chatMessageView.redraw();
chatInput.setFocus(true);
}
};
}
require('util').inherits(ErcClientModule, MenuModule);
ErcClientModule.prototype.mciReady = function(mciData, cb) {
this.standardMCIReadyHandler(mciData, cb);
};

View File

@ -644,6 +644,10 @@
value: { command: "K" }
action: @menu:mainMenuFeedbackToSysOp
}
{
value: { command: "CHAT"}
action: @menu:ercClient
}
{
value: 1
action: @menu:mainMenu
@ -907,6 +911,58 @@
}
}
ercClient: {
art: erc
module: erc_client
config: {
host: 192.168.1.171
port: 5001
bbsTag: SUPER
}
form: {
0: {
mci: {
MT1: {
width: 79
height: 21
mode: preview
autoScroll: true
}
ET3: {
autoScale: false
width: 77
argName: chattxt
focus: true
submit: true
}
}
submit: {
*: [
{
value: { chattxt: null }
action: @method:processInput
}
]
}
actionKeys: [
{
keys: [ "tab" ]
}
{
keys: [ "up arrow" ]
action: @method:scrollDown
}
{
keys: [ "down arrow" ]
action: @method:scrollUp
}
]
}
}
}
///////////////////////////////////////////////////////////////////////
// Doors Menu
///////////////////////////////////////////////////////////////////////