CClient::PutClient(): handle away-notify and account-notify

This commit is contained in:
J-P Nurmi
2015-09-12 18:18:36 +02:00
parent 0f2a37707f
commit 69f1138052
3 changed files with 38 additions and 24 deletions
+26 -9
View File
@@ -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() (<a href="http://ircv3.net/specs/extensions/account-notify-3.1.html">account-notify</a>)
* \c AWAY | \l CClient::HasAwayNotify() (<a href="http://ircv3.net/specs/extensions/away-notify-3.1.html">away-notify</a>)
*
* ### 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);
+8 -1
View File
@@ -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) {
+4 -14
View File
@@ -281,13 +281,8 @@ static void FixupChanNick(CNick& Nick, CChan* pChan) {
}
bool CIRCSock::OnAccountMessage(CMessage& Message) {
const vector<CClient*>& 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<CClient*>& 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) {