From d2b6bfb54f8592d354654f009c00b34dd2ada832 Mon Sep 17 00:00:00 2001 From: Oliver-Akins Date: Thu, 1 Oct 2020 21:12:55 -0600 Subject: [PATCH] Switch over to the Game object instead of DB This is to prevent the shit tonne of race conditions that writing to disk would've cause. --- src/events/HostGame.ts | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/events/HostGame.ts b/src/events/HostGame.ts index 927e983..ed76028 100644 --- a/src/events/HostGame.ts +++ b/src/events/HostGame.ts @@ -13,6 +13,7 @@ that the host is able to just send that to the other players */ import * as db from '../utils/db'; import { Socket } from 'socket.io'; +import { active_games } from '../main'; import { generate_game_code } from '../utils/gamecode'; export const HostGame = (socket: Socket, data: HostGame) => { @@ -24,16 +25,9 @@ export const HostGame = (socket: Socket, data: HostGame) => { game_code = generate_game_code(); } - // Init the database - db.create(game_code); - let db_init: database = { - state: `lobby`, - host: data.username, - players: {}, - game_code: game_code - }; - db_init.players[data.username] = { host: true, hitler: false, president: false, chancellor: false }; - db.write(game_code, db_init, `\t`); + let game = new Game(game_code, data.username) + + active_games[game_code] = game; console.log(`${data.username} created a game. (Gamecode: ${game_code})`);