$npx -y skills add One-Man-Company/Skills-ContextManager --skill multiplayerMultiplayer game development principles. Architecture, networking, synchronization.
| 1 | # Multiplayer Game Development |
| 2 | |
| 3 | > Networking architecture and synchronization principles. |
| 4 | |
| 5 | --- |
| 6 | |
| 7 | ## 1. Architecture Selection |
| 8 | |
| 9 | ### Decision Tree |
| 10 | |
| 11 | ``` |
| 12 | What type of multiplayer? |
| 13 | │ |
| 14 | ├── Competitive / Real-time |
| 15 | │ └── Dedicated Server (authoritative) |
| 16 | │ |
| 17 | ├── Cooperative / Casual |
| 18 | │ └── Host-based (one player is server) |
| 19 | │ |
| 20 | ├── Turn-based |
| 21 | │ └── Client-server (simple) |
| 22 | │ |
| 23 | └── Massive (MMO) |
| 24 | └── Distributed servers |
| 25 | ``` |
| 26 | |
| 27 | ### Comparison |
| 28 | |
| 29 | | Architecture | Latency | Cost | Security | |
| 30 | |--------------|---------|------|----------| |
| 31 | | **Dedicated** | Low | High | Strong | |
| 32 | | **P2P** | Variable | Low | Weak | |
| 33 | | **Host-based** | Medium | Low | Medium | |
| 34 | |
| 35 | --- |
| 36 | |
| 37 | ## 2. Synchronization Principles |
| 38 | |
| 39 | ### State vs Input |
| 40 | |
| 41 | | Approach | Sync What | Best For | |
| 42 | |----------|-----------|----------| |
| 43 | | **State Sync** | Game state | Simple, few objects | |
| 44 | | **Input Sync** | Player inputs | Action games | |
| 45 | | **Hybrid** | Both | Most games | |
| 46 | |
| 47 | ### Lag Compensation |
| 48 | |
| 49 | | Technique | Purpose | |
| 50 | |-----------|---------| |
| 51 | | **Prediction** | Client predicts server | |
| 52 | | **Interpolation** | Smooth remote players | |
| 53 | | **Reconciliation** | Fix mispredictions | |
| 54 | | **Lag compensation** | Rewind for hit detection | |
| 55 | |
| 56 | --- |
| 57 | |
| 58 | ## 3. Network Optimization |
| 59 | |
| 60 | ### Bandwidth Reduction |
| 61 | |
| 62 | | Technique | Savings | |
| 63 | |-----------|---------| |
| 64 | | **Delta compression** | Send only changes | |
| 65 | | **Quantization** | Reduce precision | |
| 66 | | **Priority** | Important data first | |
| 67 | | **Area of interest** | Only nearby entities | |
| 68 | |
| 69 | ### Update Rates |
| 70 | |
| 71 | | Type | Rate | |
| 72 | |------|------| |
| 73 | | Position | 20-60 Hz | |
| 74 | | Health | On change | |
| 75 | | Inventory | On change | |
| 76 | | Chat | On send | |
| 77 | |
| 78 | --- |
| 79 | |
| 80 | ## 4. Security Principles |
| 81 | |
| 82 | ### Server Authority |
| 83 | |
| 84 | ``` |
| 85 | Client: "I hit the enemy" |
| 86 | Server: Validate → did projectile actually hit? |
| 87 | → was player in valid state? |
| 88 | → was timing possible? |
| 89 | ``` |
| 90 | |
| 91 | ### Anti-Cheat |
| 92 | |
| 93 | | Cheat | Prevention | |
| 94 | |-------|------------| |
| 95 | | Speed hack | Server validates movement | |
| 96 | | Aimbot | Server validates sight line | |
| 97 | | Item dupe | Server owns inventory | |
| 98 | | Wall hack | Don't send hidden data | |
| 99 | |
| 100 | --- |
| 101 | |
| 102 | ## 5. Matchmaking |
| 103 | |
| 104 | ### Considerations |
| 105 | |
| 106 | | Factor | Impact | |
| 107 | |--------|--------| |
| 108 | | **Skill** | Fair matches | |
| 109 | | **Latency** | Playable connection | |
| 110 | | **Wait time** | Player patience | |
| 111 | | **Party size** | Group play | |
| 112 | |
| 113 | --- |
| 114 | |
| 115 | ## 6. Anti-Patterns |
| 116 | |
| 117 | | ❌ Don't | ✅ Do | |
| 118 | |----------|-------| |
| 119 | | Trust the client | Server is authority | |
| 120 | | Send everything | Send only necessary | |
| 121 | | Ignore latency | Design for 100-200ms | |
| 122 | | Sync exact positions | Interpolate/predict | |
| 123 | |
| 124 | --- |
| 125 | |
| 126 | > **Remember:** Never trust the client. The server is the source of truth. |