2023-01-31 22:00:30 -05:00
|
|
|
import * as toml from 'toml';
|
2023-02-02 21:19:55 -05:00
|
|
|
import IConfig from './IConfig.js';
|
2023-01-31 22:00:30 -05:00
|
|
|
import * as fs from "fs";
|
2023-02-02 21:19:55 -05:00
|
|
|
import WSServer from './WSServer.js';
|
|
|
|
|
import QEMUVM from './QEMUVM.js';
|
2023-02-24 22:54:28 -05:00
|
|
|
import log from './log.js';
|
|
|
|
|
|
|
|
|
|
log("INFO", "CollabVM Server starting up");
|
2023-01-31 22:00:30 -05:00
|
|
|
|
|
|
|
|
// Parse the config file
|
|
|
|
|
|
|
|
|
|
var Config : IConfig;
|
|
|
|
|
|
|
|
|
|
if (!fs.existsSync("config.toml")) {
|
2023-02-24 22:54:28 -05:00
|
|
|
log("FATAL", "Config.toml not found. Please copy config.example.toml and fill out fields")
|
2023-01-31 22:00:30 -05:00
|
|
|
process.exit(1);
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
var configRaw = fs.readFileSync("config.toml").toString();
|
|
|
|
|
Config = toml.parse(configRaw);
|
|
|
|
|
} catch (e) {
|
2023-02-24 22:54:28 -05:00
|
|
|
log("FATAL", `Failed to read or parse the config file: ${e}`);
|
2023-01-31 22:00:30 -05:00
|
|
|
process.exit(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2023-02-02 21:19:55 -05:00
|
|
|
async function start() {
|
2023-09-12 00:25:57 +02:00
|
|
|
// Print a warning if qmpSockDir is set
|
|
|
|
|
// and the host OS is Windows, as this
|
|
|
|
|
// configuration will very likely not work.
|
|
|
|
|
if(process.platform === "win32" && Config.vm.qmpSockDir) {
|
|
|
|
|
log("WARN", "You appear to have the option 'qmpSockDir' enabled in the config.")
|
|
|
|
|
log("WARN", "This is not supported on Windows, and you will likely run into issues.");
|
|
|
|
|
log("WARN", "To remove this warning, use the qmpHost and qmpPort options instead.");
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-02 21:19:55 -05:00
|
|
|
// Fire up the VM
|
|
|
|
|
var VM = new QEMUVM(Config);
|
|
|
|
|
await VM.Start();
|
|
|
|
|
|
|
|
|
|
// Start up the websocket server
|
|
|
|
|
var WS = new WSServer(Config, VM);
|
|
|
|
|
WS.listen();
|
|
|
|
|
}
|
|
|
|
|
start();
|