comparison rlgwebd.js @ 102:f34a286c51bd

RLG-Web server: code cleanup. Delete some TermSession code left over from the first attempt at Websockets. Also don't bother logging the disconnection of watchers after the game has ended.
author John "Elwin" Edwards <elwin@sdf.org>
date Fri, 13 Jul 2012 08:52:17 -0700
parents e59d68082664
children f30495f7ede8
comparison
equal deleted inserted replaced
101:e59d68082664 102:f34a286c51bd
129 this.record = fs.createWriteStream(ttyrec, { mode: 0664 }); 129 this.record = fs.createWriteStream(ttyrec, { mode: 0664 });
130 /* Holds the output since the last screen clear, so watchers can begin 130 /* Holds the output since the last screen clear, so watchers can begin
131 * with a complete screen. */ 131 * with a complete screen. */
132 this.framebuf = new Buffer(1024); 132 this.framebuf = new Buffer(1024);
133 this.frameoff = 0; 133 this.frameoff = 0;
134 /* List of WebSockets watching the game. */
135 this.watchsocks = [];
136 logins[lkey].sessions.push(this.sessid); 134 logins[lkey].sessions.push(this.sessid);
137 /* END setup */ 135 /* END setup */
138 function ttyrec_chunk(datastr) { 136 function ttyrec_chunk(datastr) {
139 var ts = new Date(); 137 var ts = new Date();
140 var buf = new Buffer(datastr); 138 var buf = new Buffer(datastr);
168 chunk.copy(this.framebuf, this.frameoff); 166 chunk.copy(this.framebuf, this.frameoff);
169 this.frameoff += chunk.length; 167 this.frameoff += chunk.length;
170 }; 168 };
171 this.write = function(data) { 169 this.write = function(data) {
172 this.term.write(data); 170 this.term.write(data);
173 };
174 // WebSocket watchers.
175 this.addWS = function (conn) {
176 this.watchsocks.push(conn);
177 };
178 this.removeWS = function (conn) {
179 var i = this.watchsocks.indexOf(conn);
180 if (i >= 0) {
181 if (conn.connected)
182 conn.close();
183 this.watchsocks.splice(i, 1);
184 return true;
185 }
186 else
187 return false;
188 }; 171 };
189 // Teardown. 172 // Teardown.
190 this.term.on("exit", function () { 173 this.term.on("exit", function () {
191 fs.unlink(ss.lock); 174 fs.unlink(ss.lock);
192 ss.record.end(); 175 ss.record.end();
386 session.on('data', dataH); 369 session.on('data', dataH);
387 session.on('exit', exitH); 370 session.on('exit', exitH);
388 conn.on('close', function(code, desc) { 371 conn.on('close', function(code, desc) {
389 session.removeListener('data', dataH); 372 session.removeListener('data', dataH);
390 session.removeListener('exit', exitH); 373 session.removeListener('exit', exitH);
391 tslog("A WebSocket watcher has left game %d", session.sessid); 374 if (session.sessid in sessions)
375 tslog("A WebSocket watcher has left game %d", session.sessid);
392 }); 376 });
393 conn.sendUTF(JSON.stringify({ 377 conn.sendUTF(JSON.stringify({
394 "t": "w", "w": session.w, "h": session.h, 378 "t": "w", "w": session.w, "h": session.h,
395 "p": session.pname, "g": session.game.uname 379 "p": session.pname, "g": session.game.uname
396 })); 380 }));