From e283f82fc34603397dc9efe794129cd319f24795 Mon Sep 17 00:00:00 2001 From: Benjamin Kyd Date: Fri, 30 Apr 2021 03:54:03 +0100 Subject: [PATCH] Bro --- TODO | 7 ++++--- client/public/scrabble/game.js | 3 +-- client/public/scrabble/network.js | 20 +++++++++++++++++++- data/en.lang | 1 + data/es.lang | 1 + data/locale.json | 5 +++++ data/pt-dictionary.dict | 12 ------------ data/pt.lang | 1 + server/src/game-logic.js | 25 ++++++++++++++++++++++++- server/src/letter-distributions.js | 11 +++++++++++ server/src/socketserver.js | 11 ++++++++--- 11 files changed, 75 insertions(+), 22 deletions(-) diff --git a/TODO b/TODO index dc02178..b98d500 100644 --- a/TODO +++ b/TODO @@ -15,11 +15,9 @@ → French (Alexendro) → Czech (Mikdore) - -✔ Sort out how intents work in game transitioning @done(21-04-12 21:09) - ☐ Lobbying logic ✔ Create, join, delete and leave lobbies @done(21-04-12 20:51) + ✔ Sort out how intents work in game transitioning @done(21-04-12 21:09) → Make lobbies publically discoverable on a list ☐ Dictionary @@ -38,3 +36,6 @@ ☐ Code → Refactor to code portsoc eslint → Refactor game client + +☐ Bugfixes + → If a user disconnects during a game, the game is irrevokably corrupted diff --git a/client/public/scrabble/game.js b/client/public/scrabble/game.js index ce2a96e..1c9381f 100644 --- a/client/public/scrabble/game.js +++ b/client/public/scrabble/game.js @@ -7,8 +7,7 @@ function computeTurn() } -function initGame() +function initGame(boardstate, players, tiles) { } -initGame(); diff --git a/client/public/scrabble/network.js b/client/public/scrabble/network.js index 3522f71..2d210b8 100644 --- a/client/public/scrabble/network.js +++ b/client/public/scrabble/network.js @@ -23,7 +23,7 @@ function initMultiplayer() socket.on('identify-success', args => onIdentifySuccess(socket, args)); socket.on('identify-error', args => onIdentifyError(socket, args)); - socket.on('game-start', args => console.log(args)); + socket.on('game-begin', args => onGameBegin(socket, args)); } @@ -101,6 +101,24 @@ function onDisconnect() } +function onGameBegin(socket, args) +{ + + if (!args) + { + ConnectionState.innerHTML = localeString('error-game-begin'); + return; + } + + if (!args.game.uid) + { + ConnectionState.innerHTML = localeString('error-game-begin'); + return; + } + + + +} // is game singleplayer? diff --git a/data/en.lang b/data/en.lang index aa10f6c..9daeaf8 100644 --- a/data/en.lang +++ b/data/en.lang @@ -15,6 +15,7 @@ error-bad-intent:Client has no intent error-bold:ERROR error-cannot-join-lobby:Cannot join lobby error-creating-lobby:An error occurred while creating the lobby +error-game-begin:There was an error starting the game error-illegal-intent:Illegal intent error-illegal-lobby:Illegal lobby error-illegal-user:Illegal user diff --git a/data/es.lang b/data/es.lang index 2632e9d..c7f18ad 100644 --- a/data/es.lang +++ b/data/es.lang @@ -14,6 +14,7 @@ error-bad-intent:Cliente no tiene intención error-bold:ERRO error-cannot-join-lobby:No se puede unir al lobby error-creating-lobby:Ocurrió un error al crear el lobby +error-game-begin: error-illegal-intent: error-illegal-lobby:Lobby ilegal error-illegal-user:Usuario ilegal diff --git a/data/locale.json b/data/locale.json index 149f805..65de7d3 100644 --- a/data/locale.json +++ b/data/locale.json @@ -64,6 +64,11 @@ "es": "Ocurrió un error al crear el lobby", "pt": "Ocorreu um erro ao criar o lobby" }, + "error-game-begin": { + "en": "There was an error starting the game", + "es": "", + "pt": "" + }, "error-illegal-intent": { "en": "Illegal intent", "es": "", diff --git a/data/pt-dictionary.dict b/data/pt-dictionary.dict index 2008aa6..be9e88f 100644 --- a/data/pt-dictionary.dict +++ b/data/pt-dictionary.dict @@ -1,15 +1,3 @@ - 43997 -, [CAT=punct1a] -; [CAT=punct1b] -: [CAT=punct1c] -" [CAT=punct2d] -( [CAT=punct2e] -) [CAT=punct2f] -! [CAT=punctg] -? [CAT=puncth] -. [CAT=puncti] -... [CAT=punctj] -à [$ao$CAT=cp,Prep=a,Art=o$G=f,N=s] abacateiro/p [CAT=nc,G=m,N=s] abacate/p [CAT=nc,G=m,N=s] abacaxi/p [CAT=nc,G=m,N=s] diff --git a/data/pt.lang b/data/pt.lang index c49fce7..1e1b623 100644 --- a/data/pt.lang +++ b/data/pt.lang @@ -14,6 +14,7 @@ error-bad-intent:Cliente não tem intenção error-bold:ERROR error-cannot-join-lobby:Não é possível entrar no lobby error-creating-lobby:Ocorreu um erro ao criar o lobby +error-game-begin: error-illegal-intent: error-illegal-lobby:Lobby ilegal error-illegal-user:Usuário ilegal diff --git a/server/src/game-logic.js b/server/src/game-logic.js index 80c5cda..17e6256 100644 --- a/server/src/game-logic.js +++ b/server/src/game-logic.js @@ -70,12 +70,29 @@ function BeginGame(lobby) locale: gameowner.locale, players: players, turn: 0, - tilebag: tilebag + tilebag: tilebag, + tileset: Dist.GetTileSet(gameowner.locale) }; return ActiveGames[lobby.uid]; } +/* +TURN OBJECT +{ + +} +NOTES + - Turns are handled a little weird, client sends turn on turn end and + this function validates it and changes the state of the game before + returning an error or a validation object including the next players + turn +*/ +function PlayTurn(game, turn) +{ + +} + // returns tuple ([newtileset], [newusertiles]) function ExchangeTiles(tileset, tilesToExchange) { @@ -90,5 +107,11 @@ function SelectTilesFromBag(tileset, num) module.exports = { + // Game validation exports + + // Get game exports + + // Change game state exports BeginGame: BeginGame, + PlayTurn: PlayTurn } diff --git a/server/src/letter-distributions.js b/server/src/letter-distributions.js index 4815800..e34c919 100644 --- a/server/src/letter-distributions.js +++ b/server/src/letter-distributions.js @@ -239,6 +239,15 @@ Distributions['cs'] = { ] }; +function GetDist(locale) +{ + return Distributions[locale]; +} + +function GetTileSet(locale) +{ + return Distributions[locale].tileset; +} function GenerateStartStateDistribution(locale) { @@ -263,5 +272,7 @@ function GenerateStartStateDistribution(locale) module.exports = { Distributions: Distributions, + GetDist: GetDist, + GetTileSet: GetTileSet, GenerateStartStateDistribution: GenerateStartStateDistribution }; diff --git a/server/src/socketserver.js b/server/src/socketserver.js index 66a32fd..ab0d4a4 100644 --- a/server/src/socketserver.js +++ b/server/src/socketserver.js @@ -69,6 +69,7 @@ async function Router(socket) // socket will emit game begin with play order and starting tiles // once all clients have connected with identify socket.on('lobby-game-begin', args => LobbyGameBegin(socket, args)); + socket.on('game-play-turn', args => GamePlayTurn(socket, args)) socket.on('disconnect', args => HandleDisconnect(socket, ...args)); @@ -128,6 +129,7 @@ function ClientIdentify(socket, args) // so make sure that they are joined into a lobby for // the networking socket.join(lobby.uid); + console.log(io.sockets.adapter.rooms); // If this user was the last player in the lobby to connect // start the game and tell every connected user @@ -340,6 +342,7 @@ function LobbyUserUnReady(socket, args) if (!Game.Lobbies.IsLobbyReady(lobby.uid)) LobbyUpdateCallback(user, lobby, 'game-unready'); } + function LobbyGameBegin(socket, args) { const user = Game.Registrar.GetUserbyConnection(socket.id); @@ -361,6 +364,11 @@ function LobbyGameBegin(socket, args) io.to(lobby.uid).emit('request-intent-change', { intent: 'GAMETRANSITION', lobby: lobby }); } +function GamePlayTurn(socket, args) +{ + +} + function HandleDisconnect(socket, args) { @@ -414,11 +422,8 @@ function EmitGameBegin(game) game: game }); - console.log(game); - // for (const user of game.players) // { // const gameuser = game.players.filter(i => i.uid === user.uid)[0]; - // } }