customprefix: add ranktoset/ranktounset/depriv per tier (InspIRCd change= parity for existing prefixes)

This commit is contained in:
Jean Chevronnet 2026-08-11 19:20:27 +00:00
parent 749a1c3b69
commit 9f3081cb38
2 changed files with 102 additions and 26 deletions

View file

@ -158,10 +158,25 @@ impl ChanMode for Prefix {
return Applied::No;
}
};
// must out-rank (or match) both the prefix being set and the target's
// current top rank — no de-opping someone above you.
// customprefix depriv=no: a member may not remove this prefix from themselves
if !adding && tuid == uid && !crate::modules::customprefix::can_depriv(self.ch) {
s.numeric(
uid,
ERR_CHANOPRIVSNEEDED,
&format!("{chan} :You may not remove +{} from yourself", self.ch),
);
return Applied::No;
}
// must out-rank (or match) both the rank needed to set/unset this prefix
// (customprefix ranktoset/ranktounset, default the prefix's own rank) and the
// target's current top rank — no de-opping someone above you.
let needed = if adding {
crate::modules::customprefix::rank_to_set(self.ch).unwrap_or(self.rank)
} else {
crate::modules::customprefix::rank_to_unset(self.ch).unwrap_or(self.rank)
};
let src = s.rank(uid, key);
if src < self.rank || src < target_rank {
if src < needed || src < target_rank {
s.numeric(
uid,
ERR_CHANOPRIVSNEEDED,