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:
parent
8fb4c538f0
commit
d2b6bfb54f
1 changed files with 4 additions and 10 deletions
|
|
@ -13,6 +13,7 @@ that the host is able to just send that to the other players
|
||||||
*/
|
*/
|
||||||
import * as db from '../utils/db';
|
import * as db from '../utils/db';
|
||||||
import { Socket } from 'socket.io';
|
import { Socket } from 'socket.io';
|
||||||
|
import { active_games } from '../main';
|
||||||
import { generate_game_code } from '../utils/gamecode';
|
import { generate_game_code } from '../utils/gamecode';
|
||||||
|
|
||||||
export const HostGame = (socket: Socket, data: HostGame) => {
|
export const HostGame = (socket: Socket, data: HostGame) => {
|
||||||
|
|
@ -24,16 +25,9 @@ export const HostGame = (socket: Socket, data: HostGame) => {
|
||||||
game_code = generate_game_code();
|
game_code = generate_game_code();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Init the database
|
let game = new Game(game_code, data.username)
|
||||||
db.create(game_code);
|
|
||||||
let db_init: database = {
|
active_games[game_code] = game;
|
||||||
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`);
|
|
||||||
|
|
||||||
console.log(`${data.username} created a game. (Gamecode: ${game_code})`);
|
console.log(`${data.username} created a game. (Gamecode: ${game_code})`);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue