A game server for multiplayer peer-to-peer games.
Used by these games:
Features
- User registration and authentication using device authenticator
- Secure cloud-based game configuration to update game settings remotely
- Server messages and notifications for connected players
- Matchmaking using token-based pairing with tunneling support
- Player and host identity verification
- Chat messages integrity using digital signatures
- Secure player score management
- Discord bot for management and moderation
- Anti-cheat rules with automatic violation reporting
Configuration
The application runs on Cloudflare Workers, with wrangler.jsonc as the source of truth for the Worker's bindings.
- Configure the Worker variables and secrets listed in
.env.examplevia the Cloudflare dashboard orwrangler secret put. - Create the resources declared in
wrangler.jsoncand fill in their IDs for each environment (top-level,staging, andproduction):GAMESERVER_KV— one KV namespace per environment.HYPERDRIVE— one Hyperdrive configuration per environment (same binding name, differentid).WEBSOCKET_DURABLE_OBJECT— declared viadurable_objects; no ID required.
- Connect the Worker to the repository in the Cloudflare dashboard (Settings → Builds), set the build command to
pnpm run predeploy, and keep the deploy command asnpx wrangler deploy. Commit and push — Workers Builds runs predeploy (migrations + Discord registration) and deploys on every push.
Database configuration
Provision a PostgreSQL database and create the authenticated_user role before running migrations. The deployed Worker connects through Cloudflare Hyperdrive, so the Worker itself never needs a DATABASE_URL secret — only the migration/CI commands (which run outside the Worker) connect to PostgreSQL directly.
Local configuration
Copy .env.example to .env and set:
DATABASE_URL— used by the local migration commands (pnpm run db:migrateandpnpm run predeploy).CLOUDFLARE_HYPERDRIVE_LOCAL_CONNECTION_STRING_HYPERDRIVE— used bypnpm run devto emulate theHYPERDRIVEbinding.
The dev script loads .env into the process environment, which is how Wrangler reads the local Hyperdrive connection string. The same variable works whether you run plain pnpm run dev or --env staging/--env production, because the binding name stays HYPERDRIVE.
CI/CD (staging and production)
Deployment runs through Cloudflare Workers Builds, which authenticates through the dashboard connection — no CLOUDFLARE_API_TOKEN is needed. Set the build command to pnpm run predeploy to apply migrations and register the Discord slash commands before each deploy, and keep the deploy command as npx wrangler deploy. For separate staging and production Workers, connect each environment's Worker and add --env staging/--env production to the deploy command.
Add DATABASE_URL, DISCORD_APPLICATION_ID, and DISCORD_BOT_TOKEN as build variables/secrets in the Workers Builds settings (Settings → Build). The build command runs on every push to the production branch (and on preview branches if enabled), so migrations run before each deploy.
Contributing
I welcome contributions of all kinds! Whether you're fixing bugs, adding new features, improving documentation, or suggesting enhancements, your efforts are appreciated.
Play, Create & Share