From e3b8cb85229f34fdf33f88183153f63030bd90a2 Mon Sep 17 00:00:00 2001 From: Andrea Lepori Date: Sun, 19 Apr 2020 23:07:56 +0200 Subject: remove unused code and fixes --- server/src/commands/core/bridge.js | 104 +++++++++++++++++-------------------- 1 file changed, 47 insertions(+), 57 deletions(-) (limited to 'server/src/commands/core/bridge.js') diff --git a/server/src/commands/core/bridge.js b/server/src/commands/core/bridge.js index 89ed211..01f7215 100644 --- a/server/src/commands/core/bridge.js +++ b/server/src/commands/core/bridge.js @@ -44,10 +44,54 @@ export async function run(core, server, socket, data) { ); } + // make sure requested nickname meets standards + const newNick = data.nick.trim(); + if (!UAC.verifyNickname(newNick)) { + return server.reply( + { + cmd: "warn", + text: "Nickname must consist of up to 24 letters, numbers, and underscores", + }, + socket + ); + } + + // prevent admin impersonation + // TODO: prevent mod impersonation + if (newNick.toLowerCase() === core.config.adminName.toLowerCase()) { + server.police.frisk(socket.address, 4); + + return server.reply( + { + cmd: "warn", + text: "You are not the admin, liar!", + }, + socket + ); + } + + // find any sockets that have the same nickname + const userExists = server.findSockets({ + channel: socket.channel, + nick: (targetNick) => targetNick.toLowerCase() === newNick.toLowerCase(), + }); + + // return error if found + if (userExists.length > 0) { + // That nickname is already in that channel + return server.reply( + { + cmd: "warn", + text: "Nickname taken", + }, + socket + ); + } + // build chat payload const payload = { cmd: "chat", - nick: data.nick, + nick: newNick, text, level: socket.level, }; @@ -71,63 +115,9 @@ export async function run(core, server, socket, data) { return true; } -// module hook functions -export function initHooks(server) { - server.registerHook("in", "chat", this.commandCheckIn.bind(this), 20); - server.registerHook("in", "chat", this.finalCmdCheck.bind(this), 254); -} - -// checks for miscellaneous '/' based commands -export function commandCheckIn(core, server, socket, payload) { - if (typeof payload.text !== "string") { - return false; - } - - if (payload.text.startsWith("/myhash")) { - server.reply( - { - cmd: "info", - text: `Your hash: ${socket.hash}`, - }, - socket - ); - - return false; - } - - return payload; -} - -export function finalCmdCheck(core, server, socket, payload) { - if (typeof payload.text !== "string") { - return false; - } - - if (!payload.text.startsWith("/")) { - return payload; - } - - if (payload.text.startsWith("//")) { - payload.text = payload.text.substr(1); - - return payload; - } - - server.reply( - { - cmd: "warn", - text: `Unknown command: ${payload.text}`, - }, - socket - ); - - return false; -} - export const requiredData = ["text", "nick"]; export const info = { - name: "chat", + name: "bridge", description: "Broadcasts passed `text` field to the calling users channel using `nick`", - usage: ` - API: { cmd: 'chat', text: '', nick: 'nick'} `, + usage: `API: { cmd: 'bridge', text: '', nick: 'nick'} `, }; -- cgit v1.2.1