aboutsummaryrefslogtreecommitdiffstats
path: root/server/src/commands/admin/listusers.js
diff options
context:
space:
mode:
authormarzavec <admin@marzavec.com>2018-06-04 09:07:24 +0200
committermarzavec <admin@marzavec.com>2018-06-04 09:07:24 +0200
commite35fff59ba30e78046c9212e74fce9aef56c6e93 (patch)
treec7d3e0cd75f5a6063d629d4295952488907e9562 /server/src/commands/admin/listusers.js
parentCompleted protocol decoupling (diff)
downloadhackchat-e35fff59ba30e78046c9212e74fce9aef56c6e93.tar.gz
hackchat-e35fff59ba30e78046c9212e74fce9aef56c6e93.zip
cleaned up and commented modules
Diffstat (limited to 'server/src/commands/admin/listusers.js')
-rw-r--r--server/src/commands/admin/listusers.js27
1 files changed, 16 insertions, 11 deletions
diff --git a/server/src/commands/admin/listusers.js b/server/src/commands/admin/listusers.js
index a539a3c..d3dddc2 100644
--- a/server/src/commands/admin/listusers.js
+++ b/server/src/commands/admin/listusers.js
@@ -3,32 +3,37 @@
*/
exports.run = async (core, server, socket, data) => {
+ // increase rate limit chance and ignore if not admin
if (socket.uType != 'admin') {
- // ignore if not admin
+ server._police.frisk(socket.remoteAddress, 20);
+
return;
}
+ // find all users currently in a channel
+ let currentUsers = server.findSockets({
+ channel: (channel) => true
+ });
+
+ // compile channel and user list
let channels = {};
- for (var client of server.clients) {
- if (client.channel) {
- if (!channels[client.channel]) {
- channels[client.channel] = [];
- }
- channels[client.channel].push(client.nick);
+ for (let i = 0, j = currentUsers.length; i < j; i++) {
+ if (typeof channels[currentUsers[i].channel] === 'undefined') {
+ channels[currentUsers[i].channel] = [];
}
+ channels[currentUsers[i].channel].push(currentUsers[i].nick);
}
+ // build output
let lines = [];
for (let channel in channels) {
lines.push(`?${channel} ${channels[channel].join(", ")}`);
}
- let text = '';
- text += lines.join("\n");
-
+ // send reply
server.reply({
cmd: 'info',
- text: text
+ text: lines.join("\n")
}, socket);
};