From b2e4e5182ba316aa73ec6dc698a2fb277a94f427 Mon Sep 17 00:00:00 2001 From: Daniel GP Date: Thu, 20 Nov 2025 12:26:19 +0100 Subject: [PATCH] fix(citizen-server-impl): prevent entity ownership desync on bucket changes and reduce migration timeout --- .../src/state/ServerGameState.cpp | 2 +- .../src/state/ServerGameState_Scripting.cpp | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/code/components/citizen-server-impl/src/state/ServerGameState.cpp b/code/components/citizen-server-impl/src/state/ServerGameState.cpp index d8d131168d..ccb98312c2 100644 --- a/code/components/citizen-server-impl/src/state/ServerGameState.cpp +++ b/code/components/citizen-server-impl/src/state/ServerGameState.cpp @@ -2137,7 +2137,7 @@ void ServerGameState::UpdateEntities() else { // workaround: force-migrate a stuck entity - if ((time - entity->lastReceivedAt) > 10s) + if ((time - entity->lastReceivedAt) > 5s) { if (g_oneSyncForceMigration->GetValue() || fx::IsBigMode()) { diff --git a/code/components/citizen-server-impl/src/state/ServerGameState_Scripting.cpp b/code/components/citizen-server-impl/src/state/ServerGameState_Scripting.cpp index bb64bc2953..cc57679754 100644 --- a/code/components/citizen-server-impl/src/state/ServerGameState_Scripting.cpp +++ b/code/components/citizen-server-impl/src/state/ServerGameState_Scripting.cpp @@ -1670,6 +1670,31 @@ static void Init() playerEntity->routingBucket = bucket; } + if (oldBucket != bucket) + { + auto slotId = client->GetSlotId(); + + std::shared_lock lock(gameState->m_entityListMutex); + for (auto& entity : gameState->m_entityList) + { + if (!entity || !entity->syncTree) + { + continue; + } + + if (entity->routingBucket == oldBucket) + { + std::lock_guard _(entity->guidMutex); + entity->relevantTo.reset(slotId); + + auto owner = entity->GetClient(); + if (owner && owner == client) + { + entity->wantsReassign = true; + } + } + } + } auto eventManager = resourceManager->GetComponent(); /*NETEV onPlayerBucketChange SERVER