multiplayer
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseMultiplayer Game Development
多人游戏开发
Networking architecture and synchronization principles.
网络架构与同步原则
1. Architecture Selection
1. 架构选择
Decision Tree
决策树
What type of multiplayer?
│
├── Competitive / Real-time
│ └── Dedicated Server (authoritative)
│
├── Cooperative / Casual
│ └── Host-based (one player is server)
│
├── Turn-based
│ └── Client-server (simple)
│
└── Massive (MMO)
└── Distributed serversWhat type of multiplayer?
│
├── Competitive / Real-time
│ └── Dedicated Server (authoritative)
│
├── Cooperative / Casual
│ └── Host-based (one player is server)
│
├── Turn-based
│ └── Client-server (simple)
│
└── Massive (MMO)
└── Distributed serversComparison
架构对比
| Architecture | Latency | Cost | Security |
|---|---|---|---|
| Dedicated | Low | High | Strong |
| P2P | Variable | Low | Weak |
| Host-based | Medium | Low | Medium |
| 架构类型 | 延迟 | 成本 | 安全性 |
|---|---|---|---|
| Dedicated | 低 | 高 | 强 |
| P2P | 可变 | 低 | 弱 |
| Host-based | 中等 | 低 | 中等 |
2. Synchronization Principles
2. 同步原则
State vs Input
状态同步 vs 输入同步
| Approach | Sync What | Best For |
|---|---|---|
| State Sync | Game state | Simple, few objects |
| Input Sync | Player inputs | Action games |
| Hybrid | Both | Most games |
| 方式 | 同步内容 | 适用场景 |
|---|---|---|
| State Sync | 游戏状态 | 简单、对象少的游戏 |
| Input Sync | 玩家输入 | 动作类游戏 |
| Hybrid | 两者皆有 | 大多数游戏 |
Lag Compensation
延迟补偿
| Technique | Purpose |
|---|---|
| Prediction | Client predicts server |
| Interpolation | Smooth remote players |
| Reconciliation | Fix mispredictions |
| Lag compensation | Rewind for hit detection |
| 技术手段 | 用途 |
|---|---|
| Prediction | 客户端预测服务器状态 |
| Interpolation | 平滑远程玩家显示 |
| Reconciliation | 修正预测偏差 |
| Lag compensation | 为命中检测回退状态 |
3. Network Optimization
3. 网络优化
Bandwidth Reduction
带宽缩减
| Technique | Savings |
|---|---|
| Delta compression | Send only changes |
| Quantization | Reduce precision |
| Priority | Important data first |
| Area of interest | Only nearby entities |
| 技术手段 | 效果 |
|---|---|
| Delta compression | 仅发送变化内容 |
| Quantization | 降低精度 |
| Priority | 优先发送重要数据 |
| Area of interest | 仅发送附近实体数据 |
Update Rates
更新频率
| Type | Rate |
|---|---|
| Position | 20-60 Hz |
| Health | On change |
| Inventory | On change |
| Chat | On send |
| 类型 | 频率 |
|---|---|
| 位置 | 20-60 Hz |
| 生命值 | 变化时发送 |
| 背包 | 变化时发送 |
| 聊天 | 发送时同步 |
4. Security Principles
4. 安全原则
Server Authority
服务器权威
Client: "I hit the enemy"
Server: Validate → did projectile actually hit?
→ was player in valid state?
→ was timing possible?Client: "I hit the enemy"
Server: Validate → did projectile actually hit?
→ was player in valid state?
→ was timing possible?Anti-Cheat
反作弊
| Cheat | Prevention |
|---|---|
| Speed hack | Server validates movement |
| Aimbot | Server validates sight line |
| Item dupe | Server owns inventory |
| Wall hack | Don't send hidden data |
| 作弊类型 | 防范措施 |
|---|---|
| 加速外挂 | 服务器验证移动合理性 |
| 瞄准外挂 | 服务器验证视线合理性 |
| 物品复制 | 服务器掌控背包所有权 |
| 穿墙外挂 | 不发送隐藏数据 |
5. Matchmaking
5. 匹配机制
Considerations
考量因素
| Factor | Impact |
|---|---|
| Skill | Fair matches |
| Latency | Playable connection |
| Wait time | Player patience |
| Party size | Group play |
| 因素 | 影响 |
|---|---|
| Skill | 公平匹配 |
| 延迟 | 保障可游玩的连接质量 |
| 等待时间 | 影响玩家耐心 |
| 队伍规模 | 适配组队游玩 |
6. Anti-Patterns
6. 反模式
| ❌ Don't | ✅ Do |
|---|---|
| Trust the client | Server is authority |
| Send everything | Send only necessary |
| Ignore latency | Design for 100-200ms |
| Sync exact positions | Interpolate/predict |
Remember: Never trust the client. The server is the source of truth.
| ❌ 禁止做法 | ✅ 正确做法 |
|---|---|
| 信任客户端 | 服务器作为权威来源 |
| 发送所有数据 | 仅发送必要数据 |
| 忽略延迟 | 针对100-200ms延迟设计 |
| 同步精确位置 | 使用插值/预测 |
**记住:**永远不要信任客户端,服务器才是真相的来源。