53 lines
1.9 KiB
Markdown
53 lines
1.9 KiB
Markdown
---
|
|
title: "Anti-Cheat Architecture"
|
|
type: concept
|
|
tags: [networking, security, multiplayer]
|
|
sources: [unity-multiplayer-engineer]
|
|
last_updated: 2026-04-26
|
|
---
|
|
|
|
## Aliases
|
|
- Server-Side Validation
|
|
- Anti-Cheat
|
|
- 服务器端验证
|
|
|
|
## Definition
|
|
反作弊架构是一套在服务器权威模型下**验证所有客户端输入**的设计原则和实现方案。由于客户端不可信,所有游戏关键操作必须在服务器端进行验证,拒绝非法请求并记录可疑行为。
|
|
|
|
## Core Principles
|
|
1. **永远不要信任客户端数据**:客户端发送的任何值都需要验证
|
|
2. **服务器拥有最终裁判权**:位置、生命值、分数等由服务器计算
|
|
3. **输入验证**:检查输入是否在物理上可行
|
|
4. **速率限制**:检测并断开超出人类可能速度的 RPC 调用
|
|
|
|
## Unity (NGO) Implementation
|
|
```csharp
|
|
[ServerRpc]
|
|
private void SendInputServerRpc(Vector2 input, int tick)
|
|
{
|
|
// 服务器端验证:物理上是否可能?
|
|
float maxDistancePossible = _moveSpeed * Time.fixedDeltaTime * 2f;
|
|
if (Vector3.Distance(_serverPosition.Value, newPosition) > maxDistancePossible)
|
|
{
|
|
// 拒绝:瞬移检测或严重同步错误
|
|
_serverPosition.Value = _serverPosition.Value; // 强制调和
|
|
return;
|
|
}
|
|
_serverPosition.Value = newPosition;
|
|
}
|
|
```
|
|
|
|
## Key Techniques
|
|
- **移动验证**:速度上限检测、瞬移检测
|
|
- **命中检测**:服务器端验证目标位置和碰撞
|
|
- **审计日志**:记录所有游戏影响 RPC 的时间戳、玩家ID、动作类型
|
|
- **速率限制**:每玩家每 RPC 类型的调用频率限制
|
|
|
|
## Related Concepts
|
|
- [[ServerAuthority]]: 反作弊的基础
|
|
- [[UnityLobby]]: Lobby 数据不应包含游戏状态
|
|
- [[BandwidthManagement]]: 带宽控制也是反作弊的一部分
|
|
|
|
## Related Entities
|
|
- [[UnityMultiplayerEngineer]]: 实现反作弊架构的专家
|