multiplayer-netcode
Use when the user asks about multiplayer netcode, client-side prediction and server reconciliation, entity interpolation, rollback netcode, GGPO, lag…
by j4flmao★ 47 GitHub stars
Install multiplayer-netcode in Claude Code & Claude Desktop
Sign up to install this skill
Create a free account to reveal the install command and save the skill to your library.
- Reveal the one-line install command
- Save skills to your synced library
- Get notified when skills update
About this skill
Multiplayer Netcode — Deep Guide
Purpose
Building robust multiplayer requires understanding latency, jitter, bandwidth, and how to hide them. This guide covers the full stack: transport, protocol design, client-server architecture, prediction, reconciliation, interpolation, lag compensation, rollback, and scalability.
Agent Protocol
Trigger
"multiplayer", "netcode", "client prediction", "server reconciliation", "entity interpolation", "rollback netcode", "lag compensation", "GGPO".
Input Context
- Genre and player count
- Engine and transport
- Latency targets and authority model
Output Artifact
Netcode design and code. No file unless requested.
Response Format
Model: {client-server | rollback}
Tick/send rates: {Hz}
Latency hiding: {technique}
Code: {snippet}
1. The Problem: The Network Is the Enemy
Typical round-trip times (RTT):
LAN: < 5 ms
Same region: 20-60 ms
Cross-continent: 100-200 ms (+ Wi-Fi/mobile jitter and loss)
Every client sees the world at least RTT/2 old; netcode decides who pays for that delay (the shooter, the target, or nobody via prediction).
Netcode turns "what happened at t" into "what each client believes happened at t".
2. Transport Layer
2.1 UDP vs TCP
| Aspect | TCP | UDP |
|---|---|---|
| Delivery | guaranteed, ordered | best-effort |
| Use | HTTP auth, file sync, chat | game state every frame |
| Problem | head-of-line blocking, retransmit stalls | reordering, loss |
Rule: game-critical state on UDP (custom reliable layer or RakNet-like reliable-UDP).
2.2 Reliable & Unreliable Channels
Split messages into channels:
- Unreliable (most important): position snapshots, input (recent is enough).
- Reliable ordered: login, join, inventory, item drop events.
- Reliable unordered: individual events with own ordering (per-entity).
Reliable-UDP: every packet carries its sequence number plus the latest received sequence and a 32-bit ack bitfield for the previous 32 packets, so each packet acknowledges many; lost reliable messages are re-sent in a later packet (not the same packet retransmitted).
2.3 Packet Layout
[Magic][Seq#][Ack#][AckBits][MessageCount][Message0][Message1]...
Header + per-message headers with bitpacking. Aim <1200B (Ethernet MTU 1500 minus IP/UDP headers); fragment bigger messages.
3. Architectures
3.1 Server-Authoritative (Mostly Standard)
Client ----inputs----> Server ----authoritative state----> Clients
<----snapshots (30-60Hz)----
- Server owns physics/gameplay. Clients send inputs and predict locally.
- Fair, cheat-resistant. Used by FPS (Valve, Overwatch, Fortnite).
3.2 P2P with Host Migration
- One peer is host with authority; migrating host on disconnect.
- Simpler for small games (party-based). Risk: host advantages.
3.3 P2P Lockstep (RTS)
- Every peer runs the SAME deterministic sim; inputs are exchanged and executed in lockstep with a fixed delay.
- Determinism is mandatory (fixed-point float discipline). Tiny bandwidth, perfect determinism → replays trivial.
- Problem: waits for the slowest peer per tick.
3.4 Client/Server vs P2P decision
| Game | Type |
|---|---|
| Competitive FPS/MOBA | server-authoritative + prediction |
| Top-down RTS/co-op | lockstep deterministic |
| Small co-op party | listen server with a client |
| Battle royale (40+ players) | dedicated server clusters |
4. Core Algorithms
4.1 Client-Side Prediction (Input-Based)
Client runs a local simulation of its controlled entity:
struct InputState { bool forward, back, left, right, fire; uint16_t seq; };
void ClientFrame() {
InputState in = CaptureInput();
pending.push_back({in, localTick});
ApplyToLocalSimulation(in); // PREDICT immediately
SendInputToServer(in); // UNRELIABLE channel
}
4.2 Server Reconciliation
Authoritative snapshots from server; client compares against its own predicted saved state at that point in time:
Server sends: tick, position, velocity, HP
Client: find the local state saved under same tick (input seq)
if position differs by > threshold -> snap BACK correction,
then re-apply all pending inputs up to now (fast-forward)
void OnSnapshot(tick, serverState) {
Saved& saved = history[tick];
if (distance(saved.pos, serverState.pos) > tolerance) {
world.state = serverState; // correct
for (pending input after tick) ApplyToLocalSimulation(input); // re-simulate
}
}
4.3 Interpolation (Visual Smoothing for Remote Entities)
Render other players via interpolation, not prediction:
- Keep a buffer of the last ~100ms of received snapshots.
- Render at
serverTime - interpolationDelay, where the delay covers ~2 snapshot intervals plus jitter (e.g. ~100 ms at 20 Hz snapshots) — it is independent of RTT. - For jitter: Jitter Buffer (s
Allowed tools
Tools this skill is permitted to call.
No restriction — this skill can use any tool.
Bundled files
- references/merged-game-engine-multiplayer-netcode.md
FAQ
What does the multiplayer-netcode skill do?
Use when the user asks about multiplayer netcode, client-side prediction and server reconciliation, entity interpolation, rollback netcode, GGPO, lag compensation for a shooter or choosing a transport. Produces gameplay netcode design and code. Not for server tick and fleet design (use authoritative-server or scaling-architecture).
How do I install the multiplayer-netcode skill?
Copy the skill folder into ~/.claude/skills (the Claude Code tab above does this in one command), or install it as a plugin.
Does the multiplayer-netcode skill run scripts?
No, this skill is instructions only (SKILL.md) with no executable scripts.
Related skills
mcp-builder
AnthropicGuide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
claude-api
AnthropicReference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
algorithmic-art
AnthropicCreating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
mcp-integration
AnthropicThis skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…