diff options
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()) |
