From 120d56d6c81c40645d124f3459cb27d6046eae87 Mon Sep 17 00:00:00 2001 From: calzoneman Date: Wed, 16 Oct 2013 17:36:05 -0500 Subject: [PATCH] Change the way /mute works --- changelog | 7 +++++++ lib/channel.js | 6 +++++- lib/chatcommand.js | 4 ++-- lib/user.js | 1 - lib/utilities.js | 38 +++++++++++++++++++++++++++++++++++++- 5 files changed, 51 insertions(+), 5 deletions(-) diff --git a/changelog b/changelog index b14fecd7..810158ed 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,10 @@ +Wed Oct 16 17:34 2013 CDT + * lib/utilities.js: Add a "Set" wrapper around objects to represent + sets. + * lib/channel.js, lib/user.js: Change the way muting works- muted + users are stored in a set and are automatically muted when they + join (this set is not persisted across restarts, however). + Wed Oct 16 17:19 2013 CDT * lib/channel.js, lib/user.js: Only kick users on permissions violations. Fail silently on bad packets. diff --git a/lib/channel.js b/lib/channel.js index 4e8c05e0..e6a08a59 100644 --- a/lib/channel.js +++ b/lib/channel.js @@ -38,6 +38,7 @@ var Channel = function(name) { // Initialize defaults self.registered = false; self.users = []; + self.mutedUsers = new $util.Set(); self.playlist = new Playlist(self); self.plqueue = new AsyncQueue(); self.position = -1; @@ -1097,6 +1098,9 @@ Channel.prototype.broadcastNewUser = function(user) { self.kick(user, "You're banned!"); return; } + if (self.mutedUsers.contains(user.name.toLowerCase())) { + user.meta.icon = "icon-volume-off"; + } self.sendAll("addUser", { name: user.name, rank: user.rank, @@ -2181,7 +2185,7 @@ Channel.prototype.tryChat = function(user, data) { if(!this.hasPermission(user, "chat")) return; - if(user.muted) { + if (this.mutedUsers.contains(user.name.toLowerCase())) { user.socket.emit("noflood", { action: "chat", msg: "You have been muted on this channel." diff --git a/lib/chatcommand.js b/lib/chatcommand.js index b340b38c..5ae799bf 100644 --- a/lib/chatcommand.js +++ b/lib/chatcommand.js @@ -117,7 +117,7 @@ function handleMute(chan, user, args) { return; } person.meta.icon = "icon-volume-off"; - person.muted = true; + chan.mutedUsers.add(person.name.toLowerCase()); chan.broadcastUserUpdate(person); chan.logger.log("*** " + user.name + " muted " + args[0]); } @@ -143,7 +143,7 @@ function handleUnmute(chan, user, args) { return; } person.meta.icon = false; - person.muted = false; + chan.mutedUsers.remove(person.name.toLowerCase()); chan.broadcastUserUpdate(person); chan.logger.log("*** " + user.name + " unmuted " + args[0]); } diff --git a/lib/user.js b/lib/user.js index 1ddf6351..61192353 100644 --- a/lib/user.js +++ b/lib/user.js @@ -33,7 +33,6 @@ var User = function (socket) { afk: false, icon: false }; - this.muted = false; this.throttle = {}; this.flooded = {}; this.queueLimiter = $util.newRateLimiter(); diff --git a/lib/utilities.js b/lib/utilities.js index 04ab6118..253aad61 100644 --- a/lib/utilities.js +++ b/lib/utilities.js @@ -1,3 +1,37 @@ +/* + Set prototype- simple wrapper around JS objects to + manipulate them like a set +*/ +var Set = function (items) { + this._items = {}; + var self = this; + if (items instanceof Array) + items.forEach(function (it) { self.add(it); }); +}; + +Set.prototype.contains = function (what) { + return (what in this._items); +}; + +Set.prototype.add = function (what) { + this._items[what] = true; +}; + +Set.prototype.remove = function (what) { + if (what in this._items) + delete this._items[what]; +}; + +Set.prototype.clear = function () { + this._items = {}; +}; + +Set.prototype.forEach = function (fn) { + for (var k in this._items) { + fn(k); + } +}; + module.exports = { isValidChannelName: function (name) { return name.match(/^[\w-_]{1,30}$/); @@ -127,5 +161,7 @@ module.exports = { default: return ""; } - } + }, + + Set: Set };