Begin work on StartGame event

This commit is contained in:
Oliver-Akins 2020-10-09 16:19:21 -06:00
parent 665b6b163e
commit d0ed987876

View file

@ -1,4 +1,25 @@
import { Server, Socket } from 'socket.io'; import { Server, Socket } from 'socket.io';
import { active_games, log } from '../main';
export const StartGame = (io: Server, socket: Socket, data: StartGame) => { export const StartGame = (io: Server, socket: Socket, data: StartGame) => {
console.log(`Game starting`); try {
let gc = data.game_code;
// Ensure game is active
if (active_games[gc] == null) {
log.error(`Cannot start an unknown game. (code: ${gc})`);
socket.emit(`GameStartError`, {
success: false,
message: `Cannot start game with an unknown game code.`,
});
return;
};
} catch (err) {
log.prettyError(err);
socket.emit(`GameStartError`, {
success: false,
message: `${err.name}: ${err.message}`,
});
}
}; };