# HG changeset patch # User John "Elwin" Edwards # Date 1340138430 25200 # Node ID 7a50b4412fea10c089d2c1e57dc8b4b37c20b44e # Parent e7c864e80a79c6562cf520c05824c778fbfb1438 Move credentials into the drivers. The session id, or whether the session is currently active on the server, are better handled in the drivers than in termemu.js. diff -r e7c864e80a79 -r 7a50b4412fea rlgterm.js --- a/rlgterm.js Mon Jun 18 16:53:44 2012 -0700 +++ b/rlgterm.js Tue Jun 19 13:40:30 2012 -0700 @@ -71,6 +71,8 @@ /* Login name and key */ var lname = null; var lcred = null; +/* The session id assigned by the server. */ +var sessid = null; function writeData(hexstr) { var codenum; @@ -211,10 +213,10 @@ } function getData() { - if (termemu.sessid == null) + if (sessid == null) return; var datareq = new XMLHttpRequest(); - var msg = JSON.stringify({"id": termemu.sessid, "t": "n"}); + var msg = JSON.stringify({"id": sessid, "t": "n"}); datareq.onreadystatechange = function () { if (datareq.readyState == 4 && datareq.status == 200) { var wasdata = processMsg(datareq.responseText); @@ -243,7 +245,7 @@ function sendback(str) { /* For responding to terminal queries. */ - var msgDict = {"id": termemu.sessid, "t": "d", "n": nsend++, "d": str}; + var msgDict = {"id": sessid, "t": "d", "n": nsend++, "d": str}; var datareq = new XMLHttpRequest(); datareq.onreadystatechange = postResponseHandler; datareq.open('POST', '/feed', true); @@ -252,7 +254,7 @@ } function sendkey(ev) { - if (termemu.sessid == null) + if (sessid == null) return; var keynum = ev.keyCode; var code; @@ -290,10 +292,10 @@ return; } // Isn't this check redundant? - if (termemu.sessid != null) + if (sessid != null) ev.preventDefault(); var datareq = new XMLHttpRequest(); - var msgDict = {"id": termemu.sessid, "t": "d", "n": nsend++, "d": code}; + var msgDict = {"id": sessid, "t": "d", "n": nsend++, "d": code}; datareq.onreadystatechange = postResponseHandler; datareq.open('POST', '/feed', true); datareq.send(JSON.stringify(msgDict)); @@ -305,7 +307,7 @@ } function vkey(c) { - if (termemu.sessid == null) + if (sessid == null) return; var keystr; if (c.match(/^[a-z]$/)) { @@ -343,7 +345,7 @@ else return; var datareq = new XMLHttpRequest(); - var msgDict = {"id": termemu.sessid, "t": "d", "n": nsend++, "d": keystr}; + var msgDict = {"id": sessid, "t": "d", "n": nsend++, "d": keystr}; datareq.onreadystatechange = postResponseHandler; datareq.open('POST', '/feed', true); datareq.send(JSON.stringify(msgDict)); @@ -380,7 +382,7 @@ function formlogin(ev) { ev.preventDefault(); - if (termemu.sessid != null) + if (sessid != null) return; var loginmsg = {}; loginmsg["name"] = document.getElementById("input_name").value; @@ -410,7 +412,7 @@ } function getcurrent() { - if (termemu.sessid) + if (sessid) return; var req = new XMLHttpRequest(); req.onreadystatechange = function () { @@ -454,7 +456,7 @@ } function getchoices() { - if (termemu.sessid != null || !lcred) + if (sessid != null || !lcred) return; var req = new XMLHttpRequest(); req.onreadystatechange = function () { @@ -521,7 +523,7 @@ } function startgame(game) { - if (termemu.sessid != null || !lcred) + if (sessid != null || !lcred) return; var smsg = {}; smsg["key"] = lcred; @@ -535,10 +537,10 @@ var reply = JSON.parse(req.responseText); if (reply.t == 's') { /* Success */ - termemu.sessid = reply.id; + sessid = reply.id; termemu.resize(reply.h, reply.w); setTitle("Playing as " + lname); - debug(1, "Playing with id " + termemu.sessid); + debug(1, "Playing with id " + sessid); setmode("play"); getData(); } @@ -556,7 +558,7 @@ function formreg(ev) { ev.preventDefault(); - if (termemu.sessid != null) + if (sessid != null) return; var regmsg = {}; regmsg["name"] = document.getElementById("regin_name").value; @@ -589,10 +591,10 @@ } function gameover() { - if (termemu.sessid == null) + if (sessid == null) return; /* TODO IFACE2 If the end was unexpected, tell player the game was saved. */ - termemu.sessid = null; + sessid = null; ajaxstate.clear(); setTitle("Game over."); nsend = 0; @@ -609,7 +611,7 @@ } function stop() { - if (!termemu.sessid) + if (!sessid) return; var req = new XMLHttpRequest(); req.onreadystatechange = function () { @@ -619,7 +621,7 @@ } }; req.open('POST', '/feed', true); - req.send(JSON.stringify({"id": termemu.sessid, "t": "q"})); + req.send(JSON.stringify({"id": sessid, "t": "q"})); return; } diff -r e7c864e80a79 -r 7a50b4412fea shterm.js --- a/shterm.js Mon Jun 18 16:53:44 2012 -0700 +++ b/shterm.js Tue Jun 19 13:40:30 2012 -0700 @@ -2,6 +2,7 @@ * is running a shell via the webtty.js server. */ +var isalive = false; // Whether the session is currently active. var nsend = 0; // The number of the next packet to send. var nrecv = 0; // The next packet expected. var msgQ = []; // Queue for out-of-order messages. @@ -147,7 +148,7 @@ } function getData() { - if (!termemu.alive) + if (!isalive) return; var datareq = new XMLHttpRequest(); datareq.onreadystatechange = function () { @@ -157,7 +158,7 @@ return; else if (response.t == "E") { if (response.c == 1) { - termemu.alive = false; + isalive = false; debug(1, "Server error: " + response.s); } } @@ -182,7 +183,7 @@ return; else if (response.t == "E") { if (response.c == 1) { - termemu.alive = false; + isalive = false; debug(1, "Server error: " + response.s); } return; @@ -245,7 +246,7 @@ debug(1, "Ignoring keycode " + keynum); return; } - if (termemu.alive) + if (isalive) ev.preventDefault(); var formdata = {"t": "d", "n": nsend++, "d": code}; var datareq = new XMLHttpRequest(); @@ -333,7 +334,7 @@ } function login(h, w) { - if (termemu.alive) + if (isalive) return; params = {"login": true, "h": h, "w": w}; var req = new XMLHttpRequest(); @@ -343,7 +344,7 @@ if (logindict.login) { /* Success */ termemu.resize(logindict.h, logindict.w); - termemu.alive = true; + isalive = true; nsend = 0; nrecv = 0; setTitle("Logged in"); @@ -366,7 +367,7 @@ if (req.readyState == 4 && req.status == 200) { /* Figure out whether or not it worked. */ /* FIXME the server might respond with output. */ - termemu.alive = false; + isalive = false; return; } }; diff -r e7c864e80a79 -r 7a50b4412fea termemu.js --- a/termemu.js Mon Jun 18 16:53:44 2012 -0700 +++ b/termemu.js Tue Jun 19 13:40:30 2012 -0700 @@ -53,8 +53,6 @@ // An object representing the terminal emulator. var termemu = { - sessid: null, // Session key assigned by the server - alive: false, /* Some elements of the page. */ inwrap: null, // A non-table div wrapping the screen view: null, // The div holding the terminal screen