Move the playerData check around
This commit is contained in:
parent
fd11293623
commit
d66f538f3a
1 changed files with 15 additions and 8 deletions
|
|
@ -16,22 +16,29 @@ export default (io: Server, socket: Socket, data: JoinGame) => {
|
||||||
`${conf.datastores.directory}/${data.game_code}.${conf.datastores.filetype}`,
|
`${conf.datastores.directory}/${data.game_code}.${conf.datastores.filetype}`,
|
||||||
`utf-8`
|
`utf-8`
|
||||||
)) as datastoreGame;
|
)) as datastoreGame;
|
||||||
|
|
||||||
|
let playerData = datastore.players.find(p => p.name === data.name);
|
||||||
|
|
||||||
|
// Assert that the name matches someone in the hibernated game
|
||||||
|
if (!playerData) {
|
||||||
|
log.info(`[${data.game_code}] User attempted unhibernate game with an invalid name`);
|
||||||
|
socket.emit(`GameJoined`, {
|
||||||
|
status: 403,
|
||||||
|
message: `Game with code "${data.game_code}" could not be found`,
|
||||||
|
source: `JoinGame`
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Instantiate the host's player object
|
||||||
let host = new Player(data.name, socket, true);
|
let host = new Player(data.name, socket, true);
|
||||||
let game = Game.fromJSON(host, datastore);
|
let game = Game.fromJSON(host, datastore);
|
||||||
game.log = log.getChildLogger({
|
game.log = log.getChildLogger({
|
||||||
displayLoggerName: true,
|
displayLoggerName: true,
|
||||||
name: game.id,
|
name: game.id,
|
||||||
});
|
});
|
||||||
|
|
||||||
game.ingame = datastore.ingame;
|
game.ingame = datastore.ingame;
|
||||||
|
|
||||||
// Get the specific information for team
|
|
||||||
let playerData = datastore.players.find(p => p.name === data.name);
|
|
||||||
if (playerData) {
|
|
||||||
host.role = playerData.role;
|
|
||||||
host.team = playerData.team;
|
|
||||||
};
|
|
||||||
|
|
||||||
let hand: string[] = [];
|
let hand: string[] = [];
|
||||||
if (host.team) {
|
if (host.team) {
|
||||||
let team = game.teams[host.team - 1];
|
let team = game.teams[host.team - 1];
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue