Change the way /mute works

This commit is contained in:
calzoneman 2013-10-16 17:36:05 -05:00
parent 5eda748fc4
commit 120d56d6c8
5 changed files with 51 additions and 5 deletions

View file

@ -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.

View file

@ -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."

View file

@ -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]);
}

View file

@ -33,7 +33,6 @@ var User = function (socket) {
afk: false,
icon: false
};
this.muted = false;
this.throttle = {};
this.flooded = {};
this.queueLimiter = $util.newRateLimiter();

View file

@ -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
};