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.
This commit is contained in:
Oliver-Akins 2020-10-01 21:12:55 -06:00
parent 8fb4c538f0
commit d2b6bfb54f

View file

@ -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})`);