Mercurial > hg > rlgwebd
comparison rlgwebd.js @ 36:a0387f112bcf
RLG-Web: autosave idle games.
If a game has been idle for too long, close it.
author | John "Elwin" Edwards <elwin@sdf.org> |
---|---|
date | Wed, 06 Jun 2012 10:01:18 -0700 |
parents | 57f4b36ef06b |
children | 353be34de307 |
comparison
equal
deleted
inserted
replaced
35:f15efa4818b4 | 36:a0387f112bcf |
---|---|
18 var chrootDir = "/var/dgl/"; | 18 var chrootDir = "/var/dgl/"; |
19 var dropToUID = 501; | 19 var dropToUID = 501; |
20 var dropToGID = 501; | 20 var dropToGID = 501; |
21 var serveStaticRoot = "/var/www/"; // inside the chroot | 21 var serveStaticRoot = "/var/www/"; // inside the chroot |
22 var passwdfile = "/dgldir/dgl-login"; | 22 var passwdfile = "/dgldir/dgl-login"; |
23 var playtimeout = 3600000; // Idle time before games are autosaved, in ms | |
23 | 24 |
24 /* Global state */ | 25 /* Global state */ |
25 var sessions = {}; | 26 var sessions = {}; |
26 var allowlogin = true; | 27 var allowlogin = true; |
27 | 28 |
199 if (this.alive) | 200 if (this.alive) |
200 this.child.kill('SIGHUP'); | 201 this.child.kill('SIGHUP'); |
201 }; | 202 }; |
202 this.cleanup = function () { | 203 this.cleanup = function () { |
203 /* Call this when the child is dead. */ | 204 /* Call this when the child is dead. */ |
204 if (this.alive) | 205 if (ss.alive) |
205 return; | 206 return; |
206 ss.record.end(); | 207 ss.record.end(); |
207 /* Give the client a chance to read any leftover data. */ | 208 /* Give the client a chance to read any leftover data. */ |
208 if (ss.data.length > 0) | 209 if (ss.data.length > 0) |
209 setTimeout(ss.remove, 8000); | 210 setTimeout(ss.remove, 8000); |
314 } | 315 } |
315 | 316 |
316 function auth(username, password) { | 317 function auth(username, password) { |
317 // Real authentication not implemented | 318 // Real authentication not implemented |
318 return true; | 319 return true; |
320 } | |
321 | |
322 function reaper() { | |
323 var now = new Date(); | |
324 function reapcheck(session) { | |
325 if (!session.alive) | |
326 return; | |
327 fs.fstat(session.record.fd, function (err, stats) { | |
328 if (!err && now - stats.mtime > playtimeout) { | |
329 tslog("Reaping %s", session.sessid); | |
330 session.close(); | |
331 } | |
332 }); | |
333 } | |
334 for (var sessid in sessions) { | |
335 reapcheck(sessions[sessid]); | |
336 } | |
319 } | 337 } |
320 | 338 |
321 function login(req, res, formdata) { | 339 function login(req, res, formdata) { |
322 if (!allowlogin) { | 340 if (!allowlogin) { |
323 sendError(res, 6, null); | 341 sendError(res, 6, null); |
752 process.exit(1); | 770 process.exit(1); |
753 } | 771 } |
754 httpServer = http.createServer(webHandler); | 772 httpServer = http.createServer(webHandler); |
755 httpServer.listen(httpPort); | 773 httpServer.listen(httpPort); |
756 tslog('rlgwebd running on port %d', httpPort); | 774 tslog('rlgwebd running on port %d', httpPort); |
775 setInterval(reaper, playtimeout / 4); | |
757 }); | 776 }); |
758 | 777 |