From c94890b0a627332e5630b8e35faba213a6ae3912 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Mon, 15 Jun 2026 17:04:16 +0100 Subject: Rework how list mode limits are parsed and applied. - Keep one list of all limits in ServerLimits instead of one in each list mode. This should reduce memory usage slightly and the lists are usually so small and are compared so infrequently that this won't cause any performnace issues. - Automatically look up the mode limit when the mode list is used instead of manually rehashing in each module. This should cause less footguns than the old API and doesn't require manually updating the limit on rehash. - Move code relating to variable and lower limits from the core to core_channel. This is only used by ISUPPORT. --- src/configreader.cpp | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) (limited to 'src/configreader.cpp') diff --git a/src/configreader.cpp b/src/configreader.cpp index c7d0015d0..71c2153bc 100644 --- a/src/configreader.cpp +++ b/src/configreader.cpp @@ -44,20 +44,28 @@ ServerConfig::ReadResult::ReadResult(const std::string& c, const std::string& e) { } -ServerConfig::ServerLimits::ServerLimits(const std::shared_ptr& tag) - : MaxLine(tag->getNum("maxline", 512, 512)) - , MaxNick(tag->getNum("maxnick", 30, 1, MaxLine)) - , MaxChannel(tag->getNum("maxchan", 60, 1, MaxLine)) - , MaxModes(tag->getNum("maxmodes", 20, 1)) - , MaxUser(tag->getNum("maxuser", 10, 1, MaxLine)) - , MaxQuit(tag->getNum("maxquit", 300, 0, MaxLine)) - , MaxTopic(tag->getNum("maxtopic", 330, 1, MaxLine)) - , MaxKick(tag->getNum("maxkick", 300, 1, MaxLine)) - , MaxReal(tag->getNum("maxreal", 130, 1, MaxLine)) - , MaxAway(tag->getNum("maxaway", 200, 1, MaxLine)) - , MaxHost(tag->getNum("maxhost", 64, 45, MaxLine)) - , MaxKey(tag->getNum("maxkey", 32, 1, ModeParser::MODE_PARAM_MAX)) +ServerConfig::ServerLimits::ServerLimits(const std::shared_ptr& limits, const TagList& maxlist) + : MaxLine(limits->getNum("maxline", 512, 512)) + , MaxNick(limits->getNum("maxnick", 30, 1, MaxLine)) + , MaxChannel(limits->getNum("maxchan", 60, 1, MaxLine)) + , MaxModes(limits->getNum("maxmodes", 20, 1)) + , MaxUser(limits->getNum("maxuser", 10, 1, MaxLine)) + , MaxQuit(limits->getNum("maxquit", 300, 0, MaxLine)) + , MaxTopic(limits->getNum("maxtopic", 330, 1, MaxLine)) + , MaxKick(limits->getNum("maxkick", 300, 1, MaxLine)) + , MaxReal(limits->getNum("maxreal", 130, 1, MaxLine)) + , MaxAway(limits->getNum("maxaway", 200, 1, MaxLine)) + , MaxHost(limits->getNum("maxhost", 64, 45, MaxLine)) + , MaxKey(limits->getNum("maxkey", 32, 1, ModeParser::MODE_PARAM_MAX)) { + for (const auto& [_, tag] : maxlist) + { + ListLimit limit; + limit.chan = tag->getString("chan", "*", 1); + limit.limit = tag->getNum("limit", ListModeBase::DEFAULT_LIST_SIZE); + limit.mode = tag->getString("mode"); + this->MaxList.push_back(std::move(limit)); + } } ServerConfig::ServerPaths::ServerPaths(const std::shared_ptr& tag) @@ -96,7 +104,7 @@ std::string ServerConfig::ServerPaths::ExpandPath(const std::string& base, const ServerConfig::ServerConfig() : EmptyTag(std::make_shared("empty", FilePosition("", 0, 0))) - , Limits(EmptyTag) + , Limits(EmptyTag, TagList(GetConfig().end(), GetConfig().end())) , Paths(EmptyTag) , ReadTime(ServerInstance->Time()) { @@ -412,7 +420,7 @@ void ServerConfig::Fill() IPv6Range = cidr->getNum("ipv6clone", 128, 1, 128); // Read any left over config tags. - Limits = ServerLimits(ConfValue("limits")); + Limits = ServerLimits(ConfValue("limits"), ConfTags("maxlist")); Paths = ServerPaths(ConfValue("path")); } -- cgit v1.3.1-10-gc9f91