cloudflare-do-turn-based-multiplayer
Skill171 starsChanged 8 months agoMITView on GitHub
Design, implement, debug, or verify a remote turn-based multiplayer game whose rooms run on Cloudflare Durable Objects. Use for room and invite identity, reconnectable seats, WebSocket hibernation, concurrent turns, action idempotency, revision conflicts, or cross-browser game-state agreement. Do not trigger for generic Durable Object applications or local-only games.
In this repository99 other files it gives its agents.
- AGENTS.mdAGENTS.md
- accelevents-apiSkill
- accelevents-speaker-syncSkill
- agents-sdkSkill
- ai-devblogSkill
- ai-engineeringSkill
- ai-readmeSkill
- align-meSkill
- antislop-codebaseSkill
- app-ux-paradigmsSkill
- autoreviewSkill
- babysit-runsSkill
- blog-system-designSkill
- cassandra-creatorSkill
- ceo-creatorSkill
- claude-session-introspectSkill
- cli-uxSkill
- cloudflare-email-serviceSkill
- cloudflare-one-migrationsSkill
- cloudflare-oneSkill
- cloudflare-production-builderSkill
- cloudflareSkill
- conference-developer-endpointsSkill
- conference-transcribeSkill
- coordinateSkill
- data-chatbotsSkill
- data-visualization-qualitySkill
- deep-trajectory-analysisSkill
- design-apps-with-imagegenSkill
- design-preferencesSkill
- diy-netlifySkill
- download-videoSkill
- download-x-videoSkill
- durable-objectsSkill
- europe-developer-apiSkill
- face-matchingSkill
- forgeSkill
- future-onlySkill
- generalizeSkill
- gsuite-setupSkill
- keep-it-simpleSkill
- latent-space-thumbnail-directorSkill
- live-ai-pipelinesSkill
- location-inputSkill
- long-running-operation-uxSkill
- media-heavy-workflowsSkill
- media-to-wiki-pipelineSkill
- media-transformSkill
- mobile-nativeSkill
- mobile-webapp-uxSkill
- multimodal-extractionSkill
- new-mac-setupSkill
- next-stepsSkill
- observability-hardeningSkill
- person-profile-writingSkill
- podcast-publishing-assistantSkill
- productionize-app-with-servicesSkill
- programmatic-agentsSkill
- provision-model-keysSkill
- public-qa-chatbotSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
4 rules. About 0 are common, 3 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 37
check immutable actionId duplication before checking expectedRevision.
- Distinctive: line 51
After an acknowledgement timeout, treat the result as unknown: reconnect, load the canonical snapshot, and retry only with the same action …
- Distinctive: line 60
Use the Hibernation WebSocket API for idle server connections when appropriate.
- Distinctive: line 65
Put alarm-driven bot or timeout transitions through the same mutation path.
≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Cloudflare DO Turn-Based Multiplayer
Model each room as one server-authoritative state machine. Keep the deterministic game reducer independent from Cloudflare transport so rules and concurrency can be tested without Wrangler.
Establish authority
Before editing, identify:
- the room's deterministic Durable Object ID;
- the public room code and any private invite credential;
- how a device resumes and which seats it owns;
- the persisted room revision and action identity; and
- how clients recover after an unknown result.
The URL room code is the room selector, not authentication. Store resume credentials per room, exchange private invites for device credentials, and remove invite secrets from the visible URL after exchange. Re-authorize the device against current room state on every mutation.
Read protocol-and-architecture.md when changing URLs, identity, message schemas, persistence, or recovery.
Serialize mutations
Durable Objects serialize events, but handlers can interleave at external
await boundaries. For every authoritative action:
- enter one room mutation gate;
- re-read state and re-authorize the device inside it;
- check immutable
actionIdduplication before checkingexpectedRevision; - validate the fresh revision and deterministic game rule;
- persist the accepted state before acknowledgement or broadcast; and
- return the canonical snapshot for acceptance, duplication, or rejection.
A duplicate action returns the prior accepted result without applying side
effects again. A stale or illegal action returns its actionId, reason, and
canonical snapshot. The client proposes an action; it never submits trusted
scores, turn order, or board outcomes.
Keep acknowledgement and recovery explicit
Correlate every syntactically valid mutation with its actionId. Apply snapshots
monotonically by revision. Keep a rejected local draft available for repair.
After an acknowledgement timeout, treat the result as unknown: reconnect, load
the canonical snapshot, and retry only with the same action identity when the
protocol permits it.
One in-flight action per client is the simple default. More optimistic behavior requires an explicit conflict and rebase design.
Durable Object and WebSocket boundaries
- Use the Hibernation WebSocket API for idle server connections when appropriate.
- Store only stable identifiers in WebSocket attachments; persistent room state belongs in Durable Object storage.
- Derive presence from live sockets rather than treating it as game authority.
- Version and normalize stored room state, then validate cross-field invariants.
- Put alarm-driven bot or timeout transitions through the same mutation path.
- Bound message sizes, text, activity rate, and retained action IDs.
- Parse explicit inbound and outbound protocol allowlists.
- Hash long-lived device credentials and return room/join/resume responses with
Cache-Control: no-store.
Exercise the actual Worker entrypoint and Durable Object binding; a frontend-only development server is not a multiplayer test.
Verify the failure cases that matter
At minimum, cover wrong-room credential isolation, private-invite exchange, invalid resume recovery, same-revision concurrent actions, duplicate delivery, disconnect/resume, and two isolated browsers completing turns with identical room state. Add four-player or full-round playthroughs only when supported by the game being changed.
Read failure-modes-and-verification.md for reported lobby/start failures or a release-readiness review. Report exactly which layer passed: pure protocol, local Worker/DO, isolated-browser playthrough, or deployed custom-domain behavior.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

