# HG changeset patch # User John "Elwin" Edwards # Date 1566782851 14400 # Node ID b04313038a0ba912a0c5f15e6f9b6b6613a54841 # Parent 2667aaad8e08dda3b47951713890217de2f5e698 Changes for compatibility with recent versions of NodeJS. The pty.js module is replaced with node-pty, now-mandatory callbacks are added to various fs functions, and deprecated Buffer() calls are replaced with Buffer.from() or Buffer.alloc(). diff -r 2667aaad8e08 -r b04313038a0b README.txt --- a/README.txt Tue Dec 26 13:23:55 2017 -0500 +++ b/README.txt Sun Aug 25 21:27:31 2019 -0400 @@ -5,9 +5,9 @@ Node --- -RLGWebD currently works with Node v0.10. +RLGWebD is currently being updated to work with Node v10.x. -It requires the 'posix', 'pty.js', and 'websocket' modules. Currently, +It requires the 'posix', 'node-pty', and 'websocket' modules. Currently, it expects them to be installed in "/var/local/lib/node_modules". It is not recommended to run npm as root when installing the modules. diff -r 2667aaad8e08 -r b04313038a0b rlgwebd --- a/rlgwebd Tue Dec 26 13:23:55 2017 -0500 +++ b/rlgwebd Sun Aug 25 21:27:31 2019 -0400 @@ -10,7 +10,7 @@ var child_process = require('child_process'); // Dependencies var posix = require("posix"); -var pty = require("pty.js"); +var pty = require("node-pty"); var WebSocketServer = require("websocket").server; /* Default options */ @@ -44,8 +44,8 @@ rlgwebd_options["use_https"] = true; var clearbufs = [ - new Buffer([27, 91, 72, 27, 91, 50, 74]), // xterm: CSI H CSI 2J - new Buffer([27, 91, 72, 27, 91, 74]) // screen: CSI H CSI J + Buffer.from([27, 91, 72, 27, 91, 50, 74]), // xterm: CSI H CSI 2J + Buffer.from([27, 91, 72, 27, 91, 74]) // screen: CSI H CSI J ]; /* Data on the games available. */ @@ -109,7 +109,7 @@ this.watchers = []; /* replaybuf holds the output since the last screen clear, so watchers can * begin with a complete screen. replaylen is the number of bytes stored. */ - this.replaybuf = new Buffer(1024); + this.replaybuf = Buffer.alloc(1024); this.replaylen = 0; /* Time of last activity. */ this.lasttime = new Date(); @@ -125,12 +125,12 @@ BaseGame.prototype.framepush = function(chunk) { /* If this chunk resets the screen, discard what preceded it. */ if (isclear(chunk)) { - this.replaybuf = new Buffer(1024); + this.replaybuf = Buffer.alloc(1024); this.replaylen = 0; } /* Make sure there's space. */ while (this.replaybuf.length < chunk.length + this.replaylen) { - var nbuf = new Buffer(this.replaybuf.length * 2); + var nbuf = Buffer.alloc(this.replaybuf.length * 2); this.replaybuf.copy(nbuf, 0, 0, this.replaylen); this.replaybuf = nbuf; if (this.replaybuf.length > 65536) { @@ -210,7 +210,9 @@ var progressdir = path.join("/dgldir/inprogress", this.gname); this.lock = path.join(progressdir, this.pname + ":node:" + ts + ".ttyrec"); var lmsg = this.term.pid.toString() + '\n' + this.h + '\n' + this.w + '\n'; - fs.writeFile(this.lock, lmsg, "utf8"); + fs.writeFile(this.lock, lmsg, "utf8", function (err) { + if (err) tslog("Locking failed: %s", err); + }); var ttyrec = path.join("/dgldir/ttyrec", this.pname, this.gname, ts + ".ttyrec"); this.record = fs.createWriteStream(ttyrec, { mode: 0664 }); @@ -238,8 +240,8 @@ /* Currently this also sends to the player and any watchers. */ TermSession.prototype.write_ttyrec = function (datastr) { this.lasttime = new Date(); - var buf = new Buffer(datastr); - var chunk = new Buffer(buf.length + 12); + var buf = Buffer.from(datastr); + var chunk = Buffer.alloc(buf.length + 12); /* TTYREC headers */ chunk.writeUInt32LE(Math.floor(this.lasttime.getTime() / 1000), 0); chunk.writeUInt32LE(1000 * (this.lasttime.getTime() % 1000), 4); @@ -273,7 +275,7 @@ if (hexstr.length % 2 != 0) { hexstr = hexstr.slice(0, -1); } - var keybuf = new Buffer(hexstr, "hex"); + var keybuf = Buffer.from(hexstr, "hex"); this.write(keybuf); } }; @@ -286,7 +288,9 @@ TermSession.prototype.destroy = function () { var tag = this.tag(); - fs.unlink(this.lock); + fs.unlink(this.lock, function (err) { + if (err) tslog("Lock removal failed: %s", err); + }); this.record.end(); var watchsocks = this.watchers; this.watchers = []; @@ -355,7 +359,7 @@ if (this.reading) return; this.reading = true; - var header = new Buffer(12); + var header = Buffer.alloc(12); fs.read(this.fd, header, 0, 12, this.rpos, this.datachunk.bind(this)); }; @@ -376,7 +380,7 @@ // Something is probably wrong... tslog("DGL %s: looking for %d bytes", this.tag(), datalen); } - var databuf = new Buffer(datalen); + var databuf = Buffer.alloc(datalen); fs.read(this.fd, databuf, 0, datalen, this.rpos, this.handledata.bind(this)); }; @@ -419,7 +423,9 @@ if (connlist[i].connected) connlist[i].close(); } - fs.close(this.fd); + fs.close(this.fd, function (err) { + if (err) tslog("PTY close failed: %s", err); + }); this.emit("close"); gamemux.emit('end', this.gname, this.pname); tslog("DGL %s: closed", this.tag()); @@ -690,10 +696,15 @@ function regsetup(username) { function regsetup_l2(err) { for (var g in games) { - fs.mkdir(path.join("/dgldir/ttyrec", username, games[g].uname), 0755); + fs.mkdir(path.join("/dgldir/ttyrec", username, games[g].uname), 0755, + function (err) { + if (err) tslog("ttyrec mkdir failed: %s", err); + }); } } - fs.mkdir(path.join("/dgldir/userdata", username), 0755); + fs.mkdir(path.join("/dgldir/userdata", username), 0755, function (err) { + if (err) tslog("Userdata mkdir failed: %s", err); + }); fs.mkdir(path.join("/dgldir/ttyrec/", username), 0755, regsetup_l2); } @@ -781,7 +792,9 @@ if (err.code == "ESRCH") { var nodere = RegExp("^" + pname + ":node:"); if (fname.match(nodere)) { - fs.unlink(fullfile); + fs.unlink(fullfile, function (err) { + if (err) tslog("Stale lock removal failed: %s", err); + }); } } }