First pass formatting with Prettier
* Added .prettierrc.json * Added .prettierignore * Formatted
This commit is contained in:
488
core/client.js
488
core/client.js
@@ -32,22 +32,22 @@
|
||||
----/snip/----------------------
|
||||
*/
|
||||
// ENiGMA½
|
||||
const term = require('./client_term.js');
|
||||
const ansi = require('./ansi_term.js');
|
||||
const User = require('./user.js');
|
||||
const Config = require('./config.js').get;
|
||||
const MenuStack = require('./menu_stack.js');
|
||||
const ACS = require('./acs.js');
|
||||
const Events = require('./events.js');
|
||||
const UserInterruptQueue = require('./user_interrupt_queue.js');
|
||||
const UserProps = require('./user_property.js');
|
||||
const term = require('./client_term.js');
|
||||
const ansi = require('./ansi_term.js');
|
||||
const User = require('./user.js');
|
||||
const Config = require('./config.js').get;
|
||||
const MenuStack = require('./menu_stack.js');
|
||||
const ACS = require('./acs.js');
|
||||
const Events = require('./events.js');
|
||||
const UserInterruptQueue = require('./user_interrupt_queue.js');
|
||||
const UserProps = require('./user_property.js');
|
||||
|
||||
// deps
|
||||
const stream = require('stream');
|
||||
const assert = require('assert');
|
||||
const _ = require('lodash');
|
||||
const stream = require('stream');
|
||||
const assert = require('assert');
|
||||
const _ = require('lodash');
|
||||
|
||||
exports.Client = Client;
|
||||
exports.Client = Client;
|
||||
|
||||
// :TODO: Move all of the key stuff to it's own module
|
||||
|
||||
@@ -56,86 +56,93 @@ exports.Client = Client;
|
||||
// * http://www.ansi-bbs.org/ansi-bbs-core-server.html
|
||||
//
|
||||
/* eslint-disable no-control-regex */
|
||||
const RE_DSR_RESPONSE_ANYWHERE = /(?:\u001b\[)([0-9;]+)(R)/;
|
||||
const RE_DSR_RESPONSE_ANYWHERE = /(?:\u001b\[)([0-9;]+)(R)/;
|
||||
const RE_DEV_ATTR_RESPONSE_ANYWHERE = /(?:\u001b\[)[=?]([0-9a-zA-Z;]+)(c)/;
|
||||
const RE_META_KEYCODE_ANYWHERE = /(?:\u001b)([a-zA-Z0-9])/;
|
||||
const RE_META_KEYCODE = new RegExp('^' + RE_META_KEYCODE_ANYWHERE.source + '$');
|
||||
const RE_FUNCTION_KEYCODE_ANYWHERE = new RegExp('(?:\u001b+)(O|N|\\[|\\[\\[)(?:' + [
|
||||
'(\\d+)(?:;(\\d+))?([~^$])',
|
||||
'(?:M([@ #!a`])(.)(.))', // mouse stuff
|
||||
'(?:1;)?(\\d+)?([a-zA-Z@])'
|
||||
].join('|') + ')');
|
||||
const RE_META_KEYCODE_ANYWHERE = /(?:\u001b)([a-zA-Z0-9])/;
|
||||
const RE_META_KEYCODE = new RegExp('^' + RE_META_KEYCODE_ANYWHERE.source + '$');
|
||||
const RE_FUNCTION_KEYCODE_ANYWHERE = new RegExp(
|
||||
'(?:\u001b+)(O|N|\\[|\\[\\[)(?:' +
|
||||
[
|
||||
'(\\d+)(?:;(\\d+))?([~^$])',
|
||||
'(?:M([@ #!a`])(.)(.))', // mouse stuff
|
||||
'(?:1;)?(\\d+)?([a-zA-Z@])',
|
||||
].join('|') +
|
||||
')'
|
||||
);
|
||||
/* eslint-enable no-control-regex */
|
||||
|
||||
const RE_FUNCTION_KEYCODE = new RegExp('^' + RE_FUNCTION_KEYCODE_ANYWHERE.source);
|
||||
const RE_ESC_CODE_ANYWHERE = new RegExp( [
|
||||
RE_FUNCTION_KEYCODE_ANYWHERE.source,
|
||||
RE_META_KEYCODE_ANYWHERE.source,
|
||||
RE_DSR_RESPONSE_ANYWHERE.source,
|
||||
RE_DEV_ATTR_RESPONSE_ANYWHERE.source,
|
||||
/\u001b./.source // eslint-disable-line no-control-regex
|
||||
].join('|'));
|
||||
|
||||
const RE_FUNCTION_KEYCODE = new RegExp('^' + RE_FUNCTION_KEYCODE_ANYWHERE.source);
|
||||
const RE_ESC_CODE_ANYWHERE = new RegExp(
|
||||
[
|
||||
RE_FUNCTION_KEYCODE_ANYWHERE.source,
|
||||
RE_META_KEYCODE_ANYWHERE.source,
|
||||
RE_DSR_RESPONSE_ANYWHERE.source,
|
||||
RE_DEV_ATTR_RESPONSE_ANYWHERE.source,
|
||||
/\u001b./.source, // eslint-disable-line no-control-regex
|
||||
].join('|')
|
||||
);
|
||||
|
||||
function Client(/*input, output*/) {
|
||||
stream.call(this);
|
||||
|
||||
const self = this;
|
||||
const self = this;
|
||||
|
||||
this.user = new User();
|
||||
this.currentThemeConfig = { info : { name : 'N/A', description : 'None' } };
|
||||
this.lastActivityTime = Date.now();
|
||||
this.menuStack = new MenuStack(this);
|
||||
this.acs = new ACS( { client : this, user : this.user } );
|
||||
this.interruptQueue = new UserInterruptQueue(this);
|
||||
this.user = new User();
|
||||
this.currentThemeConfig = { info: { name: 'N/A', description: 'None' } };
|
||||
this.lastActivityTime = Date.now();
|
||||
this.menuStack = new MenuStack(this);
|
||||
this.acs = new ACS({ client: this, user: this.user });
|
||||
this.interruptQueue = new UserInterruptQueue(this);
|
||||
|
||||
Object.defineProperty(this, 'currentTheme', {
|
||||
get : () => {
|
||||
get: () => {
|
||||
if (this.currentThemeConfig) {
|
||||
return this.currentThemeConfig.get();
|
||||
} else {
|
||||
return {
|
||||
info : {
|
||||
name : 'N/A',
|
||||
author : 'N/A',
|
||||
description : 'N/A',
|
||||
group : 'N/A',
|
||||
}
|
||||
info: {
|
||||
name: 'N/A',
|
||||
author: 'N/A',
|
||||
description: 'N/A',
|
||||
group: 'N/A',
|
||||
},
|
||||
};
|
||||
}
|
||||
},
|
||||
set : (theme) => {
|
||||
set: theme => {
|
||||
this.currentThemeConfig = theme;
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
Object.defineProperty(this, 'node', {
|
||||
get : function() {
|
||||
get: function () {
|
||||
return self.session.id;
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
Object.defineProperty(this, 'currentMenuModule', {
|
||||
get : function() {
|
||||
get: function () {
|
||||
return self.menuStack.currentModule;
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
this.setTemporaryDirectDataHandler = function(handler) {
|
||||
this.dataPassthrough = true; // let implementations do with what they will here
|
||||
this.setTemporaryDirectDataHandler = function (handler) {
|
||||
this.dataPassthrough = true; // let implementations do with what they will here
|
||||
this.input.removeAllListeners('data');
|
||||
this.input.on('data', handler);
|
||||
};
|
||||
|
||||
this.restoreDataHandler = function() {
|
||||
this.restoreDataHandler = function () {
|
||||
this.dataPassthrough = false;
|
||||
this.input.removeAllListeners('data');
|
||||
this.input.on('data', this.dataHandler);
|
||||
};
|
||||
|
||||
this.themeChangedListener = function( { themeId } ) {
|
||||
if(_.get(self.currentTheme, 'info.themeId') === themeId) {
|
||||
self.currentThemeConfig = require('./theme.js').getAvailableThemes().get(themeId);
|
||||
this.themeChangedListener = function ({ themeId }) {
|
||||
if (_.get(self.currentTheme, 'info.themeId') === themeId) {
|
||||
self.currentThemeConfig = require('./theme.js')
|
||||
.getAvailableThemes()
|
||||
.get(themeId);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -151,14 +158,14 @@ function Client(/*input, output*/) {
|
||||
// * http://www.ansi-bbs.org/ansi-bbs-core-server.html
|
||||
// * Christopher Jeffrey's Blessed library @ https://github.com/chjj/blessed/
|
||||
//
|
||||
this.getTermClient = function(deviceAttr) {
|
||||
this.getTermClient = function (deviceAttr) {
|
||||
let termClient = {
|
||||
'63;1;2' : 'arctel', // http://www.fbl.cz/arctel/download/techman.pdf - Irssi ConnectBot (Android)
|
||||
'50;86;84;88' : 'vtx', // https://github.com/codewar65/VTX_ClientServer/blob/master/vtx.txt
|
||||
'63;1;2': 'arctel', // http://www.fbl.cz/arctel/download/techman.pdf - Irssi ConnectBot (Android)
|
||||
'50;86;84;88': 'vtx', // https://github.com/codewar65/VTX_ClientServer/blob/master/vtx.txt
|
||||
}[deviceAttr];
|
||||
|
||||
if(!termClient) {
|
||||
if(_.startsWith(deviceAttr, '67;84;101;114;109')) {
|
||||
if (!termClient) {
|
||||
if (_.startsWith(deviceAttr, '67;84;101;114;109')) {
|
||||
//
|
||||
// See https://github.com/protomouse/synchronet/blob/master/src/conio/cterm.txt
|
||||
//
|
||||
@@ -173,176 +180,178 @@ function Client(/*input, output*/) {
|
||||
};
|
||||
|
||||
/* eslint-disable no-control-regex */
|
||||
this.isMouseInput = function(data) {
|
||||
return /\x1b\[M/.test(data) ||
|
||||
this.isMouseInput = function (data) {
|
||||
return (
|
||||
/\x1b\[M/.test(data) ||
|
||||
/\u001b\[M([\x00\u0020-\uffff]{3})/.test(data) ||
|
||||
/\u001b\[(\d+;\d+;\d+)M/.test(data) ||
|
||||
/\u001b\[<(\d+;\d+;\d+)([mM])/.test(data) ||
|
||||
/\u001b\[<(\d+;\d+;\d+;\d+)&w/.test(data) ||
|
||||
/\u001b\[24([0135])~\[(\d+),(\d+)\]\r/.test(data) ||
|
||||
/\u001b\[(O|I)/.test(data);
|
||||
/\u001b\[(O|I)/.test(data)
|
||||
);
|
||||
};
|
||||
/* eslint-enable no-control-regex */
|
||||
|
||||
this.getKeyComponentsFromCode = function(code) {
|
||||
this.getKeyComponentsFromCode = function (code) {
|
||||
return {
|
||||
// xterm/gnome
|
||||
'OP' : { name : 'f1' },
|
||||
'OQ' : { name : 'f2' },
|
||||
'OR' : { name : 'f3' },
|
||||
'OS' : { name : 'f4' },
|
||||
OP: { name: 'f1' },
|
||||
OQ: { name: 'f2' },
|
||||
OR: { name: 'f3' },
|
||||
OS: { name: 'f4' },
|
||||
|
||||
'OA' : { name : 'up arrow' },
|
||||
'OB' : { name : 'down arrow' },
|
||||
'OC' : { name : 'right arrow' },
|
||||
'OD' : { name : 'left arrow' },
|
||||
'OE' : { name : 'clear' },
|
||||
'OF' : { name : 'end' },
|
||||
'OH' : { name : 'home' },
|
||||
OA: { name: 'up arrow' },
|
||||
OB: { name: 'down arrow' },
|
||||
OC: { name: 'right arrow' },
|
||||
OD: { name: 'left arrow' },
|
||||
OE: { name: 'clear' },
|
||||
OF: { name: 'end' },
|
||||
OH: { name: 'home' },
|
||||
|
||||
// xterm/rxvt
|
||||
'[11~' : { name : 'f1' },
|
||||
'[12~' : { name : 'f2' },
|
||||
'[13~' : { name : 'f3' },
|
||||
'[14~' : { name : 'f4' },
|
||||
'[11~': { name: 'f1' },
|
||||
'[12~': { name: 'f2' },
|
||||
'[13~': { name: 'f3' },
|
||||
'[14~': { name: 'f4' },
|
||||
|
||||
'[1~' : { name : 'home' },
|
||||
'[2~' : { name : 'insert' },
|
||||
'[3~' : { name : 'delete' },
|
||||
'[4~' : { name : 'end' },
|
||||
'[5~' : { name : 'page up' },
|
||||
'[6~' : { name : 'page down' },
|
||||
'[1~': { name: 'home' },
|
||||
'[2~': { name: 'insert' },
|
||||
'[3~': { name: 'delete' },
|
||||
'[4~': { name: 'end' },
|
||||
'[5~': { name: 'page up' },
|
||||
'[6~': { name: 'page down' },
|
||||
|
||||
// Cygwin & libuv
|
||||
'[[A' : { name : 'f1' },
|
||||
'[[B' : { name : 'f2' },
|
||||
'[[C' : { name : 'f3' },
|
||||
'[[D' : { name : 'f4' },
|
||||
'[[E' : { name : 'f5' },
|
||||
'[[A': { name: 'f1' },
|
||||
'[[B': { name: 'f2' },
|
||||
'[[C': { name: 'f3' },
|
||||
'[[D': { name: 'f4' },
|
||||
'[[E': { name: 'f5' },
|
||||
|
||||
// Common impls
|
||||
'[15~' : { name : 'f5' },
|
||||
'[17~' : { name : 'f6' },
|
||||
'[18~' : { name : 'f7' },
|
||||
'[19~' : { name : 'f8' },
|
||||
'[20~' : { name : 'f9' },
|
||||
'[21~' : { name : 'f10' },
|
||||
'[23~' : { name : 'f11' },
|
||||
'[24~' : { name : 'f12' },
|
||||
'[15~': { name: 'f5' },
|
||||
'[17~': { name: 'f6' },
|
||||
'[18~': { name: 'f7' },
|
||||
'[19~': { name: 'f8' },
|
||||
'[20~': { name: 'f9' },
|
||||
'[21~': { name: 'f10' },
|
||||
'[23~': { name: 'f11' },
|
||||
'[24~': { name: 'f12' },
|
||||
|
||||
// xterm
|
||||
'[A' : { name : 'up arrow' },
|
||||
'[B' : { name : 'down arrow' },
|
||||
'[C' : { name : 'right arrow' },
|
||||
'[D' : { name : 'left arrow' },
|
||||
'[E' : { name : 'clear' },
|
||||
'[F' : { name : 'end' },
|
||||
'[H' : { name : 'home' },
|
||||
'[A': { name: 'up arrow' },
|
||||
'[B': { name: 'down arrow' },
|
||||
'[C': { name: 'right arrow' },
|
||||
'[D': { name: 'left arrow' },
|
||||
'[E': { name: 'clear' },
|
||||
'[F': { name: 'end' },
|
||||
'[H': { name: 'home' },
|
||||
|
||||
// PuTTY
|
||||
'[[5~' : { name : 'page up' },
|
||||
'[[6~' : { name : 'page down' },
|
||||
'[[5~': { name: 'page up' },
|
||||
'[[6~': { name: 'page down' },
|
||||
|
||||
// rvxt
|
||||
'[7~' : { name : 'home' },
|
||||
'[8~' : { name : 'end' },
|
||||
'[7~': { name: 'home' },
|
||||
'[8~': { name: 'end' },
|
||||
|
||||
// rxvt with modifiers
|
||||
'[a' : { name : 'up arrow', shift : true },
|
||||
'[b' : { name : 'down arrow', shift : true },
|
||||
'[c' : { name : 'right arrow', shift : true },
|
||||
'[d' : { name : 'left arrow', shift : true },
|
||||
'[e' : { name : 'clear', shift : true },
|
||||
'[a': { name: 'up arrow', shift: true },
|
||||
'[b': { name: 'down arrow', shift: true },
|
||||
'[c': { name: 'right arrow', shift: true },
|
||||
'[d': { name: 'left arrow', shift: true },
|
||||
'[e': { name: 'clear', shift: true },
|
||||
|
||||
'[2$' : { name : 'insert', shift : true },
|
||||
'[3$' : { name : 'delete', shift : true },
|
||||
'[5$' : { name : 'page up', shift : true },
|
||||
'[6$' : { name : 'page down', shift : true },
|
||||
'[7$' : { name : 'home', shift : true },
|
||||
'[8$' : { name : 'end', shift : true },
|
||||
'[2$': { name: 'insert', shift: true },
|
||||
'[3$': { name: 'delete', shift: true },
|
||||
'[5$': { name: 'page up', shift: true },
|
||||
'[6$': { name: 'page down', shift: true },
|
||||
'[7$': { name: 'home', shift: true },
|
||||
'[8$': { name: 'end', shift: true },
|
||||
|
||||
'Oa' : { name : 'up arrow', ctrl : true },
|
||||
'Ob' : { name : 'down arrow', ctrl : true },
|
||||
'Oc' : { name : 'right arrow', ctrl : true },
|
||||
'Od' : { name : 'left arrow', ctrl : true },
|
||||
'Oe' : { name : 'clear', ctrl : true },
|
||||
Oa: { name: 'up arrow', ctrl: true },
|
||||
Ob: { name: 'down arrow', ctrl: true },
|
||||
Oc: { name: 'right arrow', ctrl: true },
|
||||
Od: { name: 'left arrow', ctrl: true },
|
||||
Oe: { name: 'clear', ctrl: true },
|
||||
|
||||
'[2^' : { name : 'insert', ctrl : true },
|
||||
'[3^' : { name : 'delete', ctrl : true },
|
||||
'[5^' : { name : 'page up', ctrl : true },
|
||||
'[6^' : { name : 'page down', ctrl : true },
|
||||
'[7^' : { name : 'home', ctrl : true },
|
||||
'[8^' : { name : 'end', ctrl : true },
|
||||
'[2^': { name: 'insert', ctrl: true },
|
||||
'[3^': { name: 'delete', ctrl: true },
|
||||
'[5^': { name: 'page up', ctrl: true },
|
||||
'[6^': { name: 'page down', ctrl: true },
|
||||
'[7^': { name: 'home', ctrl: true },
|
||||
'[8^': { name: 'end', ctrl: true },
|
||||
|
||||
// SyncTERM / EtherTerm
|
||||
'[K' : { name : 'end' },
|
||||
'[@' : { name : 'insert' },
|
||||
'[V' : { name : 'page up' },
|
||||
'[U' : { name : 'page down' },
|
||||
'[K': { name: 'end' },
|
||||
'[@': { name: 'insert' },
|
||||
'[V': { name: 'page up' },
|
||||
'[U': { name: 'page down' },
|
||||
|
||||
// other
|
||||
'[Z' : { name : 'tab', shift : true },
|
||||
'[Z': { name: 'tab', shift: true },
|
||||
}[code];
|
||||
};
|
||||
|
||||
this.on('data', function clientData(data) {
|
||||
// create a uniform format that can be parsed below
|
||||
if(data[0] > 127 && undefined === data[1]) {
|
||||
if (data[0] > 127 && undefined === data[1]) {
|
||||
data[0] -= 128;
|
||||
data = '\u001b' + data.toString('utf-8');
|
||||
} else {
|
||||
data = data.toString('utf-8');
|
||||
}
|
||||
|
||||
if(self.isMouseInput(data)) {
|
||||
if (self.isMouseInput(data)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var buf = [];
|
||||
var m;
|
||||
while((m = RE_ESC_CODE_ANYWHERE.exec(data))) {
|
||||
while ((m = RE_ESC_CODE_ANYWHERE.exec(data))) {
|
||||
buf = buf.concat(data.slice(0, m.index).split(''));
|
||||
buf.push(m[0]);
|
||||
data = data.slice(m.index + m[0].length);
|
||||
}
|
||||
|
||||
buf = buf.concat(data.split('')); // remainder
|
||||
buf = buf.concat(data.split('')); // remainder
|
||||
|
||||
buf.forEach(function bufPart(s) {
|
||||
var key = {
|
||||
seq : s,
|
||||
name : undefined,
|
||||
ctrl : false,
|
||||
meta : false,
|
||||
shift : false,
|
||||
seq: s,
|
||||
name: undefined,
|
||||
ctrl: false,
|
||||
meta: false,
|
||||
shift: false,
|
||||
};
|
||||
|
||||
var parts;
|
||||
|
||||
if((parts = RE_DSR_RESPONSE_ANYWHERE.exec(s))) {
|
||||
if('R' === parts[2]) {
|
||||
const cprArgs = parts[1].split(';').map(v => (parseInt(v, 10) || 0) );
|
||||
if(2 === cprArgs.length) {
|
||||
if(self.cprOffset) {
|
||||
if ((parts = RE_DSR_RESPONSE_ANYWHERE.exec(s))) {
|
||||
if ('R' === parts[2]) {
|
||||
const cprArgs = parts[1].split(';').map(v => parseInt(v, 10) || 0);
|
||||
if (2 === cprArgs.length) {
|
||||
if (self.cprOffset) {
|
||||
cprArgs[0] = cprArgs[0] + self.cprOffset;
|
||||
cprArgs[1] = cprArgs[1] + self.cprOffset;
|
||||
}
|
||||
self.emit('cursor position report', cprArgs);
|
||||
}
|
||||
}
|
||||
} else if((parts = RE_DEV_ATTR_RESPONSE_ANYWHERE.exec(s))) {
|
||||
} else if ((parts = RE_DEV_ATTR_RESPONSE_ANYWHERE.exec(s))) {
|
||||
assert('c' === parts[2]);
|
||||
var termClient = self.getTermClient(parts[1]);
|
||||
if(termClient) {
|
||||
if (termClient) {
|
||||
self.term.termClient = termClient;
|
||||
}
|
||||
} else if('\r' === s) {
|
||||
} else if ('\r' === s) {
|
||||
key.name = 'return';
|
||||
} else if('\n' === s) {
|
||||
} else if ('\n' === s) {
|
||||
key.name = 'line feed';
|
||||
} else if('\t' === s) {
|
||||
} else if ('\t' === s) {
|
||||
key.name = 'tab';
|
||||
} else if('\x7f' === s) {
|
||||
} else if ('\x7f' === s) {
|
||||
//
|
||||
// Backspace vs delete is a crazy thing, especially in *nix.
|
||||
// - ANSI-BBS uses 0x7f for DEL
|
||||
@@ -351,61 +360,63 @@ function Client(/*input, output*/) {
|
||||
// See http://www.hypexr.org/linux_ruboff.php
|
||||
// And a great discussion @ https://lists.debian.org/debian-i18n/1998/04/msg00015.html
|
||||
//
|
||||
if(self.term.isNixTerm()) {
|
||||
key.name = 'backspace';
|
||||
if (self.term.isNixTerm()) {
|
||||
key.name = 'backspace';
|
||||
} else {
|
||||
key.name = 'delete';
|
||||
key.name = 'delete';
|
||||
}
|
||||
} else if ('\b' === s || '\x1b\x7f' === s || '\x1b\b' === s) {
|
||||
// backspace, CTRL-H
|
||||
key.name = 'backspace';
|
||||
key.meta = ('\x1b' === s.charAt(0));
|
||||
} else if('\x1b' === s || '\x1b\x1b' === s) {
|
||||
key.name = 'escape';
|
||||
key.meta = (2 === s.length);
|
||||
key.name = 'backspace';
|
||||
key.meta = '\x1b' === s.charAt(0);
|
||||
} else if ('\x1b' === s || '\x1b\x1b' === s) {
|
||||
key.name = 'escape';
|
||||
key.meta = 2 === s.length;
|
||||
} else if (' ' === s || '\x1b ' === s) {
|
||||
// rather annoying that space can come in other than just " "
|
||||
key.name = 'space';
|
||||
key.meta = (2 === s.length);
|
||||
} else if(1 === s.length && s <= '\x1a') {
|
||||
key.name = 'space';
|
||||
key.meta = 2 === s.length;
|
||||
} else if (1 === s.length && s <= '\x1a') {
|
||||
// CTRL-<letter>
|
||||
key.name = String.fromCharCode(s.charCodeAt(0) + 'a'.charCodeAt(0) - 1);
|
||||
key.ctrl = true;
|
||||
} else if(1 === s.length && s >= 'a' && s <= 'z') {
|
||||
key.name = String.fromCharCode(s.charCodeAt(0) + 'a'.charCodeAt(0) - 1);
|
||||
key.ctrl = true;
|
||||
} else if (1 === s.length && s >= 'a' && s <= 'z') {
|
||||
// normal, lowercased letter
|
||||
key.name = s;
|
||||
} else if(1 === s.length && s >= 'A' && s <= 'Z') {
|
||||
key.name = s.toLowerCase();
|
||||
key.shift = true;
|
||||
key.name = s;
|
||||
} else if (1 === s.length && s >= 'A' && s <= 'Z') {
|
||||
key.name = s.toLowerCase();
|
||||
key.shift = true;
|
||||
} else if ((parts = RE_META_KEYCODE.exec(s))) {
|
||||
// meta with character key
|
||||
key.name = parts[1].toLowerCase();
|
||||
key.meta = true;
|
||||
key.shift = /^[A-Z]$/.test(parts[1]);
|
||||
} else if((parts = RE_FUNCTION_KEYCODE.exec(s))) {
|
||||
key.name = parts[1].toLowerCase();
|
||||
key.meta = true;
|
||||
key.shift = /^[A-Z]$/.test(parts[1]);
|
||||
} else if ((parts = RE_FUNCTION_KEYCODE.exec(s))) {
|
||||
var code =
|
||||
(parts[1] || '') + (parts[2] || '') +
|
||||
(parts[4] || '') + (parts[9] || '');
|
||||
(parts[1] || '') +
|
||||
(parts[2] || '') +
|
||||
(parts[4] || '') +
|
||||
(parts[9] || '');
|
||||
|
||||
var modifier = (parts[3] || parts[8] || 1) - 1;
|
||||
|
||||
key.ctrl = !!(modifier & 4);
|
||||
key.meta = !!(modifier & 10);
|
||||
key.shift = !!(modifier & 1);
|
||||
key.code = code;
|
||||
key.ctrl = !!(modifier & 4);
|
||||
key.meta = !!(modifier & 10);
|
||||
key.shift = !!(modifier & 1);
|
||||
key.code = code;
|
||||
|
||||
_.assign(key, self.getKeyComponentsFromCode(code));
|
||||
}
|
||||
|
||||
var ch;
|
||||
if(1 === s.length) {
|
||||
if (1 === s.length) {
|
||||
ch = s;
|
||||
} else if('space' === key.name) {
|
||||
} else if ('space' === key.name) {
|
||||
// stupid hack to always get space as a regular char
|
||||
ch = ' ';
|
||||
}
|
||||
|
||||
if(_.isUndefined(key.name)) {
|
||||
if (_.isUndefined(key.name)) {
|
||||
key = undefined;
|
||||
} else {
|
||||
//
|
||||
@@ -418,14 +429,14 @@ function Client(/*input, output*/) {
|
||||
key.name;
|
||||
}
|
||||
|
||||
if(key || ch) {
|
||||
if(Config().logging.traceUserKeyboardInput) {
|
||||
self.log.trace( { key : key, ch : escape(ch) }, 'User keyboard input'); // jshint ignore:line
|
||||
if (key || ch) {
|
||||
if (Config().logging.traceUserKeyboardInput) {
|
||||
self.log.trace({ key: key, ch: escape(ch) }, 'User keyboard input'); // jshint ignore:line
|
||||
}
|
||||
|
||||
self.lastActivityTime = Date.now();
|
||||
|
||||
if(!self.ignoreInput) {
|
||||
if (!self.ignoreInput) {
|
||||
self.emit('key press', ch, key);
|
||||
}
|
||||
}
|
||||
@@ -435,23 +446,23 @@ function Client(/*input, output*/) {
|
||||
|
||||
require('util').inherits(Client, stream);
|
||||
|
||||
Client.prototype.setInputOutput = function(input, output) {
|
||||
this.input = input;
|
||||
Client.prototype.setInputOutput = function (input, output) {
|
||||
this.input = input;
|
||||
this.output = output;
|
||||
|
||||
this.term = new term.ClientTerminal(this.output);
|
||||
this.term = new term.ClientTerminal(this.output);
|
||||
};
|
||||
|
||||
Client.prototype.setTermType = function(termType) {
|
||||
this.term.env.TERM = termType;
|
||||
this.term.termType = termType;
|
||||
Client.prototype.setTermType = function (termType) {
|
||||
this.term.env.TERM = termType;
|
||||
this.term.termType = termType;
|
||||
|
||||
this.log.debug( { termType : termType }, 'Set terminal type');
|
||||
this.log.debug({ termType: termType }, 'Set terminal type');
|
||||
};
|
||||
|
||||
Client.prototype.startIdleMonitor = function() {
|
||||
Client.prototype.startIdleMonitor = function () {
|
||||
// clear existing, if any
|
||||
if(this.idleCheck) {
|
||||
if (this.idleCheck) {
|
||||
this.stopIdleMonitor();
|
||||
}
|
||||
|
||||
@@ -462,11 +473,11 @@ Client.prototype.startIdleMonitor = function() {
|
||||
// We also update minutes spent online the system here,
|
||||
// if we have a authenticated user.
|
||||
//
|
||||
this.idleCheck = setInterval( () => {
|
||||
this.idleCheck = setInterval(() => {
|
||||
const nowMs = Date.now();
|
||||
|
||||
let idleLogoutSeconds;
|
||||
if(this.user.isAuthenticated()) {
|
||||
if (this.user.isAuthenticated()) {
|
||||
idleLogoutSeconds = Config().users.idleLogoutSeconds;
|
||||
|
||||
//
|
||||
@@ -474,17 +485,17 @@ Client.prototype.startIdleMonitor = function() {
|
||||
// every user, but want at least some updates for various things
|
||||
// such as achievements. Send off every 5m.
|
||||
//
|
||||
const minOnline = this.user.incrementProperty(UserProps.MinutesOnlineTotalCount, 1);
|
||||
if(0 === (minOnline % 5)) {
|
||||
Events.emit(
|
||||
Events.getSystemEvents().UserStatIncrement,
|
||||
{
|
||||
user : this.user,
|
||||
statName : UserProps.MinutesOnlineTotalCount,
|
||||
statIncrementBy : 1,
|
||||
statValue : minOnline
|
||||
}
|
||||
);
|
||||
const minOnline = this.user.incrementProperty(
|
||||
UserProps.MinutesOnlineTotalCount,
|
||||
1
|
||||
);
|
||||
if (0 === minOnline % 5) {
|
||||
Events.emit(Events.getSystemEvents().UserStatIncrement, {
|
||||
user: this.user,
|
||||
statName: UserProps.MinutesOnlineTotalCount,
|
||||
statIncrementBy: 1,
|
||||
statValue: minOnline,
|
||||
});
|
||||
}
|
||||
} else {
|
||||
idleLogoutSeconds = Config().users.preAuthIdleLogoutSeconds;
|
||||
@@ -493,46 +504,52 @@ Client.prototype.startIdleMonitor = function() {
|
||||
// use override value if set
|
||||
idleLogoutSeconds = this.idleLogoutSecondsOverride || idleLogoutSeconds;
|
||||
|
||||
if(idleLogoutSeconds > 0 && (nowMs - this.lastActivityTime >= (idleLogoutSeconds * 1000))) {
|
||||
if (
|
||||
idleLogoutSeconds > 0 &&
|
||||
nowMs - this.lastActivityTime >= idleLogoutSeconds * 1000
|
||||
) {
|
||||
this.emit('idle timeout');
|
||||
}
|
||||
}, 1000 * 60);
|
||||
};
|
||||
|
||||
Client.prototype.stopIdleMonitor = function() {
|
||||
if(this.idleCheck) {
|
||||
Client.prototype.stopIdleMonitor = function () {
|
||||
if (this.idleCheck) {
|
||||
clearInterval(this.idleCheck);
|
||||
delete this.idleCheck;
|
||||
}
|
||||
};
|
||||
|
||||
Client.prototype.explicitActivityTimeUpdate = function() {
|
||||
Client.prototype.explicitActivityTimeUpdate = function () {
|
||||
this.lastActivityTime = Date.now();
|
||||
};
|
||||
|
||||
Client.prototype.overrideIdleLogoutSeconds = function(seconds) {
|
||||
Client.prototype.overrideIdleLogoutSeconds = function (seconds) {
|
||||
this.idleLogoutSecondsOverride = seconds;
|
||||
};
|
||||
|
||||
Client.prototype.restoreIdleLogoutSeconds = function() {
|
||||
Client.prototype.restoreIdleLogoutSeconds = function () {
|
||||
delete this.idleLogoutSecondsOverride;
|
||||
};
|
||||
|
||||
Client.prototype.end = function () {
|
||||
if(this.term) {
|
||||
if (this.term) {
|
||||
this.term.disconnect();
|
||||
}
|
||||
|
||||
Events.removeListener(Events.getSystemEvents().ThemeChanged, this.themeChangedListener);
|
||||
Events.removeListener(
|
||||
Events.getSystemEvents().ThemeChanged,
|
||||
this.themeChangedListener
|
||||
);
|
||||
|
||||
const currentModule = this.menuStack.getCurrentModule;
|
||||
|
||||
if(currentModule) {
|
||||
if (currentModule) {
|
||||
currentModule.leave();
|
||||
}
|
||||
|
||||
// persist time online for authenticated users
|
||||
if(this.user.isAuthenticated()) {
|
||||
if (this.user.isAuthenticated()) {
|
||||
this.user.persistProperty(
|
||||
UserProps.MinutesOnlineTotalCount,
|
||||
this.user.getProperty(UserProps.MinutesOnlineTotalCount)
|
||||
@@ -545,13 +562,13 @@ Client.prototype.end = function () {
|
||||
//
|
||||
// We can end up calling 'end' before TTY/etc. is established, e.g. with SSH
|
||||
//
|
||||
if(_.isFunction(this.disconnect)) {
|
||||
if (_.isFunction(this.disconnect)) {
|
||||
return this.disconnect();
|
||||
} else {
|
||||
// legacy fallback
|
||||
return this.output.end.apply(this.output, arguments);
|
||||
}
|
||||
} catch(e) {
|
||||
} catch (e) {
|
||||
// ie TypeError
|
||||
}
|
||||
};
|
||||
@@ -564,15 +581,15 @@ Client.prototype.destroySoon = function () {
|
||||
return this.output.destroySoon.apply(this.output, arguments);
|
||||
};
|
||||
|
||||
Client.prototype.waitForKeyPress = function(cb) {
|
||||
Client.prototype.waitForKeyPress = function (cb) {
|
||||
this.once('key press', function kp(ch, key) {
|
||||
cb(ch, key);
|
||||
});
|
||||
};
|
||||
|
||||
Client.prototype.isLocal = function() {
|
||||
Client.prototype.isLocal = function () {
|
||||
// :TODO: Handle ipv6 better
|
||||
return [ '127.0.0.1', '::ffff:127.0.0.1' ].includes(this.remoteAddress);
|
||||
return ['127.0.0.1', '::ffff:127.0.0.1'].includes(this.remoteAddress);
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
@@ -580,7 +597,7 @@ Client.prototype.isLocal = function() {
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// :TODO: getDefaultHandler(name) -- handlers in default_handlers.js or something
|
||||
Client.prototype.defaultHandlerMissingMod = function() {
|
||||
Client.prototype.defaultHandlerMissingMod = function () {
|
||||
var self = this;
|
||||
|
||||
function handler(err) {
|
||||
@@ -591,7 +608,6 @@ Client.prototype.defaultHandlerMissingMod = function() {
|
||||
self.term.write('This has been logged for your SysOp to review.\n');
|
||||
self.term.write('\nGoodbye!\n');
|
||||
|
||||
|
||||
//self.term.write(err);
|
||||
|
||||
//if(miscUtil.isDevelopment() && err.stack) {
|
||||
@@ -604,18 +620,18 @@ Client.prototype.defaultHandlerMissingMod = function() {
|
||||
return handler;
|
||||
};
|
||||
|
||||
Client.prototype.terminalSupports = function(query) {
|
||||
Client.prototype.terminalSupports = function (query) {
|
||||
const termClient = this.term.termClient;
|
||||
|
||||
switch(query) {
|
||||
case 'vtx_audio' :
|
||||
switch (query) {
|
||||
case 'vtx_audio':
|
||||
// https://github.com/codewar65/VTX_ClientServer/blob/master/vtx.txt
|
||||
return 'vtx' === termClient;
|
||||
|
||||
case 'vtx_hyperlink' :
|
||||
case 'vtx_hyperlink':
|
||||
return 'vtx' === termClient;
|
||||
|
||||
default :
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user