diff --git a/include/znc/Modules.h b/include/znc/Modules.h index fe5a2c75..a27a1326 100644 --- a/include/znc/Modules.h +++ b/include/znc/Modules.h @@ -658,6 +658,7 @@ public: */ virtual EModRet OnChanBufferPlayLine2(CChan& Chan, CClient& Client, CString& sLine, const timeval& tv); virtual EModRet OnChanBufferPlayLine(CChan& Chan, CClient& Client, CString& sLine); + virtual EModRet OnChanBufferPlayMessage(CMessage& Message); /** Called when a line from the query buffer is played back. * @param Client The client this line will go to. * @param sLine The raw IRC traffic line from the buffer. @@ -666,6 +667,7 @@ public: */ virtual EModRet OnPrivBufferPlayLine2(CClient& Client, CString& sLine, const timeval& tv); virtual EModRet OnPrivBufferPlayLine(CClient& Client, CString& sLine); + virtual EModRet OnPrivBufferPlayMessage(CMessage& Message); /** Called when a client successfully logged in to ZNC. */ virtual void OnClientLogin(); @@ -1219,6 +1221,8 @@ public: bool OnChanBufferPlayLine(CChan& Chan, CClient& Client, CString& sLine); bool OnPrivBufferPlayLine2(CClient& Client, CString& sLine, const timeval& tv); bool OnPrivBufferPlayLine(CClient& Client, CString& sLine); + bool OnChanBufferPlayMessage(CMessage& Message); + bool OnPrivBufferPlayMessage(CMessage& Message); bool OnClientLogin(); bool OnClientDisconnect(); diff --git a/src/Chan.cpp b/src/Chan.cpp index 38cb1336..9c024e33 100644 --- a/src/Chan.cpp +++ b/src/Chan.cpp @@ -20,6 +20,7 @@ #include #include #include +#include using std::set; using std::vector; @@ -610,16 +611,19 @@ void CChan::SendBuffer(CClient* pClient, const CBuffer& Buffer) { size_t uSize = Buffer.Size(); for (size_t uIdx = 0; uIdx < uSize; uIdx++) { const CBufLine& BufLine = Buffer.GetBufLine(uIdx); - CString sLine = BufLine.GetLine(*pUseClient, MCString::EmptyMap); + CMessage Message(BufLine.GetLine(*pUseClient, MCString::EmptyMap)); + Message.SetChan(this); + Message.SetNetwork(m_pNetwork); + Message.SetClient(pClient); + Message.SetTime(BufLine.GetTime()); + Message.SetTags(BufLine.GetTags()); if (bBatch) { - MCString msBatchTags = CUtils::GetMessageTags(sLine); - msBatchTags["batch"] = sBatchName; - CUtils::SetMessageTags(sLine, msBatchTags); + Message.SetTag("batch", sBatchName); } bool bNotShowThisLine = false; - NETWORKMODULECALL(OnChanBufferPlayLine2(*this, *pUseClient, sLine, BufLine.GetTime()), m_pNetwork->GetUser(), m_pNetwork, nullptr, &bNotShowThisLine); + NETWORKMODULECALL(OnChanBufferPlayMessage(Message), m_pNetwork->GetUser(), m_pNetwork, nullptr, &bNotShowThisLine); if (bNotShowThisLine) continue; - m_pNetwork->PutUser(sLine, pUseClient); + m_pNetwork->PutUser(Message, pUseClient); } bSkipStatusMsg = pUseClient->HasServerTime(); diff --git a/src/IRCNetwork.cpp b/src/IRCNetwork.cpp index 452b7fd5..3cb96d63 100644 --- a/src/IRCNetwork.cpp +++ b/src/IRCNetwork.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -642,11 +643,15 @@ void CIRCNetwork::ClientConnected(CClient *pClient) { uSize = m_NoticeBuffer.Size(); for (uIdx = 0; uIdx < uSize; uIdx++) { const CBufLine& BufLine = m_NoticeBuffer.GetBufLine(uIdx); - CString sLine = BufLine.GetLine(*pClient, msParams); + CMessage Message(BufLine.GetLine(*pClient, msParams)); + Message.SetNetwork(this); + Message.SetClient(pClient); + Message.SetTime(BufLine.GetTime()); + Message.SetTags(BufLine.GetTags()); bool bContinue = false; - NETWORKMODULECALL(OnPrivBufferPlayLine2(*pClient, sLine, BufLine.GetTime()), m_pUser, this, nullptr, &bContinue); + NETWORKMODULECALL(OnPrivBufferPlayMessage(Message), m_pUser, this, nullptr, &bContinue); if (bContinue) continue; - pClient->PutClient(sLine); + pClient->PutClient(Message); } m_NoticeBuffer.Clear(); diff --git a/src/Modules.cpp b/src/Modules.cpp index 3b7f1578..21fa5485 100644 --- a/src/Modules.cpp +++ b/src/Modules.cpp @@ -660,6 +660,25 @@ CModule::EModRet CModule::OnPrivBufferPlayLine2(CClient& Client, CString& sLine, return OnPrivBufferPlayLine(Client, sLine); } +CModule::EModRet CModule::OnChanBufferPlayMessage(CMessage& Message) { + CString sOriginal, sModified; + sOriginal = sModified = Message.ToString(CMessage::ExcludeTags); + EModRet ret = OnChanBufferPlayLine2(*Message.GetChan(), *Message.GetClient(), sModified, Message.GetTime()); + if (ret == CONTINUE && sOriginal != sModified) { + Message.Parse(sModified); + } + return ret; +} +CModule::EModRet CModule::OnPrivBufferPlayMessage(CMessage& Message) { + CString sOriginal, sModified; + sOriginal = sModified = Message.ToString(CMessage::ExcludeTags); + EModRet ret = OnPrivBufferPlayLine2(*Message.GetClient(), sModified, Message.GetTime()); + if (ret == CONTINUE && sOriginal != sModified) { + Message.Parse(sModified); + } + return ret; +} + void CModule::OnClientLogin() {} void CModule::OnClientDisconnect() {} CModule::EModRet CModule::OnUserRaw(CString& sLine) { return CONTINUE; } @@ -905,6 +924,8 @@ bool CModules::OnChanBufferPlayLine2(CChan& Chan, CClient& Client, CString& sLin bool CModules::OnChanBufferPlayLine(CChan& Chan, CClient& Client, CString& sLine) { MODHALTCHK(OnChanBufferPlayLine(Chan, Client, sLine)); } bool CModules::OnPrivBufferPlayLine2(CClient& Client, CString& sLine, const timeval& tv) { MODHALTCHK(OnPrivBufferPlayLine2(Client, sLine, tv)); } bool CModules::OnPrivBufferPlayLine(CClient& Client, CString& sLine) { MODHALTCHK(OnPrivBufferPlayLine(Client, sLine)); } +bool CModules::OnChanBufferPlayMessage(CMessage& Message) { MODHALTCHK(OnChanBufferPlayMessage(Message)); } +bool CModules::OnPrivBufferPlayMessage(CMessage& Message) { MODHALTCHK(OnPrivBufferPlayMessage(Message)); } bool CModules::OnCTCPReply(CNick& Nick, CString& sMessage) { MODHALTCHK(OnCTCPReply(Nick, sMessage)); } bool CModules::OnPrivCTCP(CNick& Nick, CString& sMessage) { MODHALTCHK(OnPrivCTCP(Nick, sMessage)); } bool CModules::OnPrivCTCPMessage(CPrivCTCP& Message) { MODHALTCHK(OnPrivCTCPMessage(Message)); } diff --git a/src/Query.cpp b/src/Query.cpp index 8cb536a3..2177d2f2 100644 --- a/src/Query.cpp +++ b/src/Query.cpp @@ -17,6 +17,7 @@ #include #include #include +#include using std::vector; @@ -55,24 +56,23 @@ void CQuery::SendBuffer(CClient* pClient, const CBuffer& Buffer) { size_t uSize = Buffer.Size(); for (size_t uIdx = 0; uIdx < uSize; uIdx++) { const CBufLine& BufLine = Buffer.GetBufLine(uIdx); - + CMessage Message(BufLine.GetLine(*pUseClient, MCString::EmptyMap)); if (!pUseClient->HasEchoMessage() && !pUseClient->HasSelfMessage()) { - CNick Sender(BufLine.GetFormat().Token(0)); - if (Sender.NickEquals(pUseClient->GetNick())) { + if (Message.GetNick().NickEquals(pUseClient->GetNick())) { continue; } } - - CString sLine = BufLine.GetLine(*pUseClient, msParams); + Message.SetNetwork(m_pNetwork); + Message.SetClient(pUseClient); + Message.SetTime(BufLine.GetTime()); + Message.SetTags(BufLine.GetTags()); if (bBatch) { - MCString msBatchTags = CUtils::GetMessageTags(sLine); - msBatchTags["batch"] = sBatchName; - CUtils::SetMessageTags(sLine, msBatchTags); + Message.SetTag("batch", sBatchName); } bool bContinue = false; - NETWORKMODULECALL(OnPrivBufferPlayLine2(*pUseClient, sLine, BufLine.GetTime()), m_pNetwork->GetUser(), m_pNetwork, nullptr, &bContinue); + NETWORKMODULECALL(OnPrivBufferPlayMessage(Message), m_pNetwork->GetUser(), m_pNetwork, nullptr, &bContinue); if (bContinue) continue; - m_pNetwork->PutUser(sLine, pUseClient); + m_pNetwork->PutUser(Message, pUseClient); } if (bBatch) {