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", { this.sendAll("addUser", {
name: user.name, name: user.name,
rank: user.rank, rank: user.rank,
leader: this.leader == user leader: this.leader == user,
meta: user.meta
}); });
this.sendRankStuff(user); this.sendRankStuff(user);
} }
@ -446,7 +447,8 @@ Channel.prototype.broadcastRankUpdate = function(user) {
this.sendAll("updateUser", { this.sendAll("updateUser", {
name: user.name, name: user.name,
rank: user.rank, rank: user.rank,
leader: this.leader == user leader: this.leader == user,
meta: user.meta
}); });
this.sendRankStuff(user); this.sendRankStuff(user);
} }

View File

@ -23,6 +23,10 @@ function handle(chan, user, msg) {
chan.sendMessage(user.name, msg.substring(5), "shout"); 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) { else if(msg.indexOf("/m ") == 0) {
if(user.rank >= Rank.Moderator) { if(user.rank >= Rank.Moderator) {
chan.sendMessage(user.name, msg.substring(3), "modflair", { chan.sendMessage(user.name, msg.substring(3), "modflair", {

View File

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

View File

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