Update GetPlayerList to use the game objects.
This commit is contained in:
parent
de3a8ea61e
commit
494a001afd
1 changed files with 7 additions and 7 deletions
|
|
@ -1,27 +1,27 @@
|
||||||
/*
|
/*
|
||||||
Get's the current player list. This is only really used by the host. This is
|
Get's the current player list for a game.
|
||||||
almost never called by the client itself
|
|
||||||
|
|
||||||
Emissions:
|
Emissions:
|
||||||
PlayerListResponse->sender - Sends the list of players to the client
|
PlayerListResponse->sender - Sends the list of players to the client
|
||||||
*/
|
*/
|
||||||
import * as db from '../utils/db';
|
|
||||||
import { Socket } from 'socket.io';
|
import { Socket } from 'socket.io';
|
||||||
|
import { Game } from '../utils/Game';
|
||||||
|
import { active_games } from '../main';
|
||||||
|
|
||||||
export const GetPlayerList = (socket: Socket, data: GetPlayerList) => {
|
export const GetPlayerList = (socket: Socket, data: GetPlayerList) => {
|
||||||
try {
|
try {
|
||||||
if (!db.exists(data.game_code)) {
|
if (!Object.keys(active_games).includes(data.game_code)) {
|
||||||
socket.emit(`PlayerListResponse`, {
|
socket.emit(`PlayerListResponse`, {
|
||||||
success: false,
|
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 {
|
} else {
|
||||||
let game: database = db.read(data.game_code);
|
let game: Game = active_games[data.game_code];
|
||||||
|
|
||||||
// Respond to client
|
// Respond to client
|
||||||
socket.emit(`PlayerListResponse`, {
|
socket.emit(`PlayerListResponse`, {
|
||||||
success: true,
|
success: true,
|
||||||
players: [Object.keys(game.players)],
|
players: Object.keys(game.players),
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue