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 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 @@ function TermSession(gname, pname, wsReq) {
|
|||
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 @@ function DglSession(filename) {
|
|||
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 @@ function DglSession(filename) {
|
|||
/* 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 @@ function bufncmp(buf1, buf2, n) {
|
|||
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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue