diff --git a/TODO b/TODO index cb6d21a..fba0420 100644 --- a/TODO +++ b/TODO @@ -22,6 +22,14 @@ ✔ Create, join, delete and leave lobbies @done(21-04-12 20:51) → Make lobbies publically discoverable on a list +[ ] Dictionary + → Find appropriate scrabble dictionary for + → Portuagese + → Spanish + → French + → Czech + → Optimise! nary tree + [ ] Game logic ✘ Singleplayer game logic - OUT OF SCOPE @cancelled(21-04-11 01:04) ✘ AI CPU player @cancelled(21-04-11 01:07) diff --git a/client/public/index.js b/client/public/index.js index 3846239..8846abd 100644 --- a/client/public/index.js +++ b/client/public/index.js @@ -20,7 +20,8 @@ async function onUsernameSubmit(e) const chosenUsername = UsernameInput.value; const req = { - username: chosenUsername + username: chosenUsername, + locale: localStorage.getItem('locale') }; const res = await fetch('/login', { diff --git a/server/index.js b/server/index.js index e18b7d4..5b256a1 100644 --- a/server/index.js +++ b/server/index.js @@ -26,6 +26,7 @@ async function main() function benchmarkDictionary() { let hrTime = process.hrtime(); + // convert to ns let startTime = hrTime[0] * 1000000 + hrTime[1] / 1000; // Time 10 thousand reads @@ -37,7 +38,7 @@ function benchmarkDictionary() hrTime = process.hrtime(); let endTime = hrTime[0] * 1000000 + hrTime[1] / 1000; - Logger.debug(`10 000 Reads (unoptimised): ${endTime - startTime}μs`) + Logger.debug(`10 000 Reads (unoptimised): ${endTime - startTime}μs`); Dict.Optimise(); @@ -55,7 +56,7 @@ function benchmarkDictionary() hrTime = process.hrtime(); endTime = hrTime[0] * 1000000 + hrTime[1] / 1000; - Logger.debug(`10 000 Reads (optimised): ${endTime - startTime}μs`) + Logger.debug(`10 000 Reads (optimised): ${endTime - startTime}μs`); } diff --git a/server/src/dictionary.js b/server/src/dictionary.js index 062c9a8..946d6ac 100644 --- a/server/src/dictionary.js +++ b/server/src/dictionary.js @@ -37,11 +37,37 @@ function LoadTextDictionaries() } } + +// TODO: optimisation code for dict +class Node +{ + value; + children = []; + + #root; + + constructor(root, value, children) + { + + } +} + +class Tree +{ + #root; + +} + function Optimise() { } +function findInTree() +{ + +} + function FindWord(lang, word) { word = word.toUpperCase(); diff --git a/server/src/game-logic.js b/server/src/game-logic.js index 2a287c4..c321c30 100644 --- a/server/src/game-logic.js +++ b/server/src/game-logic.js @@ -1,8 +1,25 @@ +/* +GAME OBJECT +{ + locale - - - +} +NOTES + - The locale is the language of the *owner of the lobby*, the dictionary + will reflect this language choice +*/ let ActiveGames = []; +function StartGame() +{ + +} + + + + +module.exports = { + StartGame: StartGame, +} diff --git a/server/src/game-registrar.js b/server/src/game-registrar.js index b3cfaab..8f52fe7 100644 --- a/server/src/game-registrar.js +++ b/server/src/game-registrar.js @@ -9,6 +9,7 @@ USER OBJECT username: username, uid: uid, ip: ip, + locale: en, // REGISTERED, CONNECTED, DISCONNECTED state: 'CONNECTED', // LOBYING, GAMETRANSITION, GAME, UNDECIDED @@ -19,6 +20,7 @@ USER OBJECT NOTES - Socket relations are handled by the socket server in order to seperate domain logic from game and networking logic + - locale is language, supported languages in /data/ */ // TODO: Maybe stringify this for easy session persistence // poor substitute for a proper database but it's better @@ -100,7 +102,7 @@ function GetUserIntent(useruid) } -function RegisterUser(username, ip) +function RegisterUser(username, ip, locale) { // TODO: Don't assume this is unique, even with Crypto, UUIDv4? const uid = Crypto.randomBytes(8).toString("hex"); @@ -118,6 +120,7 @@ function RegisterUser(username, ip) username: username, uid: uid, ip: ip, + locale: locale || 'en', // REGISTERED, CONNECTED, DISCONNECTED state: 'REGISTERED', // LOBYING, GAMETRANSITION, GAME, UNDECIDED diff --git a/server/src/router.js b/server/src/router.js index 433e874..b98f6a6 100644 --- a/server/src/router.js +++ b/server/src/router.js @@ -57,6 +57,7 @@ function HandleLogin(req, res, next) } const username = req.body.username; + const locale = req.body.locale; if (!Game.Registrar.ValidUsername(username)) { @@ -85,7 +86,7 @@ function HandleLogin(req, res, next) return; } - const user = Game.Registrar.RegisterUser(username, ip); + const user = Game.Registrar.RegisterUser(username, ip, locale); if (!user) { diff --git a/server/src/socketserver.js b/server/src/socketserver.js index 4a74a15..a43b8e5 100644 --- a/server/src/socketserver.js +++ b/server/src/socketserver.js @@ -133,6 +133,9 @@ function ClientIdentify(socket, args) if (Game.Lobbies.IsLobbyReadyForGame(lobby.uid)) { + + + } }