Add function to clean up and save the games to disk on exit

This commit is contained in:
Oliver-Akins 2020-09-29 22:57:33 -06:00
parent 7696de2284
commit 729f6b7cd5

View file

@ -18,6 +18,18 @@ import { InvestigateAffiliation } from "./events/special/InvestigateLoyalty/Inve
export var active_games: {[key: string]: Game} = {};
const db_dir = `data`;
/**
* This function is called whenever the main node process is terminated for
* whatever reason. It cleans up and writes all the active games to the disk.
*/
function clean_up() {
for (var code in active_games) {
console.log(`Writing game: ${code} to disk`);
writeFileSync(`${db_dir}/${code}`, active_games[code].toJSON());
};
console.log(`Finished saving games to disk.`);
}
const io = sio.listen(3000);
io.on(`connection`, (socket: sio.Socket) => {