Begin work on StartGame event
This commit is contained in:
parent
665b6b163e
commit
d0ed987876
1 changed files with 22 additions and 1 deletions
|
|
@ -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}`,
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
Loading…
Add table
Add a link
Reference in a new issue