Add some safety checks to PMs

This commit is contained in:
calzoneman 2014-02-15 12:29:05 -06:00
parent b41529d4aa
commit ad30e3a805
2 changed files with 26 additions and 7 deletions

View File

@ -2878,6 +2878,20 @@ Channel.prototype.handlePm = function (user, data) {
return; 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 msg = data.msg.substring(0, 240);
var to = null; var to = null;
for (var i = 0; i < this.users.length; i++) { for (var i = 0; i < this.users.length; i++) {
@ -2888,6 +2902,9 @@ Channel.prototype.handlePm = function (user, data) {
} }
if (!to) { if (!to) {
user.socket.emit("errorMsg", {
msg: data.to + " is not on this channel."
});
return; return;
} }

View File

@ -200,13 +200,15 @@ function addUserDropdown(entry) {
} }
/* pm button */ /* pm button */
var pm = $("<button/>").addClass("btn btn-xs btn-default") if (name !== CLIENT.name) {
.text("Private Message") var pm = $("<button/>").addClass("btn btn-xs btn-default")
.appendTo(btngroup) .text("Private Message")
.click(function () { .appendTo(btngroup)
initPm(name).find(".panel-heading").click(); .click(function () {
menu.hide(); initPm(name).find(".panel-heading").click();
}); menu.hide();
});
}
/* give/remove leader (moderator+ only) */ /* give/remove leader (moderator+ only) */
if (hasPermission("leaderctl")) { if (hasPermission("leaderctl")) {