Display idle time of games in progress.
statusmsg() now includes games' idle times, and the client displays them using getcurrent().
This commit is contained in:
parent
f750d9eb34
commit
2d9c8bd011
3 changed files with 59 additions and 7 deletions
|
|
@ -88,9 +88,9 @@
|
|||
<div class="modal" id="current">
|
||||
<div id="gametable" class="formtable">
|
||||
<div class="tcapt">Games in Progress</div>
|
||||
<div><div>Player</div><div>Game</div><div>Actions</div></div>
|
||||
<div><div>Player</div><div>Game</div><div>Idle time</div><div>Actions</div></div>
|
||||
</div>
|
||||
<div id="nogames">There are no games to watch.</div>
|
||||
<div id="nogames">No one is playing right now.</div>
|
||||
<div class="rfloat"><span class="ibutton" onclick="getcurrent()">Refresh</span></div>
|
||||
</div>
|
||||
<div class="modal" id="startgame">
|
||||
|
|
|
|||
21
rlgterm.js
21
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) {
|
||||
|
|
|
|||
41
rlgwebd.js
41
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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue