Skip to content

Commit

Permalink
fix(server/state): properly reassign entities that are set to `Entity…
Browse files Browse the repository at this point in the history
…OrphanMode::KeepEntity`

- this swaps `MoveEntityToCanidate` to use `ShouldServerKeepEntity` instead of having specific logic for orphan mode
- makes 'entitiesToDestroy' use `ShouldServerKeepEntity` instead of `IsOwnedByServerScript`so we reassign if orphan mode is set to keep the entity
  • Loading branch information
AvarianKnight committed Oct 30, 2024
1 parent 8f082c2 commit a61a9b1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,14 @@ struct SyncEntityState
}
return scriptHash;
}

/// <summary>
/// Checks of the entity is set to be kept by the server via orphan mode or by being owned by a server script.
/// </summary>
inline bool ShouldServerKeepEntity()
{
return IsOwnedByServerScript() || orphanMode == EntityOrphanMode::KeepEntity;
}

inline bool IsOwnedByScript()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1515,7 +1515,7 @@ void ServerGameState::Tick(fx::ServerInstanceBase* instance)
if (entityClient && entityClient->GetNetId() == client->GetNetId())
{
// if this entity is owned by a server script, reassign to nobody and wait until someone else owns it
if (entity->IsOwnedByServerScript())
if (entity->ShouldServerKeepEntity())
{
ReassignEntity(entity->handle, {});
}
Expand Down Expand Up @@ -2812,10 +2812,9 @@ bool ServerGameState::MoveEntityToCandidate(const fx::sync::SyncEntityPtr& entit

if (candidates.empty()) // no candidate?
{
GS_LOG("no candidates for entity %d, assigning as unowned\n", entity->handle);

if (entity->IsOwnedByServerScript())
if (entity->ShouldServerKeepEntity())
{
GS_LOG("no candidates for entity %d, assigning as unowned\n", entity->handle);
ReassignEntity(entity->handle, {});
}
else
Expand Down Expand Up @@ -2924,8 +2923,7 @@ void ServerGameState::HandleClientDrop(const fx::ClientSharedPtr& client, uint16
{
ReassignEntity(entity->handle, firstOwner);
}
// we don't want to add these to the list to remove if they're set to be kept when orphaned
else if (entity->orphanMode != sync::KeepEntity)
else
{
toErase.insert(entity->handle);
}
Expand Down

0 comments on commit a61a9b1

Please sign in to comment.