Skip to content

The royal game of Ur. Online multiplayer server/client. Written in Next.Js, TypeScript using WebSockets

License

Notifications You must be signed in to change notification settings

AlexanderGW/royal-game-of-ur

Repository files navigation

Royal Game of Ur

Online multiplayer server (Node.Js) & client (Next.Js), written in TypeScript, using WebSockets, by Alexander Gailey-White

Game demo

Notes

  • Initial release
  • Server waits until two or more (even number of users) are connected, and spawns a game.

Rules

Rules based on reconstruction by Irving Finkel

  • Two players take turns rolling the dice
  • First player randomly selected
  • Pieces move around the board, through blue, up along red, then down into the green squares
  • Player moves one of their available pieces, based on dice roll (between 0-4)
  • Landing on a rosette (darker squares) grants another roll, maxiumum of three (3) per turn.
  • A player can attack opposing pieces within the red squares, resetting that piece back to square zero (0), unless opposing piece is on the rosette, in which they're protected from attack
  • To finish a piece; the roll must move (exactly) to square fifteen (15)
  • To win; a player must get all pieces to square fifteen (15)

Usage

pnpm run server [1337] to run Websocket server on optional port number (default 1337)

pnpm dev to dev build and run the Next.Js frontend. Warning, you may run into socket communication issues with double-render, try command below.

pnpm run serve to build and run a production version of the frontend.

Todo

  • Improve lobby/stats area
  • Server data persistance
  • Customise board size and piece count
  • Challenging - Allow players to challenge their next opponent
  • Scoring - Highscore, win-streak, etc
  • Experimental: StyleX, for eventual react-strict-dom
  • Improve graphics
  • Chatbox (maybe)

WSS NGINX proxy

Using NGINX create an HTTPS WSS proxy server to encrypt WebSocket traffic

server {
    listen 1337 ssl;
    
    ...
    
    location / {
        proxy_pass http://ws-backend;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
        proxy_set_header Host $host;
    }
}

upstream ws-backend {
    # enable sticky session based on IP
    ip_hash;

    # The port [1337] passed to the server.js
    # Run on custom server port so that it doesn't conflict with NGINX
    server 127.0.0.1:1337;
}