From e4f7e2523b54090deb7e4f40f735893192fa51eb Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Sat, 3 Apr 2021 14:35:18 +0100 Subject: Automatically prune the history lists in chanhistory. --- src/modules/m_chanhistory.cpp | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/src/modules/m_chanhistory.cpp b/src/modules/m_chanhistory.cpp index 38ec217df..3ad6b81e6 100644 --- a/src/modules/m_chanhistory.cpp +++ b/src/modules/m_chanhistory.cpp @@ -61,6 +61,18 @@ struct HistoryList , maxtime(time) { } + + size_t Prune() + { + // Prune expired entries from the list. + if (maxtime) + { + time_t mintime = ServerInstance->Time() - maxtime; + while (!lines.empty() && lines.front().ts < mintime) + lines.pop_front(); + } + return lines.size(); + } }; class HistoryMode : public ParamMode > @@ -108,6 +120,7 @@ class HistoryMode : public ParamMode > history->maxlen = len; history->maxtime = time; + history->Prune(); } else { @@ -165,7 +178,7 @@ class ModuleChanHistory } } - void SendHistory(LocalUser* user, Channel* channel, HistoryList* list, time_t mintime) + void SendHistory(LocalUser* user, Channel* channel, HistoryList* list) { if (batchmanager) { @@ -173,19 +186,16 @@ class ModuleChanHistory batch.GetBatchStartMessage().PushParamRef(channel->name); } - for(std::deque::iterator i = list->lines.begin(); i != list->lines.end(); ++i) + for (std::deque::iterator i = list->lines.begin(); i != list->lines.end(); ++i) { HistoryItem& item = *i; - if (item.ts >= mintime) - { - ClientProtocol::Messages::Privmsg msg(ClientProtocol::Messages::Privmsg::nocopy, item.sourcemask, channel, item.text, item.type); - for (HistoryTagMap::iterator iter = item.tags.begin(); iter != item.tags.end(); ++iter) - AddTag(msg, iter->first, iter->second); - if (servertimemanager) - servertimemanager->Set(msg, item.ts); - batch.AddToBatch(msg); - user->Send(ServerInstance->GetRFCEvents().privmsg, msg); - } + ClientProtocol::Messages::Privmsg msg(ClientProtocol::Messages::Privmsg::nocopy, item.sourcemask, channel, item.text, item.type); + for (HistoryTagMap::iterator iter = item.tags.begin(); iter != item.tags.end(); ++iter) + AddTag(msg, iter->first, iter->second); + if (servertimemanager) + servertimemanager->Set(msg, item.ts); + batch.AddToBatch(msg); + user->Send(ServerInstance->GetRFCEvents().privmsg, msg); } if (batchmanager) @@ -250,7 +260,7 @@ class ModuleChanHistory return; HistoryList* list = historymode.ext.get(memb->chan); - if (!list) + if (!list || !list->Prune()) return; if ((prefixmsg) && (!batchcap.get(localuser))) @@ -261,11 +271,7 @@ class ModuleChanHistory memb->WriteNotice(message); } - time_t mintime = 0; - if (list->maxtime) - mintime = ServerInstance->Time() - list->maxtime; - - SendHistory(localuser, memb->chan, list, mintime); + SendHistory(localuser, memb->chan, list); } Version GetVersion() CXX11_OVERRIDE -- cgit v1.3.1-10-gc9f91 From c05f81cac83e80c7727594e3929e0709eccca689 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Tue, 6 Apr 2021 14:43:39 +0100 Subject: Use IsCTCP in blockcolor for ignoring CTCPs. --- src/modules/m_blockcolor.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/modules/m_blockcolor.cpp b/src/modules/m_blockcolor.cpp index c5dc35fe3..905cc50b5 100644 --- a/src/modules/m_blockcolor.cpp +++ b/src/modules/m_blockcolor.cpp @@ -60,10 +60,15 @@ class ModuleBlockColor : public Module bool modeset = c->IsModeSet(bc); if (!c->GetExtBanStatus(user, 'c').check(!modeset)) { - for (std::string::iterator i = details.text.begin(); i != details.text.end(); i++) + std::string ctcpname; // Unused. + std::string message; + if (!details.IsCTCP(ctcpname, message)) + message.assign(details.text); + + for (std::string::iterator i = message.begin(); i != message.end(); ++i) { - // Block all control codes except \001 for CTCP - if ((*i >= 0) && (*i < 32) && (*i != 1)) + const unsigned char chr = static_cast(*i); + if (chr < 32) { if (modeset) user->WriteNumeric(Numerics::CannotSendTo(c, "messages containing formatting characters", &bc)); -- cgit v1.3.1-10-gc9f91