Door utility and door tracking
* Require >= 45s of time in a door before it counts as "run"
This commit is contained in:
parent
4e1997302e
commit
7776391184
|
@ -4,16 +4,16 @@
|
|||
const { MenuModule } = require('./menu_module.js');
|
||||
const { resetScreen } = require('./ansi_term.js');
|
||||
const { Errors } = require('./enig_error.js');
|
||||
const Events = require('./events.js');
|
||||
const StatLog = require('./stat_log.js');
|
||||
const UserProps = require('./user_property.js');
|
||||
const {
|
||||
trackDoorRunBegin,
|
||||
trackDoorRunEnd
|
||||
} = require('./door_util.js');
|
||||
|
||||
// deps
|
||||
const async = require('async');
|
||||
const http = require('http');
|
||||
const net = require('net');
|
||||
const crypto = require('crypto');
|
||||
const moment = require('moment');
|
||||
|
||||
const packageJson = require('../package.json');
|
||||
|
||||
|
@ -139,13 +139,9 @@ exports.getModule = class BBSLinkModule extends MenuModule {
|
|||
self.client.term.write(resetScreen());
|
||||
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() {
|
||||
// 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.term.output.pipe(bridgeConnection);
|
||||
|
@ -161,11 +157,7 @@ exports.getModule = class BBSLinkModule extends MenuModule {
|
|||
self.client.term.output.unpipe(bridgeConnection);
|
||||
self.client.term.output.resume();
|
||||
|
||||
const endTime = moment();
|
||||
const runTimeMinutes = Math.floor(moment.duration(endTime.diff(startTime)).asMinutes());
|
||||
if(runTimeMinutes > 0) {
|
||||
StatLog.incrementUserStat(self.client.user, UserProps.DoorRunTotalMinutes, runTimeMinutes);
|
||||
}
|
||||
trackDoorRunEnd(doorTracking);
|
||||
};
|
||||
|
||||
bridgeConnection.on('data', function incomingData(data) {
|
||||
|
|
|
@ -5,14 +5,14 @@
|
|||
const { MenuModule } = require('../core/menu_module.js');
|
||||
const { resetScreen } = require('../core/ansi_term.js');
|
||||
const { Errors } = require('./enig_error.js');
|
||||
const Events = require('./events.js');
|
||||
const StatLog = require('./stat_log.js');
|
||||
const UserProps = require('./user_property.js');
|
||||
const {
|
||||
trackDoorRunBegin,
|
||||
trackDoorRunEnd
|
||||
} = require('./door_util.js');
|
||||
|
||||
// deps
|
||||
const async = require('async');
|
||||
const RLogin = require('rlogin');
|
||||
const moment = require('moment');
|
||||
|
||||
exports.moduleInfo = {
|
||||
name : 'CombatNet',
|
||||
|
@ -50,16 +50,14 @@ exports.getModule = class CombatNetModule extends MenuModule {
|
|||
self.client.term.write(resetScreen());
|
||||
self.client.term.write('Connecting to CombatNet, please wait...\n');
|
||||
|
||||
const startTime = moment();
|
||||
let doorTracking;
|
||||
|
||||
const restorePipeToNormal = function() {
|
||||
if(self.client.term.output) {
|
||||
self.client.term.output.removeListener('data', sendToRloginBuffer);
|
||||
|
||||
const endTime = moment();
|
||||
const runTimeMinutes = Math.floor(moment.duration(endTime.diff(startTime)).asMinutes());
|
||||
if(runTimeMinutes > 0) {
|
||||
StatLog.incrementUserStat(self.client.user, UserProps.DoorRunTotalMinutes, runTimeMinutes);
|
||||
if(doorTracking) {
|
||||
trackDoorRunEnd(doorTracking);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -102,8 +100,7 @@ exports.getModule = class CombatNetModule extends MenuModule {
|
|||
self.client.log.info('Connected to CombatNet');
|
||||
self.client.term.output.on('data', sendToRloginBuffer);
|
||||
|
||||
StatLog.incrementUserStat(self.client.user, UserProps.DoorRunTotalCount, 1);
|
||||
Events.emit(Events.getSystemEvents().UserRunDoor, { user : self.client.user } );
|
||||
doorTracking = trackDoorRunBegin(self.client);
|
||||
} else {
|
||||
return callback(Errors.General('Failed to establish establish CombatNet connection'));
|
||||
}
|
||||
|
|
|
@ -5,14 +5,14 @@
|
|||
const { MenuModule } = require('./menu_module.js');
|
||||
const { resetScreen } = require('./ansi_term.js');
|
||||
const { Errors } = require('./enig_error.js');
|
||||
const Events = require('./events.js');
|
||||
const StatLog = require('./stat_log.js');
|
||||
const UserProps = require('./user_property.js');
|
||||
const {
|
||||
trackDoorRunBegin,
|
||||
trackDoorRunEnd
|
||||
} = require('./door_util.js');
|
||||
|
||||
// deps
|
||||
const async = require('async');
|
||||
const SSHClient = require('ssh2').Client;
|
||||
const moment = require('moment');
|
||||
|
||||
exports.moduleInfo = {
|
||||
name : 'DoorParty',
|
||||
|
@ -58,17 +58,15 @@ exports.getModule = class DoorPartyModule extends MenuModule {
|
|||
|
||||
let pipeRestored = false;
|
||||
let pipedStream;
|
||||
const startTime = moment();
|
||||
let doorTracking;
|
||||
|
||||
const restorePipe = function() {
|
||||
if(pipedStream && !pipeRestored && !clientTerminated) {
|
||||
self.client.term.output.unpipe(pipedStream);
|
||||
self.client.term.output.resume();
|
||||
|
||||
const endTime = moment();
|
||||
const runTimeMinutes = Math.floor(moment.duration(endTime.diff(startTime)).asMinutes());
|
||||
if(runTimeMinutes > 0) {
|
||||
StatLog.incrementUserStat(self.client.user, UserProps.DoorRunTotalMinutes, runTimeMinutes);
|
||||
if(doorTracking) {
|
||||
trackDoorRunEnd(doorTracking);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -87,6 +85,8 @@ exports.getModule = class DoorPartyModule extends MenuModule {
|
|||
return callback(Errors.General('Failed to establish tunnel'));
|
||||
}
|
||||
|
||||
doorTracking = trackDoorRunBegin(self.client);
|
||||
|
||||
//
|
||||
// Send rlogin
|
||||
// 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`;
|
||||
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...
|
||||
self.client.term.output.pipe(stream);
|
||||
|
||||
|
@ -115,6 +112,7 @@ exports.getModule = class DoorPartyModule extends MenuModule {
|
|||
|
||||
sshClient.on('error', err => {
|
||||
self.client.log.info(`DoorParty SSH client error: ${err.message}`);
|
||||
trackDoorRunEnd(doorTracking);
|
||||
});
|
||||
|
||||
sshClient.on('close', () => {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -10,9 +10,10 @@ const Log = require('./logger.js').log;
|
|||
const {
|
||||
getEnigmaUserAgent
|
||||
} = require('./misc_util.js');
|
||||
const Events = require('./events.js');
|
||||
const StatLog = require('./stat_log.js');
|
||||
const UserProps = require('./user_property.js');
|
||||
const {
|
||||
trackDoorRunBegin,
|
||||
trackDoorRunEnd
|
||||
} = require('./door_util.js');
|
||||
|
||||
// deps
|
||||
const async = require('async');
|
||||
|
@ -156,17 +157,15 @@ exports.getModule = class ExodusModule extends MenuModule {
|
|||
|
||||
let pipeRestored = false;
|
||||
let pipedStream;
|
||||
const startTime = moment();
|
||||
let doorTracking;
|
||||
|
||||
function restorePipe() {
|
||||
if(pipedStream && !pipeRestored && !clientTerminated) {
|
||||
self.client.term.output.unpipe(pipedStream);
|
||||
self.client.term.output.resume();
|
||||
|
||||
const endTime = moment();
|
||||
const runTimeMinutes = Math.floor(moment.duration(endTime.diff(startTime)).asMinutes());
|
||||
if(runTimeMinutes > 0) {
|
||||
StatLog.incrementUserStat(self.client.user, UserProps.DoorRunTotalMinutes, runTimeMinutes);
|
||||
if(doorTracking) {
|
||||
trackDoorRunEnd(doorTracking);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -198,8 +197,7 @@ exports.getModule = class ExodusModule extends MenuModule {
|
|||
});
|
||||
|
||||
sshClient.shell(window, options, (err, stream) => {
|
||||
StatLog.incrementUserStat(self.client.user, UserProps.DoorRunTotalCount, 1);
|
||||
Events.emit(Events.getSystemEvents().UserRunDoor, { user : self.client.user } );
|
||||
doorTracking = trackDoorRunBegin(self.client, `exodus_${self.config.door}`);
|
||||
|
||||
pipedStream = stream; // :TODO: ewwwwwwwww hack
|
||||
self.client.term.output.pipe(stream);
|
||||
|
|
Loading…
Reference in New Issue