diff --git a/src/main.ts b/src/main.ts index 27fe791..16064cc 100644 --- a/src/main.ts +++ b/src/main.ts @@ -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) => {