Warn user if flood protection is delaying the messages for too long

This should help with cases like #1943
This commit is contained in:
Alexey Sokolov
2025-05-11 21:03:13 +01:00
parent cfd8d3f88d
commit 4f65f86ccd
2 changed files with 14 additions and 1 deletions

View File

@@ -238,6 +238,7 @@ class CIRCSock : public CIRCSocket {
unsigned short int m_uFloodBurst;
double m_fFloodRate;
bool m_bFloodProtection;
unsigned long long m_lastFloodWarned;
SCString m_ssSupportedTags;
VCString m_vsSSLError;

View File

@@ -89,7 +89,8 @@ CIRCSock::CIRCSock(CIRCNetwork* pNetwork)
m_iSendsAllowed(pNetwork->GetFloodBurst()),
m_uFloodBurst(pNetwork->GetFloodBurst()),
m_fFloodRate(pNetwork->GetFloodRate()),
m_bFloodProtection(IsFloodProtected(pNetwork->GetFloodRate())) {
m_bFloodProtection(IsFloodProtected(pNetwork->GetFloodRate())),
m_lastFloodWarned(0) {
EnableReadLine();
m_Nick.SetIdent(m_pNetwork->GetIdent());
m_Nick.SetHost(m_pNetwork->GetBindHost());
@@ -1383,6 +1384,17 @@ void CIRCSock::TrySend() {
PutIRCRaw(Message.ToString());
}
m_vSendQueue.pop_front();
if (m_vSendQueue.size() * m_fFloodRate > 600) {
unsigned long long now = CUtils::GetMillTime();
// Warn no more often than once every 2 minutes
if (now > m_lastFloodWarned + 2 * 60'000) {
m_lastFloodWarned = now;
this->GetNetwork()->PutStatus(
t_f("Warning: flood protection is delaying your messages "
"by {1} seconds")(m_vSendQueue.size() * m_fFloodRate));
}
}
}
}