diff --git a/core/abracadabra.js b/core/abracadabra.js index 42731ac0..34374049 100644 --- a/core/abracadabra.js +++ b/core/abracadabra.js @@ -6,17 +6,17 @@ const DropFile = require('./dropfile.js'); const Door = require('./door.js'); const theme = require('./theme.js'); const ansi = require('./ansi_term.js'); -const Events = require('./events.js'); const { Errors } = require('./enig_error.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 assert = require('assert'); const _ = require('lodash'); const paths = require('path'); -const moment = require('moment'); const activeDoorNodeInstances = {}; @@ -152,9 +152,6 @@ exports.getModule = class AbracadabraModule extends MenuModule { } runDoor() { - StatLog.incrementUserStat(this.client.user, UserProps.DoorRunTotalCount, 1); - Events.emit(Events.getSystemEvents().UserRunDoor, { user : this.client.user } ); - this.client.term.write(ansi.resetScreen()); const exeInfo = { @@ -168,14 +165,10 @@ exports.getModule = class AbracadabraModule extends MenuModule { node : this.client.node, }; - const startTime = moment(); + const doorTracking = trackDoorRunBegin(this.client, this.config.name); this.doorInstance.run(exeInfo, () => { - const endTime = moment(); - const runTimeMinutes = Math.floor(moment.duration(endTime.diff(startTime)).asMinutes()); - if(runTimeMinutes > 0) { - StatLog.incrementUserStat(this.client.user, UserProps.DoorRunTotalMinutes, runTimeMinutes); - } + trackDoorRunEnd(doorTracking); // // Try to clean up various settings such as scroll regions that may diff --git a/core/door_util.js b/core/door_util.js index c1681058..6517f1be 100644 --- a/core/door_util.js +++ b/core/door_util.js @@ -10,32 +10,29 @@ 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 }; + return { startTime, client, doorTag }; } function trackDoorRunEnd(trackInfo) { - const { startTime, timeout, client } = trackInfo; + const { startTime, client, doorTag } = trackInfo; - clearTimeout(timeout); + const diff = moment.duration(moment().diff(startTime)); + if(diff.asSeconds() >= 45) { + StatLog.incrementUserStat(client.user, UserProps.DoorRunTotalCount, 1); + } - const endTime = moment(); - const runTimeMinutes = Math.floor(moment.duration(endTime.diff(startTime)).asMinutes()); + const runTimeMinutes = Math.floor(diff.asMinutes()); if(runTimeMinutes > 0) { StatLog.incrementUserStat(client.user, UserProps.DoorRunTotalMinutes, runTimeMinutes); + + const eventInfo = { + runTimeMinutes, + user : client.user, + doorTag : doorTag || 'unknown', + }; + + Events.emit(Events.getSystemEvents().UserRunDoor, eventInfo); } } \ No newline at end of file diff --git a/core/sys_event_user_log.js b/core/sys_event_user_log.js index 39120987..63ae0e55 100644 --- a/core/sys_event_user_log.js +++ b/core/sys_event_user_log.js @@ -54,8 +54,8 @@ module.exports = function systemEventUserLogInit(statLog) { append(e, LogNames.SendMail, 1); }, [ systemEvents.UserRunDoor ] : (e) => { - // :TODO: store door tag, else '-' ? - append(e, LogNames.RunDoor, 1); + append(e, LogNames.RunDoor, e.doorTag); + append(e, LogNames.RunDoorMinutes, e.runTimeMinutes); }, [ systemEvents.UserSendNodeMsg ] : (e) => { append(e, LogNames.SendNodeMsg, e.global ? 'global' : 'direct'); diff --git a/core/system_events.js b/core/system_events.js index 1bed2d13..173f753b 100644 --- a/core/system_events.js +++ b/core/system_events.js @@ -19,7 +19,7 @@ module.exports = { UserDownload : 'codes.l33t.enigma.system.user_download', // { ..., files[ fileEntry, ...] } UserPostMessage : 'codes.l33t.enigma.system.user_post_msg', // { ..., areaTag } UserSendMail : 'codes.l33t.enigma.system.user_send_mail', // { ... } - UserRunDoor : 'codes.l33t.enigma.system.user_run_door', // { ... } + UserRunDoor : 'codes.l33t.enigma.system.user_run_door', // { ..., runTimeMinutes, doorTag|unknown } UserSendNodeMsg : 'codes.l33t.enigma.system.user_send_node_msg', // { ..., global } UserStatSet : 'codes.l33t.enigma.system.user_stat_set', // { ..., statName, statValue } UserStatIncrement : 'codes.l33t.enigma.system.user_stat_increment', // { ..., statName, statIncrementBy, statValue } diff --git a/core/user_log_name.js b/core/user_log_name.js index 6186d326..77fa996c 100644 --- a/core/user_log_name.js +++ b/core/user_log_name.js @@ -14,7 +14,8 @@ module.exports = { DlFileBytes : 'dl_file_bytes', // value=total bytes PostMessage : 'post_msg', // value=areaTag SendMail : 'send_mail', - RunDoor : 'run_door', + RunDoor : 'run_door', // value=doorTag|unknown + RunDoorMinutes : 'run_door_minutes', // value=minutes ran SendNodeMsg : 'send_node_msg', // value=global|direct AchievementEarned : 'achievement_earned', // value=achievementTag AchievementPointsEarned : 'achievement_pts_earned', // value=points earned