Print metadata at the beginning of ttyrec files.
This commit is contained in:
parent
a5bb3837ff
commit
071f4c5fbf
1 changed files with 30 additions and 19 deletions
49
rlgwebd.js
49
rlgwebd.js
|
|
@ -66,6 +66,8 @@ var dglgames = {};
|
||||||
var allowlogin = true;
|
var allowlogin = true;
|
||||||
var gamemux = new events.EventEmitter();
|
var gamemux = new events.EventEmitter();
|
||||||
|
|
||||||
|
/* TODO move TermSession and DglSession methods into the prototypes. */
|
||||||
|
|
||||||
/* Constructor. A TermSession handles a pty and the game running on it.
|
/* Constructor. A TermSession handles a pty and the game running on it.
|
||||||
* gname: (String) Name of the game to launch.
|
* gname: (String) Name of the game to launch.
|
||||||
* pname: (String) The player's name.
|
* pname: (String) The player's name.
|
||||||
|
|
@ -128,6 +130,25 @@ function TermSession(gname, pname, wsReq) {
|
||||||
/* Array for watcher connections. */
|
/* Array for watcher connections. */
|
||||||
this.watchers = [];
|
this.watchers = [];
|
||||||
/* END setup */
|
/* END setup */
|
||||||
|
this.framepush = function(chunk) {
|
||||||
|
/* If this chunk resets the screen, discard what preceded it. */
|
||||||
|
if (isclear(chunk)) {
|
||||||
|
this.framebuf = new Buffer(1024);
|
||||||
|
this.frameoff = 0;
|
||||||
|
}
|
||||||
|
/* Make sure there's space. */
|
||||||
|
while (this.framebuf.length < chunk.length + this.frameoff) {
|
||||||
|
var nbuf = new Buffer(this.framebuf.length * 2);
|
||||||
|
this.framebuf.copy(nbuf, 0, 0, this.frameoff);
|
||||||
|
this.framebuf = nbuf;
|
||||||
|
if (this.framebuf.length > 65536) {
|
||||||
|
tslog("Warning: Game %s frame buffer at %d bytes", this.tag(),
|
||||||
|
this.framebuf.length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
chunk.copy(this.framebuf, this.frameoff);
|
||||||
|
this.frameoff += chunk.length;
|
||||||
|
};
|
||||||
function ttyrec_chunk(datastr) {
|
function ttyrec_chunk(datastr) {
|
||||||
ss.lasttime = new Date();
|
ss.lasttime = new Date();
|
||||||
var buf = new Buffer(datastr);
|
var buf = new Buffer(datastr);
|
||||||
|
|
@ -149,26 +170,16 @@ function TermSession(gname, pname, wsReq) {
|
||||||
}
|
}
|
||||||
ss.emit('data', buf);
|
ss.emit('data', buf);
|
||||||
}
|
}
|
||||||
|
/* Begin the ttyrec with some metadata, like dgamelaunch does. */
|
||||||
|
var descstr = "\x1b[2J\x1b[1;1H\r\n";
|
||||||
|
descstr += "Player: " + this.pname + "\r\nGame: " + this.game.name + "\r\n";
|
||||||
|
descstr += "Server: Roguelike Gallery - rlgallery.org\r\n";
|
||||||
|
descstr += "Filename: " + ts + ".ttyrec\r\n";
|
||||||
|
descstr += "Time: (" + Math.floor(this.lasttime.getTime() / 1000) + ") ";
|
||||||
|
descstr += this.lasttime.toUTCString().slice(0, -4) + "\r\n";
|
||||||
|
descstr += "Size: " + this.w + "x" + this.h + "\r\n\x1b[2J";
|
||||||
|
ttyrec_chunk(descstr);
|
||||||
this.term.on("data", ttyrec_chunk);
|
this.term.on("data", ttyrec_chunk);
|
||||||
this.framepush = function(chunk) {
|
|
||||||
/* If this chunk resets the screen, discard what preceded it. */
|
|
||||||
if (isclear(chunk)) {
|
|
||||||
this.framebuf = new Buffer(1024);
|
|
||||||
this.frameoff = 0;
|
|
||||||
}
|
|
||||||
/* Make sure there's space. */
|
|
||||||
while (this.framebuf.length < chunk.length + this.frameoff) {
|
|
||||||
var nbuf = new Buffer(this.framebuf.length * 2);
|
|
||||||
this.framebuf.copy(nbuf, 0, 0, this.frameoff);
|
|
||||||
this.framebuf = nbuf;
|
|
||||||
if (this.framebuf.length > 65536) {
|
|
||||||
tslog("Warning: Game %s frame buffer at %d bytes", this.tag(),
|
|
||||||
this.framebuf.length);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
chunk.copy(this.framebuf, this.frameoff);
|
|
||||||
this.frameoff += chunk.length;
|
|
||||||
};
|
|
||||||
this.write = function(data) {
|
this.write = function(data) {
|
||||||
this.term.write(data);
|
this.term.write(data);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue