Update GetPlayerList to use the game objects.

This commit is contained in:
Oliver-Akins 2020-10-02 16:50:09 -06:00
parent de3a8ea61e
commit 494a001afd

View file

@ -1,27 +1,27 @@
/*
Get's the current player list. This is only really used by the host. This is
almost never called by the client itself
Get's the current player list for a game.
Emissions:
PlayerListResponse->sender - Sends the list of players to the client
*/
import * as db from '../utils/db';
import { Socket } from 'socket.io';
import { Game } from '../utils/Game';
import { active_games } from '../main';
export const GetPlayerList = (socket: Socket, data: GetPlayerList) => {
try {
if (!db.exists(data.game_code)) {
if (!Object.keys(active_games).includes(data.game_code)) {
socket.emit(`PlayerListResponse`, {
success: false,
message: `Error: ${data.game_code} does not have an active database.`,
message: `Error: ${data.game_code} does not have an active game object.`,
});
} else {
let game: database = db.read(data.game_code);
let game: Game = active_games[data.game_code];
// Respond to client
socket.emit(`PlayerListResponse`, {
success: true,
players: [Object.keys(game.players)],
players: Object.keys(game.players),
});
};
} catch (err) {