2018-03-10 15:47:00 +08:00
|
|
|
/*
|
2018-03-14 13:26:53 +08:00
|
|
|
Description: Legacy stats output, kept for compatibility, outputs user and channel count
|
2018-03-10 15:47:00 +08:00
|
|
|
*/
|
|
|
|
|
2018-09-30 14:44:36 +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',
|
2018-03-14 13:26:53 +08:00
|
|
|
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');
|
|
|
|
};
|
|
|
|
|
2018-09-30 14:44:36 +08:00
|
|
|
// module meta
|
2018-05-13 18:33:22 +08:00
|
|
|
exports.info = {
|
|
|
|
name: 'stats',
|
2018-09-30 14:44:36 +08:00
|
|
|
description: 'Sends back legacy server stats to the calling client',
|
|
|
|
usage: `
|
|
|
|
API: { cmd: 'stats' }`
|
2018-06-04 15:07:24 +08:00
|
|
|
};
|