From fa7cf1f265283eef2639186c8a43193e8665e1fd Mon Sep 17 00:00:00 2001 From: Bryan Ashby Date: Wed, 1 Jul 2015 23:41:20 -0600 Subject: [PATCH] * Code cleanup * Placeholder concept of Bunyan child logger per connected client --- core/bbs.js | 7 ++++++- core/client.js | 55 +++----------------------------------------------- 2 files changed, 9 insertions(+), 53 deletions(-) diff --git a/core/bbs.js b/core/bbs.js index 59ef99fd..a24271ec 100644 --- a/core/bbs.js +++ b/core/bbs.js @@ -153,7 +153,7 @@ function startListening() { // Start tracking the client. We'll assign it an ID which is // just the index in our connections array. // - if(typeof client.runtime === 'undefined') { + if(_.isUndefined(client.runtime)) { client.runtime = {}; } @@ -195,6 +195,11 @@ function startListening() { function addNewClient(client) { var id = client.runtime.id = clientConnections.push(client) - 1; + // Create a client specific logger + client.log = logger.log.child( { clientId : id } ); + + // :TODO: if client.log concept is kept, clean this up to use it: + var connInfo = { connectionCount : clientConnections.length, clientId : client.runtime.id, diff --git a/core/client.js b/core/client.js index 1680c27d..33ece5ee 100644 --- a/core/client.js +++ b/core/client.js @@ -44,62 +44,12 @@ var _ = require('lodash'); exports.Client = Client; -//var ANSI_CONTROL_REGEX = /(?:(?:\u001b\[)|\u009b)(?:(?:[0-9]{1,3})?(?:(?:;[0-9]{0,3})*)?[A-M|f-m])|\u001b[A-M]/g; - // :TODO: Move all of the key stuff to it's own module // // Resources & Standards: // * http://www.ansi-bbs.org/ansi-bbs-core-server.html // -var ANSI_KEY_NAME_MAP = { - 0x08 : 'backspace', // BS - 0x09 : 'tab', // - 0x7f : 'del', - 0x1b : 'esc', - 0x0d : 'enter', - 0x19 : 'end of medium', // EM / CTRL-Y -}; - -var ANSI_KEY_CSI_NAME_MAP = { - 0x40 : 'insert', // @ - 0x41 : 'up arrow', // A - 0x42 : 'down arrow', // B - 0x43 : 'right arrow', // C - 0x44 : 'left arrow', // D - - 0x48 : 'home', // H - 0x4b : 'end', // K - - 0x56 : 'page up', // V - 0x55 : 'page down', // U -}; - -var ANSI_F_KEY_NAME_MAP_1 = { - 0x50 : 'F1', - 0x51 : 'F2', - 0x52 : 'F3', - 0x53 : 'F4', - 0x74 : 'F5', -}; - -var ANSI_F_KEY_NAME_MAP_2 = { - // rxvt - 11 : 'F1', - 12 : 'F2', - 13 : 'F3', - 14 : 'F4', - 15 : 'F5', - - // SyncTERM - 17 : 'F6', - 18 : 'F7', - 19 : 'F8', - 20 : 'F9', - 21 : 'F10', - 23 : 'F11', - 24 : 'F12', -}; // :TODO: put this in a common area!!!! function getIntArgArray(array) { @@ -148,7 +98,7 @@ function Client(input, output) { this.output = output; this.term = new term.ClientTerminal(this.output); this.user = new user.User(); - this.currentTheme = { info : { name : 'N/A', description : 'None' } }; + this.currentTheme = { info : { name : 'N/A', description : 'None' } }; // // Peek at incoming |data| and emit events for any special @@ -380,7 +330,8 @@ function Client(input, output) { } if(key || ch) { - Log.trace( { key : key, ch : ch }, 'User keyboard input'); + //Log.trace( { key : key, ch : ch }, 'User keyboard input'); + self.log.trace( { key : key, ch : ch }, 'User keyboard input'); self.emit('key press', ch, key); }