Mercurial > hg > rlgwebd
diff rlgwebd.js @ 176:bf518a00190b
Add client-side support for watching dgamelaunch games.
author | John "Elwin" Edwards |
---|---|
date | Wed, 14 Jan 2015 07:44:22 -0500 |
parents | 4dd87508fc96 |
children | 85fde763c7ed |
line wrap: on
line diff
--- 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);