1
0
mirror of https://github.com/hack-chat/main.git synced 2024-03-22 13:20:33 +08:00
hack-chat-main/server/src/commands/core/stats.js

40 lines
917 B
JavaScript
Raw Normal View History

2018-03-10 15:47:00 +08:00
/*
Description: Legacy stats output, kept for compatibility, outputs user and channel count
2018-03-10 15:47:00 +08:00
*/
// module main
2018-03-10 15:47:00 +08:00
exports.run = async (core, server, socket, data) => {
2018-06-04 15:07:24 +08:00
// gather connection and channel count
2018-03-10 15:47:00 +08:00
let ips = {};
let channels = {};
for (let client of server.clients) {
if (client.channel) {
channels[client.channel] = true;
ips[client.remoteAddress] = true;
}
}
let uniqueClientCount = Object.keys(ips).length;
let uniqueChannels = Object.keys(channels).length;
ips = null;
channels = null;
2018-06-04 15:07:24 +08:00
// dispatch info
2018-03-10 15:47:00 +08:00
server.reply({
cmd: 'info',
text: `${uniqueClientCount} unique IPs in ${uniqueChannels} channels`
2018-03-10 15:47:00 +08:00
}, socket);
2018-06-04 15:07:24 +08:00
// stats are fun
2018-03-10 15:47:00 +08:00
core.managers.stats.increment('stats-requested');
};
// module meta
2018-05-13 18:33:22 +08:00
exports.info = {
name: 'stats',
description: 'Sends back legacy server stats to the calling client',
usage: `
API: { cmd: 'stats' }`
2018-06-04 15:07:24 +08:00
};