aboutsummaryrefslogtreecommitdiffstats
path: root/server/src/commands/mod
diff options
context:
space:
mode:
authormarzavec <admin@marzavec.com>2018-03-14 06:26:53 +0100
committermarzavec <admin@marzavec.com>2018-03-14 06:26:53 +0100
commit39ec02d3c4cb5f5980b172d30404210de2479f0f (patch)
treeb837c9cfff94c62aa3de9880e4f7d07460734984 /server/src/commands/mod
parentstabilized modules and server cmd field (diff)
downloadhackchat-39ec02d3c4cb5f5980b172d30404210de2479f0f.tar.gz
hackchat-39ec02d3c4cb5f5980b172d30404210de2479f0f.zip
Streamlined modules, server tweaks, better feedback
Diffstat (limited to '')
-rw-r--r--server/src/commands/mod/ban.js26
-rw-r--r--server/src/commands/mod/kick.js18
-rw-r--r--server/src/commands/mod/unban.js27
3 files changed, 40 insertions, 31 deletions
diff --git a/server/src/commands/mod/ban.js b/server/src/commands/mod/ban.js
index 1880ef3..5ee77b6 100644
--- a/server/src/commands/mod/ban.js
+++ b/server/src/commands/mod/ban.js
@@ -1,5 +1,5 @@
/*
-
+ Description: Adds the target socket's ip to the ratelimiter
*/
'use strict';
@@ -15,16 +15,9 @@ exports.run = async (core, server, socket, data) => {
}
let targetNick = data.nick;
- let badClient = null;
- for (let client of server.clients) {
- // Find badClient's socket
- if (client.channel == socket.channel && client.nick == targetNick) {
- badClient = client;
- break;
- }
- }
+ let badClient = server.findSockets({ channel: socket.channel, nick: targetNick });
- if (!badClient) {
+ if (badClient.length === 0) {
server.reply({
cmd: 'warn',
text: 'Could not find user in channel'
@@ -33,6 +26,8 @@ exports.run = async (core, server, socket, data) => {
return;
}
+ badClient = badClient[0];
+
if (badClient.uType !== 'user') {
server.reply({
cmd: 'warn',
@@ -42,16 +37,21 @@ exports.run = async (core, server, socket, data) => {
return;
}
- // TODO: add reference to banned users nick or unban by nick cmd
+ // TODO unban by hash
server._police.arrest(badClient.remoteAddress);
- // TODO: add event to log?
console.log(`${socket.nick} [${socket.trip}] banned ${targetNick} in ${socket.channel}`);
server.broadcast({
cmd: 'info',
text: `Banned ${targetNick}`
- }, { channel: socket.channel });
+ }, { channel: socket.channel, uType: 'user' });
+
+ server.broadcast({
+ cmd: 'info',
+ text: `${socket.nick} banned ${targetNick} in ${socket.channel}, userhash: ${server.getSocketHash(badClient)}`
+ }, { uType: 'mod' });
+
badClient.close();
core.managers.stats.increment('users-banned');
diff --git a/server/src/commands/mod/kick.js b/server/src/commands/mod/kick.js
index a730caf..f51d576 100644
--- a/server/src/commands/mod/kick.js
+++ b/server/src/commands/mod/kick.js
@@ -1,5 +1,5 @@
/*
-
+ Description: Forces a change on the target socket's channel, then broadcasts event
*/
'use strict';
@@ -15,16 +15,9 @@ exports.run = async (core, server, socket, data) => {
}
let targetNick = data.nick;
- let badClient = null;
- for (let client of server.clients) {
- // Find badClient's socket
- if (client.channel == socket.channel && client.nick == targetNick) {
- badClient = client;
- break;
- }
- }
+ let badClient = server.findSockets({ channel: socket.channel, nick: targetNick });
- if (!badClient) {
+ if (badClient.length === 0) {
server.reply({
cmd: 'warn',
text: 'Could not find user in channel'
@@ -33,6 +26,8 @@ exports.run = async (core, server, socket, data) => {
return;
}
+ badClient = badClient[0];
+
if (badClient.uType !== 'user') {
server.reply({
cmd: 'warn',
@@ -42,7 +37,6 @@ exports.run = async (core, server, socket, data) => {
return;
}
- // TODO: add event to log?
let newChannel = Math.random().toString(36).substr(2, 8);
badClient.channel = newChannel;
@@ -54,7 +48,7 @@ exports.run = async (core, server, socket, data) => {
nick: targetNick
}, { channel: socket.channel });
- // publicly broadcast event (TODO: should this be supressed?)
+ // publicly broadcast event
server.broadcast({
cmd: 'info',
text: `Kicked ${targetNick}`
diff --git a/server/src/commands/mod/unban.js b/server/src/commands/mod/unban.js
index 193b614..ee028d2 100644
--- a/server/src/commands/mod/unban.js
+++ b/server/src/commands/mod/unban.js
@@ -1,5 +1,5 @@
/*
-
+ Description: Removes a target ip from the ratelimiter
*/
'use strict';
@@ -15,17 +15,32 @@ exports.run = async (core, server, socket, data) => {
}
let ip = data.ip;
- let nick = data.nick; // for future upgrade
+ let hash = data.hash; // TODO unban by hash
+
+ // TODO unban by hash
+ let recordFound = server._police.pardon(data.ip);
+
+ if (!recordFound) {
+ server.reply({
+ cmd: 'warn',
+ text: 'Could not find target in records'
+ }, socket);
+
+ return;
+ }
- // TODO: support remove by nick future upgrade
- server._police.pardon(badClient.remoteAddress);
- console.log(`${socket.nick} [${socket.trip}] unbanned ${/*nick || */ip} in ${socket.channel}`);
+ console.log(`${socket.nick} [${socket.trip}] unbanned ${/*hash || */ip} in ${socket.channel}`);
server.reply({
cmd: 'info',
- text: `Unbanned ${/*nick || */ip}`
+ text: `${socket.nick} unbanned a userhash: ${server.getSocketHash(ip)}`
}, socket);
+ server.broadcast({
+ cmd: 'info',
+ text: `${socket.nick} unbanned a userhash: ${server.getSocketHash(ip)}`
+ }, { uType: 'mod' });
+
core.managers.stats.decrement('users-banned');
};