From f28e65ab8035682372edbe1c11d9ca2581e0a2e6 Mon Sep 17 00:00:00 2001 From: marzavec Date: Wed, 6 Nov 2019 23:35:23 -0800 Subject: Syntax update and formatting tweaks --- server/src/commands/mod/ban.js | 31 +++++++------- server/src/commands/mod/dumb.js | 85 +++++++++++++++++++++---------------- server/src/commands/mod/kick.js | 37 ++++++++-------- server/src/commands/mod/moveuser.js | 59 ++++++++++++------------- server/src/commands/mod/speak.js | 33 +++++++------- server/src/commands/mod/unban.js | 22 +++++----- server/src/commands/mod/unbanall.js | 19 +++++---- 7 files changed, 152 insertions(+), 134 deletions(-) (limited to 'server/src/commands/mod') diff --git a/server/src/commands/mod/ban.js b/server/src/commands/mod/ban.js index 9c8eb4f..dd5f01e 100644 --- a/server/src/commands/mod/ban.js +++ b/server/src/commands/mod/ban.js @@ -3,53 +3,53 @@ */ // module main -exports.run = async (core, server, socket, data) => { +export async function run(core, server, socket, data) { // increase rate limit chance and ignore if not admin or mod if (socket.uType === 'user') { - return server.police.frisk(socket.remoteAddress, 10); + return server.police.frisk(socket.address, 10); } // check user input if (typeof data.nick !== 'string') { - return; + return true; } // find target user - let targetNick = data.nick; + const targetNick = data.nick; let badClient = server.findSockets({ channel: socket.channel, nick: targetNick }); if (badClient.length === 0) { return server.reply({ cmd: 'warn', - text: 'Could not find user in channel' + text: 'Could not find user in channel', }, socket); } - badClient = badClient[0]; + [badClient] = badClient; // i guess banning mods or admins isn't the best idea? if (badClient.uType !== 'user') { return server.reply({ cmd: 'warn', - text: 'Cannot ban other mods, how rude' + text: 'Cannot ban other mods, how rude', }, socket); } // commit arrest record - server.police.arrest(badClient.remoteAddress, badClient.hash); + server.police.arrest(badClient.address, badClient.hash); console.log(`${socket.nick} [${socket.trip}] banned ${targetNick} in ${socket.channel}`); // notify normal users server.broadcast({ cmd: 'info', - text: `Banned ${targetNick}` + text: `Banned ${targetNick}`, }, { channel: socket.channel, uType: 'user' }); // notify mods server.broadcast({ cmd: 'info', - text: `${socket.nick} banned ${targetNick} in ${socket.channel}, userhash: ${badClient.hash}` + text: `${socket.nick} banned ${targetNick} in ${socket.channel}, userhash: ${badClient.hash}`, }, { uType: 'mod' }); // force connection closed @@ -57,13 +57,14 @@ exports.run = async (core, server, socket, data) => { // stats are fun core.stats.increment('users-banned'); -}; -// module meta -exports.requiredData = ['nick']; -exports.info = { + return true; +} + +export const requiredData = ['nick']; +export const info = { name: 'ban', description: 'Disconnects the target nickname in the same channel as calling socket & adds to ratelimiter', usage: ` - API: { cmd: 'ban', nick: '' }` + API: { cmd: 'ban', nick: '' }`, }; diff --git a/server/src/commands/mod/dumb.js b/server/src/commands/mod/dumb.js index d5e8fee..644bd4f 100644 --- a/server/src/commands/mod/dumb.js +++ b/server/src/commands/mod/dumb.js @@ -4,22 +4,22 @@ */ // module constructor -exports.init = (core) => { +export function init(core) { if (typeof core.muzzledHashes === 'undefined') { core.muzzledHashes = {}; } -}; +} // module main -exports.run = async (core, server, socket, data) => { +export async function run(core, server, socket, data) { // increase rate limit chance and ignore if not admin or mod if (socket.uType === 'user') { - return server.police.frisk(socket.remoteAddress, 10); + return server.police.frisk(socket.address, 10); } // check user input if (typeof data.nick !== 'string') { - return; + return true; } // find target user @@ -28,56 +28,58 @@ exports.run = async (core, server, socket, data) => { if (badClient.length === 0) { return server.reply({ cmd: 'warn', - text: 'Could not find user in channel' + text: 'Could not find user in channel', }, socket); } - badClient = badClient[0]; + [badClient] = badClient; // likely dont need this, muting mods and admins is fine if (badClient.uType !== 'user') { return server.reply({ cmd: 'warn', - text: 'This trick wont work on mods and admin' + text: 'This trick wont work on mods and admin', }, socket); } // store hash in mute list - let record = core.muzzledHashes[badClient.hash] = { - dumb: true - } + const record = core.muzzledHashes[badClient.hash] = { + dumb: true, + }; // store allies if needed - if(data.allies && Array.isArray(data.allies)){ - record.allies = data.allies; + if (data.allies && Array.isArray(data.allies)) { + record.allies = data.allies; } // notify mods server.broadcast({ cmd: 'info', - text: `${socket.nick} muzzled ${data.nick} in ${socket.channel}, userhash: ${badClient.hash}` + text: `${socket.nick} muzzled ${data.nick} in ${socket.channel}, userhash: ${badClient.hash}`, }, { uType: 'mod' }); -}; + + return true; +} // module hook functions -exports.initHooks = (server) => { +export function initHooks(server) { server.registerHook('in', 'chat', this.chatCheck, 25); server.registerHook('in', 'invite', this.inviteCheck, 25); // TODO: add whisper hook, need hook priorities todo finished first -}; +} // hook incoming chat commands, shadow-prevent chat if they are muzzled -exports.chatCheck = (core, server, socket, payload) => { +export function chatCheck(core, server, socket, payload) { if (typeof payload.text !== 'string') { return false; } - if(core.muzzledHashes[socket.hash]){ + if (core.muzzledHashes[socket.hash]) { // build fake chat payload - mutedPayload = { + const mutedPayload = { cmd: 'chat', nick: socket.nick, - text: payload.text + text: payload.text, }; if (socket.trip) { @@ -85,50 +87,59 @@ exports.chatCheck = (core, server, socket, payload) => { } // broadcast to any duplicate connections in channel - server.broadcast( mutedPayload, { channel: socket.channel, hash: socket.hash }); + server.broadcast(mutedPayload, { channel: socket.channel, hash: socket.hash }); // broadcast to allies, if any - if(core.muzzledHashes[socket.hash].allies){ - server.broadcast( mutedPayload, { channel: socket.channel, nick: core.muzzledHashes[socket.hash].allies }); + if (core.muzzledHashes[socket.hash].allies) { + server.broadcast( + mutedPayload, + { + channel: socket.channel, + nick: core.muzzledHashes[socket.hash].allies, + }, + ); } - // blanket "spam" protection, may expose the ratelimiting lines from `chat` and use that, TODO: one day #lazydev - server.police.frisk(socket.remoteAddress, 9); + /** + * 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; -}; +} // shadow-prevent all invites from muzzled users -exports.inviteCheck = (core, server, socket, payload) => { +export function inviteCheck(core, server, socket, payload) { if (typeof payload.nick !== 'string') { return false; } - if(core.muzzledHashes[socket.hash]){ + if (core.muzzledHashes[socket.hash]) { // generate common channel - let channel = Math.random().toString(36).substr(2, 8); + const channel = Math.random().toString(36).substr(2, 8); // send fake reply server.reply({ cmd: 'info', - text: `You invited ${payload.nick} to ?${channel}` + text: `You invited ${payload.nick} to ?${channel}`, }, socket); return false; } return payload; -}; +} -// module meta -exports.requiredData = ['nick']; -exports.info = { +export const requiredData = ['nick']; +export const info = { name: 'dumb', description: 'Globally shadow mute a connection. Optional allies array will see muted messages.', usage: ` - API: { cmd: 'dumb', nick: '', allies: ['', ...] }` + API: { cmd: 'dumb', nick: '', allies: ['', ...] }`, }; -exports.info.aliases = ['muzzle', 'mute']; +info.aliases = ['muzzle', 'mute']; diff --git a/server/src/commands/mod/kick.js b/server/src/commands/mod/kick.js index f3bc7ca..cb01d5c 100644 --- a/server/src/commands/mod/kick.js +++ b/server/src/commands/mod/kick.js @@ -3,37 +3,37 @@ */ // module main -exports.run = async (core, server, socket, data) => { +export async function run(core, server, socket, data) { // increase rate limit chance and ignore if not admin or mod if (socket.uType === 'user') { - return server.police.frisk(socket.remoteAddress, 10); + return server.police.frisk(socket.address, 10); } // check user input if (typeof data.nick !== 'string') { if (typeof data.nick !== 'object' && !Array.isArray(data.nick)) { - return; + return true; } } // find target user(s) - let badClients = server.findSockets({ channel: socket.channel, nick: data.nick }); + const badClients = server.findSockets({ channel: socket.channel, nick: data.nick }); if (badClients.length === 0) { return server.reply({ cmd: 'warn', - text: 'Could not find user(s) in channel' + text: 'Could not find user(s) in channel', }, socket); } // check if found targets are kickable, commit kick let newChannel = ''; - let kicked = []; - for (let i = 0, j = badClients.length; i < j; i++) { + const kicked = []; + for (let i = 0, j = badClients.length; i < j; i += 1) { if (badClients[i].uType !== 'user') { server.reply({ cmd: 'warn', - text: 'Cannot kick other mods, how rude' + text: 'Cannot kick other mods, how rude', }, socket); } else { newChannel = Math.random().toString(36).substr(2, 8); @@ -42,7 +42,7 @@ exports.run = async (core, server, socket, data) => { // inform mods with where they were sent server.broadcast({ cmd: 'info', - text: `${badClients[i].nick} was banished to ?${newChannel}` + text: `${badClients[i].nick} was banished to ?${newChannel}`, }, { channel: socket.channel, uType: 'mod' }); kicked.push(badClients[i].nick); @@ -51,32 +51,33 @@ exports.run = async (core, server, socket, data) => { } if (kicked.length === 0) { - return; + return true; } // broadcast client leave event - for (let i = 0, j = kicked.length; i < j; i++) { + for (let i = 0, j = kicked.length; i < j; i += 1) { server.broadcast({ cmd: 'onlineRemove', - nick: kicked[i] + nick: kicked[i], }, { channel: socket.channel }); } // publicly broadcast kick event server.broadcast({ cmd: 'info', - text: `Kicked ${kicked.join(', ')}` + text: `Kicked ${kicked.join(', ')}`, }, { channel: socket.channel, uType: 'user' }); // stats are fun core.stats.increment('users-kicked', kicked.length); -}; -// module meta -exports.requiredData = ['nick']; -exports.info = { + return true; +} + +export const requiredData = ['nick']; +export const info = { name: 'kick', description: 'Silently forces target client(s) into another channel. `nick` may be string or array of strings', usage: ` - API: { cmd: 'kick', nick: '' }` + API: { cmd: 'kick', nick: '' }`, }; diff --git a/server/src/commands/mod/moveuser.js b/server/src/commands/mod/moveuser.js index c7fc4bf..b55c207 100644 --- a/server/src/commands/mod/moveuser.js +++ b/server/src/commands/mod/moveuser.js @@ -3,79 +3,79 @@ */ // module main -exports.run = async (core, server, socket, data) => { +export async function run(core, server, socket, data) { // increase rate limit chance and ignore if not admin or mod if (socket.uType === 'user') { - return server.police.frisk(socket.remoteAddress, 10); + return server.police.frisk(socket.address, 10); } // check user input if (typeof data.nick !== 'string' || typeof data.channel !== 'string') { - return; + return true; } if (data.channel === socket.channel) { // moving them into the same channel? y u do this? - return; + return true; } - let badClients = server.findSockets({ channel: socket.channel, nick: data.nick }); + const badClients = server.findSockets({ channel: socket.channel, nick: data.nick }); if (badClients.length === 0) { return server.reply({ cmd: 'warn', - text: 'Could not find user in channel' + text: 'Could not find user in channel', }, socket); } - let badClient = badClients[0]; + const badClient = badClients[0]; if (badClient.uType !== 'user') { return server.reply({ cmd: 'warn', - text: 'Cannot move other mods, how rude' + text: 'Cannot move other mods, how rude', }, socket); } const currentNick = badClient.nick.toLowerCase(); - let userExists = server.findSockets({ + const userExists = server.findSockets({ channel: data.channel, - nick: (targetNick) => targetNick.toLowerCase() === currentNick + nick: (targetNick) => targetNick.toLowerCase() === currentNick, }); if (userExists.length > 0) { // That nickname is already in that channel - return; + return true; } - let peerList = server.findSockets({ channel: socket.channel }); + const peerList = server.findSockets({ channel: socket.channel }); if (peerList.length > 1) { - for (let i = 0, l = peerList.length; i < l; i++) { + for (let i = 0, l = peerList.length; i < l; i += 1) { server.reply({ cmd: 'onlineRemove', - nick: peerList[i].nick + nick: peerList[i].nick, }, badClient); - if (badClient.nick !== peerList[i].nick){ + if (badClient.nick !== peerList[i].nick) { server.reply({ cmd: 'onlineRemove', - nick: badClient.nick + nick: badClient.nick, }, peerList[i]); } } } - let newPeerList = server.findSockets({ channel: data.channel }); - let moveAnnouncement = { + const newPeerList = server.findSockets({ channel: data.channel }); + const moveAnnouncement = { cmd: 'onlineAdd', nick: badClient.nick, trip: badClient.trip || 'null', - hash: server.getSocketHash(badClient) + hash: server.getSocketHash(badClient), }; - let nicks = []; + const nicks = []; - for (let i = 0, l = newPeerList.length; i < l; i++) { + for (let i = 0, l = newPeerList.length; i < l; i += 1) { server.reply(moveAnnouncement, newPeerList[i]); nicks.push(newPeerList[i].nick); } @@ -84,22 +84,23 @@ exports.run = async (core, server, socket, data) => { server.reply({ cmd: 'onlineSet', - nicks: nicks + nicks, }, badClient); badClient.channel = data.channel; - server.broadcast( { + server.broadcast({ cmd: 'info', - text: `${badClient.nick} was moved into ?${data.channel}` + text: `${badClient.nick} was moved into ?${data.channel}`, }, { channel: data.channel }); -}; -// module meta -exports.requiredData = ['nick', 'channel']; -exports.info = { + return true; +} + +export const requiredData = ['nick', 'channel']; +export const info = { name: 'moveuser', description: 'This will move the target user nick into another channel', usage: ` - API: { cmd: 'moveuser', nick: '', channel: '' }` + API: { cmd: 'moveuser', nick: '', channel: '' }`, }; diff --git a/server/src/commands/mod/speak.js b/server/src/commands/mod/speak.js index 23fc4de..5514545 100644 --- a/server/src/commands/mod/speak.js +++ b/server/src/commands/mod/speak.js @@ -3,32 +3,32 @@ * Author: simple */ - // module constructor - exports.init = (core) => { - if (typeof core.muzzledHashes === 'undefined') { - core.muzzledHashes = {}; - } - }; +// module constructor +export function init(core) { + if (typeof core.muzzledHashes === 'undefined') { + core.muzzledHashes = {}; + } +} // module main -exports.run = async (core, server, socket, data) => { +export async function run(core, server, socket, data) { // increase rate limit chance and ignore if not admin or mod if (socket.uType === 'user') { - return server.police.frisk(socket.remoteAddress, 10); + return server.police.frisk(socket.address, 10); } // check user input if (typeof data.ip !== 'string' && typeof data.hash !== 'string') { return server.reply({ cmd: 'warn', - text: "hash:'targethash' or ip:'1.2.3.4' is required" + text: "hash:'targethash' or ip:'1.2.3.4' is required", }, socket); } // find target & remove mute status let target; if (typeof data.ip === 'string') { - target = getSocketHash(data.ip); + target = server.getSocketHash(data.ip); } else { target = data.hash; } @@ -38,15 +38,16 @@ exports.run = async (core, server, socket, data) => { // notify mods server.broadcast({ cmd: 'info', - text: `${socket.nick} unmuzzled : ${target}` + text: `${socket.nick} unmuzzled : ${target}`, }, { uType: 'mod' }); -}; -// module meta -exports.info = { + return true; +} + +export const info = { name: 'speak', description: 'Pardon a dumb user to be able to speak again', usage: ` - API: { cmd: 'speak', ip/hash: ' { +export async function run(core, server, socket, data) { // increase rate limit chance and ignore if not admin or mod if (socket.uType === 'user') { - return server.police.frisk(socket.remoteAddress, 10); + return server.police.frisk(socket.address, 10); } // check user input if (typeof data.ip !== 'string' && typeof data.hash !== 'string') { return server.reply({ cmd: 'warn', - text: "hash:'targethash' or ip:'1.2.3.4' is required" + text: "hash:'targethash' or ip:'1.2.3.4' is required", }, socket); } // find target - let mode, target; + let mode; let + target; if (typeof data.ip === 'string') { mode = 'ip'; target = data.ip; @@ -39,23 +40,24 @@ exports.run = async (core, server, socket, data) => { // reply with success server.reply({ cmd: 'info', - text: `Unbanned ${target}` + text: `Unbanned ${target}`, }, socket); // notify mods server.broadcast({ cmd: 'info', - text: `${socket.nick} unbanned: ${target}` + text: `${socket.nick} unbanned: ${target}`, }, { uType: 'mod' }); // stats are fun core.stats.decrement('users-banned'); -}; -// module meta -exports.info = { + return true; +} + +export const info = { name: 'unban', description: 'Removes target ip from the ratelimiter', usage: ` - API: { cmd: 'unban', ip/hash: '' }` + API: { cmd: 'unban', ip/hash: '' }`, }; diff --git a/server/src/commands/mod/unbanall.js b/server/src/commands/mod/unbanall.js index c285b80..49eeee5 100644 --- a/server/src/commands/mod/unbanall.js +++ b/server/src/commands/mod/unbanall.js @@ -3,34 +3,35 @@ */ // module main -exports.run = async (core, server, socket, data) => { +export async function run(core, server, socket) { // increase rate limit chance and ignore if not admin or mod if (socket.uType === 'user') { - return server.police.frisk(socket.remoteAddress, 10); + return server.police.frisk(socket.address, 10); } // remove arrest records - server.police.records = {}; + server.police.clear(); console.log(`${socket.nick} [${socket.trip}] unbanned all`); // reply with success server.reply({ cmd: 'info', - text: `Unbanned all ip addresses` + text: 'Unbanned all ip addresses', }, socket); // notify mods server.broadcast({ cmd: 'info', - text: `${socket.nick} unbanned all ip addresses` + text: `${socket.nick} unbanned all ip addresses`, }, { uType: 'mod' }); -}; -// module meta -exports.info = { + return true; +} + +export const info = { name: 'unbanall', description: 'Clears all banned ip addresses', usage: ` - API: { cmd: 'unbanall' }` + API: { cmd: 'unbanall' }`, }; -- cgit v1.2.1