diff options
| author | 2022-04-16 16:16:29 +0100 | |
|---|---|---|
| committer | 2022-04-16 16:16:29 +0100 | |
| commit | 30edd1070df3ddb2ae64b61b65c25f88a0b61e49 (patch) | |
| tree | 85b33545d32405f7d531bfac2d0b991a6eba3e70 /src/mode.cpp | |
| parent | Fix the command used to retrieve the number of cores on Alpine. (diff) | |
| parent | Bump peter-evans/create-pull-request from 3 to 4 (diff) | |
Merge branch 'insp3' into master.
Diffstat (limited to 'src/mode.cpp')
| -rw-r--r-- | src/mode.cpp | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/src/mode.cpp b/src/mode.cpp index bbe0b2042..3291bb55e 100644 --- a/src/mode.cpp +++ b/src/mode.cpp @@ -274,22 +274,8 @@ 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 (const auto& privmh : prefixmodes) - { - if (privmh->GetPrefixRank() >= neededrank) - { - // this mode is sufficient to allow this action - if (!neededmh || privmh->GetPrefixRank() < neededmh->GetPrefixRank()) - neededmh = privmh; - } - } - 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(), mcitem.adding ? "" : "un", modechar)); - else - user->WriteNumeric(ERR_CHANOPRIVSNEEDED, chan->name, InspIRCd::Format("You cannot %sset channel mode %c", (mcitem.adding ? "" : "un"), modechar)); + user->WriteNumeric(Numerics::ChannelPrivilegesNeeded(chan, neededrank, InspIRCd::Format("%s channel mode %c (%s)", + mcitem.adding ? "set" : "unset", mh->GetModeChar(), mh->name.c_str()))); return MODEACTION_DENY; } } @@ -713,6 +699,23 @@ PrefixMode* ModeParser::FindPrefixMode(unsigned char modeletter) return mh->IsPrefixMode(); } + +PrefixMode* ModeParser::FindNearestPrefixMode(unsigned int rank) +{ + PrefixMode* pm = nullptr; + for (const auto& thispm : GetPrefixModes()) + { + 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 char pfxletter) { for (const auto& pm : GetPrefixModes()) |
