In-browser multiplayer social deduction game inspired by Among Us.
Client:
- React.js for authentication pages and in-game HUD
- Recoil for storing global state
- Box2D physics engine
- Custom client-side prediction game engine
Server:
- Node.js authoritative game servers simulating the world at 16ms ticks
- WebRTC DataChannel UDP socket connections to clients
- Protobuf-like compressed JSON for serialized network communication
- Client receives and loads webpage
- Client checks
localStorage
for saved JWT and sends to server - Server verifies and decodes JWT
- If JWT is valid, use the
userId
claim to create new player or check if player previously connected - If JWT is invalid, sign new JWT with random
userId
claim and send to client to be saved inlocalStorage
- If JWT is valid, use the
- Create new
Player
object withactive: false
and add to hashmap (entering in game will change toactive: true
) - Run daemon on server that removes all inactive players every hour to free memory
Implementation allows for auto-reconnect of players, without requiring explicit username/password login.
- On join or create room, set socket and channel variables in player class
- On movement, emitted event received by UDP handler
- Find room and forward input to room handler
- Room handler takes care of input and uses channel to emit snapshot state of physics world back to client