$npx -y skills add thedivergentai/GD-Agentic-Skills --skill godot-adapt-single-to-multiplayerExpert patterns for adding multiplayer to single-player games including client-server architecture, authoritative server design, MultiplayerSynchronizer, lag compensation (client prediction, server reconciliation), input buffering, and anti-cheat measures. Use when retrofitting m
| 1 | ## Godot 4.7 Baseline |
| 2 | |
| 3 | - Expert patterns in this skill target **Godot 4.7+** (stable, 2026-06-18). |
| 4 | - Consult the [Godot 4.7 migration guide](https://docs.godotengine.org/en/4.7/tutorials/migrating/upgrading_to_godot_4.7.html) when upgrading projects from 4.6. |
| 5 | - **NEVER** assume 4.6 defaults (stretch mode, audio area_mask, RichTextLabel percent flags) without checking 4.7 migration notes. |
| 6 | |
| 7 | # Adapt: Single to Multiplayer |
| 8 | |
| 9 | Expert guidance for retrofitting multiplayer into single-player games. |
| 10 | |
| 11 | ## NEVER Do (Expert Multiplayer Rules) |
| 12 | |
| 13 | ### Security & Authority |
| 14 | - **NEVER trust client-reported state** — Clients own their 'Input', NOT their 'Position' or 'Health'. Server must validate every coordinate and health change. |
| 15 | - **NEVER use `get_tree()` groups for authority checks** — Use `is_multiplayer_authority()`. Group registration is non-deterministic in high-latency joins. |
| 16 | - **NEVER allow unrestricted RPC rates** — A malicious client can call a 'FireWeapon' RPC 10,000 times per second. Always implement rate-limiting (`net_rpc_rate_limiter.gd`). |
| 17 | |
| 18 | ### Movement & Lag |
| 19 | - **NEVER skip Client-Side Prediction** — Movement without prediction feels 'heavy' and unresponsive. Predict movement locally, then correct only on server disagreement. |
| 20 | - **NEVER sync peers at 60Hz** — Sending entire state every frame will saturate client bandwidth. Use a lower tick-rate (20-30Hz) and interpolate between packets. |
| 21 | - **NEVER snap peer positions** — Abrupt position updates cause 'jitter'. Store a buffer of past states and lerp between them with a 100ms delay. |
| 22 | |
| 23 | ### Bandwidth & Sync |
| 24 | - **NEVER sync 'Full Floats' if possible** — Quantize Vector3 data (truncating decimals) to save 50%+ bandwidth. Use `MultiplayerSynchronizer` with delta-sync enabled. |
| 25 | - **NEVER ignore 'Late Joiners'** — Players who join mid-game won't see existing environmental changes. Broadcast a full world-state 'Snapshot' on peer connection. |
| 26 | - **NEVER test on 0ms ping** — Everything works on localhost. Use a simulator (`net_latency_simulator.gd`) with 150ms ping to identify sync bugs. |
| 27 | |
| 28 | --- |
| 29 | |
| 30 | ## Available Scripts |
| 31 | |
| 32 | > **MANDATORY**: Read the appropriate script before implementing the corresponding pattern. |
| 33 | |
| 34 | ### [net_prediction_reconciliation.gd](scripts/net_prediction_reconciliation.gd) |
| 35 | Expert CharacterBody3D prediction with input-buffer replaying for server reconciliation. |
| 36 | |
| 37 | ### [net_snapshot_interpolation.gd](scripts/net_snapshot_interpolation.gd) |
| 38 | Professional snapshot interpolation logic for smoothing peer movement via jitter buffers. |
| 39 | |
| 40 | ### [net_auth_server_validator.gd](scripts/net_auth_server_validator.gd) |
| 41 | Authoritative server validator for anti-cheat (Position, Speed, and Action checks). |
| 42 | |
| 43 | ### [net_rpc_rate_limiter.gd](scripts/net_rpc_rate_limiter.gd) |
| 44 | Expert rate-limiter to prevent RPC flooding and macro-abuse by clients. |
| 45 | |
| 46 | ### [net_interest_management.gd](scripts/net_interest_management.gd) |
| 47 | Distance-based visibility management to optimize binary bandwidth per-peer. |
| 48 | |
| 49 | ### [net_delta_compression_sync.gd](scripts/net_delta_compression_sync.gd) |
| 50 | Expert quantization and significance-checking logic for delta-compression. |
| 51 | |
| 52 | ### [net_upnp_discovery_logic.gd](scripts/net_upnp_discovery_logic.gd) |
| 53 | Robust script for P2P network discovery and automatic port forwarding via UPNP. |
| 54 | |
| 55 | ### [net_debug_overlay_monitor.gd](scripts/net_debug_overlay_monitor.gd) |
| 56 | In-game diagnostic overlay reporting RTT (Ping), Packet Loss, and Jitter. |
| 57 | |
| 58 | ### [net_lag_compensation.gd](scripts/net_lag_compensation.gd) |
| 59 | Expert server-side state rewinding (Lag Compensation) for accurate hit-registration. |
| 60 | |
| 61 | ### [net_lobby_late_join_sync.gd](scripts/net_lobby_late_join_sync.gd) |
| 62 | Professional state-initialization logic to bridge 'Late Joiners' into a synced session. |
| 63 | |
| 64 | ### [net_latency_simulator.gd](scripts/net_latency_simulator.gd) |
| 65 | Editor-only tool for simulating high-ping and loss conditions for stress-testing. |
| 66 | |
| 67 | --- |
| 68 | |
| 69 | ## Architecture Patterns |
| 70 | |
| 71 | ### Pattern 1: Authoritative Server (Recommended) |
| 72 | |
| 73 | ```gdscript |
| 74 | # Server validates ALL gameplay logic |
| 75 | # Clients send inputs → Server processes → Server broadcasts state |
| 76 | |
| 77 | # Pros: Secure, prevents cheating |
| 78 | # Cons: Requires server hosting, lag affects gameplay |
| 79 | |
| 80 | # Use for: Competitive games, PvP, games with economies |
| 81 | ``` |
| 82 | |
| 83 | ### Pattern 2: Peer-to-Peer (Lockstep) |
| 84 | |
| 85 | ```gdscript |
| 86 | # All clients run identical simulation |
| 87 | # Inputs synced, deterministic physics |
| 88 | |
| 89 | # Pros: No dedicated server needed |
| 90 | # Cons: V |