From ad30e3a805b3ea47c345c221d8c88f88b0d6f698 Mon Sep 17 00:00:00 2001 From: calzoneman Date: Sat, 15 Feb 2014 12:29:05 -0600 Subject: [PATCH] Add some safety checks to PMs --- lib/channel.js | 17 +++++++++++++++++ www/assets/js/util.js | 16 +++++++++------- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/lib/channel.js b/lib/channel.js index 9e8a760c..004ab61d 100644 --- a/lib/channel.js +++ b/lib/channel.js @@ -2878,6 +2878,20 @@ Channel.prototype.handlePm = function (user, data) { return; } + if (data.to === user.name) { + user.socket.emit("errorMsg", { + msg: "You can't PM yourself!" + }); + return; + } + + if (!util.isValidUserName(data.to)) { + user.socket.emit("errorMsg", { + msg: data.to + " isn't a valid username." + }); + return; + } + var msg = data.msg.substring(0, 240); var to = null; for (var i = 0; i < this.users.length; i++) { @@ -2888,6 +2902,9 @@ Channel.prototype.handlePm = function (user, data) { } if (!to) { + user.socket.emit("errorMsg", { + msg: data.to + " is not on this channel." + }); return; } diff --git a/www/assets/js/util.js b/www/assets/js/util.js index 1d1b67c4..6adf1859 100644 --- a/www/assets/js/util.js +++ b/www/assets/js/util.js @@ -200,13 +200,15 @@ function addUserDropdown(entry) { } /* pm button */ - var pm = $("