mirror of
https://github.com/EQEmu/Server.git
synced 2026-05-31 04:56:20 +00:00
Updated patch map to an array and added null safety checks for the conversion
This commit is contained in:
+15
-9
@@ -22,15 +22,17 @@ template <typename Fun, typename Obj, typename... Args>
|
||||
requires std::is_member_function_pointer_v<Fun>
|
||||
static void QueuePacket(Client* c, Fun fun, Obj* obj, Args&&... args)
|
||||
{
|
||||
std::unique_ptr<EQApplicationPacket> app = std::invoke(fun, obj, std::forward<Args>(args)...);
|
||||
if (app)
|
||||
c->QueuePacket(app.get());
|
||||
if (obj != nullptr) {
|
||||
std::unique_ptr<EQApplicationPacket> app = std::invoke(fun, obj, std::forward<Args>(args)...);
|
||||
if (app)
|
||||
c->QueuePacket(app.get());
|
||||
}
|
||||
}
|
||||
|
||||
// packet generator queue functions
|
||||
static auto QueueClients(Mob* sender, bool ignore_sender = false, bool ackreq = true)
|
||||
{
|
||||
return [=]<typename Fun, typename Obj, typename... Args>(Fun fun, ComponentGetter<Obj> component, Args&&... args)
|
||||
return [=]<typename Fun, typename Obj, typename... Args>(Fun fun, const ComponentGetter<Obj>& component, Args&&... args)
|
||||
requires std::is_member_function_pointer_v<Fun>
|
||||
{
|
||||
std::vector<std::pair<EQ::versions::ClientVersion, std::unique_ptr<EQApplicationPacket>>> build_packets;
|
||||
@@ -44,8 +46,9 @@ static auto QueueClients(Mob* sender, bool ignore_sender = false, bool ackreq =
|
||||
});
|
||||
|
||||
if (packet_it == build_packets.end())
|
||||
packet_it = build_packets.emplace(build_packets.end(), ent->ClientVersion(),
|
||||
std::invoke(fun, component(ent), std::forward<Args>(args)...));
|
||||
if (Obj* comp = component(ent); comp != nullptr)
|
||||
packet_it = build_packets.emplace(build_packets.end(), ent->ClientVersion(),
|
||||
std::invoke(fun, comp, std::forward<Args>(args)...));
|
||||
|
||||
if (packet_it->second != nullptr)
|
||||
ent->QueuePacket(packet_it->second.get(), ackreq, Client::CLIENT_CONNECTED);
|
||||
@@ -61,7 +64,7 @@ static auto QueueCloseClients(
|
||||
{
|
||||
if (distance <= 0) distance = static_cast<float>(zone->GetClientUpdateRange());
|
||||
|
||||
return [=]<typename Fun, typename Obj, typename... Args>(Fun fun, ComponentGetter<Obj> component, Args&&... args)
|
||||
return [=]<typename Fun, typename Obj, typename... Args>(Fun fun, const ComponentGetter<Obj>& component, Args&&... args)
|
||||
requires std::is_member_function_pointer_v<Fun>
|
||||
{
|
||||
if (sender == nullptr) {
|
||||
@@ -85,8 +88,9 @@ static auto QueueCloseClients(
|
||||
});
|
||||
|
||||
if (packet_it == build_packets.end())
|
||||
packet_it = build_packets.emplace(build_packets.end(), client->ClientVersion(),
|
||||
std::invoke(fun, component(client), std::forward<Args>(args)...));
|
||||
if (auto comp = component(client); comp != nullptr)
|
||||
packet_it = build_packets.emplace(build_packets.end(), client->ClientVersion(),
|
||||
std::invoke(fun, comp, std::forward<Args>(args)...));
|
||||
|
||||
if (packet_it->second != nullptr)
|
||||
client->QueuePacket(packet_it->second.get(), is_ack_required, Client::CLIENT_CONNECTED);
|
||||
@@ -101,6 +105,8 @@ static auto QueueCloseClients(
|
||||
|
||||
// Helpers for the Message interface to send message packets
|
||||
namespace Message {
|
||||
|
||||
// this can return nullptr when the component doesn't exist for the version
|
||||
static std::function GetComponent = [](const Client* c) -> IMessage* {
|
||||
return GetMessageComponent(c->GetClientVersion()).get();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user