Preserve Anope negative mode locks on import instead of dropping them
Some checks failed
CI / check (push) Failing after 3m4s
Some checks failed
CI / check (push) Failing after 3m4s
This commit is contained in:
parent
d5bc2309c4
commit
c2db3bad7e
1 changed files with 25 additions and 14 deletions
|
|
@ -303,31 +303,42 @@ pub fn import_anope(anope_path: &str, out_path: &str, node: &str) -> std::io::Re
|
||||||
|
|
||||||
// Mode locks: aggregate the +modes per channel. Param modes (+f flood,
|
// Mode locks: aggregate the +modes per channel. Param modes (+f flood,
|
||||||
// +j joinflood) carry their stored value so the lock re-enforces verbatim.
|
// +j joinflood) carry their stored value so the lock re-enforces verbatim.
|
||||||
let mut locks: HashMap<String, (String, Vec<(char, String)>)> = HashMap::new();
|
// Per channel: (locked-on modes, locked-off modes, param values for on-modes).
|
||||||
|
type Mlock = (String, String, Vec<(char, String)>);
|
||||||
|
let mut locks: HashMap<String, Mlock> = HashMap::new();
|
||||||
for ml in records(&data, "ModeLock") {
|
for ml in records(&data, "ModeLock") {
|
||||||
let (Some(chan), Some(name)) = (field(ml, "ci"), field(ml, "name")) else { continue };
|
let (Some(chan), Some(name)) = (field(ml, "ci"), field(ml, "name")) else { continue };
|
||||||
if !flag(ml, "set") {
|
let set = flag(ml, "set");
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if let Some(ch) = mode_char(name) {
|
if let Some(ch) = mode_char(name) {
|
||||||
locks.entry(chan.to_string()).or_default().0.push(ch);
|
let entry = locks.entry(chan.to_string()).or_default();
|
||||||
} else if let Some(ch) = param_mode_char(name) {
|
if set {
|
||||||
|
entry.0.push(ch);
|
||||||
|
} else {
|
||||||
|
entry.1.push(ch); // a locked-OFF simple mode (-m/-p/-s), previously dropped silently
|
||||||
|
}
|
||||||
|
} else if set {
|
||||||
|
if let Some(ch) = param_mode_char(name) {
|
||||||
let Some(param) = field(ml, "param") else {
|
let Some(param) = field(ml, "param") else {
|
||||||
sum.skipped.push(format!("modelock {chan} {name}: param mode with no value"));
|
sum.skipped.push(format!("modelock {chan} {name}: param mode with no value"));
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
let entry = locks.entry(chan.to_string()).or_default();
|
let entry = locks.entry(chan.to_string()).or_default();
|
||||||
entry.0.push(ch);
|
entry.0.push(ch);
|
||||||
entry.1.push((ch, param.to_string()));
|
entry.2.push((ch, param.to_string()));
|
||||||
|
} else {
|
||||||
|
sum.skipped.push(format!("modelock {chan} {name}: unmapped mode"));
|
||||||
|
}
|
||||||
|
} else if let Some(ch) = param_mode_char(name) {
|
||||||
|
locks.entry(chan.to_string()).or_default().1.push(ch); // locked-off param mode takes no value
|
||||||
} else {
|
} else {
|
||||||
sum.skipped.push(format!("modelock {chan} {name}: unmapped mode"));
|
sum.skipped.push(format!("modelock {chan} {name}: unmapped mode"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (chan, (on, params)) in &locks {
|
for (chan, (on, off, params)) in &locks {
|
||||||
db.migrate_append(Event::ChannelMlock {
|
db.migrate_append(Event::ChannelMlock {
|
||||||
name: chan.clone(),
|
name: chan.clone(),
|
||||||
on: on.clone(),
|
on: on.clone(),
|
||||||
off: String::new(),
|
off: off.clone(),
|
||||||
params: params.clone(),
|
params: params.clone(),
|
||||||
})?;
|
})?;
|
||||||
sum.mlocked += 1;
|
sum.mlocked += 1;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue