aboutsummaryrefslogtreecommitdiffstats
path: root/server/src/commands/core/invite.js
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/commands/core/invite.js')
-rw-r--r--server/src/commands/core/invite.js24
1 files changed, 12 insertions, 12 deletions
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
+};