Achievement & Event improvements

* User stat set vs user stat increment system events
* Proper addMultipleEventListener() and removeMultipleEventListener() Events APIs
* userStatSet vs userStatInc user stat achievement types. userStatInc for example can be used for door minutes used
This commit is contained in:
Bryan Ashby
2019-01-06 21:56:12 -07:00
parent 925ca134c6
commit 34c9178099
6 changed files with 107 additions and 35 deletions

View File

@@ -5,10 +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');
// deps
const async = require('async');
const SSHClient = require('ssh2').Client;
const moment = require('moment');
exports.moduleInfo = {
name : 'DoorParty',
@@ -54,10 +58,18 @@ exports.getModule = class DoorPartyModule extends MenuModule {
let pipeRestored = false;
let pipedStream;
const startTime = moment();
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);
}
}
};
@@ -83,6 +95,9 @@ 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);