multiplayer

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Multiplayer 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 servers
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 servers

Comparison

架构对比

ArchitectureLatencyCostSecurity
DedicatedLowHighStrong
P2PVariableLowWeak
Host-basedMediumLowMedium

架构类型延迟成本安全性
Dedicated
P2P可变
Host-based中等中等

2. Synchronization Principles

2. 同步原则

State vs Input

状态同步 vs 输入同步

ApproachSync WhatBest For
State SyncGame stateSimple, few objects
Input SyncPlayer inputsAction games
HybridBothMost games
方式同步内容适用场景
State Sync游戏状态简单、对象少的游戏
Input Sync玩家输入动作类游戏
Hybrid两者皆有大多数游戏

Lag Compensation

延迟补偿

TechniquePurpose
PredictionClient predicts server
InterpolationSmooth remote players
ReconciliationFix mispredictions
Lag compensationRewind for hit detection

技术手段用途
Prediction客户端预测服务器状态
Interpolation平滑远程玩家显示
Reconciliation修正预测偏差
Lag compensation为命中检测回退状态

3. Network Optimization

3. 网络优化

Bandwidth Reduction

带宽缩减

TechniqueSavings
Delta compressionSend only changes
QuantizationReduce precision
PriorityImportant data first
Area of interestOnly nearby entities
技术手段效果
Delta compression仅发送变化内容
Quantization降低精度
Priority优先发送重要数据
Area of interest仅发送附近实体数据

Update Rates

更新频率

TypeRate
Position20-60 Hz
HealthOn change
InventoryOn change
ChatOn 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

反作弊

CheatPrevention
Speed hackServer validates movement
AimbotServer validates sight line
Item dupeServer owns inventory
Wall hackDon't send hidden data

作弊类型防范措施
加速外挂服务器验证移动合理性
瞄准外挂服务器验证视线合理性
物品复制服务器掌控背包所有权
穿墙外挂不发送隐藏数据

5. Matchmaking

5. 匹配机制

Considerations

考量因素

FactorImpact
SkillFair matches
LatencyPlayable connection
Wait timePlayer patience
Party sizeGroup play

因素影响
Skill公平匹配
延迟保障可游玩的连接质量
等待时间影响玩家耐心
队伍规模适配组队游玩

6. Anti-Patterns

6. 反模式

❌ Don't✅ Do
Trust the clientServer is authority
Send everythingSend only necessary
Ignore latencyDesign for 100-200ms
Sync exact positionsInterpolate/predict

Remember: Never trust the client. The server is the source of truth.
❌ 禁止做法✅ 正确做法
信任客户端服务器作为权威来源
发送所有数据仅发送必要数据
忽略延迟针对100-200ms延迟设计
同步精确位置使用插值/预测

**记住:**永远不要信任客户端,服务器才是真相的来源。