Giter Club home page Giter Club logo

wordle-server's Introduction

Wordle Server

Sections

Logic ๐Ÿง 

  • Each event should be in a particular format, server/<action> and client/<action>. The former describes actions sent to the server, while the latter describes actions sent to the client.

  • If the game has ended:

    • Frontend should display results
  • Else:

Data ๐Ÿ—ƒ

  • The game requires two memory areas. (Permanent) and (Temporary)

Permanent (SQL)

  • The permanent area stores the list of players and the list of games / rooms.
  • Rooms can only write twice to the permanent area (beginning โ€“ to fixate the users playing this game and at the end- to store the final results of the game).
  • When the results of a game are written to the permanent area, it becomes Read ONLY

Temporary (In-memory/NoSQL)

  • It is a hot write area i.e. number of writes >> number of reads.
  • It stores the ongoing game session
  • It performs the write to the permanent storage when the game has ended.

Struct ๐Ÿ’พ

  • Session: contains the progress for a single user in a game (session ended means I am done with the current game, **BUT **others might still be playing)
    • Username
    • Max Guessed letters >
    • Used trails >
    • Submission time of max Guessed letters
  • Game: contains the progress of everyone in the game

Endpoints ๐ŸŒ

[POST] /login ๐Ÿšช

  • Login to an existing user
Fields
{
  "username": "username", 
  "password": "password" 
}
Response
{
  "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2Vybm"
}

[POST] /register ๐Ÿ“

  • Creates a new user
Fields
{
  "username": "username", 
  "password": "password"
}
Response
{
  "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2Vybm"
}

[POST] /create/room ๐Ÿ”’

  • Creates a new room returning the id of this new room
Response
{
  "id": "58dbe7f6-9d5c-4d48-8eac-73db92d4437d"
}

[GET] /join/room/{id} ๐Ÿ”’

  • Creates a new unique token for this (user & room)
  • Notice that the token is the same for each(user & room) pair, so requesting a token for the same (user & room) pair will return the same token.
Response
{
  "token": "cb6fddb2f88acfcbbdc6c9900510"
}

[GET] /room/ ๐Ÿ”’

  • Return list of all games played by the user
Response
[
  {
    "created_at": "2023-06-19T19:51:58.802+03:00",
    "started_at": "2023-06-19T19:53:02.886447+03:00",
    "ended_at": "2023-06-19T19:51:58.802+03:00",
    "creator": "username",
    "correct_word": "FOLKS",
    "id": "58dbe7f6-9d5c-4d48-8eac-73db92d4437d"
  },
  ...
]

[GET] /room/{roomID} ๐Ÿ”’

  • Return all the information about a specific game
Response
{
    "created_at": "2023-06-19T19:51:58.802+03:00",
    "started_at": "2023-06-19T19:53:02.886447+03:00",
    "ended_at": "2023-06-19T19:51:58.802+03:00",
    "creator": "username",
    "correct_word": "FOLKS",
    "guesses": [
        {
            "word": "FOLKS",
            "played_at": "2023-06-19T16:53:27.581099801Z",
            "status": [3,3,3,3,3]
        },
        ...
    ],
    "game_performance": [
        {
            "rank": 0,
            "username": "escalopa",
            "guess_response": {
                "played_at": "2023-06-19T16:53:27.581099801Z",
                "status": [3,3,3,3,3]
            }
        },
        ...
    ],
    "id": "58dbe7f6-9d5c-4d48-8eac-73db92d4437d"
}

Websockets ๐Ÿš€

[WS] /live?token=XXXXX

  • Connects to the game's room

  • The token provied can be obtained from the join room endpoint

  • Once connected you will be able to send and receive messages from the server, messages have two types

    • [WSE] server/xxx means client => server
    • [WSE] client/xxx means server => client
  • Requests object struct

{
  "event": "event_name",
  "data": "object(can be anything)", 
}

[WSE] server/message

  • Broadcasts a message to everyone in the lobby
Fields
{
  "data": "Hello World"
}

[WSE] client/message

  • Server sends a message to all clients in the lobby (client should listen to this event to update the message box)
Fields
{
  "data": "Hello World",
  "from": "username"
}

[WSE] server/play

  • Sends a word to the server to be played
Fields
{
  "event": "server/play",
  "data": "FOLKS"
}

[WSE] client/play

  • When a player submits a word, other users are notified about the status of the leaderboard of this user.
  • The status is an array of 5 numbers, each number represents the status of the letter in the same position in the word.
    • 3 => correct letter and position
    • 2 => correct letter but wrong position
    • 1 => wrong letter
Fields
{
    "event": "client/play",
    "data": {
        "rank_offset": 0,
        "username": "escalopa",
        "guess_response": {
            "played_at": "2023-06-19T19:16:36.715290087Z",
            "status": [1,2,2,1,3] 
        }
    },
    "from": "escalopa"
}

[WSE] server/start

  • Send a signal to mark the game as started and the server should now notify other players in the game about the event.
Fields
{
  "event": "server/start",
}

[WSE] client/start

  • Notify users that the game has started, Now they can submit words using /play
Fields
{
  "event": "server/start",
  "data": "Game has started"",
}

[WSE] client/data

  • Returns the current game data, it is sent to the user when
    • The user joins the game
    • The game is started
Fields
{
    "event": "client/data",
    "data": {
        "guesses": [
            {
                "word": "FOLKS",
                "played_at": "2023-06-19T19:16:36.715290087Z",
                "status": [1,2,2,1,3]
            }
        ],
        "active": true,
        "board": [
            "escalopa"
        ]
    },
    "from": "" 
}

Future Game Modes โœจ

  • Sprint mode: Unlimited trials (shortest time to guess a word is only used to determine the winner of this game mode)
  • Wizard mode: (the smallest trials to guess a word wins, when there is a tie, the first to get the smallest trials win).

wordle-server's People

Contributors

escalopa avatar lordvidex avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Forkers

kellarosaa

wordle-server's Issues

Improve logging

  • add zero log
  • print error messages created by the handler
  • print error messages created by the player conn
  • colored logs

Stop passing correctMsg to end users

when fetching the details of a game, correct_word message is passed, and this is not necessary as all the user needs are his attempts. Besides, if the user has already guessed the word, (i.e. finished the game), he will be able to reconstruct the needed fields without hassle.

Update documentation

all events and endpoints should be updated in the README.md file of the project

Creating persistence Hub

  • Changes made on the game should be stored in some temp DB and fetched on game start
  • temp DB should be cleaned up on game close
  • store data in a file storage DB (badger, leveldb)

Add session comparator

  • users should be able to set the mode of the game and this will determine the leaderboard ranks

Get room data returns 0 rank for all users

Exapmle response

 "game_performance": [
        {
            "rank": 0,
            "username": "deku",
            "guess_response": {
                "played_at": "2023-10-06T23:38:23.345368269Z",
                "status": [
                    3,
                    3,
                    3,
                    3,
                    3
                ]
            }
        },
        {
            "rank": 0,
            "username": "TomatoSoup",
            "guess_response": {
                "played_at": "2023-10-06T23:31:58.017079Z",
                "status": [
                    1,
                    1,
                    1,
                    3,
                    1
                ]
            }
        }
    ]

Return refresh token

  • Create a table in DB to store the refresh_token timestamp for each
  • Create a new endpoint refresh to generate new pairs of tokens (access, refresh).
  • If the sent token has a timestamp before than the one in DB then logout user

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.