From 7e72bfa89c1105e0b3f127bae9b1695a81dc2215 Mon Sep 17 00:00:00 2001 From: Vladimir Panteleev Date: Thu, 27 Apr 2017 05:10:48 +0000 Subject: [PATCH] Don't send buffers to unknown clients Whenever autoadd is not enabled and an unknown client connects to ZNC, ZNC will proceed to indiscriminately send the contents of all buffers to the client. However, this behaviour keeps repeating each time the clients connects again: as this module is expected to be used with AutoClearChanBuffer and AutoClearQueryBuffer both off, the buffers aren't cleared, and ClientBuffer does not prevent ZNC from re-sending the buffers on each client connect. ClientBuffer should instead prevent ZNC from sending buffer contents to unidentified clients. Fixes #17. --- clientbuffer.cpp | 46 ++++++++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/clientbuffer.cpp b/clientbuffer.cpp index 81b3999..de65a61 100644 --- a/clientbuffer.cpp +++ b/clientbuffer.cpp @@ -163,12 +163,14 @@ CModule::EModRet CClientBufferMod::OnChanBufferStarting(CChan& chan, CClient& cl return HALTCORE; const CString& identifier = client.GetIdentifier(); - if (HasClient(identifier)) { - // let "Buffer Playback..." message through? - const CBuffer& buffer = chan.GetBuffer(); - if (!buffer.IsEmpty() && HasSeenTimestamp(identifier, chan.GetName(), GetTimestamp(buffer))) - return HALTCORE; - } + if (!HasClient(identifier)) + return HALTCORE; + + // let "Buffer Playback..." message through? + const CBuffer& buffer = chan.GetBuffer(); + if (!buffer.IsEmpty() && HasSeenTimestamp(identifier, chan.GetName(), GetTimestamp(buffer))) + return HALTCORE; + return CONTINUE; } @@ -178,31 +180,39 @@ CModule::EModRet CClientBufferMod::OnChanBufferEnding(CChan& chan, CClient& clie return HALTCORE; const CString& identifier = client.GetIdentifier(); - if (HasClient(identifier)) { - // let "Buffer Complete" message through? - const CBuffer& buffer = chan.GetBuffer(); - if (!buffer.IsEmpty() && !UpdateTimestamp(identifier, chan.GetName(), GetTimestamp(buffer))) - return HALTCORE; - } + if (!HasClient(identifier)) + return HALTCORE; + + // let "Buffer Complete" message through? + const CBuffer& buffer = chan.GetBuffer(); + if (!buffer.IsEmpty() && !UpdateTimestamp(identifier, chan.GetName(), GetTimestamp(buffer))) + return HALTCORE; + return CONTINUE; } CModule::EModRet CClientBufferMod::OnChanBufferPlayLine2(CChan& chan, CClient& client, CString& line, const timeval& tv) { const CString& identifier = client.GetIdentifier(); - if (HasClient(identifier) && HasSeenTimestamp(identifier, chan.GetName(), tv)) + if (!HasClient(identifier)) + return HALTCORE; + + if (HasSeenTimestamp(identifier, chan.GetName(), tv)) return HALTCORE; + return CONTINUE; } CModule::EModRet CClientBufferMod::OnPrivBufferPlayLine2(CClient& client, CString& line, const timeval& tv) { const CString& identifier = client.GetIdentifier(); - if (HasClient(identifier)) { - CNick nick; CString cmd, target; - if (ParseMessage(line, nick, cmd, target) && !UpdateTimestamp(identifier, target, tv)) - return HALTCORE; - } + if (!HasClient(identifier)) + return HALTCORE; + + CNick nick; CString cmd, target; + if (ParseMessage(line, nick, cmd, target) && !UpdateTimestamp(identifier, target, tv)) + return HALTCORE; + return CONTINUE; }