rlgwebd: use some newer Javascript features.
This commit is contained in:
parent
9004afebdc
commit
c38fb5d107
1 changed files with 28 additions and 26 deletions
54
rlgwebd
54
rlgwebd
|
|
@ -1,17 +1,21 @@
|
||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
var http = require('http');
|
const http = require('http');
|
||||||
var https = require('https');
|
const https = require('https');
|
||||||
var net = require('net');
|
const net = require('net');
|
||||||
var url = require('url');
|
const url = require('url');
|
||||||
var path = require('path');
|
const path = require('path');
|
||||||
var fs = require('fs');
|
const fs = require('fs');
|
||||||
var events = require('events');
|
const events = require('events');
|
||||||
var child_process = require('child_process');
|
const child_process = require('child_process');
|
||||||
// Dependencies
|
// Dependencies
|
||||||
var posix = require("posix");
|
const posix = require("posix");
|
||||||
var pty = require("node-pty");
|
const pty = require("node-pty");
|
||||||
var WebSocketServer = require("websocket").server;
|
const WebSocketServer = require("websocket").server;
|
||||||
|
|
||||||
|
const errorcodes = [ "Generic Error", "Not logged in", "Invalid data",
|
||||||
|
"Login failed", "Already playing", "Game launch failed",
|
||||||
|
"Server shutting down", "Game not in progress" ];
|
||||||
|
|
||||||
/* Default options */
|
/* Default options */
|
||||||
var rlgwebd_options = {
|
var rlgwebd_options = {
|
||||||
|
|
@ -23,12 +27,12 @@ var rlgwebd_options = {
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Read configuration from a file */
|
/* Read configuration from a file */
|
||||||
var config_file = "/etc/rlgwebd.conf";
|
const config_file = "/etc/rlgwebd.conf";
|
||||||
var config_lines = read_or_die(config_file, "Configuration file").toString().split('\n');
|
var config_lines = read_or_die(config_file, "Configuration file").toString().split('\n');
|
||||||
|
|
||||||
for (var i = 0; i < config_lines.length; i++) {
|
for (let conf_line of config_lines) {
|
||||||
if (config_lines[i].length > 0 && config_lines[i][0] != '#') {
|
if (conf_line.length > 0 && conf_line[0] != '#') {
|
||||||
var config_fields = config_lines[i].split('=');
|
var config_fields = conf_line.split('=');
|
||||||
if (config_fields.length < 2)
|
if (config_fields.length < 2)
|
||||||
continue;
|
continue;
|
||||||
var option_name = config_fields[0].trim();
|
var option_name = config_fields[0].trim();
|
||||||
|
|
@ -43,13 +47,13 @@ if ("domain_name" in rlgwebd_options && "keyfile" in rlgwebd_options &&
|
||||||
"certfile" in rlgwebd_options)
|
"certfile" in rlgwebd_options)
|
||||||
rlgwebd_options["use_https"] = true;
|
rlgwebd_options["use_https"] = true;
|
||||||
|
|
||||||
var clearbufs = [
|
const clearbufs = [
|
||||||
Buffer.from([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
|
||||||
Buffer.from([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. */
|
||||||
var games = {
|
const games = {
|
||||||
"rogue3": {
|
"rogue3": {
|
||||||
"name": "Rogue V3",
|
"name": "Rogue V3",
|
||||||
"uname": "rogue3",
|
"uname": "rogue3",
|
||||||
|
|
@ -397,9 +401,9 @@ DglSession.prototype.handledata = function (err, n, buf) {
|
||||||
/* Process the data */
|
/* Process the data */
|
||||||
this.framepush(buf);
|
this.framepush(buf);
|
||||||
var wmsg = JSON.stringify({"t": "d", "d": buf.toString("hex")});
|
var wmsg = JSON.stringify({"t": "d", "d": buf.toString("hex")});
|
||||||
for (var i = 0; i < this.watchers.length; i++) {
|
for (let watcher of this.watchers) {
|
||||||
if (this.watchers[i].connected)
|
if (watcher.connected)
|
||||||
this.watchers[i].sendUTF(wmsg);
|
watcher.sendUTF(wmsg);
|
||||||
}
|
}
|
||||||
this.emit("data", buf);
|
this.emit("data", buf);
|
||||||
/* Recurse. */
|
/* Recurse. */
|
||||||
|
|
@ -575,8 +579,8 @@ function bufncmp(buf1, buf2, n) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function isclear(buf) {
|
function isclear(buf) {
|
||||||
for (var i = 0; i < clearbufs.length; i++) {
|
for (let clearer of clearbufs) {
|
||||||
if (bufncmp(buf, clearbufs[i], clearbufs[i].length))
|
if (bufncmp(buf, clearer, clearer.length))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -847,6 +851,8 @@ function startProgressWatcher() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function serveStatic(req, res, fname) {
|
function serveStatic(req, res, fname) {
|
||||||
|
if (fname[0] !== "/")
|
||||||
|
fname = "/" + fname;
|
||||||
var nname = path.normalize(fname);
|
var nname = path.normalize(fname);
|
||||||
if (nname == "" || nname == "/")
|
if (nname == "" || nname == "/")
|
||||||
nname = "index.html";
|
nname = "index.html";
|
||||||
|
|
@ -1039,10 +1045,6 @@ function setuinfo(req, res, postdata) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var errorcodes = [ "Generic Error", "Not logged in", "Invalid data",
|
|
||||||
"Login failed", "Already playing", "Game launch failed",
|
|
||||||
"Server shutting down", "Game not in progress" ];
|
|
||||||
|
|
||||||
function sendError(res, ecode, msg, box) {
|
function sendError(res, ecode, msg, box) {
|
||||||
res.writeHead(200, { "Content-Type": "application/json" });
|
res.writeHead(200, { "Content-Type": "application/json" });
|
||||||
var edict = {"t": "E"};
|
var edict = {"t": "E"};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue