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 dropToGID = 501;
|
||||||
var serveStaticRoot = "/var/www/"; // inside the chroot
|
var serveStaticRoot = "/var/www/"; // inside the chroot
|
||||||
var passwdfile = "/dgldir/dgl-login";
|
var passwdfile = "/dgldir/dgl-login";
|
||||||
|
var playtimeout = 3600000; // Idle time before games are autosaved, in ms
|
||||||
|
|
||||||
/* Global state */
|
/* Global state */
|
||||||
var sessions = {};
|
var sessions = {};
|
||||||
|
|
@ -201,7 +202,7 @@ function TermSession(game, user, files, dims) {
|
||||||
};
|
};
|
||||||
this.cleanup = function () {
|
this.cleanup = function () {
|
||||||
/* Call this when the child is dead. */
|
/* Call this when the child is dead. */
|
||||||
if (this.alive)
|
if (ss.alive)
|
||||||
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. */
|
||||||
|
|
@ -318,6 +319,23 @@ function auth(username, password) {
|
||||||
return true;
|
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) {
|
function login(req, res, formdata) {
|
||||||
if (!allowlogin) {
|
if (!allowlogin) {
|
||||||
sendError(res, 6, null);
|
sendError(res, 6, null);
|
||||||
|
|
@ -754,5 +772,6 @@ ctlServer.listen(ctlsocket, function () {
|
||||||
httpServer = http.createServer(webHandler);
|
httpServer = http.createServer(webHandler);
|
||||||
httpServer.listen(httpPort);
|
httpServer.listen(httpPort);
|
||||||
tslog('rlgwebd running on port %d', httpPort);
|
tslog('rlgwebd running on port %d', httpPort);
|
||||||
|
setInterval(reaper, playtimeout / 4);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue