mirror of
https://github.com/Pax1601/DCSOlympus.git
synced 2025-10-29 16:56:34 +00:00
102 lines
3.4 KiB
Plaintext
102 lines
3.4 KiB
Plaintext
const yargs = require('yargs');
|
|
var fs = require('fs');
|
|
|
|
/* Define configuration parameter */
|
|
yargs.alias('c', 'config').describe('c', 'olympus.json config location').string('rp');
|
|
args = yargs.argv;
|
|
|
|
console.log('\x1b[36m%s\x1b[0m', "*********************************************************************");
|
|
console.log('\x1b[36m%s\x1b[0m', "* _____ _____ _____ ____ _ *");
|
|
console.log('\x1b[36m%s\x1b[0m', "* | __ \\ / ____|/ ____| / __ \\| | *");
|
|
console.log('\x1b[36m%s\x1b[0m', "* | | | | | | (___ | | | | |_ _ _ __ ___ _ __ _ _ ___ *");
|
|
console.log('\x1b[36m%s\x1b[0m', "* | | | | | \\___ \\ | | | | | | | | '_ ` _ \\| '_ \\| | | / __| *");
|
|
console.log('\x1b[36m%s\x1b[0m', "* | |__| | |____ ____) | | |__| | | |_| | | | | | | |_) | |_| \\__ \\ *");
|
|
console.log('\x1b[36m%s\x1b[0m', "* |_____/ \\_____|_____/ \\____/|_|\\__, |_| |_| |_| .__/ \\__,_|___/ *");
|
|
console.log('\x1b[36m%s\x1b[0m', "* __/ | | | *");
|
|
console.log('\x1b[36m%s\x1b[0m', "* |___/ |_| *");
|
|
console.log('\x1b[36m%s\x1b[0m', "*********************************************************************");
|
|
console.log('\x1b[36m%s\x1b[0m', "");
|
|
console.log("Please wait while DCS Olympus Server starts up...");
|
|
console.log(`Config location: ${args["config"]}`)
|
|
|
|
/* Load the configuration file */
|
|
var frontendPort = 0;
|
|
if (fs.existsSync(args["config"])) {
|
|
var json = JSON.parse(fs.readFileSync(args["config"], 'utf-8'));
|
|
frontendPort = json["frontend"]["port"];
|
|
} else {
|
|
console.log("Failed to read config, aborting!");
|
|
return;
|
|
}
|
|
|
|
/* Load the dependencies. The app is loaded providing the configuration file location */
|
|
var app = require('../app')(args["config"]);
|
|
var debug = require('debug')('client:server');
|
|
var http = require('http');
|
|
|
|
/* Normalize port */
|
|
var port = normalizePort(frontendPort);
|
|
app.set('port', port);
|
|
console.log("Express server listening on port: " + port)
|
|
|
|
/* Create HTTP server */
|
|
var server = http.createServer(app);
|
|
|
|
/* Listen on provided port, on all network interfaces. */
|
|
server.listen(port);
|
|
server.on('error', onError);
|
|
server.on('listening', onListening);
|
|
|
|
/* Normalize a port into a number, string, or false. */
|
|
function normalizePort(val) {
|
|
var port = parseInt(val, 10);
|
|
|
|
if (isNaN(port)) {
|
|
return val;
|
|
}
|
|
|
|
if (port >= 0) {
|
|
return port;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/* Event listener for HTTP server "error" event. */
|
|
function onError(error) {
|
|
if (error.syscall !== 'listen') {
|
|
throw error;
|
|
}
|
|
|
|
var bind = typeof port === 'string'
|
|
? 'Pipe ' + port
|
|
: 'Port ' + port;
|
|
|
|
/* Handle specific listen errors with friendly messages */
|
|
switch (error.code) {
|
|
case 'EACCES':
|
|
console.error(bind + ' requires elevated privileges');
|
|
process.exit(1);
|
|
break;
|
|
case 'EADDRINUSE':
|
|
console.error(bind + ' is already in use');
|
|
process.exit(1);
|
|
break;
|
|
default:
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
/* Event listener for HTTP server "listening" event. */
|
|
function onListening() {
|
|
var addr = server.address();
|
|
var bind = typeof addr === 'string'
|
|
? 'pipe ' + addr
|
|
: 'port ' + addr.port;
|
|
debug('Listening on ' + bind);
|
|
}
|
|
|
|
/* Final user friendly printing */
|
|
console.log("DCS Olympus server {{OLYMPUS_VERSION_NUMBER}}.{{OLYMPUS_COMMIT_HASH}} started correctly!")
|
|
console.log("Waiting for connections...")
|
|
process.title = `DCS Olympus server {{OLYMPUS_VERSION_NUMBER}} (${port})`; |