Files
nexus/wiki/concepts/AntiCheatArchitecture.md
2026-04-26 12:02:53 +08:00

1.9 KiB

title, type, tags, sources, last_updated
title type tags sources last_updated
Anti-Cheat Architecture concept
networking
security
multiplayer
unity-multiplayer-engineer
2026-04-26

Aliases

  • Server-Side Validation
  • Anti-Cheat
  • 服务器端验证

Definition

反作弊架构是一套在服务器权威模型下验证所有客户端输入的设计原则和实现方案。由于客户端不可信,所有游戏关键操作必须在服务器端进行验证,拒绝非法请求并记录可疑行为。

Core Principles

  1. 永远不要信任客户端数据:客户端发送的任何值都需要验证
  2. 服务器拥有最终裁判权:位置、生命值、分数等由服务器计算
  3. 输入验证:检查输入是否在物理上可行
  4. 速率限制:检测并断开超出人类可能速度的 RPC 调用

Unity (NGO) Implementation

[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 类型的调用频率限制