From e35fff59ba30e78046c9212e74fce9aef56c6e93 Mon Sep 17 00:00:00 2001 From: marzavec Date: Mon, 4 Jun 2018 00:07:24 -0700 Subject: cleaned up and commented modules --- server/src/commands/core/invite.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'server/src/commands/core/invite.js') diff --git a/server/src/commands/core/invite.js b/server/src/commands/core/invite.js index bcf9097..d616193 100644 --- a/server/src/commands/core/invite.js +++ b/server/src/commands/core/invite.js @@ -2,11 +2,10 @@ Description: Generates a semi-unique channel name then broadcasts it to each client */ -const verifyNickname = (nick) => { - return /^[a-zA-Z0-9_]{1,24}$/.test(nick); -}; +const verifyNickname = (nick) => /^[a-zA-Z0-9_]{1,24}$/.test(nick); exports.run = async (core, server, socket, data) => { + // check for spam if (server._police.frisk(socket.remoteAddress, 2)) { server.reply({ cmd: 'warn', @@ -16,22 +15,20 @@ exports.run = async (core, server, socket, data) => { return; } - if (typeof data.nick !== 'string') { - return; - } - - if (!verifyNickname(data.nick)) { - // Not a valid nickname? Chances are we won't find them + // verify user input + if (typeof data.nick !== 'string' || !verifyNickname(data.nick)) { return; } + // why would you invite yourself? if (data.nick == socket.nick) { - // They invited themself return; } - + + // generate common channel let channel = Math.random().toString(36).substr(2, 8); + // build and send invite let payload = { cmd: 'info', invite: channel, @@ -39,6 +36,7 @@ exports.run = async (core, server, socket, data) => { }; let inviteSent = server.broadcast( payload, { channel: socket.channel, nick: data.nick }); + // server indicates the user was not found if (!inviteSent) { server.reply({ cmd: 'warn', @@ -48,11 +46,13 @@ exports.run = async (core, server, socket, data) => { return; } + // reply with common channel server.reply({ cmd: 'info', text: `You invited ${data.nick} to ?${channel}` }, socket); + // stats are fun core.managers.stats.increment('invites-sent'); }; @@ -62,4 +62,4 @@ exports.info = { name: 'invite', usage: 'invite {nick}', description: 'Generates a unique (more or less) room name and passes it to two clients' -}; \ No newline at end of file +}; -- cgit v1.2.1