Allocate guest nicks that skip online and registered names

This commit is contained in:
Jean Chevronnet 2026-07-19 19:19:20 +00:00
parent 2c81af108b
commit 118782a4bf
No known key found for this signature in database
5 changed files with 40 additions and 7 deletions

View file

@ -418,6 +418,22 @@
e.handle(NetEvent::Privmsg { from: uid.into(), to: "42SAAAAAA".into(), text: "LOGOUT".into() })
}
// A guest rename must skip a nick that's already online, or it would collide
// with (and get) an innocent user instead of freeing the name.
#[test]
fn logout_skips_an_occupied_guest_nick() {
let mut e = engine_with("guestskip", "foo", "sesame");
e.handle(NetEvent::UserConnect { uid: "000AAAAAB".into(), nick: "foo".into(), host: "h".into() , ip: "0.0.0.0".into() });
e.handle(NetEvent::Privmsg { from: "000AAAAAB".into(), to: "42SAAAAAA".into(), text: "IDENTIFY sesame".into() });
// Someone already holds Guest12345 (the first nick the counter would pick).
e.handle(NetEvent::UserConnect { uid: "000AAAAAC".into(), nick: "Guest12345".into(), host: "h".into() , ip: "0.0.0.0".into() });
let out = logout(&mut e, "000AAAAAB");
assert!(
out.iter().any(|a| matches!(a, NetAction::ForceNick { uid, nick } if uid == "000AAAAAB" && nick == "Guest12346")),
"logout skips the taken guest nick: {out:?}"
);
}
// LOGOUT while not identified must not rename you or clear anything.
#[test]
fn logout_without_login_is_noop() {