mirror of
https://github.com/znc/znc.git
synced 2026-08-07 09:22:55 +02:00
Update server-time implementation to match new standard. #181
This commit is contained in:
+21
-7
@@ -11,26 +11,40 @@
|
||||
#include <znc/Client.h>
|
||||
#include <znc/User.h>
|
||||
|
||||
CBufLine::CBufLine(const CString& sFormat, const CString& sText, time_t tm) {
|
||||
CBufLine::CBufLine(const CString& sFormat, const CString& sText, const timespec* ts) {
|
||||
m_sFormat = sFormat;
|
||||
m_sText = sText;
|
||||
if (tm == 0)
|
||||
if (ts == NULL)
|
||||
UpdateTime();
|
||||
else
|
||||
m_tm = tm;
|
||||
m_time = *ts;
|
||||
}
|
||||
|
||||
CBufLine::~CBufLine() {}
|
||||
|
||||
void CBufLine::UpdateTime() {
|
||||
#if _POSIX_TIMERS
|
||||
if (0 == clock_gettime(CLOCK_REALTIME, &m_time)) {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
time(&m_time.tv_sec);
|
||||
m_time.tv_nsec = 0;
|
||||
}
|
||||
|
||||
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 "@t=" + CString(m_tm) + " " + sStr;
|
||||
CString s_msec(m_time.tv_nsec / 1000000);
|
||||
while (s_msec.length() < 3) {
|
||||
s_msec = "0" + s_msec;
|
||||
}
|
||||
return "@time=" + CString(m_time.tv_sec) + "." + s_msec + " " + sStr;
|
||||
} else {
|
||||
msThisParams["text"] = Client.GetUser()->AddTimestamp(m_tm, m_sText);
|
||||
msThisParams["text"] = Client.GetUser()->AddTimestamp(m_time.tv_sec, m_sText);
|
||||
return CString::NamedFormat(m_sFormat, msThisParams);
|
||||
}
|
||||
}
|
||||
@@ -41,7 +55,7 @@ CBuffer::CBuffer(unsigned int uLineCount) {
|
||||
|
||||
CBuffer::~CBuffer() {}
|
||||
|
||||
int CBuffer::AddLine(const CString& sFormat, const CString& sText, time_t tm) {
|
||||
int CBuffer::AddLine(const CString& sFormat, const CString& sText, const timespec* ts) {
|
||||
if (!m_uLineCount) {
|
||||
return 0;
|
||||
}
|
||||
@@ -50,7 +64,7 @@ int CBuffer::AddLine(const CString& sFormat, const CString& sText, time_t tm) {
|
||||
erase(begin());
|
||||
}
|
||||
|
||||
push_back(CBufLine(sFormat, sText, tm));
|
||||
push_back(CBufLine(sFormat, sText, ts));
|
||||
return size();
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -810,7 +810,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 znc.in/server-time");
|
||||
RespondCap("LS :" + sRes + "userhost-in-names multi-prefix server-time");
|
||||
m_bInCap = true;
|
||||
} else if (sSubCmd.Equals("END")) {
|
||||
m_bInCap = false;
|
||||
@@ -832,7 +832,7 @@ void CClient::HandleCap(const CString& sLine)
|
||||
if (sCap.TrimPrefix("-"))
|
||||
bVal = false;
|
||||
|
||||
bool bAccepted = ("multi-prefix" == sCap) || ("userhost-in-names" == sCap) || ("znc.in/server-time" == sCap);
|
||||
bool bAccepted = ("multi-prefix" == sCap) || ("userhost-in-names" == sCap) || ("server-time" == sCap);
|
||||
GLOBALMODULECALL(IsClientCapSupported(this, sCap, bVal), bAccepted = true);
|
||||
|
||||
if (!bAccepted) {
|
||||
@@ -852,7 +852,7 @@ 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) {
|
||||
} else if ("server-time" == *it) {
|
||||
m_bServerTime = bVal;
|
||||
}
|
||||
GLOBALMODULECALL(OnClientCapRequest(this, *it, bVal), NOTHING);
|
||||
@@ -891,7 +891,7 @@ void CClient::HandleCap(const CString& sLine)
|
||||
}
|
||||
if (m_bServerTime) {
|
||||
m_bServerTime = false;
|
||||
ssRemoved.insert("znc.in/server-time");
|
||||
ssRemoved.insert("server-time");
|
||||
}
|
||||
CString sList = "";
|
||||
for (SCString::iterator i = ssRemoved.begin(); i != ssRemoved.end(); ++i) {
|
||||
|
||||
Reference in New Issue
Block a user