2019-01-18 03:18:02 +00:00
|
|
|
/* jslint node: true */
|
|
|
|
'use strict';
|
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
const Events = require('./events.js');
|
|
|
|
const LogNames = require('./user_log_name.js');
|
2019-01-18 03:18:02 +00:00
|
|
|
|
|
|
|
const DefaultKeepForDays = 365;
|
|
|
|
|
|
|
|
module.exports = function systemEventUserLogInit(statLog) {
|
|
|
|
const systemEvents = Events.getSystemEvents();
|
|
|
|
|
|
|
|
const interestedEvents = [
|
|
|
|
systemEvents.NewUser,
|
2022-06-05 20:04:25 +00:00
|
|
|
systemEvents.UserLogin,
|
|
|
|
systemEvents.UserLogoff,
|
|
|
|
systemEvents.UserUpload,
|
|
|
|
systemEvents.UserDownload,
|
|
|
|
systemEvents.UserPostMessage,
|
|
|
|
systemEvents.UserSendMail,
|
|
|
|
systemEvents.UserRunDoor,
|
|
|
|
systemEvents.UserSendNodeMsg,
|
2019-01-18 03:18:02 +00:00
|
|
|
systemEvents.UserAchievementEarned,
|
|
|
|
];
|
|
|
|
|
|
|
|
const append = (e, n, v) => {
|
|
|
|
statLog.appendUserLogEntry(e.user, n, v, DefaultKeepForDays);
|
|
|
|
};
|
|
|
|
|
|
|
|
Events.addMultipleEventListener(interestedEvents, (event, eventName) => {
|
|
|
|
const detailHandler = {
|
2022-06-05 20:04:25 +00:00
|
|
|
[systemEvents.NewUser]: e => {
|
2019-01-18 03:18:02 +00:00
|
|
|
append(e, LogNames.NewUser, 1);
|
|
|
|
},
|
2022-06-05 20:04:25 +00:00
|
|
|
[systemEvents.UserLogin]: e => {
|
2019-01-18 03:18:02 +00:00
|
|
|
append(e, LogNames.Login, 1);
|
|
|
|
},
|
2022-06-05 20:04:25 +00:00
|
|
|
[systemEvents.UserLogoff]: e => {
|
2019-01-18 03:18:02 +00:00
|
|
|
append(e, LogNames.Logoff, e.minutesOnline);
|
|
|
|
},
|
2022-06-05 20:04:25 +00:00
|
|
|
[systemEvents.UserUpload]: e => {
|
|
|
|
if (e.files.length) {
|
|
|
|
// we can get here for dupe uploads
|
2019-01-18 04:27:25 +00:00
|
|
|
append(e, LogNames.UlFiles, e.files.length);
|
2022-06-05 20:04:25 +00:00
|
|
|
const totalBytes = e.files.reduce(
|
|
|
|
(bytes, fileEntry) => bytes + fileEntry.meta.byte_size,
|
|
|
|
0
|
|
|
|
);
|
2019-01-18 04:27:25 +00:00
|
|
|
append(e, LogNames.UlFileBytes, totalBytes);
|
|
|
|
}
|
2019-01-18 03:18:02 +00:00
|
|
|
},
|
2022-06-05 20:04:25 +00:00
|
|
|
[systemEvents.UserDownload]: e => {
|
|
|
|
if (e.files.length) {
|
2019-01-18 04:27:25 +00:00
|
|
|
append(e, LogNames.DlFiles, e.files.length);
|
2022-06-05 20:04:25 +00:00
|
|
|
const totalBytes = e.files.reduce(
|
|
|
|
(bytes, fileEntry) => bytes + fileEntry.byteSize,
|
|
|
|
0
|
|
|
|
);
|
2019-01-18 04:27:25 +00:00
|
|
|
append(e, LogNames.DlFileBytes, totalBytes);
|
|
|
|
}
|
2019-01-18 03:18:02 +00:00
|
|
|
},
|
2022-06-05 20:04:25 +00:00
|
|
|
[systemEvents.UserPostMessage]: e => {
|
2019-01-18 03:18:02 +00:00
|
|
|
append(e, LogNames.PostMessage, e.areaTag);
|
|
|
|
},
|
2022-06-05 20:04:25 +00:00
|
|
|
[systemEvents.UserSendMail]: e => {
|
2019-01-18 03:18:02 +00:00
|
|
|
append(e, LogNames.SendMail, 1);
|
|
|
|
},
|
2022-06-05 20:04:25 +00:00
|
|
|
[systemEvents.UserRunDoor]: e => {
|
2019-01-19 06:12:01 +00:00
|
|
|
append(e, LogNames.RunDoor, e.doorTag);
|
|
|
|
append(e, LogNames.RunDoorMinutes, e.runTimeMinutes);
|
2019-01-18 03:18:02 +00:00
|
|
|
},
|
2022-06-05 20:04:25 +00:00
|
|
|
[systemEvents.UserSendNodeMsg]: e => {
|
2019-01-18 03:18:02 +00:00
|
|
|
append(e, LogNames.SendNodeMsg, e.global ? 'global' : 'direct');
|
|
|
|
},
|
2022-06-05 20:04:25 +00:00
|
|
|
[systemEvents.UserAchievementEarned]: e => {
|
2019-01-18 03:18:02 +00:00
|
|
|
append(e, LogNames.AchievementEarned, e.achievementTag);
|
|
|
|
append(e, LogNames.AchievementPointsEarned, e.points);
|
2022-06-05 20:04:25 +00:00
|
|
|
},
|
2019-01-18 03:18:02 +00:00
|
|
|
}[eventName];
|
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
if (detailHandler) {
|
2019-01-18 03:18:02 +00:00
|
|
|
detailHandler(event);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|