File contents 多人游戏开发
网络架构与同步原则。
1. 架构选择
决策树
什么类型的多人游戏?
|
+-- 竞技 / 实时
| +-- Dedicated Server(专用服务器,权威)
|
+-- 合作 / 休闲
| +-- Host-based(基于主机,一个玩家作为服务器)
|
+-- 回合制
| +-- Client-server(客户端-服务器,简单)
|
+-- 大型(MMO)
+-- 分布式服务器
比较
架构
延迟
成本
安全性
Dedicated(专用)
低
高
强
P2P
可变
低
弱
Host-based(主机)
中
低
中
2. 同步原则
状态 vs 输入
方法
同步什么
最适合
State Sync(状态同步)
游戏状态
简单、对象少
Input Sync(输入同步)
玩家输入
动作游戏
Hybrid(混合)
两者
大多数游戏
延迟补偿
技术
目的
Prediction(预测)
客户端预测服务器
Interpolation(插值)
平滑远程玩家
Reconciliation(和解)
修正错误预测
Lag compensation(延迟补偿)
回滚以进行命中检测
3. 网络优化
带宽减少
技术
节省
Delta compression(增量压缩)
仅发送变化
Quantization(量化)
降低精度
Priority(优先级)
重要数据优先
Area of interest(兴趣区域)
仅附近实体
更新率
类型
速率
位置
20-60 Hz
生命值
变化时
库存
变化时
聊天
发送时
4. 安全原则
服务器权威
客户端: "我击中了敌人"
服务器: 验证 -> 抛射物真的击中了吗?
-> 玩家处于有效状态吗?
-> 时间上可能吗?
反作弊
作弊
预防
Speed hack(速度挂)
服务器验证移动
Aimbot(自瞄)
服务器验证视线
Item dupe(复制物品)
服务器拥有库存
Wall hack(透视)
不发送隐藏数据
5. 匹配
考量因素
因素
影响
Skill(技能)
公平比赛
Latency(延迟)
可玩的连接
Wait time(等待时间)
玩家耐心
Party size(队伍大小)
组队游玩
6. 反模式
[FAIL] 禁止
[OK] 推荐
信任客户端
服务器是权威
发送一切
仅发送必要的
忽略延迟
为 100-200ms 设计
同步精确位置
插值/预测
记住: 永远不要信任客户端。服务器是真理之源。
1 --- 2 name: multiplayer 3 description: 多人游戏开发原则。架构、网络、同步。 4 --- 5 6 # 多人游戏开发 7 8 > 网络架构与同步原则。 9 10 --- 11 12 ## 1. 架构选择 13 14 ### 决策树 15 16 ``` 17 什么类型的多人游戏? 18 | 19 +-- 竞技 / 实时 20 | +-- Dedicated Server(专用服务器,权威) 21 | 22 +-- 合作 / 休闲 23 | +-- Host-based(基于主机,一个玩家作为服务器) 24 | 25 +-- 回合制 26 | +-- Client-server(客户端-服务器,简单) 27 | 28 +-- 大型(MMO) 29 +-- 分布式服务器 30 ``` 31 32 ### 比较 33 34 | 架构 | 延迟 | 成本 | 安全性 | 35 | --- | --- | --- | --- | 36 | **Dedicated(专用)** | 低 | 高 | 强 | 37 | **P2P** | 可变 | 低 | 弱 | 38 | **Host-based(主机)** | 中 | 低 | 中 | 39 40 --- 41 42 ## 2. 同步原则 43 44 ### 状态 vs 输入 45 46 | 方法 | 同步什么 | 最适合 | 47 | --- | --- | --- | 48 | **State Sync(状态同步)** | 游戏状态 | 简单、对象少 | 49 | **Input Sync(输入同步)** | 玩家输入 | 动作游戏 | 50 | **Hybrid(混合)** | 两者 | 大多数游戏 | 51 52 ### 延迟补偿 53 54 | 技术 | 目的 | 55 | --- | --- | 56 | **Prediction(预测)** | 客户端预测服务器 | 57 | **Interpolation(插值)** | 平滑远程玩家 | 58 | **Reconciliation(和解)** | 修正错误预测 | 59 | **Lag compensation(延迟补偿)** | 回滚以进行命中检测 | 60 61 --- 62 63 ## 3. 网络优化 64 65 ### 带宽减少 66 67 | 技术 | 节省 | 68 | --- | --- | 69 | **Delta compression(增量压缩)** | 仅发送变化 | 70 | **Quantization(量化)** | 降低精度 | 71 | **Priority(优先级)** | 重要数据优先 | 72 | **Area of interest(兴趣区域)** | 仅附近实体 | 73 74 ### 更新率 75 76 | 类型 | 速率 | 77 | --- | --- | 78 | 位置 | 20-60 Hz | 79 | 生命值 | 变化时 | 80 | 库存 | 变化时 | 81 | 聊天 | 发送时 | 82 83 --- 84 85 ## 4. 安全原则 86 87 ### 服务器权威 88 89 ``` 90 客户端: "我击中了敌人" 91 服务器: 验证 -> 抛射物真的击中了吗? 92 -> 玩家处于有效状态吗? 93 -> 时间上可能吗? 94 ``` 95 96 ### 反作弊 97 98 | 作弊 | 预防 | 99 | --- | --- | 100 | Speed hack(速度挂) | 服务器验证移动 | 101 | Aimbot(自瞄) | 服务器验证视线 | 102 | Item dupe(复制物品) | 服务器拥有库存 | 103 | Wall hack(透视) | 不发送隐藏数据 | 104 105 --- 106 107 ## 5. 匹配 108 109 ### 考量因素 110 111 | 因素 | 影响 | 112 | --- | --- | 113 | **Skill(技能)** | 公平比赛 | 114 | **Latency(延迟)** | 可玩的连接 | 115 | **Wait time(等待时间)** | 玩家耐心 | 116 | **Party size(队伍大小)** | 组队游玩 | 117 118 --- 119 120 ## 6. 反模式 121 122 | [FAIL] 禁止 | [OK] 推荐 | 123 | --- | --- | 124 | 信任客户端 | 服务器是权威 | 125 | 发送一切 | 仅发送必要的 | 126 | 忽略延迟 | 为 100-200ms 设计 | 127 | 同步精确位置 | 插值/预测 | 128 129 --- 130 131 > **记住:** 永远不要信任客户端。服务器是真理之源。
misonl/ling/tree/main/.agents/skills/game-development/multiplayer commit f1dcee2480
Frequently asked questions How do I install the Multiplayer skill? Run npx skillmds@latest add misonl/multiplayer in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
What does the Multiplayer skill do? 多人游戏开发原则。架构、网络、同步。 It is listed under Coding & Dev Tools on SkillMD.
Is Multiplayer safe to use? This skill has not completed SkillMD's automated safety review yet. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
Which AI agents work with Multiplayer? This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Is Multiplayer free to use? Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
Who published Multiplayer? misonl (@misonl) published this skill. Their other Agent Skills are listed on their SkillMD profile.