comparison rlgwebd.js @ 182:3c0e7697bb30

Begin moving TermSession methods into the prototype. This should make a clearer line between general functionality and the initialization of specific instances.
author John "Elwin" Edwards
date Sat, 17 Jan 2015 19:57:40 -0500
parents 926b0780bc44
children db2f5ab112e9
comparison
equal deleted inserted replaced
181:926b0780bc44 182:3c0e7697bb30
128 this.frameoff = 0; 128 this.frameoff = 0;
129 this.playerconn = wsReq.accept(null, wsReq.origin); 129 this.playerconn = wsReq.accept(null, wsReq.origin);
130 /* Array for watcher connections. */ 130 /* Array for watcher connections. */
131 this.watchers = []; 131 this.watchers = [];
132 /* END setup */ 132 /* END setup */
133 this.framepush = function(chunk) {
134 /* If this chunk resets the screen, discard what preceded it. */
135 if (isclear(chunk)) {
136 this.framebuf = new Buffer(1024);
137 this.frameoff = 0;
138 }
139 /* Make sure there's space. */
140 while (this.framebuf.length < chunk.length + this.frameoff) {
141 var nbuf = new Buffer(this.framebuf.length * 2);
142 this.framebuf.copy(nbuf, 0, 0, this.frameoff);
143 this.framebuf = nbuf;
144 if (this.framebuf.length > 65536) {
145 tslog("Warning: Game %s frame buffer at %d bytes", this.tag(),
146 this.framebuf.length);
147 }
148 }
149 chunk.copy(this.framebuf, this.frameoff);
150 this.frameoff += chunk.length;
151 };
152 function ttyrec_chunk(datastr) { 133 function ttyrec_chunk(datastr) {
153 ss.lasttime = new Date(); 134 ss.lasttime = new Date();
154 var buf = new Buffer(datastr); 135 var buf = new Buffer(datastr);
155 var chunk = new Buffer(buf.length + 12); 136 var chunk = new Buffer(buf.length + 12);
156 /* TTYREC headers */ 137 /* TTYREC headers */
181 ttyrec_chunk(descstr); 162 ttyrec_chunk(descstr);
182 this.term.on("data", ttyrec_chunk); 163 this.term.on("data", ttyrec_chunk);
183 this.write = function(data) { 164 this.write = function(data) {
184 this.term.write(data); 165 this.term.write(data);
185 }; 166 };
186 this.tag = function() {
187 return this.game.uname + "/" + this.pname;
188 };
189 // Teardown. 167 // Teardown.
190 this.term.on("exit", function () { 168 this.term.on("exit", function () {
191 var tag = ss.tag(); 169 var tag = ss.tag();
192 fs.unlink(ss.lock); 170 fs.unlink(ss.lock);
193 ss.record.end(); 171 ss.record.end();
249 }); 227 });
250 this.watchers.push(conn); 228 this.watchers.push(conn);
251 }; 229 };
252 } 230 }
253 TermSession.prototype = new events.EventEmitter(); 231 TermSession.prototype = new events.EventEmitter();
232 TermSession.prototype.tag = function () {
233 if (this.pname === undefined || this.game === undefined)
234 return "";
235 return this.game.uname + "/" + this.pname;
236 };
237 TermSession.prototype.framepush = function(chunk) {
238 /* If this chunk resets the screen, discard what preceded it. */
239 if (isclear(chunk)) {
240 this.framebuf = new Buffer(1024);
241 this.frameoff = 0;
242 }
243 /* Make sure there's space. */
244 while (this.framebuf.length < chunk.length + this.frameoff) {
245 var nbuf = new Buffer(this.framebuf.length * 2);
246 this.framebuf.copy(nbuf, 0, 0, this.frameoff);
247 this.framebuf = nbuf;
248 if (this.framebuf.length > 65536) {
249 tslog("Warning: Game %s frame buffer at %d bytes", this.tag(),
250 this.framebuf.length);
251 }
252 }
253 chunk.copy(this.framebuf, this.frameoff);
254 this.frameoff += chunk.length;
255 };
254 256
255 function DglSession(filename) { 257 function DglSession(filename) {
256 var ss = this; 258 var ss = this;
257 events.EventEmitter.call(this); 259 events.EventEmitter.call(this);
258 var pathcoms = filename.split('/'); 260 var pathcoms = filename.split('/');