Ever wanted to play a local game with a friend who is far away? Star makes local multiplayer games playable remotely!
Warning
This project is a work in progress.
-
Build the server:
make build registar
-
Copy the server binary to the target machine.
-
Run the server:
sudo SECRET=my-secret CERT_DOMAINS=my-domain.com ./registar
This will start a relay server named "registar", which listens on ports 80 and 443. See more about registar here.
- Host the game.
- Run the client, click "Start a server" -> "Advanced settings."
- Select the game port on which the game runs.
- Enter the server's secret.
- Enter the server's URL.
- Click "Start".
- Share the invite code with your friend.
- Enter the invite code provided by the host.
- Connect to the game.
The registar server is a relay server that relays UDP traffic over HTTP/3 using DATAGRAMs.
- Automatic TLS certificate management with Let's Encrypt.
- Automatic redirects to HTTPS.
- HTTP/3 advertisement.
The server can be configured using the following environment variables:
SECRET- A secret to prevent unauthorized connections to the server (required).LISTEN_ADDRESS- The address to listen for HTTP traffic.LISTEN_TLS_ADDRESS- The address to listen for HTTPS and HTTP/3 traffic.LOG_LEVEL- The logging level (INFO,DEBUG).CERT_SELF_SIGNED- If set totrue, enerates and uses a self-signed certificate instead of Let's Encrypt. Useful for testing.CERT_DIR- The path to the directory where certificates are stored.CERT_DOMAINS- A comma-separated list of domains for which to issue certificates (required).CERT_IP_ADDRESS- A comma-separated list of IP addresses for which to issue certificates.
Client is a simple WebView application that dynamically renders HTML pages using Go templates, served by a local HTTP server. See screenshots for a preview.
In summary, it is a relay server with two types of clients: host and peer. The host and peer connect to each other via this relay server. It operates on top of HTTP/3 and relays UDP traffic using HTTP/3 DATAGRAMs.
Diagram
The mermaid diagram illustrates how the connection is established:
- The Host Forwarder registers itself with the Server and issues a new invite key.
- The Peer Forwarder waits for the Game Client to connect. On the first packet, it connects to the Server using the invite code.
- The Server then asks the Host Forwarder to initiate a new connection to the Game Host.
- The Host Forwarder and Peer Forwarder relay data between the Game Host and Game Client via the Server.
sequenceDiagram
participant Game Host as Game Host
participant Host Forwarder as Host Forwarder
participant Server as Server
participant Peer Forwarder as Peer Forwarder
participant Game Client as Game Client
Note left of Game Host: Game Host initiates connection
Host Forwarder ->> Server: CONNECT Register Game
Server ->>+ Host Forwarder: HTTP OK
rect rgb(191, 223, 255, 0.3)
Note right of Peer Forwarder: Game Client initiates connection
Game Client ->> Peer Forwarder: Connect Game
rect rgb(200, 150, 255, 0.3)
Peer Forwarder ->>+ Server: CONNECT Connect Game
Server ->> Host Forwarder: CONNECT
Host Forwarder ->> Game Host: Dial
Host Forwarder ->> Server: CONNECT
Server ->> Host Forwarder: OK
Server <<-->> Host Forwarder: DATAGRAM stream
Server ->>- Peer Forwarder: HTTP OK
Server <<-->> Peer Forwarder: DATAGRAM stream
end
end
Note over Host Forwarder, Peer Forwarder: Server forwards data between two clients
Peer Forwarder ->> Game Client: Forward
Host Forwarder ->> Game Host: Forward
To compile webview for Windows, mingw-w64 is required:
brew install mingw-w64On Linux:
apt install binutils-mingw-w64 Then build the app:
make build-webview-winRun the API:
SECRET=registar_secret LOG_LEVEL=DEBUG CERT_SELF_SIGNED=true go run ./cmd/registar/...Here we tell our app to use a generated self-signed certificate: a certificate created by a self-signed Certificate Authority (CA).
During initialization, the app will also create a ca.crt file: a self-signed CA certificate. Use it to verify the server's certificate.
Run in another terminal:
curl -Lv --cacert ca.crt http://localhost/-/healthYou can use a pre-built curl with HTTP/3 support from https://github.com/stunnel/static-curl.
Run in another terminal:
curl -Lv --cacert ca.crt --http3 http://localhost/-/health