diff --git a/rlgwebd.js b/rlgwebd.js index e9602ca..b303921 100755 --- a/rlgwebd.js +++ b/rlgwebd.js @@ -54,10 +54,14 @@ var games = { */ function TermSession(game, user, files, dims) { /* First make sure starting the game will work. */ - if (!(game in games)) { + if (game in games) { + this.game = games[game]; + } + else { // TODO: throw an exception instead return null; } + this.player = user; /* This order seems to best avoid race conditions... */ this.alive = false; this.sessid = randkey(); @@ -86,7 +90,7 @@ function TermSession(game, user, files, dims) { childenv["PTYHELPER"] = String(this.h) + "x" + String(this.w); /* TODO handle tty-opening errors */ /* TODO make argument-finding into a method */ - args = [games[game].path, "-n", user.toString()]; + args = [this.game.path, "-n", user.toString()]; this.child = child_process.spawn("/bin/ptyhelper", args, {"env": childenv}); var ss = this; this.alive = true; @@ -558,6 +562,21 @@ function readFeed(res, term) { } } +function statusmsg(req, res) { + var reply = {"s": allowlogin, "g": []}; + for (var sessid in sessions) { + if (sessions[sessid].alive) { + var gamedesc = {}; + gamedesc["p"] = sessions[sessid].player; + gamedesc["g"] = sessions[sessid].game.name; + reply["g"].push(gamedesc); + } + } + res.writeHead(200, { "Content-Type": "application/json" }); + res.write(JSON.stringify(reply)); + res.end(); +} + var errorcodes = [ "Generic Error", "Not logged in", "Invalid data", "Login failed", "Already playing", "Game launch failed", "Server shutting down" ]; @@ -637,10 +656,8 @@ function webHandler(req, res) { } readFeed(res, cterm); } - /* Default page, create a new term */ - /* FIXME New term not created anymore, is a special case still needed? */ - else if (target == '/') { - serveStatic(req, res, "/"); + else if (target == '/status') { + statusmsg(req, res); } else /* Go look for it in the filesystem */ serveStatic(req, res, target);