diff options
author | Peter Powell <petpow@saberuk.com> | 2017-07-24 16:51:01 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-24 16:51:01 +0100 |
commit | 6ad780e527094d5d1cb68af1ec326b58db182c80 (patch) | |
tree | ea49869ba451ebbeb824ee1f6496a55f75ebfaff | |
parent | b4c5a118dbea3403e073998eeb397316755b074a (diff) | |
parent | 60658d0bdbc8d047c3dbfc19abb005e147b5b2b9 (diff) |
Merge pull request #1221 from SaberUK/master+isupport-maxlist
Replace the deprecated MAXBANS token with MAXLIST.
-rw-r--r-- | include/listmode.h | 7 | ||||
-rw-r--r-- | src/coremods/core_channel/core_channel.cpp | 25 | ||||
-rw-r--r-- | src/listmode.cpp | 15 | ||||
-rw-r--r-- | src/server.cpp | 1 |
4 files changed, 45 insertions, 3 deletions
diff --git a/include/listmode.h b/include/listmode.h index 94af1d524..f49c5b3c8 100644 --- a/include/listmode.h +++ b/include/listmode.h @@ -63,6 +63,9 @@ class CoreExport ListModeBase : public ModeHandler */ typedef std::vector<ListLimit> limitlist; + /** The default maximum list size. */ + static const unsigned int DEFAULT_LIST_SIZE = 64; + /** Finds the limit of modes that can be placed on the given channel name according to the config * @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 @@ -123,6 +126,10 @@ class CoreExport ListModeBase : public ModeHandler */ unsigned int GetLimit(Channel* channel); + /** Gets the lower list limit for this listmode. + */ + unsigned int GetLowerLimit(); + /** Retrieves the list of all modes set on the given channel * @param channel Channel to get the list from * @return A list with all modes of this type set on the given channel, can be NULL diff --git a/src/coremods/core_channel/core_channel.cpp b/src/coremods/core_channel/core_channel.cpp index aba4d9769..6fe6199db 100644 --- a/src/coremods/core_channel/core_channel.cpp +++ b/src/coremods/core_channel/core_channel.cpp @@ -20,6 +20,7 @@ #include "inspircd.h" #include "core_channel.h" #include "invite.h" +#include "listmode.h" class CoreModChannel : public Module { @@ -58,6 +59,30 @@ class CoreModChannel : public Module } } + void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE + { + // Build a map of limits to their mode character. + insp::flat_map<int, std::string> limits; + const ModeParser::ListModeList& listmodes = ServerInstance->Modes->GetListModes(); + for (ModeParser::ListModeList::const_iterator iter = listmodes.begin(); iter != listmodes.end(); ++iter) + { + const unsigned int limit = (*iter)->GetLowerLimit(); + limits[limit].push_back((*iter)->GetModeChar()); + } + + // Generate the MAXLIST token from the limits map. + std::string& buffer = tokens["MAXLIST"]; + for (insp::flat_map<int, std::string>::const_iterator iter = limits.begin(); iter != limits.end(); ++iter) + { + if (!buffer.empty()) + buffer.push_back(','); + + buffer.append(iter->second); + buffer.push_back(':'); + buffer.append(ConvToStr(iter->first)); + } + } + void OnPostJoin(Membership* memb) CXX11_OVERRIDE { Channel* const chan = memb->chan; diff --git a/src/listmode.cpp b/src/listmode.cpp index cd034688c..23f98bf3f 100644 --- a/src/listmode.cpp +++ b/src/listmode.cpp @@ -77,7 +77,7 @@ void ListModeBase::DoRehash() // Add the default entry. This is inserted last so if the user specifies a // wildcard record in the config it will take precedence over this entry. - chanlimits.push_back(ListLimit("*", 64)); + chanlimits.push_back(ListLimit("*", DEFAULT_LIST_SIZE)); // Most of the time our settings are unchanged, so we can avoid iterating the chanlist if (oldlimits == chanlimits) @@ -102,7 +102,7 @@ unsigned int ListModeBase::FindLimit(const std::string& channame) return it->limit; } } - return 64; + return DEFAULT_LIST_SIZE; } unsigned int ListModeBase::GetLimitInternal(const std::string& channame, ChanData* cd) @@ -121,6 +121,17 @@ unsigned int ListModeBase::GetLimit(Channel* channel) return GetLimitInternal(channel->name, cd); } +unsigned int ListModeBase::GetLowerLimit() +{ + unsigned int limit = UINT_MAX; + for (limitlist::iterator iter = chanlimits.begin(); iter != chanlimits.end(); ++iter) + { + if (iter->limit < limit) + limit = iter->limit; + } + return limit == UINT_MAX ? DEFAULT_LIST_SIZE : limit; +} + ModeAction ListModeBase::OnModeChange(User* source, User*, Channel* channel, std::string ¶meter, bool adding) { // Try and grab the list diff --git a/src/server.cpp b/src/server.cpp index 2feb08f96..6782187fe 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -171,7 +171,6 @@ void ISupportManager::Build() tokens["CHANTYPES"] = "#"; tokens["ELIST"] = "MU"; tokens["KICKLEN"] = ConvToStr(ServerInstance->Config->Limits.MaxKick); - tokens["MAXBANS"] = "64"; // TODO: make this a config setting. tokens["MAXTARGETS"] = ConvToStr(ServerInstance->Config->MaxTargets); tokens["MODES"] = ConvToStr(ServerInstance->Config->Limits.MaxModes); tokens["NETWORK"] = ServerInstance->Config->Network; |