diff --git a/include/znc/Client.h b/include/znc/Client.h index 07f3cc9b..e7291c7c 100644 --- a/include/znc/Client.h +++ b/include/znc/Client.h @@ -187,15 +187,32 @@ public: */ void PutClient(const CString& sLine); /** Sends a message to the client. - * @param Message The message to be sent. - * @note Only known and compatible message tags are sent. + * @param Message The message to be sent. + * @note Only known and compatible messages and tags are sent. + * @return \c true if the message was sent, or \c false if it was ignored. * - * Not all IRC clients are capable of handling arbitrary sets of message - * tags. For example, some older versions of some popular clients were - * prepared to parse just one interesting tag, \c time, and would break - * if multiple tags were included. Thus, in order to stay compatible with - * a variety of IRC clients, ZNC has to filter out message tags that the - * client has not explicitly requested. + * This method ensures that only messages and tags, that the client has + * explicitly requested, are sent. Not all IRC clients are capable of + * handling all messages and tags. For example, some older versions of + * popular clients were prepared to parse just one interesting tag, + * \c time, and would break if multiple tags were included. Furthermore, + * messages that are specific to a certain capability, should not be sent + * to a client that has not requested the respective capability. Thus, in + * order to stay compatible with a variety of IRC clients, ZNC has to + * filter out messages and tags that the client has not explicitly + * requested. + * + * ### Message types + * + * The following table documents which capabilities the client is required + * to have requested in order to receive certain types of messages. + * + * Message type | Capability + * ------------ | ---------- + * \c ACCOUNT | \l CClient::HasAccountNotify() (account-notify) + * \c AWAY | \l CClient::HasAwayNotify() (away-notify) + * + * ### Message tags * * The following table documents currently supported message tags, and * which capabilities the client is required to have requested to receive @@ -215,7 +232,7 @@ public: * pClient->PutClient(Message.ToString()); * \endcode */ - void PutClient(const CMessage& Message); + bool PutClient(const CMessage& Message); unsigned int PutStatus(const CTable& table); void PutStatus(const CString& sLine); void PutStatusNotice(const CString& sLine); diff --git a/src/Client.cpp b/src/Client.cpp index 8fbaf707..00aa9376 100644 --- a/src/Client.cpp +++ b/src/Client.cpp @@ -749,8 +749,14 @@ void CClient::PutClient(const CString& sLine) { Write(sCopy + "\r\n"); } -void CClient::PutClient(const CMessage& Message) +bool CClient::PutClient(const CMessage& Message) { + if (!m_bAwayNotify && Message.GetType() == CMessage::Type::Away) { + return false; + } else if (!m_bAccountNotify && Message.GetType() == CMessage::Type::Account) { + return false; + } + CString sLine = Message.ToString(CMessage::ExcludeTags); // TODO: introduce a module hook that gives control over the tags that are sent @@ -777,6 +783,7 @@ void CClient::PutClient(const CMessage& Message) } PutClient(sLine); + return true; } void CClient::PutStatusNotice(const CString& sLine) { diff --git a/src/IRCSock.cpp b/src/IRCSock.cpp index dc9b83a5..78cd5d0e 100644 --- a/src/IRCSock.cpp +++ b/src/IRCSock.cpp @@ -281,13 +281,8 @@ static void FixupChanNick(CNick& Nick, CChan* pChan) { } bool CIRCSock::OnAccountMessage(CMessage& Message) { - const vector& vClients = m_pNetwork->GetClients(); - for (CClient* pClient : vClients) { - if (pClient->HasAccountNotify()) { - m_pNetwork->PutUser(Message, pClient); - } - } - return true; + // TODO: IRCSOCKMODULECALL(OnAccountMessage(Message)) ? + return false; } bool CIRCSock::OnActionMessage(CActionMessage& Message) { @@ -323,13 +318,8 @@ bool CIRCSock::OnActionMessage(CActionMessage& Message) { } bool CIRCSock::OnAwayMessage(CMessage& Message) { - const vector& vClients = m_pNetwork->GetClients(); - for (CClient* pClient : vClients) { - if (pClient->HasAwayNotify()) { - m_pNetwork->PutUser(Message, pClient); - } - } - return true; + // TODO: IRCSOCKMODULECALL(OnAwayMessage(Message)) ? + return false; } bool CIRCSock::OnCapabilityMessage(CMessage& Message) {