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().
This commit is contained in:
parent
4940bf86ae
commit
f2256500e1
2 changed files with 32 additions and 19 deletions
|
|
@ -5,9 +5,9 @@ browser. It is intended to be compatible with dgamelaunch.
|
||||||
|
|
||||||
Node
|
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
|
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.
|
is not recommended to run npm as root when installing the modules.
|
||||||
|
|
||||||
|
|
|
||||||
47
rlgwebd
47
rlgwebd
|
|
@ -10,7 +10,7 @@ var events = require('events');
|
||||||
var child_process = require('child_process');
|
var child_process = require('child_process');
|
||||||
// Dependencies
|
// Dependencies
|
||||||
var posix = require("posix");
|
var posix = require("posix");
|
||||||
var pty = require("pty.js");
|
var pty = require("node-pty");
|
||||||
var WebSocketServer = require("websocket").server;
|
var WebSocketServer = require("websocket").server;
|
||||||
|
|
||||||
/* Default options */
|
/* Default options */
|
||||||
|
|
@ -44,8 +44,8 @@ if ("domain_name" in rlgwebd_options && "keyfile" in rlgwebd_options &&
|
||||||
rlgwebd_options["use_https"] = true;
|
rlgwebd_options["use_https"] = true;
|
||||||
|
|
||||||
var clearbufs = [
|
var clearbufs = [
|
||||||
new Buffer([27, 91, 72, 27, 91, 50, 74]), // xterm: CSI H CSI 2J
|
Buffer.from([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, 74]) // screen: CSI H CSI J
|
||||||
];
|
];
|
||||||
|
|
||||||
/* Data on the games available. */
|
/* Data on the games available. */
|
||||||
|
|
@ -109,7 +109,7 @@ function BaseGame() {
|
||||||
this.watchers = [];
|
this.watchers = [];
|
||||||
/* replaybuf holds the output since the last screen clear, so watchers can
|
/* replaybuf holds the output since the last screen clear, so watchers can
|
||||||
* begin with a complete screen. replaylen is the number of bytes stored. */
|
* 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;
|
this.replaylen = 0;
|
||||||
/* Time of last activity. */
|
/* Time of last activity. */
|
||||||
this.lasttime = new Date();
|
this.lasttime = new Date();
|
||||||
|
|
@ -125,12 +125,12 @@ BaseGame.prototype.tag = function () {
|
||||||
BaseGame.prototype.framepush = function(chunk) {
|
BaseGame.prototype.framepush = function(chunk) {
|
||||||
/* If this chunk resets the screen, discard what preceded it. */
|
/* If this chunk resets the screen, discard what preceded it. */
|
||||||
if (isclear(chunk)) {
|
if (isclear(chunk)) {
|
||||||
this.replaybuf = new Buffer(1024);
|
this.replaybuf = Buffer.alloc(1024);
|
||||||
this.replaylen = 0;
|
this.replaylen = 0;
|
||||||
}
|
}
|
||||||
/* Make sure there's space. */
|
/* Make sure there's space. */
|
||||||
while (this.replaybuf.length < chunk.length + this.replaylen) {
|
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.copy(nbuf, 0, 0, this.replaylen);
|
||||||
this.replaybuf = nbuf;
|
this.replaybuf = nbuf;
|
||||||
if (this.replaybuf.length > 65536) {
|
if (this.replaybuf.length > 65536) {
|
||||||
|
|
@ -210,7 +210,9 @@ function TermSession(gname, pname, wsReq) {
|
||||||
var progressdir = path.join("/dgldir/inprogress", this.gname);
|
var progressdir = path.join("/dgldir/inprogress", this.gname);
|
||||||
this.lock = path.join(progressdir, this.pname + ":node:" + ts + ".ttyrec");
|
this.lock = path.join(progressdir, this.pname + ":node:" + ts + ".ttyrec");
|
||||||
var lmsg = this.term.pid.toString() + '\n' + this.h + '\n' + this.w + '\n';
|
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,
|
var ttyrec = path.join("/dgldir/ttyrec", this.pname, this.gname,
|
||||||
ts + ".ttyrec");
|
ts + ".ttyrec");
|
||||||
this.record = fs.createWriteStream(ttyrec, { mode: 0664 });
|
this.record = fs.createWriteStream(ttyrec, { mode: 0664 });
|
||||||
|
|
@ -238,8 +240,8 @@ TermSession.prototype = new BaseGame();
|
||||||
/* Currently this also sends to the player and any watchers. */
|
/* Currently this also sends to the player and any watchers. */
|
||||||
TermSession.prototype.write_ttyrec = function (datastr) {
|
TermSession.prototype.write_ttyrec = function (datastr) {
|
||||||
this.lasttime = new Date();
|
this.lasttime = new Date();
|
||||||
var buf = new Buffer(datastr);
|
var buf = Buffer.from(datastr);
|
||||||
var chunk = new Buffer(buf.length + 12);
|
var chunk = Buffer.alloc(buf.length + 12);
|
||||||
/* TTYREC headers */
|
/* TTYREC headers */
|
||||||
chunk.writeUInt32LE(Math.floor(this.lasttime.getTime() / 1000), 0);
|
chunk.writeUInt32LE(Math.floor(this.lasttime.getTime() / 1000), 0);
|
||||||
chunk.writeUInt32LE(1000 * (this.lasttime.getTime() % 1000), 4);
|
chunk.writeUInt32LE(1000 * (this.lasttime.getTime() % 1000), 4);
|
||||||
|
|
@ -273,7 +275,7 @@ TermSession.prototype.input_msg = function (message) {
|
||||||
if (hexstr.length % 2 != 0) {
|
if (hexstr.length % 2 != 0) {
|
||||||
hexstr = hexstr.slice(0, -1);
|
hexstr = hexstr.slice(0, -1);
|
||||||
}
|
}
|
||||||
var keybuf = new Buffer(hexstr, "hex");
|
var keybuf = Buffer.from(hexstr, "hex");
|
||||||
this.write(keybuf);
|
this.write(keybuf);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -286,7 +288,9 @@ TermSession.prototype.close = function () {
|
||||||
|
|
||||||
TermSession.prototype.destroy = function () {
|
TermSession.prototype.destroy = function () {
|
||||||
var tag = this.tag();
|
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();
|
this.record.end();
|
||||||
var watchsocks = this.watchers;
|
var watchsocks = this.watchers;
|
||||||
this.watchers = [];
|
this.watchers = [];
|
||||||
|
|
@ -355,7 +359,7 @@ DglSession.prototype.startchunk = function () {
|
||||||
if (this.reading)
|
if (this.reading)
|
||||||
return;
|
return;
|
||||||
this.reading = true;
|
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));
|
fs.read(this.fd, header, 0, 12, this.rpos, this.datachunk.bind(this));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -376,7 +380,7 @@ DglSession.prototype.datachunk = function (err, n, buf) {
|
||||||
// Something is probably wrong...
|
// Something is probably wrong...
|
||||||
tslog("DGL %s: looking for %d bytes", this.tag(), datalen);
|
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));
|
fs.read(this.fd, databuf, 0, datalen, this.rpos, this.handledata.bind(this));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -419,7 +423,9 @@ DglSession.prototype.close = function () {
|
||||||
if (connlist[i].connected)
|
if (connlist[i].connected)
|
||||||
connlist[i].close();
|
connlist[i].close();
|
||||||
}
|
}
|
||||||
fs.close(this.fd);
|
fs.close(this.fd, function (err) {
|
||||||
|
if (err) tslog("PTY close failed: %s", err);
|
||||||
|
});
|
||||||
this.emit("close");
|
this.emit("close");
|
||||||
gamemux.emit('end', this.gname, this.pname);
|
gamemux.emit('end', this.gname, this.pname);
|
||||||
tslog("DGL %s: closed", this.tag());
|
tslog("DGL %s: closed", this.tag());
|
||||||
|
|
@ -690,10 +696,15 @@ function login(req, res, formdata) {
|
||||||
function regsetup(username) {
|
function regsetup(username) {
|
||||||
function regsetup_l2(err) {
|
function regsetup_l2(err) {
|
||||||
for (var g in games) {
|
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);
|
fs.mkdir(path.join("/dgldir/ttyrec/", username), 0755, regsetup_l2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -781,7 +792,9 @@ function stopgame(res, formdata) {
|
||||||
if (err.code == "ESRCH") {
|
if (err.code == "ESRCH") {
|
||||||
var nodere = RegExp("^" + pname + ":node:");
|
var nodere = RegExp("^" + pname + ":node:");
|
||||||
if (fname.match(nodere)) {
|
if (fname.match(nodere)) {
|
||||||
fs.unlink(fullfile);
|
fs.unlink(fullfile, function (err) {
|
||||||
|
if (err) tslog("Stale lock removal failed: %s", err);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue