Continue refactoring, tweak sban

This commit is contained in:
calzoneman 2013-11-09 12:33:18 -06:00
parent 30c5f67d4d
commit b6f4702570
6 changed files with 71 additions and 26 deletions

View file

@ -448,7 +448,10 @@ module.exports = function (Server) {
image: img, image: img,
text: text text: text
}; };
chan.broadcastUserUpdate(user); chan.sendAll("setUserProfile", {
name: user.name,
profile: user.profile
});
} }
} }
} }

View file

@ -1040,6 +1040,14 @@ Channel.prototype.sendAllWithRank = function(rank, msg, data) {
} }
} }
Channel.prototype.sendAllExcept = function(user, msg, data) {
for(var i = 0; i < this.users.length; i++) {
if (this.users[i] !== user) {
this.users[i].socket.emit(msg, data);
}
}
}
Channel.prototype.broadcastPlaylistMeta = function() { Channel.prototype.broadcastPlaylistMeta = function() {
var total = 0; var total = 0;
var iter = this.playlist.items.first; var iter = this.playlist.items.first;
@ -1097,15 +1105,24 @@ Channel.prototype.broadcastNewUser = function(user) {
self.kick(user, "You're banned!"); self.kick(user, "You're banned!");
return; return;
} }
if (self.mutedUsers.contains(user.name.toLowerCase())) { if (self.mutedUsers.contains(user.name.toLowerCase()) ||
self.mutedUsers.contains("[shadow]"+user.name.toLowerCase())) {
user.meta.icon = "icon-volume-off"; user.meta.icon = "icon-volume-off";
} }
self.sendAll("addUser", {
var pkt = {
name: user.name, name: user.name,
rank: user.rank, rank: user.rank,
meta: user.meta, meta: user.meta,
profile: user.profile profile: user.profile
}); };
if (self.mutedUsers.contains("[shadow]"+user.name.toLowerCase())) {
self.sendAllExcept(user, "addUser", pkt);
pkt.meta.icon = false;
user.socket.emit("addUser", pkt);
} else {
self.sendAll("addUser", pkt);
}
if(user.rank > 0) { if(user.rank > 0) {
self.saveInitialRank(user); self.saveInitialRank(user);
@ -1119,20 +1136,7 @@ Channel.prototype.broadcastNewUser = function(user) {
msgclass: "server-whisper", msgclass: "server-whisper",
time: Date.now() time: Date.now()
}; };
self.users.forEach(function(u) { self.sendAllWithRank(2, "joinMessage", pkt);
if(u.rank >= 2) {
u.socket.emit("joinMessage", pkt);
}
});
});
}
Channel.prototype.broadcastUserUpdate = function(user) {
this.sendAll("updateUser", {
name: user.name,
rank: user.rank,
meta: user.meta,
profile: user.profile
}); });
} }
@ -2323,7 +2327,10 @@ Channel.prototype.trySetRank = function(user, data) {
self.sendAllWithRank(3, "setChannelRank", data); self.sendAllWithRank(3, "setChannelRank", data);
}); });
} }
self.broadcastUserUpdate(receiver); self.sendAll("setUserRank", {
name: receiver.name,
rank: receiver.rank
});
} else if(self.registered) { } else if(self.registered) {
self.getRank(data.user, function (err, rrank) { self.getRank(data.user, function (err, rrank) {
if (self.dead) if (self.dead)

View file

@ -119,8 +119,21 @@ function handleShadowMute(chan, user, args) {
}); });
return; return;
} }
/* Reset a previous regular mute */
if (chan.mutedUsers.contains(person.name.toLowerCase())) {
chan.mutedUsers.remove(person.name.toLowerCase());
chan.sendAll("setUserIcon", {
name: person.name,
icon: false
});
}
chan.mutedUsers.add("[shadow]" + person.name.toLowerCase()); chan.mutedUsers.add("[shadow]" + person.name.toLowerCase());
chan.logger.log("*** " + user.name + " shadow muted " + args[0]); chan.logger.log("*** " + user.name + " shadow muted " + args[0]);
person.meta.icon = "icon-volume-off";
chan.sendAllExcept(person, "setUserIcon", {
name: person.name,
icon: "icon-volume-off"
});
var pkt = { var pkt = {
username: "[server]", username: "[server]",
msg: user.name + " shadow muted " + args[0], msg: user.name + " shadow muted " + args[0],
@ -156,7 +169,10 @@ function handleMute(chan, user, args) {
} }
person.meta.icon = "icon-volume-off"; person.meta.icon = "icon-volume-off";
chan.mutedUsers.add(person.name.toLowerCase()); chan.mutedUsers.add(person.name.toLowerCase());
chan.broadcastUserUpdate(person); chan.sendAll("setUserIcon", {
name: person.name,
icon: "icon-volume-off"
});
chan.logger.log("*** " + user.name + " muted " + args[0]); chan.logger.log("*** " + user.name + " muted " + args[0]);
} }
} }
@ -183,7 +199,10 @@ function handleUnmute(chan, user, args) {
person.meta.icon = false; person.meta.icon = false;
chan.mutedUsers.remove(person.name.toLowerCase()); chan.mutedUsers.remove(person.name.toLowerCase());
chan.mutedUsers.remove("[shadow]" + person.name.toLowerCase()); chan.mutedUsers.remove("[shadow]" + person.name.toLowerCase());
chan.broadcastUserUpdate(person); chan.sendAll("setUserIcon", {
name: person.name,
icon: false
});
chan.logger.log("*** " + user.name + " unmuted " + args[0]); chan.logger.log("*** " + user.name + " unmuted " + args[0]);
} }
} }

