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", {

11
user.js
View File

@ -1,11 +1,11 @@
/* /*
The MIT License (MIT) The MIT License (MIT)
Copyright (c) 2013 Calvin Montgomery Copyright (c) 2013 Calvin Montgomery
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
@ -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) {
@ -239,7 +242,7 @@ User.prototype.initCallbacks = function() {
this.channel.tryUpdateMotd(this, data); this.channel.tryUpdateMotd(this, data);
} }
}.bind(this)); }.bind(this));
this.socket.on("voteskip", function(data) { this.socket.on("voteskip", function(data) {
if(this.channel != null) { if(this.channel != null) {
this.channel.tryVoteskip(this); this.channel.tryVoteskip(this);

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