diff --git a/app/Menu/Menu.js b/app/Menu/Menu.js index 6c1dd74..3dc8c54 100644 --- a/app/Menu/Menu.js +++ b/app/Menu/Menu.js @@ -145,17 +145,20 @@ function (ColorConverter, Exception) { } function populate(list) { + + var html = ""; if(list.length > 0) { for (var i = 0; i < list.length; i++) { var channel = list[i]; - html += ""; - html += ""; - html += channel.name - html += "death match"; + html += ""; + html += "" + channel.name + ""; + html += "death match"; + html += "" + channel.playerCount + ""; + html += ""; }; } else { - html += "No channels found."; + html += "No channels found."; } $("#list").innerHTML = html; diff --git a/app/Server/Coordinator.js b/app/Server/Coordinator.js index cbd039d..a5da29c 100644 --- a/app/Server/Coordinator.js +++ b/app/Server/Coordinator.js @@ -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; diff --git a/app/Server/User.js b/app/Server/User.js index a2e412f..44194a0 100644 --- a/app/Server/User.js +++ b/app/Server/User.js @@ -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; diff --git a/static/html/index.html b/static/html/index.html index 94b9be9..f1d3b36 100644 --- a/static/html/index.html +++ b/static/html/index.html @@ -62,6 +62,7 @@ Name Type + Player