From 39ec02d3c4cb5f5980b172d30404210de2479f0f Mon Sep 17 00:00:00 2001 From: marzavec Date: Tue, 13 Mar 2018 22:26:53 -0700 Subject: Streamlined modules, server tweaks, better feedback --- server/src/commands/mod/ban.js | 26 +++++++++++++------------- server/src/commands/mod/kick.js | 18 ++++++------------ server/src/commands/mod/unban.js | 27 +++++++++++++++++++++------ 3 files changed, 40 insertions(+), 31 deletions(-) (limited to 'server/src/commands/mod') 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'); }; -- cgit v1.2.1