aboutsummaryrefslogtreecommitdiffstats
path: root/server/src/commands
diff options
context:
space:
mode:
authorAndrea Lepori <alepori@student.ethz.ch>2020-04-19 23:07:56 +0200
committerAndrea Lepori <alepori@student.ethz.ch>2020-04-19 23:07:56 +0200
commite3b8cb85229f34fdf33f88183153f63030bd90a2 (patch)
tree03befa692f5a449fde637a2280d4aedefb43d29c /server/src/commands
parentadd bridge command to send messages with different nicks (diff)
downloadhackchat-e3b8cb85229f34fdf33f88183153f63030bd90a2.tar.gz
hackchat-e3b8cb85229f34fdf33f88183153f63030bd90a2.zip
remove unused code and fixes
Diffstat (limited to 'server/src/commands')
-rw-r--r--server/src/commands/core/bridge.js104
1 files changed, 47 insertions, 57 deletions
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: '<text to send>', nick: 'nick'} `,
+ usage: `API: { cmd: 'bridge', text: '<text to send>', nick: 'nick'} `,
};