Add OnSendToIRCMessage and OnSendToClientMessage

This also alters PutClient such that the CMessage variant handles
sending messages, rather than the CString variant. As a side bonus, this
gives callers better information on whether the message was sent to the
client. Additionally, it eliminates the need for a hook to let modules
set the tags sent to a client, as that can now be done inside
OnSendToClientMessage.
This commit is contained in:
Eli Young
2017-04-11 13:03:38 -07:00
parent f37aa308e1
commit 823ac07240
13 changed files with 123 additions and 26 deletions
+18 -15
View File
@@ -483,13 +483,8 @@ CString CClient::GetFullName() const {
}
void CClient::PutClient(const CString& sLine) {
bool bReturn = false;
CString sCopy = sLine;
NETWORKMODULECALL(OnSendToClient(sCopy, *this), m_pUser, m_pNetwork, this,
&bReturn);
if (bReturn) return;
DEBUG("(" << GetFullName() << ") ZNC -> CLI [" << sCopy << "]");
Write(sCopy + "\r\n");
CMessage Message(sLine);
PutClient(Message);
}
bool CClient::PutClient(const CMessage& Message) {
@@ -563,10 +558,7 @@ bool CClient::PutClient(const CMessage& Message) {
}
}
CString sLine = Msg.ToString(CMessage::ExcludeTags);
// TODO: introduce a module hook that gives control over the tags that are
// sent
// TODO: add the ability to set a list of tags to send
MCString mssTags;
if (HasServerTime()) {
@@ -585,11 +577,22 @@ bool CClient::PutClient(const CMessage& Message) {
}
}
if (!mssTags.empty()) {
CUtils::SetMessageTags(sLine, mssTags);
}
Msg.SetTags(mssTags);
Msg.SetClient(this);
Msg.SetNetwork(m_pNetwork);
PutClient(sLine);
bool bReturn = false;
NETWORKMODULECALL(OnSendToClientMessage(Msg), m_pUser, m_pNetwork, this,
&bReturn);
if (bReturn) return false;
CString sCopy = Msg.ToString();
NETWORKMODULECALL(OnSendToClient(sCopy, *this), m_pUser, m_pNetwork, this,
&bReturn);
if (bReturn) return false;
DEBUG("(" << GetFullName() << ") ZNC -> CLI [" << sCopy << "]");
Write(sCopy + "\r\n");
return true;
}
+13 -6
View File
@@ -1154,13 +1154,20 @@ void CIRCSock::TrySend() {
m_iSendsAllowed--;
bool bSkip = false;
CString& sLine = m_vsSendQueue.front();
IRCSOCKMODULECALL(OnSendToIRC(sLine), &bSkip);
CMessage Message(sLine);
Message.SetNetwork(m_pNetwork);
IRCSOCKMODULECALL(OnSendToIRCMessage(Message), &bSkip);
if (!bSkip) {
;
DEBUG("(" << m_pNetwork->GetUser()->GetUserName() << "/"
<< m_pNetwork->GetName() << ") ZNC -> IRC [" << sLine
<< "]");
Write(sLine + "\r\n");
CString sCopy = Message.ToString();
IRCSOCKMODULECALL(OnSendToIRC(sCopy), &bSkip);
if (!bSkip) {
DEBUG("(" << m_pNetwork->GetUser()->GetUserName() << "/"
<< m_pNetwork->GetName() << ") ZNC -> IRC [" << sCopy
<< "]");
Write(sCopy + "\r\n");
}
}
m_vsSendQueue.pop_front();
}
+13
View File
@@ -983,7 +983,14 @@ CModule::EModRet CModule::OnDeleteNetwork(CIRCNetwork& Network) {
CModule::EModRet CModule::OnSendToClient(CString& sLine, CClient& Client) {
return CONTINUE;
}
CModule::EModRet CModule::OnSendToClientMessage(CMessage& Message) {
return CONTINUE;
}
CModule::EModRet CModule::OnSendToIRC(CString& sLine) { return CONTINUE; }
CModule::EModRet CModule::OnSendToIRCMessage(CMessage& Message) {
return CONTINUE;
}
bool CModule::OnServerCapAvailable(const CString& sCap) { return false; }
void CModule::OnServerCapResult(const CString& sCap, bool bSuccess) {}
@@ -1444,7 +1451,13 @@ bool CModules::OnDeleteNetwork(CIRCNetwork& Network) {
bool CModules::OnSendToClient(CString& sLine, CClient& Client) {
MODHALTCHK(OnSendToClient(sLine, Client));
}
bool CModules::OnSendToClientMessage(CMessage& Message) {
MODHALTCHK(OnSendToClientMessage(Message));
}
bool CModules::OnSendToIRC(CString& sLine) { MODHALTCHK(OnSendToIRC(sLine)); }
bool CModules::OnSendToIRCMessage(CMessage& Message) {
MODHALTCHK(OnSendToIRCMessage(Message));
}
bool CModules::OnStatusCommand(CString& sCommand) {
MODHALTCHK(OnStatusCommand(sCommand));
}