mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 18:47:35 +00:00
added current channel user playing to list. fixes #106
This commit is contained in:
parent
e452399caf
commit
3138509a57
4 changed files with 34 additions and 7 deletions
|
|
@ -145,17 +145,20 @@ function (ColorConverter, Exception) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function populate(list) {
|
function populate(list) {
|
||||||
|
|
||||||
|
|
||||||
var html = "";
|
var html = "";
|
||||||
if(list.length > 0) {
|
if(list.length > 0) {
|
||||||
for (var i = 0; i < list.length; i++) {
|
for (var i = 0; i < list.length; i++) {
|
||||||
var channel = list[i];
|
var channel = list[i];
|
||||||
html += "<tr><td>";
|
html += "<tr>";
|
||||||
html += "<a href='#" + channel.name + "'>";
|
html += "<td><a href='#" + channel.name + "'>" + channel.name + "</a></td>";
|
||||||
html += channel.name
|
html += "<td>death match</td>";
|
||||||
html += "</a></td><td>death match</td></tr>";
|
html += "<td>" + channel.playerCount + "</td>";
|
||||||
|
html += "</tr>";
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
html += "<tr><td colspan='2'>No channels found.</td></tr>";
|
html += "<tr><td colspan='3'>No channels found.</td></tr>";
|
||||||
}
|
}
|
||||||
|
|
||||||
$("#list").innerHTML = html;
|
$("#list").innerHTML = html;
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ function (User, PipeToChannel, Nc, Settings) {
|
||||||
|
|
||||||
function Coordinator() {
|
function Coordinator() {
|
||||||
this.channelPipes = {};
|
this.channelPipes = {};
|
||||||
|
this.users = [];
|
||||||
|
|
||||||
Nc.on(Nc.ns.server.events.controlCommand.coordinator, this.onMessage, this);
|
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) {
|
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) {
|
Coordinator.prototype.assignUserToChannel = function (user, channelName) {
|
||||||
|
|
@ -33,8 +43,18 @@ function (User, PipeToChannel, Nc, Settings) {
|
||||||
Coordinator.prototype.getChannels = function(options) {
|
Coordinator.prototype.getChannels = function(options) {
|
||||||
var list = [];
|
var list = [];
|
||||||
for (var channelName in this.channelPipes) {
|
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({
|
list.push({
|
||||||
name: channelName
|
name: channelName,
|
||||||
|
playerCount: count
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,9 @@ function (Parent, ProtocolHelper, Nc) {
|
||||||
}
|
}
|
||||||
|
|
||||||
User.prototype.onDisconnect = function () {
|
User.prototype.onDisconnect = function () {
|
||||||
|
|
||||||
|
this.coordinator.removeUser(this);
|
||||||
|
|
||||||
if(!this.channelPipe) {
|
if(!this.channelPipe) {
|
||||||
console.warn("Disconnecting user without a channel.");
|
console.warn("Disconnecting user without a channel.");
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -62,6 +62,7 @@
|
||||||
<tr>
|
<tr>
|
||||||
<th>Name</th>
|
<th>Name</th>
|
||||||
<th>Type</th>
|
<th>Type</th>
|
||||||
|
<th>Player</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody id="list"></tbody>
|
<tbody id="list"></tbody>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue