42 lines
1.4 KiB
Markdown
42 lines
1.4 KiB
Markdown
---
|
||
title: "Server-Authoritative Model"
|
||
type: concept
|
||
tags: []
|
||
sources: [unreal-multiplayer-architect]
|
||
last_updated: 2026-04-26
|
||
---
|
||
|
||
## Definition
|
||
服务器权威模型是 UE5 多人游戏网络架构的核心原则:服务器拥有真相(Server Owns Truth),所有游戏状态变更必须在服务器执行,客户端仅发送请求(RPC),由服务器验证后复制结果。
|
||
|
||
## Core Principles
|
||
- 所有游戏逻辑和状态变更必须运行在服务器端
|
||
- 客户端仅负责输入发送、本地预测和视觉表现
|
||
- `HasAuthority()` 检查必须在每次状态变更前执行
|
||
- 服务器有权拒绝任何非法客户端请求
|
||
|
||
## Implementation in UE5
|
||
```cpp
|
||
void AMyCharacter::TakeDamage(float DamageAmount)
|
||
{
|
||
// 必须先检查权威
|
||
if (!HasAuthority()) return; // 客户端绝对不能直接修改生命值
|
||
|
||
Health -= DamageAmount;
|
||
// 服务器修改后自动复制到所有客户端
|
||
}
|
||
```
|
||
|
||
## Connection to Other Concepts
|
||
- [[Actor Replication]] — 实现服务器权威的具体机制
|
||
- [[Network Prediction]] — 客户端利用权威模型进行本地预测以减少延迟
|
||
- [[RPC (Remote Procedure Call)]] — 客户端向服务器发送请求的通信方式
|
||
|
||
## Relationship to Agent
|
||
[[UnrealMultiplayerArchitect]] 是该模型的严格执行者,其核心规则强制所有游戏状态变更必须通过服务器权威验证。
|
||
|
||
## Aliases
|
||
- Server Authority
|
||
- Server-Owns-Truth
|
||
- Server-Authoritative Networking
|