changeset 181:926b0780bc44

Print metadata at the beginning of ttyrec files.
author John "Elwin" Edwards
date Sat, 17 Jan 2015 15:48:41 -0500
parents 85fde763c7ed
children 3c0e7697bb30
files rlgwebd.js
diffstat 1 files changed, 30 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/rlgwebd.js	Fri Jan 16 08:25:25 2015 -0500
+++ b/rlgwebd.js	Sat Jan 17 15:48:41 2015 -0500
@@ -66,6 +66,8 @@
 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 @@
   /* 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 @@
     }
     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);
   };