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,
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() {
var total = 0;
var iter = this.playlist.items.first;
@ -1097,15 +1105,24 @@ Channel.prototype.broadcastNewUser = function(user) {
self.kick(user, "You're banned!");
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";
}
self.sendAll("addUser", {
var pkt = {
name: user.name,
rank: user.rank,
meta: user.meta,
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) {
self.saveInitialRank(user);
@ -1119,20 +1136,7 @@ Channel.prototype.broadcastNewUser = function(user) {
msgclass: "server-whisper",
time: Date.now()
};
self.users.forEach(function(u) {
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
self.sendAllWithRank(2, "joinMessage", pkt);
});
}
@ -2323,7 +2327,10 @@ Channel.prototype.trySetRank = function(user, data) {
self.sendAllWithRank(3, "setChannelRank", data);
});
}
self.broadcastUserUpdate(receiver);
self.sendAll("setUserRank", {
name: receiver.name,
rank: receiver.rank
});
} else if(self.registered) {
self.getRank(data.user, function (err, rrank) {
if (self.dead)

View file

@ -119,8 +119,21 @@ function handleShadowMute(chan, user, args) {
});
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.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 = {
username: "[server]",
msg: user.name + " shadow muted " + args[0],
@ -156,7 +169,10 @@ function handleMute(chan, user, args) {
}
person.meta.icon = "icon-volume-off";
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]);
}
}
@ -183,7 +199,10 @@ function handleUnmute(chan, user, args) {
person.meta.icon = false;
chan.mutedUsers.remove(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]);
}
}

View file

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

View file

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

View file

@ -82,7 +82,8 @@ function formatUserlistItem(div) {
name: div.data("name") || "",
rank: div.data("rank"),
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]);
name.removeClass();
@ -125,8 +126,8 @@ function formatUserlistItem(div) {
name.css("font-style", "italic");
$("<i/>").addClass("icon-time").appendTo(flair);
}
if(data.meta && data.meta.icon) {
$("<i/>").addClass(data.meta.icon).prependTo(flair);
if (data.icon) {
$("<i/>").addClass(data.icon).prependTo(flair);
}
}