Mercurial > hg > rlgwebd
diff rlgwebd.js @ 180:85fde763c7ed
Improve the clear-command recognition.
xterm and screen use different control sequences to clear the screen.
Both are now recognized.
author | John "Elwin" Edwards |
---|---|
date | Fri, 16 Jan 2015 08:25:25 -0500 |
parents | bf518a00190b |
children | 926b0780bc44 |
line wrap: on
line diff
--- a/rlgwebd.js Wed Jan 14 20:45:12 2015 -0500 +++ b/rlgwebd.js Fri Jan 16 08:25:25 2015 -0500 @@ -20,42 +20,42 @@ var dropToUser = "rodney"; var serveStaticRoot = "/var/www/"; // inside the chroot +var clearbufs = [ + new Buffer([27, 91, 72, 27, 91, 50, 74]), // xterm: CSI H CSI 2J + new Buffer([27, 91, 72, 27, 91, 74]) // screen: CSI H CSI J +]; + /* Data on the games available. */ var games = { "rogue3": { "name": "Rogue V3", "uname": "rogue3", "suffix": ".r3sav", - "path": "/usr/bin/rogue3", - "clear": new Buffer([27, 91, 72, 27, 91, 50, 74]) // CSI H CSI 2J + "path": "/usr/bin/rogue3" }, "rogue4": { "name": "Rogue V4", "uname": "rogue4", "suffix": ".r4sav", - "path": "/usr/bin/rogue4", - "clear": new Buffer([27, 91, 72, 27, 91, 50, 74]) // CSI H CSI 2J + "path": "/usr/bin/rogue4" }, "rogue5": { "name": "Rogue V5", "uname": "rogue5", "suffix": ".r5sav", - "path": "/usr/bin/rogue5", - "clear": new Buffer([27, 91, 72, 27, 91, 50, 74]) // CSI H CSI 2J + "path": "/usr/bin/rogue5" }, "srogue": { "name": "Super-Rogue", "uname": "srogue", "suffix": ".srsav", - "path": "/usr/bin/srogue", - "clear": new Buffer([27, 91, 72, 27, 91, 50, 74]) // CSI H CSI 2J + "path": "/usr/bin/srogue" }, "arogue5": { "name": "Advanced Rogue 5", "uname": "arogue5", "suffix": ".ar5sav", - "path": "/usr/bin/arogue5", - "clear": new Buffer([27, 91, 72, 27, 91, 50, 74]) // CSI H CSI 2J + "path": "/usr/bin/arogue5" } }; @@ -152,7 +152,7 @@ this.term.on("data", ttyrec_chunk); this.framepush = function(chunk) { /* If this chunk resets the screen, discard what preceded it. */ - if (bufncmp(chunk, this.game.clear, this.game.clear.length)) { + if (isclear(chunk)) { this.framebuf = new Buffer(1024); this.frameoff = 0; } @@ -263,9 +263,7 @@ this.frameoff = 0; this.framepush = function(chunk) { /* If this chunk resets the screen, discard what preceded it. */ - var cgame = games[this.gname]; - if (bufncmp(chunk, cgame.clear, cgame.clear.length)) { - tslog("DGL %s: clearing frame", ss.tag()); + if (isclear(chunk)) { this.framebuf = new Buffer(1024); this.frameoff = 0; } @@ -300,8 +298,8 @@ /* Update timestamp, to within 1 second. */ ss.lasttime = new Date(1000 * buf.readUInt32LE(0)); var datalen = buf.readUInt32LE(8); - //tslog("Allocating %d bytes", datalen); if (datalen > 16384) { + // Something is probably wrong... tslog("DGL %s: looking for %d bytes", ss.tag(), datalen); } var databuf = new Buffer(datalen); @@ -536,6 +534,14 @@ return true; } +function isclear(buf) { + for (var i = 0; i < clearbufs.length; i++) { + if (bufncmp(buf, clearbufs[i], clearbufs[i].length)) + return true; + } + return false; +} + function tslog() { arguments[0] = new Date().toISOString() + ": " + String(arguments[0]); console.log.apply(console, arguments);