Skip to content

Commit

Permalink
Add OnPrivBufferStarting/Ending signals, similar to Chan buffers
Browse files Browse the repository at this point in the history
Allows hooking into query buffer playback before and after all the
lines of the query buffer are replayed. The EModRet return value
has no effect at the moment, but may be used in the future to e.g.
prevent playback. The Chan version of these signals use EModRet to
skip emitting the status message, but not the whole playback.
  • Loading branch information
torarnv committed Jul 13, 2016
1 parent 56620af commit 4d5724e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
18 changes: 18 additions & 0 deletions include/znc/Modules.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
// Forward Declarations
class CAuthBase;
class CChan;
class CQuery;
class CIRCNetwork;
class CClient;
class CWebSock;
Expand Down Expand Up @@ -733,6 +734,21 @@ class CModule {
virtual EModRet OnChanBufferPlayLine(CChan& Chan, CClient& Client,
CString& sLine);

/** Called before a query buffer is played back to a client.
* @since 1.7.0
* @param Query The query which will be played back.
* @param Client The client the buffer will be played back to.
* @return See CModule::EModRet.
*/
virtual EModRet OnPrivBufferStarting(CQuery& Query, CClient& Client);
/** Called after a query buffer was played back to a client.
* @since 1.7.0
* @param Query The query which was played back.
* @param Client The client the buffer was played back to.
* @return See CModule::EModRet.
*/
virtual EModRet OnPrivBufferEnding(CQuery& Query, CClient& Client);

/** Called for each message during a query's buffer play back.
* @since 1.7.0
* @param Message The playback message.
Expand Down Expand Up @@ -1412,6 +1428,8 @@ class CModules : public std::vector<CModule*> {
bool OnChanBufferPlayLine2(CChan& Chan, CClient& Client, CString& sLine,
const timeval& tv);
bool OnChanBufferPlayLine(CChan& Chan, CClient& Client, CString& sLine);
bool OnPrivBufferStarting(CQuery& Query, CClient& Client);
bool OnPrivBufferEnding(CQuery& Query, CClient& Client);
bool OnPrivBufferPlayLine2(CClient& Client, CString& sLine,
const timeval& tv);
bool OnPrivBufferPlayLine(CClient& Client, CString& sLine);
Expand Down
13 changes: 13 additions & 0 deletions src/Modules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <znc/FileUtils.h>
#include <znc/Template.h>
#include <znc/User.h>
#include <znc/Query.h>
#include <znc/IRCNetwork.h>
#include <znc/WebModules.h>
#include <znc/znc.h>
Expand Down Expand Up @@ -725,6 +726,12 @@ CModule::EModRet CModule::OnChanBufferPlayLine(CChan& Chan, CClient& Client,
CString& sLine) {
return CONTINUE;
}
CModule::EModRet CModule::OnPrivBufferStarting(CQuery& Query, CClient& Client) {
return CONTINUE;
}
CModule::EModRet CModule::OnPrivBufferEnding(CQuery& Query, CClient& Client) {
return CONTINUE;
}
CModule::EModRet CModule::OnPrivBufferPlayLine(CClient& Client,
CString& sLine) {
return CONTINUE;
Expand Down Expand Up @@ -1343,6 +1350,12 @@ bool CModules::OnChanBufferPlayLine(CChan& Chan, CClient& Client,
CString& sLine) {
MODHALTCHK(OnChanBufferPlayLine(Chan, Client, sLine));
}
bool CModules::OnPrivBufferStarting(CQuery& Query, CClient& Client) {
MODHALTCHK(OnPrivBufferStarting(Query, Client));
}
bool CModules::OnPrivBufferEnding(CQuery& Query, CClient& Client) {
MODHALTCHK(OnPrivBufferEnding(Query, Client));
}
bool CModules::OnPrivBufferPlayLine2(CClient& Client, CString& sLine,
const timeval& tv) {
MODHALTCHK(OnPrivBufferPlayLine2(Client, sLine, tv));
Expand Down
8 changes: 8 additions & 0 deletions src/Query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ void CQuery::SendBuffer(CClient* pClient, const CBuffer& Buffer) {
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();

Expand Down Expand Up @@ -82,6 +86,10 @@ void CQuery::SendBuffer(CClient* pClient, const CBuffer& Buffer) {
pUseClient);
}

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

pUseClient->SetPlaybackActive(bWasPlaybackActive);

if (pClient) break;
Expand Down

0 comments on commit 4d5724e

Please sign in to comment.