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

1.5 KiB

title, type, tags, sources, last_updated
title type tags sources last_updated
Server Authority concept
networking
multiplayer
security
unity-multiplayer-engineer
2026-04-26

Aliases

  • Server Authority Model
  • Server-Authoritative Architecture

Definition

服务器权威模型是一种多人游戏网络架构范式,其中服务器拥有所有游戏状态的最终真相,包括玩家位置、生命值、分数、物品所有权等。客户端仅发送输入请求,服务器模拟并广播权威状态给所有客户端。

Key Principles

  • 客户端永远不直接发送位置数据——只发送原始输入(方向键、鼠标点击等)
  • 服务器执行所有游戏逻辑模拟,客户端显示服务器返回的结果
  • "永远不要信任来自客户端未经服务器验证的值"
  • 客户端预测移动后必须与服务器状态调和校正

Implementation in Unity (NGO)

// 服务器权威位置(只有服务器可写)
private NetworkVariable<Vector3> _serverPosition = new NetworkVariable<Vector3>(
    readPerm: NetworkVariableReadPermission.Everyone,
    writePerm: NetworkVariableWritePermission.Server);