Name a poke from a sender with no unique id who is not on the snapshot
Driver::sender made a synthetic user id for such a sender ("client:N") but put
no User entity into LIVE, so SessionLink::signal found no User and the nick of
the poke was empty. The earlier fix covered senders that have a unique id only.
The driver now puts a bare User with the name the link gave and no uid into
LIVE, keyed by the synthetic client id, before it pushes the signal (so it
shows in no presence, and the poke's from_uid stays none). A client id is given
again to whoever connects next, so the user is replaced when the same client
id comes back with another name; a sender with an empty name gets none.
Test: a poke from client 77 with no unique id is named, and named again with
the new name when the client id comes back as somebody else. It fails on the
code before this commit.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b0b1c82ddc
commit
6a2f00a636
3 files changed
+54
-5
No files matched your search
@@ -2111,3 +2111,28 @@ async fn a_transfer_waits_for_the_server_for_as_long_as_the_caller_does() {
|
||||
tokio::time::sleep(Duration::from_millis(50)).await;
|
||||
assert!(reply.is_closed(), "the link's job outlived its caller");
|
||||
}
|
||||
|
||||
/// A sender with no unique id who is not on the snapshot is named all the
|
||||
/// same: the name the link gave goes into LIVE as a user of its own.
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn a_poke_from_a_sender_with_no_unique_id_outside_the_snapshot_is_named() {
|
||||
let mut rig = Rig::new(everything()).await;
|
||||
let poke = |name: &str| LinkEvent::Poke {
|
||||
from: 77,
|
||||
from_uid: None,
|
||||
from_name: name.into(),
|
||||
message: "boo".into(),
|
||||
};
|
||||
async fn named(rig: &mut Rig) -> (Option<String>, String) {
|
||||
rig.event(|e| match e {
|
||||
LinkEvent::Poke { from: 77, from_uid, from_name, .. } => Some((from_uid, from_name)),
|
||||
_ => None,
|
||||
})
|
||||
.await
|
||||
}
|
||||
rig.play(poke("ghost"));
|
||||
assert_eq!(named(&mut rig).await, (None, "ghost".to_owned()));
|
||||
// The link gives the client id to whoever connects next: the name follows.
|
||||
rig.play(poke("ghost two"));
|
||||
assert_eq!(named(&mut rig).await, (None, "ghost two".to_owned()));
|
||||
}
|
||||
@@ -881,15 +881,33 @@ impl Driver {
|
||||
let participant = client.map_or(0, u32::from);
|
||||
match uid.filter(|u| !u.is_empty()) {
|
||||
Some(uid) => (self.extra_user(uid, name), participant),
|
||||
None if client.is_some() => {
|
||||
// A sender with no unique id: by its client id.
|
||||
let id = ids::synthetic_user(&format!("client:{}", participant));
|
||||
(id, participant)
|
||||
}
|
||||
None if client.is_some() => (self.extra_client(participant, name), participant),
|
||||
None => (0, participant),
|
||||
}
|
||||
}
|
||||
|
||||
/// A user for a sender with no unique id who is not on the snapshot,
|
||||
/// made from its client id and put into LIVE with the name the link
|
||||
/// gave, so that whoever reads the poke or the message can name it. The
|
||||
/// link hands a client id to whoever connects next: the name follows the
|
||||
/// sender.
|
||||
fn extra_client(&mut self, client: u32, name: &str) -> u64 {
|
||||
let id = ids::synthetic_user(&format!("client:{client}"));
|
||||
if name.is_empty() {
|
||||
return id;
|
||||
}
|
||||
let user = entities::client_user(id, name, self.cfg.ts6);
|
||||
if self.extras.get(&id) != Some(&user) {
|
||||
self.extras.insert(id, user.clone());
|
||||
let entity = entity(Kind::User(user));
|
||||
if let Some(key) = Key::of(&entity) {
|
||||
self.live.insert(key, entity.clone());
|
||||
self.commit(ScopeId::Live(SERVER_ID), vec![entity], Vec::new());
|
||||
}
|
||||
}
|
||||
id
|
||||
}
|
||||
|
||||
/// A user for a unique id the snapshot does not hold, put into LIVE.
|
||||
fn extra_user(&mut self, uid: &str, name: &str) -> u64 {
|
||||
let id = ids::synthetic_user(uid);
|
||||
|
||||
@@ -246,6 +246,12 @@ pub(crate) fn bare_user(uid: &str, name: &str, ts6: bool) -> v1::User {
|
||||
)
|
||||
}
|
||||
|
||||
/// A user who is on no snapshot and has no unique id (the sender of a poke
|
||||
/// or a message that the link names by its client id only): `id` and name.
|
||||
pub(crate) fn client_user(id: u64, name: &str, ts6: bool) -> v1::User {
|
||||
user(&ClientInfo { nickname: name.to_owned(), ..Default::default() }, id, ts6)
|
||||
}
|
||||
|
||||
/// Everything the snapshot `presence` says, as entities of the scopes of
|
||||
/// server 1. `ts6`: the server is TeamSpeak 6 (the kind of its unique ids).
|
||||
pub(crate) fn build(presence: &Presence, ts6: bool, own_client: Option<u16>) -> Built {
|
||||
|
||||
Reference in new issue
Block a user