Improve the clear-command recognition.
xterm and screen use different control sequences to clear the screen. Both are now recognized.
This commit is contained in:
parent
c0a0939b0d
commit
a5bb3837ff
1 changed files with 21 additions and 15 deletions
36
rlgwebd.js
36
rlgwebd.js
|
|
@ -20,42 +20,42 @@ var chrootDir = "/var/dgl/";
|
||||||
var dropToUser = "rodney";
|
var dropToUser = "rodney";
|
||||||
var serveStaticRoot = "/var/www/"; // inside the chroot
|
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. */
|
/* Data on the games available. */
|
||||||
var games = {
|
var games = {
|
||||||
"rogue3": {
|
"rogue3": {
|
||||||
"name": "Rogue V3",
|
"name": "Rogue V3",
|
||||||
"uname": "rogue3",
|
"uname": "rogue3",
|
||||||
"suffix": ".r3sav",
|
"suffix": ".r3sav",
|
||||||
"path": "/usr/bin/rogue3",
|
"path": "/usr/bin/rogue3"
|
||||||
"clear": new Buffer([27, 91, 72, 27, 91, 50, 74]) // CSI H CSI 2J
|
|
||||||
},
|
},
|
||||||
"rogue4": {
|
"rogue4": {
|
||||||
"name": "Rogue V4",
|
"name": "Rogue V4",
|
||||||
"uname": "rogue4",
|
"uname": "rogue4",
|
||||||
"suffix": ".r4sav",
|
"suffix": ".r4sav",
|
||||||
"path": "/usr/bin/rogue4",
|
"path": "/usr/bin/rogue4"
|
||||||
"clear": new Buffer([27, 91, 72, 27, 91, 50, 74]) // CSI H CSI 2J
|
|
||||||
},
|
},
|
||||||
"rogue5": {
|
"rogue5": {
|
||||||
"name": "Rogue V5",
|
"name": "Rogue V5",
|
||||||
"uname": "rogue5",
|
"uname": "rogue5",
|
||||||
"suffix": ".r5sav",
|
"suffix": ".r5sav",
|
||||||
"path": "/usr/bin/rogue5",
|
"path": "/usr/bin/rogue5"
|
||||||
"clear": new Buffer([27, 91, 72, 27, 91, 50, 74]) // CSI H CSI 2J
|
|
||||||
},
|
},
|
||||||
"srogue": {
|
"srogue": {
|
||||||
"name": "Super-Rogue",
|
"name": "Super-Rogue",
|
||||||
"uname": "srogue",
|
"uname": "srogue",
|
||||||
"suffix": ".srsav",
|
"suffix": ".srsav",
|
||||||
"path": "/usr/bin/srogue",
|
"path": "/usr/bin/srogue"
|
||||||
"clear": new Buffer([27, 91, 72, 27, 91, 50, 74]) // CSI H CSI 2J
|
|
||||||
},
|
},
|
||||||
"arogue5": {
|
"arogue5": {
|
||||||
"name": "Advanced Rogue 5",
|
"name": "Advanced Rogue 5",
|
||||||
"uname": "arogue5",
|
"uname": "arogue5",
|
||||||
"suffix": ".ar5sav",
|
"suffix": ".ar5sav",
|
||||||
"path": "/usr/bin/arogue5",
|
"path": "/usr/bin/arogue5"
|
||||||
"clear": new Buffer([27, 91, 72, 27, 91, 50, 74]) // CSI H CSI 2J
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -152,7 +152,7 @@ function TermSession(gname, pname, wsReq) {
|
||||||
this.term.on("data", ttyrec_chunk);
|
this.term.on("data", ttyrec_chunk);
|
||||||
this.framepush = function(chunk) {
|
this.framepush = function(chunk) {
|
||||||
/* If this chunk resets the screen, discard what preceded it. */
|
/* 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.framebuf = new Buffer(1024);
|
||||||
this.frameoff = 0;
|
this.frameoff = 0;
|
||||||
}
|
}
|
||||||
|
|
@ -263,9 +263,7 @@ function DglSession(filename) {
|
||||||
this.frameoff = 0;
|
this.frameoff = 0;
|
||||||
this.framepush = function(chunk) {
|
this.framepush = function(chunk) {
|
||||||
/* If this chunk resets the screen, discard what preceded it. */
|
/* If this chunk resets the screen, discard what preceded it. */
|
||||||
var cgame = games[this.gname];
|
if (isclear(chunk)) {
|
||||||
if (bufncmp(chunk, cgame.clear, cgame.clear.length)) {
|
|
||||||
tslog("DGL %s: clearing frame", ss.tag());
|
|
||||||
this.framebuf = new Buffer(1024);
|
this.framebuf = new Buffer(1024);
|
||||||
this.frameoff = 0;
|
this.frameoff = 0;
|
||||||
}
|
}
|
||||||
|
|
@ -300,8 +298,8 @@ function DglSession(filename) {
|
||||||
/* Update timestamp, to within 1 second. */
|
/* Update timestamp, to within 1 second. */
|
||||||
ss.lasttime = new Date(1000 * buf.readUInt32LE(0));
|
ss.lasttime = new Date(1000 * buf.readUInt32LE(0));
|
||||||
var datalen = buf.readUInt32LE(8);
|
var datalen = buf.readUInt32LE(8);
|
||||||
//tslog("Allocating %d bytes", datalen);
|
|
||||||
if (datalen > 16384) {
|
if (datalen > 16384) {
|
||||||
|
// Something is probably wrong...
|
||||||
tslog("DGL %s: looking for %d bytes", ss.tag(), datalen);
|
tslog("DGL %s: looking for %d bytes", ss.tag(), datalen);
|
||||||
}
|
}
|
||||||
var databuf = new Buffer(datalen);
|
var databuf = new Buffer(datalen);
|
||||||
|
|
@ -536,6 +534,14 @@ function bufncmp(buf1, buf2, n) {
|
||||||
return true;
|
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() {
|
function tslog() {
|
||||||
arguments[0] = new Date().toISOString() + ": " + String(arguments[0]);
|
arguments[0] = new Date().toISOString() + ": " + String(arguments[0]);
|
||||||
console.log.apply(console, arguments);
|
console.log.apply(console, arguments);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue