mirror of
https://github.com/znc/znc.git
synced 2026-05-03 03:52:33 +02:00
Make CBufLine hold a CMessage internally
This commit is contained in:
@@ -19,34 +19,69 @@
|
||||
#include <znc/User.h>
|
||||
#include <time.h>
|
||||
|
||||
CBufLine::CBufLine(const CString& sFormat, const CString& sText, const timeval* ts, const MCString& mssTags) : m_sFormat(sFormat), m_sText(sText), m_time(), m_mssTags(mssTags) {
|
||||
CBufLine::CBufLine(const CMessage& Format, const CString& sText) : m_Message(Format), m_sText(sText) {
|
||||
}
|
||||
|
||||
CBufLine::CBufLine(const CString& sFormat, const CString& sText, const timeval* ts, const MCString& mssTags) : m_sText(sText) {
|
||||
m_Message.Parse(sFormat);
|
||||
m_Message.SetTags(mssTags);
|
||||
|
||||
if (ts == nullptr)
|
||||
UpdateTime();
|
||||
else
|
||||
m_time = *ts;
|
||||
m_Message.SetTime(*ts);
|
||||
}
|
||||
|
||||
CBufLine::~CBufLine() {}
|
||||
|
||||
void CBufLine::UpdateTime() {
|
||||
if (0 == gettimeofday(&m_time, nullptr)) {
|
||||
return;
|
||||
timeval tv;
|
||||
if (0 != gettimeofday(&tv, nullptr)) {
|
||||
tv.tv_sec = time(nullptr);
|
||||
tv.tv_usec = 0;
|
||||
}
|
||||
m_time.tv_sec = time(nullptr);
|
||||
m_time.tv_usec = 0;
|
||||
m_Message.SetTime(tv);
|
||||
}
|
||||
|
||||
CString CBufLine::GetLine(const CClient& Client, const MCString& msParams) const {
|
||||
MCString msThisParams = msParams;
|
||||
CMessage CBufLine::ToMessage(const CClient& Client, const MCString& mssParams) const {
|
||||
CMessage Line = m_Message;
|
||||
|
||||
CString sSender = Line.GetNick().GetNickMask();
|
||||
Line.SetNick(CNick(CString::NamedFormat(sSender, mssParams)));
|
||||
|
||||
MCString mssThisParams = mssParams;
|
||||
if (Client.HasServerTime()) {
|
||||
mssThisParams["text"] = m_sText;
|
||||
} else {
|
||||
mssThisParams["text"] = Client.GetUser()->AddTimestamp(Line.GetTime().tv_sec, m_sText);
|
||||
}
|
||||
|
||||
// make a copy of params, because the following loop modifies the original
|
||||
VCString vsParams = Line.GetParams();
|
||||
for (unsigned int uIdx = 0; uIdx < vsParams.size(); ++uIdx) {
|
||||
Line.SetParam(uIdx, CString::NamedFormat(vsParams[uIdx], mssThisParams));
|
||||
}
|
||||
|
||||
return Line;
|
||||
}
|
||||
|
||||
CString CBufLine::GetLine(const CClient& Client, const MCString& mssParams) const {
|
||||
CMessage Line = ToMessage(Client, mssParams);
|
||||
|
||||
// Note: Discard all tags (except the time tag, conditionally) to
|
||||
// keep the same behavior as ZNC versions 1.6 and earlier had. See
|
||||
// CClient::PutClient(CMessage) documentation for more details.
|
||||
Line.SetTags(MCString::EmptyMap);
|
||||
|
||||
if (Client.HasServerTime()) {
|
||||
msThisParams["text"] = m_sText;
|
||||
CString sStr = CString::NamedFormat(m_sFormat, msThisParams);
|
||||
return "@time=" + CUtils::FormatServerTime(m_time) + " " + sStr;
|
||||
} else {
|
||||
msThisParams["text"] = Client.GetUser()->AddTimestamp(m_time.tv_sec, m_sText);
|
||||
return CString::NamedFormat(m_sFormat, msThisParams);
|
||||
CString sTime = m_Message.GetTag("time");
|
||||
if (sTime.empty()) {
|
||||
sTime = CUtils::FormatServerTime(m_Message.GetTime());
|
||||
}
|
||||
Line.SetTag("time", sTime);
|
||||
}
|
||||
|
||||
return Line.ToString();
|
||||
}
|
||||
|
||||
CBuffer::CBuffer(unsigned int uLineCount) : m_uLineCount(uLineCount) {
|
||||
|
||||
Reference in New Issue
Block a user