From 01d8a92009cd99380c5e614a49b9da5aae0effdc Mon Sep 17 00:00:00 2001 From: Zach Toogood Date: Mon, 3 Mar 2025 12:29:34 +0000 Subject: [PATCH 1/2] IPC: Swap to using static dispatch --- src/common/ipc.h | 4 +- src/map/ipc_client.cpp | 2 +- src/map/ipc_client.h | 76 +++++++++++----------- src/world/ipc_server.cpp | 2 +- src/world/ipc_server.h | 79 ++++++++++++----------- tools/generate_ipc_stubs.py | 122 ++++++++++++++++++++++-------------- 6 files changed, 156 insertions(+), 129 deletions(-) diff --git a/src/common/ipc.h b/src/common/ipc.h index c311609d557..ea8306ff99d 100644 --- a/src/common/ipc.h +++ b/src/common/ipc.h @@ -74,7 +74,7 @@ namespace ipc auto bytes = std::vector(); auto bytes_written = alpaca::serialize(object, bytes); - const auto type = static_cast(getEnumType()); + const auto type = static_cast(EnumTypeV); std::vector message(1 + bytes_written); message[0] = type; @@ -110,7 +110,7 @@ namespace ipc } const auto type = static_cast(message[0]); - if (type != getEnumType()) + if (type != EnumTypeV) { return std::nullopt; } diff --git a/src/map/ipc_client.cpp b/src/map/ipc_client.cpp index e3aa3dd868d..30cdda3c0a6 100644 --- a/src/map/ipc_client.cpp +++ b/src/map/ipc_client.cpp @@ -124,7 +124,7 @@ void IPCClient::handleIncomingMessages() // TODO: Make an IPP for the world server, so we can use it here DebugIPCFmt("Incoming {} message", msgType); - ipc::IIPCMessageHandler::handleMessage(IPP(), { static_cast(out.data()), out.size() }); + handleMessage(IPP(), { static_cast(out.data()), out.size() }); } } diff --git a/src/map/ipc_client.h b/src/map/ipc_client.h index 1f86a02161a..5a8405192f0 100644 --- a/src/map/ipc_client.h +++ b/src/map/ipc_client.h @@ -33,7 +33,7 @@ #include #include -class IPCClient final : public ipc::IIPCMessageHandler +class IPCClient final : public ipc::IPCMessageHandlerBase { public: IPCClient(); @@ -44,44 +44,44 @@ class IPCClient final : public ipc::IIPCMessageHandler void sendMessage(const T& message); // - // ipc::IIPCMessageHandler + // ipc::IPCMessageHandlerBase // - void handleMessage_EmptyStruct(const IPP& ipp, const ipc::EmptyStruct& message) override; - void handleMessage_CharLogin(const IPP& ipp, const ipc::CharLogin& message) override; - void handleMessage_CharZone(const IPP& ipp, const ipc::CharZone& message) override; - void handleMessage_CharVarUpdate(const IPP& ipp, const ipc::CharVarUpdate& message) override; - void handleMessage_ChatMessageTell(const IPP& ipp, const ipc::ChatMessageTell& message) override; - void handleMessage_ChatMessageParty(const IPP& ipp, const ipc::ChatMessageParty& message) override; - void handleMessage_ChatMessageAlliance(const IPP& ipp, const ipc::ChatMessageAlliance& message) override; - void handleMessage_ChatMessageLinkshell(const IPP& ipp, const ipc::ChatMessageLinkshell& message) override; - void handleMessage_ChatMessageUnity(const IPP& ipp, const ipc::ChatMessageUnity& message) override; - void handleMessage_ChatMessageYell(const IPP& ipp, const ipc::ChatMessageYell& message) override; - void handleMessage_ChatMessageServerMessage(const IPP& ipp, const ipc::ChatMessageServerMessage& message) override; - void handleMessage_ChatMessageCustom(const IPP& ipp, const ipc::ChatMessageCustom& message) override; - void handleMessage_PartyInvite(const IPP& ipp, const ipc::PartyInvite& message) override; - void handleMessage_PartyInviteResponse(const IPP& ipp, const ipc::PartyInviteResponse& message) override; - void handleMessage_PartyReload(const IPP& ipp, const ipc::PartyReload& message) override; - void handleMessage_PartyDisband(const IPP& ipp, const ipc::PartyDisband& message) override; - void handleMessage_AllianceReload(const IPP& ipp, const ipc::AllianceReload& message) override; - void handleMessage_AllianceDissolve(const IPP& ipp, const ipc::AllianceDissolve& message) override; - void handleMessage_PlayerKick(const IPP& ipp, const ipc::PlayerKick& message) override; - void handleMessage_MessageStandard(const IPP& ipp, const ipc::MessageStandard& message) override; - void handleMessage_MessageSystem(const IPP& ipp, const ipc::MessageSystem& message) override; - void handleMessage_LinkshellRankChange(const IPP& ipp, const ipc::LinkshellRankChange& message) override; - void handleMessage_LinkshellRemove(const IPP& ipp, const ipc::LinkshellRemove& message) override; - void handleMessage_LinkshellSetMessage(const IPP& ipp, const ipc::LinkshellSetMessage& message) override; - void handleMessage_LuaFunction(const IPP& ipp, const ipc::LuaFunction& message) override; - void handleMessage_KillSession(const IPP& ipp, const ipc::KillSession& message) override; - void handleMessage_ConquestEvent(const IPP& ipp, const ipc::ConquestEvent& message) override; - void handleMessage_BesiegedEvent(const IPP& ipp, const ipc::BesiegedEvent& message) override; - void handleMessage_CampaignEvent(const IPP& ipp, const ipc::CampaignEvent& message) override; - void handleMessage_ColonizationEvent(const IPP& ipp, const ipc::ColonizationEvent& message) override; - void handleMessage_EntityInformationRequest(const IPP& ipp, const ipc::EntityInformationRequest& message) override; - void handleMessage_EntityInformationResponse(const IPP& ipp, const ipc::EntityInformationResponse& message) override; - void handleMessage_SendPlayerToLocation(const IPP& ipp, const ipc::SendPlayerToLocation& message) override; - - void handleUnknownMessage(const IPP& ipp, const std::span message) override; + void handleMessage_EmptyStruct(const IPP& ipp, const ipc::EmptyStruct& message); + void handleMessage_CharLogin(const IPP& ipp, const ipc::CharLogin& message); + void handleMessage_CharZone(const IPP& ipp, const ipc::CharZone& message); + void handleMessage_CharVarUpdate(const IPP& ipp, const ipc::CharVarUpdate& message); + void handleMessage_ChatMessageTell(const IPP& ipp, const ipc::ChatMessageTell& message); + void handleMessage_ChatMessageParty(const IPP& ipp, const ipc::ChatMessageParty& message); + void handleMessage_ChatMessageAlliance(const IPP& ipp, const ipc::ChatMessageAlliance& message); + void handleMessage_ChatMessageLinkshell(const IPP& ipp, const ipc::ChatMessageLinkshell& message); + void handleMessage_ChatMessageUnity(const IPP& ipp, const ipc::ChatMessageUnity& message); + void handleMessage_ChatMessageYell(const IPP& ipp, const ipc::ChatMessageYell& message); + void handleMessage_ChatMessageServerMessage(const IPP& ipp, const ipc::ChatMessageServerMessage& message); + void handleMessage_ChatMessageCustom(const IPP& ipp, const ipc::ChatMessageCustom& message); + void handleMessage_PartyInvite(const IPP& ipp, const ipc::PartyInvite& message); + void handleMessage_PartyInviteResponse(const IPP& ipp, const ipc::PartyInviteResponse& message); + void handleMessage_PartyReload(const IPP& ipp, const ipc::PartyReload& message); + void handleMessage_PartyDisband(const IPP& ipp, const ipc::PartyDisband& message); + void handleMessage_AllianceReload(const IPP& ipp, const ipc::AllianceReload& message); + void handleMessage_AllianceDissolve(const IPP& ipp, const ipc::AllianceDissolve& message); + void handleMessage_PlayerKick(const IPP& ipp, const ipc::PlayerKick& message); + void handleMessage_MessageStandard(const IPP& ipp, const ipc::MessageStandard& message); + void handleMessage_MessageSystem(const IPP& ipp, const ipc::MessageSystem& message); + void handleMessage_LinkshellRankChange(const IPP& ipp, const ipc::LinkshellRankChange& message); + void handleMessage_LinkshellRemove(const IPP& ipp, const ipc::LinkshellRemove& message); + void handleMessage_LinkshellSetMessage(const IPP& ipp, const ipc::LinkshellSetMessage& message); + void handleMessage_LuaFunction(const IPP& ipp, const ipc::LuaFunction& message); + void handleMessage_KillSession(const IPP& ipp, const ipc::KillSession& message); + void handleMessage_ConquestEvent(const IPP& ipp, const ipc::ConquestEvent& message); + void handleMessage_BesiegedEvent(const IPP& ipp, const ipc::BesiegedEvent& message); + void handleMessage_CampaignEvent(const IPP& ipp, const ipc::CampaignEvent& message); + void handleMessage_ColonizationEvent(const IPP& ipp, const ipc::ColonizationEvent& message); + void handleMessage_EntityInformationRequest(const IPP& ipp, const ipc::EntityInformationRequest& message); + void handleMessage_EntityInformationResponse(const IPP& ipp, const ipc::EntityInformationResponse& message); + void handleMessage_SendPlayerToLocation(const IPP& ipp, const ipc::SendPlayerToLocation& message); + + void handleUnknownMessage(const IPP& ipp, const std::span message); private: ZMQDealerWrapper zmqDealerWrapper_; @@ -97,7 +97,7 @@ void IPCClient::sendMessage(const T& message) TracyZoneScoped; // TODO: IPP for World Server - DebugIPCFmt("Sending message: {}", ipc::toString(ipc::getEnumType())); + DebugIPCFmt("Sending message: {}", ipc::toStringV); const auto bytes = ipc::toBytesWithHeader(message); zmqDealerWrapper_.outgoingQueue_.enqueue(zmq::message_t(bytes)); diff --git a/src/world/ipc_server.cpp b/src/world/ipc_server.cpp index 1b045fa3a96..d2fb6e79cc5 100644 --- a/src/world/ipc_server.cpp +++ b/src/world/ipc_server.cpp @@ -358,7 +358,7 @@ void IPCServer::handleIncomingMessages() DebugIPCFmt("Incoming {} message from {}", msgType, message.ipp.toString()); - ipc::IIPCMessageHandler::handleMessage(message.ipp, { message.payload.data(), message.payload.size() }); + handleMessage(message.ipp, { message.payload.data(), message.payload.size() }); } } diff --git a/src/world/ipc_server.h b/src/world/ipc_server.h index c4ba6eb2622..c9b9f5a9a57 100644 --- a/src/world/ipc_server.h +++ b/src/world/ipc_server.h @@ -35,11 +35,10 @@ #include #include -class IPCServer final : public ipc::IIPCMessageHandler +class IPCServer final : public ipc::IPCMessageHandlerBase { public: IPCServer(WorldServer& worldServer); - ~IPCServer() override = default; void handleIncomingMessages(); @@ -78,44 +77,44 @@ class IPCServer final : public ipc::IIPCMessageHandler void rerouteMessageToAllZones(const auto& message); // - // ipc::IIPCMessageHandler + // ipc::IPCMessageHandlerBase // - void handleMessage_EmptyStruct(const IPP& ipp, const ipc::EmptyStruct& message) override; - void handleMessage_CharLogin(const IPP& ipp, const ipc::CharLogin& message) override; - void handleMessage_CharZone(const IPP& ipp, const ipc::CharZone& message) override; - void handleMessage_CharVarUpdate(const IPP& ipp, const ipc::CharVarUpdate& message) override; - void handleMessage_ChatMessageTell(const IPP& ipp, const ipc::ChatMessageTell& message) override; - void handleMessage_ChatMessageParty(const IPP& ipp, const ipc::ChatMessageParty& message) override; - void handleMessage_ChatMessageAlliance(const IPP& ipp, const ipc::ChatMessageAlliance& message) override; - void handleMessage_ChatMessageLinkshell(const IPP& ipp, const ipc::ChatMessageLinkshell& message) override; - void handleMessage_ChatMessageUnity(const IPP& ipp, const ipc::ChatMessageUnity& message) override; - void handleMessage_ChatMessageYell(const IPP& ipp, const ipc::ChatMessageYell& message) override; - void handleMessage_ChatMessageServerMessage(const IPP& ipp, const ipc::ChatMessageServerMessage& message) override; - void handleMessage_ChatMessageCustom(const IPP& ipp, const ipc::ChatMessageCustom& message) override; - void handleMessage_PartyInvite(const IPP& ipp, const ipc::PartyInvite& message) override; - void handleMessage_PartyInviteResponse(const IPP& ipp, const ipc::PartyInviteResponse& message) override; - void handleMessage_PartyReload(const IPP& ipp, const ipc::PartyReload& message) override; - void handleMessage_PartyDisband(const IPP& ipp, const ipc::PartyDisband& message) override; - void handleMessage_AllianceReload(const IPP& ipp, const ipc::AllianceReload& message) override; - void handleMessage_AllianceDissolve(const IPP& ipp, const ipc::AllianceDissolve& message) override; - void handleMessage_PlayerKick(const IPP& ipp, const ipc::PlayerKick& message) override; - void handleMessage_MessageStandard(const IPP& ipp, const ipc::MessageStandard& message) override; - void handleMessage_MessageSystem(const IPP& ipp, const ipc::MessageSystem& message) override; - void handleMessage_LinkshellRankChange(const IPP& ipp, const ipc::LinkshellRankChange& message) override; - void handleMessage_LinkshellRemove(const IPP& ipp, const ipc::LinkshellRemove& message) override; - void handleMessage_LinkshellSetMessage(const IPP& ipp, const ipc::LinkshellSetMessage& message) override; - void handleMessage_LuaFunction(const IPP& ipp, const ipc::LuaFunction& message) override; - void handleMessage_KillSession(const IPP& ipp, const ipc::KillSession& message) override; - void handleMessage_ConquestEvent(const IPP& ipp, const ipc::ConquestEvent& message) override; - void handleMessage_BesiegedEvent(const IPP& ipp, const ipc::BesiegedEvent& message) override; - void handleMessage_CampaignEvent(const IPP& ipp, const ipc::CampaignEvent& message) override; - void handleMessage_ColonizationEvent(const IPP& ipp, const ipc::ColonizationEvent& message) override; - void handleMessage_EntityInformationRequest(const IPP& ipp, const ipc::EntityInformationRequest& message) override; - void handleMessage_EntityInformationResponse(const IPP& ipp, const ipc::EntityInformationResponse& message) override; - void handleMessage_SendPlayerToLocation(const IPP& ipp, const ipc::SendPlayerToLocation& message) override; - - void handleUnknownMessage(const IPP& ipp, const std::span message) override; + void handleMessage_EmptyStruct(const IPP& ipp, const ipc::EmptyStruct& message); + void handleMessage_CharLogin(const IPP& ipp, const ipc::CharLogin& message); + void handleMessage_CharZone(const IPP& ipp, const ipc::CharZone& message); + void handleMessage_CharVarUpdate(const IPP& ipp, const ipc::CharVarUpdate& message); + void handleMessage_ChatMessageTell(const IPP& ipp, const ipc::ChatMessageTell& message); + void handleMessage_ChatMessageParty(const IPP& ipp, const ipc::ChatMessageParty& message); + void handleMessage_ChatMessageAlliance(const IPP& ipp, const ipc::ChatMessageAlliance& message); + void handleMessage_ChatMessageLinkshell(const IPP& ipp, const ipc::ChatMessageLinkshell& message); + void handleMessage_ChatMessageUnity(const IPP& ipp, const ipc::ChatMessageUnity& message); + void handleMessage_ChatMessageYell(const IPP& ipp, const ipc::ChatMessageYell& message); + void handleMessage_ChatMessageServerMessage(const IPP& ipp, const ipc::ChatMessageServerMessage& message); + void handleMessage_ChatMessageCustom(const IPP& ipp, const ipc::ChatMessageCustom& message); + void handleMessage_PartyInvite(const IPP& ipp, const ipc::PartyInvite& message); + void handleMessage_PartyInviteResponse(const IPP& ipp, const ipc::PartyInviteResponse& message); + void handleMessage_PartyReload(const IPP& ipp, const ipc::PartyReload& message); + void handleMessage_PartyDisband(const IPP& ipp, const ipc::PartyDisband& message); + void handleMessage_AllianceReload(const IPP& ipp, const ipc::AllianceReload& message); + void handleMessage_AllianceDissolve(const IPP& ipp, const ipc::AllianceDissolve& message); + void handleMessage_PlayerKick(const IPP& ipp, const ipc::PlayerKick& message); + void handleMessage_MessageStandard(const IPP& ipp, const ipc::MessageStandard& message); + void handleMessage_MessageSystem(const IPP& ipp, const ipc::MessageSystem& message); + void handleMessage_LinkshellRankChange(const IPP& ipp, const ipc::LinkshellRankChange& message); + void handleMessage_LinkshellRemove(const IPP& ipp, const ipc::LinkshellRemove& message); + void handleMessage_LinkshellSetMessage(const IPP& ipp, const ipc::LinkshellSetMessage& message); + void handleMessage_LuaFunction(const IPP& ipp, const ipc::LuaFunction& message); + void handleMessage_KillSession(const IPP& ipp, const ipc::KillSession& message); + void handleMessage_ConquestEvent(const IPP& ipp, const ipc::ConquestEvent& message); + void handleMessage_BesiegedEvent(const IPP& ipp, const ipc::BesiegedEvent& message); + void handleMessage_CampaignEvent(const IPP& ipp, const ipc::CampaignEvent& message); + void handleMessage_ColonizationEvent(const IPP& ipp, const ipc::ColonizationEvent& message); + void handleMessage_EntityInformationRequest(const IPP& ipp, const ipc::EntityInformationRequest& message); + void handleMessage_EntityInformationResponse(const IPP& ipp, const ipc::EntityInformationResponse& message); + void handleMessage_SendPlayerToLocation(const IPP& ipp, const ipc::SendPlayerToLocation& message); + + void handleUnknownMessage(const IPP& ipp, const std::span message); private: WorldServer& worldServer_; @@ -134,7 +133,7 @@ void IPCServer::sendMessage(const IPP& ipp, const T& message) { TracyZoneScoped; - DebugIPCFmt("Sending {} message to {}", ipc::toString(ipc::getEnumType()), ipp.toString()); + DebugIPCFmt("Sending {} message to {}", ipc::toStringV, ipp.toString()); const auto bytes = ipc::toBytesWithHeader(message); const auto out = IPPMessage{ ipp, std::vector{ bytes.begin(), bytes.end() } }; @@ -147,7 +146,7 @@ void IPCServer::broadcastMessage(const T& message) { TracyZoneScoped; - DebugIPCFmt("Broadcasting {} message to all zone endpoints", ipc::toString(ipc::getEnumType())); + DebugIPCFmt("Broadcasting {} message to all zone endpoints", ipc::toStringV); for (const auto& ipp : zoneSettings_.mapEndpoints_) { diff --git a/tools/generate_ipc_stubs.py b/tools/generate_ipc_stubs.py index a7357cce16d..4c34c6ee749 100644 --- a/tools/generate_ipc_stubs.py +++ b/tools/generate_ipc_stubs.py @@ -1,8 +1,6 @@ -# On a build this script is automatically run, generating build/generated/ipc_stubs.h, which contains: -# - MessageType enum -# - getEnumType(MessageType) helper -# - toString(MessageType) helper -# - IIPCMessageHandler interface +# +# During CMake configuration/build this script is automatically run, generating build/generated/ipc_stubs.h +# # fmt: off @@ -64,8 +62,9 @@ def generate_ipc_stubs(output_dir, struct_names): - output_path = os.path.join(output_dir, "generated") - print(f"Generating ipc stubs...\nOutput path: {output_path}") + output_path = os.path.normpath(os.path.join(output_dir, "generated")) + print(f"Generating ipc stubs...") + print(f"Output directory: {output_path}") os.makedirs(output_path, exist_ok=True) @@ -74,8 +73,11 @@ def generate_ipc_stubs(output_dir, struct_names): f.write(f"// This file is auto-generated by tools/generate_ipc_stubs.py\n") f.write(f"// Do not modify this file directly.\n\n") f.write(f"#pragma once\n\n") + f.write(f"#include \n") f.write(f"#include \n") - f.write(f"#include \n\n") + f.write(f"#include \n") + f.write(f"#include \n") + f.write(f"#include \n") f.write(f"#include \n\n") f.write(f"#include \"common/ipc_structs.h\"\n") f.write(f"#include \"common/ipp.h\"\n\n") @@ -84,14 +86,23 @@ def generate_ipc_stubs(output_dir, struct_names): generate_message_type_enum(f, struct_names) generate_struct_completion_traits(f) - generate_get_enum_type_function(f, struct_names) + generate_enum_types(f, struct_names) + generate_enum_to_string_templates(f, struct_names) generate_enum_to_string_function(f, struct_names) - generate_message_handler_interface(f, struct_names) + generate_message_handler_crtp_base(f, struct_names) f.write(f"}} // namespace ipc\n") +def output_header(file, str): + file.write(f"//\n") + file.write(f"// {str}\n") + file.write(f"//\n\n") + + def generate_message_type_enum(file, struct_names): + output_header(file, "Message Type Enum") + max_name_length = max(len(name) for name in struct_names) file.write(f"enum class MessageType : uint8_t\n{{\n") @@ -105,58 +116,76 @@ def generate_message_type_enum(file, struct_names): def generate_struct_completion_traits(file): - file.write("template \n") - file.write("struct is_struct_complete : std::false_type {};\n\n") + output_header(file, "Struct Completion Traits") + + file.write(f"template \n") + file.write(f"struct is_struct_complete : std::false_type {{}};\n\n") file.write(f"template \n") file.write(f"struct is_struct_complete> : std::true_type {{}};\n\n") -def generate_get_enum_type_function(file, struct_names): +def generate_enum_types(file, struct_names): + output_header(file, "Enum Type Templates") + file.write(f"template \n") - file.write(f"constexpr auto getEnumType() -> MessageType\n") - file.write(f"{{\n") - file.write(f" static_assert(is_struct_complete::value, \"You must fully define this struct in common/ipc_structs.h.\");\n\n") - file.write(f" using UnderlyingT = std::decay_t;\n\n") + file.write(f"struct EnumType;\n\n") - counter = 0 + file.write(f"// Specializations for each IPC struct:\n") for name in struct_names: - if counter == 0: - file.write(f" if constexpr (std::is_same_v)\n") - else: - file.write(f" else if constexpr (std::is_same_v)\n") + file.write(f"template <>\n") + file.write(f"struct EnumType<{name}>\n") + file.write(f"{{\n") + file.write(f" static constexpr MessageType value = MessageType::{name};\n") + file.write(f"}};\n\n") - file.write(f" {{\n") - file.write(f" return MessageType::{name};\n") - file.write(f" }}\n") + file.write(f"template \n") + file.write(f"constexpr MessageType EnumTypeV = EnumType>::value;\n\n") - counter += 1 - file.write(f"}}\n\n") +def generate_enum_to_string_templates(file, struct_names): + output_header(file, "Enum to String Templates") + + file.write(f"template \n") + file.write(f"struct EnumToString;\n\n") + + for name in struct_names: + file.write(f"template <>\n") + file.write(f"struct EnumToString<{name}>\n") + file.write(f"{{\n") + file.write(f" static constexpr const char* value = \"{name}\";\n") + file.write(f"}};\n\n") + + file.write(f"template \n") + file.write(f"constexpr const char* toStringV = EnumToString>::value;\n\n") def generate_enum_to_string_function(file, struct_names): - file.write(f"constexpr auto toString(MessageType type) -> std::string\n") - file.write(f"{{\n") - file.write(f" switch (type)\n") - file.write(f" {{\n") + output_header(file, "Enum to String Function") + file.write(f"constexpr std::array messageTypeStrings =\n") + file.write(f"{{\n") for name in struct_names: - file.write(f" case MessageType::{name}:\n") - file.write(f" return \"{name}\";\n") + file.write(f" \"{name}\",\n") + file.write(f"}};\n\n") - file.write(f" default:\n") - file.write(f" return \"Unknown\";\n") + file.write(f"inline std::string_view toString(MessageType type)\n") + file.write(f"{{\n") + file.write(f" const auto index = static_cast(type);\n") + file.write(f" if (index >= 1 && index <= messageTypeStrings.size())\n") + file.write(f" {{\n") + file.write(f" return messageTypeStrings[index - 1];\n") file.write(f" }}\n") + file.write(f" return \"Unknown\";\n") file.write(f"}}\n\n") +def generate_message_handler_crtp_base(file, struct_names): + output_header(file, "Message Handler CRTP Base") -def generate_message_handler_interface(file, struct_names): - file.write(f"class IIPCMessageHandler\n") + file.write(f"template \n") + file.write(f"class IPCMessageHandlerBase\n") file.write(f"{{\n") file.write(f"public:\n") - file.write(f" virtual ~IIPCMessageHandler() = default;\n\n") - file.write(f" void handleMessage(const IPP& ipp, const std::span message)\n") file.write(f" {{\n") file.write(f" const auto messageType = static_cast(message[0]);\n") @@ -172,22 +201,21 @@ def generate_message_handler_interface(file, struct_names): file.write(f" ShowError(\"Failed to deserialize {name} message.\");\n") file.write(f" break;\n") file.write(f" }}\n") - file.write(f" handleMessage_{name}(ipp, *object);\n") + file.write(f" static_cast(this)->handleMessage_{name}(ipp, *object);\n") file.write(f" }}\n") file.write(f" break;\n") file.write(f" default:\n") - file.write(f" handleUnknownMessage(ipp, message);\n") - file.write(f" break;\n") + file.write(f" {{\n") + file.write(f" static_cast(this)->handleUnknownMessage(ipp, message);\n") + file.write(f" }}\n") + file.write(f" break;\n") file.write(f" }}\n") file.write(f" }}\n\n") - file.write(f"protected:\n") for name in struct_names: - file.write(f" virtual void handleMessage_{name}(const IPP& ipp, const ipc::{name}& message) = 0;\n") - - file.write(f"\n virtual void handleUnknownMessage(const IPP& ipp, const std::span message) = 0;\n") - + file.write(f" // Derived must implement: void handleMessage_{name}(const IPP& ipp, const ipc::{name}& message);\n") + file.write(f" // Derived must implement: void handleUnknownMessage(const IPP& ipp, const std::span message);\n") file.write(f"}};\n\n") From 96fdff36b50fe2be55ef353a20bd2d0fb60b2608 Mon Sep 17 00:00:00 2001 From: sleepingkirby Date: Mon, 3 Mar 2025 12:38:27 +0000 Subject: [PATCH 2/2] Remove redundant std::move() in ipc.h --- src/common/ipc.h | 16 ++++++++-------- src/map/ipc_client.cpp | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/common/ipc.h b/src/common/ipc.h index ea8306ff99d..72b07585df5 100644 --- a/src/common/ipc.h +++ b/src/common/ipc.h @@ -71,8 +71,8 @@ namespace ipc template auto toBytesWithHeader(const T& object) -> std::vector { - auto bytes = std::vector(); - auto bytes_written = alpaca::serialize(object, bytes); + auto bytes = std::vector(); + const auto bytes_written = alpaca::serialize(object, bytes); const auto type = static_cast(EnumTypeV); @@ -91,14 +91,14 @@ namespace ipc return std::nullopt; } - auto ec = std::error_code{}; - auto object = alpaca::deserialize(message, ec); + auto ec = std::error_code{}; + const auto object = alpaca::deserialize(message, ec); if (ec) { return std::nullopt; } - return std::move(object); + return object; } template @@ -117,13 +117,13 @@ namespace ipc const auto bytes = std::span(message.data() + 1, message.size() - 1); - auto ec = std::error_code{}; - auto object = alpaca::deserialize(bytes, ec); + auto ec = std::error_code{}; + const auto object = alpaca::deserialize(bytes, ec); if (ec) { return std::nullopt; } - return std::move(object); + return object; } } // namespace ipc diff --git a/src/map/ipc_client.cpp b/src/map/ipc_client.cpp index 30cdda3c0a6..57bcda516cc 100644 --- a/src/map/ipc_client.cpp +++ b/src/map/ipc_client.cpp @@ -678,7 +678,7 @@ void IPCClient::handleMessage_KillSession(const IPP& ipp, const ipc::KillSession map_session_data_t* sessionToDelete = nullptr; - for (const auto [_, session] : map_session_list) + for (const auto& [_, session] : map_session_list) { if (session->charID == message.victimId) {