Add function to clean up and save the games to disk on exit
This commit is contained in:
parent
7696de2284
commit
729f6b7cd5
1 changed files with 12 additions and 0 deletions
12
src/main.ts
12
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) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue