> For the complete documentation index, see [llms.txt](https://docs.edgegap.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.edgegap.com/docs/sample-projects/web-games/manus-orb-arena.md).

# Manus Orb Arena

Make a Manus game multiplayer with Edgegap: ask Manus Game Dev for a self-hostable Node.js server, run one server per match near its players, and add Find Match with the Edgegap matchmaker.

Learn how to host a multiplayer game built with [Manus](https://manus.im/) Game Dev on Edgegap.

Orb Arena is a neon arena game for 2 to 4 players: each player flies a hover drone, pushes glowing orbs into their own goal, and dashes to stun rivals. Manus wrote the browser client and the authoritative Node.js WebSocket server from a single prompt.

* **Manus**: used while you build the game, to write the client and the game server.
* **Edgegap**: used while people play, for one dedicated server per match, near its players, and optional matchmaking.

This sample shows:

* **A self-hostable server from Manus**: when Manus Game Dev offers a Cloud Computer to host multiplayer, ask it for a server you host yourself, and run that server on Edgegap.
* **One small Edgegap file**: `server/src/edgegap.js` stops the deployment when the match is over and checks matchmaker tickets. It does nothing outside Edgegap, so the server still runs anywhere.
* **Optional find match** with the [Edgegap JavaScript SDK](https://www.npmjs.com/package/@edgegap/sdk): 2 to 4 players per match. Without a matchmaker, players join with a room code and the server address, exactly as Manus built it.
* **Manus's original output**: the tag `manus-original` in the repository holds the untouched code, so every change for Edgegap is visible in the history.

{% hint style="info" %}
See the [sample repository](https://github.com/edgegap/netcode-sample-manus-orb-arena) for the game, the game server, the matchmaker config and the tests.
{% endhint %}

## ✔️ Preparation

Before we start, you will need:

* [Manus Orb Arena sample](https://github.com/edgegap/netcode-sample-manus-orb-arena), or your own game made with Manus Game Dev.
* [Node.js](https://nodejs.org/) 22 or newer, to run the server locally.

<details>

<summary><a href="https://www.docker.com/products/docker-desktop/">Install Docker Desktop (or Docker CLI)</a></summary>

* [Install Docker Desktop from the official source](https://www.docker.com/products/docker-desktop/) (no account required).
* Restart your computer after completing the installation.

</details>

☑️ Try the game locally first:

{% code collapsedlinecount="10" %}

```bash
cd server && npm install && npm start
cd client && python -m http.server 8091
```

{% endcode %}

Run the two commands in separate terminals. Open `http://localhost:8091` in two browser tabs, enter the same room code in both, and click **Enter Arena**.

## 🤖 Build the Game with Manus

### 1. Ask for a Self-Hostable Server

☑️ In Manus, choose **Make a game** and describe a multiplayer game. Orb Arena started from this prompt:

{% code overflow="wrap" collapsedlinecount="10" %}

```
Make a top-down browser arena game for 2-4 players online: each player is a hover drone that pushes glowing orbs into their own goal, with a dash that stuns other drones. 3-minute matches, highest score wins. Simple neon visual style. Online multiplayer so friends can play together from a link.
```

{% endcode %}

☑️ When Manus asks for a Cloud Computer to host the game server, reply in the chat:

{% code overflow="wrap" collapsedlinecount="10" %}

```
can you build the game server binary so i can host it locally on my machine instead
```

{% endcode %}

Manus builds a Node.js WebSocket server with the game rules, reading its port from `PORT` and listening on `0.0.0.0`, plus standalone binaries.

☑️ Ask for the browser client, with the server address as a page parameter:

{% code overflow="wrap" collapsedlinecount="10" %}

```
can you also build the browser client so i can test it against my server? Let me set the server address in the page (a ?server= URL parameter like ws://localhost:8787/ws or wss://myhost:port/ws), so the same client works with my local server or a server I host somewhere else.
```

{% endcode %}

☑️ Download the files from the task (each file preview has a **Code** tab, and Manus links an archive of the whole folder) and push them to your own repository.

{% hint style="warning" %}
**Check that game state keeps arriving.** The first server Manus wrote for Orb Arena sent one state snapshot and then stopped, so players looked frozen, and Manus's own test only checked that two players could join. Connect two clients for a few seconds and count the snapshots, for example with the sample's `tests/ws-check.cjs`.
{% endhint %}

✅ You may now proceed to the next step.

### 2. Add the Edgegap Server File

☑️ Copy `server/src/edgegap.js` from the sample into your server's `src/` folder, and call its hooks from the server:

{% code collapsedlinecount="10" %}

```javascript
const edgegap = require('./edgegap');                     // top of the server
edgegap.connectedChanged(playersOnline());                // when a player joins, rejoins or leaves
edgegap.matchStarted();                                   // where a match starts
edgegap.matchEnded();                                     // where results are sent
edgegap.started();                                        // when the server is listening
```

{% endcode %}

On Edgegap, the server stops its own deployment when nobody joined within 120 seconds, when every player left 30 seconds ago, or 60 seconds after the match ended. Billing stops with it.

☑️ Add the sample's `server/Dockerfile` next to your server's `package.json`.

✅ You may now proceed to the next step.

## ⚡ Deploy and Connect

### 3. Build the Server Image

☑️ To get started, you'll need to [create a free account with Edgegap](https://app.edgegap.com/auth/register). No credit card required.

☑️ Find your [Container Registry](https://docs.edgegap.com/learn/advanced-features/edgegap-container-registry.md) project name and credentials.

☑️ Sign in to Edgegap's Container Registry with Docker, using your registry project name, username and token:

{% tabs %}
{% tab title="Bash (Linux)" %}

```bash
project='<REGISTRY_PROJECT>';
username='robot$<REGISTRY_ORGANIZATION_ID>+client-push';
token='<REGISTRY_TOKEN>';

echo "$token" | docker login registry.edgegap.com -u "$username" --password-stdin 2>&1
```

{% endtab %}

{% tab title="PowerShell (Windows)" %}

```powershell
$project = '<REGISTRY_PROJECT>'
$username = 'robot$<REGISTRY_ORGANIZATION_ID>+client-push'
$token = '<REGISTRY_TOKEN>'

echo "$token" | docker login registry.edgegap.com -u "$username" --password-stdin 2>&1
```

{% endtab %}
{% endtabs %}

☑️ Build and push the image, tagged with the build time:

{% code collapsedlinecount="10" %}

```bash
docker build --platform linux/amd64 -t registry.edgegap.com/<project>/manus-orb-arena:<tag> server
docker push registry.edgegap.com/<project>/manus-orb-arena:<tag>
```

{% endcode %}

{% hint style="danger" %}
:x: **DO NOT - overwrite existing tags or use `latest`  tag** - this will deploy an outdated cache.\
:white\_check\_mark: **DO - always increase your version tag** and deploy the new build.
{% endhint %}

✅ You may now proceed to the next step.

### 4. Create the App Version

☑️ [Create an application](https://app.edgegap.com/application-management/applications/list) named `manus-orb-arena`, with one version named after your tag:

* **Image**: registry `registry.edgegap.com`, repository `<project>/manus-orb-arena`, tag `<tag>`,
* **Resources**: 0.25 vCPU and 512 MB memory,
* **Port**: `8787`, name `gameport`, protocol **WS**, with **TLS Upgrade** enabled,
* **Restart policy**: Never,
* **Max duration**: 30 minutes, as a safety net: the server stops itself.

{% hint style="warning" %}
**TLS Upgrade** lets browsers on `https` pages connect to `wss://<id>.pr.edgegap.net:<port>/ws`. Edgegap terminates TLS and forwards plain WebSocket traffic to port `8787`.
{% endhint %}

{% hint style="info" %}
Free Tier is limited to 2 Applications, 2 versions, and 10 GB of Container Registry storage.
{% endhint %}

☑️ Deploy one server from the dashboard, then open the client in two tabs with the deployment's address and the same room code:

{% code overflow="wrap" collapsedlinecount="10" %}

```
http://localhost:8091/?server=wss://<fqdn>:<external port>/ws&room=ARENA1
```

{% endcode %}

🙌 Both players are now in the same match, on a server placed near them. Close both tabs, and the deployment stops itself about 30 seconds later.

✅ You may now proceed to the next step.

### 5. Add Find Match (Optional)

☑️ Set `application.version` in the sample's `matchmaker/arena.json` to your version, and add the address of your page to `allowed_cors_origins`.

☑️ Open the [Matchmaker](https://app.edgegap.com/matchmaker-management-v2/matchmakers/list) page in the dashboard, click **Create**, upload the config, and click **Create and Start**.

The `arena` profile matches 2 to 4 players. After 20 seconds, a player waiting alone gets a server.

☑️ When the matchmaker shows **Online**, copy its **API URL** and **Auth Token** into `client/config.local.js`, a copy of `client/config.js`. The page now shows **Find Match**.

{% hint style="success" %}
The **matchmaker Auth Token is safe to ship in web pages**: it can only ask for matches. Never put your Edgegap API token in a page or in the server image.
{% endhint %}

☑️ Open your page in two browser tabs and click **Find Match** in both within 20 seconds.

Each page:

1. joins the matchmaker and waits for `HOST_ASSIGNED`,
2. connects to `wss://<fqdn>:<port>/ws` and sends its ticket ID, retrying for a few seconds while the server starts,
3. plays: it sends inputs and draws the state the server sends back.

The game server:

1. lets in only the matched tickets,
2. starts the match when every matched player is in,
3. stops its own deployment after everyone leaves.

## 📦 Ship Your Game

* Host the page anywhere: `client/` is static files with no build step.
* Close the game connection when the page is closed, as the sample's client does on `pagehide`, so the server sees players leave at once and stops sooner.
* Turn `inspect` off in the matchmaker config before launch.
* To ship new rules, push a new image tag, create a new app version, and point the matchmaker at it. New matches use it, and running ones keep the old build.

{% hint style="info" %}
Using a coding agent? The `edgegap-manus` skill in [Edgegap's agent skills](https://github.com/edgegap/llm-agent-skills), also served by the [Edgegap MCP server](https://docs.edgegap.com/docs/mcp-integration.md), holds these steps, the server file and the tests, and walks your agent through the same path for your own Manus game.
{% endhint %}
