# HG changeset patch
# User John "Elwin" Edwards
# Date 1421239462 18000
# Node ID bf518a00190bc11925af25a5413ccf452408081e
# Parent 4dd87508fc9649caa7eb651f20e63a3e696f88a6
Add client-side support for watching dgamelaunch games.
diff -r 4dd87508fc96 -r bf518a00190b index-rlg.html
--- a/index-rlg.html Tue Jan 13 20:30:10 2015 -0500
+++ b/index-rlg.html Wed Jan 14 07:44:22 2015 -0500
@@ -101,7 +101,7 @@
No one is playing right now.
diff -r 4dd87508fc96 -r bf518a00190b rlgterm.js
--- a/rlgterm.js Tue Jan 13 20:30:10 2015 -0500
+++ b/rlgterm.js Wed Jan 14 07:44:22 2015 -0500
@@ -337,6 +337,7 @@
var cell2 = document.createElement("div");
var cell3 = document.createElement("div");
var cell4 = document.createElement("div");
+ var cell5 = document.createElement("div");
cell1.appendChild(document.createTextNode(gamelist[i].p));
var uname = gamelist[i].g;
if (uname in games)
@@ -344,16 +345,23 @@
else {
continue;
}
- cell3.appendChild(document.createTextNode(idlestr(gamelist[i].i)));
+ var srcstr = "VR";
+ if (gamelist[i].c == "rlg")
+ srcstr = "Web";
+ else if (gamelist[i].c == "dgl")
+ srcstr = "SSH";
+ cell3.appendChild(document.createTextNode(srcstr));
+ cell4.appendChild(document.createTextNode(idlestr(gamelist[i].i)));
var button = document.createElement("span");
button.appendChild(document.createTextNode("Watch"));
button.onclick = makeWatcher(uname + "/" + gamelist[i].p);
button.className = "ibutton";
- cell4.appendChild(button);
+ cell5.appendChild(button);
row.appendChild(cell1);
row.appendChild(cell2);
row.appendChild(cell3);
row.appendChild(cell4);
+ row.appendChild(cell5);
gamediv.appendChild(row);
}
}
@@ -413,6 +421,7 @@
var justbegun = {};
justbegun.g = msg.g;
justbegun.p = msg.p;
+ justbegun.c = msg.c;
justbegun.i = 0;
currentList.push(justbegun);
tableCurrent(currentList);
@@ -873,19 +882,20 @@
}
function idlestr(ms) {
+ /* Minute accuracy is good enough. */
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;
+ var minutes = Math.round(ms / 60000);
+ if (minutes < 60)
+ return String(minutes) + " min";
+ var hours = Math.floor(minutes / 60);
+ if (hours < 24)
+ return String(hours) + " hr " + String(minutes % 60) + " min";
+ var days = Math.floor(days / 24);
+ if (days == 1)
+ return "1 day " + String(hours % 24) + " hr";
+ else
+ return String(days) + " days " + String(hours % 24) + " hr";
}
function bell(on) {
diff -r 4dd87508fc96 -r bf518a00190b rlgwebd.js
--- a/rlgwebd.js Tue Jan 13 20:30:10 2015 -0500
+++ b/rlgwebd.js Wed Jan 14 07:44:22 2015 -0500
@@ -109,7 +109,7 @@
tslog("%s playing %s (pid %d)", this.pname, this.game.uname, this.term.pid);
this.failed = false;
sessions[this.game.uname + "/" + this.pname] = this;
- gamemux.emit('begin', this.game.uname, this.pname);
+ gamemux.emit('begin', this.game.uname, this.pname, 'rlg');
/* Set up the lockfile and ttyrec */
this.lasttime = new Date();
var ts = timestamp(this.lasttime);
@@ -345,6 +345,7 @@
ss.fd = fd;
ss.emit('open', true);
tslog("DGL %s: open", ss.tag());
+ gamemux.emit('begin', ss.gname, ss.pname, 'dgl');
ss.readchunk();
ss.recwatcher = fs.watch(ss.ttyrec, function (ev, finame) {
if (ev == "change")
@@ -368,6 +369,7 @@
}
fs.close(this.fd);
this.emit("close");
+ gamemux.emit('end', this.gname, this.pname);
tslog("DGL %s: closed", ss.tag());
};
this.watchers = [];
@@ -820,22 +822,21 @@
var now = new Date();
var statusinfo = {"s": allowlogin, "g": []};
for (var tag in sessions) {
- var gamedesc = {};
+ var gamedesc = {"c": "rlg"};
gamedesc["p"] = sessions[tag].pname;
gamedesc["g"] = sessions[tag].game.uname;
gamedesc["i"] = now - sessions[tag].lasttime;
gamedesc["w"] = sessions[tag].watchers.length;
statusinfo["g"].push(gamedesc);
}
- statusinfo["dgl"] = [];
for (var tag in dglgames) {
- var dglinfo = {};
+ var dglinfo = {"c": "dgl"};
var slash = tag.search('/');
dglinfo["g"] = tag.slice(0, slash);
dglinfo["p"] = tag.slice(slash + 1);
dglinfo["i"] = now - dglgames[tag].lasttime;
dglinfo["w"] = dglgames[tag].watchers.length;
- statusinfo["dgl"].push(dglinfo);
+ statusinfo["g"].push(dglinfo);
}
callback(statusinfo);
}
@@ -1084,8 +1085,9 @@
conn.sendUTF(JSON.stringify(info));
});
}
- var beginH = function (gname, pname) {
- conn.sendUTF(JSON.stringify({"t": "b", "p": pname, "g": gname}));
+ var beginH = function (gname, pname, client) {
+ conn.sendUTF(JSON.stringify({"t": "b", "c": client, "p": pname,
+ "g": gname}));
};
var listH = function (list) {
conn.sendUTF(JSON.stringify(list));
@@ -1112,11 +1114,11 @@
* complete list. */
function pushStatus() {
var now = new Date();
- var statusinfo = {"t": "p", "s": allowlogin, "g": [], "dgl": []};
+ var statusinfo = {"t": "p", "s": allowlogin, "g": []};
for (var tag in sessions) {
var delta = now - sessions[tag].lasttime;
if (delta < 60000) {
- var gamedesc = {};
+ var gamedesc = {"c": "rlg"};
gamedesc["p"] = sessions[tag].pname;
gamedesc["g"] = sessions[tag].game.uname;
gamedesc["i"] = delta;
@@ -1127,13 +1129,13 @@
for (var tag in dglgames) {
var delta = now - dglgames[tag].lasttime;
if (delta < 60000) {
- var dglinfo = {};
+ var dglinfo = {"c": "dgl"};
var slash = tag.search('/');
dglinfo["g"] = tag.slice(0, slash);
dglinfo["p"] = tag.slice(slash + 1);
dglinfo["i"] = delta;
dglinfo["w"] = dglgames[tag].watchers.length;
- statusinfo["dgl"].push(dglinfo);
+ statusinfo["g"].push(dglinfo);
}
}
gamemux.emit('list', statusinfo);