added current channel user playing to list. fixes #106

This commit is contained in:
logsol 2015-02-22 19:30:37 +01:00
parent e452399caf
commit 3138509a57
4 changed files with 34 additions and 7 deletions

View file

@ -11,6 +11,7 @@ function (User, PipeToChannel, Nc, Settings) {
function Coordinator() {
this.channelPipes = {};
this.users = [];
Nc.on(Nc.ns.server.events.controlCommand.coordinator, this.onMessage, this);
@ -18,7 +19,16 @@ function (User, PipeToChannel, Nc, Settings) {
}
Coordinator.prototype.createUser = function (socketLink) {
new User(socketLink, this);
this.users.push(new User(socketLink, this));
}
Coordinator.prototype.removeUser = function (user) {
for(var i = 0; i < this.users.length; i++) {
if(this.users[i] === user) {
this.users.splice(i, 1);
break;
}
}
}
Coordinator.prototype.assignUserToChannel = function (user, channelName) {
@ -33,8 +43,18 @@ function (User, PipeToChannel, Nc, Settings) {
Coordinator.prototype.getChannels = function(options) {
var list = [];
for (var channelName in this.channelPipes) {
var count = 0;
for(var i = 0; i < this.users.length; i++) {
if(this.users[i].channelPipe === this.channelPipes[channelName]){
count++;
}
}
list.push({
name: channelName
name: channelName,
playerCount: count
});
}
return list;

View file

@ -40,6 +40,9 @@ function (Parent, ProtocolHelper, Nc) {
}
User.prototype.onDisconnect = function () {
this.coordinator.removeUser(this);
if(!this.channelPipe) {
console.warn("Disconnecting user without a channel.");
return;