Skip to content

A realtime web game built with websockets, Preact, and Astro.

Notifications You must be signed in to change notification settings

lilnasy/tic-tac-toe

Repository files navigation

⨯◯

A realtime web game built with websockets, Preact, and Astro.

🔍 Browse Around...

  • / serves as the main menu, allowing to start a new game and to join an existing game with a shared code.
  • /connect creates a websocket connection between the browser and the "lobby".
  • /world/:worldName supports shareable links to automatically join a game.

📸 Screenshots

🕸️ Built on the Platform

  • 🪄 @starting-style for animating microinteractions.
  • 🖌️ OKLCH for visually consistent color palettes.
  • 🗄️ IndexedDB for saving player details and selected theme.
  • 📡 Service workers to prevent flash of "unthemed" content.

🏋️ Lightweight Libraries for the Heavylifting

✈️ Continuous Deployment

Using a GitHub Actions workflow and a bash script, changes are automatically deployed to the VPS running sillystring.party.

🔐 Secrets

  • The GitHub Actions workflow knows a deploy token, which is required by the server when requesting a redeploy.
  • The server knows a GitHub access token, which is required by github.com when downloading artifacts.

🪓 Hacking

🚩 Getting Started

  1. Clone the repository:
git clone https://github.com/lilnasy/tic-tac-toe
cd tic-tac-toe
  1. Install dependencies:
pnpm install

To start the development server:

pnpm dev

The application will be available at http://localhost:4321

🏗️ Project Structure

  • 🎮 /game: Game logic and state management.
  • 📚 /lib: Polyfills, state management helpers, IndexedDB persistence helpers, vite plugins.
  • 🎞️ /assets: Sound effects and favicons.
  • 📃 /pages: Astro file-based router.
  • 🧩 /components: UI and interaction logic.
  • 🛠️ /patches: fixes to known issues in the libraries being used, and revert of preact's mangled code.

🏭 Building for Production

To create a production build:

pnpm build

Start the node server:

node --enable-source-maps dist/server/entry.mjs

Start caddy to create TLS certificates, manage cache, and serve the application:

caddy run --config ./Caddyfile

🛫 Deploying as a service

Autorestart the server on failure, manage logs, and start the server on every boot by creating an OpenRC service.

Create the OpenRC service file in /etc/init.d/tictactoe:

#!/sbin/openrc-run
supervisor="supervise-daemon"
name="Tic Tac Toe"
description="Run a node server hosting the game."
command="node"
# adjust as necessary
command_args="--enable-source-maps /app/dist/server/entry.mjs"
command_background=true
pidfile="/run/tictactoe.pid"
output_log="/var/log/tictactoe.log"
error_log="/var/log/tictactoe.err"

Start the service:

service tictactoe start

Check uptime:

rc-status

About

A realtime web game built with websockets, Preact, and Astro.

Resources

Stars

Watchers

Forks