Door utility and door tracking

* Require >= 45s of time in a door before it counts as "run"
This commit is contained in:
Bryan Ashby 2019-01-18 22:09:10 -07:00
parent 4e1997302e
commit 7776391184
5 changed files with 74 additions and 48 deletions

View File

@ -4,16 +4,16 @@
const { MenuModule } = require('./menu_module.js'); const { MenuModule } = require('./menu_module.js');
const { resetScreen } = require('./ansi_term.js'); const { resetScreen } = require('./ansi_term.js');
const { Errors } = require('./enig_error.js'); const { Errors } = require('./enig_error.js');
const Events = require('./events.js'); const {
const StatLog = require('./stat_log.js'); trackDoorRunBegin,
const UserProps = require('./user_property.js'); trackDoorRunEnd
} = require('./door_util.js');
// deps // deps
const async = require('async'); const async = require('async');
const http = require('http'); const http = require('http');
const net = require('net'); const net = require('net');
const crypto = require('crypto'); const crypto = require('crypto');
const moment = require('moment');
const packageJson = require('../package.json'); const packageJson = require('../package.json');
@ -139,13 +139,9 @@ exports.getModule = class BBSLinkModule extends MenuModule {
self.client.term.write(resetScreen()); self.client.term.write(resetScreen());
self.client.term.write(' Connecting to BBSLink.net, please wait...\n'); self.client.term.write(' Connecting to BBSLink.net, please wait...\n');
const startTime = moment(); const doorTracking = trackDoorRunBegin(self.client, `bbslink_${self.config.door}`);
const bridgeConnection = net.createConnection(connectOpts, function connected() { const bridgeConnection = net.createConnection(connectOpts, function connected() {
// bump stats, fire events, etc.
StatLog.incrementUserStat(self.client.user, UserProps.DoorRunTotalCount, 1);
Events.emit(Events.getSystemEvents().UserRunDoor, { user : self.client.user } );
self.client.log.info(connectOpts, 'BBSLink bridge connection established'); self.client.log.info(connectOpts, 'BBSLink bridge connection established');
self.client.term.output.pipe(bridgeConnection); self.client.term.output.pipe(bridgeConnection);
@ -161,11 +157,7 @@ exports.getModule = class BBSLinkModule extends MenuModule {
self.client.term.output.unpipe(bridgeConnection); self.client.term.output.unpipe(bridgeConnection);
self.client.term.output.resume(); self.client.term.output.resume();
const endTime = moment(); trackDoorRunEnd(doorTracking);
const runTimeMinutes = Math.floor(moment.duration(endTime.diff(startTime)).asMinutes());
if(runTimeMinutes > 0) {
StatLog.incrementUserStat(self.client.user, UserProps.DoorRunTotalMinutes, runTimeMinutes);
}
}; };
bridgeConnection.on('data', function incomingData(data) { bridgeConnection.on('data', function incomingData(data) {

View File

@ -5,14 +5,14 @@
const { MenuModule } = require('../core/menu_module.js'); const { MenuModule } = require('../core/menu_module.js');
const { resetScreen } = require('../core/ansi_term.js'); const { resetScreen } = require('../core/ansi_term.js');
const { Errors } = require('./enig_error.js'); const { Errors } = require('./enig_error.js');
const Events = require('./events.js'); const {
const StatLog = require('./stat_log.js'); trackDoorRunBegin,
const UserProps = require('./user_property.js'); trackDoorRunEnd
} = require('./door_util.js');
// deps // deps
const async = require('async'); const async = require('async');
const RLogin = require('rlogin'); const RLogin = require('rlogin');
const moment = require('moment');
exports.moduleInfo = { exports.moduleInfo = {
name : 'CombatNet', name : 'CombatNet',
@ -50,16 +50,14 @@ exports.getModule = class CombatNetModule extends MenuModule {
self.client.term.write(resetScreen()); self.client.term.write(resetScreen());
self.client.term.write('Connecting to CombatNet, please wait...\n'); self.client.term.write('Connecting to CombatNet, please wait...\n');
const startTime = moment(); let doorTracking;
const restorePipeToNormal = function() { const restorePipeToNormal = function() {
if(self.client.term.output) { if(self.client.term.output) {
self.client.term.output.removeListener('data', sendToRloginBuffer); self.client.term.output.removeListener('data', sendToRloginBuffer);
const endTime = moment(); if(doorTracking) {
const runTimeMinutes = Math.floor(moment.duration(endTime.diff(startTime)).asMinutes()); trackDoorRunEnd(doorTracking);
if(runTimeMinutes > 0) {
StatLog.incrementUserStat(self.client.user, UserProps.DoorRunTotalMinutes, runTimeMinutes);
} }
} }
}; };
@ -102,8 +100,7 @@ exports.getModule = class CombatNetModule extends MenuModule {
self.client.log.info('Connected to CombatNet'); self.client.log.info('Connected to CombatNet');
self.client.term.output.on('data', sendToRloginBuffer); self.client.term.output.on('data', sendToRloginBuffer);
StatLog.incrementUserStat(self.client.user, UserProps.DoorRunTotalCount, 1); doorTracking = trackDoorRunBegin(self.client);
Events.emit(Events.getSystemEvents().UserRunDoor, { user : self.client.user } );
} else { } else {
return callback(Errors.General('Failed to establish establish CombatNet connection')); return callback(Errors.General('Failed to establish establish CombatNet connection'));
} }

View File

@ -5,14 +5,14 @@
const { MenuModule } = require('./menu_module.js'); const { MenuModule } = require('./menu_module.js');
const { resetScreen } = require('./ansi_term.js'); const { resetScreen } = require('./ansi_term.js');
const { Errors } = require('./enig_error.js'); const { Errors } = require('./enig_error.js');
const Events = require('./events.js'); const {
const StatLog = require('./stat_log.js'); trackDoorRunBegin,
const UserProps = require('./user_property.js'); trackDoorRunEnd
} = require('./door_util.js');
// deps // deps
const async = require('async'); const async = require('async');
const SSHClient = require('ssh2').Client; const SSHClient = require('ssh2').Client;
const moment = require('moment');
exports.moduleInfo = { exports.moduleInfo = {
name : 'DoorParty', name : 'DoorParty',
@ -58,17 +58,15 @@ exports.getModule = class DoorPartyModule extends MenuModule {
let pipeRestored = false; let pipeRestored = false;
let pipedStream; let pipedStream;
const startTime = moment(); let doorTracking;
const restorePipe = function() { const restorePipe = function() {
if(pipedStream && !pipeRestored && !clientTerminated) { if(pipedStream && !pipeRestored && !clientTerminated) {
self.client.term.output.unpipe(pipedStream); self.client.term.output.unpipe(pipedStream);
self.client.term.output.resume(); self.client.term.output.resume();
const endTime = moment(); if(doorTracking) {
const runTimeMinutes = Math.floor(moment.duration(endTime.diff(startTime)).asMinutes()); trackDoorRunEnd(doorTracking);
if(runTimeMinutes > 0) {
StatLog.incrementUserStat(self.client.user, UserProps.DoorRunTotalMinutes, runTimeMinutes);
} }
} }
}; };
@ -87,6 +85,8 @@ exports.getModule = class DoorPartyModule extends MenuModule {
return callback(Errors.General('Failed to establish tunnel')); return callback(Errors.General('Failed to establish tunnel'));
} }
doorTracking = trackDoorRunBegin(self.client);
// //
// Send rlogin // Send rlogin
// DoorParty wants the "server username" portion to be in the format of [BBS_TAG]USERNAME, e.g. // DoorParty wants the "server username" portion to be in the format of [BBS_TAG]USERNAME, e.g.
@ -95,9 +95,6 @@ exports.getModule = class DoorPartyModule extends MenuModule {
const rlogin = `\x00${self.client.user.username}\x00[${self.config.bbsTag}]${self.client.user.username}\x00${self.client.term.termType}\x00`; const rlogin = `\x00${self.client.user.username}\x00[${self.config.bbsTag}]${self.client.user.username}\x00${self.client.term.termType}\x00`;
stream.write(rlogin); stream.write(rlogin);
StatLog.incrementUserStat(self.client.user, UserProps.DoorRunTotalCount, 1);
Events.emit(Events.getSystemEvents().UserRunDoor, { user : self.client.user } );
pipedStream = stream; // :TODO: this is hacky... pipedStream = stream; // :TODO: this is hacky...
self.client.term.output.pipe(stream); self.client.term.output.pipe(stream);
@ -115,6 +112,7 @@ exports.getModule = class DoorPartyModule extends MenuModule {
sshClient.on('error', err => { sshClient.on('error', err => {
self.client.log.info(`DoorParty SSH client error: ${err.message}`); self.client.log.info(`DoorParty SSH client error: ${err.message}`);
trackDoorRunEnd(doorTracking);
}); });
sshClient.on('close', () => { sshClient.on('close', () => {

41
core/door_util.js Normal file
View File

@ -0,0 +1,41 @@
/* jslint node: true */
'use strict';
const UserProps = require('./user_property.js');
const Events = require('./events.js');
const StatLog = require('./stat_log.js');
const moment = require('moment');
exports.trackDoorRunBegin = trackDoorRunBegin;
exports.trackDoorRunEnd = trackDoorRunEnd;
function trackDoorRunBegin(client, doorTag) {
const startTime = moment();
// door must be running for >= 45s for us to officially record it
const timeout = setTimeout( () => {
StatLog.incrementUserStat(client.user, UserProps.DoorRunTotalCount, 1);
const eventInfo = { user : client.user };
if(doorTag) {
eventInfo.doorTag = doorTag;
}
Events.emit(Events.getSystemEvents().UserRunDoor, eventInfo);
}, 45 * 1000);
return { startTime, timeout, client, doorTag };
}
function trackDoorRunEnd(trackInfo) {
const { startTime, timeout, client } = trackInfo;
clearTimeout(timeout);
const endTime = moment();
const runTimeMinutes = Math.floor(moment.duration(endTime.diff(startTime)).asMinutes());
if(runTimeMinutes > 0) {
StatLog.incrementUserStat(client.user, UserProps.DoorRunTotalMinutes, runTimeMinutes);
}
}

View File

@ -10,9 +10,10 @@ const Log = require('./logger.js').log;
const { const {
getEnigmaUserAgent getEnigmaUserAgent
} = require('./misc_util.js'); } = require('./misc_util.js');
const Events = require('./events.js'); const {
const StatLog = require('./stat_log.js'); trackDoorRunBegin,
const UserProps = require('./user_property.js'); trackDoorRunEnd
} = require('./door_util.js');
// deps // deps
const async = require('async'); const async = require('async');
@ -156,17 +157,15 @@ exports.getModule = class ExodusModule extends MenuModule {
let pipeRestored = false; let pipeRestored = false;
let pipedStream; let pipedStream;
const startTime = moment(); let doorTracking;
function restorePipe() { function restorePipe() {
if(pipedStream && !pipeRestored && !clientTerminated) { if(pipedStream && !pipeRestored && !clientTerminated) {
self.client.term.output.unpipe(pipedStream); self.client.term.output.unpipe(pipedStream);
self.client.term.output.resume(); self.client.term.output.resume();
const endTime = moment(); if(doorTracking) {
const runTimeMinutes = Math.floor(moment.duration(endTime.diff(startTime)).asMinutes()); trackDoorRunEnd(doorTracking);
if(runTimeMinutes > 0) {
StatLog.incrementUserStat(self.client.user, UserProps.DoorRunTotalMinutes, runTimeMinutes);
} }
} }
} }
@ -198,8 +197,7 @@ exports.getModule = class ExodusModule extends MenuModule {
}); });
sshClient.shell(window, options, (err, stream) => { sshClient.shell(window, options, (err, stream) => {
StatLog.incrementUserStat(self.client.user, UserProps.DoorRunTotalCount, 1); doorTracking = trackDoorRunBegin(self.client, `exodus_${self.config.door}`);
Events.emit(Events.getSystemEvents().UserRunDoor, { user : self.client.user } );
pipedStream = stream; // :TODO: ewwwwwwwww hack pipedStream = stream; // :TODO: ewwwwwwwww hack
self.client.term.output.pipe(stream); self.client.term.output.pipe(stream);