Skip to content

Commit

Permalink
Merge timing netevent (mr-553)
Browse files Browse the repository at this point in the history
63dafc3 - tweak(server): move msgNetGameEventV2 for compatibility to sync thread
f6b8773 - tweak(server): remove small fmt usage
c90f7da - tweak(onesync): add max net game event retries to client
  • Loading branch information
nihonium committed Oct 14, 2024
2 parents 1d91592 + 63dafc3 commit 20656b6
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ class NetGameEventPacketHandlerV2
}

static void COMPONENT_EXPORT(CITIZEN_SERVER_IMPL) RouteEvent(const fwRefContainer<fx::ServerGameStatePublic>& sgs, uint32_t bucket, const std::vector<uint16_t>& targetPlayers, const fwRefContainer<fx::ClientRegistry>& clientRegistry, const net::Buffer& data);

void COMPONENT_EXPORT(CITIZEN_SERVER_IMPL) Handle(fx::ServerInstanceBase* instance, const fx::ClientSharedPtr& client, net::Buffer& packet);

static void COMPONENT_EXPORT(CITIZEN_SERVER_IMPL) HandleNetEvent(fx::ServerInstanceBase* instance, const fx::ClientSharedPtr& client, const net::Buffer& packet);

static constexpr const char* GetPacketId()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,15 @@ void NetGameEventPacketHandlerV2::RouteEvent(const fwRefContainer<fx::ServerGame
}
}

void NetGameEventPacketHandlerV2::Handle(fx::ServerInstanceBase* instance, const fx::ClientSharedPtr& client, net::Buffer& buffer)
void NetGameEventPacketHandlerV2::Handle(fx::ServerInstanceBase* instance, const fx::ClientSharedPtr& client, net::Buffer& packet)
{
gscomms_execute_callback_on_sync_thread([instance, client, packet = std::move(packet)]
{
HandleNetEvent(instance, client, packet);
});
}

void NetGameEventPacketHandlerV2::HandleNetEvent(fx::ServerInstanceBase* instance, const fx::ClientSharedPtr& client, const net::Buffer& buffer)
{
static size_t kClientMaxPacketSize = net::SerializableComponent::GetMaxSize<net::packet::ClientNetGameEventV2>();
static size_t kServerMaxReplySize = net::SerializableComponent::GetMaxSize<net::packet::ServerNetGameEventV2Packet>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6754,7 +6754,7 @@ inline auto GetHandler(fx::ServerInstanceBase* instance, const fx::ClientSharedP
return [instance, client, ev = std::move(ev)]()
{
auto evComponent = instance->GetComponent<fx::ResourceManager>()->GetComponent<fx::ResourceEventManagerComponent>();
return evComponent->TriggerEvent2(ev->GetName(), { }, fmt::sprintf("%d", client->GetNetId()), *ev);
return evComponent->TriggerEvent2(ev->GetName(), { }, std::to_string(client->GetNetId()), *ev);
};
}

Expand All @@ -6776,7 +6776,7 @@ inline auto GetHandlerWithEvent(fx::ServerInstanceBase* instance, const fx::Clie
return [instance, client, ev = std::move(ev)]()
{
auto evComponent = instance->GetComponent<fx::ResourceManager>()->GetComponent<fx::ResourceEventManagerComponent>();
return evComponent->TriggerEvent2(ev->GetName(), { }, fmt::sprintf("%d", client->GetNetId()), *ev);
return evComponent->TriggerEvent2(ev->GetName(), { }, std::to_string(client->GetNetId()), *ev);
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class NetGameEventV2PacketHandler : public net::PacketHandler<net::packet::Serve
return;
}

rage::HandleNetGameEventV2(serverNetGameEventV2);
rage::HandleNetGameEventV2(serverNetGameEventV2, 0);
});
}
};
Expand Down
2 changes: 1 addition & 1 deletion code/components/gta-net-five/include/netGameEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,5 +255,5 @@ namespace rage
CNetGamePlayer* GetPlayer31();

static void HandleNetGameEvent(const char* idata, size_t len);
static void HandleNetGameEventV2(net::packet::ServerNetGameEventV2& serverNetGameEventV2);
static void HandleNetGameEventV2(net::packet::ServerNetGameEventV2& serverNetGameEventV2, uint8_t retries);
}
18 changes: 13 additions & 5 deletions code/components/gta-net-five/src/netGameEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,15 @@ struct ReEventQueueItem
uint16_t eventId;
bool isReply;
std::vector<uint8_t> eventData;
uint8_t retries;

ReEventQueueItem(net::packet::ServerNetGameEventV2& serverNetGameEvent):
ReEventQueueItem(net::packet::ServerNetGameEventV2& serverNetGameEvent, uint8_t retries):
eventNameHash(serverNetGameEvent.eventNameHash),
clientNetId(serverNetGameEvent.clientNetId),
eventId(serverNetGameEvent.eventId),
isReply(serverNetGameEvent.isReply),
eventData(serverNetGameEvent.data.GetValue().begin(), serverNetGameEvent.data.GetValue().end())
eventData(serverNetGameEvent.data.GetValue().begin(), serverNetGameEvent.data.GetValue().end()),
retries(retries)
{

}
Expand Down Expand Up @@ -543,13 +545,18 @@ void rage::HandleNetGameEvent(const char* idata, size_t len)
}
}

void rage::HandleNetGameEventV2(net::packet::ServerNetGameEventV2& serverNetGameEventV2)
void rage::HandleNetGameEventV2(net::packet::ServerNetGameEventV2& serverNetGameEventV2, uint8_t retries)
{
if (!icgi->HasVariable("networkInited"))
{
return;
}

if (retries > 100)
{
return;
}

// TODO: use a real player for some things that _are_ 32-safe
rage::EnsurePlayer31();

Expand Down Expand Up @@ -641,7 +648,7 @@ void rage::HandleNetGameEventV2(net::packet::ServerNetGameEventV2& serverNetGame

if (rejected)
{
g_reEventQueueV2.emplace_back(serverNetGameEventV2);
g_reEventQueueV2.emplace_back(serverNetGameEventV2, retries + 1);
}
}
}
Expand Down Expand Up @@ -1167,7 +1174,7 @@ namespace rage
serverNetGameEvent.isReply = g_reEventQueueV2.front().isReply;
serverNetGameEvent.data = {g_reEventQueueV2.front().eventData.data(), g_reEventQueueV2.front().eventData.size()};

HandleNetGameEventV2(serverNetGameEvent);
HandleNetGameEventV2(serverNetGameEvent, g_reEventQueueV2.front().retries);

g_reEventQueueV2.pop_front();
}
Expand Down Expand Up @@ -1235,6 +1242,7 @@ static InitFunction initFunction([]()
g_events.clear();
g_eventsV2.clear();
g_reEventQueue.clear();
g_reEventQueueV2.clear();
});
});

Expand Down

0 comments on commit 20656b6

Please sign in to comment.