Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase max sync packet length #1500

Merged
merged 1 commit into from Jun 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 17 additions & 8 deletions code/components/citizen-server-impl/src/state/ServerGameState.cpp
Expand Up @@ -38,11 +38,14 @@
#include <citizen_util/shared_reference.h>

#ifdef STATE_FIVE
static constexpr int g_netObjectTypeBitLength = 4;
static constexpr int kNetObjectTypeBitLength = 4;
#elif defined(STATE_RDR3)
static constexpr int g_netObjectTypeBitLength = 5;
static constexpr int kNetObjectTypeBitLength = 5;
#endif

static constexpr int kSyncPacketMaxLength = 2400;
static constexpr int kPacketWarnLength = 1300;

namespace rl
{
bool MessageBuffer::GetLengthHackState()
Expand Down Expand Up @@ -720,10 +723,16 @@ static void FlushBuffer(rl::MessageBuffer& buffer, uint32_t msgType, uint64_t fr
*(uint32_t*)(outData.data()) = msgType;
*(uint64_t*)(outData.data() + 4) = newFrame.full;

net::Buffer netBuffer(reinterpret_cast<uint8_t*>(outData.data()), len + 4 + 8);
netBuffer.Seek(len + 4 + 8); // since the buffer constructor doesn't actually set the offset
int bufferLen = len + 4 + 8;
net::Buffer netBuffer(reinterpret_cast<uint8_t*>(outData.data()), bufferLen);
netBuffer.Seek(bufferLen); // since the buffer constructor doesn't actually set the offset

if (bufferLen >= kPacketWarnLength)
{
console::DPrintf("net", "Sending a large packet (%d compressed bytes) to client %d, report if there will be any sync issues\n", bufferLen, client->GetNetId());
}

GS_LOG("flushBuffer: sending %d bytes to %d\n", len + 4 + 8, client->GetNetId());
GS_LOG("flushBuffer: sending %d bytes to %d\n", bufferLen, client->GetNetId());

client->SendPacket(1, netBuffer, NetPacketType_Unreliable);

Expand Down Expand Up @@ -1748,7 +1757,7 @@ void ServerGameState::Tick(fx::ServerInstanceBase* instance)
preCb(frameIndex, isFirstFrameUpdate);

// create a buffer once (per thread) to save allocations
static thread_local rl::MessageBuffer mb(1200);
static thread_local rl::MessageBuffer mb(kSyncPacketMaxLength);

mb.SetCurrentBit(0);

Expand Down Expand Up @@ -1809,7 +1818,7 @@ void ServerGameState::Tick(fx::ServerInstanceBase* instance)

if (syncType == 1)
{
cmdState.cloneBuffer.Write(g_netObjectTypeBitLength, (uint8_t)entity->type);
cmdState.cloneBuffer.Write(kNetObjectTypeBitLength, (uint8_t)entity->type);
cmdState.cloneBuffer.Write(32, entity->creationToken);
}

Expand Down Expand Up @@ -3085,7 +3094,7 @@ bool ServerGameState::ProcessClonePacket(const fx::ClientSharedPtr& client, rl::
{
creationToken = inPacket.Read<uint32_t>(32);

objectType = (sync::NetObjEntityType)inPacket.Read<uint8_t>(g_netObjectTypeBitLength);
objectType = (sync::NetObjEntityType)inPacket.Read<uint8_t>(kNetObjectTypeBitLength);
}

auto length = inPacket.Read<uint16_t>(12);
Expand Down
12 changes: 7 additions & 5 deletions code/components/gta-net-five/src/CloneManager.cpp
Expand Up @@ -43,11 +43,13 @@ rage::netObject* g_curNetObject;
static std::set<uint16_t> g_dontParrotDeletionAcks;

#ifdef GTA_FIVE
static constexpr int g_netObjectTypeBitLength = 4;
static constexpr int kNetObjectTypeBitLength = 4;
#elif IS_RDR3
static constexpr int g_netObjectTypeBitLength = 5;
static constexpr int kNetObjectTypeBitLength = 5;
#endif

static constexpr int kSyncPacketMaxLength = 2400;

void ObjectIds_AddObjectId(int objectId);
void ObjectIds_StealObjectId(int objectId);
void ObjectIds_ConfirmObjectId(int objectId);
Expand Down Expand Up @@ -908,7 +910,7 @@ void msgClone::Read(int syncType, rl::MessageBuffer& buffer)

if (syncType == 1)
{
m_entityType = (NetObjEntityType)buffer.Read<uint8_t>(g_netObjectTypeBitLength);
m_entityType = (NetObjEntityType)buffer.Read<uint8_t>(kNetObjectTypeBitLength);
m_creationToken = 0;

if (icgi->NetProtoVersion >= 0x202002271209)
Expand Down Expand Up @@ -2336,7 +2338,7 @@ void CloneManagerLocal::WriteUpdates()
#endif

// allocate a RAGE buffer
uint8_t packetStub[1200] = { 0 };
uint8_t packetStub[kSyncPacketMaxLength] = { 0 };
rage::datBitBuffer rlBuffer(packetStub, sizeof(packetStub));

// if we want to delete this object
Expand Down Expand Up @@ -2566,7 +2568,7 @@ void CloneManagerLocal::WriteUpdates()
netBuffer.Write(32, g_objectIdToCreationToken[objectId]);
}

netBuffer.Write(g_netObjectTypeBitLength, objectType);
netBuffer.Write(kNetObjectTypeBitLength, objectType);
}

uint32_t len = rlBuffer.GetDataLength();
Expand Down