Doom Workers Save

Website and Message Router source code for the Multiplayer Doom on Cloudflare Workers tech demo

Project README

Multiplayer Doom Workers

This repo contains two Workers

Website

Assets are in ./assets

Worker code is in site/index.js

You need the following files in ./assets (not included in this repo):

To publish:

npm install -g @cloudflare/wrangler@beta
wrangler login
wrangler publish --config wrangler-site.toml

Adjust wrangler-site.toml to your account_id and zone_id.

Wasm Doom message router

Our message router has the following requirements:

  • Accept Wasm Doom WebSocket connections and build a routing table
  • Receive and parse the incoming messages
  • Broadcast the messages to the corresponding clients
  • Handle some REST APIs to create and validate Doom rooms (sessions)

Just supports the network multiplayer in our Silent Space Marine showcase project.

Read more about it in our blog post here.

The router source code is at router/index.mjs

To publish:

First make sure you have Durable Objects enabled in your account.

Make sure you have the Durable Objects wrangler (beta) installed:

npm install -g @cloudflare/wrangler@beta

Adjust wrangler-router.toml to your account_id and zone_id or use the CF_ACCOUNT_ID and CF_ZONE_ID environment variables.

Run this command just once

wrangler login
wrangler publish --config wrangler-router.toml --new-class Router

Later updates use:

wrangler login
wrangler publish --config wrangler-router.toml

Makefile

You can use make to deploy the workers.

Create an .env file with your account and zone ids:

ROUTER_CF_ZONE_ID = 72...........91
ROUTER_CF_ACCOUNT_ID = 0a...............2f
SITE_CF_ZONE_ID = 13....................a0
SITE_CF_ACCOUNT_ID = 07.................4f

Run make:

make publish

Running Multiplayer Doom locally

You can run the Website, Wasm Doom and Multiplayer locally, in your computer, using a NodeJS WebSocket router implementation.

First install NodeJS and npm. Then:

cd scripts
npm install
./router.js

Point your browser to http://0.0.0.0:8000

Read more about Multiplayer Doom on Cloudflare Workers in our blog post here.

Open Source Agenda is not affiliated with "Doom Workers" Project. README Source: cloudflare/doom-workers
Stars
124
Open Issues
1
Last Commit
11 months ago
License

Open Source Agenda Badge

Open Source Agenda Rating