TBAN timed channel bans (auto-lift on the tick)
This commit is contained in:
parent
835c1cf099
commit
cab53016e8
5 changed files with 92 additions and 1 deletions
|
|
@ -103,6 +103,7 @@ pub struct Ban {
|
|||
pub mask: String,
|
||||
pub setter: String,
|
||||
pub ts: u64,
|
||||
pub expires: Option<u64>, // TBAN: unix ts to auto-lift at (None = permanent)
|
||||
}
|
||||
|
||||
/// +f message flood: `[*]lines:secs` — kick past `lines` msgs in `secs` (and set
|
||||
|
|
@ -348,6 +349,26 @@ impl Server {
|
|||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
/// Lift any expired TBAN timed bans, announcing `MODE -b` to each channel.
|
||||
/// Called from the background tick.
|
||||
pub fn purge_tbans(&mut self) {
|
||||
let now = now();
|
||||
let mut expired: Vec<(String, String, String)> = Vec::new(); // (key, name, mask)
|
||||
for (key, ch) in &self.channels {
|
||||
for b in &ch.bans {
|
||||
if b.expires.is_some_and(|e| e <= now) {
|
||||
expired.push((key.clone(), ch.name.clone(), b.mask.clone()));
|
||||
}
|
||||
}
|
||||
}
|
||||
for (key, name, mask) in expired {
|
||||
if let Some(ch) = self.channels.get_mut(&key) {
|
||||
ch.bans.retain(|b| b.mask != mask);
|
||||
}
|
||||
self.to_channel(&key, &format!(":{} MODE {name} -b {mask}", self.name), None);
|
||||
}
|
||||
}
|
||||
|
||||
/// Force `uid` out of `chan` (SAPART / SVSPART enforcement): announce the PART
|
||||
/// to the channel and to links, drop the membership, reap the channel if empty.
|
||||
/// No-op if the user isn't a member.
|
||||
|
|
@ -758,6 +779,7 @@ impl Server {
|
|||
mask,
|
||||
setter: self.name.clone(),
|
||||
ts: now(),
|
||||
expires: None,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue