Implement AFK functionality [Issue #37]

This commit is contained in:
calzoneman 2013-04-19 14:50:08 -05:00
parent fb19822eca
commit 3c4d7073a5
5 changed files with 32 additions and 20 deletions

View File

@ -437,7 +437,8 @@ Channel.prototype.broadcastNewUser = function(user) {
this.sendAll("addUser", {
name: user.name,
rank: user.rank,
leader: this.leader == user
leader: this.leader == user,
meta: user.meta
});
this.sendRankStuff(user);
}
@ -446,7 +447,8 @@ Channel.prototype.broadcastRankUpdate = function(user) {
this.sendAll("updateUser", {
name: user.name,
rank: user.rank,
leader: this.leader == user
leader: this.leader == user,
meta: user.meta
});
this.sendRankStuff(user);
}

View File

@ -23,6 +23,10 @@ function handle(chan, user, msg) {
chan.sendMessage(user.name, msg.substring(5), "shout");
}
}
else if(msg.indexOf("/afk") == 0) {
user.meta.afk = !user.meta.afk;
chan.broadcastRankUpdate(user);
}
else if(msg.indexOf("/m ") == 0) {
if(user.rank >= Rank.Moderator) {
chan.sendMessage(user.name, msg.substring(3), "modflair", {

View File

@ -25,6 +25,9 @@ var User = function(socket, ip) {
this.channel = null;
this.playerReady = false;
this.name = "";
this.meta = {
afk: false
};
this.initCallbacks();
if(Server.announcement != null) {

View File

@ -142,12 +142,12 @@ function initCallbacks() {
socket.on("userlist", function(data) {
$(".userlist_item").each(function() { $(this).remove(); });
for(var i = 0; i < data.length; i++) {
addUser(data[i].name, data[i].rank, data[i].leader);
addUser(data[i]);
}
});
socket.on("addUser", function(data) {
addUser(data.name, data.rank, data.leader);
addUser(data);
});
socket.on("updateUser", function(data) {
@ -178,7 +178,7 @@ function initCallbacks() {
var name = users[i].children[1].innerHTML;
// Reformat user
if(name == data.name) {
formatUserlistItem(users[i], data.rank, data.leader);
formatUserlistItem(users[i], data);
}
}
});

View File

@ -19,16 +19,16 @@ function handleDisconnect() {
}
// Adds a user to the chatbox userlist
function addUser(name, rank, leader) {
function addUser(data) {
var div = $("<div/>").attr("class", "userlist_item");
var flair = $("<span/>").appendTo(div);
var nametag = $("<span/>").text(name).appendTo(div);
formatUserlistItem(div[0], rank, leader);
addUserDropdown(div, name);
var nametag = $("<span/>").text(data.name).appendTo(div);
formatUserlistItem(div[0], data);
addUserDropdown(div, data.name);
var users = $("#userlist").children();
for(var i = 0; i < users.length; i++) {
var othername = users[i].children[1].innerHTML;
if(othername.toLowerCase() > name.toLowerCase()) {
if(othername.toLowerCase() > data.name.toLowerCase()) {
div.insertBefore(users[i]);
return;
}
@ -36,19 +36,22 @@ function addUser(name, rank, leader) {
div.appendTo($("#userlist"));
}
// Format a userlist entry based on a person"s rank
function formatUserlistItem(div, rank, leader) {
// Format a userlist entry based on a person's rank
function formatUserlistItem(div, data) {
var name = div.children[1];
$(name).removeClass();
$(name).addClass(getNameColor(rank));
$(name).css("font-style", "");
$(name).addClass(getNameColor(data.rank));
var flair = div.children[0];
flair.innerHTML = "";
// denote current leader with a star
if(leader) {
if(data.leader) {
$("<i/>").addClass("icon-star-empty").appendTo(flair);
}
else {
flair.innerHTML = "";
if(data.meta.afk) {
$(name).css("font-style", "italic");
$("<i/>").addClass("icon-time").appendTo(flair);
}
}