From 2b6e771383f4c6f392b32ce26e4d759b56791132 Mon Sep 17 00:00:00 2001 From: marzavec Date: Thu, 12 Mar 2020 13:28:20 -0500 Subject: Protocol Updates and Bug Fixes --- server/src/commands/mod/dumb.js | 34 +++++++++++++++++++++++++++++++--- server/src/commands/mod/moveuser.js | 1 + server/src/commands/mod/speak.js | 18 ++++++++++++++++++ server/src/commands/mod/unban.js | 4 ++-- server/src/commands/mod/unbanall.js | 2 ++ 5 files changed, 54 insertions(+), 5 deletions(-) (limited to 'server/src/commands/mod') diff --git a/server/src/commands/mod/dumb.js b/server/src/commands/mod/dumb.js index 51fc745..ba2886d 100644 --- a/server/src/commands/mod/dumb.js +++ b/server/src/commands/mod/dumb.js @@ -66,9 +66,9 @@ export async function run(core, server, socket, data) { // module hook functions export function initHooks(server) { - server.registerHook('in', 'chat', this.chatCheck.bind(this), 25); - server.registerHook('in', 'invite', this.inviteCheck.bind(this), 25); - // TODO: add whisper hook, need hook priorities todo finished first + server.registerHook('in', 'chat', this.chatCheck.bind(this), 10); + server.registerHook('in', 'invite', this.inviteCheck.bind(this), 10); + server.registerHook('in', 'whisper', this.whisperCheck.bind(this), 10); } // hook incoming chat commands, shadow-prevent chat if they are muzzled @@ -140,6 +140,34 @@ export function inviteCheck(core, server, socket, payload) { return payload; } +// shadow-prevent all whispers from muzzled users +export function whisperCheck(core, server, socket, payload) { + if (typeof payload.nick !== 'string') { + return false; + } + + if (typeof payload.text !== 'string') { + return false; + } + + if (core.muzzledHashes[socket.hash]) { + const targetNick = payload.nick; + + server.reply({ + cmd: 'info', + type: 'whisper', + text: `You whispered to @${targetNick}: ${payload.text}`, + }, socket); + + // blanket "spam" protection, may expose the ratelimiting lines from `chat` and use that, TODO: one day #lazydev + server.police.frisk(socket.address, 9); + + return false; + } + + return payload; +} + export const requiredData = ['nick']; export const info = { name: 'dumb', diff --git a/server/src/commands/mod/moveuser.js b/server/src/commands/mod/moveuser.js index 4b5d52c..b86edb4 100644 --- a/server/src/commands/mod/moveuser.js +++ b/server/src/commands/mod/moveuser.js @@ -68,6 +68,7 @@ export async function run(core, server, socket, data) { } } + // TODO: import from join module const newPeerList = server.findSockets({ channel: data.channel }); const moveAnnouncement = { cmd: 'onlineAdd', diff --git a/server/src/commands/mod/speak.js b/server/src/commands/mod/speak.js index f184ef5..e5ff8e2 100644 --- a/server/src/commands/mod/speak.js +++ b/server/src/commands/mod/speak.js @@ -27,6 +27,24 @@ export async function run(core, server, socket, data) { }, socket); } + if (typeof data.ip === 'string') { + if (data.ip === '*') { + core.muzzledHashes = {}; + + return server.broadcast({ + cmd: 'info', + text: `${socket.nick} unmuzzled all users`, + }, { level: UAC.isModerator }); + } + } else if (data.hash === '*') { + core.muzzledHashes = {}; + + return server.broadcast({ + cmd: 'info', + text: `${socket.nick} unmuzzled all users`, + }, { level: UAC.isModerator }); + } + // find target & remove mute status let target; if (typeof data.ip === 'string') { diff --git a/server/src/commands/mod/unban.js b/server/src/commands/mod/unban.js index 9f50e92..3b72fdc 100644 --- a/server/src/commands/mod/unban.js +++ b/server/src/commands/mod/unban.js @@ -20,8 +20,8 @@ export async function run(core, server, socket, data) { } // find target - let mode; let - target; + let mode; + let target; if (typeof data.ip === 'string') { mode = 'ip'; target = data.ip; diff --git a/server/src/commands/mod/unbanall.js b/server/src/commands/mod/unbanall.js index a5de3c8..9d417aa 100644 --- a/server/src/commands/mod/unbanall.js +++ b/server/src/commands/mod/unbanall.js @@ -14,6 +14,8 @@ export async function run(core, server, socket) { // remove arrest records server.police.clear(); + core.stats.set('users-banned', 0); + console.log(`${socket.nick} [${socket.trip}] unbanned all`); // reply with success -- cgit v1.2.1