Print metadata at the beginning of ttyrec files.

This commit is contained in:
John "Elwin" Edwards 2015-01-17 15:48:41 -05:00
parent a5bb3837ff
commit 071f4c5fbf

View file

@ -66,6 +66,8 @@ var dglgames = {};
var allowlogin = true;
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.
* gname: (String) Name of the game to launch.
* pname: (String) The player's name.
@ -128,6 +130,25 @@ function TermSession(gname, pname, wsReq) {
/* Array for watcher connections. */
this.watchers = [];
/* 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) {
ss.lasttime = new Date();
var buf = new Buffer(datastr);
@ -149,26 +170,16 @@ function TermSession(gname, pname, wsReq) {
}
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.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.term.write(data);
};