aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/listmode.h17
-rw-r--r--src/listmode.cpp34
2 files changed, 28 insertions, 23 deletions
diff --git a/include/listmode.h b/include/listmode.h
index 941e87be6..458676eee 100644
--- a/include/listmode.h
+++ b/include/listmode.h
@@ -53,7 +53,7 @@ private:
{
public:
ModeList list;
- long maxitems = -1;
+ std::optional<size_t> maxitems;
};
/** The number of items a listmode's list may contain
@@ -61,8 +61,8 @@ private:
struct ListLimit final
{
std::string mask;
- unsigned long limit;
- ListLimit(const std::string& Mask, unsigned long Limit)
+ size_t limit;
+ ListLimit(const std::string& Mask, size_t Limit)
: mask(Mask)
, limit(Limit)
{
@@ -82,7 +82,7 @@ private:
* @param channame The channel name to find the limit for
* @return The maximum number of modes of this type that we allow to be set on the given channel name
*/
- unsigned long FindLimit(const std::string& channame);
+ size_t FindLimit(const std::string& channame);
/** Returns the limit on the given channel for this mode.
* If the limit is cached then the cached value is returned,
@@ -92,7 +92,7 @@ private:
* @param cd The ChanData associated with channel channame
* @return The maximum number of modes of this type that we allow to be set on the given channel
*/
- unsigned long GetLimitInternal(const std::string& channame, ChanData* cd);
+ size_t GetLimitInternal(const std::string& channame, ChanData* cd);
protected:
/** Numeric to use when outputting the list
@@ -136,11 +136,11 @@ public:
* @param channel The channel to inspect
* @return Maximum number of modes of this type that can be placed on the given channel
*/
- unsigned long GetLimit(Channel* channel);
+ size_t GetLimit(Channel* channel);
/** Gets the lower list limit for this listmode.
*/
- unsigned long GetLowerLimit();
+ size_t GetLowerLimit();
/** Retrieves the list of all modes set on the given channel
* @param channel Channel to get the list from
@@ -182,8 +182,9 @@ public:
* @param source Source user adding the parameter
* @param channel Channel the parameter is being added to
* @param parameter The actual parameter being added
+ * @param limit The list limit for the channel.
*/
- virtual void TellListTooLong(LocalUser* source, Channel* channel, const std::string& parameter);
+ virtual void TellListTooLong(LocalUser* source, Channel* channel, const std::string& parameter, size_t limit);
/** Tell the user an item is already on the list.
* Overridden by implementing module.
diff --git a/src/listmode.cpp b/src/listmode.cpp
index 7707e269e..40a91004e 100644
--- a/src/listmode.cpp
+++ b/src/listmode.cpp
@@ -80,7 +80,7 @@ void ListModeBase::DoRehash()
if (!mname.empty() && !insp::equalsci(mname, name) && !(mname.length() == 1 && GetModeChar() == mname[0]))
continue;
- ListLimit limit(c->getString("chan", "*", 1), c->getNum<unsigned long>("limit", DEFAULT_LIST_SIZE));
+ ListLimit limit(c->getString("chan", "*", 1), c->getNum<size_t>("limit", DEFAULT_LIST_SIZE));
if (limit.mask.empty())
throw ModuleException(creator, INSP_FORMAT("<maxlist:chan> is empty, at {}", c->source.str()));
@@ -109,11 +109,11 @@ void ListModeBase::DoRehash()
{
ChanData* cd = extItem.Get(chan);
if (cd)
- cd->maxitems = -1;
+ cd->maxitems.reset();
}
}
-unsigned long ListModeBase::FindLimit(const std::string& channame)
+size_t ListModeBase::FindLimit(const std::string& channame)
{
for (const auto& chanlimit : chanlimits)
{
@@ -126,14 +126,14 @@ unsigned long ListModeBase::FindLimit(const std::string& channame)
return 0;
}
-unsigned long ListModeBase::GetLimitInternal(const std::string& channame, ChanData* cd)
+size_t ListModeBase::GetLimitInternal(const std::string& channame, ChanData* cd)
{
- if (cd->maxitems < 0)
+ if (!cd->maxitems)
cd->maxitems = FindLimit(channame);
- return cd->maxitems;
+ return cd->maxitems.value();
}
-unsigned long ListModeBase::GetLimit(Channel* channel)
+size_t ListModeBase::GetLimit(Channel* channel)
{
ChanData* cd = extItem.Get(channel);
if (!cd) // just find the limit
@@ -142,12 +142,12 @@ unsigned long ListModeBase::GetLimit(Channel* channel)
return GetLimitInternal(channel->name, cd);
}
-unsigned long ListModeBase::GetLowerLimit()
+size_t ListModeBase::GetLowerLimit()
{
if (chanlimits.empty())
return DEFAULT_LIST_SIZE;
- unsigned long limit = ULONG_MAX;
+ size_t limit = std::numeric_limits<size_t>::max();
for (const auto& chanlimit : chanlimits)
{
if (chanlimit.limit < limit)
@@ -187,11 +187,15 @@ bool ListModeBase::OnModeChange(User* source, User*, Channel* channel, Modes::Ch
extItem.Set(channel, cd);
}
- if (lsource && cd->list.size() >= GetLimitInternal(channel->name, cd))
+ if (lsource)
{
- // The list size might be 0 so we have to check even if just created.
- TellListTooLong(lsource, channel, change.param);
- return false;
+ size_t limit = GetLimitInternal(channel->name, cd);
+ if (cd->list.size() >= limit)
+ {
+ // The list size might be 0 so we have to check even if just created.
+ TellListTooLong(lsource, channel, change.param, limit);
+ return false;
+ }
}
// Add the new entry to the list.
@@ -231,9 +235,9 @@ void ListModeBase::OnParameterMissing(User* source, User* dest, Channel* channel
// Intentionally left blank.
}
-void ListModeBase::TellListTooLong(LocalUser* source, Channel* channel, const std::string& parameter)
+void ListModeBase::TellListTooLong(LocalUser* source, Channel* channel, const std::string& parameter, size_t limit)
{
- source->WriteNumeric(ERR_BANLISTFULL, channel->name, parameter, mode, INSP_FORMAT("Channel {} list is full", name));
+ source->WriteNumeric(ERR_BANLISTFULL, channel->name, parameter, mode, INSP_FORMAT("Channel {} list is full ({} entries)", name, limit));
}
void ListModeBase::TellAlreadyOnList(LocalUser* source, Channel* channel, const std::string& parameter)