Adjust order of operations to set host property of Game.
This commit is contained in:
parent
8812982747
commit
b546123bc9
1 changed files with 5 additions and 5 deletions
|
|
@ -5,16 +5,16 @@ import { conf, games, log } from '../main';
|
||||||
|
|
||||||
export default (io: Server, socket: Socket, data: CreateGame) => {
|
export default (io: Server, socket: Socket, data: CreateGame) => {
|
||||||
try {
|
try {
|
||||||
|
let host = new Player(data.name, socket, true);
|
||||||
|
|
||||||
// Create the game object to save
|
// Create the game object to save
|
||||||
let game = new Game(conf);
|
let game = new Game(conf, host);
|
||||||
games[game.id] = game;
|
games[game.id] = game;
|
||||||
log.info(`New game created with ID ${game.id}`);
|
|
||||||
|
|
||||||
// Register the player with the game
|
|
||||||
let host = new Player(data.name, socket, true);
|
|
||||||
game.players.push(host);
|
game.players.push(host);
|
||||||
|
log.info(`New game created with ID ${game.id} (host=${host.name})`);
|
||||||
|
|
||||||
|
|
||||||
|
socket.join(game.id);
|
||||||
socket.emit(`GameCreated`, {
|
socket.emit(`GameCreated`, {
|
||||||
status: 200,
|
status: 200,
|
||||||
game_code: game.id,
|
game_code: game.id,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue