Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
  • 7 commits
  • 18 files changed
  • 0 commit comments
  • 1 contributor
Commits on Oct 27, 2011
@stephank stephank Add server time CAP and Client flag. f7e5b41
@stephank stephank Add string formatting function with named params.
In addition to the formatting function, a matching Escape type is added.
2fdf54d
@stephank stephank Rewrite Buffer to store a format string.
Will use this to allow more parameters to be inserted at the time the
buffers are flushed to the client.
948ae25
@stephank stephank Unify channel buffers and CBuffer. cb4131e
@stephank stephank Slight refactor of CBuffer & CBufLine.
This is in preparation of adding more attributes to a CBufLine. Going
forward, at least savebuf will need access to all of these to properly
serialize buffers.

Basically, instead of relying on `GetLine()` to return `false`, the
caller is now expected to check bounds himself using `Size()`.
c3d677a
@stephank stephank Store and format time in CBufLine.
Buflines need to know which part of text to wrap with the timestamp. The
second parameter to `AddLine` (and shorthands) is that text, which after
wrapping is added as the `text` parameter to `NamedFormat`.

Timestamps are formatted at the moment buffers are flushed to the
client. The client parameter to `GetLine` provides access to the User
and the new server-time capability.
c36480c
@stephank stephank Working savebuff saving and loading.
It's even backwards compatible!
355f196
View
48 include/znc/Buffer.h
@@ -15,25 +15,34 @@
using std::deque;
+// Forward Declarations
+class CClient;
+// !Forward Declarations
+
class CBufLine {
public:
- CBufLine(const CString& sPre, const CString& sPost, bool bIncNick);
+ CBufLine(const CString& sFormat, const CString& sText = "", time_t tm = 0);
~CBufLine();
- void GetLine(const CString& sTarget, CString& sRet) const;
+ CString GetLine(const CClient& Client, const MCString& msParams) const;
+ void UpdateTime() { time(&m_tm); }
- const CString& GetPre() const { return m_sPre; }
- const CString& GetPost() const { return m_sPost; }
- bool GetIncNick() const { return m_bIncNick; }
+ // Setters
+ void SetFormat(const CString& sFormat) { m_sFormat = sFormat; }
+ void SetText(const CString& sText) { m_sText = sText; }
+ void SetTime(time_t tm) { m_tm = tm; }
+ // !Setters
- void SetPre(const CString& s) { m_sPre = s; }
- void SetPost(const CString& s) { m_sPost = s; }
- void SetIncNick(bool b) { m_bIncNick = b; }
+ // Getters
+ const CString& GetFormat() const { return m_sFormat; }
+ const CString& GetText() const { return m_sText; }
+ time_t GetTime() const { return m_tm; }
+ // !Getters
private:
protected:
- CString m_sPre;
- CString m_sPost;
- bool m_bIncNick;
+ CString m_sFormat;
+ CString m_sText;
+ time_t m_tm;
};
class CBuffer : private deque<CBufLine> {
@@ -41,18 +50,19 @@ class CBuffer : private deque<CBufLine> {
CBuffer(unsigned int uLineCount = 100);
~CBuffer();
- int AddLine(const CString& sPre, const CString& sPost, bool bIncNick = true);
- /// Same as AddLine, but if there is already a line with sPre it is replaced.
- int UpdateLine(const CString& sPre, const CString& sPost, bool bIncNick = true);
- /// Same as UpdateLine, but does nothing if this exact line already exists
- int UpdateExactLine(const CString& sPre, const CString& sPost, bool bIncNick = true);
- bool GetNextLine(const CString& sTarget, CString& sRet);
- bool GetLine(const CString& sTarget, CString& sRet, unsigned int uIdx) const;
+ int AddLine(const CString& sFormat, const CString& sText = "", time_t tm = 0);
+ /// Same as AddLine, but replaces a line whose format string starts with sMatch if there is one.
+ int UpdateLine(const CString& sMatch, const CString& sFormat, const CString& sText = "");
+ /// Same as UpdateLine, but does nothing if this exact line already exists.
+ int UpdateExactLine(const CString& sFormat, const CString& sText = "");
+ const CBufLine& GetBufLine(unsigned int uIdx) const;
+ CString GetLine(unsigned int uIdx, const CClient& Client, const MCString& msParams = MCString::EmptyMap) const;
+ unsigned int Size() const { return size(); }
bool IsEmpty() const { return empty(); }
void Clear() { clear(); }
// Setters
- void SetLineCount(unsigned int u);
+ bool SetLineCount(unsigned int u, bool bForce = false);
// !Setters
// Getters
View
15 include/znc/Chan.h
@@ -12,6 +12,7 @@
#include <znc/zncconfig.h>
#include <znc/Nick.h>
#include <znc/ZNCString.h>
+#include <znc/Buffer.h>
#include <map>
#include <set>
#include <vector>
@@ -87,9 +88,11 @@ class CChan {
// !Nicks
// Buffer
- int AddBuffer(const CString& sLine);
- void ClearBuffer();
- void TrimBuffer(const unsigned int uMax);
+ const CBuffer& GetBuffer() const { return m_Buffer; }
+ unsigned int GetBufferCount() const { return m_Buffer.GetLineCount(); }
+ bool SetBufferCount(unsigned int u, bool bForce = false) { return m_Buffer.SetLineCount(u, bForce); };
+ int AddBuffer(const CString& sFormat, const CString& sText = "", time_t tm = 0) { return m_Buffer.AddLine(sFormat, sText, tm); }
+ void ClearBuffer() { m_Buffer.Clear(); }
void SendBuffer(CClient* pClient);
// !Buffer
@@ -108,7 +111,6 @@ class CChan {
void SetTopicOwner(const CString& s) { m_sTopicOwner = s; }
void SetTopicDate(unsigned long u) { m_ulTopicDate = u; }
void SetDefaultModes(const CString& s) { m_sDefaultModes = s; }
- bool SetBufferCount(unsigned int u, bool bForce = false);
void SetKeepBuffer(bool b) { m_bKeepBuffer = b; }
void SetDetached(bool b = true) { m_bDetached = b; }
void SetInConfig(bool b) { m_bInConfig = b; }
@@ -133,10 +135,8 @@ class CChan {
const CString& GetTopicOwner() const { return m_sTopicOwner; }
unsigned int GetTopicDate() const { return m_ulTopicDate; }
const CString& GetDefaultModes() const { return m_sDefaultModes; }
- const vector<CString>& GetBuffer() const { return m_vsBuffer; }
const map<CString,CNick>& GetNicks() const { return m_msNicks; }
unsigned int GetNickCount() const { return m_msNicks.size(); }
- unsigned int GetBufferCount() const { return m_uBufferCount; }
bool KeepBuffer() const { return m_bKeepBuffer; }
bool IsDetached() const { return m_bDetached; }
bool InConfig() const { return m_bInConfig; }
@@ -162,8 +162,7 @@ class CChan {
unsigned int m_uJoinTries;
CString m_sDefaultModes;
map<CString,CNick> m_msNicks; // Todo: make this caseless (irc style)
- unsigned int m_uBufferCount;
- vector<CString> m_vsBuffer;
+ CBuffer m_Buffer;
bool m_bModeKnown;
map<unsigned char, CString> m_musModes;
View
3 include/znc/Client.h
@@ -85,6 +85,7 @@ class CClient : public CZNCSock {
m_bNamesx = false;
m_bUHNames = false;
m_bAway = false;
+ m_bServerTime = false;
EnableReadLine();
// RFC says a line can have 512 chars max, but we are
// a little more gentle ;)
@@ -103,6 +104,7 @@ class CClient : public CZNCSock {
bool HasNamesx() const { return m_bNamesx; }
bool HasUHNames() const { return m_bUHNames; }
bool IsAway() const { return m_bAway; }
+ bool HasServerTime() const { return m_bServerTime; }
void UserCommand(CString& sLine);
void UserPortCommand(CString& sLine);
@@ -151,6 +153,7 @@ class CClient : public CZNCSock {
bool m_bNamesx;
bool m_bUHNames;
bool m_bAway;
+ bool m_bServerTime;
CUser* m_pUser;
CIRCNetwork* m_pNetwork;
CString m_sNick;
View
14 include/znc/IRCNetwork.h
@@ -107,17 +107,17 @@ class CIRCNetwork {
bool PutIRC(const CString& sLine);
// Buffers
- void AddRawBuffer(const CString& sPre, const CString& sPost, bool bIncNick = true) { m_RawBuffer.AddLine(sPre, sPost, bIncNick); }
- void UpdateRawBuffer(const CString& sPre, const CString& sPost, bool bIncNick = true) { m_RawBuffer.UpdateLine(sPre, sPost, bIncNick); }
- void UpdateExactRawBuffer(const CString& sPre, const CString& sPost, bool bIncNick = true) { m_RawBuffer.UpdateExactLine(sPre, sPost, bIncNick); }
+ void AddRawBuffer(const CString& sFormat, const CString& sText = "") { m_RawBuffer.AddLine(sFormat, sText); }
+ void UpdateRawBuffer(const CString& sMatch, const CString& sFormat, const CString& sText = "") { m_RawBuffer.UpdateLine(sMatch, sFormat, sText); }
+ void UpdateExactRawBuffer(const CString& sFormat, const CString& sText = "") { m_RawBuffer.UpdateExactLine(sFormat, sText); }
void ClearRawBuffer() { m_RawBuffer.Clear(); }
- void AddMotdBuffer(const CString& sPre, const CString& sPost, bool bIncNick = true) { m_MotdBuffer.AddLine(sPre, sPost, bIncNick); }
- void UpdateMotdBuffer(const CString& sPre, const CString& sPost, bool bIncNick = true) { m_MotdBuffer.UpdateLine(sPre, sPost, bIncNick); }
+ void AddMotdBuffer(const CString& sFormat, const CString& sText = "") { m_MotdBuffer.AddLine(sFormat, sText); }
+ void UpdateMotdBuffer(const CString& sMatch, const CString& sFormat, const CString& sText = "") { m_MotdBuffer.UpdateLine(sMatch, sFormat, sText); }
void ClearMotdBuffer() { m_MotdBuffer.Clear(); }
- void AddQueryBuffer(const CString& sPre, const CString& sPost, bool bIncNick = true) { m_QueryBuffer.AddLine(sPre, sPost, bIncNick); }
- void UpdateQueryBuffer(const CString& sPre, const CString& sPost, bool bIncNick = true) { m_QueryBuffer.UpdateLine(sPre, sPost, bIncNick); }
+ void AddQueryBuffer(const CString& sFormat, const CString& sText = "") { m_QueryBuffer.AddLine(sFormat, sText); }
+ void UpdateQueryBuffer(const CString& sMatch, const CString& sFormat, const CString& sText = "") { m_QueryBuffer.UpdateLine(sMatch, sFormat, sText); }
void ClearQueryBuffer() { m_QueryBuffer.Clear(); }
// !Buffers
View
2 include/znc/User.h
@@ -89,7 +89,7 @@ class CUser {
CString& ExpandString(const CString& sStr, CString& sRet) const;
CString AddTimestamp(const CString& sStr) const;
- CString& AddTimestamp(const CString& sStr, CString& sRet) const;
+ CString AddTimestamp(time_t tm, const CString& sStr) const;
bool Clone(const CUser& User, CString& sErrorRet, bool bCloneChans = true);
void BounceAllClients();
View
17 include/znc/ZNCString.h
@@ -27,6 +27,7 @@ using std::pair;
#define _SQL(s) CString("'" + CString(s).Escape_n(CString::ESQL) + "'")
#define _URL(s) CString(s).Escape_n(CString::EURL)
#define _HTML(s) CString(s).Escape_n(CString::EHTML)
+#define _NAMEDFMT(s) CString(s).Escape_n(CString::ENAMEDFMT)
class CString;
class MCString;
@@ -68,7 +69,8 @@ class CString : public string {
EASCII,
EURL,
EHTML,
- ESQL
+ ESQL,
+ ENAMEDFMT
} EEscape;
explicit CString(bool b) : string(b ? "true" : "false") {}
@@ -282,6 +284,16 @@ class CString : public string {
const CString& sLeft = "", const CString& sRight = "", bool bTrimQuotes = true,
bool bTrimWhiteSpace = false) const;
+ /** Build a string from a format string, replacing values from a map.
+ * The format specification can contain simple named parameters that match
+ * keys in the given map. For example in the string "a {b} c", the key "b"
+ * is looked up in the map, and inserted for "{b}".
+ * @param sFormat The format specification.
+ * @param msValues A map of named parameters to their values.
+ * @return The string with named parameters replaced.
+ */
+ static CString NamedFormat(const CString& sFormat, const MCString& msValues);
+
/** Produces a random string.
* @param uLength The length of the resulting string.
* @return A random string.
@@ -470,6 +482,9 @@ class MCString : public map<CString, CString> {
/** Destruct this MCString. */
virtual ~MCString() { clear(); }
+ /** A static instance of an empty map. */
+ static const MCString EmptyMap;
+
/** Status codes that can be returned by WriteToDisk() and
* ReadFromDisk(). */
enum status_t
View
7 modules/buffextras.cpp
@@ -22,9 +22,7 @@ class CBuffExtras : public CModule {
if (!Channel.KeepBuffer() && m_pNetwork->IsUserOnline())
return;
- CString s = ":" + GetModNick() + "!" + GetModName() + "@znc.in PRIVMSG "
- + Channel.GetName() + " :" + m_pUser->AddTimestamp(sMessage);
- Channel.AddBuffer(s);
+ Channel.AddBuffer(":" + GetModNick() + "!" + GetModName() + "@znc.in PRIVMSG " + _NAMEDFMT(Channel.GetName()) + " :{text}", sMessage);
}
virtual void OnRawMode(const CNick& OpNick, CChan& Channel, const CString& sModes, const CString& sArgs) {
@@ -32,8 +30,7 @@ class CBuffExtras : public CModule {
}
virtual void OnKick(const CNick& OpNick, const CString& sKickedNick, CChan& Channel, const CString& sMessage) {
- AddBuffer(Channel, OpNick.GetNickMask() + " kicked " + sKickedNick
- + " Reason: [" + sMessage + "]");
+ AddBuffer(Channel, OpNick.GetNickMask() + " kicked " + sKickedNick + " Reason: [" + sMessage + "]");
}
virtual void OnQuit(const CNick& Nick, const CString& sMessage, const vector<CChan*>& vChans) {
View
2 modules/crypt.cpp
@@ -47,7 +47,7 @@ class CCryptMod : public CModule {
CChan* pChan = m_pNetwork->FindChan(sTarget);
if (pChan) {
if (pChan->KeepBuffer())
- pChan->AddBuffer(":\244" + m_pNetwork->GetIRCNick().GetNickMask() + " PRIVMSG " + sTarget + " :" + sMessage);
+ pChan->AddBuffer(":\244" + _NAMEDFMT(m_pNetwork->GetIRCNick().GetNickMask()) + " PRIVMSG " + _NAMEDFMT(sTarget) + " :" + _NAMEDFMT(sMessage));
m_pUser->PutUser(":\244" + m_pNetwork->GetIRCNick().GetNickMask() + " PRIVMSG " + sTarget + " :" + sMessage, NULL, m_pClient);
}
View
34 modules/savebuff.cpp
@@ -16,6 +16,7 @@
#include <znc/Chan.h>
#include <znc/User.h>
+#include <znc/Buffer.h>
#include <znc/IRCNetwork.h>
#include <znc/FileUtils.h>
#include <sys/stat.h>
@@ -104,7 +105,7 @@ class CSaveBuff : public CModule
CString sFile;
if (DecryptChannel(pChan->GetName(), sFile))
{
- if (!pChan->GetBuffer().empty())
+ if (!pChan->GetBuffer().IsEmpty())
return(true); // reloaded a module probably in this case, so just verify we can decrypt the file
VCString vsLines;
@@ -115,7 +116,23 @@ class CSaveBuff : public CModule
for (it = vsLines.begin(); it != vsLines.end(); ++it) {
CString sLine(*it);
sLine.Trim();
- pChan->AddBuffer(sLine);
+ if (sLine[0] == '@' && it+1 != vsLines.end())
+ {
+ CString sTimestamp = sLine.Token(0);
+ sTimestamp.TrimLeft("@");
+ time_t tm = sTimestamp.ToLongLong();
+
+ CString sFormat = sLine.Token(1, true);
+
+ CString sText(*++it);
+ sText.Trim();
+
+ pChan->AddBuffer(sFormat, sText, tm);
+ } else
+ {
+ // Old format, escape the line and use as is.
+ pChan->AddBuffer(_NAMEDFMT(sLine));
+ }
}
} else
{
@@ -142,13 +159,18 @@ class CSaveBuff : public CModule
continue;
}
- const vector<CString> & vBuffer = vChans[a]->GetBuffer();
+ const CBuffer& Buffer = vChans[a]->GetBuffer();
+ CString sLine;
CString sFile = CRYPT_VERIFICATION_TOKEN;
- for (u_int b = 0; b < vBuffer.size(); b++)
- {
- sFile += vBuffer[b] + "\n";
+ unsigned int uSize = Buffer.Size();
+ for (unsigned int uIdx = 0; uIdx < uSize; uIdx++) {
+ const CBufLine& Line = Buffer.GetBufLine(uIdx);
+ sFile +=
+ "@" + CString(Line.GetTime()) + " " +
+ Line.GetFormat() + "\n" +
+ Line.GetText() + "\n";
}
CBlowfish c(m_sPassword, BF_ENCRYPT);
View
16 modules/watch.cpp
@@ -167,11 +167,13 @@ class CWatcherMod : public CModule {
}
virtual void OnClientLogin() {
- CString sBufLine;
- while (m_Buffer.GetNextLine(m_pNetwork->GetCurNick(), sBufLine)) {
- PutUser(sBufLine);
- }
+ MCString msParams;
+ msParams["target"] = m_pNetwork->GetCurNick();
+ unsigned int uSize = m_Buffer.Size();
+ for (unsigned int uIdx = 0; uIdx < uSize; uIdx++) {
+ PutUser(m_Buffer.GetLine(uIdx, *GetClient(), msParams));
+ }
m_Buffer.Clear();
}
@@ -289,11 +291,9 @@ class CWatcherMod : public CModule {
if (WatchEntry.IsMatch(Nick, sMessage, sSource, m_pNetwork)) {
if (m_pNetwork->IsUserAttached()) {
- m_pNetwork->PutUser(":" + WatchEntry.GetTarget() + "!watch@znc.in PRIVMSG " +
- m_pNetwork->GetCurNick() + " :" + sMessage);
+ m_pNetwork->PutUser(":" + WatchEntry.GetTarget() + "!watch@znc.in PRIVMSG " + m_pNetwork->GetCurNick() + " :" + sMessage);
} else {
- m_Buffer.AddLine(":" + WatchEntry.GetTarget() + "!watch@znc.in PRIVMSG ",
- " :" + m_pUser->AddTimestamp(sMessage));
+ m_Buffer.AddLine(":" + _NAMEDFMT(WatchEntry.GetTarget()) + "!watch@znc.in PRIVMSG {target} :{text}", sMessage);
}
}
}
View
79 src/Buffer.cpp
@@ -7,20 +7,32 @@
*/
#include <znc/Buffer.h>
-
-CBufLine::CBufLine(const CString& sPre, const CString& sPost, bool bIncNick=true) {
- m_sPre = sPre;
- m_sPost = sPost;
- m_bIncNick = bIncNick;
+#include <znc/znc.h>
+#include <znc/Client.h>
+#include <znc/User.h>
+
+CBufLine::CBufLine(const CString& sFormat, const CString& sText, time_t tm) {
+ m_sFormat = sFormat;
+ m_sText = sText;
+ if (tm == 0)
+ UpdateTime();
+ else
+ m_tm = tm;
}
CBufLine::~CBufLine() {}
-void CBufLine::GetLine(const CString& sTarget, CString& sRet) const {
- if (m_bIncNick)
- sRet = m_sPre + sTarget + m_sPost;
- else
- sRet = m_sPre + m_sPost;
+CString CBufLine::GetLine(const CClient& Client, const MCString& msParams) const {
+ MCString msThisParams = msParams;
+
+ if (Client.HasServerTime()) {
+ msThisParams["text"] = m_sText;
+ CString sStr = CString::NamedFormat(m_sFormat, msThisParams);
+ return "@" + CString(m_tm) + " " + sStr;
+ } else {
+ msThisParams["text"] = Client.GetUser()->AddTimestamp(m_tm, m_sText);
+ return CString::NamedFormat(m_sFormat, msThisParams);
+ }
}
CBuffer::CBuffer(unsigned int uLineCount) {
@@ -29,7 +41,7 @@ CBuffer::CBuffer(unsigned int uLineCount) {
CBuffer::~CBuffer() {}
-int CBuffer::AddLine(const CString& sPre, const CString& sPost, bool bIncNick) {
+int CBuffer::AddLine(const CString& sFormat, const CString& sText, time_t tm) {
if (!m_uLineCount) {
return 0;
}
@@ -38,57 +50,52 @@ int CBuffer::AddLine(const CString& sPre, const CString& sPost, bool bIncNick) {
erase(begin());
}
- push_back(CBufLine(sPre, sPost, bIncNick));
+ push_back(CBufLine(sFormat, sText, tm));
return size();
}
-int CBuffer::UpdateLine(const CString& sPre, const CString& sPost, bool bIncNick) {
+int CBuffer::UpdateLine(const CString& sMatch, const CString& sFormat, const CString& sText) {
for (iterator it = begin(); it != end(); ++it) {
- if (it->GetPre() == sPre) {
- it->SetPost(sPost);
- it->SetIncNick(bIncNick);
+ if (it->GetFormat().compare(0, sMatch.length(), sMatch) == 0) {
+ it->SetFormat(sFormat);
+ it->SetText(sText);
+ it->UpdateTime();
return size();
}
}
- return AddLine(sPre, sPost, bIncNick);
+ return AddLine(sFormat, sText);
}
-int CBuffer::UpdateExactLine(const CString& sPre, const CString& sPost, bool bIncNick) {
+int CBuffer::UpdateExactLine(const CString& sFormat, const CString& sText) {
for (iterator it = begin(); it != end(); ++it) {
- if (it->GetPre() == sPre && it->GetPost() == sPost)
+ if (it->GetFormat() == sFormat && it->GetText() == sText) {
return size();
+ }
}
- return AddLine(sPre, sPost, bIncNick);
+ return AddLine(sFormat, sText);
}
-bool CBuffer::GetLine(const CString& sTarget, CString& sRet, unsigned int uIdx) const {
- if (uIdx >= size()) {
- return false;
- }
-
- (*this)[uIdx].GetLine(sTarget, sRet);
- return true;
+const CBufLine& CBuffer::GetBufLine(unsigned int uIdx) const {
+ return (*this)[uIdx];
}
-bool CBuffer::GetNextLine(const CString& sTarget, CString& sRet) {
- sRet = "";
+CString CBuffer::GetLine(unsigned int uIdx, const CClient& Client, const MCString& msParams) const {
+ return (*this)[uIdx].GetLine(Client, msParams);
+}
- if (!size()) {
+bool CBuffer::SetLineCount(unsigned int u, bool bForce) {
+ if (!bForce && u > CZNC::Get().GetMaxBufferSize()) {
return false;
}
- begin()->GetLine(sTarget, sRet);
- erase(begin());
- return true;
-}
-
-void CBuffer::SetLineCount(unsigned int u) {
m_uLineCount = u;
// We may need to shrink the buffer if the allowed size got smaller
while (size() > m_uLineCount) {
erase(begin());
}
+
+ return true;
}
View
45 src/Chan.cpp
@@ -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]);
+ unsigned int uSize = m_Buffer.Size();
+ for (unsigned int uIdx = 0; uIdx < uSize; uIdx++) {
+ CString sLine = m_Buffer.GetLine(uIdx, *pClient);
NETWORKMODULECALL(OnChanBufferPlayLine(*this, *pUseClient, sLine), m_pNetwork->GetUser(), m_pNetwork, NULL, continue);
m_pNetwork->PutUser(sLine, pUseClient);
}
View
16 src/Client.cpp
@@ -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) + " :{text}", 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 {text}\001", sMessage);
}
// 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) + " :{text}", sMsg);
}
PutIRC("PRIVMSG " + sTarget + " :" + sMsg);
@@ -768,7 +768,7 @@ void CClient::HandleCap(const CString& sLine)
for (SCString::iterator i = ssOfferCaps.begin(); i != ssOfferCaps.end(); ++i) {
sRes += *i + " ";
}
- RespondCap("LS :" + sRes + "userhost-in-names multi-prefix");
+ RespondCap("LS :" + sRes + "userhost-in-names multi-prefix znc.in/server-time");
m_bInCap = true;
} else if (sSubCmd.Equals("END")) {
m_bInCap = false;
@@ -784,7 +784,7 @@ void CClient::HandleCap(const CString& sLine)
if (sCap.TrimPrefix("-"))
bVal = false;
- bool bAccepted = ("multi-prefix" == sCap) || ("userhost-in-names" == sCap);
+ bool bAccepted = ("multi-prefix" == sCap) || ("userhost-in-names" == sCap) || ("znc.in/server-time" == sCap);
GLOBALMODULECALL(IsClientCapSupported(this, sCap, bVal), bAccepted = true);
if (!bAccepted) {
@@ -804,6 +804,8 @@ void CClient::HandleCap(const CString& sLine)
m_bNamesx = bVal;
} else if ("userhost-in-names" == *it) {
m_bUHNames = bVal;
+ } else if ("znc.in/server-time" == *it) {
+ m_bServerTime = bVal;
}
GLOBALMODULECALL(OnClientCapRequest(this, *it, bVal), NOTHING);
@@ -839,6 +841,10 @@ void CClient::HandleCap(const CString& sLine)
m_bUHNames = false;
ssRemoved.insert("userhost-in-names");
}
+ if (m_bServerTime) {
+ m_bServerTime = false;
+ ssRemoved.insert("znc.in/server-time");
+ }
CString sList = "";
for (SCString::iterator i = ssRemoved.begin(); i != ssRemoved.end(); ++i) {
m_ssAcceptedCaps.erase(*i);
View
2 src/ClientCommand.cpp
@@ -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;
}
View
42 src/IRCNetwork.cpp
@@ -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();
@@ -344,14 +344,16 @@ void CIRCNetwork::ClientConnected(CClient *pClient) {
m_vClients.push_back(pClient);
+ unsigned int uIdx, uSize;
+ MCString msParams;
+ msParams["target"] = GetIRCNick().GetNick();
+
if (m_RawBuffer.IsEmpty()) {
pClient->PutClient(":irc.znc.in 001 " + pClient->GetNick() + " :- Welcome to ZNC -");
} else {
- unsigned int uIdx = 0;
- CString sLine;
-
- while (m_RawBuffer.GetLine(GetIRCNick().GetNick(), sLine, uIdx++)) {
- pClient->PutClient(sLine);
+ uSize = m_RawBuffer.Size();
+ for (uIdx = 0; uIdx < uSize; uIdx++) {
+ pClient->PutClient(m_RawBuffer.GetLine(uIdx, *pClient, msParams));
}
// The assumption is that the client got this nick from the 001 reply
@@ -359,11 +361,9 @@ void CIRCNetwork::ClientConnected(CClient *pClient) {
}
// Send the cached MOTD
- unsigned int uIdx = 0;
- CString sLine;
-
- while (m_MotdBuffer.GetLine(GetIRCNick().GetNick(), sLine, uIdx++)) {
- pClient->PutClient(sLine);
+ uSize = m_MotdBuffer.Size();
+ for (uIdx = 0; uIdx < uSize; uIdx++) {
+ pClient->PutClient(m_MotdBuffer.GetLine(uIdx, *pClient, msParams));
}
if (GetIRCSock() != NULL) {
@@ -391,11 +391,13 @@ void CIRCNetwork::ClientConnected(CClient *pClient) {
}
}
- CString sBufLine;
- while (m_QueryBuffer.GetNextLine(GetIRCNick().GetNick(), sBufLine)) {
- NETWORKMODULECALL(OnPrivBufferPlayLine(*pClient, sBufLine), m_pUser, this, NULL, continue);
- pClient->PutClient(sBufLine);
+ uSize = m_QueryBuffer.Size();
+ for (uIdx = 0; uIdx < uSize; uIdx++) {
+ CString sLine = m_QueryBuffer.GetLine(uIdx, *pClient, msParams);
+ NETWORKMODULECALL(OnPrivBufferPlayLine(*pClient, sLine), m_pUser, this, NULL, continue);
+ pClient->PutClient(sLine);
}
+ m_QueryBuffer.Clear();
// Tell them why they won't connect
if (!m_pUser->GetIRCConnectEnabled())
View
24 src/IRCSock.cpp
@@ -118,6 +118,7 @@ void CIRCSock::ReadLine(const CString& sData) {
unsigned int uRaw = sCmd.ToUInt();
CString sNick = sLine.Token(2);
CString sRest = sLine.Token(3, true);
+ CString sTmp;
switch (uRaw) {
case 1: { // :irc.server.com 001 nick :Welcome to the Internet Relay Network nick
@@ -152,13 +153,13 @@ void CIRCSock::ReadLine(const CString& sData) {
IRCSOCKMODULECALL(OnIRCConnected(), NOTHING);
m_pNetwork->ClearRawBuffer();
- m_pNetwork->AddRawBuffer(":" + sServer + " " + sCmd + " ", " " + sRest);
+ m_pNetwork->AddRawBuffer(":" + _NAMEDFMT(sServer) + " " + sCmd + " {target} " + _NAMEDFMT(sRest));
break;
}
case 5:
ParseISupport(sRest);
- m_pNetwork->UpdateExactRawBuffer(":" + sServer + " " + sCmd + " ", " " + sRest);
+ m_pNetwork->UpdateExactRawBuffer(":" + _NAMEDFMT(sServer) + " " + sCmd + " {target} " + _NAMEDFMT(sRest));
break;
case 10: { // :irc.server.com 010 nick <hostname> <port> :<info>
CString sHost = sRest.Token(0);
@@ -180,7 +181,8 @@ void CIRCSock::ReadLine(const CString& sData) {
case 255: // client count
case 265: // local users
case 266: // global users
- m_pNetwork->UpdateRawBuffer(":" + sServer + " " + sCmd + " ", " " + sRest);
+ sTmp = ":" + _NAMEDFMT(sServer) + " " + sCmd;
+ m_pNetwork->UpdateRawBuffer(sTmp, sTmp + " {target} " + _NAMEDFMT(sRest));
break;
case 305:
m_pNetwork->SetIRCAway(false);
@@ -331,7 +333,7 @@ void CIRCSock::ReadLine(const CString& sData) {
m_pNetwork->ClearMotdBuffer();
case 372: // motd
case 376: // end motd
- m_pNetwork->AddMotdBuffer(":" + sServer + " " + sCmd + " ", " " + sRest);
+ m_pNetwork->AddMotdBuffer(":" + _NAMEDFMT(sServer) + " " + sCmd + " {target} " + _NAMEDFMT(sRest));
break;
case 437:
// :irc.server.net 437 * badnick :Nick/channel is temporarily unavailable
@@ -663,7 +665,7 @@ void CIRCSock::ReadLine(const CString& sData) {
CString sMsg = sRest.Token(0, true).TrimPrefix_n();
if (!m_pNetwork->IsUserOnline()) {
- m_pNetwork->AddQueryBuffer(":" + Nick.GetNickMask() + " WALLOPS ", ":" + m_pNetwork->GetUser()->AddTimestamp(sMsg), false);
+ m_pNetwork->AddQueryBuffer(":" + _NAMEDFMT(Nick.GetNickMask()) + " WALLOPS :{text}", sMsg);
}
} else if (sCmd.Equals("CAP")) {
// CAPs are supported only before authorization.
@@ -770,7 +772,7 @@ bool CIRCSock::OnPrivCTCP(CNick& Nick, CString& sMessage) {
if (!m_pNetwork->IsUserOnline()) {
// If the user is detached, add to the buffer
- m_pNetwork->AddQueryBuffer(":" + Nick.GetNickMask() + " PRIVMSG ", " :\001ACTION " + m_pNetwork->GetUser()->AddTimestamp(sMessage) + "\001");
+ m_pNetwork->AddQueryBuffer(":" + _NAMEDFMT(Nick.GetNickMask()) + " PRIVMSG {target} :\001ACTION {text}\001", sMessage);
}
sMessage = "ACTION " + sMessage;
@@ -825,7 +827,7 @@ bool CIRCSock::OnPrivNotice(CNick& Nick, CString& sMessage) {
if (!m_pNetwork->IsUserOnline()) {
// If the user is detached, add to the buffer
- m_pNetwork->AddQueryBuffer(":" + Nick.GetNickMask() + " NOTICE ", " :" + m_pNetwork->GetUser()->AddTimestamp(sMessage));
+ m_pNetwork->AddQueryBuffer(":" + _NAMEDFMT(Nick.GetNickMask()) + " NOTICE {target} :{text}", sMessage);
}
return false;
@@ -836,7 +838,7 @@ bool CIRCSock::OnPrivMsg(CNick& Nick, CString& sMessage) {
if (!m_pNetwork->IsUserOnline()) {
// If the user is detached, add to the buffer
- m_pNetwork->AddQueryBuffer(":" + Nick.GetNickMask() + " PRIVMSG ", " :" + m_pNetwork->GetUser()->AddTimestamp(sMessage));
+ m_pNetwork->AddQueryBuffer(":" + _NAMEDFMT(Nick.GetNickMask()) + " PRIVMSG {target} :{text}", sMessage);
}
return false;
@@ -851,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 {text}\001", sMessage);
}
sMessage = "ACTION " + sMessage;
}
@@ -869,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) + " :{text}", sMessage);
}
}
@@ -882,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) + " :{text}", sMessage);
}
}
View
11 src/User.cpp
@@ -502,17 +502,15 @@ CString& CUser::ExpandString(const CString& sStr, CString& sRet) const {
}
CString CUser::AddTimestamp(const CString& sStr) const {
- CString sRet;
- return AddTimestamp(sStr, sRet);
+ time_t tm;
+ return AddTimestamp(time(&tm), sStr);
}
-CString& CUser::AddTimestamp(const CString& sStr, CString& sRet) const {
+CString CUser::AddTimestamp(time_t tm, const CString& sStr) const {
char szTimestamp[1024];
- time_t tm;
- sRet = sStr;
+ CString sRet = sStr;
if (!GetTimestampFormat().empty() && (m_bAppendTimestamp || m_bPrependTimestamp)) {
- time(&tm);
tm += (time_t)(m_fTimezoneOffset * 60 * 60); // offset is in hours
size_t i = strftime(szTimestamp, sizeof(szTimestamp), GetTimestampFormat().c_str(), localtime(&tm));
// If strftime returns 0, an error occured in format, or result is empty
@@ -530,6 +528,7 @@ CString& CUser::AddTimestamp(const CString& sStr, CString& sRet) const {
sRet += szTimestamp;
}
}
+
return sRet;
}
View
66 src/ZNCString.cpp
@@ -171,6 +171,8 @@ CString::EEscape CString::ToEscape(const CString& sEsc) {
return EURL;
} else if (sEsc.Equals("SQL")) {
return ESQL;
+ } else if (sEsc.Equals("NAMEDFMT")) {
+ return ENAMEDFMT;
}
return EASCII;
@@ -277,6 +279,16 @@ CString CString::Escape_n(EEscape eFrom, EEscape eTo) const {
}
break;
+ case ENAMEDFMT:
+ if (*p != '\\' || iLength < (a +1)) {
+ ch = *p;
+ } else {
+ a++;
+ p++;
+ ch = *p;
+ }
+
+ break;
}
switch (eTo) {
@@ -317,6 +329,13 @@ CString CString::Escape_n(EEscape eFrom, EEscape eTo) const {
} else { sRet += ch; }
break;
+ case ENAMEDFMT:
+ if (ch == '\\') { sRet += '\\'; sRet += '\\';
+ } else if (ch == '{') { sRet += '\\'; sRet += '{';
+ } else if (ch == '}') { sRet += '\\'; sRet += '}';
+ } else { sRet += ch; }
+
+ break;
}
}
@@ -639,6 +658,51 @@ unsigned int CString::Split(const CString& sDelim, SCString& ssRet, bool bAllowE
return ssRet.size();
}
+CString CString::NamedFormat(const CString& sFormat, const MCString& msValues) {
+ CString sRet;
+
+ CString sKey;
+ bool bEscape = false;
+ bool bParam = false;
+ const char* p = sFormat.c_str();
+
+ while (*p) {
+ if (!bParam) {
+ if (bEscape) {
+ sRet += *p;
+ bEscape = false;
+ } else if (*p == '\\') {
+ bEscape = true;
+ } else if (*p == '{') {
+ bParam = true;
+ sKey.clear();
+ } else {
+ sRet += *p;
+ }
+
+ } else {
+ if (bEscape) {
+ sKey += *p;
+ bEscape = false;
+ } else if (*p == '\\') {
+ bEscape = true;
+ } else if (*p == '}') {
+ bParam = false;
+ MCString::const_iterator it = msValues.find(sKey);
+ if (it != msValues.end()) {
+ sRet += (*it).second;
+ }
+ } else {
+ sKey += *p;
+ }
+ }
+
+ p++;
+ }
+
+ return sRet;
+}
+
CString CString::RandomString(unsigned int uLength) {
const char chars[] = "abcdefghijklmnopqrstuvwxyz"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
@@ -1031,6 +1095,8 @@ bool CString::RightChomp(unsigned int uLen) {
}
//////////////// MCString ////////////////
+const MCString MCString::EmptyMap;
+
MCString::status_t MCString::WriteToDisk(const CString& sPath, mode_t iMode) const {
CFile cFile(sPath);

No commit comments for this range

Something went wrong with that request. Please try again.