01Playing
- Browser co-op: open the game, press CO-OP, then HOST A GAME. Send your partner the room code or the invite link (
https://canyoncommand.10fold.stream/play/?room=CODE). They press CO-OP, type the code and press JOIN, or just open the link. The host picks the map and difficulty and presses START. - In Discord: join a voice channel, open the Activities (rocket) menu and launch Canyon Command. Solo play works as usual. Press CO-OP and everyone who launched the Activity in that voice channel lands in the same room; the first one in is the host.
- Roles: the host is Commander 1 and holds the left half of the map; the first person to join is Commander 2 and holds the right half. Anyone else watches. Each commander builds only on their half, has their own credits and their own ability cooldowns, and abilities can be used anywhere. Lives are shared, 1.5 times the solo amount, and a leak at either gate costs the team.
- Dropping out: if your partner leaves, you take over their half, their machines and their credits until someone joins again. If the host leaves, the partner's game takes over the battle.
- Maps: Basalt Fork and Ember Crossing (60 × 36 cells, two entries and a gate per half). Both can also be played solo from the operation list, holding all four entries.
- Records: co-op wins count for medals, ranks and XP. Co-op best scores are kept apart from solo ones. Co-op battles are not saved for CONTINUE.
02How it works
| Part | Where |
|---|---|
| Discord launch | The root mapping points at /play, so Discord loads the game directly. (Mapping / to the site root does not work: Discord's proxy follows the Worker's redirect to /play/ itself, keeps the address /, and the game's relative script paths then miss, which leaves a blank screen.) |
| Discord sign-in | game/sub-net.js loads game/vendor/discord-sdk.js, calls authorize (scopes identify, rpc.activities.write) and swaps the code at POST /api/token. The Worker keeps nothing. |
| Rich Presence | presTick() in the entry point sends the map, difficulty, wave and lives every few seconds (only changes are sent). Image keys: substellar, main-menu, briefing, building, defending, boss-wave, victory, defeat. |
| Co-op relay | wss://…/api/room?room=CODE: one Room Durable Object per room passes messages between the host and the others. Max 8 sockets, 512 KB per message, 120 messages a second per socket, keep-alive every 30 s. Discord rooms are d-<instance id>. |
| Sync | The host's SubGame runs the battle. Every 0.5 s it sends syncOut() (all tower fields and the grid when something was built, sold or unlocked, and every 5 s; otherwise compact tower and enemy arrays, about 10 KB). The partner's game runs with follower = true (no waves, no game over of its own) so motion and sound stay smooth, and syncIn() merges the host's state by id. Partner commands (place, sell, upgrade, repair, useAbility, upAbility, hurry, setMode) apply locally and go to the host, which runs them as that player. |
| Engine | np players, pp is the player a call acts for (as(p, fn)), wallets cr, ability state abs, zoneOf(c) against the map's half column, gates with gateOf(e), setAway(p). Co-op maps use hpK2 for enemy health. |
| No outside servers | Discord blocks them inside Activities, so React and the Rajdhani font are in game/vendor (pointed at through window.__resources by game/sub-boot.js; support.js is unchanged). sub-boot.js also copies Discord's script nonce onto every script the page adds. |
| Secrets | Worker secrets DISCORD_CLIENT_ID and DISCORD_CLIENT_SECRET. Never in the repository. Set with npx wrangler secret put <name>. |
The runtime compiles the page's template and logic in the browser (new Function), so it needs a Content Security Policy that allows unsafe-eval. A local test with a strict nonce policy plus unsafe-eval loads the whole game; without unsafe-eval it does not.
03Discord app settings
App Canyon Command, application ID 1573358643561369690 (Discord does not allow : in app names), in the Knot Vector team of the Developer Portal.
| Page | Setting | Value |
|---|---|---|
| OAuth2 | Redirect | https://127.0.0.1 (Discord requires one; it is not used) |
| Activities → Settings | Enable Activities | On; supported platforms: desktop and web. Discord lists iOS and Android without separating tablets from phones, so mobile stays off until the phone layout is checked inside Discord. |
| Activities → URL Mappings | Root mapping / |
canyoncommand.10fold.stream/play (the game's own folder, so its relative paths work) |
| Activities → URL Mappings | Proxy path /api |
canyoncommand.10fold.stream/api (sign-in and the co-op relay) |
| Installation | Install contexts | User Install and Guild Install |
| General Information | Terms of Service URL | https://canyoncommand.10fold.stream/terms |
| General Information | Privacy Policy URL | https://canyoncommand.10fold.stream/privacy |
| General Information, Activities → Art Assets, Rich Presence → Art Assets, Bot | Art | From Substellar-Canyon-Command-Discord-Assets-v1.zip (project library; not in this repository). Its README maps each file to its field. |
While the app is unpublished, only team members and people under App Testers can launch it, in servers with fewer than 25 members.
04Testing
- Two-player test without Discord:
npm run build, thennpx wrangler dev --port 8788 --local, openhttp://127.0.0.1:8788/play/in two browser windows and use CO-OP.?debug=1exposes the component aswindow.__sub. - Balance:
node tools/balance-bot.js --maps co_fork,co_cross --diffs normal,hard --np 2 --strat pro(one bot per half). The co-op maps are generated bytools/coop-maps.cjs; edit the roads there and paste its output intogame/sub-data.js. - The Discord SDK is pinned in
package.jsonand bundled intogame/vendor/discord-sdk.jsbynode tools/vendor-discord.mjs.