From abcbe86dc597a7c3e3ea18dcb3339b8e8400257b Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Wed, 17 Jun 2026 14:49:38 +0100 Subject: Add a WriteNumeric overload that takes a vector of numerics. --- src/users.cpp | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'src/users.cpp') diff --git a/src/users.cpp b/src/users.cpp index dbbbc8c13..b366ed951 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -773,9 +773,7 @@ void User::WriteNumeric(const Numeric::Numeric& numeric) return; ModResult modres; - FIRST_MOD_RESULT(OnNumeric, modres, (this, numeric)); - if (modres == MOD_RES_DENY) return; @@ -783,6 +781,31 @@ void User::WriteNumeric(const Numeric::Numeric& numeric) localuser->Send(ServerInstance->GetRFCEvents().numeric, numericmsg); } +void User::WriteNumeric(const std::vector& numerics) +{ + auto* const lthis = IS_LOCAL(this); + if (!lthis) + return; + + ClientProtocol::MessageList messages; + for (const auto& numeric : numerics) + { + ModResult modres; + FIRST_MOD_RESULT(OnNumeric, modres, (this, numeric)); + if (modres != MOD_RES_DENY) + messages.push_back(new ClientProtocol::Messages::Numeric(numeric, this)); + } + + if (!messages.empty()) + { + ClientProtocol::Event numericev(ServerInstance->GetRFCEvents().numeric); + numericev.SetMessageList(messages); + lthis->Send(numericev); + stdalgo::delete_all(messages); + } +} + + void User::WriteRemoteNotice(const std::string& text) { ServerInstance->PI->SendMessage(this, text, MessageType::NOTICE); @@ -877,6 +900,11 @@ void User::WriteRemoteNumeric(const Numeric::Numeric& numeric) WriteNumeric(numeric); } +void User::WriteRemoteNumeric(const std::vector& numerics) +{ + WriteNumeric(numerics); +} + /* return 0 or 1 depending if users u and u2 share one or more common channels * (used by QUIT, NICK etc which arent channel specific notices) * -- cgit v1.3.1-10-gc9f91 From ef88adc36d5c5214a15e653a6cfe827660bdfb0a Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Wed, 17 Jun 2026 15:03:07 +0100 Subject: Allow an event hook for after messages are sent to a client. --- include/clientprotocol.h | 15 +++++++++++++++ src/clientprotocol.cpp | 6 ++++++ src/users.cpp | 1 + 3 files changed, 22 insertions(+) (limited to 'src/users.cpp') diff --git a/include/clientprotocol.h b/include/clientprotocol.h index a68aa0541..61db79037 100644 --- a/include/clientprotocol.h +++ b/include/clientprotocol.h @@ -543,6 +543,12 @@ public: * @param messagelist List to fill in with messages to send to the user for the event */ void GetMessagesForUser(LocalUser* user, MessageList& messagelist); + + /** Called after a list of messages was sent to a user. + * @param user User that messages were sent to. + * @param messagelist List containing messages that were sent to the user for the event. + */ + void PostSendMessagesToUser(LocalUser* user, const MessageList& messagelist); }; class CoreExport ClientProtocol::MessageTagEvent @@ -648,6 +654,15 @@ public: * MOD_RES_ALLOW to send the messages in messagelist to the user and to not run other hooks. */ virtual ModResult OnPreEventSend(LocalUser* user, const ClientProtocol::Event& ev, ClientProtocol::MessageList& messagelist) = 0; + + /** Called for each user that received the event. + * @param user User the message list was sent to. + * @param ev Event associated with the messages. + * @param messagelist List of messages that were sent to the user. + */ + virtual void OnPostEventSend(LocalUser* user, const ClientProtocol::Event& ev, const ClientProtocol::MessageList& messagelist) + { + } }; /** Event provider for client protocol events. diff --git a/src/clientprotocol.cpp b/src/clientprotocol.cpp index 519c6b21b..de3516707 100644 --- a/src/clientprotocol.cpp +++ b/src/clientprotocol.cpp @@ -175,3 +175,9 @@ void ClientProtocol::Event::GetMessagesForUser(LocalUser* user, MessageList& mes if (res == MOD_RES_DENY) messagelist.clear(); } + +void ClientProtocol::Event::PostSendMessagesToUser(LocalUser* user, const MessageList& messagelist) +{ + if (this->event) + this->event->Call(&EventHook::OnPostEventSend, user, *this, messagelist); +} diff --git a/src/users.cpp b/src/users.cpp index b366ed951..a1df507c4 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -764,6 +764,7 @@ void LocalUser::Send(ClientProtocol::Event& protoev, ClientProtocol::MessageList if (res != MOD_RES_DENY) Write(serializer->SerializeForUser(this, curr)); } + protoev.PostSendMessagesToUser(this, msglist); } void User::WriteNumeric(const Numeric::Numeric& numeric) -- cgit v1.3.1-10-gc9f91