+ if (MOD_RESULT == MOD_RES_PASSTHRU)
+ {
+ unsigned int neededrank = mh->GetLevelRequired();
+ /* Compare our rank on the channel against the rank of the required prefix,
+ * allow if >= ours. Because mIRC and xchat throw a tizz if the modes shown
+ * in NAMES(X) are not in rank order, we know the most powerful mode is listed
+ * first, so we don't need to iterate, we just look up the first instead.
+ */
+ unsigned int ourrank = chan->GetPrefixValue(user);
+ if (ourrank < neededrank)
+ {
+ ModeHandler* neededmh = NULL;
+ for(char c='A'; c <= 'z'; c++)
+ {
+ ModeHandler *privmh = FindMode(c, MODETYPE_CHANNEL);
+ if (privmh && 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, "%s %s :You must have channel %s access or above to %sset channel mode %c",
+ user->nick.c_str(), chan->name.c_str(), neededmh->name.c_str(), adding ? "" : "un", modechar);
+ else
+ user->WriteNumeric(ERR_CHANOPRIVSNEEDED, "%s %s :You cannot %sset channel mode %c",
+ user->nick.c_str(), chan->name.c_str(), adding ? "" : "un", modechar);
+ return MODEACTION_DENY;
+ }