0
0
Fork 0

Add cleanup listeners if they are enabled.

This commit is contained in:
Oliver-Akins 2021-01-05 16:54:45 -07:00
parent 7914ff7e45
commit f0f3032465

View file

@ -4,6 +4,7 @@ import { readFileSync } from "fs";
import { Game } from "./objects/Game"; import { Game } from "./objects/Game";
import startWebsocket from "./websocket"; import startWebsocket from "./websocket";
import { Validate } from "./utils/validate"; import { Validate } from "./utils/validate";
import { processExit } from "./utils/cleanup";
export const conf: config = toml.parse(readFileSync(`server.toml`, `utf-8`)); export const conf: config = toml.parse(readFileSync(`server.toml`, `utf-8`));
@ -18,6 +19,17 @@ export const log: Logger = new Logger({
name: `GLOBAL`, name: `GLOBAL`,
}); });
// Ensure the config valid
if (Validate.config(conf)) { if (Validate.config(conf)) {
// Add event listeners if we want to use the datastore saving game system
if (conf.datastores.enabled) {
// Get games from datastore
process.on(`uncaughtException`, processExit);
process.on(`SIGINT`, processExit);
};
startWebsocket(conf); startWebsocket(conf);
} }