From 694f50c9c0c0ae1fd77f86528027f14984ee2e57 Mon Sep 17 00:00:00 2001 From: Alexey Sokolov Date: Sun, 11 May 2025 21:16:20 +0100 Subject: [PATCH] Make CTCP flood timer use monotonic time Probably should use std::chrono types instead of int, but that'll be a later change --- include/znc/IRCSock.h | 4 ++-- src/IRCSock.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/znc/IRCSock.h b/include/znc/IRCSock.h index d5b8d9cd..73a1b550 100644 --- a/include/znc/IRCSock.h +++ b/include/znc/IRCSock.h @@ -228,9 +228,9 @@ class CIRCSock : public CIRCSocket { SCString m_ssPendingCaps; SCString m_ssPendingCapsPhase2; MCString m_msCapLsValues; - time_t m_lastCTCP; + unsigned long long m_lastCTCP; unsigned int m_uNumCTCP; - static const time_t m_uCTCPFloodTime; + static const unsigned long long m_uCTCPFloodTime; static const unsigned int m_uCTCPFloodCount; MCString m_mISupport; std::deque m_vSendQueue; diff --git a/src/IRCSock.cpp b/src/IRCSock.cpp index 676e731b..37f3b9d5 100644 --- a/src/IRCSock.cpp +++ b/src/IRCSock.cpp @@ -31,7 +31,7 @@ using std::map; NETWORKMODULECALL(macFUNC, m_pNetwork->GetUser(), m_pNetwork, nullptr, \ macEXITER) // These are used in OnGeneralCTCP() -const time_t CIRCSock::m_uCTCPFloodTime = 5; +const unsigned long long CIRCSock::m_uCTCPFloodTime = 5000; const unsigned int CIRCSock::m_uCTCPFloodCount = 5; // It will be bad if user sets it to 0.00000000000001 @@ -544,7 +544,7 @@ bool CIRCSock::OnCTCPMessage(CCTCPMessage& Message) { } if (!sReply.empty()) { - time_t now = time(nullptr); + unsigned long long now = CUtils::GetMillTime(); // If the last CTCP is older than m_uCTCPFloodTime, reset the counter if (m_lastCTCP + m_uCTCPFloodTime < now) m_uNumCTCP = 0; m_lastCTCP = now;