Add server authority checks for networking safety
- PerceptionComponent: omniscient TActorIterator only runs with HasAuthority() - PersonalityComponent: ApplyReaction and ForceState gate replicated CurrentState writes to server only Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
d6325b373d
commit
b60086d107
@ -280,7 +280,8 @@ AActor* UPS_AI_Behavior_PerceptionComponent::GetHighestThreatActor(
|
||||
const AAIController* OwnerAIC = Cast<AAIController>(GetOwner());
|
||||
const APawn* OwnerPawn = OwnerAIC ? OwnerAIC->GetPawn() : nullptr;
|
||||
|
||||
if (OwnerPawn)
|
||||
// Only run on server — TActorIterator results differ on clients
|
||||
if (OwnerPawn && OwnerPawn->HasAuthority())
|
||||
{
|
||||
const EPS_AI_Behavior_TargetType TopPriority = TargetPriority[0];
|
||||
const UPS_AI_Behavior_Settings* Settings = GetDefault<UPS_AI_Behavior_Settings>();
|
||||
|
||||
@ -132,6 +132,12 @@ EPS_AI_Behavior_State UPS_AI_Behavior_PersonalityComponent::EvaluateReaction() c
|
||||
|
||||
EPS_AI_Behavior_State UPS_AI_Behavior_PersonalityComponent::ApplyReaction()
|
||||
{
|
||||
// Only server can change replicated state
|
||||
if (!GetOwner() || !GetOwner()->HasAuthority())
|
||||
{
|
||||
return CurrentState;
|
||||
}
|
||||
|
||||
const EPS_AI_Behavior_State NewState = EvaluateReaction();
|
||||
if (NewState != CurrentState)
|
||||
{
|
||||
@ -151,6 +157,12 @@ EPS_AI_Behavior_State UPS_AI_Behavior_PersonalityComponent::ApplyReaction()
|
||||
|
||||
void UPS_AI_Behavior_PersonalityComponent::ForceState(EPS_AI_Behavior_State NewState)
|
||||
{
|
||||
// Only server can change replicated state
|
||||
if (!GetOwner() || !GetOwner()->HasAuthority())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (NewState != CurrentState)
|
||||
{
|
||||
const EPS_AI_Behavior_State OldState = CurrentState;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user