Implement a GetHand event.
This commit is contained in:
parent
0abb127f8e
commit
b0b8b1296e
1 changed files with 32 additions and 0 deletions
32
server/src/events/GetHand.ts
Normal file
32
server/src/events/GetHand.ts
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
import { Server, Socket } from 'socket.io';
|
||||||
|
import { games, log } from '../main';
|
||||||
|
|
||||||
|
export default (io: Server, socket: Socket, data: GetHand) => {
|
||||||
|
try {
|
||||||
|
if (!games[data.game_code]) {
|
||||||
|
log.debug(`Can't find game with code: ${data.game_code}`);
|
||||||
|
socket.emit(`UpdateHand`, {
|
||||||
|
status: 404,
|
||||||
|
message: `Can't find game with code: ${data.game_code}`,
|
||||||
|
source: `GetHand`
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
let game = games[data.game_code];
|
||||||
|
let hand = game.teams[data.team - 1].hand;
|
||||||
|
|
||||||
|
game.log.silly(`Client requested guesser hand`);
|
||||||
|
socket.emit(`UpdateHand`, {
|
||||||
|
status: 200,
|
||||||
|
mode: "replace",
|
||||||
|
questions: hand
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
socket.emit(`QuestionList`, {
|
||||||
|
status: 500,
|
||||||
|
message: `${err.name}: ${err.message}`,
|
||||||
|
source: `GetQuestions`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
Loading…
Add table
Add a link
Reference in a new issue