aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Sadie Powell2021-04-06 15:40:21 +0100
committerGravatar Sadie Powell2021-04-06 15:40:21 +0100
commitc05bb42e8d900e5f65232ab2cfa34d846e41faa3 (patch)
tree70f4d1bce39656ac6d98b054fc901fa082af95c3
parentRewrite the COMMANDS handler (diff)
parentUse IsCTCP in blockcolor for ignoring CTCPs. (diff)
Merge branch 'insp3' into master.
-rw-r--r--src/modules/m_blockcolor.cpp11
-rw-r--r--src/modules/m_chanhistory.cpp42
2 files changed, 32 insertions, 21 deletions
diff --git a/src/modules/m_blockcolor.cpp b/src/modules/m_blockcolor.cpp
index 650d7aec8..d102524f2 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 (!extban.GetStatus(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<unsigned char>(*i);
+ if (chr < 32)
{
if (modeset)
user->WriteNumeric(Numerics::CannotSendTo(c, "messages containing formatting characters", &bc));
diff --git a/src/modules/m_chanhistory.cpp b/src/modules/m_chanhistory.cpp
index 29705e255..a958e7f63 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<HistoryMode, SimpleExtItem<HistoryList> >
@@ -108,6 +120,7 @@ class HistoryMode : public ParamMode<HistoryMode, SimpleExtItem<HistoryList> >
history->maxlen = len;
history->maxtime = time;
+ history->Prune();
}
else
{
@@ -154,7 +167,7 @@ class ModuleChanHistory
}
}
- void SendHistory(LocalUser* user, Channel* channel, HistoryList* list, time_t mintime)
+ void SendHistory(LocalUser* user, Channel* channel, HistoryList* list)
{
if (batchmanager)
{
@@ -162,19 +175,16 @@ class ModuleChanHistory
batch.GetBatchStartMessage().PushParamRef(channel->name);
}
- for(std::deque<HistoryItem>::iterator i = list->lines.begin(); i != list->lines.end(); ++i)
+ for (std::deque<HistoryItem>::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)
@@ -240,7 +250,7 @@ class ModuleChanHistory
return;
HistoryList* list = historymode.ext.Get(memb->chan);
- if (!list)
+ if (!list || !list->Prune())
return;
if ((prefixmsg) && (!batchcap.IsEnabled(localuser)))
@@ -251,11 +261,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);
}
};