diff --git a/server/src/game-logic.js b/server/src/game-logic.js index 3dca161..bee138e 100644 --- a/server/src/game-logic.js +++ b/server/src/game-logic.js @@ -71,6 +71,15 @@ NOTES let ActiveGames = []; +function GetGameByUserUID(useruid) +{ + for (const game in ActiveGames) + for (const player of ActiveGames[game].players) + if (player.uid === useruid) return ActiveGames[game]; + + return false; +} + function GetTurnUser(gameuid) { if (!ActiveGames[gameuid]) return false; @@ -187,6 +196,7 @@ module.exports = { // Game validation exports // Get game exports + GetGameByUserUID: GetGameByUserUID, GetTurnUser: GetTurnUser, // Change game state exports diff --git a/server/src/socketserver.js b/server/src/socketserver.js index eb50d06..af87dae 100644 --- a/server/src/socketserver.js +++ b/server/src/socketserver.js @@ -103,6 +103,25 @@ function ClientIdentify(socket, args) Game.Registrar.ChangeUserIntent(user.uid, intent); const status = Game.Registrar.UserConnect(user.uid, socket.id, intent); + + // User reconnecting to game after disconnect (Not sure what this entails, mainly for debugging) + if (intent === 'GAME' && oldIntent === 'GAME') + { + socket.emit('identify-success', {connected: true, user: user}); + + const game = Game.Logic.GetGameByUserUID(user.uid); + + if (!game) + { + err.addError(500, 'Internal Server Error', 'error-illegal-intent'); + socket.emit('identify-error', err.toError); + return; + } + + EmitGameBegin(game); + return; + } + // If the user enters a game without transitioning, no bueno if (intent === 'GAME' && oldIntent !== 'GAMETRANSITION') { @@ -148,7 +167,6 @@ function ClientIdentify(socket, args) return; } - } if (status === true) @@ -414,6 +432,9 @@ function LobbyUpdateCallback(user, lobby, state) // send the client their user as well as the rest of the game +// works at any point during the game as the client will always +// setup a game not assuming begining - also fresh games have a +// populated gamestates array function EmitGameBegin(game) { // Instead of using io.to(room), i'm sending an individual packet to everyone