diff --git a/index-rlg.html b/index-rlg.html
index 609bfdf..d3c72a2 100644
--- a/index-rlg.html
+++ b/index-rlg.html
@@ -88,9 +88,9 @@
-
There are no games to watch.
+
No one is playing right now.
Refresh
diff --git a/rlgterm.js b/rlgterm.js
index b2d1867..ae83038 100644
--- a/rlgterm.js
+++ b/rlgterm.js
@@ -453,6 +453,7 @@ function getcurrent() {
var cell1 = document.createElement("div");
var cell2 = document.createElement("div");
var cell3 = document.createElement("div");
+ var cell4 = document.createElement("div");
cell1.appendChild(document.createTextNode(reply.g[i].p));
var uname = reply.g[i].g;
if (uname in games)
@@ -461,14 +462,16 @@ function getcurrent() {
debug(1, "Unrecognized game: " + uname);
continue;
}
+ cell3.appendChild(document.createTextNode(idlestr(reply.g[i].i)));
var button = document.createElement("span");
button.appendChild(document.createTextNode("Watch"));
button.onclick = makeWatcher(reply.g[i].n);
button.className = "ibutton";
- cell3.appendChild(button);
+ cell4.appendChild(button);
row.appendChild(cell1);
row.appendChild(cell2);
row.appendChild(cell3);
+ row.appendChild(cell4);
gamediv.appendChild(row);
}
};
@@ -779,6 +782,22 @@ function textsize(larger) {
return;
}
+function idlestr(ms) {
+ if (typeof(ms) != "number")
+ return "?";
+ var seconds = Math.round(ms / 1000);
+ var ss = String(seconds % 60);
+ if (ss.length < 2)
+ ss = "0" + ss;
+ var mm = String(Math.floor((seconds % 3600) / 60));
+ if (mm.length < 2)
+ mm = "0" + mm;
+ var hh = String(Math.floor(seconds / 3600));
+ if (hh.length < 2)
+ hh = "0" + hh;
+ return hh + ":" + mm + ":" + ss;
+}
+
function bell(on) {
var imgnode = document.getElementById("bell");
if (on) {
diff --git a/rlgwebd.js b/rlgwebd.js
index f06cef8..9026fbc 100755
--- a/rlgwebd.js
+++ b/rlgwebd.js
@@ -801,7 +801,24 @@ function readFeed(client, res) {
}
function statusmsg(req, res) {
+ var now = new Date();
var reply = {"s": allowlogin, "g": []};
+ function respond() {
+ res.writeHead(200, { "Content-Type": "application/json" });
+ if (req.method != 'HEAD')
+ res.write(JSON.stringify(reply));
+ res.end();
+ }
+ function idleset(i, idletime) {
+ if (i >= 0 && i < reply.g.length) {
+ reply.g[i].i = idletime;
+ }
+ for (var j = 0; j < reply.g.length; j++) {
+ if (!("i" in reply.g[j]))
+ return;
+ }
+ respond();
+ }
for (var sessid in sessions) {
var gamedesc = {};
gamedesc["n"] = sessid;
@@ -809,10 +826,26 @@ function statusmsg(req, res) {
gamedesc["g"] = sessions[sessid].game.uname;
reply["g"].push(gamedesc);
}
- res.writeHead(200, { "Content-Type": "application/json" });
- if (req.method != 'HEAD')
- res.write(JSON.stringify(reply));
- res.end();
+ if (reply.g.length == 0) {
+ respond();
+ return;
+ }
+ function makecallback(i) {
+ return function (err, stats) {
+ if (err)
+ idleset(i, null);
+ else
+ idleset(i, now - stats.mtime);
+ }
+ }
+ for (var i = 0; i < reply.g.length; i++) {
+ if (reply.g[i].n in sessions) {
+ fs.fstat(sessions[reply.g[i].n].record.fd, makecallback(i));
+ }
+ else {
+ idleset(i, null);
+ }
+ }
}
function pstatusmsg(req, res) {