Server Data Model - daniellok/decrypto GitHub Wiki

Thought Dumps

  1. jackbox model for server channel and user initialisation
  • Server generates room code
  • When users join, have them enter a nickname
  • Nickname acts as uid for each user in that room
  • If a user disconnects and reconnects with the same name, give them their old state
  1. set an activity timeout
  • We will have to be quite careful about garbage collection
  1. do we want pass and play?

Class Diagram

The state and functions we'll need for each class in order to run a game

Server

State

Name Type Description
rooms Map<string, Room> List of all the current rooms in the server. Keys of the map are the room IDs

Functions

Name Type Description
connectUserToRoom() (userId, roomId) => void Takes a given user and connects them to the given room. We'd probably delegate most of the logic to the room itself, and this will just be used for routing

Room

Name Type Description
id string ID of the room, was thinking of just randomly generating a 4-letter code
playerList Map<string, Player> Map of all players in the room
teamA Team Team object representing one of the two teams
teamB Team Team class representing the other team
phase gamePhase* enum representing the current phase of the game
roundCount int Which round the game is on, used to determine when to stop
type gamePhase = 'team-a-coding' 
  | 'team-a-guessing' 
  | 'team-b-coding' 
  | 'team-b-guessing' 
  | 'tiebreaker-guess' 
  | 'tiebreaker-reveal' 
  | 'team-a-win' 
  | 'team-b-win';

Team

Name Type Description
teamPlayerList Map<string, Player> Map of all the players in the team. Keys of the map are the player IDs
codemaster Player The team's current codemaster
words Array<string> An array of length 4, representing the team's words
code Array<number> An array of length 3, representing the current code (e.g. [4, 1, 2])
clues Array<string> An array of length 3, containing the codemaster's current clues
previousClues Array<Array<string>> An array of length 4, containing all the previously given clues for each word
wordGuesses Array<string> An array of length 4, representing the team's guesses for the other team's words in the event of a tiebreaker

Player

Name Type Description
id string The player's nickname, which functions as an id within the context of the room
active boolean Whether or not the user is still connected (e.g. they might disconnect and reconnect later, but if it's their turn to be codemaster they should be skipped)
conn Socket Socket connection object for this client
codeGuess Array<number> The player's guess for the current round's code
⚠️ **GitHub.com Fallback** ⚠️