RLG-Web: autosave idle games.
If a game has been idle for too long, close it.
This commit is contained in:
parent
520226a343
commit
07c7ea3515
1 changed files with 20 additions and 1 deletions
21
rlgwebd.js
21
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);
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue