# HG changeset patch # User John "Elwin" Edwards # Date 1421542660 18000 # Node ID 3c0e7697bb308642d9763e66169a6b9a5c625006 # Parent 926b0780bc449adb1a07ec8ca71e6fa936882ead Begin moving TermSession methods into the prototype. This should make a clearer line between general functionality and the initialization of specific instances. diff -r 926b0780bc44 -r 3c0e7697bb30 rlgwebd.js --- a/rlgwebd.js Sat Jan 17 15:48:41 2015 -0500 +++ b/rlgwebd.js Sat Jan 17 19:57:40 2015 -0500 @@ -130,25 +130,6 @@ /* 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); @@ -183,9 +164,6 @@ this.write = function(data) { this.term.write(data); }; - this.tag = function() { - return this.game.uname + "/" + this.pname; - }; // Teardown. this.term.on("exit", function () { var tag = ss.tag(); @@ -251,6 +229,30 @@ }; } TermSession.prototype = new events.EventEmitter(); +TermSession.prototype.tag = function () { + if (this.pname === undefined || this.game === undefined) + return ""; + return this.game.uname + "/" + this.pname; +}; +TermSession.prototype.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 DglSession(filename) { var ss = this;