diff --git a/rlgwebd.js b/rlgwebd.js index 9ae33ee..90129df 100755 --- a/rlgwebd.js +++ b/rlgwebd.js @@ -20,6 +20,7 @@ var dropToUID = 501; var dropToGID = 501; var serveStaticRoot = "/var/www/"; // inside the chroot var passwdfile = "/dgldir/dgl-login"; +var playtimeout = 3600000; // Idle time before games are autosaved, in ms /* Global state */ var sessions = {}; @@ -201,7 +202,7 @@ function TermSession(game, user, files, dims) { }; this.cleanup = function () { /* Call this when the child is dead. */ - if (this.alive) + if (ss.alive) return; ss.record.end(); /* Give the client a chance to read any leftover data. */ @@ -318,6 +319,23 @@ function auth(username, password) { return true; } +function reaper() { + var now = new Date(); + function reapcheck(session) { + if (!session.alive) + return; + fs.fstat(session.record.fd, function (err, stats) { + if (!err && now - stats.mtime > playtimeout) { + tslog("Reaping %s", session.sessid); + session.close(); + } + }); + } + for (var sessid in sessions) { + reapcheck(sessions[sessid]); + } +} + function login(req, res, formdata) { if (!allowlogin) { sendError(res, 6, null); @@ -754,5 +772,6 @@ ctlServer.listen(ctlsocket, function () { httpServer = http.createServer(webHandler); httpServer.listen(httpPort); tslog('rlgwebd running on port %d', httpPort); + setInterval(reaper, playtimeout / 4); });