RLG-Web: delay removing TermSessions until the client is informed.
Add a TermSession.sendq flag that indicates whether a type q message has been sent to the client. Don't immediately destroy the TermSession on child exit if the message hasn't been sent. This is an ugly hack until the TermSession class is separated into an EventEmitter to handle the PTY and a listening object that handles communication with the client. That will also allow other clients to watch the game.
This commit is contained in:
parent
74ee771a72
commit
c7cb905b29
1 changed files with 7 additions and 2 deletions
|
|
@ -72,6 +72,8 @@ function TermSession(game, user, dims, lkey) {
|
||||||
this.key = lkey;
|
this.key = lkey;
|
||||||
/* This order seems to best avoid race conditions... */
|
/* This order seems to best avoid race conditions... */
|
||||||
this.alive = false;
|
this.alive = false;
|
||||||
|
// A kludge until TermSession is rewritten to handle real watching.
|
||||||
|
this.sendq = false;
|
||||||
this.sessid = randkey(2);
|
this.sessid = randkey(2);
|
||||||
while (this.sessid in sessions) {
|
while (this.sessid in sessions) {
|
||||||
this.sessid = randkey(2);
|
this.sessid = randkey(2);
|
||||||
|
|
@ -218,7 +220,7 @@ function TermSession(game, user, dims, lkey) {
|
||||||
return;
|
return;
|
||||||
ss.record.end();
|
ss.record.end();
|
||||||
/* Give the client a chance to read any leftover data. */
|
/* Give the client a chance to read any leftover data. */
|
||||||
if (ss.data.length > 0)
|
if (ss.data.length > 0 || !ss.sendq)
|
||||||
setTimeout(ss.remove, 8000);
|
setTimeout(ss.remove, 8000);
|
||||||
else
|
else
|
||||||
ss.remove();
|
ss.remove();
|
||||||
|
|
@ -582,6 +584,7 @@ function endgame(term, res) {
|
||||||
res.writeHead(200, resheaders);
|
res.writeHead(200, resheaders);
|
||||||
res.write(JSON.stringify({"t": "q"}));
|
res.write(JSON.stringify({"t": "q"}));
|
||||||
res.end();
|
res.end();
|
||||||
|
term.sendq = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -653,8 +656,10 @@ function readFeed(res, term) {
|
||||||
if (term.alive)
|
if (term.alive)
|
||||||
reply.t = "n";
|
reply.t = "n";
|
||||||
else {
|
else {
|
||||||
if (allowlogin)
|
if (allowlogin) {
|
||||||
reply.t = "q";
|
reply.t = "q";
|
||||||
|
term.sendq = true;
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
sendError(res, 6, null);
|
sendError(res, 6, null);
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue