diff options
| author | 2022-04-11 23:49:10 +0100 | |
|---|---|---|
| committer | 2022-04-11 23:49:22 +0100 | |
| commit | 6830169ef13d4599916496b149c72577e6fb297d (patch) | |
| tree | 1e8a2de9c5e8f26781e8d35075aeac55d47272e4 /src/mode.cpp | |
| parent | Add a method to ConfigTag to help with retrieving a single character. (diff) | |
Add a method for finding the next prefix mode above a rank.
Diffstat (limited to 'src/mode.cpp')
| -rw-r--r-- | src/mode.cpp | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/src/mode.cpp b/src/mode.cpp index 4ab91fc6b..8fdbcdea0 100644 --- a/src/mode.cpp +++ b/src/mode.cpp @@ -286,18 +286,7 @@ ModeAction ModeParser::TryMode(User* user, User* targetuser, Channel* chan, Mode unsigned int ourrank = chan->GetPrefixValue(user); if (ourrank < neededrank) { - const PrefixMode* neededmh = NULL; - const PrefixModeList& prefixmodes = GetPrefixModes(); - for (PrefixModeList::const_iterator i = prefixmodes.begin(); i != prefixmodes.end(); ++i) - { - const PrefixMode* const privmh = *i; - if (privmh->GetPrefixRank() >= neededrank) - { - // this mode is sufficient to allow this action - if (!neededmh || privmh->GetPrefixRank() < neededmh->GetPrefixRank()) - neededmh = privmh; - } - } + const PrefixMode* neededmh = FindNearestPrefixMode(neededrank); if (neededmh) user->WriteNumeric(ERR_CHANOPRIVSNEEDED, chan->name, InspIRCd::Format("You must have channel %s access or above to %sset channel mode %c", neededmh->name.c_str(), adding ? "" : "un", modechar)); @@ -732,6 +721,24 @@ PrefixMode* ModeParser::FindPrefixMode(unsigned char modeletter) return mh->IsPrefixMode(); } +PrefixMode* ModeParser::FindNearestPrefixMode(unsigned int rank) +{ + PrefixMode* pm = NULL; + const PrefixModeList& prefixmodes = GetPrefixModes(); + for (PrefixModeList::const_iterator i = prefixmodes.begin(); i != prefixmodes.end(); ++i) + { + PrefixMode* thispm = *i; + if (thispm->GetPrefixRank() < rank) + continue; // Not ranked high enough. + + // Is it lower than the last checked mode? + if (!pm || thispm->GetPrefixRank() < pm->GetPrefixRank()) + pm = thispm; + + } + return pm; +} + PrefixMode* ModeParser::FindPrefix(unsigned const char pfxletter) { const PrefixModeList& list = GetPrefixModes(); |
