Skip to content

Commit

Permalink
Merge object id reserve (mr-529)
Browse files Browse the repository at this point in the history
506b180 - fix(server): object id reserve
  • Loading branch information
nihonium-cfx committed Sep 24, 2024
2 parents e510b48 + 506b180 commit 8a1586d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1197,7 +1197,6 @@ struct GameStateClientData
{
rl::MessageBuffer ackBuffer{ 16384 };
std::unordered_set<int> objectIds;
std::unordered_set<int> reservedObjectIds;

std::mutex selfMutex;

Expand Down
24 changes: 2 additions & 22 deletions code/components/citizen-server-impl/src/state/ServerGameState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3198,9 +3198,6 @@ void ServerGameState::FinalizeClone(const fx::ClientSharedPtr& client, const fx:
{
auto [lock, clientData] = GetClientData(this, clientRef);
clientData->objectIds.erase(objectId);

// erase reserved object id from client, because the object got removed
clientData->reservedObjectIds.erase(objectId);
}
}

Expand Down Expand Up @@ -3302,9 +3299,6 @@ bool ServerGameState::ProcessClonePacket(const fx::ClientSharedPtr& client, rl::
auto [lock, data] = GetClientData(this, client);
data->playerId = playerId;
timestamp = data->syncTs;

// indicate that the reserved object id was used
data->reservedObjectIds.erase(objectId);
}

std::vector<uint8_t> bitBytes(length);
Expand Down Expand Up @@ -3939,20 +3933,7 @@ void ServerGameState::GetFreeObjectIds(const fx::ClientSharedPtr& client, uint8_
{
auto [lock, data] = GetClientData(this, client);
std::unique_lock objectIdsLock(m_objectIdsMutex);

// prevent requesting in sum more than double the amount of object ids that a single request can hold
// this allows reserving 64 in normal mode and 12 in big mode
if (data->reservedObjectIds.size() >= numIds * 2)
{
// empty response is required, because client has g_requestedIds set to false
// and will never request new ids again until a response is received
net::Buffer outBuffer;
outBuffer.Write<uint32_t>(HashRageString("msgObjectIds"));
outBuffer.Write<uint16_t>(0);
client->SendPacket(1, outBuffer, NetPacketType_Reliable);
return;
}


uint16_t id = 1;

for (uint8_t i = 0; i < numIds; i++)
Expand All @@ -3964,9 +3945,8 @@ void ServerGameState::GetFreeObjectIds(const fx::ClientSharedPtr& client, uint8_
if (!m_objectIdsSent.test(id) && !m_objectIdsUsed.test(id))
{
hadId = true;

data->objectIds.insert(id);
data->reservedObjectIds.insert(id);
freeIds.push_back(id);
m_objectIdsSent.set(id);

Expand Down

0 comments on commit 8a1586d

Please sign in to comment.