View file

@ -589,8 +589,12 @@ User.prototype.initCallbacks = function () {
self.rank = rank; self.rank = rank;
self.socket.emit("rank", rank); self.socket.emit("rank", rank);
if (self.inChannel()) if (self.inChannel()) {
self.channel.broadcastUserUpdate(self); self.channel.sendAll("setUserRank", {
name: self.name,
rank: rank
});
}
}); });
}; };

View file

@ -677,6 +677,7 @@ Callbacks = {
div.data("rank", data.rank); div.data("rank", data.rank);
div.data("leader", false); div.data("leader", false);
div.data("profile", data.profile); div.data("profile", data.profile);
div.data("icon", data.meta.icon);
formatUserlistItem(div, data); formatUserlistItem(div, data);
addUserDropdown(div, data); addUserDropdown(div, data);
div.appendTo($("#userlist")); div.appendTo($("#userlist"));
@ -726,6 +727,16 @@ Callbacks = {
sortUserlist(); sortUserlist();
}, },
setUserIcon: function (data) {
var user = findUserlistItem(data.name);
if (user === null) {
return;
}
user.data("icon", data.icon);
formatUserlistItem(user);
},
updateUser: function(data) { updateUser: function(data) {
if(data.name == CLIENT.name) { if(data.name == CLIENT.name) {
CLIENT.leader = data.leader; CLIENT.leader = data.leader;

View file

@ -82,7 +82,8 @@ function formatUserlistItem(div) {
name: div.data("name") || "", name: div.data("name") || "",
rank: div.data("rank"), rank: div.data("rank"),
profile: div.data("profile") || { image: "", text: ""}, profile: div.data("profile") || { image: "", text: ""},
leader: div.data("leader") || false leader: div.data("leader") || false,
icon: div.data("icon") || false
}; };
var name = $(div.children()[1]); var name = $(div.children()[1]);
name.removeClass(); name.removeClass();
@ -125,8 +126,8 @@ function formatUserlistItem(div) {
name.css("font-style", "italic"); name.css("font-style", "italic");
$("<i/>").addClass("icon-time").appendTo(flair); $("<i/>").addClass("icon-time").appendTo(flair);
} }
if(data.meta && data.meta.icon) { if (data.icon) {
$("<i/>").addClass(data.meta.icon).prependTo(flair); $("<i/>").addClass(data.icon).prependTo(flair);
} }
} }