aboutsummaryrefslogtreecommitdiffstats
path: root/server/src/commands/core/stats.js
diff options
context:
space:
mode:
authorNeel Kamath <neelkamath@protonmail.com>2018-05-13 13:07:56 +0200
committerNeel Kamath <neelkamath@protonmail.com>2018-05-13 13:07:56 +0200
commit949404cd1aad8492ae0338130f16054adfa38ab7 (patch)
tree6fed796d224901f5b6832543b19973af425e0fa9 /server/src/commands/core/stats.js
parentFlatten (diff)
downloadhackchat-949404cd1aad8492ae0338130f16054adfa38ab7.tar.gz
hackchat-949404cd1aad8492ae0338130f16054adfa38ab7.zip
Prevent fucking shit up
Diffstat (limited to 'server/src/commands/core/stats.js')
-rw-r--r--server/src/commands/core/stats.js32
1 files changed, 32 insertions, 0 deletions
diff --git a/server/src/commands/core/stats.js b/server/src/commands/core/stats.js
new file mode 100644
index 0000000..b9dc002
--- /dev/null
+++ b/server/src/commands/core/stats.js
@@ -0,0 +1,32 @@
+/*
+ Description: Legacy stats output, kept for compatibility, outputs user and channel count
+*/
+
+exports.run = async (core, server, socket, data) => {
+ 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;
+
+ server.reply({
+ cmd: 'info',
+ text: `${uniqueClientCount} unique IPs in ${uniqueChannels} channels`
+ }, socket);
+
+ core.managers.stats.increment('stats-requested');
+};
+
+exports.info = {
+ name: 'stats',
+ description: 'Sends back legacy server stats to the calling client'
+}; \ No newline at end of file