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
|
||||
|
||||
var http = require('http');
|
||||
var https = require('https');
|
||||
var net = require('net');
|
||||
var url = require('url');
|
||||
var path = require('path');
|
||||
var fs = require('fs');
|
||||
var events = require('events');
|
||||
var child_process = require('child_process');
|
||||
const http = require('http');
|
||||
const https = require('https');
|
||||
const net = require('net');
|
||||
const url = require('url');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const events = require('events');
|
||||
const child_process = require('child_process');
|
||||
// Dependencies
|
||||
var posix = require("posix");
|
||||
var pty = require("node-pty");
|
||||
var WebSocketServer = require("websocket").server;
|
||||
const posix = require("posix");
|
||||
const pty = require("node-pty");
|
||||
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 */
|
||||
var rlgwebd_options = {
|
||||
|
|
@ -23,12 +27,12 @@ var rlgwebd_options = {
|
|||
};
|
||||
|
||||
/* 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');
|
||||
|
||||
for (var i = 0; i < config_lines.length; i++) {
|
||||
if (config_lines[i].length > 0 && config_lines[i][0] != '#') {
|
||||
var config_fields = config_lines[i].split('=');
|
||||
for (let conf_line of config_lines) {
|
||||
if (conf_line.length > 0 && conf_line[0] != '#') {
|
||||
var config_fields = conf_line.split('=');
|
||||
if (config_fields.length < 2)
|
||||
continue;
|
||||
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)
|
||||
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, 74]) // screen: CSI H CSI J
|
||||
];
|
||||
|
||||
/* Data on the games available. */
|
||||
var games = {
|
||||
const games = {
|
||||
"rogue3": {
|
||||
"name": "Rogue V3",
|
||||
"uname": "rogue3",
|
||||
|
|
@ -397,9 +401,9 @@ DglSession.prototype.handledata = function (err, n, buf) {
|
|||
/* Process the data */
|
||||
this.framepush(buf);
|
||||
var wmsg = JSON.stringify({"t": "d", "d": buf.toString("hex")});
|
||||
for (var i = 0; i < this.watchers.length; i++) {
|
||||
if (this.watchers[i].connected)
|
||||
this.watchers[i].sendUTF(wmsg);
|
||||
for (let watcher of this.watchers) {
|
||||
if (watcher.connected)
|
||||
watcher.sendUTF(wmsg);
|
||||
}
|
||||
this.emit("data", buf);
|
||||
/* Recurse. */
|
||||
|
|
@ -575,8 +579,8 @@ function bufncmp(buf1, buf2, n) {
|
|||
}
|
||||
|
||||
function isclear(buf) {
|
||||
for (var i = 0; i < clearbufs.length; i++) {
|
||||
if (bufncmp(buf, clearbufs[i], clearbufs[i].length))
|
||||
for (let clearer of clearbufs) {
|
||||
if (bufncmp(buf, clearer, clearer.length))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
@ -847,6 +851,8 @@ function startProgressWatcher() {
|
|||
}
|
||||
|
||||
function serveStatic(req, res, fname) {
|
||||
if (fname[0] !== "/")
|
||||
fname = "/" + fname;
|
||||
var nname = path.normalize(fname);
|
||||
if (nname == "" || nname == "/")
|
||||
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) {
|
||||
res.writeHead(200, { "Content-Type": "application/json" });
|
||||
var edict = {"t": "E"};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue