mirror of
https://github.com/znc/znc.git
synced 2026-07-06 18:01:21 +02:00
Unify channel buffers and CBuffer.
This commit is contained in:
+17
-1
@@ -7,6 +7,7 @@
|
||||
*/
|
||||
|
||||
#include <znc/Buffer.h>
|
||||
#include <znc/znc.h>
|
||||
|
||||
CBufLine::CBufLine(const CString& sFormat) {
|
||||
m_sFormat = sFormat;
|
||||
@@ -58,6 +59,15 @@ int CBuffer::UpdateExactLine(const CString& sFormat) {
|
||||
return AddLine(sFormat);
|
||||
}
|
||||
|
||||
bool CBuffer::GetLineFormat(unsigned int uIdx, CString& sRet) const {
|
||||
if (uIdx >= size()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
sRet = (*this)[uIdx].GetFormat();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CBuffer::GetLine(unsigned int uIdx, CString& sRet, const MCString& msParams) const {
|
||||
if (uIdx >= size()) {
|
||||
return false;
|
||||
@@ -79,11 +89,17 @@ bool CBuffer::GetNextLine(CString& sRet, const MCString& msParams) {
|
||||
return true;
|
||||
}
|
||||
|
||||
void CBuffer::SetLineCount(unsigned int u) {
|
||||
bool CBuffer::SetLineCount(unsigned int u, bool bForce) {
|
||||
if (!bForce && u > CZNC::Get().GetMaxBufferSize()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
m_uLineCount = u;
|
||||
|
||||
// We may need to shrink the buffer if the allowed size got smaller
|
||||
while (size() > m_uLineCount) {
|
||||
erase(begin());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
+6
-39
@@ -26,9 +26,9 @@ CChan::CChan(const CString& sName, CIRCNetwork* pNetwork, bool bInConfig, CConfi
|
||||
m_bInConfig = bInConfig;
|
||||
m_Nick.SetNetwork(m_pNetwork);
|
||||
m_bDetached = false;
|
||||
m_uBufferCount = m_pNetwork->GetUser()->GetBufferCount();
|
||||
m_bKeepBuffer = m_pNetwork->GetUser()->KeepBuffer();
|
||||
m_bDisabled = false;
|
||||
SetBufferCount(m_pNetwork->GetUser()->GetBufferCount(), true);
|
||||
SetKeepBuffer(m_pNetwork->GetUser()->KeepBuffer());
|
||||
Reset();
|
||||
|
||||
if (pConfig) {
|
||||
@@ -106,14 +106,6 @@ void CChan::Clone(CChan& chan) {
|
||||
}
|
||||
}
|
||||
|
||||
bool CChan::SetBufferCount(unsigned int u, bool bForce) {
|
||||
if (!bForce && u > CZNC::Get().GetMaxBufferSize())
|
||||
return false;
|
||||
m_uBufferCount = u;
|
||||
TrimBuffer(m_uBufferCount);
|
||||
return true;
|
||||
}
|
||||
|
||||
void CChan::Cycle() const {
|
||||
m_pNetwork->PutIRC("PART " + GetName() + "\r\nJOIN " + GetName() + " " + GetKey());
|
||||
}
|
||||
@@ -516,34 +508,8 @@ CNick* CChan::FindNick(const CString& sNick) {
|
||||
return (it != m_msNicks.end()) ? &it->second : NULL;
|
||||
}
|
||||
|
||||
int CChan::AddBuffer(const CString& sLine) {
|
||||
// Todo: revisit the buffering
|
||||
if (!m_uBufferCount) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (m_vsBuffer.size() >= m_uBufferCount) {
|
||||
m_vsBuffer.erase(m_vsBuffer.begin());
|
||||
}
|
||||
|
||||
m_vsBuffer.push_back(sLine);
|
||||
return m_vsBuffer.size();
|
||||
}
|
||||
|
||||
void CChan::ClearBuffer() {
|
||||
m_vsBuffer.clear();
|
||||
}
|
||||
|
||||
void CChan::TrimBuffer(const unsigned int uMax) {
|
||||
if (m_vsBuffer.size() > uMax) {
|
||||
m_vsBuffer.erase(m_vsBuffer.begin(), m_vsBuffer.begin() + (m_vsBuffer.size() - uMax));
|
||||
}
|
||||
}
|
||||
|
||||
void CChan::SendBuffer(CClient* pClient) {
|
||||
if (m_pNetwork && m_pNetwork->IsUserAttached()) {
|
||||
const vector<CString>& vsBuffer = GetBuffer();
|
||||
|
||||
// in the event that pClient is NULL, 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.
|
||||
@@ -558,7 +524,7 @@ void CChan::SendBuffer(CClient* pClient) {
|
||||
// if pClient is not NULL, the loops break after the first iteration.
|
||||
//
|
||||
// Rework this if you like ...
|
||||
if (vsBuffer.size()) {
|
||||
if (!m_Buffer.IsEmpty()) {
|
||||
const vector<CClient*> & vClients = m_pNetwork->GetClients();
|
||||
for (size_t uClient = 0; uClient < vClients.size(); ++uClient) {
|
||||
|
||||
@@ -570,8 +536,9 @@ void CChan::SendBuffer(CClient* pClient) {
|
||||
m_pNetwork->PutUser(":***!znc@znc.in PRIVMSG " + GetName() + " :Buffer Playback...", pUseClient);
|
||||
}
|
||||
|
||||
for (unsigned int a = 0; a < vsBuffer.size(); a++) {
|
||||
CString sLine(vsBuffer[a]);
|
||||
CString sLine;
|
||||
unsigned int uIdx = 0;
|
||||
while (m_Buffer.GetLine(uIdx++, sLine)) {
|
||||
NETWORKMODULECALL(OnChanBufferPlayLine(*this, *pUseClient, sLine), m_pNetwork->GetUser(), m_pNetwork, NULL, continue);
|
||||
m_pNetwork->PutUser(sLine, pUseClient);
|
||||
}
|
||||
|
||||
+3
-3
@@ -239,7 +239,7 @@ void CClient::ReadLine(const CString& sData) {
|
||||
CChan* pChan = m_pNetwork->FindChan(sTarget);
|
||||
|
||||
if ((pChan) && (pChan->KeepBuffer())) {
|
||||
pChan->AddBuffer(":" + GetNickMask() + " NOTICE " + sTarget + " :" + m_pUser->AddTimestamp(sMsg));
|
||||
pChan->AddBuffer(":" + _NAMEDFMT(GetNickMask()) + " NOTICE " + _NAMEDFMT(sTarget) + " :" + _NAMEDFMT(m_pUser->AddTimestamp(sMsg)));
|
||||
}
|
||||
|
||||
// Relay to the rest of the clients that may be connected to this user
|
||||
@@ -285,7 +285,7 @@ void CClient::ReadLine(const CString& sData) {
|
||||
sCTCP = "ACTION " + sMessage;
|
||||
|
||||
if (pChan && pChan->KeepBuffer()) {
|
||||
pChan->AddBuffer(":" + GetNickMask() + " PRIVMSG " + sTarget + " :\001ACTION " + m_pUser->AddTimestamp(sMessage) + "\001");
|
||||
pChan->AddBuffer(":" + _NAMEDFMT(GetNickMask()) + " PRIVMSG " + _NAMEDFMT(sTarget) + " :\001ACTION " + _NAMEDFMT(m_pUser->AddTimestamp(sMessage)) + "\001");
|
||||
}
|
||||
|
||||
// Relay to the rest of the clients that may be connected to this user
|
||||
@@ -333,7 +333,7 @@ void CClient::ReadLine(const CString& sData) {
|
||||
CChan* pChan = m_pNetwork->FindChan(sTarget);
|
||||
|
||||
if ((pChan) && (pChan->KeepBuffer())) {
|
||||
pChan->AddBuffer(":" + GetNickMask() + " PRIVMSG " + sTarget + " :" + m_pUser->AddTimestamp(sMsg));
|
||||
pChan->AddBuffer(":" + _NAMEDFMT(GetNickMask()) + " PRIVMSG " + _NAMEDFMT(sTarget) + " :" + _NAMEDFMT(m_pUser->AddTimestamp(sMsg)));
|
||||
}
|
||||
|
||||
PutIRC("PRIVMSG " + sTarget + " :" + sMsg);
|
||||
|
||||
@@ -1073,7 +1073,7 @@ void CClient::UserCommand(CString& sLine) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (pChan->GetBuffer().empty()) {
|
||||
if (pChan->GetBuffer().IsEmpty()) {
|
||||
PutStatus("The buffer for [" + sChan + "] is empty");
|
||||
return;
|
||||
}
|
||||
|
||||
+6
-6
@@ -49,9 +49,9 @@ CIRCNetwork::CIRCNetwork(CUser *pUser, const CString& sName) {
|
||||
m_sChanPrefixes = "";
|
||||
m_bIRCAway = false;
|
||||
|
||||
m_RawBuffer.SetLineCount(100); // This should be more than enough raws, especially since we are buffering the MOTD separately
|
||||
m_MotdBuffer.SetLineCount(200); // This should be more than enough motd lines
|
||||
m_QueryBuffer.SetLineCount(250);
|
||||
m_RawBuffer.SetLineCount(100, true); // This should be more than enough raws, especially since we are buffering the MOTD separately
|
||||
m_MotdBuffer.SetLineCount(200, true); // This should be more than enough motd lines
|
||||
m_QueryBuffer.SetLineCount(250, true);
|
||||
}
|
||||
|
||||
CIRCNetwork::CIRCNetwork(CUser *pUser, const CIRCNetwork *pNetwork, bool bCloneChans) {
|
||||
@@ -67,9 +67,9 @@ CIRCNetwork::CIRCNetwork(CUser *pUser, const CIRCNetwork *pNetwork, bool bCloneC
|
||||
m_sChanPrefixes = "";
|
||||
m_bIRCAway = false;
|
||||
|
||||
m_RawBuffer.SetLineCount(100); // This should be more than enough raws, especially since we are buffering the MOTD separately
|
||||
m_MotdBuffer.SetLineCount(200); // This should be more than enough motd lines
|
||||
m_QueryBuffer.SetLineCount(250);
|
||||
m_RawBuffer.SetLineCount(100, true); // This should be more than enough raws, especially since we are buffering the MOTD separately
|
||||
m_MotdBuffer.SetLineCount(200, true); // This should be more than enough motd lines
|
||||
m_QueryBuffer.SetLineCount(250, true);
|
||||
|
||||
// Servers
|
||||
const vector<CServer*>& vServers = pNetwork->GetServers();
|
||||
|
||||
+3
-3
@@ -853,7 +853,7 @@ bool CIRCSock::OnChanCTCP(CNick& Nick, const CString& sChan, CString& sMessage)
|
||||
if (sMessage.TrimPrefix("ACTION ")) {
|
||||
IRCSOCKMODULECALL(OnChanAction(Nick, *pChan, sMessage), return true);
|
||||
if (pChan->KeepBuffer() || !m_pNetwork->IsUserOnline() || pChan->IsDetached()) {
|
||||
pChan->AddBuffer(":" + Nick.GetNickMask() + " PRIVMSG " + sChan + " :\001ACTION " + m_pNetwork->GetUser()->AddTimestamp(sMessage) + "\001");
|
||||
pChan->AddBuffer(":" + _NAMEDFMT(Nick.GetNickMask()) + " PRIVMSG " + _NAMEDFMT(sChan) + " :\001ACTION " + _NAMEDFMT(m_pNetwork->GetUser()->AddTimestamp(sMessage)) + "\001");
|
||||
}
|
||||
sMessage = "ACTION " + sMessage;
|
||||
}
|
||||
@@ -871,7 +871,7 @@ bool CIRCSock::OnChanNotice(CNick& Nick, const CString& sChan, CString& sMessage
|
||||
IRCSOCKMODULECALL(OnChanNotice(Nick, *pChan, sMessage), return true);
|
||||
|
||||
if (pChan->KeepBuffer() || !m_pNetwork->IsUserOnline() || pChan->IsDetached()) {
|
||||
pChan->AddBuffer(":" + Nick.GetNickMask() + " NOTICE " + sChan + " :" + m_pNetwork->GetUser()->AddTimestamp(sMessage));
|
||||
pChan->AddBuffer(":" + _NAMEDFMT(Nick.GetNickMask()) + " NOTICE " + _NAMEDFMT(sChan) + " :" + _NAMEDFMT(m_pNetwork->GetUser()->AddTimestamp(sMessage)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -884,7 +884,7 @@ bool CIRCSock::OnChanMsg(CNick& Nick, const CString& sChan, CString& sMessage) {
|
||||
IRCSOCKMODULECALL(OnChanMsg(Nick, *pChan, sMessage), return true);
|
||||
|
||||
if (pChan->KeepBuffer() || !m_pNetwork->IsUserOnline() || pChan->IsDetached()) {
|
||||
pChan->AddBuffer(":" + Nick.GetNickMask() + " PRIVMSG " + sChan + " :" + m_pNetwork->GetUser()->AddTimestamp(sMessage));
|
||||
pChan->AddBuffer(":" + _NAMEDFMT(Nick.GetNickMask()) + " PRIVMSG " + _NAMEDFMT(sChan) + " :" + _NAMEDFMT(m_pNetwork->GetUser()->AddTimestamp(sMessage)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user