Delete datastore when it's reloaded
This commit is contained in:
parent
bd70fa5f99
commit
d4356348dc
1 changed files with 9 additions and 1 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
import { readFileSync } from 'fs';
|
|
||||||
import { Game } from '../objects/Game';
|
import { Game } from '../objects/Game';
|
||||||
import { Player } from '../objects/Player';
|
import { Player } from '../objects/Player';
|
||||||
import { Server, Socket } from 'socket.io';
|
import { Server, Socket } from 'socket.io';
|
||||||
|
import { readFileSync, unlinkSync } from 'fs';
|
||||||
import { games, hibernatedGames, log, conf } from '../main';
|
import { games, hibernatedGames, log, conf } from '../main';
|
||||||
|
|
||||||
export default (io: Server, socket: Socket, data: JoinGame) => {
|
export default (io: Server, socket: Socket, data: JoinGame) => {
|
||||||
|
|
@ -68,6 +68,14 @@ export default (io: Server, socket: Socket, data: JoinGame) => {
|
||||||
hibernatedGames.splice(hibernatedIndex, 1);
|
hibernatedGames.splice(hibernatedIndex, 1);
|
||||||
games[game.id] = game;
|
games[game.id] = game;
|
||||||
|
|
||||||
|
// Try removing the file from the directory
|
||||||
|
try {
|
||||||
|
unlinkSync(`${conf.datastores.directory}/${game.id}.${conf.datastores.filetype}`);
|
||||||
|
game.log.info(`Game datastore deleted`);
|
||||||
|
} catch (err) {
|
||||||
|
game.log.prettyError(err);
|
||||||
|
};
|
||||||
|
|
||||||
game.log.info(`Successfully unhibernated`);
|
game.log.info(`Successfully unhibernated`);
|
||||||
socket.join(game.id);
|
socket.join(game.id);
|
||||||
socket.emit(`GameRejoined`, {
|
socket.emit(`GameRejoined`, {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue