Skip to content

Commit

Permalink
Merge Properly reassign entities that are set to `EntityOrphanMode::K…
Browse files Browse the repository at this point in the history
…eepEntity` (pr-2893)

a61a9b1 - fix(server/state): properly reassign entities that are set to `EntityOrphanMode::KeepEntity`
  • Loading branch information
prikolium-cfx committed Oct 31, 2024
2 parents dbe520e + a61a9b1 commit 138b1a5
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 138b1a5

Please sign in to comment.