Exemplo n.º 1
0
void CQuery::SendBuffer(CClient* pClient, const CBuffer& Buffer) {
	if (m_pNetwork && m_pNetwork->IsUserAttached()) {
		// Based on CChan::SendBuffer()
		if (!Buffer.IsEmpty()) {
			const vector<CClient*> & vClients = m_pNetwork->GetClients();
			for (CClient* pEachClient : vClients) {
				CClient * pUseClient = (pClient ? pClient : pEachClient);

				MCString msParams;
				msParams["target"] = pUseClient->GetNick();

				bool bWasPlaybackActive = pUseClient->IsPlaybackActive();
				pUseClient->SetPlaybackActive(true);

				bool bBatch = pUseClient->HasBatch();
				CString sBatchName = m_sName.MD5();

				if (bBatch) {
					m_pNetwork->PutUser(":znc.in BATCH +" + sBatchName + " znc.in/playback " + m_sName, pUseClient);
				}

				size_t uSize = Buffer.Size();
				for (size_t uIdx = 0; uIdx < uSize; uIdx++) {
					const CBufLine& BufLine = Buffer.GetBufLine(uIdx);

					if (!pUseClient->HasEchoMessage() && !pUseClient->HasSelfMessage()) {
						CNick Sender(BufLine.GetFormat().Token(0));
						if (Sender.NickEquals(pUseClient->GetNick())) {
							continue;
						}
					}

					CString sLine = BufLine.GetLine(*pUseClient, msParams);
					if (bBatch) {
						MCString msBatchTags = CUtils::GetMessageTags(sLine);
						msBatchTags["batch"] = sBatchName;
						CUtils::SetMessageTags(sLine, msBatchTags);
					}
					bool bContinue = false;
					NETWORKMODULECALL(OnPrivBufferPlayLine2(*pUseClient, sLine, BufLine.GetTime()), m_pNetwork->GetUser(), m_pNetwork, nullptr, &bContinue);
					if (bContinue) continue;
					m_pNetwork->PutUser(sLine, pUseClient);
				}

				if (bBatch) {
					m_pNetwork->PutUser(":znc.in BATCH -" + sBatchName, pUseClient);
				}

				pUseClient->SetPlaybackActive(bWasPlaybackActive);

				if (pClient)
					break;
			}
		}
	}
}
Exemplo n.º 2
0
Arquivo: Query.cpp Projeto: aszrul/znc
void CQuery::SendBuffer(CClient* pClient, const CBuffer& Buffer) {
    if (m_pNetwork && m_pNetwork->IsUserAttached()) {
        // Based on CChan::SendBuffer()
        if (!Buffer.IsEmpty()) {
            const vector<CClient*>& vClients = m_pNetwork->GetClients();
            for (CClient* pEachClient : vClients) {
                CClient* pUseClient = (pClient ? pClient : pEachClient);

                MCString msParams;
                msParams["target"] = pUseClient->GetNick();

                bool bWasPlaybackActive = pUseClient->IsPlaybackActive();
                pUseClient->SetPlaybackActive(true);

                NETWORKMODULECALL(OnPrivBufferStarting(*this, *pUseClient),
                                  m_pNetwork->GetUser(), m_pNetwork, nullptr,
                                  NOTHING);

                bool bBatch = pUseClient->HasBatch();
                CString sBatchName = m_sName.MD5();

                if (bBatch) {
                    m_pNetwork->PutUser(":znc.in BATCH +" + sBatchName +
                                            " znc.in/playback " + m_sName,
                                        pUseClient);
                }

                size_t uSize = Buffer.Size();
                for (size_t uIdx = 0; uIdx < uSize; uIdx++) {
                    const CBufLine& BufLine = Buffer.GetBufLine(uIdx);
                    CMessage Message = BufLine.ToMessage(*pUseClient, msParams);
                    if (!pUseClient->HasEchoMessage() &&
                        !pUseClient->HasSelfMessage()) {
                        if (Message.GetNick().NickEquals(
                                pUseClient->GetNick())) {
                            continue;
                        }
                    }
                    Message.SetNetwork(m_pNetwork);
                    Message.SetClient(pUseClient);
                    if (bBatch) {
                        Message.SetTag("batch", sBatchName);
                    }
                    bool bContinue = false;
                    NETWORKMODULECALL(OnPrivBufferPlayMessage(Message),
                                      m_pNetwork->GetUser(), m_pNetwork,
                                      nullptr, &bContinue);
                    if (bContinue) continue;
                    m_pNetwork->PutUser(Message, pUseClient);
                }

                if (bBatch) {
                    m_pNetwork->PutUser(":znc.in BATCH -" + sBatchName,
                                        pUseClient);
                }

                NETWORKMODULECALL(OnPrivBufferEnding(*this, *pUseClient),
                                  m_pNetwork->GetUser(), m_pNetwork, nullptr,
                                  NOTHING);

                pUseClient->SetPlaybackActive(bWasPlaybackActive);

                if (pClient) break;
            }
        }
    }
}
Exemplo n.º 3
0
void CChan::SendBuffer(CClient* pClient, const CBuffer& Buffer) {
    if (m_pNetwork && m_pNetwork->IsUserAttached()) {
        // in the event that pClient is nullptr, need to send this to all
        // clients for the user I'm presuming here that pClient is listed
        // inside vClients thus vClients at this point can't be empty.
        //
        // This loop has to be cycled twice to maintain the existing behavior
        // which is
        // 1. OnChanBufferStarting
        // 2. OnChanBufferPlayLine
        // 3. ClearBuffer() if not keeping the buffer
        // 4. OnChanBufferEnding
        //
        // With the exception of ClearBuffer(), this needs to happen per
        // client, and if pClient is not nullptr, the loops break after the
        // first iteration.
        //
        // Rework this if you like ...
        if (!Buffer.IsEmpty()) {
            const vector<CClient*>& vClients = m_pNetwork->GetClients();
            for (CClient* pEachClient : vClients) {
                CClient* pUseClient = (pClient ? pClient : pEachClient);

                bool bWasPlaybackActive = pUseClient->IsPlaybackActive();
                pUseClient->SetPlaybackActive(true);

                bool bSkipStatusMsg = pUseClient->HasServerTime();
                NETWORKMODULECALL(OnChanBufferStarting(*this, *pUseClient),
                                  m_pNetwork->GetUser(), m_pNetwork, nullptr,
                                  &bSkipStatusMsg);

                if (!bSkipStatusMsg) {
                    m_pNetwork->PutUser(":***[email protected] PRIVMSG " + GetName() +
                                            " :Buffer Playback...",
                                        pUseClient);
                }

                bool bBatch = pUseClient->HasBatch();
                CString sBatchName = GetName().MD5();

                if (bBatch) {
                    m_pNetwork->PutUser(":znc.in BATCH +" + sBatchName +
                                            " znc.in/playback " + GetName(),
                                        pUseClient);
                }

                size_t uSize = Buffer.Size();
                for (size_t uIdx = 0; uIdx < uSize; uIdx++) {
                    const CBufLine& BufLine = Buffer.GetBufLine(uIdx);
                    CMessage Message =
                        BufLine.ToMessage(*pUseClient, MCString::EmptyMap);
                    Message.SetChan(this);
                    Message.SetNetwork(m_pNetwork);
                    Message.SetClient(pUseClient);
                    if (bBatch) {
                        Message.SetTag("batch", sBatchName);
                    }
                    bool bNotShowThisLine = false;
                    NETWORKMODULECALL(OnChanBufferPlayMessage(Message),
                                      m_pNetwork->GetUser(), m_pNetwork,
                                      nullptr, &bNotShowThisLine);
                    if (bNotShowThisLine) continue;
                    m_pNetwork->PutUser(Message, pUseClient);
                }

                bSkipStatusMsg = pUseClient->HasServerTime();
                NETWORKMODULECALL(OnChanBufferEnding(*this, *pUseClient),
                                  m_pNetwork->GetUser(), m_pNetwork, nullptr,
                                  &bSkipStatusMsg);
                if (!bSkipStatusMsg) {
                    m_pNetwork->PutUser(":***[email protected] PRIVMSG " + GetName() +
                                            " :Playback Complete.",
                                        pUseClient);
                }

                if (bBatch) {
                    m_pNetwork->PutUser(":znc.in BATCH -" + sBatchName,
                                        pUseClient);
                }

                pUseClient->SetPlaybackActive(bWasPlaybackActive);

                if (pClient) break;
            }
        }
    }
}