Started clientside turn communication
This commit is contained in:
@@ -71,6 +71,13 @@ NOTES
|
||||
let ActiveGames = [];
|
||||
|
||||
|
||||
function GetTurnUser(gameuid)
|
||||
{
|
||||
if (!ActiveGames[gameuid]) return false;
|
||||
return ActiveGames[gameuid].players[ActiveGames[gameuid].turn];
|
||||
}
|
||||
|
||||
|
||||
function BeginGame(lobby)
|
||||
{
|
||||
// game uses the owners language - assumes it's valid
|
||||
@@ -180,6 +187,7 @@ module.exports = {
|
||||
// Game validation exports
|
||||
|
||||
// Get game exports
|
||||
GetTurnUser: GetTurnUser,
|
||||
|
||||
// Change game state exports
|
||||
BeginGame: BeginGame,
|
||||
|
||||
@@ -424,10 +424,17 @@ function EmitGameBegin(game)
|
||||
const gameuserconnection = Game.Registrar.GetConnectionByUser(gameuser.uid);
|
||||
|
||||
// TODO: consider not sending all users the entire game state
|
||||
// due to cheating
|
||||
// due to cheating - a few more considerations and maybe a
|
||||
// getsafegame function is needed
|
||||
io.to(gameuserconnection).emit('game-begin', {
|
||||
game: game,
|
||||
gameuser: gameuser
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
// Let starting player know it's their turn
|
||||
const userturnstart = Game.Logic.GetTurnUser(game.uid).uid;
|
||||
const userturnstartconnection = Game.Registrar.GetConnectionByUser(userturnstart);
|
||||
|
||||
io.to(userturnstartconnection).emit('game-your-turn');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user